libkdepim Library API Documentation

categoryeditdialog.cpp

00001 /*
00002     This file is part of libkdepim.
00003     Copyright (c) 2000, 2001, 2002 Cornelius Schumacher <schumacher@kde.org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 
00024 #include <qstringlist.h>
00025 #include <qlineedit.h>
00026 #include <qlistview.h>
00027 #include <qheader.h>
00028 #include <qpushbutton.h>
00029 
00030 #include "kpimprefs.h"
00031 
00032 #include "categoryeditdialog.h"
00033 
00034 using namespace KPIM;
00035 
00036 CategoryEditDialog::CategoryEditDialog( KPimPrefs *prefs, QWidget* parent,
00037                                         const char* name, bool modal,
00038                                         WFlags fl )
00039   : CategoryEditDialog_base( parent, name, modal, fl ),
00040     mPrefs( prefs )  
00041 {
00042   mCategories->header()->hide();
00043 
00044   QStringList::Iterator it;
00045   bool categoriesExist=false;
00046   for (it = mPrefs->mCustomCategories.begin();
00047        it != mPrefs->mCustomCategories.end(); ++it ) {
00048     new QListViewItem(mCategories,*it);
00049     categoriesExist=true;
00050   }
00051 
00052   connect(mCategories,SIGNAL(selectionChanged(QListViewItem *)),
00053           SLOT(editItem(QListViewItem *)));
00054   connect(mEdit,SIGNAL(textChanged ( const QString & )),this,SLOT(slotTextChanged(const QString &)));
00055   mButtonRemove->setEnabled(categoriesExist);
00056   mButtonModify->setEnabled(categoriesExist);
00057   mButtonAdd->setEnabled(!mEdit->text().isEmpty());
00058 }
00059 
00060 /*
00061  *  Destroys the object and frees any allocated resources
00062  */
00063 CategoryEditDialog::~CategoryEditDialog()
00064 {
00065     // no need to delete child widgets, Qt does it all for us
00066 }
00067 
00068 void CategoryEditDialog::slotTextChanged(const QString &text)
00069 {
00070     mButtonAdd->setEnabled(!text.isEmpty());
00071 }
00072 
00073 void CategoryEditDialog::add()
00074 {
00075   if (!mEdit->text().isEmpty()) {
00076     new QListViewItem(mCategories,mEdit->text());
00077     mEdit->setText("");
00078     mButtonRemove->setEnabled(mCategories->childCount()>0);
00079     mButtonModify->setEnabled(mCategories->childCount()>0);
00080   }
00081 }
00082 
00083 void CategoryEditDialog::remove()
00084 {
00085   if (mCategories->currentItem()) {
00086     delete mCategories->currentItem();
00087     mButtonRemove->setEnabled(mCategories->childCount()>0);
00088     mButtonModify->setEnabled(mCategories->childCount()>0);
00089   }
00090 }
00091 
00092 void CategoryEditDialog::modify()
00093 {
00094   if (!mEdit->text().isEmpty()) {
00095     if (mCategories->currentItem()) {
00096       mCategories->currentItem()->setText(0,mEdit->text());
00097     }
00098   }
00099 }
00100 
00101 void CategoryEditDialog::slotOk()
00102 {
00103   slotApply();
00104   accept();
00105 }
00106 
00107 void CategoryEditDialog::slotApply()
00108 {
00109   mPrefs->mCustomCategories.clear();
00110 
00111   QListViewItem *item = mCategories->firstChild();
00112   while(item) {
00113     mPrefs->mCustomCategories.append(item->text(0));
00114     item = item->nextSibling();
00115   }
00116   mPrefs->writeConfig();
00117 
00118   emit categoryConfigChanged();
00119 }
00120 
00121 void CategoryEditDialog::editItem(QListViewItem *item)
00122 {
00123   mEdit->setText(item->text(0));
00124   mButtonRemove->setEnabled(true);
00125   mButtonModify->setEnabled(true);
00126 }
00127 
00128 #include "categoryeditdialog.moc"
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:22 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001