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( const QStringList &categoryList ) 00053 { 00054 mWidget->mCategories->clear(); 00055 mCategoryList.clear(); 00056 00057 QStringList::ConstIterator it; 00058 00059 for ( it = categoryList.begin(); it != categoryList.end(); ++it ) 00060 if ( mPrefs->mCustomCategories.find( *it ) == mPrefs->mCustomCategories.end() ) 00061 mPrefs->mCustomCategories.append( *it ); 00062 00063 for ( it = mPrefs->mCustomCategories.begin(); 00064 it != mPrefs->mCustomCategories.end(); ++it ) { 00065 new QCheckListItem( mWidget->mCategories, *it, QCheckListItem::CheckBox ); 00066 } 00067 } 00068 00069 CategorySelectDialog::~CategorySelectDialog() 00070 { 00071 } 00072 00073 void CategorySelectDialog::setSelected(const QStringList &selList) 00074 { 00075 clear(); 00076 00077 QStringList::ConstIterator it; 00078 for ( it = selList.begin(); it != selList.end(); ++it ) { 00079 QCheckListItem *item = (QCheckListItem *)mWidget->mCategories->firstChild(); 00080 while (item) { 00081 if (item->text() == *it) { 00082 item->setOn(true); 00083 break; 00084 } 00085 item = (QCheckListItem *)item->nextSibling(); 00086 } 00087 } 00088 } 00089 00090 QStringList CategorySelectDialog::selectedCategories() const 00091 { 00092 return mCategoryList; 00093 } 00094 00095 void CategorySelectDialog::slotApply() 00096 { 00097 QStringList categories; 00098 QCheckListItem *item = (QCheckListItem *)mWidget->mCategories->firstChild(); 00099 while (item) { 00100 if (item->isOn()) { 00101 categories.append(item->text()); 00102 } 00103 item = (QCheckListItem *)item->nextSibling(); 00104 } 00105 00106 QString categoriesStr = categories.join(", "); 00107 00108 mCategoryList = categories; 00109 00110 emit categoriesSelected(categories); 00111 emit categoriesSelected(categoriesStr); 00112 } 00113 00114 void CategorySelectDialog::slotOk() 00115 { 00116 slotApply(); 00117 accept(); 00118 } 00119 00120 void CategorySelectDialog::clear() 00121 { 00122 QCheckListItem *item = (QCheckListItem *)mWidget->mCategories->firstChild(); 00123 while (item) { 00124 item->setOn(false); 00125 item = (QCheckListItem *)item->nextSibling(); 00126 } 00127 } 00128 00129 void CategorySelectDialog::updateCategoryConfig() 00130 { 00131 QStringList selected; 00132 QCheckListItem *item = (QCheckListItem *)mWidget->mCategories->firstChild(); 00133 while (item) { 00134 if (item->isOn()) { 00135 selected.append(item->text()); 00136 } 00137 item = (QCheckListItem *)item->nextSibling(); 00138 } 00139 00140 setCategories(); 00141 00142 setSelected(selected); 00143 } 00144 00145 #include "categoryselectdialog.moc"
KDE Logo
This file is part of the documentation for libkdepim Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:50:23 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003