summaryrefslogtreecommitdiffabout
path: root/kaddressbook/xxportselectdialog.cpp
Unidiff
Diffstat (limited to 'kaddressbook/xxportselectdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/xxportselectdialog.cpp279
1 files changed, 279 insertions, 0 deletions
diff --git a/kaddressbook/xxportselectdialog.cpp b/kaddressbook/xxportselectdialog.cpp
new file mode 100644
index 0000000..e0da3b2
--- a/dev/null
+++ b/kaddressbook/xxportselectdialog.cpp
@@ -0,0 +1,279 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk>
4 Tobias Koenig <tokoe@kde.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable,
22 without including the source code for Qt in the source distribution.
23*/
24
25/*
26Enhanced Version of the file for platform independent KDE tools.
27Copyright (c) 2004 Ulf Schenk
28
29$Id$
30*/
31
32#include <kabc/addressbook.h>
33#include <kapplication.h>
34#include <kcombobox.h>
35#include <klocale.h>
36#include <kglobal.h>
37
38#include <qbuttongroup.h>
39#include <qcombobox.h>
40#include <qheader.h>
41#include <qlabel.h>
42#include <qlayout.h>
43#include <qlistview.h>
44#include <qpushbutton.h>
45#include <qradiobutton.h>
46#include <qstringlist.h>
47#include <qwhatsthis.h>
48
49#include "kabcore.h"
50#include "kabprefs.h"
51
52#include "xxportselectdialog.h"
53
54XXPortSelectDialog::XXPortSelectDialog( KABCore *core, bool sort,
55 QWidget* parent, const char* name )
56 : KDialogBase( Plain, i18n( "Choose which contacts to export" ), Help | Ok | Cancel,
57 Ok, parent, name, true, true ), mCore( core ),
58 mUseSorting( sort )
59{
60 initGUI();
61
62 connect( mFiltersCombo, SIGNAL( activated( int ) ),
63 SLOT( filterChanged( int ) ) );
64 connect( mCategoriesView, SIGNAL( clicked( QListViewItem* ) ),
65 SLOT( categoryClicked( QListViewItem* ) ) );
66
67 // setup filters
68#ifndef KAB_EMBEDDED
69 mFilters = Filter::restore( kapp->config(), "Filter" );
70 Filter::List::iterator filterIt;
71#else //KAB_EMBEDDED
72 mFilters = Filter::restore( KGlobal::config(), "Filter" );
73 Filter::List::Iterator filterIt;
74#endif //KAB_EMBEDDED
75 QStringList filters;
76 for ( filterIt = mFilters.begin(); filterIt != mFilters.end(); ++filterIt )
77 filters.append( (*filterIt).name() );
78
79 mFiltersCombo->insertStringList( filters );
80 mUseFilters->setEnabled( filters.count() > 0 );
81
82 // setup categories
83 QStringList categories = KABPrefs::instance()->mCustomCategories;
84 QStringList::Iterator it;
85 for ( it = categories.begin(); it != categories.end(); ++it )
86 new QCheckListItem( mCategoriesView, *it, QCheckListItem::CheckBox );
87 mUseCategories->setEnabled( categories.count() > 0 );
88
89 int count = mCore->selectedUIDs().count();
90 mUseSelection->setEnabled( count != 0 );
91 mUseSelection->setChecked( count > 1 );
92
93 mSortTypeCombo->insertItem( i18n( "Ascending" ) );
94 mSortTypeCombo->insertItem( i18n( "Descending" ) );
95
96 mFields = mCore->addressBook()->fields( KABC::Field::All );
97 KABC::Field::List::Iterator fieldIt;
98 for ( fieldIt = mFields.begin(); fieldIt != mFields.end(); ++fieldIt )
99 mFieldCombo->insertItem( (*fieldIt)->label() );
100}
101
102KABC::AddresseeList XXPortSelectDialog::contacts()
103{
104 QStringList selection = mCore->selectedUIDs();
105
106 KABC::AddresseeList list;
107 if ( mUseSelection->isChecked() ) {
108 QStringList::Iterator it;
109 for ( it = selection.begin(); it != selection.end(); ++it ) {
110 KABC::Addressee addr = mCore->addressBook()->findByUid( *it );
111 if ( !addr.isEmpty() )
112 list.append( addr );
113 }
114 } else if ( mUseFilters->isChecked() ) {
115 // find contacts that can pass selected filter
116 Filter::List::Iterator filterIt;
117 for ( filterIt = mFilters.begin(); filterIt != mFilters.end(); ++filterIt )
118 if ( (*filterIt).name() == mFiltersCombo->currentText() )
119 break;
120
121 KABC::AddressBook::Iterator it;
122 for ( it = mCore->addressBook()->begin(); it != mCore->addressBook()->end(); ++it ) {
123 if ( (*filterIt).filterAddressee( *it ) )
124 list.append( *it );
125 }
126 } else if ( mUseCategories->isChecked() ) {
127 QStringList categorieList = categories();
128 KABC::AddressBook::Iterator it;
129 for ( it = mCore->addressBook()->begin(); it != mCore->addressBook()->end(); ++it ) {
130 QStringList tmp( (*it).categories() );
131 QStringList::Iterator tmpIt;
132 for ( tmpIt = tmp.begin(); tmpIt != tmp.end(); ++tmpIt )
133 if ( categorieList.contains( *tmpIt ) ) {
134 list.append( *it );
135 break;
136 }
137 }
138 } else {
139 // create a string list of all entries:
140 KABC::AddressBook::Iterator it;
141 for ( it = mCore->addressBook()->begin(); it != mCore->addressBook()->end(); ++it )
142 list.append( *it );
143 }
144
145 if ( mUseSorting ) {
146 list.setReverseSorting( mSortTypeCombo->currentItem() == 1 );
147 uint pos = mFieldCombo->currentItem();
148 if ( pos < mFields.count() )
149 list.sortByField( mFields[ pos ] );
150 }
151
152 return list;
153}
154
155QStringList XXPortSelectDialog::categories() const
156{
157 QStringList list;
158
159 QListViewItemIterator it( mCategoriesView );
160 for ( ; it.current(); ++it ) {
161 QCheckListItem* qcli = static_cast<QCheckListItem*>(it.current());
162 if ( qcli->isOn() )
163 list.append( it.current()->text( 0 ) );
164 }
165
166 return list;
167}
168
169void XXPortSelectDialog::filterChanged( int )
170{
171 mUseFilters->setChecked( true );
172}
173
174void XXPortSelectDialog::categoryClicked( QListViewItem *i )
175{
176 QCheckListItem *qcli = static_cast<QCheckListItem*>( i );
177 if ( qcli->isOn() )
178 mUseCategories->setChecked( true );
179}
180
181void XXPortSelectDialog::slotHelp()
182{
183#ifndef KAB_EMBEDDED
184 kapp->invokeHelp( "import-and-export" );
185#else //KAB_EMBEDDED
186 qDebug("XXPortSelectDialog::slotHelp is not implemented yet");
187#endif //KAB_EMBEDDED
188
189}
190
191void XXPortSelectDialog::initGUI()
192{
193 QFrame *page = plainPage();
194
195 QVBoxLayout *topLayout = new QVBoxLayout( page, KDialog::marginHint(),
196 KDialog::spacingHint() );
197
198 QLabel *label = new QLabel( i18n( "Which contacts do you want to export?" ), page );
199 topLayout->addWidget( label );
200
201 mButtonGroup = new QButtonGroup( i18n( "Selection" ), page );
202 mButtonGroup->setColumnLayout( 0, Qt::Vertical );
203 mButtonGroup->layout()->setSpacing( KDialog::spacingHint() );
204 mButtonGroup->layout()->setMargin( KDialog::marginHint() );
205
206 QGridLayout *groupLayout = new QGridLayout( mButtonGroup->layout() );
207 groupLayout->setAlignment( Qt::AlignTop );
208
209 mUseWholeBook = new QRadioButton( i18n( "&All contacts" ), mButtonGroup );
210 mUseWholeBook->setChecked( true );
211 QWhatsThis::add( mUseWholeBook, i18n( "Export the entire address book" ) );
212 groupLayout->addWidget( mUseWholeBook, 0, 0 );
213
214 mUseSelection = new QRadioButton( i18n( "&Selected contacts" ), mButtonGroup );
215 QWhatsThis::add( mUseSelection, i18n( "Only export contacts selected in KAddressBook.\n"
216 "This option is disabled if no contacts are selected." ) );
217 groupLayout->addWidget( mUseSelection, 1, 0 );
218
219 mUseFilters = new QRadioButton( i18n( "Contacts matching &filter" ), mButtonGroup );
220 QWhatsThis::add( mUseFilters, i18n( "Only export contacts matching the selected filter.\n"
221 "This option is disabled if you haven't defined any filters" ) );
222 groupLayout->addWidget( mUseFilters, 2, 0 );
223
224 mUseCategories = new QRadioButton( i18n( "Category &members" ), mButtonGroup );
225 QWhatsThis::add( mUseCategories, i18n( "Only export contacts who are members of a category that is checked on the list to the left.\n"
226 "This option is disabled if you have no categories." ) );
227 groupLayout->addWidget( mUseCategories, 3, 0 );
228
229 mFiltersCombo = new QComboBox( false, mButtonGroup );
230 QWhatsThis::add( mFiltersCombo, i18n( "Select a filter to decide which contacts to export." ) );
231 groupLayout->addWidget( mFiltersCombo, 2, 1 );
232
233 mCategoriesView = new QListView( mButtonGroup );
234 mCategoriesView->addColumn( "" );
235 mCategoriesView->header()->hide();
236 QWhatsThis::add( mCategoriesView, i18n( "Check the categories whose members you want to export." ) );
237 groupLayout->addWidget( mCategoriesView, 3, 1 );
238
239 topLayout->addWidget( mButtonGroup );
240
241 QButtonGroup *sortingGroup = new QButtonGroup( i18n( "Sorting" ), page );
242 sortingGroup->setColumnLayout( 0, Qt::Vertical );
243 QGridLayout *sortLayout = new QGridLayout( sortingGroup->layout(), 2, 2,
244 KDialog::spacingHint() );
245 sortLayout->setAlignment( Qt::AlignTop );
246
247 label = new QLabel( i18n( "Criterion:" ), sortingGroup );
248 sortLayout->addWidget( label, 0, 0 );
249
250#ifndef KAB_EMBEDDED
251 mFieldCombo = new KComboBox( false, sortingGroup );
252#else //KAB_EMBEDDED
253 //US Combobox is not editable anyway
254 mFieldCombo = new KComboBox( sortingGroup );
255#endif //KAB_EMBEDDED
256 sortLayout->addWidget( mFieldCombo, 0, 1 );
257
258 label = new QLabel( i18n( "Order:" ), sortingGroup );
259 sortLayout->addWidget( label, 1, 0 );
260
261#ifndef KAB_EMBEDDED
262 mSortTypeCombo = new KComboBox( false, sortingGroup );
263#else //KAB_EMBEDDED
264 //US Combobox is not editable anyway
265 mSortTypeCombo = new KComboBox( sortingGroup );
266#endif //KAB_EMBEDDED
267 sortLayout->addWidget( mSortTypeCombo, 1, 1 );
268
269 topLayout->addWidget( sortingGroup );
270
271 if ( !mUseSorting )
272 sortingGroup->hide();
273}
274
275#ifndef KAB_EMBEDDED
276#include "xxportselectdialog.moc"
277#endif //KAB_EMBEDDED
278
279