Diffstat (limited to 'kaddressbook/filtereditdialog.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | kaddressbook/filtereditdialog.cpp | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/kaddressbook/filtereditdialog.cpp b/kaddressbook/filtereditdialog.cpp index 063585a..987f234 100644 --- a/kaddressbook/filtereditdialog.cpp +++ b/kaddressbook/filtereditdialog.cpp | |||
@@ -1,210 +1,224 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressBook. | 2 | This file is part of KAddressBook. |
3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> | 3 | Copyright (c) 2002 Mike Pilone <mpilone@slac.com> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 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 | 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 | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 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 | 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. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | /* | 24 | /* |
25 | Enhanced Version of the file for platform independent KDE tools. | 25 | Enhanced Version of the file for platform independent KDE tools. |
26 | Copyright (c) 2004 Ulf Schenk | 26 | Copyright (c) 2004 Ulf Schenk |
27 | 27 | ||
28 | $Id$ | 28 | $Id$ |
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include <qbuttongroup.h> | 31 | #include <qbuttongroup.h> |
32 | #include <qhbox.h> | 32 | #include <qhbox.h> |
33 | #include <qlabel.h> | 33 | #include <qlabel.h> |
34 | #include <qlayout.h> | 34 | #include <qlayout.h> |
35 | #include <qpushbutton.h> | 35 | #include <qpushbutton.h> |
36 | #include <qradiobutton.h> | 36 | #include <qradiobutton.h> |
37 | #include <qcheckbox.h> | ||
37 | #include <qregexp.h> | 38 | #include <qregexp.h> |
38 | #include <qstring.h> | 39 | #include <qstring.h> |
39 | #include <qtoolbutton.h> | 40 | #include <qtoolbutton.h> |
40 | #include <qtooltip.h> | 41 | #include <qtooltip.h> |
41 | #include <qwidget.h> | 42 | #include <qwidget.h> |
42 | 43 | ||
43 | #include <kapplication.h> | 44 | #include <kapplication.h> |
44 | #include <kbuttonbox.h> | 45 | #include <kbuttonbox.h> |
45 | #include <kdebug.h> | 46 | #include <kdebug.h> |
46 | #include <kiconloader.h> | 47 | #include <kiconloader.h> |
47 | #include <klineedit.h> | 48 | #include <klineedit.h> |
48 | #include <klistbox.h> | 49 | #include <klistbox.h> |
49 | #include <klistview.h> | 50 | #include <klistview.h> |
50 | #include <klocale.h> | 51 | #include <klocale.h> |
51 | #include <kglobal.h> | 52 | #include <kglobal.h> |
52 | 53 | ||
53 | #include "kabprefs.h" | 54 | #include "kabprefs.h" |
54 | #include "filtereditdialog.h" | 55 | #include "filtereditdialog.h" |
55 | 56 | ||
56 | FilterEditDialog::FilterEditDialog( QWidget *parent, const char *name ) | 57 | FilterEditDialog::FilterEditDialog( QWidget *parent, const char *name ) |
57 | : KDialogBase( Plain, i18n( "Edit Address Book Filter" ), | 58 | : KDialogBase( Plain, i18n( "Edit Address Book Filter" ), |
58 | Help | Ok | Cancel, Ok, parent, name, /*US false*/ true, true ) | 59 | Help | Ok | Cancel, Ok, parent, name, /*US false*/ true, true ) |
59 | { | 60 | { |
60 | initGUI(); | 61 | initGUI(); |
61 | 62 | ||
62 | QStringList cats = KABPrefs::instance()->mCustomCategories; | 63 | QStringList cats = KABPrefs::instance()->mCustomCategories; |
63 | 64 | ||
64 | QStringList::Iterator iter; | 65 | QStringList::Iterator iter; |
65 | for ( iter = cats.begin(); iter != cats.end(); ++iter ) | 66 | for ( iter = cats.begin(); iter != cats.end(); ++iter ) |
66 | mCategoriesView->insertItem( new QCheckListItem( mCategoriesView, (*iter), QCheckListItem::CheckBox ) ); | 67 | mCategoriesView->insertItem( new QCheckListItem( mCategoriesView, (*iter), QCheckListItem::CheckBox ) ); |
67 | filterNameTextChanged( mNameEdit->text() ); | 68 | filterNameTextChanged( mNameEdit->text() ); |
68 | } | 69 | } |
69 | 70 | ||
70 | FilterEditDialog::~FilterEditDialog() | 71 | FilterEditDialog::~FilterEditDialog() |
71 | { | 72 | { |
72 | } | 73 | } |
73 | 74 | ||
74 | void FilterEditDialog::setFilter( const Filter &filter ) | 75 | void FilterEditDialog::setFilter( const Filter &filter ) |
75 | { | 76 | { |
76 | mNameEdit->setText( filter.name() ); | 77 | mNameEdit->setText( filter.name() ); |
77 | 78 | ||
78 | QStringList categories = filter.categories(); | 79 | QStringList categories = filter.categories(); |
79 | QListViewItem *item = mCategoriesView->firstChild(); | 80 | QListViewItem *item = mCategoriesView->firstChild(); |
80 | while ( item != 0 ) { | 81 | while ( item != 0 ) { |
81 | if ( categories.contains( item->text( 0 ) ) ) { | 82 | if ( categories.contains( item->text( 0 ) ) ) { |
82 | QCheckListItem *checkItem = static_cast<QCheckListItem*>( item ); | 83 | QCheckListItem *checkItem = static_cast<QCheckListItem*>( item ); |
83 | checkItem->setOn( true ); | 84 | checkItem->setOn( true ); |
84 | } | 85 | } |
85 | 86 | ||
86 | item = item->nextSibling(); | 87 | item = item->nextSibling(); |
87 | } | 88 | } |
88 | 89 | ||
89 | if ( filter.matchRule() == Filter::Matching ) | 90 | if ( filter.matchRule() == Filter::Matching ) |
90 | mMatchRuleGroup->setButton( 0 ); | 91 | mMatchRuleGroup->setButton( 0 ); |
91 | else | 92 | else |
92 | mMatchRuleGroup->setButton( 1 ); | 93 | mMatchRuleGroup->setButton( 1 ); |
94 | |||
95 | int c = filter.criteria() ; | ||
96 | mPublic->setChecked(c &Filter::ShowPublic); | ||
97 | mPrivate->setChecked(c & Filter::ShowPrivate); | ||
98 | mConfidential->setChecked(c & Filter::ShowConfidential); | ||
99 | |||
93 | } | 100 | } |
94 | 101 | ||
95 | Filter FilterEditDialog::filter() | 102 | Filter FilterEditDialog::filter() |
96 | { | 103 | { |
97 | Filter filter; | 104 | Filter filter; |
98 | 105 | ||
99 | filter.setName( mNameEdit->text() ); | 106 | filter.setName( mNameEdit->text() ); |
100 | 107 | ||
101 | QStringList categories; | 108 | QStringList categories; |
102 | QListViewItem *item = mCategoriesView->firstChild(); | 109 | QListViewItem *item = mCategoriesView->firstChild(); |
103 | while ( item != 0 ) { | 110 | while ( item != 0 ) { |
104 | QCheckListItem *checkItem = static_cast<QCheckListItem*>( item ); | 111 | QCheckListItem *checkItem = static_cast<QCheckListItem*>( item ); |
105 | if ( checkItem->isOn() ) | 112 | if ( checkItem->isOn() ) |
106 | categories.append( item->text( 0 ) ); | 113 | categories.append( item->text( 0 ) ); |
107 | 114 | ||
108 | item = item->nextSibling(); | 115 | item = item->nextSibling(); |
109 | } | 116 | } |
110 | filter.setCategories( categories ); | 117 | filter.setCategories( categories ); |
111 | 118 | ||
112 | if ( mMatchRuleGroup->find( 0 )->isOn() ) | 119 | if ( mMatchRuleGroup->find( 0 )->isOn() ) |
113 | filter.setMatchRule( Filter::Matching ); | 120 | filter.setMatchRule( Filter::Matching ); |
114 | else | 121 | else |
115 | filter.setMatchRule( Filter::NotMatching ); | 122 | filter.setMatchRule( Filter::NotMatching ); |
116 | 123 | ||
124 | int c = 0; | ||
125 | if (mPublic->isChecked()) c |= Filter::ShowPublic; | ||
126 | if (mPrivate->isChecked()) c |= Filter::ShowPrivate; | ||
127 | if (mConfidential->isChecked()) c |= Filter::ShowConfidential; | ||
128 | filter.setCriteria( c ) ; | ||
129 | |||
117 | return filter; | 130 | return filter; |
118 | } | 131 | } |
119 | 132 | ||
120 | void FilterEditDialog::initGUI() | 133 | void FilterEditDialog::initGUI() |
121 | { | 134 | { |
122 | #ifndef KAB_EMBEDDED | 135 | #ifndef KAB_EMBEDDED |
123 | resize( 490, 300 ); | 136 | resize( 490, 300 ); |
124 | #else //KAB_EMBEDDED | 137 | #else //KAB_EMBEDDED |
125 | resize( KMIN(KGlobal::getDesktopWidth()-10, 490), KMIN(KGlobal::getDesktopHeight()-50, 300)); | 138 | resize( KMIN(KGlobal::getDesktopWidth()-10, 490), KMIN(KGlobal::getDesktopHeight()-50, 300)); |
126 | #endif //KAB_EMBEDDED | 139 | #endif //KAB_EMBEDDED |
127 | 140 | ||
128 | 141 | ||
129 | QWidget *page = plainPage(); | 142 | QWidget *page = plainPage(); |
130 | QLabel *label; | 143 | QLabel *label; |
131 | 144 | ||
132 | QGridLayout *topLayout = new QGridLayout( page, 3, 2, 0, spacingHint() ); | 145 | QGridLayout *topLayout = new QGridLayout( page, 3, 2, 0, spacingHint() ); |
133 | 146 | ||
134 | label = new QLabel( i18n( "Name" ), page ); | 147 | label = new QLabel( i18n( "Name" ), page ); |
135 | mNameEdit = new KLineEdit( page ); | 148 | mNameEdit = new KLineEdit( page ); |
136 | mNameEdit->setFocus(); | 149 | mNameEdit->setFocus(); |
137 | topLayout->addWidget( label, 0, 0 ); | 150 | topLayout->addWidget( label, 0, 0 ); |
138 | topLayout->addWidget( mNameEdit, 0, 1 ); | 151 | topLayout->addWidget( mNameEdit, 0, 1 ); |
139 | connect( mNameEdit, SIGNAL( textChanged( const QString& ) ), | 152 | connect( mNameEdit, SIGNAL( textChanged( const QString& ) ), |
140 | SLOT( filterNameTextChanged( const QString&) ) ); | 153 | SLOT( filterNameTextChanged( const QString&) ) ); |
141 | 154 | ||
142 | mCategoriesView = new KListView( page ); | 155 | mCategoriesView = new KListView( page ); |
143 | mCategoriesView->addColumn( i18n( "Categories" ) ); | 156 | mCategoriesView->addColumn( i18n( "Categories" ) ); |
144 | topLayout->addMultiCellWidget( mCategoriesView, 1, 1, 0, 1 ); | 157 | topLayout->addMultiCellWidget( mCategoriesView, 1, 1, 0, 1 ); |
145 | 158 | ||
146 | mMatchRuleGroup = new QButtonGroup( page ); | 159 | mMatchRuleGroup = new QHButtonGroup( i18n( "Category rule" ), page ); |
147 | mMatchRuleGroup->setExclusive( true ); | 160 | mMatchRuleGroup->setExclusive( true ); |
148 | 161 | QRadioButton *radio = new QRadioButton( i18n( "Include categories" ), mMatchRuleGroup ); | |
149 | QBoxLayout *gbLayout = new QVBoxLayout( mMatchRuleGroup ); | ||
150 | gbLayout->setSpacing( KDialog::spacingHint() ); | ||
151 | gbLayout->setMargin( KDialog::marginHint() ); | ||
152 | |||
153 | QRadioButton *radio = new QRadioButton( i18n( "Show only contacts matching\n the selected categories" ), mMatchRuleGroup ); | ||
154 | radio->setChecked( true ); | 162 | radio->setChecked( true ); |
155 | mMatchRuleGroup->insert( radio ); | 163 | //mMatchRuleGroup->insert( radio ); |
156 | gbLayout->addWidget( radio ); | 164 | radio = new QRadioButton( i18n( "Exclude categories" ), mMatchRuleGroup ); |
165 | //mMatchRuleGroup->insert( radio ); | ||
166 | topLayout->addMultiCellWidget( mMatchRuleGroup, 2, 2, 0, 1 ); | ||
157 | 167 | ||
158 | radio = new QRadioButton( i18n( "Show all contacts except those\n matching the selected categories" ), mMatchRuleGroup ); | 168 | QHButtonGroup * mMatchPPCGroup = new QHButtonGroup(i18n( "Include contacts, that are:" ), page ); |
159 | mMatchRuleGroup->insert( radio ); | 169 | mPublic = new QCheckBox( i18n( "public" ), mMatchPPCGroup ); |
160 | gbLayout->addWidget( radio ); | 170 | mPrivate = new QCheckBox( i18n( "private" ), mMatchPPCGroup ); |
171 | mConfidential = new QCheckBox( i18n( "confidential" ), mMatchPPCGroup ); | ||
172 | mPublic->setChecked( true ); | ||
173 | mPrivate->setChecked( true ); | ||
174 | mConfidential->setChecked( true ); | ||
175 | topLayout->addMultiCellWidget( mMatchPPCGroup, 3, 3, 0, 1 ); | ||
161 | 176 | ||
162 | topLayout->addMultiCellWidget( mMatchRuleGroup, 2, 2, 0, 1 ); | ||
163 | } | 177 | } |
164 | 178 | ||
165 | void FilterEditDialog::filterNameTextChanged( const QString &text ) | 179 | void FilterEditDialog::filterNameTextChanged( const QString &text ) |
166 | { | 180 | { |
167 | enableButtonOK( !text.isEmpty() ); | 181 | enableButtonOK( !text.isEmpty() ); |
168 | } | 182 | } |
169 | 183 | ||
170 | void FilterEditDialog::slotHelp() | 184 | void FilterEditDialog::slotHelp() |
171 | { | 185 | { |
172 | #ifndef KAB_EMBEDDED | 186 | #ifndef KAB_EMBEDDED |
173 | kapp->invokeHelp( "using-filters" ); | 187 | kapp->invokeHelp( "using-filters" ); |
174 | #endif //KAB_EMBEDDED | 188 | #endif //KAB_EMBEDDED |
175 | } | 189 | } |
176 | 190 | ||
177 | FilterDialog::FilterDialog( QWidget *parent, const char *name ) | 191 | FilterDialog::FilterDialog( QWidget *parent, const char *name ) |
178 | : KDialogBase( Plain, i18n( "Edit Address Book Filters" ), | 192 | : KDialogBase( Plain, i18n( "Edit Address Book Filters" ), |
179 | Ok | Cancel, Ok, parent, name, /*US false*/true, true ) | 193 | Ok | Cancel, Ok, parent, name, /*US false*/true, true ) |
180 | { | 194 | { |
181 | initGUI(); | 195 | initGUI(); |
182 | } | 196 | } |
183 | 197 | ||
184 | FilterDialog::~FilterDialog() | 198 | FilterDialog::~FilterDialog() |
185 | { | 199 | { |
186 | } | 200 | } |
187 | 201 | ||
188 | void FilterDialog::setFilters( const Filter::List &list ) | 202 | void FilterDialog::setFilters( const Filter::List &list ) |
189 | { | 203 | { |
190 | mFilterList.clear(); | 204 | mFilterList.clear(); |
191 | mInternalFilterList.clear(); | 205 | mInternalFilterList.clear(); |
192 | 206 | ||
193 | Filter::List::ConstIterator it; | 207 | Filter::List::ConstIterator it; |
194 | for ( it = list.begin(); it != list.end(); ++it ) { | 208 | for ( it = list.begin(); it != list.end(); ++it ) { |
195 | if ( (*it).isInternal() ) | 209 | if ( (*it).isInternal() ) |
196 | mInternalFilterList.append( *it ); | 210 | mInternalFilterList.append( *it ); |
197 | else | 211 | else |
198 | mFilterList.append( *it ); | 212 | mFilterList.append( *it ); |
199 | } | 213 | } |
200 | 214 | ||
201 | refresh(); | 215 | refresh(); |
202 | } | 216 | } |
203 | 217 | ||
204 | Filter::List FilterDialog::filters() const | 218 | Filter::List FilterDialog::filters() const |
205 | { | 219 | { |
206 | Filter::List list = mFilterList + mInternalFilterList; | 220 | Filter::List list = mFilterList + mInternalFilterList; |
207 | return list; | 221 | return list; |
208 | } | 222 | } |
209 | 223 | ||
210 | void FilterDialog::add() | 224 | void FilterDialog::add() |