summaryrefslogtreecommitdiffabout
path: root/libkdepim/categoryselectdialog.cpp
Unidiff
Diffstat (limited to 'libkdepim/categoryselectdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/categoryselectdialog.cpp173
1 files changed, 173 insertions, 0 deletions
diff --git a/libkdepim/categoryselectdialog.cpp b/libkdepim/categoryselectdialog.cpp
new file mode 100644
index 0000000..7b0aced
--- a/dev/null
+++ b/libkdepim/categoryselectdialog.cpp
@@ -0,0 +1,173 @@
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 <qlistview.h>
25#include <qpushbutton.h>
26#include <qheader.h>
27#include <qapp.h>
28#include <qmessagebox.h>
29
30
31#include <libkdepim/categoryeditdialog.h>
32#include "categoryselectdialog.h"
33
34#include "kpimprefs.h"
35
36using namespace KPIM;
37
38CategorySelectDialog::CategorySelectDialog( KPimPrefs *prefs, QWidget* parent,
39 const char* name,
40 bool modal, WFlags fl )
41 : CategorySelectDialog_base( parent, name, true, fl ),
42 mPrefs( prefs )
43{
44 mCategories->header()->hide();
45
46 setCategories();
47
48 connect(mButtonEdit,SIGNAL(clicked()),this, SLOT(editCategoriesDialog()));
49 if ( qApp->desktop()->height() < 321 )
50 setMaximumHeight( QApplication::desktop()->height() - 50 );
51 else
52 setMaximumHeight( QApplication::desktop()->height() - 80 );
53 if ( QApplication::desktop()->width() > 460 )
54 resize( 260, 360 );
55}
56void CategorySelectDialog::editCategoriesDialog()
57{
58 KPIM::CategoryEditDialog* ced = new KPIM::CategoryEditDialog(mPrefs,this );
59
60 ced->exec();
61 delete ced;
62 setCategories();
63}
64void CategorySelectDialog::setCategories()
65{
66 mCategories->clear();
67 mCategoryList.clear();
68
69 QStringList::Iterator it;
70
71 for (it = mPrefs->mCustomCategories.begin();
72 it != mPrefs->mCustomCategories.end(); ++it ) {
73 new QCheckListItem(mCategories,*it,QCheckListItem::CheckBox);
74 }
75}
76
77CategorySelectDialog::~CategorySelectDialog()
78{
79}
80
81void CategorySelectDialog::setSelected(const QStringList &selList)
82{
83 clear();
84
85 QStringList::ConstIterator it;
86 QStringList notFound;
87 bool found = false;
88 for (it=selList.begin();it!=selList.end();++it) {
89 //qDebug(" CategorySelectDialog::setSelected(");
90 QCheckListItem *item = (QCheckListItem *)mCategories->firstChild();
91 while (item) {
92 if (item->text() == *it) {
93 item->setOn(true);
94 found = true;
95 break;
96 }
97 item = (QCheckListItem *)item->nextSibling();
98 }
99// if ( ! found ) {
100
101//emit updateCategoriesGlobal();
102// QMessageBox::information( this, "KO/E: Information!",
103// "Categories found, which were not\n"
104// "in list of categories!\n"
105// "message",
106// "OK", "", 0,
107// 0, 1 );
108// setSelected(selList);
109// return;
110// }
111 }
112}
113
114QStringList CategorySelectDialog::selectedCategories() const
115{
116 return mCategoryList;
117}
118
119void CategorySelectDialog::slotApply()
120{
121 QStringList categories;
122 QCheckListItem *item = (QCheckListItem *)mCategories->firstChild();
123 while (item) {
124 if (item->isOn()) {
125 categories.append(item->text());
126 }
127 item = (QCheckListItem *)item->nextSibling();
128 }
129
130 QString categoriesStr = categories.join(",");
131
132 mCategoryList = categories;
133
134 emit categoriesSelected(categories);
135 emit categoriesSelected(categoriesStr);
136}
137void CategorySelectDialog::accept()
138{
139 slotOk();
140}
141
142void CategorySelectDialog::slotOk()
143{
144 slotApply();
145 QDialog::accept();
146}
147
148void CategorySelectDialog::clear()
149{
150 QCheckListItem *item = (QCheckListItem *)mCategories->firstChild();
151 while (item) {
152 item->setOn(false);
153 item = (QCheckListItem *)item->nextSibling();
154 }
155}
156
157void CategorySelectDialog::updateCategoryConfig()
158{
159 QStringList selected;
160 QCheckListItem *item = (QCheckListItem *)mCategories->firstChild();
161 while (item) {
162 if (item->isOn()) {
163 selected.append(item->text());
164 }
165 item = (QCheckListItem *)item->nextSibling();
166 }
167
168 setCategories();
169
170 setSelected(selected);
171}
172
173#include "categoryselectdialog.moc"