libkdepim Library API Documentation

categoryselectdialog.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 <qlistview.h>
00025 #include <qpushbutton.h>
00026 #include <qheader.h>
00027 
00028 #include "categoryselectdialog.h"
00029 
00030 #include "kpimprefs.h"
00031 
00032 using namespace KPIM;
00033 
00034 CategorySelectDialog::CategorySelectDialog( KPimPrefs *prefs, QWidget* parent,
00035                                             const char* name, 
00036                                             bool modal, WFlags fl )
00037   : CategorySelectDialog_base( parent, name, modal, fl ),
00038     mPrefs( prefs )
00039 {
00040   mCategories->header()->hide();
00041 
00042   setCategories();
00043  
00044   connect(mButtonEdit,SIGNAL(clicked()),SIGNAL(editCategories()));
00045 }
00046 
00047 void CategorySelectDialog::setCategories()
00048 {
00049   mCategories->clear();
00050 
00051   QStringList::Iterator it;
00052 
00053   for (it = mPrefs->mCustomCategories.begin();
00054        it != mPrefs->mCustomCategories.end(); ++it ) {
00055     new QCheckListItem(mCategories,*it,QCheckListItem::CheckBox);
00056   }
00057 }
00058 
00059 CategorySelectDialog::~CategorySelectDialog()
00060 {
00061 }
00062 
00063 void CategorySelectDialog::setSelected(const QStringList &selList)
00064 {
00065   clear();
00066 
00067   QStringList::ConstIterator it;
00068   for (it=selList.begin();it!=selList.end();++it) {
00069     QCheckListItem *item = (QCheckListItem *)mCategories->firstChild();
00070     while (item) {
00071       if (item->text() == *it) {
00072         item->setOn(true);
00073         break;
00074       }
00075       item = (QCheckListItem *)item->nextSibling();
00076     }
00077   }
00078 }
00079 
00080 void CategorySelectDialog::slotApply()
00081 {
00082   QStringList categories;
00083   QCheckListItem *item = (QCheckListItem *)mCategories->firstChild();
00084   while (item) {
00085     if (item->isOn()) {
00086       categories.append(item->text());
00087     }
00088     item = (QCheckListItem *)item->nextSibling();
00089   }
00090   
00091   QString categoriesStr = categories.join(", ");
00092 
00093   emit categoriesSelected(categories);
00094   emit categoriesSelected(categoriesStr);
00095 }
00096 
00097 void CategorySelectDialog::slotOk()
00098 {
00099   slotApply();
00100   accept();
00101 }
00102 
00103 void CategorySelectDialog::clear()
00104 {
00105   QCheckListItem *item = (QCheckListItem *)mCategories->firstChild();
00106   while (item) {
00107     item->setOn(false);
00108     item = (QCheckListItem *)item->nextSibling();
00109   }  
00110 }
00111 
00112 void CategorySelectDialog::updateCategoryConfig()
00113 {
00114   QStringList selected;
00115   QCheckListItem *item = (QCheckListItem *)mCategories->firstChild();
00116   while (item) {
00117     if (item->isOn()) {
00118       selected.append(item->text());
00119     }
00120     item = (QCheckListItem *)item->nextSibling();
00121   }
00122 
00123   setCategories();
00124   
00125   setSelected(selected);
00126 }
00127 
00128 #include "categoryselectdialog.moc"
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:00 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001