Diffstat (limited to 'libkdepim/categoryeditdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libkdepim/categoryeditdialog.cpp | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/libkdepim/categoryeditdialog.cpp b/libkdepim/categoryeditdialog.cpp new file mode 100644 index 0000000..87172c1 --- a/dev/null +++ b/libkdepim/categoryeditdialog.cpp | |||
@@ -0,0 +1,135 @@ | |||
1 | /* | ||
2 | This file is part of libkdepim. | ||
3 | Copyright (c) 2000, 2001, 2002 Cornelius Schumacher <schumacher@kde.org> | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software | ||
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
18 | |||
19 | As a special exception, permission is given to link this program | ||
20 | with any edition of Qt, and distribute the resulting executable, | ||
21 | without including the source code for Qt in the source distribution. | ||
22 | */ | ||
23 | |||
24 | #include <qstringlist.h> | ||
25 | #include <qlineedit.h> | ||
26 | #include <qlistview.h> | ||
27 | #include <qheader.h> | ||
28 | #include <qpushbutton.h> | ||
29 | #include <qapplication.h> | ||
30 | |||
31 | #include "kpimprefs.h" | ||
32 | |||
33 | #include "categoryeditdialog.h" | ||
34 | |||
35 | using namespace KPIM; | ||
36 | |||
37 | CategoryEditDialog::CategoryEditDialog( KPimPrefs *prefs, QWidget* parent, | ||
38 | const char* name, bool modal, | ||
39 | WFlags fl ) | ||
40 | : CategoryEditDialog_base( parent, name, modal, fl ), | ||
41 | mPrefs( prefs ) | ||
42 | { | ||
43 | mCategories->header()->hide(); | ||
44 | |||
45 | QStringList::Iterator it; | ||
46 | bool categoriesExist=false; | ||
47 | for (it = mPrefs->mCustomCategories.begin(); | ||
48 | it != mPrefs->mCustomCategories.end(); ++it ) { | ||
49 | new QListViewItem(mCategories,*it); | ||
50 | categoriesExist=true; | ||
51 | } | ||
52 | |||
53 | connect(mCategories,SIGNAL(selectionChanged(QListViewItem *)), | ||
54 | SLOT(editItem(QListViewItem *))); | ||
55 | connect(mEdit,SIGNAL(textChanged ( const QString & )),this,SLOT(slotTextChanged(const QString &))); | ||
56 | mButtonRemove->setEnabled(categoriesExist); | ||
57 | mButtonModify->setEnabled(categoriesExist); | ||
58 | mButtonAdd->setEnabled(!mEdit->text().isEmpty()); | ||
59 | if ( QApplication::desktop()->width() > 460 ) | ||
60 | resize( 300, 360 ); | ||
61 | } | ||
62 | |||
63 | /* | ||
64 | * Destroys the object and frees any allocated resources | ||
65 | */ | ||
66 | CategoryEditDialog::~CategoryEditDialog() | ||
67 | { | ||
68 | // no need to delete child widgets, Qt does it all for us | ||
69 | } | ||
70 | |||
71 | void CategoryEditDialog::slotTextChanged(const QString &text) | ||
72 | { | ||
73 | mButtonAdd->setEnabled(!text.isEmpty()); | ||
74 | } | ||
75 | |||
76 | void CategoryEditDialog::add() | ||
77 | { | ||
78 | if (!mEdit->text().isEmpty()) { | ||
79 | new QListViewItem(mCategories,mEdit->text()); | ||
80 | mEdit->setText(""); | ||
81 | mButtonRemove->setEnabled(mCategories->childCount()>0); | ||
82 | mButtonModify->setEnabled(mCategories->childCount()>0); | ||
83 | } | ||
84 | } | ||
85 | |||
86 | void CategoryEditDialog::remove() | ||
87 | { | ||
88 | if (mCategories->currentItem()) { | ||
89 | delete mCategories->currentItem(); | ||
90 | mButtonRemove->setEnabled(mCategories->childCount()>0); | ||
91 | mButtonModify->setEnabled(mCategories->childCount()>0); | ||
92 | } | ||
93 | } | ||
94 | |||
95 | void CategoryEditDialog::modify() | ||
96 | { | ||
97 | if (!mEdit->text().isEmpty()) { | ||
98 | if (mCategories->currentItem()) { | ||
99 | mCategories->currentItem()->setText(0,mEdit->text()); | ||
100 | } | ||
101 | } | ||
102 | } | ||
103 | void CategoryEditDialog::accept() | ||
104 | { | ||
105 | slotOk(); | ||
106 | } | ||
107 | |||
108 | void CategoryEditDialog::slotOk() | ||
109 | { | ||
110 | slotApply(); | ||
111 | QDialog::accept(); | ||
112 | } | ||
113 | |||
114 | void CategoryEditDialog::slotApply() | ||
115 | { | ||
116 | mPrefs->mCustomCategories.clear(); | ||
117 | |||
118 | QListViewItem *item = mCategories->firstChild(); | ||
119 | while(item) { | ||
120 | mPrefs->mCustomCategories.append(item->text(0)); | ||
121 | item = item->nextSibling(); | ||
122 | } | ||
123 | mPrefs->writeConfig(); | ||
124 | |||
125 | emit categoryConfigChanged(); | ||
126 | } | ||
127 | |||
128 | void CategoryEditDialog::editItem(QListViewItem *item) | ||
129 | { | ||
130 | mEdit->setText(item->text(0)); | ||
131 | mButtonRemove->setEnabled(true); | ||
132 | mButtonModify->setEnabled(true); | ||
133 | } | ||
134 | |||
135 | #include "categoryeditdialog.moc" | ||