libkdepim Library API Documentation

categoryselectdialog.cpp

00001 /*
00002     This file is part of libkdepim.
00003 
00004     Copyright (c) 2000, 2001, 2002 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019     Boston, MA 02111-1307, USA.
00020 */
00021 
00022 #include <qlistview.h>
00023 #include <qpushbutton.h>
00024 #include <qheader.h>
00025 
00026 #include <libkdepim/categoryselectdialog_base.h>
00027 #include <klocale.h>
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, bool modal )
00036   : KDialogBase::KDialogBase( parent, name, modal,
00037     i18n("Select Categories"), Ok|Apply|Cancel|Help, Ok, true ),
00038     mPrefs( prefs )
00039 {
00040   mWidget = new CategorySelectDialog_base( this, "CategorySelection" );
00041   mWidget->mCategories->header()->hide();
00042   setMainWidget( mWidget );
00043 
00044   setCategories();
00045  
00046   connect( mWidget->mButtonEdit, SIGNAL(clicked()),
00047            SIGNAL(editCategories()) );
00048   connect( mWidget->mButtonClear, SIGNAL(clicked()),
00049            SLOT(clear()) );
00050 }
00051 
00052 void CategorySelectDialog::setCategories()
00053 {
00054   mWidget->mCategories->clear();
00055   mCategoryList.clear();
00056 
00057   QStringList::Iterator it;
00058 
00059   for (it = mPrefs->mCustomCategories.begin();
00060        it != mPrefs->mCustomCategories.end(); ++it ) {
00061     new QCheckListItem( mWidget->mCategories, *it, QCheckListItem::CheckBox );
00062   }
00063 }
00064 
00065 CategorySelectDialog::~CategorySelectDialog()
00066 {
00067 }
00068 
00069 void CategorySelectDialog::setSelected(const QStringList &selList)
00070 {
00071   clear();
00072 
00073   QStringList::ConstIterator it;
00074   for ( it = selList.begin(); it != selList.end(); ++it ) {
00075     QCheckListItem *item = (QCheckListItem *)mWidget->mCategories->firstChild();
00076     while (item) {
00077       if (item->text() == *it) {
00078         item->setOn(true);
00079         break;
00080       }
00081       item = (QCheckListItem *)item->nextSibling();
00082     }
00083   }
00084 }
00085 
00086 QStringList CategorySelectDialog::selectedCategories() const
00087 {
00088   return mCategoryList;
00089 }
00090 
00091 void CategorySelectDialog::slotApply()
00092 {
00093   QStringList categories;
00094   QCheckListItem *item = (QCheckListItem *)mWidget->mCategories->firstChild();
00095   while (item) {
00096     if (item->isOn()) {
00097       categories.append(item->text());
00098     }
00099     item = (QCheckListItem *)item->nextSibling();
00100   }
00101   
00102   QString categoriesStr = categories.join(", ");
00103 
00104   mCategoryList = categories;
00105 
00106   emit categoriesSelected(categories);
00107   emit categoriesSelected(categoriesStr);
00108 }
00109 
00110 void CategorySelectDialog::slotOk()
00111 {
00112   slotApply();
00113   accept();
00114 }
00115 
00116 void CategorySelectDialog::clear()
00117 {
00118   QCheckListItem *item = (QCheckListItem *)mWidget->mCategories->firstChild();
00119   while (item) {
00120     item->setOn(false);
00121     item = (QCheckListItem *)item->nextSibling();
00122   }  
00123 }
00124 
00125 void CategorySelectDialog::updateCategoryConfig()
00126 {
00127   QStringList selected;
00128   QCheckListItem *item = (QCheckListItem *)mWidget->mCategories->firstChild();
00129   while (item) {
00130     if (item->isOn()) {
00131       selected.append(item->text());
00132     }
00133     item = (QCheckListItem *)item->nextSibling();
00134   }
00135 
00136   setCategories();
00137   
00138   setSelected(selected);
00139 }
00140 
00141 #include "categoryselectdialog.moc"
KDE Logo
This file is part of the documentation for libkdepim Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:36:31 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003