libtdepim

categoryselectdialog.cpp
1/*
2 This file is part of libtdepim.
3
4 Copyright (c) 2000, 2001, 2002 Cornelius Schumacher <schumacher@kde.org>
5 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21*/
22
23#include <tqlistview.h>
24#include <tqpushbutton.h>
25#include <tqheader.h>
26
27#include "categoryselectdialog_base.h"
28#include <tdelocale.h>
29#include "categoryselectdialog.h"
30
31#include "kpimprefs.h"
32
33using namespace KPIM;
34
35CategorySelectDialog::CategorySelectDialog( KPimPrefs *prefs, TQWidget* parent,
36 const char* name, bool modal )
37 : KDialogBase::KDialogBase( parent, name, modal,
38 i18n("Select Categories"), Ok|Apply|Cancel|Help, Ok, true ),
39 mPrefs( prefs )
40{
41 mWidget = new CategorySelectDialog_base( this, "CategorySelection" );
42 mWidget->mCategories->header()->hide();
43 setMainWidget( mWidget );
44
45 setCategories();
46
47 connect( mWidget->mButtonEdit, TQ_SIGNAL(clicked()),
48 TQ_SIGNAL(editCategories()) );
49 connect( mWidget->mButtonClear, TQ_SIGNAL(clicked()),
50 TQ_SLOT(clear()) );
51}
52
53void CategorySelectDialog::setCategories( const TQStringList &categoryList )
54{
55 mWidget->mCategories->clear();
56 mCategoryList.clear();
57
58 TQStringList::ConstIterator it;
59
60 for ( it = categoryList.begin(); it != categoryList.end(); ++it )
61 if ( mPrefs->mCustomCategories.find( *it ) == mPrefs->mCustomCategories.end() )
62 mPrefs->mCustomCategories.append( *it );
63
64 for ( it = mPrefs->mCustomCategories.begin();
65 it != mPrefs->mCustomCategories.end(); ++it ) {
66 new TQCheckListItem( mWidget->mCategories, *it, TQCheckListItem::CheckBox );
67 }
68}
69
70CategorySelectDialog::~CategorySelectDialog()
71{
72}
73
74void CategorySelectDialog::setSelected(const TQStringList &selList)
75{
76 clear();
77
78 TQStringList::ConstIterator it;
79 for ( it = selList.begin(); it != selList.end(); ++it ) {
80 TQCheckListItem *item = (TQCheckListItem *)mWidget->mCategories->firstChild();
81 while (item) {
82 if (item->text() == *it) {
83 item->setOn(true);
84 break;
85 }
86 item = (TQCheckListItem *)item->nextSibling();
87 }
88 }
89}
90
91TQStringList CategorySelectDialog::selectedCategories() const
92{
93 return mCategoryList;
94}
95
96void CategorySelectDialog::slotApply()
97{
98 TQStringList categories;
99 TQCheckListItem *item = (TQCheckListItem *)mWidget->mCategories->firstChild();
100 while (item) {
101 if (item->isOn()) {
102 categories.append(item->text());
103 }
104 item = (TQCheckListItem *)item->nextSibling();
105 }
106
107 TQString categoriesStr = categories.join(", ");
108
109 mCategoryList = categories;
110
111 emit categoriesSelected(categories);
112 emit categoriesSelected(categoriesStr);
113}
114
115void CategorySelectDialog::slotOk()
116{
117 slotApply();
118 accept();
119}
120
121void CategorySelectDialog::clear()
122{
123 TQCheckListItem *item = (TQCheckListItem *)mWidget->mCategories->firstChild();
124 while (item) {
125 item->setOn(false);
126 item = (TQCheckListItem *)item->nextSibling();
127 }
128}
129
130void CategorySelectDialog::updateCategoryConfig()
131{
132 TQStringList selected;
133 TQCheckListItem *item = (TQCheckListItem *)mWidget->mCategories->firstChild();
134 while (item) {
135 if (item->isOn()) {
136 selected.append(item->text());
137 }
138 item = (TQCheckListItem *)item->nextSibling();
139 }
140
141 setCategories();
142
143 setSelected(selected);
144}
145
146#include "categoryselectdialog.moc"
TDEPIM classes for drag and drop of mails.