libkdepim Library API Documentation

categoryeditdialog.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 <qstringlist.h> 00023 #include <qlineedit.h> 00024 #include <qlistview.h> 00025 #include <qheader.h> 00026 #include <qpushbutton.h> 00027 #include <klocale.h> 00028 00029 #include "kpimprefs.h" 00030 00031 #include "categoryeditdialog_base.h" 00032 #include "categoryeditdialog.h" 00033 00034 using namespace KPIM; 00035 00036 CategoryEditDialog::CategoryEditDialog( KPimPrefs *prefs, QWidget* parent, 00037 const char* name, bool modal ) 00038 : KDialogBase::KDialogBase( parent, name, modal, 00039 i18n("Edit Categories"), Ok|Apply|Cancel|Help, Ok, true ), 00040 mPrefs( prefs ) 00041 { 00042 mWidget = new CategoryEditDialog_base( this, "CategoryEdit" ); 00043 mWidget->mCategories->header()->hide(); 00044 setMainWidget( mWidget ); 00045 00046 QStringList::Iterator it; 00047 bool categoriesExist=false; 00048 for ( it = mPrefs->mCustomCategories.begin(); 00049 it != mPrefs->mCustomCategories.end(); ++it ) { 00050 new QListViewItem( mWidget->mCategories, *it ); 00051 categoriesExist = true; 00052 } 00053 00054 connect( mWidget->mCategories, SIGNAL( selectionChanged( QListViewItem * )), 00055 SLOT( editItem( QListViewItem * )) ); 00056 connect( mWidget->mEdit, SIGNAL( textChanged( const QString & )), 00057 this, SLOT( slotTextChanged( const QString & ))); 00058 connect( mWidget->mButtonAdd, SIGNAL( clicked() ), 00059 this, SLOT( add() ) ); 00060 connect( mWidget->mButtonModify, SIGNAL( clicked() ), 00061 this, SLOT( modify() ) ); 00062 connect( mWidget->mButtonRemove, SIGNAL( clicked() ), 00063 this, SLOT( remove() ) ); 00064 00065 mWidget->mButtonRemove->setEnabled( categoriesExist ); 00066 mWidget->mButtonModify->setEnabled( categoriesExist ); 00067 mWidget->mButtonAdd->setEnabled( !mWidget->mEdit->text().isEmpty() ); 00068 } 00069 00070 /* 00071 * Destroys the object and frees any allocated resources 00072 */ 00073 CategoryEditDialog::~CategoryEditDialog() 00074 { 00075 // no need to delete child widgets, Qt does it all for us 00076 } 00077 00078 void CategoryEditDialog::slotTextChanged(const QString &text) 00079 { 00080 mWidget->mButtonAdd->setEnabled( !text.isEmpty() ); 00081 } 00082 00083 void CategoryEditDialog::add() 00084 { 00085 if ( !mWidget->mEdit->text().isEmpty() ) { 00086 new QListViewItem( mWidget->mCategories, mWidget->mEdit->text() ); 00087 mWidget->mEdit->setText(""); 00088 mWidget->mButtonRemove->setEnabled( mWidget->mCategories->childCount()>0 ); 00089 mWidget->mButtonModify->setEnabled( mWidget->mCategories->childCount()>0 ); 00090 } 00091 } 00092 00093 void CategoryEditDialog::remove() 00094 { 00095 if (mWidget->mCategories->currentItem()) { 00096 delete mWidget->mCategories->currentItem(); 00097 mWidget->mButtonRemove->setEnabled( mWidget->mCategories->childCount()>0 ); 00098 mWidget->mButtonModify->setEnabled( mWidget->mCategories->childCount()>0 ); 00099 } 00100 } 00101 00102 void CategoryEditDialog::modify() 00103 { 00104 if ( !mWidget->mEdit->text().isEmpty() ) { 00105 if ( mWidget->mCategories->currentItem() ) { 00106 mWidget->mCategories->currentItem()->setText( 0, mWidget->mEdit->text() ); 00107 } 00108 } 00109 } 00110 00111 void CategoryEditDialog::slotOk() 00112 { 00113 slotApply(); 00114 accept(); 00115 } 00116 00117 void CategoryEditDialog::slotApply() 00118 { 00119 mPrefs->mCustomCategories.clear(); 00120 00121 QListViewItem *item = mWidget->mCategories->firstChild(); 00122 while ( item ) { 00123 mPrefs->mCustomCategories.append( item->text(0) ); 00124 item = item->nextSibling(); 00125 } 00126 mPrefs->writeConfig(); 00127 00128 emit categoryConfigChanged(); 00129 } 00130 00131 void CategoryEditDialog::editItem( QListViewItem *item ) 00132 { 00133 mWidget->mEdit->setText( item->text(0) ); 00134 mWidget->mButtonRemove->setEnabled( true ); 00135 mWidget->mButtonModify->setEnabled( true ); 00136 } 00137 00138 #include "categoryeditdialog.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 Wed Jul 28 23:57:46 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003