categoryselectdialog.cpp
00001 /* 00002 This file is part of libkdepim. 00003 00004 Copyright (c) 2000, 2001, 2002 Cornelius Schumacher <schumacher@kde.org> 00005 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #include <tqlistview.h> 00024 #include <tqpushbutton.h> 00025 #include <tqheader.h> 00026 00027 #include "categoryselectdialog_base.h" 00028 #include <klocale.h> 00029 #include "categoryselectdialog.h" 00030 00031 #include "kpimprefs.h" 00032 00033 using namespace KPIM; 00034 00035 CategorySelectDialog::CategorySelectDialog( KPimPrefs *prefs, TQWidget* parent, 00036 const char* name, bool modal ) 00037 : KDialogBase::KDialogBase( parent, name, modal, 00038 i18n("Select Categories"), Ok|Apply|Cancel|Help, Ok, true ), 00039 mPrefs( prefs ) 00040 { 00041 mWidget = new CategorySelectDialog_base( this, "CategorySelection" ); 00042 mWidget->mCategories->header()->hide(); 00043 setMainWidget( mWidget ); 00044 00045 setCategories(); 00046 00047 connect( mWidget->mButtonEdit, TQT_SIGNAL(clicked()), 00048 TQT_SIGNAL(editCategories()) ); 00049 connect( mWidget->mButtonClear, TQT_SIGNAL(clicked()), 00050 TQT_SLOT(clear()) ); 00051 } 00052 00053 void CategorySelectDialog::setCategories( const TQStringList &categoryList ) 00054 { 00055 mWidget->mCategories->clear(); 00056 mCategoryList.clear(); 00057 00058 TQStringList::ConstIterator it; 00059 00060 for ( it = categoryList.begin(); it != categoryList.end(); ++it ) 00061 if ( mPrefs->mCustomCategories.find( *it ) == mPrefs->mCustomCategories.end() ) 00062 mPrefs->mCustomCategories.append( *it ); 00063 00064 for ( it = mPrefs->mCustomCategories.begin(); 00065 it != mPrefs->mCustomCategories.end(); ++it ) { 00066 new TQCheckListItem( mWidget->mCategories, *it, TQCheckListItem::CheckBox ); 00067 } 00068 } 00069 00070 CategorySelectDialog::~CategorySelectDialog() 00071 { 00072 } 00073 00074 void CategorySelectDialog::setSelected(const TQStringList &selList) 00075 { 00076 clear(); 00077 00078 TQStringList::ConstIterator it; 00079 for ( it = selList.begin(); it != selList.end(); ++it ) { 00080 TQCheckListItem *item = (TQCheckListItem *)mWidget->mCategories->firstChild(); 00081 while (item) { 00082 if (item->text() == *it) { 00083 item->setOn(true); 00084 break; 00085 } 00086 item = (TQCheckListItem *)item->nextSibling(); 00087 } 00088 } 00089 } 00090 00091 TQStringList CategorySelectDialog::selectedCategories() const 00092 { 00093 return mCategoryList; 00094 } 00095 00096 void CategorySelectDialog::slotApply() 00097 { 00098 TQStringList categories; 00099 TQCheckListItem *item = (TQCheckListItem *)mWidget->mCategories->firstChild(); 00100 while (item) { 00101 if (item->isOn()) { 00102 categories.append(item->text()); 00103 } 00104 item = (TQCheckListItem *)item->nextSibling(); 00105 } 00106 00107 TQString categoriesStr = categories.join(", "); 00108 00109 mCategoryList = categories; 00110 00111 emit categoriesSelected(categories); 00112 emit categoriesSelected(categoriesStr); 00113 } 00114 00115 void CategorySelectDialog::slotOk() 00116 { 00117 slotApply(); 00118 accept(); 00119 } 00120 00121 void CategorySelectDialog::clear() 00122 { 00123 TQCheckListItem *item = (TQCheckListItem *)mWidget->mCategories->firstChild(); 00124 while (item) { 00125 item->setOn(false); 00126 item = (TQCheckListItem *)item->nextSibling(); 00127 } 00128 } 00129 00130 void CategorySelectDialog::updateCategoryConfig() 00131 { 00132 TQStringList selected; 00133 TQCheckListItem *item = (TQCheckListItem *)mWidget->mCategories->firstChild(); 00134 while (item) { 00135 if (item->isOn()) { 00136 selected.append(item->text()); 00137 } 00138 item = (TQCheckListItem *)item->nextSibling(); 00139 } 00140 00141 setCategories(); 00142 00143 setSelected(selected); 00144 } 00145 00146 #include "categoryselectdialog.moc"