• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdeedu
  • Sitemap
  • Contact Us
 

kiten/lib

dictFilePreferenceDialog.cpp

Go to the documentation of this file.
00001 /* This file is part of Kiten, a KDE Japanese Reference Tool...
00002    Copyright (C) 2006 Joseph Kerian <jkerian@gmail.com>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "dictFilePreferenceDialog.h"
00021 
00022 #include <QtGui/QWidget>
00023 #include <QtGui/QVBoxLayout>
00024 #include <QtGui/QListWidget>
00025 #include <QtGui/QLayout>
00026 #include <QtGui/QFrame>
00027 #include <QtCore/QStringList>
00028 #include <QtCore/QString>
00029 
00030 #include <kactionselector.h>
00031 #include <kconfigskeleton.h>
00032 #include <klocale.h>
00033 
00034 dictFileFieldSelector::dictFileFieldSelector(KConfigSkeleton *iconfig, 
00035         const QString &dictionaryTypeName, QWidget *parent) :
00036     DictionaryPreferenceDialog(parent,dictionaryTypeName), dictName(dictionaryTypeName) {
00037 
00038     QVBoxLayout *newTabLayout = new QVBoxLayout();
00039 
00040     //Make selection box
00041     ListView = new KActionSelector();
00042     ListView->setAvailableLabel(i18n("&Available Fields:"));
00043     newTabLayout->addWidget(ListView);
00044 
00045     //Add layout to our widget
00046     this->setLayout(newTabLayout);
00047 
00048     //Create Default List
00049     completeList.append("--NewLine--");
00050     completeList.append("--NewLine--");
00051     completeList.append("--NewLine--");
00052     completeList.append("Word/Kanji");
00053     completeList.append("Reading");
00054     completeList.append("Meaning");
00055 
00056     //Make connections
00057     connect(ListView, SIGNAL(added(QListWidgetItem*)), this, SLOT(settingChanged()));
00058     connect(ListView, SIGNAL(removed(QListWidgetItem*)), this, SLOT(settingChanged()));
00059     connect(ListView, SIGNAL(movedUp(QListWidgetItem*)), this, SLOT(settingChanged()));
00060     connect(ListView, SIGNAL(movedDown(QListWidgetItem*)), this, SLOT(settingChanged()));
00061 
00062     config = iconfig;
00063     updateWidgets();
00064 }
00065 
00066 dictFileFieldSelector::~dictFileFieldSelector() {}
00067 
00068 void dictFileFieldSelector::setAvailable(const QStringList &list) {
00069     completeList = list;
00070     updateWidgets();
00071 }
00072 
00073 void dictFileFieldSelector::addAvailable(const QStringList &list) {
00074     completeList += list;
00075     updateWidgets();
00076 }
00077 
00078 void dictFileFieldSelector::setDefaultList(const QStringList &list) {
00079     defaultList = list;
00080 }
00081 
00082 void dictFileFieldSelector::updateWidgets() {
00083     readFromPrefs();
00084 }
00085 void dictFileFieldSelector::updateWidgetsDefault() {
00086     
00087 }
00088 
00089 void dictFileFieldSelector::updateSettings() {
00090     writeToPrefs();
00091 }
00092 
00093 void dictFileFieldSelector::settingChanged() {
00094     emit widgetChanged();
00095 }
00096 
00097 void dictFileFieldSelector::readFromPrefs() {
00098     QStringList selectedList;
00099 
00100     config->setCurrentGroup("dicts_"+dictName);
00101 
00102     QStringList actionList = completeList;
00103     QString itemName = dictName + "__displayFields";
00104     KConfigSkeletonItem *item = config->findItem(itemName);
00105     if(item != NULL) {
00106         selectedList = item->property().toStringList();
00107     } else {    //it's not currently in the preferences list
00108         config->addItem(new KConfigSkeleton::ItemStringList(
00109                     "dicts_"+dictName,itemName,*new QStringList()),itemName);
00110         config->readConfig();
00111         selectedList = config->findItem(itemName)->property().toStringList();
00112     }
00113 
00114     foreach( const QString &it, selectedList)
00115         actionList.removeAt(actionList.indexOf(it)); //don't just use remove()... will remove all
00116 
00117     ListView->availableListWidget()->clear();
00118     ListView->selectedListWidget()->clear();
00119     ListView->availableListWidget()->addItems(actionList);
00120     ListView->selectedListWidget()->addItems(selectedList);
00121 }
00122 
00123 void dictFileFieldSelector::writeToPrefs() {
00124     config->setCurrentGroup("dicts_"+dictName);
00125     QStringList theList;
00126     KConfigSkeletonItem *item;
00127     QString itemName;
00128 
00129     for(int i=0; i < ListView->selectedListWidget()->count(); i++)
00130         theList.append(ListView->selectedListWidget()->item(i)->text());
00131 
00132     itemName = dictName+"__displayFields";
00133     item = config->findItem(itemName);
00134     if(!item) {
00135         item = new KConfigSkeleton::ItemStringList("dicts_"+dictName,itemName,*new QStringList());
00136         config->addItem(item,itemName);
00137     }
00138     item->setProperty(theList);
00139 
00140     config->writeConfig();
00141 }
00142 
00143 #include "dictFilePreferenceDialog.moc"

kiten/lib

Skip menu "kiten/lib"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdeedu

Skip menu "kdeedu"
  • kalzium
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  •   docs
  •   src
  • parley
  •   stepcore
Generated for kdeedu by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal