Build, if that was not necessary blame cartman who told me "sure" :-D
[kdepim.git] / libkdepim / categoryeditdialog.cpp
blobcd2aa52275e329c1482307b29351aaa2286272ff
1 /*
2 This file is part of libkdepim.
4 Copyright (c) 2000, 2001, 2002 Cornelius Schumacher <schumacher@kde.org>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
22 #include <qstringlist.h>
23 #include <qlineedit.h>
24 #include <qlistview.h>
25 #include <qheader.h>
26 #include <qpushbutton.h>
27 #include <klocale.h>
29 #include "kpimprefs.h"
31 #include "categoryeditdialog_base.h"
32 #include "categoryeditdialog.h"
34 using namespace KPIM;
36 CategoryEditDialog::CategoryEditDialog( KPimPrefs *prefs, QWidget* parent,
37 const char* name, bool modal )
38 : KDialogBase::KDialogBase( parent, name, modal,
39 i18n("Edit Categories"), Ok|Apply|Cancel|Help, Ok, true ),
40 mPrefs( prefs )
42 mWidget = new CategoryEditDialog_base( this, "CategoryEdit" );
43 mWidget->mCategories->header()->hide();
44 setMainWidget( mWidget );
46 QStringList::Iterator it;
47 bool categoriesExist=false;
48 for ( it = mPrefs->mCustomCategories.begin();
49 it != mPrefs->mCustomCategories.end(); ++it ) {
50 new QListViewItem( mWidget->mCategories, *it );
51 categoriesExist = true;
54 connect( mWidget->mCategories, SIGNAL( selectionChanged( QListViewItem * )),
55 SLOT( editItem( QListViewItem * )) );
56 connect( mWidget->mEdit, SIGNAL( textChanged( const QString & )),
57 this, SLOT( slotTextChanged( const QString & )));
58 connect( mWidget->mButtonAdd, SIGNAL( clicked() ),
59 this, SLOT( add() ) );
60 connect( mWidget->mButtonModify, SIGNAL( clicked() ),
61 this, SLOT( modify() ) );
62 connect( mWidget->mButtonRemove, SIGNAL( clicked() ),
63 this, SLOT( remove() ) );
65 mWidget->mButtonRemove->setEnabled( categoriesExist );
66 mWidget->mButtonModify->setEnabled( categoriesExist );
67 mWidget->mButtonAdd->setEnabled( !mWidget->mEdit->text().isEmpty() );
71 * Destroys the object and frees any allocated resources
73 CategoryEditDialog::~CategoryEditDialog()
75 // no need to delete child widgets, Qt does it all for us
78 void CategoryEditDialog::slotTextChanged(const QString &text)
80 mWidget->mButtonAdd->setEnabled( !text.isEmpty() );
83 void CategoryEditDialog::add()
85 if ( !mWidget->mEdit->text().isEmpty() ) {
86 new QListViewItem( mWidget->mCategories, mWidget->mEdit->text() );
87 mWidget->mEdit->setText("");
88 mWidget->mButtonRemove->setEnabled( mWidget->mCategories->childCount()>0 );
89 mWidget->mButtonModify->setEnabled( mWidget->mCategories->childCount()>0 );
93 void CategoryEditDialog::remove()
95 if (mWidget->mCategories->currentItem()) {
96 delete mWidget->mCategories->currentItem();
97 mWidget->mButtonRemove->setEnabled( mWidget->mCategories->childCount()>0 );
98 mWidget->mButtonModify->setEnabled( mWidget->mCategories->childCount()>0 );
102 void CategoryEditDialog::modify()
104 if ( !mWidget->mEdit->text().isEmpty() ) {
105 if ( mWidget->mCategories->currentItem() ) {
106 mWidget->mCategories->currentItem()->setText( 0, mWidget->mEdit->text() );
111 void CategoryEditDialog::slotOk()
113 slotApply();
114 accept();
117 void CategoryEditDialog::slotApply()
119 mPrefs->mCustomCategories.clear();
121 QListViewItem *item = mWidget->mCategories->firstChild();
122 while ( item ) {
123 mPrefs->mCustomCategories.append( item->text(0) );
124 item = item->nextSibling();
126 mPrefs->writeConfig();
128 emit categoryConfigChanged();
131 void CategoryEditDialog::editItem( QListViewItem *item )
133 mWidget->mEdit->setText( item->text(0) );
134 mWidget->mButtonRemove->setEnabled( true );
135 mWidget->mButtonModify->setEnabled( true );
138 void CategoryEditDialog::reload()
140 QStringList::Iterator it;
141 mWidget->mCategories->clear();
142 for ( it = mPrefs->mCustomCategories.begin();
143 it != mPrefs->mCustomCategories.end(); ++it ) {
144 new QListViewItem( mWidget->mCategories, *it );
148 #include "categoryeditdialog.moc"