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 
33 using namespace KPIM;
34 
35 CategorySelectDialog::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, TQT_SIGNAL(clicked()),
48  TQT_SIGNAL(editCategories()) );
49  connect( mWidget->mButtonClear, TQT_SIGNAL(clicked()),
50  TQT_SLOT(clear()) );
51 
52  mPrefs->toNotify = this;
53 }
54 
55 void CategorySelectDialog::setCategories( const TQStringList &categoryList )
56 {
57  mWidget->mCategories->clear();
58  mCategoryList.clear();
59 
60  TQStringList::ConstIterator it;
61 
62  for ( it = categoryList.begin(); it != categoryList.end(); ++it )
63  if ( mPrefs->mCustomCategories.find( *it ) == mPrefs->mCustomCategories.end() )
64  mPrefs->mCustomCategories.append( *it );
65 
66  for ( it = mPrefs->mCustomCategories.begin();
67  it != mPrefs->mCustomCategories.end(); ++it ) {
68  new TQCheckListItem( mWidget->mCategories, *it, TQCheckListItem::CheckBox );
69  }
70 }
71 
72 CategorySelectDialog::~CategorySelectDialog()
73 {
74  mPrefs->toNotify = NULL;
75 }
76 
77 void CategorySelectDialog::setSelected(const TQStringList &selList)
78 {
79  clear();
80 
81  TQStringList::ConstIterator it;
82  for ( it = selList.begin(); it != selList.end(); ++it ) {
83  TQCheckListItem *item = (TQCheckListItem *)mWidget->mCategories->firstChild();
84  while (item) {
85  if (item->text() == *it) {
86  item->setOn(true);
87  break;
88  }
89  item = (TQCheckListItem *)item->nextSibling();
90  }
91  }
92 }
93 
94 TQStringList CategorySelectDialog::selectedCategories() const
95 {
96  return mCategoryList;
97 }
98 
99 void CategorySelectDialog::slotApply()
100 {
101  TQStringList categories;
102  TQCheckListItem *item = (TQCheckListItem *)mWidget->mCategories->firstChild();
103  while (item) {
104  if (item->isOn()) {
105  categories.append(item->text());
106  }
107  item = (TQCheckListItem *)item->nextSibling();
108  }
109 
110  TQString categoriesStr = categories.join(", ");
111 
112  mCategoryList = categories;
113 
114  emit categoriesSelected(categories);
115  emit categoriesSelected(categoriesStr);
116 }
117 
118 void CategorySelectDialog::slotOk()
119 {
120  slotApply();
121  accept();
122 }
123 
124 void CategorySelectDialog::clear()
125 {
126  TQCheckListItem *item = (TQCheckListItem *)mWidget->mCategories->firstChild();
127  while (item) {
128  item->setOn(false);
129  item = (TQCheckListItem *)item->nextSibling();
130  }
131 }
132 
133 void CategorySelectDialog::updateCategoryConfig()
134 {
135  TQStringList selected;
136  TQCheckListItem *item = (TQCheckListItem *)mWidget->mCategories->firstChild();
137  while (item) {
138  if (item->isOn()) {
139  selected.append(item->text());
140  }
141  item = (TQCheckListItem *)item->nextSibling();
142  }
143 
144  setCategories();
145 
146  setSelected(selected);
147 }
148 
149 #include "categoryselectdialog.moc"
TDEPIM classes for drag and drop of mails.