summaryrefslogtreecommitdiffabout
path: root/kaddressbook
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /kaddressbook
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'kaddressbook') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/addresseditwidget.cpp622
-rw-r--r--kaddressbook/addresseditwidget.h159
-rw-r--r--kaddressbook/addresseeconfig.cpp94
-rw-r--r--kaddressbook/addresseeconfig.h55
-rw-r--r--kaddressbook/addresseeeditordialog.cpp129
-rw-r--r--kaddressbook/addresseeeditordialog.h62
-rw-r--r--kaddressbook/addresseeeditorwidget.cpp1284
-rw-r--r--kaddressbook/addresseeeditorwidget.h184
-rw-r--r--kaddressbook/addresseeutil.cpp66
-rw-r--r--kaddressbook/addresseeutil.h61
-rw-r--r--kaddressbook/addviewdialog.cpp118
-rw-r--r--kaddressbook/addviewdialog.h73
-rw-r--r--kaddressbook/configurewidget.cpp54
-rw-r--r--kaddressbook/configurewidget.h67
-rw-r--r--kaddressbook/details/detailsviewcontainer.cpp171
-rw-r--r--kaddressbook/details/detailsviewcontainer.h103
-rw-r--r--kaddressbook/details/global.h28
-rw-r--r--kaddressbook/details/look_basic.cpp75
-rw-r--r--kaddressbook/details/look_basic.h134
-rw-r--r--kaddressbook/details/look_details.cpp419
-rw-r--r--kaddressbook/details/look_details.h157
-rw-r--r--kaddressbook/details/look_html.cpp45
-rw-r--r--kaddressbook/details/look_html.h75
-rw-r--r--kaddressbook/emaileditwidget.cpp275
-rw-r--r--kaddressbook/emaileditwidget.h101
-rw-r--r--kaddressbook/extensionmanager.cpp246
-rw-r--r--kaddressbook/extensionmanager.h88
-rw-r--r--kaddressbook/extensionwidget.cpp84
-rw-r--r--kaddressbook/extensionwidget.h119
-rw-r--r--kaddressbook/features/distributionlistwidget.cpp501
-rw-r--r--kaddressbook/features/distributionlistwidget.h143
-rw-r--r--kaddressbook/features/mergewidget.cpp374
-rw-r--r--kaddressbook/features/mergewidget.h87
-rw-r--r--kaddressbook/filter.cpp205
-rw-r--r--kaddressbook/filter.h153
-rw-r--r--kaddressbook/filtereditdialog.cpp302
-rw-r--r--kaddressbook/filtereditdialog.h104
-rw-r--r--kaddressbook/geowidget.cpp629
-rw-r--r--kaddressbook/geowidget.h155
-rw-r--r--kaddressbook/imagewidget.cpp299
-rw-r--r--kaddressbook/imagewidget.h86
-rw-r--r--kaddressbook/incsearchwidget.cpp147
-rw-r--r--kaddressbook/incsearchwidget.h73
-rw-r--r--kaddressbook/jumpbuttonbar.cpp232
-rw-r--r--kaddressbook/jumpbuttonbar.h84
-rw-r--r--kaddressbook/kabcore.cpp1571
-rw-r--r--kaddressbook/kabcore.h421
-rw-r--r--kaddressbook/kabprefs.cpp127
-rw-r--r--kaddressbook/kabprefs.h88
-rw-r--r--kaddressbook/kaddressbook.desktop8
-rw-r--r--kaddressbook/kaddressbook.pro166
-rw-r--r--kaddressbook/kaddressbookE.pro154
-rw-r--r--kaddressbook/kaddressbookmain.cpp293
-rw-r--r--kaddressbook/kaddressbookmain.h126
-rw-r--r--kaddressbook/kaddressbookview.cpp171
-rw-r--r--kaddressbook/kaddressbookview.h295
-rw-r--r--kaddressbook/kcmconfigs/addresseewidget.cpp236
-rw-r--r--kaddressbook/kcmconfigs/addresseewidget.h87
-rw-r--r--kaddressbook/kcmconfigs/extensionconfigdialog.cpp59
-rw-r--r--kaddressbook/kcmconfigs/extensionconfigdialog.h48
-rw-r--r--kaddressbook/kcmconfigs/kabconfigwidget.cpp357
-rw-r--r--kaddressbook/kcmconfigs/kabconfigwidget.h72
-rw-r--r--kaddressbook/kcmconfigs/kcmkabconfig.cpp86
-rw-r--r--kaddressbook/kcmconfigs/kcmkabconfig.h53
-rw-r--r--kaddressbook/keywidget.cpp277
-rw-r--r--kaddressbook/keywidget.h65
-rw-r--r--kaddressbook/mainembedded.cpp208
-rw-r--r--kaddressbook/nameeditdialog.cpp296
-rw-r--r--kaddressbook/nameeditdialog.h90
-rw-r--r--kaddressbook/old_mainwindow.cpp1561
-rw-r--r--kaddressbook/old_mainwindow.h122
-rw-r--r--kaddressbook/phoneeditwidget.cpp532
-rw-r--r--kaddressbook/phoneeditwidget.h147
-rw-r--r--kaddressbook/secrecywidget.cpp70
-rw-r--r--kaddressbook/secrecywidget.h50
-rw-r--r--kaddressbook/typecombo.h193
-rw-r--r--kaddressbook/undo.cpp119
-rw-r--r--kaddressbook/undo.h95
-rw-r--r--kaddressbook/undocmds.cpp240
-rw-r--r--kaddressbook/undocmds.h117
-rw-r--r--kaddressbook/viewconfigurefieldspage.cpp345
-rw-r--r--kaddressbook/viewconfigurefieldspage.h81
-rw-r--r--kaddressbook/viewconfigurefilterpage.cpp137
-rw-r--r--kaddressbook/viewconfigurefilterpage.h63
-rw-r--r--kaddressbook/viewconfigurewidget.cpp159
-rw-r--r--kaddressbook/viewconfigurewidget.h106
-rw-r--r--kaddressbook/viewmanager.cpp685
-rw-r--r--kaddressbook/viewmanager.h152
-rw-r--r--kaddressbook/views/cardview.cpp1719
-rw-r--r--kaddressbook/views/cardview.desktop18
-rw-r--r--kaddressbook/views/cardview.h473
-rw-r--r--kaddressbook/views/colorlistbox.cpp230
-rw-r--r--kaddressbook/views/colorlistbox.h76
-rw-r--r--kaddressbook/views/configurecardviewdialog.cpp364
-rw-r--r--kaddressbook/views/configurecardviewdialog.h117
-rw-r--r--kaddressbook/views/configuretableviewdialog.cpp155
-rw-r--r--kaddressbook/views/configuretableviewdialog.h88
-rw-r--r--kaddressbook/views/contactlistview.cpp340
-rw-r--r--kaddressbook/views/contactlistview.h128
-rw-r--r--kaddressbook/views/kaddressbookcardview.cpp394
-rw-r--r--kaddressbook/views/kaddressbookcardview.h117
-rw-r--r--kaddressbook/views/kaddressbookiconview.cpp378
-rw-r--r--kaddressbook/views/kaddressbookiconview.h130
-rw-r--r--kaddressbook/views/kaddressbooktableview.cpp337
-rw-r--r--kaddressbook/views/kaddressbooktableview.h114
-rw-r--r--kaddressbook/xxport/csv_xxport.cpp187
-rw-r--r--kaddressbook/xxport/csv_xxport.h68
-rw-r--r--kaddressbook/xxport/csvimportdialog.cpp922
-rw-r--r--kaddressbook/xxport/csvimportdialog.h124
-rw-r--r--kaddressbook/xxport/kde2_xxport.cpp116
-rw-r--r--kaddressbook/xxport/kde2_xxport.h62
-rw-r--r--kaddressbook/xxport/vcard_xxport.cpp238
-rw-r--r--kaddressbook/xxport/vcard_xxport.h64
-rw-r--r--kaddressbook/xxportmanager.cpp269
-rw-r--r--kaddressbook/xxportmanager.h79
-rw-r--r--kaddressbook/xxportobject.cpp152
-rw-r--r--kaddressbook/xxportobject.h157
-rw-r--r--kaddressbook/xxportselectdialog.cpp279
-rw-r--r--kaddressbook/xxportselectdialog.h81
119 files changed, 27026 insertions, 0 deletions
diff --git a/kaddressbook/addresseditwidget.cpp b/kaddressbook/addresseditwidget.cpp
new file mode 100644
index 0000000..3dcd592
--- a/dev/null
+++ b/kaddressbook/addresseditwidget.cpp
@@ -0,0 +1,622 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4 2003 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#include <qbuttongroup.h>
26#include <qcheckbox.h>
27#include <qhbox.h>
28#include <qlabel.h>
29#include <qlayout.h>
30#include <qlistbox.h>
31#include <qlistview.h>
32#include <qpushbutton.h>
33#include <qsignal.h>
34#include <qstring.h>
35#include <qapplication.h>
36
37#ifndef KAB_EMBEDDED
38#include <qtextedit.h>
39#include <kaccelmanager.h>
40#include <kbuttonbox.h>
41#else //KAB_EMBEDDED
42#include <qmultilineedit.h>
43#endif //KAB_EMBEDDED
44
45#include <qtoolbutton.h>
46#include <qtooltip.h>
47
48#include <kapplication.h>
49#include <kcombobox.h>
50#include <kconfig.h>
51#include <kdebug.h>
52#include <kdialog.h>
53#include <kiconloader.h>
54#include <klineedit.h>
55#include <klistview.h>
56#include <klocale.h>
57#include <kglobal.h>
58#include <kmessagebox.h>
59#include <kseparator.h>
60
61#include "addresseditwidget.h"
62
63
64
65AddressEditWidget::AddressEditWidget( QWidget *parent, const char *name )
66 : QWidget( parent, name )
67{
68
69 mConfig = AddresseeConfig::instance();
70 QVBoxLayout *layout = new QVBoxLayout( this );
71 layout->setSpacing( KDialog::spacingHintSmall() );
72 QHBox *b1 = new QHBox( this);
73 //QLabel * label = new QLabel( b1 );
74 //label->setPixmap( KGlobal::iconLoader()->loadIcon( "gohome", KIcon::Desktop, 0 ) );
75
76
77 //label->setAlignment( AlignCenter);
78 layout->addWidget( b1 );
79 mTypeCombo = new AddressTypeCombo( mAddressList, b1 );
80 QPushButton *editButton = new QPushButton( i18n( "&Edit Addresses..." ),
81 b1 );
82 connect( mTypeCombo, SIGNAL( activated( int ) ),
83 SLOT( updateAddressEdit() ) );
84 // layout->addWidget( mTypeCombo );
85
86#ifndef KAB_EMBEDDED
87 mAddressTextEdit = new QTextEdit( this );
88 mAddressTextEdit->setReadOnly( true );
89 mAddressTextEdit->setMinimumHeight( 20 );
90#else //KAB_EMBEDDED
91 mAddressTextEdit = new QMultiLineEdit( this );
92 mAddressTextEdit->setReadOnly( true );
93 mAddressTextEdit->setMinimumHeight( 20 );
94#endif //KAB_EMBEDDED
95
96 layout->addWidget( mAddressTextEdit );
97
98
99 connect( editButton, SIGNAL( clicked() ), SLOT( edit() ) );
100}
101
102AddressEditWidget::~AddressEditWidget()
103{
104
105}
106
107KABC::Address::List AddressEditWidget::addresses()
108{
109 KABC::Address::List retList;
110
111 KABC::Address::List::Iterator it;
112 for ( it = mAddressList.begin(); it != mAddressList.end(); ++it )
113 if ( !(*it).isEmpty() )
114 retList.append( *it );
115
116 return retList;
117}
118
119void AddressEditWidget::setAddresses( const KABC::Addressee &addr,
120 const KABC::Address::List &list )
121{
122 mAddressee = addr;
123
124 mAddressList.clear();
125
126 // Insert types for existing numbers.
127 mTypeCombo->insertTypeList( list );
128
129 QValueList<int> defaultTypes;
130 defaultTypes << KABC::Address::Home;
131 defaultTypes << KABC::Address::Work;
132
133 mConfig->setUid( mAddressee.uid() );
134 QValueList<int> configList = mConfig->noDefaultAddrTypes();
135 QValueList<int>::ConstIterator it;
136 for ( it = configList.begin(); it != configList.end(); ++it )
137 defaultTypes.remove( *it );
138
139 // Insert default types.
140 // Doing this for mPrefCombo is enough because the list is shared by all
141 // combos.
142 for( it = defaultTypes.begin(); it != defaultTypes.end(); ++it ) {
143 if ( !mTypeCombo->hasType( *it ) )
144 mTypeCombo->insertType( list, *it, Address( *it ) );
145 }
146
147 mTypeCombo->updateTypes();
148
149 // find preferred address which will be shown
150 int preferred = KABC::Address::Home; // default if no preferred address set
151 uint i;
152 for (i = 0; i < list.count(); i++)
153 if ( list[i].type() & KABC::Address::Pref ) {
154 preferred = list[i].type();
155 break;
156 }
157
158 mTypeCombo->selectType( preferred );
159
160 updateAddressEdit();
161}
162
163void AddressEditWidget::edit()
164{
165 AddressEditDialog dialog( mAddressList, mTypeCombo->currentItem(), this );
166 if ( dialog.exec() ) {
167 if ( dialog.changed() ) {
168 mAddressList = dialog.addresses();
169
170 bool hasHome = false, hasWork = false;
171 KABC::Address::List::Iterator it;
172 for ( it = mAddressList.begin(); it != mAddressList.end(); ++it ) {
173 if ( (*it).type() == KABC::Address::Home ) {
174 if ( !(*it).isEmpty() )
175 hasHome = true;
176 }
177 if ( (*it).type() == KABC::Address::Work ) {
178 if ( !(*it).isEmpty() )
179 hasWork = true;
180 }
181 }
182
183 mConfig->setUid( mAddressee.uid() );
184 QValueList<int> configList;
185 if ( !hasHome ) {
186 configList << KABC::Address::Home;
187 }
188 if ( !hasWork ) {
189 configList << KABC::Address::Work;
190 }
191 mConfig->setNoDefaultAddrTypes( configList );
192
193 mTypeCombo->updateTypes();
194 updateAddressEdit();
195 emit modified();
196 }
197 }
198}
199
200void AddressEditWidget::updateAddressEdit()
201{
202 KABC::Address::List::Iterator it = mTypeCombo->selectedElement();
203
204 bool block = signalsBlocked();
205 blockSignals( true );
206
207 mAddressTextEdit->setText( "" );
208
209 if ( it != mAddressList.end() ) {
210 KABC::Address a = *it;
211 if ( !a.isEmpty() ) {
212#if KDE_VERSION >= 319
213 if ( a.type() & KABC::Address::Work ) {
214 mAddressTextEdit->setText( a.formattedAddress( mAddressee.realName(),
215 mAddressee.organization() ) );
216 } else {
217 mAddressTextEdit->setText( a.formattedAddress( mAddressee.realName() ) );
218 }
219#else
220 QString text;
221 if ( !a.street().isEmpty() )
222 text += a.street() + "\n";
223
224 if ( !a.postOfficeBox().isEmpty() )
225 text += a.postOfficeBox() + "\n";
226
227 text += a.locality() + QString(" ") + a.region();
228
229 if ( !a.postalCode().isEmpty() )
230 text += QString(", ") + a.postalCode();
231
232 text += "\n";
233
234 if ( !a.country().isEmpty() )
235 text += a.country() + "\n";
236
237 text += a.extended();
238
239 mAddressTextEdit->setText( text );
240#endif
241 }
242 }
243
244 blockSignals( block );
245}
246
247AddressEditDialog::AddressEditDialog( const KABC::Address::List &list,
248 int selected, QWidget *parent,
249 const char *name )
250 : KDialogBase( Plain, i18n( "Edit Address" ), Ok | Cancel, Ok,
251 parent, name, true, true ),
252 mPreviousAddress( 0 )
253{
254 mAddressList = list;
255
256 QWidget *page = plainPage();
257
258 QGridLayout *topLayout = new QGridLayout( page, 8, 2 );
259 topLayout->setSpacing( spacingHintSmall() );
260
261 mTypeCombo = new AddressTypeCombo( mAddressList, page );
262 topLayout->addMultiCellWidget( mTypeCombo, 0, 0, 0, 1 );
263
264 QLabel *label = new QLabel( i18n( "Street:" ), page );
265 label->setAlignment( Qt::AlignTop | Qt::AlignLeft );
266 topLayout->addWidget( label, 1, 0 );
267
268#ifndef KAB_EMBEDDED
269 mStreetTextEdit = new QTextEdit( page );
270#else //KAB_EMBEDDED
271 mStreetTextEdit = new QMultiLineEdit( page );
272//US qDebug("AddressEditDialog::AddressEditDialog has to be changed");
273#endif //KAB_EMBEDDED
274
275 label->setBuddy( mStreetTextEdit );
276 topLayout->addWidget( mStreetTextEdit, 1, 1 );
277
278 label = new QLabel( i18n( "Post office box:" ), page );
279 topLayout->addWidget( label, 2 , 0 );
280 mPOBoxEdit = new KLineEdit( page );
281 label->setBuddy( mPOBoxEdit );
282 topLayout->addWidget( mPOBoxEdit, 2, 1 );
283 int maxwid = QApplication::desktop()->width();
284 maxwid -= (spacingHintSmall()+label->sizeHint().width() );
285 label = new QLabel( i18n( "Locality:" ), page );
286 topLayout->addWidget( label, 3, 0 );
287 mLocalityEdit = new KLineEdit( page );
288 label->setBuddy( mLocalityEdit );
289 topLayout->addWidget( mLocalityEdit, 3, 1 );
290
291 label = new QLabel( i18n( "Region:" ), page );
292 topLayout->addWidget( label, 4, 0 );
293 mRegionEdit = new KLineEdit( page );
294 label->setBuddy( mRegionEdit );
295 topLayout->addWidget( mRegionEdit, 4, 1 );
296
297 label = new QLabel( i18n( "Postal code:" ), page );
298 topLayout->addWidget( label, 5, 0 );
299 mPostalCodeEdit = new KLineEdit( page );
300 label->setBuddy( mPostalCodeEdit );
301 topLayout->addWidget( mPostalCodeEdit, 5, 1 );
302
303 label = new QLabel( i18n( "Country:" ), page );
304 topLayout->addWidget( label, 6, 0 );
305 mCountryCombo = new KComboBox( page );
306
307 mCountryCombo->setMaximumWidth( maxwid -10 );
308 mCountryCombo->setEditable( true );
309 mCountryCombo->setDuplicatesEnabled( false );
310 mCountryCombo->setAutoCompletion( true );
311 fillCountryCombo();
312 label->setBuddy( mCountryCombo );
313 topLayout->addWidget( mCountryCombo, 6, 1 );
314 mCountryCombo->setSizeLimit( 8);
315 mPreferredCheckBox = new QCheckBox( i18n( "This is the preferred address" ), page );
316 topLayout->addMultiCellWidget( mPreferredCheckBox, 7, 7, 0, 1 );
317 /*
318 KSeparator *sep = new KSeparator( KSeparator::HLine, page );
319 topLayout->addMultiCellWidget( sep, 8, 8, 0, 1 );
320 */
321 QHBox *buttonBox = new QHBox( page );
322 buttonBox->setSpacing( spacingHint() );
323 topLayout->addMultiCellWidget( buttonBox, 9, 9, 0, 1 );
324
325 QPushButton *addButton = new QPushButton( i18n( "New..." ), buttonBox );
326 connect( addButton, SIGNAL( clicked() ), SLOT( addAddress() ) );
327
328 mRemoveButton = new QPushButton( i18n( "Remove" ), buttonBox );
329 connect( mRemoveButton, SIGNAL( clicked() ), SLOT( removeAddress() ) );
330
331 mChangeTypeButton = new QPushButton( i18n( "Change Type" ), buttonBox );
332 connect( mChangeTypeButton, SIGNAL( clicked() ), SLOT( changeType() ) );
333
334 mTypeCombo->updateTypes();
335 mTypeCombo->setCurrentItem( selected );
336
337 updateAddressEdits();
338
339 connect( mTypeCombo, SIGNAL( activated( int ) ),
340 SLOT( updateAddressEdits() ) );
341 connect( mStreetTextEdit, SIGNAL( textChanged() ), SLOT( modified() ) );
342 connect( mPOBoxEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
343 connect( mLocalityEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
344 connect( mRegionEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
345 connect( mPostalCodeEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
346 connect( mCountryCombo, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
347 connect( mPreferredCheckBox, SIGNAL( toggled( bool ) ), SLOT( modified() ) );
348
349#ifndef KAB_EMBEDDED
350 KAcceleratorManager::manage( this );
351#else //KAB_EMBEDDED
352//US qDebug("AddressEditDialog::AddressEditDialog has to be changed 2");
353#endif //KAB_EMBEDDED
354
355 mChanged = false;
356
357 bool state = (mAddressList.count() > 0);
358 mRemoveButton->setEnabled( state );
359 mChangeTypeButton->setEnabled( state );
360#ifndef DESKTOP_VERSION
361 showMaximized();
362#endif
363}
364
365AddressEditDialog::~AddressEditDialog()
366{
367}
368
369KABC::Address::List AddressEditDialog::addresses()
370{
371 saveAddress( *(mTypeCombo->selectedElement()) );
372
373 return mAddressList;
374}
375
376bool AddressEditDialog::changed() const
377{
378 return mChanged;
379}
380
381void AddressEditDialog::addAddress()
382{
383 AddressTypeDialog dlg( mTypeCombo->selectedType(), this );
384 if ( dlg.exec() ) {
385 mAddressList.append( Address( dlg.type() ) );
386
387 mTypeCombo->updateTypes();
388 mTypeCombo->setCurrentItem( mTypeCombo->count() - 1 );
389 updateAddressEdits();
390
391 modified();
392
393 mRemoveButton->setEnabled( true );
394 mChangeTypeButton->setEnabled( true );
395 }
396}
397
398void AddressEditDialog::removeAddress()
399{
400 if ( mAddressList.count() > 0 ) {
401 KABC::Address::List::Iterator it = mTypeCombo->selectedElement();
402 if ( mPreviousAddress && mPreviousAddress->id() == (*it).id() )
403 mPreviousAddress = 0;
404
405 mAddressList.remove( it );
406 mTypeCombo->updateTypes();
407 updateAddressEdits();
408
409 modified();
410 }
411
412 bool state = ( mAddressList.count() > 0 );
413 mRemoveButton->setEnabled( state );
414 mChangeTypeButton->setEnabled( state );
415}
416
417void AddressEditDialog::changeType()
418{
419 KABC::Address::List::Iterator a = mTypeCombo->selectedElement();
420
421 AddressTypeDialog dlg( (*a).type(), this );
422 if ( dlg.exec() ) {
423 (*a).setType( dlg.type() );
424
425 mTypeCombo->updateTypes();
426
427 modified();
428 }
429}
430
431void AddressEditDialog::updateAddressEdits()
432{
433 if ( mPreviousAddress )
434 saveAddress( *mPreviousAddress );
435
436 KABC::Address::List::Iterator it = mTypeCombo->selectedElement();
437 KABC::Address a = *it;
438 mPreviousAddress = &(*it);
439
440 bool tmp = mChanged;
441
442 mStreetTextEdit->setText( a.street() );
443 mRegionEdit->setText( a.region() );
444 mLocalityEdit->setText( a.locality() );
445 mPostalCodeEdit->setText( a.postalCode() );
446 mPOBoxEdit->setText( a.postOfficeBox() );
447
448#ifndef KAB_EMBEDDED
449 mCountryCombo->setCurrentText( a.country() );
450#else //KAB_EMBEDDED
451 mCountryCombo->setEditText( a.country() );
452//US qDebug("AddressEditDialog::updateAddressEdits has to be changed 1");
453#endif //KAB_EMBEDDED
454
455 mPreferredCheckBox->setChecked( a.type() & KABC::Address::Pref );
456
457 mStreetTextEdit->setFocus();
458
459 mChanged = tmp;
460}
461
462void AddressEditDialog::modified()
463{
464 mChanged = true;
465}
466
467void AddressEditDialog::saveAddress( KABC::Address &addr )
468{
469 addr.setLocality( mLocalityEdit->text() );
470 addr.setRegion( mRegionEdit->text() );
471 addr.setPostalCode( mPostalCodeEdit->text() );
472 addr.setCountry( mCountryCombo->currentText() );
473 addr.setPostOfficeBox( mPOBoxEdit->text() );
474 addr.setStreet( mStreetTextEdit->text() );
475
476
477 if ( mPreferredCheckBox->isChecked() ) {
478 KABC::Address::List::Iterator it;
479 for ( it = mAddressList.begin(); it != mAddressList.end(); ++it )
480 (*it).setType( (*it).type() & ~( KABC::Address::Pref ) );
481
482 addr.setType( addr.type() | KABC::Address::Pref );
483 }
484}
485
486void AddressEditDialog::fillCountryCombo()
487{
488 QString country[] = {
489 i18n( "Afghanistan" ), i18n( "Albania" ), i18n( "Algeria" ),
490 i18n( "American Samoa" ), i18n( "Andorra" ), i18n( "Angola" ),
491 i18n( "Anguilla" ), i18n( "Antarctica" ), i18n( "Antigua and Barbuda" ),
492 i18n( "Argentina" ), i18n( "Armenia" ), i18n( "Aruba" ),
493 i18n( "Ashmore and Cartier Islands" ), i18n( "Australia" ),
494 i18n( "Austria" ), i18n( "Azerbaijan" ), i18n( "Bahamas" ),
495 i18n( "Bahrain" ), i18n( "Bangladesh" ), i18n( "Barbados" ),
496 i18n( "Belarus" ), i18n( "Belgium" ), i18n( "Belize" ),
497 i18n( "Benin" ), i18n( "Bermuda" ), i18n( "Bhutan" ),
498 i18n( "Bolivia" ), i18n( "Bosnia and Herzegovina" ), i18n( "Botswana" ),
499 i18n( "Brazil" ), i18n( "Brunei" ), i18n( "Bulgaria" ),
500 i18n( "Burkina Faso" ), i18n( "Burundi" ), i18n( "Cambodia" ),
501 i18n( "Cameroon" ), i18n( "Canada" ), i18n( "Cape Verde" ),
502 i18n( "Cayman Islands" ), i18n( "Central African Republic" ),
503 i18n( "Chad" ), i18n( "Chile" ), i18n( "China" ), i18n( "Colombia" ),
504 i18n( "Comoros" ), i18n( "Congo" ), i18n( "Congo, Dem. Rep." ),
505 i18n( "Costa Rica" ), i18n( "Croatia" ),
506 i18n( "Cuba" ), i18n( "Cyprus" ), i18n( "Czech Republic" ),
507 i18n( "Denmark" ), i18n( "Djibouti" ),
508 i18n( "Dominica" ), i18n( "Dominican Republic" ), i18n( "Ecuador" ),
509 i18n( "Egypt" ), i18n( "El Salvador" ), i18n( "Equatorial Guinea" ),
510 i18n( "Eritrea" ), i18n( "Estonia" ), i18n( "England" ),
511 i18n( "Ethiopia" ), i18n( "European Union" ), i18n( "Faroe Islands" ),
512 i18n( "Fiji" ), i18n( "Finland" ), i18n( "France" ),
513 i18n( "French Polynesia" ), i18n( "Gabon" ), i18n( "Gambia" ),
514 i18n( "Georgia" ), i18n( "Germany" ), i18n( "Ghana" ),
515 i18n( "Greece" ), i18n( "Greenland" ), i18n( "Grenada" ),
516 i18n( "Guam" ), i18n( "Guatemala" ), i18n( "Guinea" ),
517 i18n( "Guinea-Bissau" ), i18n( "Guyana" ), i18n( "Haiti" ),
518 i18n( "Honduras" ), i18n( "Hong Kong" ), i18n( "Hungary" ),
519 i18n( "Iceland" ), i18n( "India" ), i18n( "Indonesia" ),
520 i18n( "Iran" ), i18n( "Iraq" ), i18n( "Ireland" ),
521 i18n( "Israel" ), i18n( "Italy" ), i18n( "Ivory Coast" ),
522 i18n( "Jamaica" ), i18n( "Japan" ), i18n( "Jordan" ),
523 i18n( "Kazakhstan" ), i18n( "Kenya" ), i18n( "Kiribati" ),
524 i18n( "Korea, North" ), i18n( "Korea, South" ),
525 i18n( "Kuwait" ), i18n( "Kyrgyzstan" ), i18n( "Laos" ),
526 i18n( "Latvia" ), i18n( "Lebanon" ), i18n( "Lesotho" ),
527 i18n( "Liberia" ), i18n( "Libya" ), i18n( "Liechtenstein" ),
528 i18n( "Lithuania" ), i18n( "Luxembourg" ), i18n( "Macau" ),
529 i18n( "Madagascar" ), i18n( "Malawi" ), i18n( "Malaysia" ),
530 i18n( "Maldives" ), i18n( "Mali" ), i18n( "Malta" ),
531 i18n( "Marshall Islands" ), i18n( "Martinique" ), i18n( "Mauritania" ),
532 i18n( "Mauritius" ), i18n( "Mexico" ),
533 i18n( "Micronesia, Federated States Of" ), i18n( "Moldova" ),
534 i18n( "Monaco" ), i18n( "Mongolia" ), i18n( "Montserrat" ),
535 i18n( "Morocco" ), i18n( "Mozambique" ), i18n( "Myanmar" ),
536 i18n( "Namibia" ),
537 i18n( "Nauru" ), i18n( "Nepal" ), i18n( "Netherlands" ),
538 i18n( "Netherlands Antilles" ), i18n( "New Caledonia" ),
539 i18n( "New Zealand" ), i18n( "Nicaragua" ), i18n( "Niger" ),
540 i18n( "Nigeria" ), i18n( "Niue" ), i18n( "North Korea" ),
541 i18n( "Northern Ireland" ), i18n( "Northern Mariana Islands" ),
542 i18n( "Norway" ), i18n( "Oman" ), i18n( "Pakistan" ), i18n( "Palau" ),
543 i18n( "Palestinian" ), i18n( "Panama" ), i18n( "Papua New Guinea" ),
544 i18n( "Paraguay" ), i18n( "Peru" ), i18n( "Philippines" ),
545 i18n( "Poland" ), i18n( "Portugal" ), i18n( "Puerto Rico" ),
546 i18n( "Qatar" ), i18n( "Romania" ), i18n( "Russia" ), i18n( "Rwanda" ),
547 i18n( "St. Kitts and Nevis" ), i18n( "St. Lucia" ),
548 i18n( "St. Vincent and the Grenadines" ), i18n( "San Marino" ),
549 i18n( "Sao Tome and Principe" ), i18n( "Saudi Arabia" ),
550 i18n( "Senegal" ), i18n( "Serbia & Montenegro" ), i18n( "Seychelles" ),
551 i18n( "Sierra Leone" ), i18n( "Singapore" ), i18n( "Slovakia" ),
552 i18n( "Slovenia" ), i18n( "Solomon Islands" ), i18n( "Somalia" ),
553 i18n( "South Africa" ), i18n( "South Korea" ), i18n( "Spain" ),
554 i18n( "Sri Lanka" ), i18n( "St. Kitts and Nevis" ), i18n( "Sudan" ),
555 i18n( "Suriname" ), i18n( "Swaziland" ), i18n( "Sweden" ),
556 i18n( "Switzerland" ), i18n( "Syria" ), i18n( "Taiwan" ),
557 i18n( "Tajikistan" ), i18n( "Tanzania" ), i18n( "Thailand" ),
558 i18n( "Tibet" ), i18n( "Togo" ), i18n( "Tonga" ),
559 i18n( "Trinidad and Tobago" ), i18n( "Tunisia" ), i18n( "Turkey" ),
560 i18n( "Turkmenistan" ), i18n( "Turks and Caicos Islands" ),
561 i18n( "Tuvalu" ), i18n( "Uganda " ), i18n( "Ukraine" ),
562 i18n( "United Arab Emirates" ), i18n( "United Kingdom" ),
563 i18n( "United States" ), i18n( "Uruguay" ), i18n( "Uzbekistan" ),
564 i18n( "Vanuatu" ), i18n( "Vatican City" ), i18n( "Venezuela" ),
565 i18n( "Vietnam" ), i18n( "Western Samoa" ), i18n( "Yemen" ),
566 i18n( "Yugoslavia" ), i18n( "Zaire" ), i18n( "Zambia" ),
567 i18n( "Zimbabwe" ),
568 ""
569 };
570
571 QStringList countries;
572 for ( int i = 0; !country[ i ].isEmpty(); ++i )
573 countries.append( country[ i ] );
574
575 countries.sort();
576
577 mCountryCombo->insertStringList( countries );
578}
579
580
581AddressTypeDialog::AddressTypeDialog( int type, QWidget *parent )
582 : KDialogBase( Plain, i18n( "Edit Address Type" ), Ok | Cancel, Ok,
583 parent, "AddressTypeDialog" )
584{
585 QWidget *page = plainPage();
586 QVBoxLayout *layout = new QVBoxLayout( page );
587
588 mGroup = new QButtonGroup( 2, Horizontal, i18n( "Address Types" ), page );
589 layout->addWidget( mGroup );
590
591 mTypeList = KABC::Address::typeList();
592 mTypeList.remove( KABC::Address::Pref );
593
594 KABC::Address::TypeList::Iterator it;
595 for ( it = mTypeList.begin(); it != mTypeList.end(); ++it )
596 new QCheckBox( KABC::Address::typeLabel( *it ), mGroup );
597
598 for ( int i = 0; i < mGroup->count(); ++i ) {
599 QCheckBox *box = (QCheckBox*)mGroup->find( i );
600 box->setChecked( type & mTypeList[ i ] );
601 }
602}
603
604AddressTypeDialog::~AddressTypeDialog()
605{
606}
607
608int AddressTypeDialog::type() const
609{
610 int type = 0;
611 for ( int i = 0; i < mGroup->count(); ++i ) {
612 QCheckBox *box = (QCheckBox*)mGroup->find( i );
613 if ( box->isChecked() )
614 type += mTypeList[ i ];
615 }
616
617 return type;
618}
619
620#ifndef KAB_EMBEDDED
621#include "addresseditwidget.moc"
622#endif //KAB_EMBEDDED
diff --git a/kaddressbook/addresseditwidget.h b/kaddressbook/addresseditwidget.h
new file mode 100644
index 0000000..bc96d74
--- a/dev/null
+++ b/kaddressbook/addresseditwidget.h
@@ -0,0 +1,159 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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#ifndef ADDRESSEDITWIDGET_H
25#define ADDRESSEDITWIDGET_H
26
27#include <qwidget.h>
28
29#include <kdialogbase.h>
30#include <kabc/address.h>
31#include <kabc/addressee.h>
32
33#include "addresseeconfig.h"
34#include "typecombo.h"
35
36class QButtonGroup;
37class QCheckBox;
38class QListView;
39#ifndef KAB_EMBEDDED
40class QTextEdit;
41#else //KAB_EMBEDDED
42class QMultiLineEdit;
43#endif //KAB_EMBEDDED
44class QToolButton;
45
46class KComboBox;
47class KLineEdit;
48class KListView;
49
50typedef TypeCombo<KABC::Address> AddressTypeCombo;
51
52/**
53 Editor widget for addresses.
54 */
55class AddressEditWidget : public QWidget
56{
57 Q_OBJECT
58
59 public:
60 AddressEditWidget( QWidget *parent, const char *name = 0 );
61 ~AddressEditWidget();
62
63 KABC::Address::List addresses();
64 void setAddresses( const KABC::Addressee &addr,
65 const KABC::Address::List &list );
66
67 void updateTypeCombo( const KABC::Address::List&, KComboBox* );
68 KABC::Address currentAddress( KComboBox*, int );
69
70 signals:
71 void modified();
72
73 protected slots:
74 void updateAddressEdit();
75
76 void edit();
77
78 private:
79 AddresseeConfig * mConfig;
80 AddressTypeCombo *mTypeCombo;
81
82 QPushButton *mEditButton;
83#ifndef KAB_EMBEDDED
84 QTextEdit *mAddressTextEdit;
85#else //KAB_EMBEDDED
86 QMultiLineEdit *mAddressTextEdit;
87#endif //KAB_EMBEDDED
88
89 KABC::Address::List mAddressList;
90 KABC::Addressee mAddressee;
91 int mIndex;
92};
93
94/**
95 Dialog for editing address details.
96 */
97class AddressEditDialog : public KDialogBase
98{
99 Q_OBJECT
100
101 public:
102 AddressEditDialog( const KABC::Address::List &list, int selected,
103 QWidget *parent, const char *name = 0 );
104 ~AddressEditDialog();
105
106 KABC::Address::List addresses();
107 bool changed() const;
108
109 protected slots:
110 void addAddress();
111 void removeAddress();
112 void changeType();
113
114 void updateAddressEdits();
115 void modified();
116
117 private:
118 void saveAddress( KABC::Address &addr );
119 void fillCountryCombo();
120
121 AddressTypeCombo *mTypeCombo;
122#ifndef KAB_EMBEDDED
123 QTextEdit *mStreetTextEdit;
124#else //KAB_EMBEDDED
125 QMultiLineEdit *mStreetTextEdit;
126#endif //KAB_EMBEDDED
127 KComboBox *mCountryCombo;
128 KLineEdit *mRegionEdit;
129 KLineEdit *mLocalityEdit;
130 KLineEdit *mPostalCodeEdit;
131 KLineEdit *mPOBoxEdit;
132 QCheckBox *mPreferredCheckBox;
133
134 QPushButton *mRemoveButton;
135 QPushButton *mChangeTypeButton;
136
137 KABC::Address::List mAddressList;
138 KABC::Address *mPreviousAddress;
139 bool mChanged;
140};
141
142/**
143 Dialog for selecting an address type.
144 */
145class AddressTypeDialog : public KDialogBase
146{
147 public:
148 AddressTypeDialog( int type, QWidget *parent );
149 ~AddressTypeDialog();
150
151 int type() const;
152
153 private:
154 QButtonGroup *mGroup;
155
156 KABC::Address::TypeList mTypeList;
157};
158
159#endif
diff --git a/kaddressbook/addresseeconfig.cpp b/kaddressbook/addresseeconfig.cpp
new file mode 100644
index 0000000..ea0436f
--- a/dev/null
+++ b/kaddressbook/addresseeconfig.cpp
@@ -0,0 +1,94 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Tobias Koenig <tokoe@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 "addresseeconfig.h"
25#include "kabprefs.h"
26//US
27#include <kstandarddirs.h>
28#include <qfileinfo.h>
29
30using namespace KABC;
31
32static AddresseeConfig* extern_AddresseeConfig = 0;
33static KConfig * extern_Config = 0;
34
35AddresseeConfig::AddresseeConfig()
36{
37
38
39}
40AddresseeConfig::~AddresseeConfig()
41{
42 delete AddresseeConfig::config();
43}
44
45
46AddresseeConfig* AddresseeConfig::instance()
47{
48 if ( ! extern_AddresseeConfig )
49 extern_AddresseeConfig = new AddresseeConfig();
50 return extern_AddresseeConfig;
51}
52KConfig* AddresseeConfig::config()
53{
54 if ( ! extern_Config ) {
55 QString conf = locateLocal("config", "kaddressrc");
56 extern_Config= new KConfig( conf );
57 }
58 return extern_Config;
59}
60
61
62void AddresseeConfig::setUid( const QString & uid )
63{
64 AddresseeConfig::config()->setGroup( uid );
65 mUid = uid;
66}
67
68void AddresseeConfig::setAutomaticNameParsing( bool value )
69{
70 AddresseeConfig::config()->writeEntry( "AutomaticNameParsing", value );
71}
72
73 bool AddresseeConfig::automaticNameParsing()
74{
75
76 return AddresseeConfig::config()->readBoolEntry( "AutomaticNameParsing",
77 KABPrefs::instance()->mAutomaticNameParsing );
78}
79
80void AddresseeConfig::setNoDefaultAddrTypes( const QValueList<int> &types )
81{
82 AddresseeConfig::config()->writeEntry( "NoDefaultAddrTypes", types );
83 AddresseeConfig::config()->sync();
84}
85
86 QValueList<int> AddresseeConfig::noDefaultAddrTypes() const
87{
88 return AddresseeConfig::config()->readIntListEntry( "NoDefaultAddrTypes" );
89}
90
91void AddresseeConfig::remove( const QString & uid )
92{
93 AddresseeConfig::config()->deleteGroup( uid );
94}
diff --git a/kaddressbook/addresseeconfig.h b/kaddressbook/addresseeconfig.h
new file mode 100644
index 0000000..47fbdd6
--- a/dev/null
+++ b/kaddressbook/addresseeconfig.h
@@ -0,0 +1,55 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Tobias Koenig <tokoe@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#ifndef ADDRESSEECONFIG_H
25#define ADDRESSEECONFIG_H
26
27#include <kabc/addressee.h>
28#include <kconfig.h>
29
30using namespace KABC;
31
32class AddresseeConfig
33{
34 public:
35 AddresseeConfig();
36 ~AddresseeConfig();
37 static AddresseeConfig* instance();
38 static KConfig* config();
39
40 Addressee addressee();
41
42 void setUid( const QString & uid );
43 void setAutomaticNameParsing( bool value );
44 bool automaticNameParsing();
45
46 void setNoDefaultAddrTypes( const QValueList<int> &types );
47 QValueList<int> noDefaultAddrTypes() const;
48
49 void remove( const QString & uid);
50
51 private:
52 QString mUid;
53};
54
55#endif
diff --git a/kaddressbook/addresseeeditordialog.cpp b/kaddressbook/addresseeeditordialog.cpp
new file mode 100644
index 0000000..102138e
--- a/dev/null
+++ b/kaddressbook/addresseeeditordialog.cpp
@@ -0,0 +1,129 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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 <qlayout.h>
25
26#include <kdebug.h>
27#include <klocale.h>
28#include <kglobal.h>
29
30#include "addresseeeditorwidget.h"
31#include "kabcore.h"
32
33#include "addresseeeditordialog.h"
34
35AddresseeEditorDialog::AddresseeEditorDialog( KABCore *core, QWidget *parent,
36 const char *name )
37 : KDialogBase( KDialogBase::Plain, i18n( "Edit Contact" ),
38 KDialogBase::Ok | KDialogBase::Cancel | KDialogBase::Apply,
39 KDialogBase::Ok, parent, name, false )
40{
41#ifdef KAB_EMBEDDED
42 resize( KMIN(KGlobal::getDesktopWidth()-10, 490), KMIN(KGlobal::getDesktopHeight()-50, 300));
43#endif //KAB_EMBEDDED
44
45 kdDebug(5720) << "AddresseeEditorDialog()" << endl;
46
47 QWidget *page = plainPage();
48
49 QVBoxLayout *layout = new QVBoxLayout( page );
50
51 mEditorWidget = new AddresseeEditorWidget( core, false, page );
52 connect( mEditorWidget, SIGNAL( modified( const KABC::Addressee::List& ) ),
53 SLOT( widgetModified() ) );
54 layout->addWidget( mEditorWidget );
55
56 enableButton( KDialogBase::Apply, false );
57}
58
59AddresseeEditorDialog::~AddresseeEditorDialog()
60{
61 kdDebug(5720) << "~AddresseeEditorDialog()" << endl;
62
63 emit editorDestroyed( mEditorWidget->addressee().uid() );
64}
65
66void AddresseeEditorDialog::setAddressee( const KABC::Addressee &addr )
67{
68 enableButton( KDialogBase::Apply, false );
69
70 mEditorWidget->setAddressee( addr );
71}
72
73KABC::Addressee AddresseeEditorDialog::addressee()
74{
75 return mEditorWidget->addressee();
76}
77
78bool AddresseeEditorDialog::dirty()
79{
80 return mEditorWidget->dirty();
81}
82
83void AddresseeEditorDialog::slotApply()
84{
85 if ( mEditorWidget->dirty() ) {
86 mEditorWidget->save();
87 emit contactModified( mEditorWidget->addressee() );
88 }
89
90 enableButton( KDialogBase::Apply, false );
91
92 KDialogBase::slotApply();
93}
94
95void AddresseeEditorDialog::slotOk()
96{
97 slotApply();
98
99 KDialogBase::slotOk();
100
101 // Destroy this dialog
102#ifndef KAB_EMBEDDED
103 delayedDestruct();
104#else //KAB_EMBEDDED
105 delete this;
106#endif //KAB_EMBEDDED
107}
108
109void AddresseeEditorDialog::widgetModified()
110{
111 enableButton( KDialogBase::Apply, true );
112}
113
114void AddresseeEditorDialog::slotCancel()
115{
116 KDialogBase::slotCancel();
117
118 // Destroy this dialog
119#ifndef KAB_EMBEDDED
120 delayedDestruct();
121#else //KAB_EMBEDDED
122 delete this;
123#endif //KAB_EMBEDDED
124
125}
126
127#ifndef KAB_EMBEDDED
128#include "addresseeeditordialog.moc"
129#endif //KAB_EMBEDDED
diff --git a/kaddressbook/addresseeeditordialog.h b/kaddressbook/addresseeeditordialog.h
new file mode 100644
index 0000000..1a00d3a
--- a/dev/null
+++ b/kaddressbook/addresseeeditordialog.h
@@ -0,0 +1,62 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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#ifndef ADDRESSEEEDITORDIALOG_H
25#define ADDRESSEEEDITORDIALOG_H
26
27#include <kdialogbase.h>
28
29#include <kabc/addressbook.h>
30
31class AddresseeEditorWidget;
32class QWidget;
33class KABCore;
34
35class AddresseeEditorDialog : public KDialogBase
36{
37 Q_OBJECT
38
39 public:
40 AddresseeEditorDialog( KABCore *core, QWidget *parent, const char *name = 0 );
41 ~AddresseeEditorDialog();
42
43 void setAddressee( const KABC::Addressee& );
44 KABC::Addressee addressee();
45
46 bool dirty();
47
48 signals:
49 void contactModified( const KABC::Addressee& );
50 void editorDestroyed( const QString& );
51
52 protected slots:
53 virtual void slotApply();
54 virtual void slotOk();
55 virtual void slotCancel();
56 void widgetModified();
57
58 private:
59 AddresseeEditorWidget *mEditorWidget;
60};
61
62#endif
diff --git a/kaddressbook/addresseeeditorwidget.cpp b/kaddressbook/addresseeeditorwidget.cpp
new file mode 100644
index 0000000..4365ee5
--- a/dev/null
+++ b/kaddressbook/addresseeeditorwidget.cpp
@@ -0,0 +1,1284 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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 <qcheckbox.h>
25#include <qhbox.h>
26#include <qlabel.h>
27#include <qlayout.h>
28#include <qlistbox.h>
29#include <qpushbutton.h>
30#include <qtabwidget.h>
31
32#ifndef KAB_EMBEDDED
33#include <qtextedit.h>
34
35#include <kaccelmanager.h>
36#include "keywidget.h"
37#include "soundwidget.h"
38
39#else //KAB_EMBEDDED
40#include <qmultilineedit.h>
41#endif //KAB_EMBEDDED
42
43
44#include "keywidget.h"
45#include "geowidget.h"
46#include "imagewidget.h"
47#include "nameeditdialog.h"
48#include "phoneeditwidget.h"
49#include "secrecywidget.h"
50
51
52#include <qtoolbutton.h>
53#include <qtooltip.h>
54
55#include <kapplication.h>
56#include <kconfig.h>
57#include <kcombobox.h>
58#include <kdebug.h>
59#include <kdialogbase.h>
60#include <kglobal.h>
61#include <kiconloader.h>
62#include <klineedit.h>
63#include <klocale.h>
64#include <kmessagebox.h>
65#include <kseparator.h>
66#include <ksqueezedtextlabel.h>
67
68#include <libkdepim/categoryeditdialog.h>
69#include <libkdepim/categoryselectdialog.h>
70
71#include <libkdepim/kdateedit.h>
72
73#include "addresseditwidget.h"
74#include "emaileditwidget.h"
75#include "kabcore.h"
76#include "kabprefs.h"
77
78#include "addresseeeditorwidget.h"
79
80
81
82AddresseeEditorWidget::AddresseeEditorWidget( KABCore *core, bool isExtension,
83 QWidget *parent, const char *name )
84 : ExtensionWidget( core, parent, name ), mIsExtension( isExtension ),
85 mBlockSignals( false )
86{
87
88 mAConfig = AddresseeConfig::instance();
89
90 kdDebug(5720) << "AddresseeEditorWidget()" << endl;
91 mFormattedNameType = NameEditDialog::CustomName;
92 initGUI();
93 mCategoryDialog = 0;
94 mCategoryEditDialog = 0;
95
96 // Load the empty addressee as defaults
97 load();
98
99 mDirty = false;
100}
101
102AddresseeEditorWidget::~AddresseeEditorWidget()
103{
104 kdDebug(5720) << "~AddresseeEditorWidget()" << endl;
105}
106
107void AddresseeEditorWidget::contactsSelectionChanged()
108{
109 KABC::Addressee::List list = selectedContacts();
110
111 mAddressee = list[ 0 ];
112 load();
113}
114
115void AddresseeEditorWidget::setAddressee( const KABC::Addressee &addr )
116{
117 mAddressee = addr;
118 load();
119}
120
121const KABC::Addressee &AddresseeEditorWidget::addressee()
122{
123 return mAddressee;
124}
125
126void AddresseeEditorWidget::textChanged( const QString& )
127{
128 emitModified();
129}
130
131void AddresseeEditorWidget::initGUI()
132{
133 QVBoxLayout *layout = new QVBoxLayout( this );
134
135 mTabWidget = new QTabWidget( this );
136 layout->addWidget( mTabWidget );
137
138 setupTab1();
139 setupTab1_1();
140 setupTab2();
141 setupTab2_1();
142 setupTab3();
143 setupTab3_1();
144
145 mNameEdit->setFocus();
146
147 connect( mTabWidget, SIGNAL( currentChanged(QWidget*) ),
148 SLOT( pageChanged(QWidget*) ) );
149}
150
151void AddresseeEditorWidget::setupTab1()
152{
153 // This is the General tab
154 QWidget *tab1 = new QWidget( mTabWidget );
155
156//US QGridLayout *layout = new QGridLayout( tab1, 11, 7 );
157 QGridLayout *layout = new QGridLayout( tab1, 7, 1 );
158 layout->setMargin( KDialogBase::marginHintSmall() );
159 layout->setSpacing( KDialogBase::spacingHintSmall() );
160
161 QLabel *label;
162 KSeparator* bar;
163 QPushButton *button;
164
165 //////////////////////////////////
166 // Upper left group (person info)
167
168 // Person icon
169 /* LR
170 label = new QLabel( tab1 );
171//US ambiguous call. Add one more parameter
172//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop ) );
173 label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop, 0 ) );
174 layout->addMultiCellWidget( label, 0, 1, 0, 0 );
175 */
176 // First name
177 button = new QPushButton( i18n( "Name..." ), tab1 );
178//US QToolTip::add( button, i18n( "Edit the contact's name" ) );
179 mNameEdit = new KLineEdit( tab1, "mNameEdit" );
180 connect( mNameEdit, SIGNAL( textChanged( const QString& ) ),
181 SLOT( nameTextChanged( const QString& ) ) );
182 connect( button, SIGNAL( clicked() ), SLOT( nameButtonClicked() ) );
183
184 mNameLabel = new KSqueezedTextLabel( tab1 );
185 mNameLabel->hide();
186
187 layout->addWidget( button, 0, 0 );
188 layout->addWidget( mNameEdit, 0, 1 );
189 layout->addWidget( mNameLabel, 0, 1 );
190
191 label = new QLabel( i18n( "Role:" ), tab1 );
192 mRoleEdit = new KLineEdit( tab1 );
193 connect( mRoleEdit, SIGNAL( textChanged( const QString& ) ),
194 SLOT( textChanged( const QString& ) ) );
195 label->setBuddy( mRoleEdit );
196 layout->addWidget( label, 1, 0 );
197 layout->addWidget( mRoleEdit, 1, 1 );
198
199 // Organization
200 label = new QLabel( i18n( "Organization:" ), tab1 );
201 mOrgEdit = new KLineEdit( tab1 );
202 label->setBuddy( mOrgEdit );
203 connect( mOrgEdit, SIGNAL( textChanged( const QString& ) ),
204 SLOT( textChanged( const QString& ) ) );
205 layout->addWidget( label, 2, 0 );
206 layout->addWidget( mOrgEdit, 2, 1 );
207
208 // File as (formatted name)
209 label = new QLabel( i18n( "Formatted name:" ), tab1 );
210 mFormattedNameLabel = new KSqueezedTextLabel( tab1 );
211 layout->addWidget( label, 3, 0 );
212 layout->addWidget( mFormattedNameLabel, 3, 1 );
213 /* LR
214 // Left hand separator. This separator doesn't go all the way
215 // across so the dialog still flows from top to bottom
216 bar = new KSeparator( KSeparator::HLine, tab1 );
217 layout->addMultiCellWidget( bar, 4, 4, 0, 2 );
218 */
219 //////////////////////////////////////
220
221 /* LR
222 // Phone numbers (upper right)
223 label = new QLabel( tab1 );
224//US loadIcon call is ambiguous. Add one more parameter
225//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) );
226 label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) );
227//US layout->addMultiCellWidget( label, 0, 1, 3, 3 );
228 layout->addMultiCellWidget( label, 5, 6, 0, 0 );
229 */
230 mPhoneEditWidget = new PhoneEditWidget( tab1 );
231 connect( mPhoneEditWidget, SIGNAL( modified() ), SLOT( emitModified() ) );
232//US layout->addMultiCellWidget( mPhoneEditWidget, 0, 3, 4, 6 );
233 int iii;
234#ifndef DESKTOP_VERSION
235 iii = 7;
236#else
237 iii = 8;
238#endif
239 layout->addMultiCellWidget( mPhoneEditWidget, 4, iii, 0, 1 );
240 ++iii;
241 /* LR
242 bar = new KSeparator( KSeparator::HLine, tab1 );
243//US layout->addMultiCellWidget( bar, 4, 4, 3, 6 );
244 layout->addMultiCellWidget( bar, 9, 9, 0, 2 );
245 */
246/*US
247 //////////////////////////////////////
248 // Addresses (lower left)
249 label = new QLabel( tab1 );
250//US loadIcon call is ambiguous. Add one more parameter
251//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "gohome", KIcon::Desktop ) );
252 label->setPixmap( KGlobal::iconLoader()->loadIcon( "gohome", KIcon::Desktop, 0 ) );
253 layout->addMultiCellWidget( label, 5, 6, 0, 0 );
254
255 mAddressEditWidget = new AddressEditWidget( tab1 );
256 connect( mAddressEditWidget, SIGNAL( modified() ), SLOT( emitModified() ) );
257 layout->addMultiCellWidget( mAddressEditWidget, 5, 9, 1, 2 );
258
259 //////////////////////////////////////
260 // Email / Web (lower right)
261 label = new QLabel( tab1 );
262//US loadIcon call is ambiguous. Add one more parameter
263//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "email", KIcon::Desktop) );
264 label->setPixmap( KGlobal::iconLoader()->loadIcon( "email", KIcon::Desktop, 0) );
265 layout->addMultiCellWidget( label, 5, 6, 3, 3 );
266
267 mEmailWidget = new EmailEditWidget( tab1 );
268 connect( mEmailWidget, SIGNAL( modified() ), SLOT( emitModified() ) );
269 layout->addMultiCellWidget( mEmailWidget, 5, 6, 4, 6 );
270
271 // add the separator
272 bar = new KSeparator( KSeparator::HLine, tab1 );
273 layout->addMultiCellWidget( bar, 7, 7, 3, 6 );
274
275 label = new QLabel( tab1 );
276//US loadIcon call is ambiguous. Add one more parameter
277//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "homepage", KIcon::Desktop) );
278 label->setPixmap( KGlobal::iconLoader()->loadIcon( "homepage", KIcon::Desktop, 0) );
279 layout->addMultiCellWidget( label, 8, 9, 3, 3 );
280
281 label = new QLabel( i18n( "URL:" ), tab1 );
282 mURLEdit = new KLineEdit( tab1 );
283 connect( mURLEdit, SIGNAL( textChanged( const QString& ) ),
284 SLOT( textChanged( const QString& ) ) );
285 label->setBuddy( mURLEdit );
286 layout->addWidget( label, 8, 4 );
287 layout->addMultiCellWidget( mURLEdit, 8, 8, 5, 6 );
288
289 label = new QLabel( i18n( "&IM address:" ), tab1 );
290 mIMAddressEdit = new KLineEdit( tab1 );
291 connect( mIMAddressEdit, SIGNAL( textChanged( const QString& ) ),
292 SLOT( textChanged( const QString& ) ) );
293 label->setBuddy( mIMAddressEdit );
294 layout->addWidget( label, 9, 4 );
295 layout->addMultiCellWidget( mIMAddressEdit, 9, 9, 5, 6 );
296
297 layout->addColSpacing( 6, 50 );
298
299 bar = new KSeparator( KSeparator::HLine, tab1 );
300 layout->addMultiCellWidget( bar, 10, 10, 0, 6 );
301*/
302 ///////////////////////////////////////
303 QHBox *categoryBox = new QHBox( tab1 );
304 categoryBox->setSpacing( KDialogBase::spacingHint() );
305 categoryBox->setMargin( KDialogBase::marginHintSmall() );
306
307 // Categories
308 button = new QPushButton( i18n( "Categories" ), categoryBox );
309 connect( button, SIGNAL( clicked() ), SLOT( categoryButtonClicked() ) );
310
311 mCategoryEdit = new KLineEdit( categoryBox );
312 mCategoryEdit->setReadOnly( true );
313 connect( mCategoryEdit, SIGNAL( textChanged( const QString& ) ),
314 SLOT( textChanged( const QString& ) ) );
315
316 mSecrecyWidget = new SecrecyWidget( categoryBox );
317 connect( mSecrecyWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
318
319//US layout->addMultiCellWidget( categoryBox, 11, 11, 0, 6 );
320 layout->addMultiCellWidget( categoryBox, iii, iii, 0, 1 );
321
322 // Build the layout and add to the tab widget
323 layout->activate(); // required
324
325 mTabWidget->addTab( tab1, i18n( "&General" ) );
326}
327
328
329void AddresseeEditorWidget::setupTab1_1()
330{
331 // This is the Address tab
332 QWidget *tab1_1 = new QWidget( mTabWidget );
333
334//US QGridLayout *layout = new QGridLayout( tab1_1, 11, 7 );
335 QGridLayout *layout = new QGridLayout( tab1_1, 7, 2 );
336 layout->setMargin( KDialogBase::marginHintSmall() );
337 layout->setSpacing( KDialogBase::spacingHintSmall() );
338
339 QLabel *label;
340 KSeparator* bar;
341 QPushButton *button;
342
343/*US
344 //////////////////////////////////
345 // Upper left group (person info)
346
347 // Person icon
348 label = new QLabel( tab1 );
349//US ambiguous call. Add one more parameter
350//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop ) );
351 label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop, 0 ) );
352 layout->addMultiCellWidget( label, 0, 1, 0, 0 );
353
354 // First name
355 button = new QPushButton( i18n( "Name..." ), tab1 );
356 QToolTip::add( button, i18n( "Edit the contact's name" ) );
357 mNameEdit = new KLineEdit( tab1, "mNameEdit" );
358 connect( mNameEdit, SIGNAL( textChanged( const QString& ) ),
359 SLOT( nameTextChanged( const QString& ) ) );
360 connect( button, SIGNAL( clicked() ), SLOT( nameButtonClicked() ) );
361
362#ifndef KAB_EMBEDDED
363 mNameLabel = new KSqueezedTextLabel( tab1 );
364 mNameLabel->hide();
365#else //KAB_EMBEDDED
366qDebug("AddresseeEditorWidget::setupTab1 has to be changed");
367#endif //KAB_EMBEDDED
368
369 layout->addWidget( button, 0, 1 );
370 layout->addWidget( mNameEdit, 0, 2 );
371
372#ifndef KAB_EMBEDDED
373 layout->addWidget( mNameLabel, 0, 2 );
374#else //KAB_EMBEDDED
375qDebug("AddresseeEditorWidget::setupTab1 has to be changed");
376#endif //KAB_EMBEDDED
377
378 label = new QLabel( i18n( "Role:" ), tab1 );
379 mRoleEdit = new KLineEdit( tab1 );
380 connect( mRoleEdit, SIGNAL( textChanged( const QString& ) ),
381 SLOT( textChanged( const QString& ) ) );
382 label->setBuddy( mRoleEdit );
383 layout->addWidget( label, 1, 1 );
384 layout->addWidget( mRoleEdit, 1, 2 );
385
386 // Organization
387 label = new QLabel( i18n( "Organization:" ), tab1 );
388 mOrgEdit = new KLineEdit( tab1 );
389 label->setBuddy( mOrgEdit );
390 connect( mOrgEdit, SIGNAL( textChanged( const QString& ) ),
391 SLOT( textChanged( const QString& ) ) );
392 layout->addWidget( label, 2, 1 );
393 layout->addWidget( mOrgEdit, 2, 2 );
394
395 // File as (formatted name)
396 label = new QLabel( i18n( "Formatted name:" ), tab1 );
397#ifndef KAB_EMBEDDED
398 mFormattedNameLabel = new KSqueezedTextLabel( tab1 );
399#else //KAB_EMBEDDED
400qDebug("AddresseeEditorWidget::setupTab1 has to be changed");
401#endif //KAB_EMBEDDED
402 layout->addWidget( label, 3, 1 );
403#ifndef KAB_EMBEDDED
404 layout->addWidget( mFormattedNameLabel, 3, 2 );
405#else //KAB_EMBEDDED
406qDebug("AddresseeEditorWidget::setupTab1 has to be changed");
407#endif //KAB_EMBEDDED
408
409 // Left hand separator. This separator doesn't go all the way
410 // across so the dialog still flows from top to bottom
411 bar = new KSeparator( KSeparator::HLine, tab1 );
412 layout->addMultiCellWidget( bar, 4, 4, 0, 2 );
413
414 //////////////////////////////////////
415 // Phone numbers (upper right)
416 label = new QLabel( tab1 );
417//US loadIcon call is ambiguous. Add one more parameter
418//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) );
419 label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) );
420 layout->addMultiCellWidget( label, 0, 1, 3, 3 );
421
422 mPhoneEditWidget = new PhoneEditWidget( tab1 );
423 connect( mPhoneEditWidget, SIGNAL( modified() ), SLOT( emitModified() ) );
424 layout->addMultiCellWidget( mPhoneEditWidget, 0, 3, 4, 6 );
425
426 bar = new KSeparator( KSeparator::HLine, tab1 );
427 layout->addMultiCellWidget( bar, 4, 4, 3, 6 );
428*/
429 //////////////////////////////////////
430 // Addresses (lower left)
431 /* LR
432 label = new QLabel( tab1_1 );
433//US loadIcon call is ambiguous. Add one more parameter
434//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "gohome", KIcon::Desktop ) );
435 label->setPixmap( KGlobal::iconLoader()->loadIcon( "gohome", KIcon::Desktop, 0 ) );
436//US layout->addMultiCellWidget( label, 5, 6, 0, 0 );
437 layout->addMultiCellWidget( label, 0, 1, 0, 0 );
438 */
439
440 mAddressEditWidget = new AddressEditWidget( tab1_1 );
441 connect( mAddressEditWidget, SIGNAL( modified() ), SLOT( emitModified() ) );
442//US layout->addMultiCellWidget( mAddressEditWidget, 5, 9, 1, 2 );
443 layout->addMultiCellWidget( mAddressEditWidget, 0, 4, 0, 1 );
444
445//US
446/* LR
447 bar = new KSeparator( KSeparator::HLine, tab1_1 );
448 layout->addMultiCellWidget( bar, 5, 5, 0, 3 );
449*/
450
451 //////////////////////////////////////
452 // Email / Web (lower right)
453 /* LR
454 label = new QLabel( tab1_1 );
455//US loadIcon call is ambiguous. Add one more parameter
456//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "email", KIcon::Desktop) );
457 label->setPixmap( KGlobal::iconLoader()->loadIcon( "email", KIcon::Desktop, 0) );
458//US layout->addMultiCellWidget( label, 5, 6, 3, 3 );
459 layout->addMultiCellWidget( label, 6, 7, 0, 0 );
460 */
461 mEmailWidget = new EmailEditWidget( tab1_1 );
462 connect( mEmailWidget, SIGNAL( modified() ), SLOT( emitModified() ) );
463//US layout->addMultiCellWidget( mEmailWidget, 5, 6, 4, 6 );
464 layout->addMultiCellWidget( mEmailWidget, 5, 6, 0, 1 );
465
466 /* LR
467 // add the separator
468 bar = new KSeparator( KSeparator::HLine, tab1_1 );
469//US layout->addMultiCellWidget( bar, 7, 7, 3, 6 );
470 layout->addMultiCellWidget( bar, 8, 8, 0, 3 );
471
472 label = new QLabel( tab1_1 );
473//US loadIcon call is ambiguous. Add one more parameter
474//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "homepage", KIcon::Desktop) );
475 label->setPixmap( KGlobal::iconLoader()->loadIcon( "homepage", KIcon::Desktop, 0) );
476//US layout->addMultiCellWidget( label, 8, 9, 3, 3 );
477 layout->addMultiCellWidget( label, 9, 10, 0, 0 );
478 */
479 label = new QLabel( i18n( "URL:" ), tab1_1 );
480 mURLEdit = new KLineEdit( tab1_1 );
481 connect( mURLEdit, SIGNAL( textChanged( const QString& ) ),
482 SLOT( textChanged( const QString& ) ) );
483 label->setBuddy( mURLEdit );
484//US layout->addWidget( label, 8, 4 );
485 layout->addWidget( label, 7,0 );
486//US layout->addMultiCellWidget( mURLEdit, 8, 8, 5, 6 );
487 layout->addWidget( mURLEdit, 7, 1);
488
489 label = new QLabel( i18n( "&IM address:" ), tab1_1 );
490 mIMAddressEdit = new KLineEdit( tab1_1 );
491 connect( mIMAddressEdit, SIGNAL( textChanged( const QString& ) ),
492 SLOT( textChanged( const QString& ) ) );
493 label->setBuddy( mIMAddressEdit );
494//US layout->addWidget( label, 9, 4 );
495 layout->addWidget( label, 8, 0 );
496//US layout->addMultiCellWidget( mIMAddressEdit, 9, 9, 5, 6 );
497 layout->addWidget( mIMAddressEdit, 8,1 );
498
499//US layout->addColSpacing( 6, 50 );
500
501//US bar = new KSeparator( KSeparator::HLine, tab1_1 );
502//US layout->addMultiCellWidget( bar, 10, 10, 0, 6 );
503
504/*US
505 ///////////////////////////////////////
506 QHBox *categoryBox = new QHBox( tab1 );
507 categoryBox->setSpacing( KDialogBase::spacingHintSmall() );
508
509 // Categories
510 button = new QPushButton( i18n( "Categories" ), categoryBox );
511 connect( button, SIGNAL( clicked() ), SLOT( categoryButtonClicked() ) );
512
513 mCategoryEdit = new KLineEdit( categoryBox );
514 mCategoryEdit->setReadOnly( true );
515 connect( mCategoryEdit, SIGNAL( textChanged( const QString& ) ),
516 SLOT( textChanged( const QString& ) ) );
517
518 mSecrecyWidget = new SecrecyWidget( categoryBox );
519 connect( mSecrecyWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
520
521 layout->addMultiCellWidget( categoryBox, 11, 11, 0, 6 );
522*/
523 // Build the layout and add to the tab widget
524 layout->activate(); // required
525
526 mTabWidget->addTab( tab1_1, i18n( "&Address" ) );
527}
528
529
530
531void AddresseeEditorWidget::setupTab2()
532{
533 // This is the Details tab
534 QWidget *tab2 = new QWidget( mTabWidget );
535
536 QGridLayout *layout = new QGridLayout( tab2, 8, 3 );
537 layout->setMargin( KDialogBase::marginHintSmall() );
538 layout->setSpacing( KDialogBase::spacingHintSmall() );
539
540 QLabel *label;
541 KSeparator* bar;
542
543 ///////////////////////
544 // Office info
545
546 // Department
547 label = new QLabel( tab2 );
548//US loadIcon call is ambiguous. Add one more parameter
549//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "folder", KIcon::Desktop ) );
550 label->setPixmap( KGlobal::iconLoader()->loadIcon( "folder", KIcon::Desktop, 0 ) );
551 layout->addMultiCellWidget( label, 0, 1, 0, 0 );
552
553 label = new QLabel( i18n( "Department:" ), tab2 );
554 layout->addWidget( label, 0, 1 );
555 mDepartmentEdit = new KLineEdit( tab2 );
556 connect( mDepartmentEdit, SIGNAL( textChanged( const QString& ) ),
557 SLOT( textChanged( const QString& ) ) );
558 label->setBuddy( mDepartmentEdit );
559 layout->addWidget( mDepartmentEdit, 0, 2 );
560
561 label = new QLabel( i18n( "Office:" ), tab2 );
562 layout->addWidget( label, 1, 1 );
563 mOfficeEdit = new KLineEdit( tab2 );
564 connect( mOfficeEdit, SIGNAL( textChanged( const QString& ) ),
565 SLOT( textChanged( const QString& ) ) );
566 label->setBuddy( mOfficeEdit );
567 layout->addWidget( mOfficeEdit, 1, 2 );
568
569 label = new QLabel( i18n( "Profession:" ), tab2 );
570 layout->addWidget( label, 2, 1 );
571 mProfessionEdit = new KLineEdit( tab2 );
572 connect( mProfessionEdit, SIGNAL( textChanged( const QString& ) ),
573 SLOT( textChanged( const QString& ) ) );
574 label->setBuddy( mProfessionEdit );
575 layout->addWidget( mProfessionEdit, 2, 2 );
576
577 label = new QLabel( i18n( "Manager\'s name:" ), tab2 );
578//US layout->addWidget( label, 0, 3 );
579 layout->addWidget( label, 3, 1 );
580 mManagerEdit = new KLineEdit( tab2 );
581 connect( mManagerEdit, SIGNAL( textChanged( const QString& ) ),
582 SLOT( textChanged( const QString& ) ) );
583 label->setBuddy( mManagerEdit );
584//US layout->addMultiCellWidget( mManagerEdit, 0, 0, 4, 5 );
585 layout->addWidget( mManagerEdit, 3, 2 );
586
587 label = new QLabel( i18n( "Assistant's name:" ), tab2 );
588//US layout->addWidget( label, 1, 3 );
589 layout->addWidget( label, 4, 1 );
590 mAssistantEdit = new KLineEdit( tab2 );
591 connect( mAssistantEdit, SIGNAL( textChanged( const QString& ) ),
592 SLOT( textChanged( const QString& ) ) );
593 label->setBuddy( mAssistantEdit );
594//US layout->addMultiCellWidget( mAssistantEdit, 1, 1, 4, 5 );
595 layout->addWidget( mAssistantEdit, 4, 2 );
596
597 bar = new KSeparator( KSeparator::HLine, tab2 );
598//US layout->addMultiCellWidget( bar, 3, 3, 0, 5 );
599 layout->addMultiCellWidget( bar, 5, 5, 0, 2 );
600
601 /////////////////////////////////////////////////
602 // Personal info
603
604 label = new QLabel( tab2 );
605//US loadIcon call is ambiguous. Add one more parameter
606//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop ) );
607 label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop, 0 ) );
608//US layout->addMultiCellWidget( label, 4, 5, 0, 0 );
609 layout->addMultiCellWidget( label, 6, 7, 0, 0 );
610
611 label = new QLabel( i18n( "Nick name:" ), tab2 );
612//US layout->addWidget( label, 4, 1 );
613 layout->addWidget( label, 6, 1 );
614 mNicknameEdit = new KLineEdit( tab2 );
615 connect( mNicknameEdit, SIGNAL( textChanged( const QString& ) ),
616 SLOT( textChanged( const QString& ) ) );
617 label->setBuddy( mNicknameEdit );
618//US layout->addWidget( mNicknameEdit, 4, 2 );
619 layout->addWidget( mNicknameEdit, 6, 2 );
620
621 label = new QLabel( i18n( "Spouse's name:" ), tab2 );
622//US layout->addWidget( label, 5, 1 );
623 layout->addWidget( label, 7, 1 );
624 mSpouseEdit = new KLineEdit( tab2 );
625 connect( mSpouseEdit, SIGNAL( textChanged( const QString& ) ),
626 SLOT( textChanged( const QString& ) ) );
627 label->setBuddy( mSpouseEdit );
628//US layout->addWidget( mSpouseEdit, 5, 2 );
629 layout->addWidget( mSpouseEdit, 7, 2 );
630
631 label = new QLabel( i18n( "Birthday:" ), tab2 );
632//US layout->addWidget( label, 4, 3 );
633 layout->addWidget( label, 8, 1 );
634 mBirthdayPicker = new KDateEdit( tab2 );
635 mBirthdayPicker->setHandleInvalid( true );
636 connect( mBirthdayPicker, SIGNAL( dateChanged( QDate ) ),
637 SLOT( dateChanged( QDate ) ) );
638
639
640#ifndef KAB_EMBEDDED
641 //US invalid dates are handdled by the KDateEdit widget itself
642 connect( mBirthdayPicker, SIGNAL( invalidDateEntered() ),
643 SLOT( invalidDate() ) );
644 connect( mBirthdayPicker, SIGNAL( textChanged( const QString& ) ),
645 SLOT( emitModified() ) );
646#endif //KAB_EMBEDDED
647
648 label->setBuddy( mBirthdayPicker );
649//US layout->addWidget( mBirthdayPicker, 4, 4 );
650 layout->addWidget( mBirthdayPicker, 8, 2 );
651
652 label = new QLabel( i18n( "Anniversary:" ), tab2 );
653//US layout->addWidget( label, 5, 3 );
654 layout->addWidget( label, 9, 1 );
655 mAnniversaryPicker = new KDateEdit( tab2 );
656 mAnniversaryPicker->setHandleInvalid( true );
657 connect( mAnniversaryPicker, SIGNAL( dateChanged( QDate ) ),
658 SLOT( dateChanged( QDate ) ) );
659#ifndef KAB_EMBEDDED
660 //US invalid dates are handled by the KDateEdit widget itself
661 connect( mAnniversaryPicker, SIGNAL( invalidDateEntered() ),
662 SLOT( invalidDate() ) );
663 connect( mAnniversaryPicker, SIGNAL( textChanged( const QString& ) ),
664 SLOT( emitModified() ) );
665#endif //KAB_EMBEDDED
666
667 label->setBuddy( mAnniversaryPicker );
668//US layout->addWidget( mAnniversaryPicker, 5, 4 );
669 layout->addWidget( mAnniversaryPicker, 9, 2 );
670
671/*US
672 bar = new KSeparator( KSeparator::HLine, tab2 );
673 layout->addMultiCellWidget( bar, 6, 6, 0, 5 );
674
675 //////////////////////////////////////
676 // Notes
677 label = new QLabel( i18n( "Note:" ), tab2 );
678 label->setAlignment( Qt::AlignTop | Qt::AlignLeft );
679 layout->addWidget( label, 7, 0 );
680#ifndef KAB_EMBEDDED
681 mNoteEdit = new QTextEdit( tab2 );
682 mNoteEdit->setWordWrap( QTextEdit::WidgetWidth );
683 mNoteEdit->setMinimumSize( mNoteEdit->sizeHint() );
684#else //KAB_EMBEDDED
685 mNoteEdit = new QMultiLineEdit( tab2 );
686//US mNoteEdit->setWordWrap( QTextEdit::WidgetWidth );
687//US mNoteEdit->setMinimumSize( mNoteEdit->sizeHint() );
688qDebug("AddresseeEditorWidget::setupTab2 has to be changed");
689#endif //KAB_EMBEDDED
690 connect( mNoteEdit, SIGNAL( textChanged() ), SLOT( emitModified() ) );
691 label->setBuddy( mNoteEdit );
692 layout->addMultiCellWidget( mNoteEdit, 7, 7, 1, 5 );
693*/
694 // Build the layout and add to the tab widget
695 layout->activate(); // required
696
697 mTabWidget->addTab( tab2, i18n( "&Details" ) );
698}
699
700void AddresseeEditorWidget::setupTab2_1()
701{
702 // This is the Details tab
703 QWidget *tab2_2 = new QWidget( mTabWidget );
704
705 QGridLayout *layout = new QGridLayout( tab2_2, 1, 2 );
706 layout->setMargin( KDialogBase::marginHintSmall() );
707 layout->setSpacing( KDialogBase::spacingHintSmall() );
708
709 QLabel *label;
710 KSeparator* bar;
711
712/*US
713 ///////////////////////
714 // Office info
715
716 // Department
717 label = new QLabel( tab2 );
718//US loadIcon call is ambiguous. Add one more parameter
719//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "folder", KIcon::Desktop ) );
720 label->setPixmap( KGlobal::iconLoader()->loadIcon( "folder", KIcon::Desktop, 0 ) );
721 layout->addMultiCellWidget( label, 0, 1, 0, 0 );
722
723 label = new QLabel( i18n( "Department:" ), tab2 );
724 layout->addWidget( label, 0, 1 );
725 mDepartmentEdit = new KLineEdit( tab2 );
726 connect( mDepartmentEdit, SIGNAL( textChanged( const QString& ) ),
727 SLOT( textChanged( const QString& ) ) );
728 label->setBuddy( mDepartmentEdit );
729 layout->addWidget( mDepartmentEdit, 0, 2 );
730
731 label = new QLabel( i18n( "Office:" ), tab2 );
732 layout->addWidget( label, 1, 1 );
733 mOfficeEdit = new KLineEdit( tab2 );
734 connect( mOfficeEdit, SIGNAL( textChanged( const QString& ) ),
735 SLOT( textChanged( const QString& ) ) );
736 label->setBuddy( mOfficeEdit );
737 layout->addWidget( mOfficeEdit, 1, 2 );
738
739 label = new QLabel( i18n( "Profession:" ), tab2 );
740 layout->addWidget( label, 2, 1 );
741 mProfessionEdit = new KLineEdit( tab2 );
742 connect( mProfessionEdit, SIGNAL( textChanged( const QString& ) ),
743 SLOT( textChanged( const QString& ) ) );
744 label->setBuddy( mProfessionEdit );
745 layout->addWidget( mProfessionEdit, 2, 2 );
746
747 label = new QLabel( i18n( "Manager\'s name:" ), tab2 );
748 layout->addWidget( label, 0, 3 );
749 mManagerEdit = new KLineEdit( tab2 );
750 connect( mManagerEdit, SIGNAL( textChanged( const QString& ) ),
751 SLOT( textChanged( const QString& ) ) );
752 label->setBuddy( mManagerEdit );
753 layout->addMultiCellWidget( mManagerEdit, 0, 0, 4, 5 );
754
755 label = new QLabel( i18n( "Assistant's name:" ), tab2 );
756 layout->addWidget( label, 1, 3 );
757 mAssistantEdit = new KLineEdit( tab2 );
758 connect( mAssistantEdit, SIGNAL( textChanged( const QString& ) ),
759 SLOT( textChanged( const QString& ) ) );
760 label->setBuddy( mAssistantEdit );
761 layout->addMultiCellWidget( mAssistantEdit, 1, 1, 4, 5 );
762
763 bar = new KSeparator( KSeparator::HLine, tab2 );
764 layout->addMultiCellWidget( bar, 3, 3, 0, 5 );
765
766 /////////////////////////////////////////////////
767 // Personal info
768
769 label = new QLabel( tab2 );
770//US loadIcon call is ambiguous. Add one more parameter
771//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop ) );
772 label->setPixmap( KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop, 0 ) );
773 layout->addMultiCellWidget( label, 4, 5, 0, 0 );
774
775 label = new QLabel( i18n( "Nick name:" ), tab2 );
776 layout->addWidget( label, 4, 1 );
777 mNicknameEdit = new KLineEdit( tab2 );
778 connect( mNicknameEdit, SIGNAL( textChanged( const QString& ) ),
779 SLOT( textChanged( const QString& ) ) );
780 label->setBuddy( mNicknameEdit );
781 layout->addWidget( mNicknameEdit, 4, 2 );
782
783 label = new QLabel( i18n( "Spouse's name:" ), tab2 );
784 layout->addWidget( label, 5, 1 );
785 mSpouseEdit = new KLineEdit( tab2 );
786 connect( mSpouseEdit, SIGNAL( textChanged( const QString& ) ),
787 SLOT( textChanged( const QString& ) ) );
788 label->setBuddy( mSpouseEdit );
789 layout->addWidget( mSpouseEdit, 5, 2 );
790
791 label = new QLabel( i18n( "Birthday:" ), tab2 );
792 layout->addWidget( label, 4, 3 );
793 mBirthdayPicker = new KDateEdit( tab2 );
794 mBirthdayPicker->setHandleInvalid( true );
795 connect( mBirthdayPicker, SIGNAL( dateChanged( QDate ) ),
796 SLOT( dateChanged( QDate ) ) );
797 connect( mBirthdayPicker, SIGNAL( invalidDateEntered() ),
798 SLOT( invalidDate() ) );
799 connect( mBirthdayPicker, SIGNAL( textChanged( const QString& ) ),
800 SLOT( emitModified() ) );
801 label->setBuddy( mBirthdayPicker );
802 layout->addWidget( mBirthdayPicker, 4, 4 );
803
804 label = new QLabel( i18n( "Anniversary:" ), tab2 );
805 layout->addWidget( label, 5, 3 );
806 mAnniversaryPicker = new KDateEdit( tab2 );
807 mAnniversaryPicker->setHandleInvalid( true );
808 connect( mAnniversaryPicker, SIGNAL( dateChanged( QDate ) ),
809 SLOT( dateChanged( QDate ) ) );
810 connect( mAnniversaryPicker, SIGNAL( invalidDateEntered() ),
811 SLOT( invalidDate() ) );
812 connect( mAnniversaryPicker, SIGNAL( textChanged( const QString& ) ),
813 SLOT( emitModified() ) );
814 label->setBuddy( mAnniversaryPicker );
815 layout->addWidget( mAnniversaryPicker, 5, 4 );
816
817 bar = new KSeparator( KSeparator::HLine, tab2 );
818 layout->addMultiCellWidget( bar, 6, 6, 0, 5 );
819*/
820 //////////////////////////////////////
821 // Notes
822 label = new QLabel( i18n( "Note:" ), tab2_2 );
823 label->setAlignment( Qt::AlignTop | Qt::AlignLeft );
824//US layout->addWidget( label, 7, 0 );
825 layout->addWidget( label, 0, 0 );
826#ifndef KAB_EMBEDDED
827 mNoteEdit = new QTextEdit( tab2_2 );
828 mNoteEdit->setWordWrap( QTextEdit::WidgetWidth );
829 mNoteEdit->setMinimumSize( mNoteEdit->sizeHint() );
830#else //KAB_EMBEDDED
831 mNoteEdit = new QMultiLineEdit( tab2_2 );
832 mNoteEdit->setWordWrap( QMultiLineEdit::WidgetWidth );
833 mNoteEdit->setMinimumSize( mNoteEdit->sizeHint() );
834#endif //KAB_EMBEDDED
835
836 connect( mNoteEdit, SIGNAL( textChanged() ), SLOT( emitModified() ) );
837 label->setBuddy( mNoteEdit );
838//US layout->addMultiCellWidget( mNoteEdit, 7, 7, 1, 5 );
839 layout->addWidget( mNoteEdit, 1, 0);
840
841 // Build the layout and add to the tab widget
842 layout->activate(); // required
843
844 mTabWidget->addTab( tab2_2, i18n( "&Notes" ) );
845}
846
847
848
849void AddresseeEditorWidget::setupTab3()
850{
851 // This is the Misc tab
852 QWidget *tab3 = new QWidget( mTabWidget );
853
854 QGridLayout *layout = new QGridLayout( tab3, 1, 1 );
855 layout->setMargin( KDialogBase::marginHintSmall() );
856 layout->setSpacing( KDialogBase::spacingHintSmall() );
857//US layout->setColStretch( 2, 1 );
858
859 //////////////////////////////////////
860 // Geo
861 mGeoWidget = new GeoWidget( tab3 );
862 // mGeoWidget->setMinimumSize( mGeoWidget->sizeHint() );
863 connect( mGeoWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
864 layout->addWidget( mGeoWidget, 0, 0 );
865/*US
866 //////////////////////////////////////
867 // Sound
868#ifndef KAB_EMBEDDED
869 mSoundWidget = new SoundWidget( tab3 );
870 mSoundWidget->setMinimumSize( mSoundWidget->sizeHint() );
871 connect( mSoundWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
872 layout->addWidget( mSoundWidget, 0, 1, Qt::AlignTop );
873#else //KAB_EMBEDDED
874qDebug("AddresseeEditorWidget::setupTab2 sound part is not supported = has to be changed");
875#endif //KAB_EMBEDDED
876
877 //////////////////////////////////////
878 // Images
879 mImageWidget = new ImageWidget( tab3 );
880 mImageWidget->setMinimumSize( mImageWidget->sizeHint() );
881 connect( mImageWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
882 layout->addWidget( mImageWidget, 1, 0, Qt::AlignTop );
883*/
884//US
885/*
886 KSeparator* bar = new KSeparator( KSeparator::HLine, tab3 );
887 layout->addMultiCellWidget( bar, 1, 1, 0, 0 );
888*/
889 //////////////////////////////////////
890 // Keys
891 mKeyWidget = new KeyWidget( tab3 );
892 //mKeyWidget->setMinimumSize( mKeyWidget->sizeHint() );
893 connect( mKeyWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
894//US layout->addWidget( mKeyWidget, 1, 1, Qt::AlignTop );
895 layout->addWidget( mKeyWidget, 1, 0 );
896
897 mTabWidget->addTab( tab3, i18n( "&Misc" ) );
898}
899
900void AddresseeEditorWidget::setupTab3_1()
901{
902 // This is the Misc tab
903 QWidget *tab3 = new QWidget( mTabWidget );
904
905//US QGridLayout *layout = new QGridLayout( tab3, 2, 3 );
906 QGridLayout *layout = new QGridLayout( tab3, 1, 1 );
907 layout->setMargin( KDialogBase::marginHint() );
908 layout->setSpacing( KDialogBase::spacingHint() );
909//US layout->setColStretch( 2, 1 );
910
911/*US
912 //////////////////////////////////////
913 // Geo
914 mGeoWidget = new GeoWidget( tab3 );
915 mGeoWidget->setMinimumSize( mGeoWidget->sizeHint() );
916 connect( mGeoWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
917 layout->addWidget( mGeoWidget, 0, 0, Qt::AlignTop );
918*/
919 //////////////////////////////////////
920 // Sound
921#ifndef KAB_EMBEDDED
922 mSoundWidget = new SoundWidget( tab3 );
923 mSoundWidget->setMinimumSize( mSoundWidget->sizeHint() );
924 connect( mSoundWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
925 layout->addWidget( mSoundWidget, 0, 1, Qt::AlignTop );
926#else //KAB_EMBEDDED
927//US qDebug("AddresseeEditorWidget::setupTab2 sound part is not supported = has to be changed");
928#endif //KAB_EMBEDDED
929
930 //////////////////////////////////////
931 // Images
932 mImageWidget = new ImageWidget( tab3 );
933 mImageWidget->setMinimumSize( mImageWidget->sizeHint() );
934 connect( mImageWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
935 layout->addWidget( mImageWidget, 0, 0, Qt::AlignTop );
936/*US
937 //////////////////////////////////////
938 // Keys
939 mKeyWidget = new KeyWidget( tab3 );
940 mKeyWidget->setMinimumSize( mKeyWidget->sizeHint() );
941 connect( mKeyWidget, SIGNAL( changed() ), SLOT( emitModified() ) );
942 layout->addWidget( mKeyWidget, 1, 1, Qt::AlignTop );
943*/
944 mTabWidget->addTab( tab3, i18n( "&Images" ) );
945}
946
947
948void AddresseeEditorWidget::load()
949{
950 kdDebug(5720) << "AddresseeEditorWidget::load()" << endl;
951
952 // Block signals in case anything tries to emit modified
953 // CS: This doesn't seem to work.
954 bool block = signalsBlocked();
955 blockSignals( true );
956 mBlockSignals = true; // used for internal signal blocking
957
958 mNameEdit->setText( mAddressee.assembledName() );
959
960 if ( mAddressee.formattedName().isEmpty() ) {
961//US KConfig config( "kaddressbookrc" );
962 KConfig config( locateLocal("config", "kaddressbookrc") );
963 config.setGroup( "General" );
964 mFormattedNameType = config.readNumEntry( "FormattedNameType", 1 );
965 mAddressee.setFormattedName( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
966 } else {
967 if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::SimpleName ) )
968 mFormattedNameType = NameEditDialog::SimpleName;
969 else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::FullName ) )
970 mFormattedNameType = NameEditDialog::FullName;
971 else if ( mAddressee.formattedName() == NameEditDialog::formattedName( mAddressee, NameEditDialog::ReverseName ) )
972 mFormattedNameType = NameEditDialog::ReverseName;
973 else
974 mFormattedNameType = NameEditDialog::CustomName;
975 }
976
977 mFormattedNameLabel->setText( mAddressee.formattedName() );
978
979 mRoleEdit->setText( mAddressee.role() );
980 mOrgEdit->setText( mAddressee.organization() );
981
982//US mURLEdit->setURL( mAddressee.url().url() );
983 mURLEdit->setText( mAddressee.url().prettyURL() );
984//US?? mURLEdit->home( false );
985
986 // mNoteEdit->setText( mAddressee.note() );
987 mNoteEdit->setText( mAddressee.note() );
988 mEmailWidget->setEmails( mAddressee.emails() );
989 mPhoneEditWidget->setPhoneNumbers( mAddressee.phoneNumbers() );
990 mAddressEditWidget->setAddresses( mAddressee, mAddressee.addresses() );
991 mBirthdayPicker->setDate( mAddressee.birthday().date() );
992
993//US mAnniversaryPicker->setDate( QDate::fromString( mAddressee.custom(
994//US "KADDRESSBOOK", "X-Anniversary" ), Qt::ISODate) );
995 QDate dt = KGlobal::locale()->readDate( mAddressee.custom("KADDRESSBOOK", "X-Anniversary" ),
996 "%Y-%m-%d"); // = Qt::ISODate
997 mAnniversaryPicker->setDate( dt );
998
999
1000 mNicknameEdit->setText( mAddressee.nickName() );
1001 mCategoryEdit->setText( mAddressee.categories().join( "," ) );
1002
1003 mGeoWidget->setGeo( mAddressee.geo() );
1004 mImageWidget->setPhoto( mAddressee.photo() );
1005 mImageWidget->setLogo( mAddressee.logo() );
1006 mKeyWidget->setKeys( mAddressee.keys() );
1007 mSecrecyWidget->setSecrecy( mAddressee.secrecy() );
1008#ifndef KAB_EMBEDDED
1009 mSoundWidget->setSound( mAddressee.sound() );
1010#else //KAB_EMBEDDED
1011//US qDebug("AddresseeEditorWidget::load has to be changed 2");
1012#endif //KAB_EMBEDDED
1013
1014 // Load customs
1015 mIMAddressEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-IMAddress" ) );
1016 mSpouseEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-SpousesName" ) );
1017 mManagerEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-ManagersName" ) );
1018 mAssistantEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-AssistantsName" ) );
1019 mDepartmentEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Department" ) );
1020 mOfficeEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Office" ) );
1021 mProfessionEdit->setText( mAddressee.custom( "KADDRESSBOOK", "X-Profession" ) );
1022
1023 blockSignals( block );
1024 mBlockSignals = false;
1025
1026 mDirty = false;
1027}
1028
1029void AddresseeEditorWidget::save()
1030{
1031 if ( !mDirty ) return;
1032
1033 mAddressee.setRole( mRoleEdit->text() );
1034 mAddressee.setOrganization( mOrgEdit->text() );
1035 mAddressee.setUrl( KURL( mURLEdit->text() ) );
1036 mAddressee.setNote( mNoteEdit->text() );
1037 if ( mBirthdayPicker->inputIsValid() )
1038 mAddressee.setBirthday( QDateTime( mBirthdayPicker->date() ) );
1039 else
1040 mAddressee.setBirthday( QDateTime() );
1041
1042 mAddressee.setNickName( mNicknameEdit->text() );
1043 mAddressee.setCategories( QStringList::split( ",", mCategoryEdit->text() ) );
1044
1045 mAddressee.setGeo( mGeoWidget->geo() );
1046 mAddressee.setPhoto( mImageWidget->photo() );
1047 mAddressee.setLogo( mImageWidget->logo() );
1048 mAddressee.setKeys( mKeyWidget->keys() );
1049#ifndef KAB_EMBEDDED
1050 mAddressee.setSound( mSoundWidget->sound() );
1051#else //KAB_EMBEDDED
1052//US qDebug("AddresseeEditorWidget::save sound not supported");
1053#endif //KAB_EMBEDDED
1054 mAddressee.setSecrecy( mSecrecyWidget->secrecy() );
1055
1056 // save custom fields
1057 mAddressee.insertCustom( "KADDRESSBOOK", "X-IMAddress", mIMAddressEdit->text() );
1058 mAddressee.insertCustom( "KADDRESSBOOK", "X-SpousesName", mSpouseEdit->text() );
1059 mAddressee.insertCustom( "KADDRESSBOOK", "X-ManagersName", mManagerEdit->text() );
1060 mAddressee.insertCustom( "KADDRESSBOOK", "X-AssistantsName", mAssistantEdit->text() );
1061 mAddressee.insertCustom( "KADDRESSBOOK", "X-Department", mDepartmentEdit->text() );
1062 mAddressee.insertCustom( "KADDRESSBOOK", "X-Office", mOfficeEdit->text() );
1063 mAddressee.insertCustom( "KADDRESSBOOK", "X-Profession", mProfessionEdit->text() );
1064 if ( mAnniversaryPicker->inputIsValid() ) {
1065
1066//US mAddressee.insertCustom( "KADDRESSBOOK", "X-Anniversary",
1067//US mAnniversaryPicker->date().toString( Qt::ISODate ) );
1068 int orgformat = KGlobal::locale()->getIntDateFormat();
1069 QDate da = mAnniversaryPicker->date();
1070 KGlobal::locale()->setIntDateFormat( 2 ); // = Qt::ISODate
1071 QString dt = KGlobal::locale()->formatDate(da, true);
1072 KGlobal::locale()->setIntDateFormat(orgformat );
1073 mAddressee.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt);
1074 }
1075 else
1076 mAddressee.removeCustom( "KADDRESSBOOK", "X-Anniversary" );
1077
1078 // Save the email addresses
1079 QStringList emails = mAddressee.emails();
1080 QStringList::Iterator iter;
1081 for ( iter = emails.begin(); iter != emails.end(); ++iter )
1082 mAddressee.removeEmail( *iter );
1083
1084 emails = mEmailWidget->emails();
1085 bool first = true;
1086 for ( iter = emails.begin(); iter != emails.end(); ++iter ) {
1087 mAddressee.insertEmail( *iter, first );
1088 first = false;
1089 }
1090
1091 // Save the phone numbers
1092 KABC::PhoneNumber::List phoneNumbers;
1093 KABC::PhoneNumber::List::Iterator phoneIter;
1094 phoneNumbers = mAddressee.phoneNumbers();
1095 for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
1096 ++phoneIter )
1097 mAddressee.removePhoneNumber( *phoneIter );
1098
1099 phoneNumbers = mPhoneEditWidget->phoneNumbers();
1100 for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
1101 ++phoneIter )
1102 mAddressee.insertPhoneNumber( *phoneIter );
1103
1104 // Save the addresses
1105 KABC::Address::List addresses;
1106 KABC::Address::List::Iterator addressIter;
1107 addresses = mAddressee.addresses();
1108 for ( addressIter = addresses.begin(); addressIter != addresses.end();
1109 ++addressIter )
1110 mAddressee.removeAddress( *addressIter );
1111
1112 addresses = mAddressEditWidget->addresses();
1113 for ( addressIter = addresses.begin(); addressIter != addresses.end();
1114 ++addressIter )
1115 mAddressee.insertAddress( *addressIter );
1116 mDirty = false;
1117}
1118
1119bool AddresseeEditorWidget::dirty()
1120{
1121 return mDirty;
1122}
1123
1124void AddresseeEditorWidget::nameTextChanged( const QString &text )
1125{
1126 // use the addressee class to parse the name for us
1127 mAConfig->setUid( mAddressee.uid() );
1128 if ( mAConfig->automaticNameParsing() ) {
1129 if ( !mAddressee.formattedName().isEmpty() ) {
1130 QString fn = mAddressee.formattedName();
1131 mAddressee.setNameFromString( text );
1132 mAddressee.setFormattedName( fn );
1133 } else {
1134 // use extra addressee to avoid a formatted name assignment
1135 Addressee addr;
1136 addr.setNameFromString( text );
1137 mAddressee.setPrefix( addr.prefix() );
1138 mAddressee.setGivenName( addr.givenName() );
1139 mAddressee.setAdditionalName( addr.additionalName() );
1140 mAddressee.setFamilyName( addr.familyName() );
1141 mAddressee.setSuffix( addr.suffix() );
1142 }
1143 }
1144
1145 nameBoxChanged();
1146
1147 emitModified();
1148}
1149
1150void AddresseeEditorWidget::nameBoxChanged()
1151{
1152 KABC::Addressee addr;
1153 mAConfig->setUid( mAddressee.uid() );
1154 if ( mAConfig->automaticNameParsing() ) {
1155 addr.setNameFromString( mNameEdit->text() );
1156 mNameLabel->hide();
1157 mNameEdit->show();
1158 } else {
1159 addr = mAddressee;
1160 mNameEdit->hide();
1161 mNameLabel->setText( mNameEdit->text() );
1162 mNameLabel->show();
1163 }
1164
1165 if ( mFormattedNameType != NameEditDialog::CustomName ) {
1166 mFormattedNameLabel->setText( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
1167 mAddressee.setFormattedName( NameEditDialog::formattedName( mAddressee, mFormattedNameType ) );
1168 }
1169}
1170
1171void AddresseeEditorWidget::nameButtonClicked()
1172{
1173 // show the name dialog.
1174 NameEditDialog dialog( mAddressee, mFormattedNameType, this );
1175
1176 if ( dialog.exec() ) {
1177 if ( dialog.changed() ) {
1178 mAddressee.setFamilyName( dialog.familyName() );
1179 mAddressee.setGivenName( dialog.givenName() );
1180 mAddressee.setPrefix( dialog.prefix() );
1181 mAddressee.setSuffix( dialog.suffix() );
1182 mAddressee.setAdditionalName( dialog.additionalName() );
1183 mFormattedNameType = dialog.formattedNameType();
1184 if ( mFormattedNameType == NameEditDialog::CustomName ) {
1185 mFormattedNameLabel->setText( dialog.customFormattedName() );
1186 mAddressee.setFormattedName( dialog.customFormattedName() );
1187 }
1188 // Update the name edit.
1189 bool block = mNameEdit->signalsBlocked();
1190 mNameEdit->blockSignals( true );
1191 mNameEdit->setText( mAddressee.assembledName() );
1192 mNameEdit->blockSignals( block );
1193
1194 // Update the combo box.
1195 nameBoxChanged();
1196
1197 emitModified();
1198 }
1199 }
1200}
1201
1202void AddresseeEditorWidget::categoryButtonClicked()
1203{
1204 // Show the category dialog
1205 if ( mCategoryDialog == 0 ) {
1206 mCategoryDialog = new KPIM::CategorySelectDialog( KABPrefs::instance(), this );
1207 connect( mCategoryDialog, SIGNAL( categoriesSelected( const QStringList& ) ),
1208 SLOT(categoriesSelected( const QStringList& ) ) );
1209 connect( mCategoryDialog, SIGNAL( editCategories() ), SLOT( editCategories() ) );
1210 }
1211
1212 mCategoryDialog->setCategories();
1213 mCategoryDialog->setSelected( QStringList::split( ",", mCategoryEdit->text() ) );
1214 mCategoryDialog->show();
1215 mCategoryDialog->raise();
1216}
1217
1218void AddresseeEditorWidget::categoriesSelected( const QStringList &list )
1219{
1220 mCategoryEdit->setText( list.join( "," ) );
1221}
1222
1223void AddresseeEditorWidget::editCategories()
1224{
1225 if ( mCategoryEditDialog == 0 ) {
1226 mCategoryEditDialog = new KPIM::CategoryEditDialog( KABPrefs::instance(), this );
1227 connect( mCategoryEditDialog, SIGNAL( categoryConfigChanged() ),
1228 SLOT( categoryButtonClicked() ) );
1229 }
1230
1231 mCategoryEditDialog->show();
1232 mCategoryEditDialog->raise();
1233}
1234
1235void AddresseeEditorWidget::emitModified()
1236{
1237 mDirty = true;
1238
1239 KABC::Addressee::List list;
1240
1241 if ( mIsExtension && !mBlockSignals ) {
1242 save();
1243 list.append( mAddressee );
1244 }
1245
1246 emit modified( list );
1247}
1248
1249void AddresseeEditorWidget::dateChanged( QDate )
1250{
1251 emitModified();
1252}
1253
1254//US invalid dates are handdled by the KDateEdit widget itself
1255void AddresseeEditorWidget::invalidDate()
1256{
1257 KMessageBox::sorry( this, i18n( "You must specify a valid date" ) );
1258}
1259
1260
1261void AddresseeEditorWidget::pageChanged( QWidget *wdg )
1262{
1263#ifndef KAB_EMBEDDED
1264 if ( wdg )
1265 KAcceleratorManager::manage( wdg );
1266#else //KAB_EMBEDDED
1267//US
1268#endif //KAB_EMBEDDED
1269
1270}
1271
1272QString AddresseeEditorWidget::title() const
1273{
1274 return i18n( "Contact Editor" );
1275}
1276
1277QString AddresseeEditorWidget::identifier() const
1278{
1279 return i18n( "contact_editor" );
1280}
1281
1282#ifndef KAB_EMBEDDED
1283#include "addresseeeditorwidget.moc"
1284#endif //KAB_EMBEDDED
diff --git a/kaddressbook/addresseeeditorwidget.h b/kaddressbook/addresseeeditorwidget.h
new file mode 100644
index 0000000..b9d9e25
--- a/dev/null
+++ b/kaddressbook/addresseeeditorwidget.h
@@ -0,0 +1,184 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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#ifndef ADDRESSEEEDITORWIDGET_H
25#define ADDRESSEEEDITORWIDGET_H
26
27#include <qdatetime.h>
28
29#include <kabc/addressee.h>
30#include <kdialogbase.h>
31#include <kjanuswidget.h>
32
33#include "extensionwidget.h"
34
35class AddresseeConfig;
36class QCheckBox;
37class QSpinBox;
38class QTabWidget;
39
40#ifndef KAB_EMBEDDED
41class QTextEdit;
42#else //KAB_EMBEDDED
43class QMultiLineEdit;
44#endif //KAB_EMBEDDED
45
46class KComboBox;
47class KDateEdit;
48class KLineEdit;
49class KSqueezedTextLabel;
50
51class AddressEditWidget;
52class EmailEditWidget;
53class GeoWidget;
54class ImageWidget;
55class KABCore;
56class KeyWidget;
57class PhoneEditWidget;
58class SecrecyWidget;
59class SoundWidget;
60
61namespace KPIM
62{
63 class CategorySelectDialog;
64 class CategoryEditDialog;
65}
66
67namespace KABC { class AddressBook; }
68
69class AddresseeEditorWidget : public ExtensionWidget
70{
71 Q_OBJECT
72
73 public:
74 AddresseeEditorWidget( KABCore *core, bool isExtension,
75 QWidget *parent, const char *name = 0 );
76 ~AddresseeEditorWidget();
77
78 void setAddressee( const KABC::Addressee& );
79 const KABC::Addressee &addressee();
80
81 void contactsSelectionChanged();
82
83 void load();
84 void save();
85
86 bool dirty();
87
88 QString title() const;
89 QString identifier() const;
90
91 protected slots:
92 void textChanged( const QString& );
93 void pageChanged( QWidget *wdg );
94
95 /**
96 Emits the modified signal and sets the dirty flag. Any slot
97 that modifies data should use this method instead of calling emit
98 modified() directly.
99 */
100 void emitModified();
101
102 void dateChanged( QDate );
103 void invalidDate();
104 void nameTextChanged( const QString& );
105 void nameBoxChanged();
106 void nameButtonClicked();
107 void categoryButtonClicked();
108
109 /**
110 Called whenever the categories change in the categories dialog.
111 */
112 void categoriesSelected( const QStringList& );
113
114 /**
115 Edits which categories are available in the CategorySelectDialog.
116 */
117 void editCategories();
118
119 private:
120 AddresseeConfig * mAConfig;
121 void initGUI();
122 void setupTab1();
123 void setupTab1_1();
124 void setupTab2();
125 void setupTab2_1();
126 void setupTab3();
127 void setupTab3_1();
128
129 KABC::Addressee mAddressee;
130 int mFormattedNameType;
131 bool mDirty;
132 bool mIsExtension;
133 bool mBlockSignals;
134
135 // GUI
136 KPIM::CategorySelectDialog *mCategoryDialog;
137 KPIM::CategoryEditDialog *mCategoryEditDialog;
138 QTabWidget *mTabWidget;
139
140 // Tab1 and Tab1_1
141 KLineEdit *mNameEdit;
142 KLineEdit *mRoleEdit;
143 KLineEdit *mOrgEdit;
144
145 KSqueezedTextLabel *mFormattedNameLabel;
146 AddressEditWidget *mAddressEditWidget;
147 EmailEditWidget *mEmailWidget;
148 PhoneEditWidget *mPhoneEditWidget;
149 KLineEdit *mURLEdit;
150 KLineEdit *mIMAddressEdit;
151 KLineEdit *mCategoryEdit;
152 SecrecyWidget *mSecrecyWidget;
153 KSqueezedTextLabel *mNameLabel;
154
155 // Tab2 and Tab2_2
156 KLineEdit *mDepartmentEdit;
157 KLineEdit *mOfficeEdit;
158 KLineEdit *mProfessionEdit;
159 KLineEdit *mManagerEdit;
160 KLineEdit *mAssistantEdit;
161 KLineEdit *mNicknameEdit;
162 KLineEdit *mSpouseEdit;
163 KDateEdit *mBirthdayPicker;
164 KDateEdit *mAnniversaryPicker;
165#ifndef KAB_EMBEDDED
166 QTextEdit *mNoteEdit;
167#else //KAB_EMBEDDED
168 QMultiLineEdit *mNoteEdit;
169#endif //KAB_EMBEDDED
170
171 QSpinBox *mTimeZoneSpin;
172 QSpinBox *mGeoLat;
173 QSpinBox *mGeoLon;
174
175 // Tab3
176 GeoWidget *mGeoWidget;
177 ImageWidget *mImageWidget;
178#ifndef KAB_EMBEDDED
179 SoundWidget *mSoundWidget;
180#endif //KAB_EMBEDDED
181 KeyWidget *mKeyWidget;
182};
183
184#endif
diff --git a/kaddressbook/addresseeutil.cpp b/kaddressbook/addresseeutil.cpp
new file mode 100644
index 0000000..366384a
--- a/dev/null
+++ b/kaddressbook/addresseeutil.cpp
@@ -0,0 +1,66 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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 <kabc/stdaddressbook.h>
25#include <kabc/vcardconverter.h>
26#include <kdebug.h>
27#include <klocale.h>
28#include <kmessagebox.h>
29
30#include "addresseeutil.h"
31
32QString AddresseeUtil::addresseesToClipboard( const KABC::Addressee::List &list )
33{
34 KABC::VCardConverter converter;
35 QString vcard;
36
37 KABC::Addressee::List::ConstIterator it;
38 for ( it = list.begin(); it != list.end(); ++it ) {
39 QString tmp;
40 if ( converter.addresseeToVCard( *it, tmp ) )
41 vcard += tmp + "\r\n";
42 }
43
44 return vcard;
45}
46
47KABC::Addressee::List AddresseeUtil::clipboardToAddressees( const QString &data )
48{
49 uint numVCards = data.contains( "BEGIN:VCARD", false );
50 QStringList dataList = QStringList::split( "\r\n\r\n", data );
51
52 KABC::Addressee::List addrList;
53 for ( uint i = 0; i < numVCards && i < dataList.count(); ++i ) {
54 KABC::VCardConverter converter;
55 KABC::Addressee addr;
56
57 if ( !converter.vCardToAddressee( dataList[ i ].stripWhiteSpace(), addr ) ) {
58 KMessageBox::error( 0, i18n( "Invalid vCard format in clipboard" ) );
59 continue;
60 }
61
62 addrList.append( addr );
63 }
64
65 return addrList;
66}
diff --git a/kaddressbook/addresseeutil.h b/kaddressbook/addresseeutil.h
new file mode 100644
index 0000000..2eefc1c
--- a/dev/null
+++ b/kaddressbook/addresseeutil.h
@@ -0,0 +1,61 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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#ifndef ADDRESSEEUTIL_H
25#define ADDRESSEEUTIL_H
26
27#include <qstring.h>
28#include <kabc/addressee.h>
29
30/**
31 This class provides some utility methods for transposing an
32 addressee to different types (ie: clipboard). This class
33 is probably just temporary until these function stablize and move
34 to KABC.
35
36 NOTE: Currently these methods are not implemented properly. The
37 vCard parser in KABC needs to be updated and there is no way to get from
38 KABC::Addressee to vCard.
39*/
40class AddresseeUtil
41{
42 public:
43 /**
44 Same as above function, except that an entire list of KABC::Addressee
45 objects will be converted to vCard and put in the string.
46 */
47 static QString addresseesToClipboard( const KABC::Addressee::List &addrList );
48
49 /**
50 Convert a string from the clipboard into a list of addressee objects.
51 If the clipboard text was not a valid vcard, an empty list
52 will be returned.
53 */
54 static KABC::Addressee::List clipboardToAddressees( const QString &clipboard );
55
56 private:
57 AddresseeUtil() {}
58 ~AddresseeUtil() {}
59};
60
61#endif
diff --git a/kaddressbook/addviewdialog.cpp b/kaddressbook/addviewdialog.cpp
new file mode 100644
index 0000000..6def26b
--- a/dev/null
+++ b/kaddressbook/addviewdialog.cpp
@@ -0,0 +1,118 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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#ifndef KAB_EMBEDDED
25#endif //KAB_EMBEDDED
26
27#include <qradiobutton.h>
28#include <qbuttongroup.h>
29#include <qlabel.h>
30#include <qlineedit.h>
31#include <qlayout.h>
32
33#include <klocale.h>
34#include <kglobal.h>
35#include "kaddressbookview.h"
36#include "addviewdialog.h"
37
38AddViewDialog::AddViewDialog( QDict<ViewFactory> *viewFactoryDict,
39 QWidget *parent, const char *name )
40 : KDialogBase( KDialogBase::Plain, i18n( "Add View" ),
41 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
42 parent, name ),
43 mViewFactoryDict( viewFactoryDict )
44{
45//US setMinimumSize( KMIN(KGlobal::getDesktopWidth(), 300), KMIN(KGlobal::getDesktopHeight(), 300));
46
47 mTypeId = 0;
48
49 QWidget *page = plainPage();
50
51 QGridLayout *layout = new QGridLayout( page, 2, 2 );
52 layout->setSpacing( spacingHint() );
53 layout->setRowStretch( 1, 1 );
54 layout->setColStretch( 1, 1 );
55
56 QLabel *label = new QLabel( i18n( "View name:" ), page );
57 layout->addWidget( label, 0, 0 );
58
59 mViewNameEdit = new QLineEdit( page );
60 connect( mViewNameEdit, SIGNAL( textChanged( const QString& ) ),
61 SLOT( textChanged( const QString& ) ) );
62 layout->addWidget( mViewNameEdit, 0, 1 );
63
64 mTypeGroup = new QButtonGroup( 2, Qt::Horizontal, i18n( "View Type" ), page );
65 connect( mTypeGroup, SIGNAL( clicked( int ) ), this, SLOT( clicked( int ) ) );
66 layout->addMultiCellWidget( mTypeGroup, 1, 1, 0, 1 );
67
68 // Now create the radio buttons. This needs some layout work.
69 QDictIterator<ViewFactory> iter( *mViewFactoryDict );
70 for ( iter.toFirst(); iter.current(); ++iter ) {
71//US i am not quit sure, why I can nopt use (*iter)-> here
72//US new QRadioButton( (*iter)->type(), mTypeGroup );
73//US label = new QLabel( (*iter)->description(), mTypeGroup );
74#ifdef DESKTOP_VERSION
75 new QRadioButton( (*iter)->type(), mTypeGroup );
76 label = new QLabel( (*iter)->description(), mTypeGroup );
77#else
78 new QRadioButton( (*iter).type(), mTypeGroup );
79 label = new QLabel( (*iter).description(), mTypeGroup );
80
81#endif
82 label->setAlignment( Qt::AlignLeft | Qt::AlignTop | Qt::WordBreak );
83 }
84
85 mTypeGroup->setButton( 0 );
86 mViewNameEdit->setFocus();
87 enableButton( KDialogBase::Ok, false );
88
89
90}
91
92AddViewDialog::~AddViewDialog()
93{
94}
95
96QString AddViewDialog::viewName()const
97{
98 return mViewNameEdit->text();
99}
100
101QString AddViewDialog::viewType()const
102{
103 return mTypeGroup->find( mTypeId )->text();
104}
105
106void AddViewDialog::clicked( int id )
107{
108 mTypeId = id;
109}
110
111void AddViewDialog::textChanged( const QString &text )
112{
113 enableButton( KDialogBase::Ok, !text.isEmpty() );
114}
115
116#ifndef KAB_EMBEDDED
117#include "addviewdialog.moc"
118#endif //KAB_EMBEDDED
diff --git a/kaddressbook/addviewdialog.h b/kaddressbook/addviewdialog.h
new file mode 100644
index 0000000..8cc12f5
--- a/dev/null
+++ b/kaddressbook/addviewdialog.h
@@ -0,0 +1,73 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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#ifndef ADDVIEWDIALOG_H
25#define ADDVIEWDIALOG_H
26
27#include <kdialogbase.h>
28#include <qdict.h>
29#include <qstring.h>
30
31class ViewFactory;
32class QButtonGroup;
33class QLineEdit;
34
35
36/**
37 Modal dialog used for adding a new view. The dialog asks for the name of
38 the view as well as the type. Someday it would be nice for this to be a
39 wizard.
40 */
41class AddViewDialog : public KDialogBase
42{
43 Q_OBJECT
44
45 public:
46 AddViewDialog( QDict<ViewFactory> *viewFactoryDict, QWidget *parent,
47 const char *name = 0 );
48 ~AddViewDialog();
49
50 QString viewName()const;
51
52 QString viewType()const ;
53
54 protected slots:
55 /**
56 Called when the user selects a type radio button.
57 */
58 void clicked( int id );
59
60 /**
61 Called when the user changes the text in the name of the view.
62 */
63 void textChanged( const QString &text );
64
65 private:
66 QDict<ViewFactory> *mViewFactoryDict;
67 QLineEdit *mViewNameEdit;
68 QButtonGroup *mTypeGroup;
69
70 int mTypeId;
71};
72
73#endif
diff --git a/kaddressbook/configurewidget.cpp b/kaddressbook/configurewidget.cpp
new file mode 100644
index 0000000..eb57c3a
--- a/dev/null
+++ b/kaddressbook/configurewidget.cpp
@@ -0,0 +1,54 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Tobias Koenig <tokoe@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 <kabc/addressbook.h>
25
26#include "configurewidget.h"
27
28
29ConfigureWidget::ConfigureWidget( KABC::AddressBook *ab, QWidget *parent,
30 const char *name )
31 : QWidget( parent, name ), mAddressBook( ab )
32{
33 //qDebug("new ConfigureWidget %x ", parent);
34}
35
36ConfigureWidget::~ConfigureWidget()
37{
38 //qDebug("ConfigureWidget::~ConfigureWidget() ");
39}
40
41void ConfigureWidget::restoreSettings( KConfig* )
42{
43 // should be reimplemented in the views, extensions etc.
44}
45
46void ConfigureWidget::saveSettings( KConfig* )
47{
48 // should be reimplemented in the views, extensions etc.
49}
50
51KABC::AddressBook *ConfigureWidget::addressBook() const
52{
53 return mAddressBook;
54}
diff --git a/kaddressbook/configurewidget.h b/kaddressbook/configurewidget.h
new file mode 100644
index 0000000..2528c9d
--- a/dev/null
+++ b/kaddressbook/configurewidget.h
@@ -0,0 +1,67 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Tobias Koenig <tokoe@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#ifndef CONFIGUREWIDGET_H
25#define CONFIGUREWIDGET_H
26
27
28#include <qwidget.h>
29#include <kconfig.h>
30
31namespace KABC {
32class AddressBook;
33}
34
35class ConfigureWidget : public QWidget
36{
37 public:
38 ConfigureWidget( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
39 ~ConfigureWidget();
40
41 /**
42 This method is called before the configure dialog is shown.
43 The widget should reimplement it and fill the GUI with the
44 values from the config file.
45 Important: Don't change the group of cfg!
46 */
47 virtual void restoreSettings( KConfig *cfg );
48
49 /**
50 This method is called after the user clicked the 'Ok' button.
51 The widget should reimplement it and save all values from
52 the GUI to the config file.
53 Important: Don't change the group of cfg!
54 */
55 virtual void saveSettings( KConfig *cfg );
56
57
58 /**
59 Returns a pointer to the address book of this widget.
60 */
61 KABC::AddressBook *addressBook() const;
62
63 private:
64 KABC::AddressBook *mAddressBook;
65};
66
67#endif
diff --git a/kaddressbook/details/detailsviewcontainer.cpp b/kaddressbook/details/detailsviewcontainer.cpp
new file mode 100644
index 0000000..8f566cf
--- a/dev/null
+++ b/kaddressbook/details/detailsviewcontainer.cpp
@@ -0,0 +1,171 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 1996-2002 Mirko Boehm <mirko@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 <qcombobox.h>
25#include <qframe.h>
26#include <qlabel.h>
27#include <qlayout.h>
28#include <qwidgetstack.h>
29
30#include <kapplication.h>
31#include <kdebug.h>
32#include <kdialog.h>
33
34#include "look_basic.h"
35//#include "look_details.h"
36#include "look_html.h"
37
38#ifdef KAB_EMBEDDED
39#include "kabprefs.h"
40#endif //KAB_EMBEDDED
41
42
43#include "detailsviewcontainer.h"
44
45ViewContainer::ViewContainer( QWidget *parent, const char* name )
46 : QWidget( parent, name ), mCurrentLook( 0 )
47{
48 QBoxLayout *topLayout = new QVBoxLayout( this );
49 //topLayout->setMargin( KDialog::marginHint() );
50 //topLayout->setSpacing( KDialog::spacingHint() );
51 topLayout->setMargin( 0 );
52 topLayout->setSpacing( 0 );
53
54 QBoxLayout *styleLayout = new QHBoxLayout( topLayout );
55
56 QLabel *label = new QLabel( i18n("Style:"), this );
57 styleLayout->addWidget( label );
58
59 mStyleCombo = new QComboBox( this );
60 styleLayout->addWidget( mStyleCombo );
61
62 QFrame *frameRuler = new QFrame( this );
63//US frameRuler->setFrameShape( QFrame::HLine );
64//US frameRuler->setFrameShadow( QFrame::Sunken );
65//US topLayout->addWidget( frameRuler );
66
67 mDetailsStack = new QWidgetStack( this );
68 topLayout->addWidget( mDetailsStack, 1 );
69
70 registerLooks();
71
72#if 1
73 // Hide detailed view selection combo box, because we currently have
74 // only one. Reenable it when there are more detailed views.
75 label->hide();
76 mStyleCombo->hide();
77 frameRuler->hide();
78#endif
79}
80
81KABBasicLook *ViewContainer::currentLook()
82{
83 return mCurrentLook;
84}
85
86void ViewContainer::registerLooks()
87{
88 mLookFactories.append( new KABHtmlViewFactory( mDetailsStack ) );
89// mLookFactories.append( new KABDetailedViewFactory( mDetailsStack ) );
90 mStyleCombo->clear();
91
92 for ( uint i = 0; i < mLookFactories.count(); ++i )
93 mStyleCombo->insertItem( mLookFactories.at( i )->description() );
94
95 if ( !mLookFactories.isEmpty() )
96 slotStyleSelected( 0 );
97}
98
99void ViewContainer::slotStyleSelected( int index )
100{
101#ifndef KAB_EMBEDDED
102 KConfig *config = kapp->config();
103#else //KAB_EMBEDDED
104 //US I hope I got the same config object as above expected.
105 KConfig *config = KABPrefs::instance()->getConfig();
106#endif //KAB_EMBEDDED
107 KABC::Addressee addr;
108
109 if ( index >= 0 && index < mStyleCombo->count() ) {
110 if ( mCurrentLook != 0 ) {
111 mCurrentLook->saveSettings( config );
112 addr = mCurrentLook->addressee();
113
114 delete mCurrentLook;
115 mCurrentLook = 0;
116 }
117
118 KABLookFactory *factory = mLookFactories.at( index );
119 kdDebug(5720) << "ViewContainer::slotStyleSelected: "
120 << "creating look "
121 << factory->description() << endl;
122
123 mCurrentLook = factory->create();
124 mDetailsStack->raiseWidget( mCurrentLook );
125
126 connect( mCurrentLook, SIGNAL( sendEmail( const QString& ) ), this,
127 SIGNAL( sendEmail( const QString& ) ) );
128 connect( mCurrentLook, SIGNAL( browse( const QString& ) ), this,
129 SIGNAL( browse( const QString& ) ) );
130 }
131
132 mCurrentLook->restoreSettings( config );
133 mCurrentLook->setAddressee( addr );
134}
135void ViewContainer::refreshView()
136{
137 if ( mCurrentLook )
138 mCurrentLook->setAddressee( mCurrentAddressee );
139}
140
141void ViewContainer::setAddressee( const KABC::Addressee& addressee )
142{
143 if ( mCurrentLook != 0 ) {
144 if ( addressee == mCurrentAddressee )
145 return;
146 else {
147 mCurrentAddressee = addressee;
148 mCurrentLook->setAddressee( mCurrentAddressee );
149 }
150 }
151}
152
153KABC::Addressee ViewContainer::addressee()
154{
155 static KABC::Addressee empty; // do not use!
156
157 if ( !mCurrentLook )
158 return empty;
159 else
160 return mCurrentLook->addressee();
161}
162
163void ViewContainer::setReadOnly( bool state )
164{
165 if ( mCurrentLook )
166 mCurrentLook->setReadOnly( state );
167}
168
169#ifndef KAB_EMBEDDED
170#include "detailsviewcontainer.moc"
171#endif //KAB_EMBEDDED
diff --git a/kaddressbook/details/detailsviewcontainer.h b/kaddressbook/details/detailsviewcontainer.h
new file mode 100644
index 0000000..b561d12
--- a/dev/null
+++ b/kaddressbook/details/detailsviewcontainer.h
@@ -0,0 +1,103 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 1996-2002 Mirko Boehm <mirko@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#ifndef DETAILSVIEWCONTAINER_H
25#define DETAILSVIEWCONTAINER_H
26
27#include <qptrlist.h>
28
29#include "look_basic.h"
30
31class QComboBox;
32class QWidgetStack;
33
34class ViewContainer : public QWidget
35{
36 Q_OBJECT
37
38 public:
39 ViewContainer( QWidget *parent = 0, const char* name = 0 );
40
41 /**
42 Return the look currently selected. If there is none, it
43 returns zero. Do not use this pointer to store a reference
44 to a look, the user might select another one (e.g., create
45 a new object) at any time.
46 */
47 KABBasicLook *currentLook();
48 void refreshView();
49 /**
50 Return the contact currently displayed.
51 */
52 KABC::Addressee addressee();
53
54 public slots:
55 /**
56 Set the contact currently displayed.
57 */
58 void setAddressee( const KABC::Addressee& addressee );
59
60 /**
61 Set read-write state.
62 */
63 void setReadOnly( bool state );
64
65 signals:
66 /**
67 The contact has been changed.
68 */
69 void addresseeChanged();
70
71 /**
72 The user acticated the email address displayed. This may happen
73 by, for example, clicking on the displayed mailto-URL.
74 */
75 void sendEmail( const QString& );
76
77 /**
78 The user activated one of the displayed HTTP URLs. For example
79 by clicking on the displayed homepage address.
80 */
81 void browse( const QString& );
82
83 protected:
84 /**
85 A style has been selected. Overloaded from base class.
86 */
87 void slotStyleSelected( int );
88
89 /**
90 Register the available looks.
91 */
92 void registerLooks();
93
94 private:
95 KABC::Addressee mCurrentAddressee;
96 KABBasicLook *mCurrentLook;
97 QPtrList<KABLookFactory> mLookFactories;
98
99 QComboBox *mStyleCombo;
100 QWidgetStack *mDetailsStack;
101};
102
103#endif
diff --git a/kaddressbook/details/global.h b/kaddressbook/details/global.h
new file mode 100644
index 0000000..3c52bc2
--- a/dev/null
+++ b/kaddressbook/details/global.h
@@ -0,0 +1,28 @@
1#ifndef KAB3_GLOBAL_H
2#define KAB3_GLOBAL_H
3
4// keys of configuration file settings:
5
6#define ConfigGeneral "General"
7
8#define ConfigGeneral_RememberLastContact "RememberLastContact"
9#define ConfigGeneral_ShowContactInHeader "ShowContactInHeader"
10
11#define ConfigView "View"
12
13#define ConfigView_View "ConfigView"
14
15#define ConfigView_UseKDEDefaultFonts "UseKDEDefaultFonts"
16#define ConfigView_DefaultBackgroundImage "DefaultBackgroundImage"
17#define ConfigView_DefaultBackgroundColor "DefaultBackgroundColor"
18#define ConfigView_UseDefaultBackground "UseDefaultBackground"
19
20#define ConfigView_HeadlineBGColor "HeadlineBGColor"
21#define ConfigView_UseHeadlineBGColor "UseHeadlineBGColor"
22#define ConfigView_HeadlineTextColor "HeadlineTextColor"
23#define ConfigView_HeadlineFont "HeadlineFont"
24#define ConfigView_BodyFont "BodyFont"
25#define ConfigView_DetailsFont "DetailsFont"
26
27
28#endif
diff --git a/kaddressbook/details/look_basic.cpp b/kaddressbook/details/look_basic.cpp
new file mode 100644
index 0000000..0245686
--- a/dev/null
+++ b/kaddressbook/details/look_basic.cpp
@@ -0,0 +1,75 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 1996-2002 Mirko Boehm <mirko@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 <kdebug.h>
25
26#include "look_basic.h"
27
28KABBasicLook::KABBasicLook( QWidget *parent, const char *name )
29 : QVBox( parent, name ), mReadOnly( false )
30{
31}
32
33void KABBasicLook::setReadOnly( bool state )
34{
35 mReadOnly = state;
36}
37
38bool KABBasicLook::isReadOnly() const
39{
40 return mReadOnly;
41}
42
43void KABBasicLook::setAddressee( const KABC::Addressee &addr )
44{
45 if ( mAddressee == addr )
46 return;
47
48 mAddressee = addr;
49 repaint( false );
50}
51
52KABC::Addressee KABBasicLook::addressee()
53{
54 return mAddressee;
55}
56
57void KABBasicLook::restoreSettings( KConfig* )
58{
59}
60
61void KABBasicLook::saveSettings( KConfig* )
62{
63}
64
65KABLookFactory::KABLookFactory( QWidget *parent, const char *name )
66 : mParent( parent ), mName( name )
67{
68}
69
70KABLookFactory::~KABLookFactory()
71{
72}
73#ifndef KAB_EMBEDDED
74#include "look_basic.moc"
75#endif //KAB_EMBEDDED
diff --git a/kaddressbook/details/look_basic.h b/kaddressbook/details/look_basic.h
new file mode 100644
index 0000000..7e8baff
--- a/dev/null
+++ b/kaddressbook/details/look_basic.h
@@ -0,0 +1,134 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 1996-2002 Mirko Boehm <mirko@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#ifndef LOOK_KABBASIC_H
25#define LOOK_KABBASIC_H
26
27#include <kabc/addressbook.h>
28#include <qvbox.h>
29
30class KConfig;
31
32/**
33 This is a pure virtual base class that defines the
34 interface for how to display and change entries of
35 the KDE addressbook.
36
37 This basic widget does not show anything in its client space.
38 Derive it and implement its look and how the user may edit the
39 entry.
40
41 The paintEvent() has to paint the whole widget, since repaint()
42 calls will not delete the widgets background.
43 */
44class KABBasicLook : public QVBox
45{
46 Q_OBJECT
47
48 public:
49 /**
50 The constructor.
51 */
52 KABBasicLook( QWidget *parent = 0, const char *name = 0 );
53
54 /**
55 Set the entry. It will be displayed automatically.
56 */
57 virtual void setAddressee( const KABC::Addressee& addressee );
58
59 /**
60 Get the current entry.
61 */
62 virtual KABC::Addressee addressee();
63
64 /**
65 Configure the view from the configuration file.
66 */
67 virtual void restoreSettings( KConfig* );
68
69 /**
70 Save the view settings to the configuration file.
71 */
72 virtual void saveSettings( KConfig* );
73
74 /**
75 Retrieve read-write state.
76 */
77 bool isReadOnly() const;
78
79 signals:
80 /**
81 This signal is emitted when the user changed the entry.
82 */
83 void entryChanged();
84
85 /**
86 This signal indicates that the entry needs to be changed
87 immidiately in the database. This might be due to changes in
88 values that are available in menus.
89 */
90 void saveMe();
91
92 /**
93 The user acticated the email address displayed. This may happen
94 by, for example, clicking on the displayed mailto-URL.
95 */
96 void sendEmail( const QString &email );
97
98 /**
99 The user activated one of the displayed HTTP URLs. For example
100 by clicking on the displayed homepage address.
101 */
102 void browse( const QString &url );
103
104 public slots:
105 /**
106 Set read-write state.
107 */
108 virtual void setReadOnly( bool state );
109
110 private:
111 KABC::Addressee mAddressee;
112 bool mReadOnly;
113};
114
115class KABLookFactory
116{
117 public:
118 KABLookFactory( QWidget *parent = 0, const char *name = 0 );
119 virtual ~KABLookFactory();
120
121 virtual KABBasicLook *create() = 0;
122
123 /**
124 Overload this method to provide a one-liner description
125 for your look.
126 */
127 virtual QString description() = 0;
128
129 protected:
130 QWidget *mParent;
131 const char* mName;
132};
133
134#endif
diff --git a/kaddressbook/details/look_details.cpp b/kaddressbook/details/look_details.cpp
new file mode 100644
index 0000000..51ec0c0
--- a/dev/null
+++ b/kaddressbook/details/look_details.cpp
@@ -0,0 +1,419 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 1996-2002 Mirko Boehm <mirko@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 <kconfig.h>
25#include <kdebug.h>
26#include <kglobalsettings.h>
27#include <kinstance.h>
28#include <klocale.h>
29#include <kstandarddirs.h>
30
31#include <qcursor.h>
32#include <qdir.h>
33#include <qpainter.h>
34#include <qpopupmenu.h>
35
36#include "global.h"
37#include "kabentrypainter.h"
38
39#include "look_details.h"
40
41#define GRID 5
42
43const QString KABDetailedView::mBorderedBGDir = "kab3part/backgrounds/bordered/";
44const QString KABDetailedView::mTiledBGDir = "kab3part/backgrounds/tiled/";
45
46KABDetailedView::KABDetailedView( QWidget *parent, const char *name )
47 : KABBasicLook( parent, name ), mPainter( 0 ), mBackgroundStyle( None ),
48 mDefaultBGColor( white ), mHeadLineBGColor( darkBlue ),
49 mHeadLineTextColor( yellow ), mGrid( 3 ), mMenuBorderedBG( 0 ),
50 mMenuTiledBG( 0 )
51{
52 KToggleAction** actions[] = {
53 &mActionShowAddresses,
54 &mActionShowEmails,
55 &mActionShowPhones,
56 &mActionShowURLs
57 };
58
59 QString actionTexts[] = {
60 i18n( "Show Postal Addresses" ),
61 i18n( "Show Email Addresses" ),
62 i18n( "Show Telephone Numbers" ),
63 i18n( "Show Web Pages (URLs)" )
64 };
65
66 QFont general = KGlobalSettings::generalFont();
67 QFont fixed = KGlobalSettings::fixedFont();
68 QString gfont = general.family();
69 QString ffont = fixed.family();
70
71 int gpointsize = general.pixelSize();
72 if ( gpointsize == -1 )
73 gpointsize = general.pointSize();
74
75 int fpointsize = fixed.pixelSize();
76 if ( fpointsize == -1 )
77 fpointsize = fixed.pointSize();
78
79 mPainter = new KABEntryPainter;
80
81 mPainter->setForegroundColor( black );
82 mPainter->setHeaderColor( mHeadLineTextColor );
83 mPainter->setUseHeaderColor( mUseHeadLineBGColor );
84 mPainter->setBackgroundColor( mHeadLineBGColor );
85
86 mPainter->setHeaderFont( QFont( gfont, gpointsize + 4, QFont::Bold, true ) );
87 mPainter->setHeadLineFont( QFont( gfont, gpointsize + 2, QFont::Bold, true ) );
88 mPainter->setBodyFont( QFont( gfont, gpointsize, QFont::Normal, false ) );
89 mPainter->setFixedFont( QFont( ffont, fpointsize, QFont::Normal, false ) );
90 mPainter->setCommentFont( QFont( gfont, gpointsize, QFont::Normal, false ) );
91
92 const int numActions = sizeof( actions ) / sizeof( actions[ 0 ] );
93
94 for ( int count = 0; count < numActions; ++count ) {
95 *actions[ count ] = new KToggleAction( actionTexts[ count ] );
96 (*actions[ count ])->setChecked( true );
97 }
98
99 setMouseTracking( true );
100
101 setBackgroundMode( NoBackground );
102}
103
104KABDetailedView::~KABDetailedView()
105{
106 delete mPainter;
107 mPainter = 0;
108}
109
110bool KABDetailedView::getBackground( QString path, QPixmap& image )
111{
112 QMap<QString, QPixmap>::iterator pos;
113
114 pos = mBackgroundMap.find( path );
115 if ( pos == mBackgroundMap.end() ) { // the image has not been loaded previously
116 if ( image.load( path ) ) {
117 mBackgroundMap[ path ] = image;
118 return true;
119 } else
120 return false;
121 } else { // image found in cache
122 image = pos.data();
123 return true;
124 }
125}
126
127void KABDetailedView::paintEvent( QPaintEvent* )
128{
129 const int BorderSpace = mGrid;
130 QPixmap pm( width(), height() );
131 QPainter p;
132
133 QRect entryArea = QRect( BorderSpace, mGrid, width() - mGrid - BorderSpace,
134 height() - 2 * mGrid );
135 p.begin( &pm );
136
137 p.setPen( darkBlue );
138 p.setBrush( mDefaultBGColor );
139 p.drawRect( 0, 0, width(), height() );
140 switch ( mBackgroundStyle ) {
141 case Tiled:
142 p.drawTiledPixmap( 1, 1, width() - 2, height() - 2, mCurrentBackground );
143 break;
144 case Bordered:
145 p.drawTiledPixmap( 1, 1, QMIN( width() - 2, mCurrentBackground.width() ),
146 height() - 2, mCurrentBackground );
147 break;
148 case None: // no BG image defined for this entry:
149 default:
150 if ( mUseDefaultBGImage )
151 p.drawTiledPixmap( 1, 1, width() - 2, height() - 2, mDefaultBGImage );
152 break;
153 };
154
155 p.setViewport( entryArea );
156
157 mPainter->setShowAddresses( mActionShowAddresses->isChecked() );
158 mPainter->setShowEmails( mActionShowEmails->isChecked() );
159 mPainter->setShowPhones( mActionShowPhones->isChecked() );
160 mPainter->setShowURLs( mActionShowURLs->isChecked() );
161 mPainter->printAddressee( addressee(), QRect( 0, 0, entryArea.width(),
162 entryArea.height() ), &p );
163 p.end();
164 bitBlt( this, 0, 0, &pm );
165}
166
167void KABDetailedView::mouseMoveEvent( QMouseEvent *e )
168{
169 QPoint bias( mGrid, mGrid );
170 int rc;
171 bool hit = false;
172
173 if ( ( rc = mPainter->hitsEmail( e->pos() - bias ) ) != -1 )
174 hit = true;
175 else if ( ( rc = mPainter->hitsURL( e->pos() - bias ) ) != -1 )
176 hit = true;
177 else if ( ( rc = mPainter->hitsPhone( e->pos() - bias ) ) != -1 )
178 hit = true;
179 else if ( ( rc = mPainter->hitsTalk( e->pos() - bias ) ) != -1 )
180 hit = true;
181
182 if ( hit ) {
183 if ( cursor().shape() != PointingHandCursor )
184 setCursor( PointingHandCursor );
185 else if( cursor().shape() != ArrowCursor )
186 setCursor(ArrowCursor);
187 }
188}
189
190void KABDetailedView::mousePressEvent( QMouseEvent *e )
191{
192 QPopupMenu menu( this );
193 QPopupMenu *menuBG = new QPopupMenu( &menu );
194 mMenuBorderedBG = new QPopupMenu( &menu );
195 mMenuTiledBG = new QPopupMenu( &menu );
196
197 menu.insertItem( i18n( "Select Background" ), menuBG );
198 menuBG->insertItem( i18n( "Bordered Backgrounds" ), mMenuBorderedBG );
199 menuBG->insertItem( i18n( "Tiled Backgrounds" ), mMenuTiledBG );
200 menu.insertSeparator();
201
202 QPoint point = e->pos() - QPoint( mGrid, mGrid );
203 int rc;
204 QStringList dirsBorderedBG, dirsTiledBG;
205 QDir dir;
206
207 switch( e->button() ) {
208 case QMouseEvent::RightButton:
209 if ( isReadOnly() )
210 menu.setItemEnabled( menu.idAt( 0 ), false );
211 else {
212 // TODO: settings need to be saved in view options
213 dirsBorderedBG = KGlobal::instance()->dirs()->findDirs( "data", mBorderedBGDir );
214 if ( dirsBorderedBG.count() > 0 ) {
215 dir.setPath( dirsBorderedBG[ 0 ] );
216 mBorders = dir.entryList( QDir::Files );
217 for ( uint count = 0; count < mBorders.count(); ++count )
218 mMenuBorderedBG->insertItem( mBorders[ count ], count );
219
220 connect( mMenuBorderedBG, SIGNAL( activated( int ) ),
221 SLOT( slotBorderedBGSelected( int ) ) );
222 } else
223 menuBG->setItemEnabled( menuBG->idAt( 0 ), false );
224
225 dirsTiledBG = KGlobal::instance()->dirs()->findDirs( "data", mTiledBGDir );
226 if ( dirsTiledBG.count() > 0 ) {
227 dir.setPath( dirsTiledBG[ 0 ] );
228 mTiles = dir.entryList( QDir::Files );
229 for ( uint count = 0; count < mTiles.count(); ++count )
230 mMenuTiledBG->insertItem( mTiles[ count ], count );
231
232 connect( mMenuTiledBG, SIGNAL( activated( int ) ),
233 SLOT( slotTiledBGSelected( int ) ) );
234 } else
235 menuBG->setItemEnabled( menuBG->idAt( 1 ), false );
236 }
237
238 mActionShowAddresses->plug( &menu );
239 mActionShowEmails->plug( &menu );
240 mActionShowPhones->plug( &menu );
241 mActionShowURLs->plug( &menu );
242
243 menu.exec( e->globalPos() );
244 break;
245
246 case QMouseEvent::LeftButton:
247 // find whether the pointer touches an email address, URL,
248 // talk address or telephone number:
249 if ( ( rc = mPainter->hitsEmail( point ) ) != -1 ) {
250 emit sendEmail( addressee().emails()[ rc ] );
251 break;
252 }
253 if ( ( rc = mPainter->hitsURL( point ) ) != -1 ) {
254 emit browse( addressee().url().prettyURL() );
255 break;
256 }
257 if ( ( rc = mPainter->hitsPhone( point ) ) != -1 ) {
258 // not implemented yet
259 break;
260 }
261 if ( ( rc = mPainter->hitsTalk( point ) ) != -1 ) {
262 // not implemented yet
263 break;
264 }
265 break;
266 default:
267 break;
268 }
269
270 mMenuBorderedBG = 0;
271 mMenuTiledBG = 0;
272}
273
274void KABDetailedView::setAddressee( const KABC::Addressee &addr )
275{
276 BackgroundStyle style = None;
277 QString dir, file, styleSetting;
278 KABBasicLook::setAddressee( addr );
279
280 // TODO: preload path and styleSetting with possible preference values
281 styleSetting = addressee().custom( "kab", "BackgroundStyle" );
282 style = (BackgroundStyle)styleSetting.toInt();
283 file = addressee().custom( "kab", "BackgroundImage" );
284 if ( !file.isEmpty() ) {
285 switch ( style ) {
286 case Tiled:
287 dir = mTiledBGDir;
288 break;
289 case Bordered:
290 dir = mBorderedBGDir;
291 break;
292 case None:
293 default:
294 break;
295 }
296
297 QStringList dirs = KGlobal::instance()->dirs()->findDirs( "data", dir );
298 mBackgroundStyle = None;
299 if ( !dirs.isEmpty() ) {
300 uint count = 0;
301 for ( ; count < dirs.count(); ++count ) {
302 QDir folder;
303 folder.setPath( dirs[ count ] );
304 file = folder.absPath() + "/" + file;
305 if ( getBackground( file, mCurrentBackground ) ) {
306 mBackgroundStyle = style;
307 break;
308 }
309 }
310
311 if ( count == dirs.count() ) {
312 kdDebug(5720) << "KABDetailedView::setEntry: " << file
313 << " not locatable." << endl;
314 }
315 }
316 } else { // no background here
317 mBackgroundStyle = None;
318 mCurrentBackground.resize( 0, 0 );
319 }
320
321 repaint( false );
322}
323
324void KABDetailedView::slotBorderedBGSelected( int index )
325{
326 if ( index >= 0 && (uint)index < mBorders.count() && !isReadOnly() ) {
327 // get the selection and make it a full path
328 QString path = mBorders[ index ];
329 mBackgroundStyle = Bordered;
330 addressee().insertCustom( "kab", "BackgroundStyle",
331 QString().setNum( mBackgroundStyle ) );
332 addressee().insertCustom( "kab", "BackgroundImage", path );
333 setAddressee( addressee() );
334 }
335}
336
337void KABDetailedView::slotTiledBGSelected( int index )
338{
339 if ( index >= 0 && (uint)index < mTiles.count() && !isReadOnly() ) {
340 QString path = mTiles[ index ];
341 mBackgroundStyle = Tiled;
342 addressee().insertCustom( "kab", "BackgroundStyle",
343 QString().setNum( mBackgroundStyle ) );
344 addressee().insertCustom( "kab", "BackgroundImage", path );
345 setAddressee( addressee() );
346 }
347}
348
349void KABDetailedView::setReadOnly( bool state )
350{
351 KABBasicLook::setReadOnly( state );
352 repaint( false );
353}
354
355void KABDetailedView::restoreSettings( KConfig *config )
356{
357 QFont general = KGlobalSettings::generalFont();
358 QFont fixed = KGlobalSettings::fixedFont();
359 QString gfont = general.family();
360 QString ffont = fixed.family();
361
362 int gpointsize = general.pixelSize();
363 if ( gpointsize == -1 )
364 gpointsize = general.pointSize();
365
366 int fpointsize = fixed.pixelSize();
367 if ( fpointsize == -1 )
368 fpointsize = fixed.pointSize();
369
370 config->setGroup( ConfigView );
371
372 // load the default background image:
373 QString bgImage;
374 mUseDefaultBGImage = config->readBoolEntry( ConfigView_UseDefaultBackground, true );
375 mDefaultBGColor = config->readColorEntry( ConfigView_DefaultBackgroundColor, &white );
376 bgImage = config->readEntry( ConfigView_DefaultBackgroundImage, "konqueror/tiles/kenwimer.png" );
377
378 if ( mUseDefaultBGImage ) {
379 uint count = 0;
380 QStringList dirs = KGlobal::instance()->dirs()->findDirs( "data", "/" );
381 if ( !dirs.isEmpty() ) {
382 for ( count = 0; count < dirs.count(); ++count ) {
383 if ( getBackground( dirs[ count ] + "/" + bgImage, mDefaultBGImage ) )
384 break;
385 }
386 }
387
388 if ( count == dirs.count() ) {
389 mUseDefaultBGImage = getBackground( bgImage, mDefaultBGImage );
390 if ( !mUseDefaultBGImage )
391 kdDebug(5720) << "KABDetailedView::configure: "
392 << "default BG image selected, but could not be loaded."
393 << endl;
394 }
395 }
396
397 mDefaultBGColor = config->readColorEntry( ConfigView_DefaultBackgroundColor, &white );
398 mHeadLineBGColor = config->readColorEntry( ConfigView_HeadlineBGColor, &darkBlue );
399 mHeadLineTextColor = config->readColorEntry( ConfigView_HeadlineTextColor, &yellow );
400 mUseHeadLineBGColor = config->readBoolEntry( ConfigView_UseHeadlineBGColor, true );
401
402 if ( !mPainter )
403 mPainter = new KABEntryPainter;
404
405 mPainter->setForegroundColor( black );
406 mPainter->setHeaderColor( mHeadLineTextColor );
407 mPainter->setUseHeaderColor( mUseHeadLineBGColor );
408 mPainter->setBackgroundColor( mHeadLineBGColor );
409
410 mPainter->setHeaderFont( QFont( gfont, gpointsize + 4, QFont::Bold, true ) );
411 mPainter->setHeadLineFont( QFont( gfont, gpointsize + 2, QFont::Bold, true ) );
412 mPainter->setBodyFont( QFont( gfont, gpointsize, QFont::Normal, false ) );
413 mPainter->setFixedFont( QFont( ffont, fpointsize, QFont::Normal, false ) );
414 mPainter->setCommentFont( QFont( gfont, gpointsize, QFont::Normal, false ) );
415}
416
417#ifndef KAB_EMBEDDED
418#include "look_details.moc"
419#endif //KAB_EMBEDDED
diff --git a/kaddressbook/details/look_details.h b/kaddressbook/details/look_details.h
new file mode 100644
index 0000000..e8d50a9
--- a/dev/null
+++ b/kaddressbook/details/look_details.h
@@ -0,0 +1,157 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 1996-2002 Mirko Boehm <mirko@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#ifndef LOOK_DETAILS_H
25#define LOOK_DETAILS_H
26
27#include <kabc/addressbook.h>
28#include <kaction.h>
29#include <klocale.h>
30
31#include <qmap.h>
32#include <qpixmap.h>
33#include <qptrlist.h>
34#include <qrect.h>
35
36#include "look_basic.h"
37
38class KABEntryPainter;
39class QComboBox;
40
41/**
42 This class implements the detailed view.
43 Currently, there is no possibility to change the entry in this
44 view.
45 */
46
47class KABDetailedView : public KABBasicLook
48{
49 Q_OBJECT
50
51 public:
52 /**
53 Enum to select how the background is drawn.
54 */
55 enum BackgroundStyle
56 {
57 None,
58 Tiled,
59 Bordered
60 };
61
62 /**
63 The constructor.
64 */
65 KABDetailedView( QWidget *parent = 0, const char* name = 0 );
66
67 /**
68 The virtual destructor.
69 */
70 virtual ~KABDetailedView();
71
72 /**
73 Set the addressee.
74 */
75 void setAddressee( const KABC::Addressee& );
76
77 /**
78 Overloaded from KABBasicLook.
79 */
80 void setReadOnly( bool );
81
82 /**
83 Overloaded from KABBasicLook.
84 */
85 void restoreSettings( KConfig* );
86
87 public slots:
88 void slotBorderedBGSelected( int index );
89 void slotTiledBGSelected( int index );
90
91 protected:
92 void paintEvent( QPaintEvent* );
93 void mousePressEvent( QMouseEvent* );
94 void mouseMoveEvent( QMouseEvent* );
95
96 /**
97 A method to retrieve a background image according to the path
98 stored in the entry. It is either loaded
99 from backgrounds, that acts as a cache, or from the file
100 and added to @see backgrounds.
101 */
102 bool getBackground( QString path, QPixmap& image );
103
104 private:
105 QPtrList<QRect> mURLRects;
106 QPtrList<QRect> mEmailRects;
107 QPtrList<QRect> mPhoneRects;
108 KABEntryPainter *mPainter;
109
110 QMap<QString, QPixmap> mBackgroundMap;
111 QPixmap mCurrentBackground;
112
113 BackgroundStyle mBackgroundStyle;
114
115 bool mUseDefaultBGImage;
116 bool mUseHeadLineBGColor;
117
118 QColor mDefaultBGColor;
119 QColor mHeadLineBGColor;
120 QColor mHeadLineTextColor;
121
122 QPixmap mDefaultBGImage;
123
124 KToggleAction *mActionShowAddresses;
125 KToggleAction *mActionShowEmails;
126 KToggleAction *mActionShowPhones;
127 KToggleAction *mActionShowURLs;
128
129 const int mGrid;
130 QStringList mBorders;
131 QStringList mTiles;
132
133 QPopupMenu *mMenuBorderedBG;
134 QPopupMenu *mMenuTiledBG;
135
136 static const QString mBorderedBGDir;
137 static const QString mTiledBGDir;
138};
139
140class KABDetailedViewFactory : public KABLookFactory
141{
142 public:
143 KABDetailedViewFactory( QWidget *parent = 0, const char *name = 0 )
144 : KABLookFactory( parent, name ) {}
145
146 KABBasicLook *create()
147 {
148 return new KABDetailedView( mParent, mName );
149 }
150
151 QString description()
152 {
153 return i18n( "Detailed Style: Display all details, no modifications." );
154 }
155};
156
157#endif
diff --git a/kaddressbook/details/look_html.cpp b/kaddressbook/details/look_html.cpp
new file mode 100644
index 0000000..2a70273
--- a/dev/null
+++ b/kaddressbook/details/look_html.cpp
@@ -0,0 +1,45 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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 <libkdepim/addresseeview.h>
25
26#include "look_html.h"
27#include <qscrollview.h>
28KABHtmlView::KABHtmlView( QWidget *parent, const char *name )
29 : KABBasicLook( parent, name )
30{
31 mView = new KPIM::AddresseeView( this );
32}
33
34KABHtmlView::~KABHtmlView()
35{
36}
37
38void KABHtmlView::setAddressee( const KABC::Addressee &addr )
39{
40 mView->setAddressee( addr );
41}
42
43#ifndef KAB_EMBEDDED
44#include "look_html.moc"
45#endif //KAB_EMBEDDED
diff --git a/kaddressbook/details/look_html.h b/kaddressbook/details/look_html.h
new file mode 100644
index 0000000..68a02d9
--- a/dev/null
+++ b/kaddressbook/details/look_html.h
@@ -0,0 +1,75 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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#ifndef LOOK_HTML_H
25#define LOOK_HTML_H
26
27#include <klocale.h>
28
29#include "look_basic.h"
30
31namespace KABC { class Addressee; }
32namespace KPIM { class AddresseeView; }
33
34class KABHtmlView : public KABBasicLook
35{
36 Q_OBJECT
37
38 public:
39 /**
40 The constructor.
41 */
42 KABHtmlView( QWidget *parent = 0, const char* name = 0 );
43
44 /**
45 The virtual destructor.
46 */
47 virtual ~KABHtmlView();
48
49 /**
50 Set the addressee.
51 */
52 void setAddressee( const KABC::Addressee& );
53
54 private:
55 KPIM::AddresseeView *mView;
56};
57
58class KABHtmlViewFactory : public KABLookFactory
59{
60 public:
61 KABHtmlViewFactory( QWidget *parent = 0, const char *name = 0 )
62 : KABLookFactory( parent, name ) {}
63
64 KABBasicLook *create()
65 {
66 return new KABHtmlView( mParent, mName );
67 }
68
69 QString description()
70 {
71 return i18n( "HTML table style." );
72 }
73};
74
75#endif
diff --git a/kaddressbook/emaileditwidget.cpp b/kaddressbook/emaileditwidget.cpp
new file mode 100644
index 0000000..0e01b02
--- a/dev/null
+++ b/kaddressbook/emaileditwidget.cpp
@@ -0,0 +1,275 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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 <qcheckbox.h>
25#include <qlabel.h>
26#include <qlayout.h>
27#include <qpushbutton.h>
28#include <qstring.h>
29#include <qtoolbutton.h>
30#include <qtooltip.h>
31#include <qlistbox.h>
32
33#ifndef KAB_EMBEDDED
34#include <kaccelmanager.h>
35#endif //KAB_EMBEDDED
36#include <kconfig.h>
37#include <kcombobox.h>
38#include <kdebug.h>
39#include <kglobal.h>
40#include <kdialog.h>
41#include <kiconloader.h>
42#include <klineedit.h>
43#include <klocale.h>
44#include <kmessagebox.h>
45
46#include "emaileditwidget.h"
47
48EmailEditWidget::EmailEditWidget( QWidget *parent, const char *name )
49 : QWidget( parent, name )
50{
51 QGridLayout *topLayout = new QGridLayout( this, 2, 2 );
52 topLayout->setSpacing( KDialog::spacingHint() );
53 QLabel* label = new QLabel( this );
54
55 label->setPixmap( KGlobal::iconLoader()->loadIcon( "mail_send", KIcon::Desktop, 0) );
56
57 topLayout->addWidget( label, 0, 0 );
58 label->setAlignment( AlignCenter );
59 QPushButton *editButton = new QPushButton( i18n( "Edit Email Addresses..." ), this);
60 topLayout->addWidget( editButton, 0, 1 );
61 label = new QLabel( i18n( "Email:" ), this );
62 topLayout->addWidget( label, 1, 0 );
63
64 mEmailEdit = new KLineEdit( this );
65 connect( mEmailEdit, SIGNAL( textChanged( const QString& ) ),
66 SLOT( textChanged( const QString& ) ) );
67 connect( mEmailEdit, SIGNAL( textChanged( const QString& ) ),
68 SIGNAL( modified() ) );
69 label->setBuddy( mEmailEdit );
70 topLayout->addWidget( mEmailEdit, 1, 1 );
71
72
73 connect( editButton, SIGNAL( clicked() ), SLOT( edit() ) );
74
75 topLayout->activate();
76}
77
78EmailEditWidget::~EmailEditWidget()
79{
80}
81
82void EmailEditWidget::setEmails( const QStringList &list )
83{
84 mEmailList = list;
85
86 bool blocked = mEmailEdit->signalsBlocked();
87 mEmailEdit->blockSignals( true );
88 if ( list.count() > 0 )
89 mEmailEdit->setText( list[ 0 ] );
90 else
91 mEmailEdit->setText( "" );
92 mEmailEdit->blockSignals( blocked );
93}
94
95QStringList EmailEditWidget::emails()
96{
97 if ( mEmailEdit->text().isEmpty() ) {
98 if ( mEmailList.count() > 0 )
99 mEmailList.remove( mEmailList.begin() );
100 } else {
101 if ( mEmailList.count() > 0 )
102 mEmailList.remove( mEmailList.begin() );
103
104 mEmailList.prepend( mEmailEdit->text() );
105 }
106
107 return mEmailList;
108}
109
110void EmailEditWidget::edit()
111{
112 EmailEditDialog dlg( mEmailList, this );
113
114 if ( dlg.exec() ) {
115 if ( dlg.changed() ) {
116 mEmailList = dlg.emails();
117 mEmailEdit->setText( mEmailList[ 0 ] );
118 emit modified();
119 }
120 }
121}
122
123void EmailEditWidget::textChanged( const QString &text )
124{
125 if ( mEmailList.count() > 0 )
126 mEmailList.remove( mEmailList.begin() );
127
128 mEmailList.prepend( text );
129}
130
131
132EmailEditDialog::EmailEditDialog( const QStringList &list, QWidget *parent,
133 const char *name )
134 : KDialogBase( KDialogBase::Plain, i18n( "Edit Email Addresses" ),
135 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
136 parent, name, true )
137{
138 QWidget *page = plainPage();
139
140 QGridLayout *topLayout = new QGridLayout( page, 4, 3 );
141
142 QLabel *label = new QLabel( i18n( "Email address:" ), page );
143 topLayout->addWidget( label, 0, 0 );
144
145 mEmailEdit = new KLineEdit( page );
146 label->setBuddy( mEmailEdit );
147 topLayout->addWidget( mEmailEdit, 0, 1 );
148 connect( mEmailEdit, SIGNAL( returnPressed() ), SLOT( add() ) );
149 connect( mEmailEdit, SIGNAL( textChanged( const QString& ) ),
150 SLOT( emailChanged() ) );
151
152 mAddButton = new QPushButton( i18n( "Add" ), page );
153 mAddButton->setEnabled( false );
154 connect( mAddButton, SIGNAL( clicked() ), SLOT( add() ) );
155 topLayout->addWidget( mAddButton, 0, 2 );
156
157 mEmailListBox = new QListBox( page );
158
159 // Make sure there is room for the scrollbar
160 mEmailListBox->setMinimumHeight( mEmailListBox->sizeHint().height() + 30 );
161 connect( mEmailListBox, SIGNAL( highlighted( int ) ),
162 SLOT( selectionChanged( int ) ) );
163 topLayout->addMultiCellWidget( mEmailListBox, 1, 3, 0, 1 );
164
165 mEditButton = new QPushButton( i18n( "Change" ), page );
166 connect( mEditButton, SIGNAL( clicked() ), SLOT( edit() ) );
167 topLayout->addWidget( mEditButton, 1, 2 );
168
169 mRemoveButton = new QPushButton( i18n( "Remove" ), page );
170 connect( mRemoveButton, SIGNAL( clicked() ), SLOT( remove() ) );
171 topLayout->addWidget( mRemoveButton, 2, 2 );
172
173 mStandardButton = new QPushButton( i18n( "Set Standard" ), page );
174 connect( mStandardButton, SIGNAL( clicked() ), SLOT( standard() ) );
175 topLayout->addWidget( mStandardButton, 3, 2 );
176
177 topLayout->activate();
178 QStringList items = list;
179
180qDebug("EmailEditDialog::EmailEditDialog has to be changed (lowPrio)");
181//US must be fixed !!!
182/*
183 if ( items.remove( "" ) > 0 )
184 mChanged = true;
185 else
186 mChanged = false;
187*/
188
189 mEmailListBox->insertStringList( items );
190 // set default state
191 selectionChanged( -1 );
192
193#ifndef KAB_EMBEDDED
194 KAcceleratorManager::manage( this );
195#else //KAB_EMBEDDED
196//US qDebug("EmailEditDialog::EmailEditDialog has to be changed");
197#endif //KAB_EMBEDDED
198
199}
200
201EmailEditDialog::~EmailEditDialog()
202{
203}
204
205QStringList EmailEditDialog::emails() const
206{
207 QStringList emails;
208
209 for ( uint i = 0; i < mEmailListBox->count(); ++i )
210 emails << mEmailListBox->text( i );
211
212 return emails;
213}
214
215void EmailEditDialog::add()
216{
217 mEmailListBox->insertItem( mEmailEdit->text() );
218
219 mEmailEdit->clear();
220 mEmailEdit->setFocus();
221
222 mChanged = true;
223}
224
225void EmailEditDialog::edit()
226{
227 mEmailEdit->setText( mEmailListBox->currentText() );
228 mEmailEdit->setFocus();
229}
230
231void EmailEditDialog::remove()
232{
233 QString address = mEmailListBox->currentText();
234
235 QString text = i18n( "<qt>Are you sure that you want to remove the email address <b>%1</b>?</qt>" ).arg( address );
236 QString caption = i18n( "Confirm Remove" );
237
238 if ( KMessageBox::questionYesNo( this, text, caption ) == KMessageBox::Yes ) {
239 mEmailListBox->removeItem( mEmailListBox->currentItem() );
240 mChanged = true;
241 }
242}
243
244bool EmailEditDialog::changed() const
245{
246 return mChanged;
247}
248
249void EmailEditDialog::standard()
250{
251 QString text = mEmailListBox->currentText();
252 mEmailListBox->removeItem( mEmailListBox->currentItem() );
253 mEmailListBox->insertItem( text, 0 );
254 mEmailListBox->setSelected( 0, true );
255
256 mChanged = true;
257}
258
259void EmailEditDialog::selectionChanged( int index )
260{
261 bool value = ( index >= 0 ); // An item is selected
262
263 mRemoveButton->setEnabled( value );
264 mEditButton->setEnabled( value );
265 mStandardButton->setEnabled( value );
266}
267
268void EmailEditDialog::emailChanged()
269{
270 mAddButton->setEnabled( !mEmailEdit->text().isEmpty() );
271}
272
273#ifndef KAB_EMBEDDED
274#include "emaileditwidget.moc"
275#endif //KAB_EMBEDDED
diff --git a/kaddressbook/emaileditwidget.h b/kaddressbook/emaileditwidget.h
new file mode 100644
index 0000000..acdecaf
--- a/dev/null
+++ b/kaddressbook/emaileditwidget.h
@@ -0,0 +1,101 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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#ifndef EMAILEDITWIDGET_H
25#define EMAILEDITWIDGET_H
26
27#include <kabc/addressee.h>
28#include <kdialogbase.h>
29
30#include "addresseeconfig.h"
31
32class QButtonGroup;
33class QCheckBox;
34class QListView;
35class QListBox;
36class QTextEdit;
37class QToolButton;
38
39class KComboBox;
40class KLineEdit;
41class KListView;
42
43/**
44 This widget displays a list box of the email addresses as well as buttons
45 to manipulate them (up, down, add, remove).
46*/
47class EmailEditWidget : public QWidget
48{
49 Q_OBJECT
50
51 public:
52 EmailEditWidget( QWidget *parent, const char *name = 0 );
53 ~EmailEditWidget();
54
55 void setEmails( const QStringList &list );
56 QStringList emails();
57
58 signals:
59 void modified();
60
61 private slots:
62 void edit();
63 void textChanged( const QString& );
64
65 private:
66 KLineEdit *mEmailEdit;
67 QStringList mEmailList;
68};
69
70class EmailEditDialog : public KDialogBase
71{
72 Q_OBJECT
73
74 public:
75 EmailEditDialog( const QStringList &list, QWidget *parent,
76 const char *name = 0 );
77 ~EmailEditDialog();
78
79 QStringList emails() const;
80 bool changed() const;
81
82 protected slots:
83 void add();
84 void remove();
85 void edit();
86 void standard();
87 void selectionChanged( int );
88 void emailChanged();
89
90 private:
91 KLineEdit *mEmailEdit;
92 QListBox *mEmailListBox;
93 QPushButton *mAddButton;
94 QPushButton *mRemoveButton;
95 QPushButton *mEditButton;
96 QPushButton *mStandardButton;
97
98 bool mChanged;
99};
100
101#endif
diff --git a/kaddressbook/extensionmanager.cpp b/kaddressbook/extensionmanager.cpp
new file mode 100644
index 0000000..9114cdc
--- a/dev/null
+++ b/kaddressbook/extensionmanager.cpp
@@ -0,0 +1,246 @@
1/*
2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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#include <qlayout.h>
24#include <qapplication.h>
25#include <kactionclasses.h>
26#include <kconfig.h>
27#include <kdebug.h>
28#include <klocale.h>
29
30#ifndef KAB_EMBEDDED
31#include <ktrader.h>
32#else //KAB_EMBEDDED
33#include <features/mergewidget.h>
34#include <features/distributionlistwidget.h>
35#endif //KAB_EMBEDDED
36
37#include "addresseeeditorwidget.h"
38#include "kabcore.h"
39#include "kabprefs.h"
40
41#include "extensionmanager.h"
42
43ExtensionManager::ExtensionManager( KABCore *core, QWidget *parent,
44 const char *name )
45 : QScrollView( parent, name ), mCore( core ), mCurrentExtensionWidget( 0 )
46{
47#ifdef KAB_EMBEDDED
48//US QPopupMenu *settingsmenu = (QPopupMenu*)mCore->getSettingsMenu();
49 QWidget *settingsmenu = (QWidget*)mCore->getSettingsMenu();
50#endif //KAB_EMBEDDED
51
52 mActionExtensions = new KSelectAction( i18n( "Show Extension Bar" ), 0,
53 mCore->actionCollection(),
54 "options_show_extensions" );
55
56 mActionExtensions->plug( settingsmenu );
57
58 connect( mActionExtensions, SIGNAL( activated( int ) ),
59 SLOT( setActiveExtension( int ) ) );
60 mWidgetBox = new QWidget( viewport() );
61 addChild( mWidgetBox );
62 setResizePolicy(AutoOneFit);
63 createExtensionWidgets();
64 hide();
65}
66
67ExtensionManager::~ExtensionManager()
68{
69}
70
71void ExtensionManager::restoreSettings()
72{
73 mActionExtensions->setCurrentItem( KABPrefs::instance()->mCurrentExtension );
74 int i = 1;
75 mCurrentExtensionWidget = mExtensionWidgetList.at( i-1 );
76 while ( mCurrentExtensionWidget ) {
77 if( i != KABPrefs::instance()->mCurrentExtension )
78 mCurrentExtensionWidget->hide();
79 mCurrentExtensionWidget = mExtensionWidgetList.at( ++i-1 );
80
81 }
82 setActiveExtension( mActionExtensions->currentItem() );
83}
84
85void ExtensionManager::saveSettings()
86{
87 KABPrefs::instance()->mCurrentExtension = mActionExtensions->currentItem();
88}
89
90void ExtensionManager::reconfigure()
91{
92 saveSettings();
93 createExtensionWidgets();
94 restoreSettings();
95}
96
97bool ExtensionManager::isQuickEditVisible() const
98{
99 return ( mCurrentExtensionWidget &&
100 mCurrentExtensionWidget->identifier() == "contact_editor" );
101}
102
103void ExtensionManager::setSelectionChanged()
104{
105 if ( mCurrentExtensionWidget )
106 mCurrentExtensionWidget->contactsSelectionChanged();
107}
108
109void ExtensionManager::setActiveExtension( int id )
110{
111 //qDebug("+++++++++++++++++++ExtensionManager::setActiveExtension %d ", id);
112 if ( id == 0 ) {
113 hide();
114 mCurrentExtensionWidget = 0;
115#ifndef DESKTOP_VERSION
116//US our screen is so small, that we better hide the detailscreen, just in case.
117 mCore->setDetailsToState( );
118#endif //KAB_EMBEDDED
119 } else if ( id > 0 ) {
120 if ( mCurrentExtensionWidget )
121 mCurrentExtensionWidget->hide();
122
123 mCurrentExtensionWidget = mExtensionWidgetList.at( id - 1 );
124
125 if ( mCurrentExtensionWidget ) {
126#ifndef DESKTOP_VERSION
127//US our screen is so small, that we better hide the detailscreen, just in case.
128 mCore->setDetailsVisible( false );
129#endif //KAB_EMBEDDED
130 show();
131 mWidgetBox->show();
132 mCurrentExtensionWidget->show();
133 } else {
134 hide();
135 mCurrentExtensionWidget = 0;
136#ifndef DESKTOP_VERSION
137//US our screen is so small, that we better hide the detailscreen, just in case.
138 mCore->setDetailsToState( );
139#endif //KAB_EMBEDDED
140 }
141 }
142}
143
144void ExtensionManager::createExtensionWidgets()
145{
146 // clear extension widget list
147 mExtensionWidgetList.setAutoDelete( true );
148 QPtrListIterator<ExtensionWidget> wdgIt( mExtensionWidgetList );
149 ExtensionWidget *wdg = 0;
150 while ( ( wdg = wdgIt.current() ) != 0 )
151 mExtensionWidgetList.remove( wdg );
152
153 mExtensionWidgetList.setAutoDelete( false );
154
155 QStringList extensionNames( i18n( "None" ) );
156
157 // add addressee editor as default
158
159 QHBoxLayout *hbl = new QHBoxLayout (mWidgetBox );
160
161 wdg = new AddresseeEditorWidget( mCore, true, mWidgetBox );
162 hbl->addWidget( wdg );
163 //wdg->hide();
164 connect( wdg, SIGNAL( modified( const KABC::Addressee::List& ) ),
165 SIGNAL( modified( const KABC::Addressee::List& ) ) );
166 mExtensionWidgetList.append( wdg );
167 extensionNames.append( wdg->title() );
168
169 // load the other extensions
170 QStringList activeExtensions = KABPrefs::instance()->mActiveExtensions;
171
172#ifndef KAB_EMBEDDED
173 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/Extension" );
174 KTrader::OfferList::ConstIterator it;
175 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
176 if ( !(*it)->hasServiceType( "KAddressBook/Extension" ) )
177 continue;
178
179 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
180 if ( !factory ) {
181 kdDebug(5720) << "ExtensionManager::loadExtensions(): Factory creation failed" << endl;
182 continue;
183 }
184
185 ExtensionFactory *extensionFactory = static_cast<ExtensionFactory*>( factory );
186
187 if ( !extensionFactory ) {
188 kdDebug(5720) << "ExtensionManager::loadExtensions(): Cast failed" << endl;
189 continue;
190 }
191
192 if ( !activeExtensions.contains( extensionFactory->identifier() ) )
193 continue;
194
195 wdg = extensionFactory->extension( mCore, this );
196 if ( wdg ) {
197 //wdg->hide();
198 connect( wdg, SIGNAL( modified( const KABC::Addressee::List& ) ),
199 SIGNAL( modified( const KABC::Addressee::List& ) ) );
200 mExtensionWidgetList.append( wdg );
201 extensionNames.append( wdg->title() );
202 }
203 }
204#else //KAB_EMBEDDED
205 //load Mergefactory/extension
206 ExtensionFactory *extensionFactory = new MergeFactory();
207 if ( activeExtensions.contains( extensionFactory->identifier() ) )
208 {
209 wdg = extensionFactory->extension( mCore, mWidgetBox );
210 if ( wdg ) {
211 hbl->addWidget( wdg );
212 //wdg->hide();
213 connect( wdg, SIGNAL( modified( const KABC::Addressee::List& ) ),
214 SIGNAL( modified( const KABC::Addressee::List& ) ) );
215 mExtensionWidgetList.append( wdg );
216 extensionNames.append( wdg->title() );
217 }
218 }
219
220 //load DistributionListfactory/extension
221 extensionFactory = new DistributionListFactory();
222 if (activeExtensions.contains( extensionFactory->identifier() ) )
223 {
224 wdg = extensionFactory->extension( mCore, mWidgetBox );
225 if ( wdg ) {
226 hbl->addWidget( wdg );
227 //wdg->hide();
228 connect( wdg, SIGNAL( modified( const KABC::Addressee::List& ) ),
229 SIGNAL( modified( const KABC::Addressee::List& ) ) );
230 mExtensionWidgetList.append( wdg );
231 extensionNames.append( wdg->title() );
232 }
233 }
234
235 hbl->addStretch();
236
237#endif //KAB_EMBEDDED
238
239
240 mActionExtensions->setItems( extensionNames );
241 mCurrentExtensionWidget = 0;
242}
243
244#ifndef KAB_EMBEDDED
245#include "extensionmanager.moc"
246#endif //KAB_EMBEDDED
diff --git a/kaddressbook/extensionmanager.h b/kaddressbook/extensionmanager.h
new file mode 100644
index 0000000..8f64a50
--- a/dev/null
+++ b/kaddressbook/extensionmanager.h
@@ -0,0 +1,88 @@
1/*
2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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#ifndef EXTENSIONMANAGER_H
25#define EXTENSIONMANAGER_H
26
27#include <qhbox.h>
28#include <qscrollview.h>
29#include <qptrlist.h>
30
31#include <extensionwidget.h>
32
33class KABCore;
34class KSelectAction;
35
36
37class ExtensionManager : public QScrollView
38{
39 Q_OBJECT
40
41 public:
42 ExtensionManager( KABCore *core, QWidget *parent, const char *name = 0 );
43 ~ExtensionManager();
44
45 /**
46 Restores the extension manager specific settings.
47 */
48 void restoreSettings();
49
50 /**
51 Saves the extension manager specific settings.
52 */
53 void saveSettings();
54
55 /**
56 Rereads the extension manager specific settings with some
57 additional initialization stuff.
58 */
59 void reconfigure();
60
61 /**
62 Returns whether the quickedit extension is currently visible.
63 */
64 bool isQuickEditVisible() const;
65
66 public slots:
67 void setSelectionChanged();
68
69 signals:
70 void modified( const KABC::Addressee::List& );
71
72 private slots:
73 void setActiveExtension( int id );
74
75 private:
76 void createExtensionWidgets();
77
78 KABCore *mCore;
79 QWidget *mWidgetBox;
80
81 ExtensionWidget *mCurrentExtensionWidget;
82 QPtrList<ExtensionWidget> mExtensionWidgetList;
83
84 KSelectAction *mActionExtensions;
85
86};
87
88#endif
diff --git a/kaddressbook/extensionwidget.cpp b/kaddressbook/extensionwidget.cpp
new file mode 100644
index 0000000..69f4aa8
--- a/dev/null
+++ b/kaddressbook/extensionwidget.cpp
@@ -0,0 +1,84 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Tobias Koenig <tokoe@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 "configurewidget.h"
25#include "kabcore.h"
26
27#include "extensionwidget.h"
28
29ExtensionWidget::ExtensionWidget( KABCore *core, QWidget *parent,
30 const char *name )
31 : QWidget( parent, name ), mCore( core )
32{
33}
34
35ExtensionWidget::~ExtensionWidget()
36{
37}
38
39KABCore *ExtensionWidget::core() const
40{
41 return mCore;
42}
43
44bool ExtensionWidget::contactsSelected() const
45{
46 return mCore->selectedUIDs().count() != 0;
47}
48
49KABC::Addressee::List ExtensionWidget::selectedContacts()
50{
51 KABC::Addressee::List list;
52
53 QStringList uids = mCore->selectedUIDs();
54 QStringList::Iterator it;
55 for ( it = uids.begin(); it != uids.end(); ++it )
56 list.append( mCore->addressBook()->findByUid( *it ) );
57
58 return list;
59}
60
61void ExtensionWidget::contactsSelectionChanged()
62{
63 // do nothing
64}
65
66QString ExtensionWidget::title() const
67{
68 return "<bug!!!>";
69}
70
71QString ExtensionWidget::identifier() const
72{
73 return "<bug!!!>";
74}
75
76ConfigureWidget *ExtensionFactory::configureWidget( QWidget*, const char* )
77{
78 return 0;
79}
80
81#ifndef KAB_EMBEDDED
82#include "extensionwidget.moc"
83#endif //KAB_EMBEDDED
84
diff --git a/kaddressbook/extensionwidget.h b/kaddressbook/extensionwidget.h
new file mode 100644
index 0000000..fc91f21
--- a/dev/null
+++ b/kaddressbook/extensionwidget.h
@@ -0,0 +1,119 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Tobias Koenig <tokoe@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#ifndef EXTENSIONWIDGET_H
25#define EXTENSIONWIDGET_H
26
27#include <qwidget.h>
28
29#include <kabc/addressbook.h>
30#ifndef KAB_EMBEDDED
31#include <klibloader.h>
32#endif //KAB_EMBEDDED
33
34class ConfigureWidget;
35class KABCore;
36
37class ExtensionWidget : public QWidget
38{
39 Q_OBJECT
40
41 public:
42 ExtensionWidget( KABCore *core, QWidget *parent, const char *name = 0 );
43 ~ExtensionWidget();
44
45 /**
46 @return A pointer to the core object
47 */
48 KABCore *core() const;
49
50 /**
51 Returns whether there are selected contacts in the view.
52 */
53 bool contactsSelected() const;
54
55 /**
56 Returns a list of contacts that are selected in the view.
57 Use @ref addresseesSelected() to test if there exists selected
58 contacts.
59 */
60 KABC::Addressee::List selectedContacts();
61
62 /**
63 This method is called whenever the selection in the view changed.
64 */
65 virtual void contactsSelectionChanged();
66
67 /**
68 This method should be reimplemented and return the i18ned title of this
69 widget.
70 */
71 virtual QString title() const;
72
73 /**
74 This method should be reimplemented and return a unique identifier.
75 */
76 virtual QString identifier() const;
77
78 signals:
79 void modified( const KABC::Addressee::List &list );
80
81 private:
82 KABCore *mCore;
83
84 class ExtensionWidgetPrivate;
85 ExtensionWidgetPrivate *d;
86};
87
88#ifndef KAB_EMBEDDED
89//MOC_SKIP_BEGIN
90class ExtensionFactory : public KLibFactory
91//MOC_SKIP_END
92#else //KAB_EMBEDDED
93class ExtensionFactory
94#endif //KAB_EMBEDDED
95{
96 public:
97 virtual ExtensionWidget *extension( KABCore *core, QWidget *parent,
98 const char *name = 0 ) = 0;
99
100 virtual ConfigureWidget *configureWidget( QWidget *parent,
101 const char *name = 0 );
102
103 virtual bool configureWidgetAvailable() { return false; }
104
105 /**
106 This method should return the same identifier like the config
107 widget.
108 */
109 virtual QString identifier() const = 0;
110
111 protected:
112 virtual QObject* createObject( QObject*, const char*, const char*,
113 const QStringList & )
114 {
115 return 0;
116 }
117};
118
119#endif
diff --git a/kaddressbook/features/distributionlistwidget.cpp b/kaddressbook/features/distributionlistwidget.cpp
new file mode 100644
index 0000000..bfcb121
--- a/dev/null
+++ b/kaddressbook/features/distributionlistwidget.cpp
@@ -0,0 +1,501 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Tobias Koenig <tokoe@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 <qbuttongroup.h>
25#include <qcombobox.h>
26#include <qlabel.h>
27#include <qlayout.h>
28#include <qlistview.h>
29#include <qpushbutton.h>
30#include <qradiobutton.h>
31
32#ifndef KAB_EMBEDDED
33#include <kaccelmanager.h>
34#endif //KAB_EMBEDDED
35
36
37#include <kdebug.h>
38#include <klineeditdlg.h>
39#include <klocale.h>
40#include <kglobal.h>
41#include <kmessagebox.h>
42
43#include <kabc/addressbook.h>
44#include <kabc/addresseedialog.h>
45#include <kabc/distributionlist.h>
46#include <kabc/vcardconverter.h>
47
48#ifndef KAB_EMBEDDED
49#include <libkdepim/kvcarddrag.h>
50#endif //KAB_EMBEDDED
51
52#include "kabcore.h"
53
54#include "distributionlistwidget.h"
55
56#ifndef KAB_EMBEDDED
57
58class DistributionListFactory : public ExtensionFactory
59{
60 public:
61 ExtensionWidget *extension( KABCore *core, QWidget *parent, const char *name )
62 {
63 return new DistributionListWidget( core, parent, name );
64 }
65
66 QString identifier() const
67 {
68 return "distribution_list_editor";
69 }
70};
71
72extern "C" {
73 void *init_libkaddrbk_distributionlist()
74 {
75 return ( new DistributionListFactory );
76 }
77}
78#endif //KAB_EMBEDDED
79
80class ContactItem : public QListViewItem
81{
82 public:
83 ContactItem( DistributionListView *parent, const KABC::Addressee &addressee,
84 const QString &email = QString::null ) :
85 QListViewItem( parent ),
86 mAddressee( addressee ),
87 mEmail( email )
88 {
89 setText( 0, addressee.realName() );
90 if( email.isEmpty() ) {
91 setText( 1, addressee.preferredEmail() );
92 setText( 2, i18n( "Yes" ) );
93 } else {
94 setText( 1, email );
95 setText( 2, i18n( "No" ) );
96 }
97 }
98
99 KABC::Addressee addressee() const
100 {
101 return mAddressee;
102 }
103
104 QString email() const
105 {
106 return mEmail;
107 }
108
109 protected:
110 bool acceptDrop( const QMimeSource* )
111 {
112 return true;
113 }
114
115 private:
116 KABC::Addressee mAddressee;
117 QString mEmail;
118};
119
120DistributionListWidget::DistributionListWidget( KABCore *core, QWidget *parent,
121 const char *name )
122 : ExtensionWidget( core, parent, name ), mManager( 0 )
123{
124 QGridLayout *topLayout = new QGridLayout( this, 3, 4, KDialog::marginHint(),
125 KDialog::spacingHint() );
126
127 if (KGlobal::getOrientation() == KGlobal::Portrait)
128 {
129 mCreateListButton = new QPushButton( i18n( "New List" ), this );
130 mEditListButton = new QPushButton( i18n( "Ren List" ), this );
131 mRemoveListButton = new QPushButton( i18n( "Del List" ), this );
132 mAddContactButton = new QPushButton( i18n( "Add Cont." ), this );
133 mChangeEmailButton = new QPushButton( i18n( "Chge Email" ), this );
134 mRemoveContactButton = new QPushButton( i18n( "Del Cont." ), this );
135 }
136 else
137 {
138 mCreateListButton = new QPushButton( i18n( "New List..." ), this );
139 mEditListButton = new QPushButton( i18n( "Rename List..." ), this );
140 mRemoveListButton = new QPushButton( i18n( "Remove List" ), this );
141 mAddContactButton = new QPushButton( i18n( "Add Contact" ), this );
142 mChangeEmailButton = new QPushButton( i18n( "Change Email..." ), this );
143 mRemoveContactButton = new QPushButton( i18n( "Remove Contact" ), this );
144 }
145 mNameCombo = new QComboBox( this );
146 topLayout->addWidget( mNameCombo, 0, 0 );
147 connect( mNameCombo, SIGNAL( activated( int ) ), SLOT( updateContactView() ) );
148
149 topLayout->addWidget( mCreateListButton, 0, 1 );
150 connect( mCreateListButton, SIGNAL( clicked() ), SLOT( createList() ) );
151
152 topLayout->addWidget( mEditListButton, 0, 2 );
153 connect( mEditListButton, SIGNAL( clicked() ), SLOT( editList() ) );
154
155 topLayout->addWidget( mRemoveListButton, 0, 3 );
156 connect( mRemoveListButton, SIGNAL( clicked() ), SLOT( removeList() ) );
157
158 mContactView = new DistributionListView( this );
159 mContactView->addColumn( i18n( "Name" ) );
160 mContactView->addColumn( i18n( "Email" ) );
161 mContactView->addColumn( i18n( "Use Preferred" ) );
162 mContactView->setEnabled( false );
163 mContactView->setAllColumnsShowFocus( true );
164 mContactView->setMinimumHeight( 30 );
165
166 topLayout->addMultiCellWidget( mContactView, 1, 1, 0, 3 );
167 connect( mContactView, SIGNAL( selectionChanged() ),
168 SLOT( selectionContactViewChanged() ) );
169 connect( mContactView, SIGNAL( dropped( QDropEvent*, QListViewItem* ) ),
170 SLOT( dropped( QDropEvent*, QListViewItem* ) ) );
171
172 mAddContactButton->setEnabled( false );
173 topLayout->addWidget( mAddContactButton, 2, 0 );
174 connect( mAddContactButton, SIGNAL( clicked() ), SLOT( addContact() ) );
175
176 topLayout->addWidget( mChangeEmailButton, 2, 2 );
177 connect( mChangeEmailButton, SIGNAL( clicked() ), SLOT( changeEmail() ) );
178
179 topLayout->addWidget( mRemoveContactButton, 2, 3 );
180 connect( mRemoveContactButton, SIGNAL( clicked() ), SLOT( removeContact() ) );
181
182 mManager = new KABC::DistributionListManager( core->addressBook() );
183 mManager->load();
184
185 updateNameCombo();
186
187#ifdef KAB_EMBEDDED
188// if (KGlobal::getOrientation() == KGlobal::Portrait)
189// parent->setMaximumSize( KGlobal::getDesktopWidth() , 150);
190#endif //KAB_EMBEDDED
191
192#ifndef KAB_EMBEDDED
193 KAcceleratorManager::manage( this );
194#endif //KAB_EMBEDDED
195}
196
197DistributionListWidget::~DistributionListWidget()
198{
199 delete mManager;
200}
201
202void DistributionListWidget::save()
203{
204qDebug("DistributionListWidget::save");
205 mManager->save();
206}
207
208void DistributionListWidget::selectionContactViewChanged()
209{
210 ContactItem *contactItem =
211 static_cast<ContactItem *>( mContactView->selectedItem() );
212 bool state = contactItem;
213
214 mChangeEmailButton->setEnabled( state );
215 mRemoveContactButton->setEnabled( state );
216}
217
218void DistributionListWidget::createList()
219{
220 KLineEditDlg dlg( i18n( "Please enter name:" ), QString::null, this );
221#ifdef KAB_EMBEDDED
222 dlg.setFixedSize(200, 50);
223#endif //KAB_EMBEDDED
224 dlg.setCaption( i18n( "New Distribution List" ) );
225 if ( !dlg.exec() )
226 return;
227
228 new KABC::DistributionList( mManager, dlg.text() );
229
230 mNameCombo->clear();
231 mNameCombo->insertStringList( mManager->listNames() );
232 mNameCombo->setCurrentItem( mNameCombo->count() - 1 );
233
234 updateContactView();
235
236 changed();
237}
238
239void DistributionListWidget::editList()
240{
241 QString oldName = mNameCombo->currentText();
242
243 KLineEditDlg dlg( i18n( "Please change name:" ), oldName, this );
244#ifdef KAB_EMBEDDED
245 dlg.setFixedSize(200, 50);
246#endif //KAB_EMBEDDED
247 dlg.setCaption( i18n("Distribution List") );
248 if ( !dlg.exec() )
249 return;
250
251 KABC::DistributionList *list = mManager->list( oldName );
252 list->setName( dlg.text() );
253
254 mNameCombo->clear();
255 mNameCombo->insertStringList( mManager->listNames() );
256 mNameCombo->setCurrentItem( mNameCombo->count() - 1 );
257
258 updateContactView();
259
260 changed();
261}
262
263void DistributionListWidget::removeList()
264{
265 int result = KMessageBox::warningContinueCancel( this,
266 i18n( "<qt>Delete distribution list <b>%1</b>?</qt>" ) .arg( mNameCombo->currentText() ),
267 QString::null, i18n( "Delete" ) );
268
269 if ( result != KMessageBox::Continue )
270 return;
271
272 delete mManager->list( mNameCombo->currentText() );
273 mNameCombo->removeItem( mNameCombo->currentItem() );
274
275 updateContactView();
276
277 changed();
278}
279
280void DistributionListWidget::addContact()
281{
282 KABC::DistributionList *list = mManager->list( mNameCombo->currentText() );
283 if ( !list )
284 return;
285
286 KABC::Addressee::List addrList = selectedContacts();
287 KABC::Addressee::List::Iterator it;
288 for ( it = addrList.begin(); it != addrList.end(); ++it )
289 list->insertEntry( *it );
290
291 updateContactView();
292
293 changed();
294}
295
296void DistributionListWidget::removeContact()
297{
298 KABC::DistributionList *list = mManager->list( mNameCombo->currentText() );
299 if ( !list )
300 return;
301
302 ContactItem *contactItem =
303 static_cast<ContactItem *>( mContactView->selectedItem() );
304 if ( !contactItem )
305 return;
306
307 list->removeEntry( contactItem->addressee(), contactItem->email() );
308 delete contactItem;
309
310 changed();
311}
312
313void DistributionListWidget::changeEmail()
314{
315 KABC::DistributionList *list = mManager->list( mNameCombo->currentText() );
316 if ( !list )
317 return;
318
319 ContactItem *contactItem =
320 static_cast<ContactItem *>( mContactView->selectedItem() );
321 if ( !contactItem )
322 return;
323
324 QString email = EmailSelector::getEmail( contactItem->addressee().emails(),
325 contactItem->email(), this );
326 list->removeEntry( contactItem->addressee(), contactItem->email() );
327 list->insertEntry( contactItem->addressee(), email );
328
329 updateContactView();
330
331 changed();
332}
333
334void DistributionListWidget::updateContactView()
335{
336 mContactView->clear();
337
338 KABC::DistributionList *list = mManager->list( mNameCombo->currentText() );
339 if ( !list ) {
340 mEditListButton->setEnabled( false );
341 mRemoveListButton->setEnabled( false );
342 mChangeEmailButton->setEnabled( false );
343 mRemoveContactButton->setEnabled( false );
344 mContactView->setEnabled( false );
345 return;
346 } else {
347 mEditListButton->setEnabled( true );
348 mRemoveListButton->setEnabled( true );
349 mContactView->setEnabled( true );
350 }
351
352 KABC::DistributionList::Entry::List entries = list->entries();
353 KABC::DistributionList::Entry::List::ConstIterator it;
354 for( it = entries.begin(); it != entries.end(); ++it )
355 new ContactItem( mContactView, (*it).addressee, (*it).email );
356
357 ContactItem *contactItem =
358 static_cast<ContactItem *>( mContactView->selectedItem() );
359 bool state = contactItem;
360
361 mChangeEmailButton->setEnabled( state );
362 mRemoveContactButton->setEnabled( state );
363}
364
365void DistributionListWidget::updateNameCombo()
366{
367 mNameCombo->insertStringList( mManager->listNames() );
368
369 updateContactView();
370}
371
372void DistributionListWidget::dropEvent( QDropEvent *e )
373{
374 KABC::DistributionList *distributionList = mManager->list( mNameCombo->currentText() );
375 if ( !distributionList )
376 return;
377
378 QString vcards;
379#ifndef KAB_EMBEDDED
380 if ( KVCardDrag::decode( e, vcards ) ) {
381#endif //KAB_EMBEDDED
382 QStringList list = QStringList::split( "\r\n\r\n", vcards );
383 QStringList::Iterator it;
384 KABC::VCardConverter converter;
385 for ( it = list.begin(); it != list.end(); ++it ) {
386 KABC::Addressee addr;
387 if ( converter.vCardToAddressee( (*it).stripWhiteSpace(), addr ) )
388 distributionList->insertEntry( addr );
389 }
390
391 changed();
392 updateContactView();
393#ifndef KAB_EMBEDDED
394 }
395#endif //KAB_EMBEDDED
396}
397
398void DistributionListWidget::contactsSelectionChanged()
399{
400 mAddContactButton->setEnabled( contactsSelected() && mNameCombo->count() > 0 );
401}
402
403QString DistributionListWidget::title() const
404{
405 return i18n( "Distribution List Editor" );
406}
407
408QString DistributionListWidget::identifier() const
409{
410 return "distribution_list_editor";
411}
412
413void DistributionListWidget::dropped( QDropEvent *e, QListViewItem* )
414{
415 dropEvent( e );
416}
417
418void DistributionListWidget::changed()
419{
420 save();
421}
422
423
424DistributionListView::DistributionListView( QWidget *parent, const char* name )
425 : KListView( parent, name )
426{
427 setDragEnabled( true );
428 setAcceptDrops( true );
429 setAllColumnsShowFocus( true );
430}
431
432void DistributionListView::dragEnterEvent( QDragEnterEvent* e )
433{
434#ifndef KAB_EMBEDDED
435 bool canDecode = QTextDrag::canDecode( e );
436 e->accept( canDecode );
437#endif //KAB_EMBEDDED
438}
439
440void DistributionListView::viewportDragMoveEvent( QDragMoveEvent *e )
441{
442#ifndef KAB_EMBEDDED
443 bool canDecode = QTextDrag::canDecode( e );
444 e->accept( canDecode );
445#endif //KAB_EMBEDDED
446}
447
448void DistributionListView::viewportDropEvent( QDropEvent *e )
449{
450 emit dropped( e, 0 );
451}
452
453void DistributionListView::dropEvent( QDropEvent *e )
454{
455 emit dropped( e, 0 );
456}
457
458
459EmailSelector::EmailSelector( const QStringList &emails,
460 const QString &current, QWidget *parent )
461 : KDialogBase( KDialogBase::Plain, i18n("Select Email Address"), Ok, Ok,
462 parent )
463{
464 QFrame *topFrame = plainPage();
465 QBoxLayout *topLayout = new QVBoxLayout( topFrame );
466
467 mButtonGroup = new QButtonGroup( 1, Horizontal, i18n("Email Addresses"),
468 topFrame );
469 topLayout->addWidget( mButtonGroup );
470
471 QStringList::ConstIterator it;
472 for( it = emails.begin(); it != emails.end(); ++it ) {
473 QRadioButton *button = new QRadioButton( *it, mButtonGroup );
474 if ( (*it) == current ) {
475 button->setDown( true );
476 }
477 }
478}
479
480QString EmailSelector::selected()
481{
482 QButton *button = mButtonGroup->selected();
483 if ( button )
484 return button->text();
485
486 return QString::null;
487}
488
489QString EmailSelector::getEmail( const QStringList &emails,
490 const QString &current, QWidget *parent )
491{
492 EmailSelector dlg( emails, current, parent );
493 dlg.exec();
494
495 return dlg.selected();
496}
497
498
499#ifndef KAB_EMBEDDED
500#include "distributionlistwidget.moc"
501#endif //KAB_EMBEDDED
diff --git a/kaddressbook/features/distributionlistwidget.h b/kaddressbook/features/distributionlistwidget.h
new file mode 100644
index 0000000..82bac3d
--- a/dev/null
+++ b/kaddressbook/features/distributionlistwidget.h
@@ -0,0 +1,143 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Tobias Koenig <tokoe@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#ifndef DISTRIBUTIONLISTWIDGET_H
25#define DISTRIBUTIONLISTWIDGET_H
26
27#include <kdialogbase.h>
28#include <klistview.h>
29
30#include "extensionwidget.h"
31
32class QButtonGroup;
33class QComboBox;
34class QLabel;
35class QListView;
36
37class DistributionListView;
38class KABCore;
39
40namespace KABC {
41class AddressBook;
42class DistributionListManager;
43}
44
45class DistributionListWidget : public ExtensionWidget
46{
47 Q_OBJECT
48
49 public:
50 DistributionListWidget( KABCore*, QWidget *parent, const char *name = 0 );
51 virtual ~DistributionListWidget();
52
53 void contactsSelectionChanged();
54
55 QString title() const;
56 QString identifier() const;
57
58 public slots:
59 void save();
60 void dropped( QDropEvent*, QListViewItem* );
61
62 private slots:
63 void createList();
64 void editList();
65 void removeList();
66 void addContact();
67 void removeContact();
68 void changeEmail();
69 void updateNameCombo();
70 void updateContactView();
71 void selectionContactViewChanged();
72 void changed();
73
74 protected:
75 void dropEvent( QDropEvent* );
76
77 private:
78 QComboBox *mNameCombo;
79 QLabel *mListLabel;
80 DistributionListView *mContactView;
81
82 KABC::DistributionListManager *mManager;
83 QPushButton *mCreateListButton;
84 QPushButton *mEditListButton;
85 QPushButton *mRemoveListButton;
86 QPushButton *mChangeEmailButton;
87 QPushButton *mAddContactButton;
88 QPushButton *mRemoveContactButton;
89};
90
91/**
92 @short Helper class
93*/
94class DistributionListView : public KListView
95{
96 Q_OBJECT
97
98 public:
99 DistributionListView( QWidget *parent, const char* name = 0 );
100
101 protected:
102 void dragEnterEvent( QDragEnterEvent *e );
103 void dropEvent( QDropEvent *e );
104 void viewportDragMoveEvent( QDragMoveEvent *e );
105 void viewportDropEvent( QDropEvent *e );
106};
107
108/**
109 @short Helper class
110*/
111class EmailSelector : public KDialogBase
112{
113 public:
114 EmailSelector( const QStringList &emails, const QString &current,
115 QWidget *parent );
116
117 QString selected();
118
119 static QString getEmail( const QStringList &emails, const QString &current,
120 QWidget *parent );
121
122 private:
123 QButtonGroup *mButtonGroup;
124};
125
126
127#ifdef KAB_EMBEDDED
128class DistributionListFactory : public ExtensionFactory
129{
130 public:
131 ExtensionWidget *extension( KABCore *core, QWidget *parent, const char *name )
132 {
133 return new DistributionListWidget( core, parent, name );
134 }
135
136 QString identifier() const
137 {
138 return "distribution_list_editor";
139 }
140};
141#endif //KAB_EMBEDDED
142
143#endif
diff --git a/kaddressbook/features/mergewidget.cpp b/kaddressbook/features/mergewidget.cpp
new file mode 100644
index 0000000..2476e42
--- a/dev/null
+++ b/kaddressbook/features/mergewidget.cpp
@@ -0,0 +1,374 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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 <qlayout.h>
25#include <qpushbutton.h>
26
27#ifndef KAB_EMBEDDED
28#include <kaccelmanager.h>
29#endif //KAB_EMBEDDED
30
31#include <kdebug.h>
32#include <klistview.h>
33#include <klocale.h>
34#include <kglobal.h>
35#include <kmessagebox.h>
36
37#include <kabc/addressbook.h>
38
39#include "kabcore.h"
40
41#include "mergewidget.h"
42
43#ifndef KAB_EMBEDDED
44class MergeFactory : public ExtensionFactory
45{
46 public:
47 ExtensionWidget *extension( KABCore *core, QWidget *parent, const char *name )
48 {
49 return new MergeWidget( core, parent, name );
50 }
51
52 QString identifier() const
53 {
54 return "merge";
55 }
56};
57
58extern "C" {
59 void *init_libkaddrbk_merge()
60 {
61 return ( new MergeFactory );
62 }
63}
64#endif //KAB_EMBEDDED
65
66class ContactItem : public QListViewItem
67{
68 public:
69 ContactItem( KListView *parent, const KABC::Addressee &addressee )
70 : QListViewItem( parent ), mAddressee( addressee )
71 {
72 KABC::Field::List fieldList = KABC::Field::defaultFields();
73 KABC::Field::List::ConstIterator it;
74
75 int i = 0;
76 for ( it = fieldList.begin(); it != fieldList.end(); ++it )
77 setText( i++, (*it)->value( mAddressee ) );
78 }
79
80 KABC::Addressee addressee() const
81 {
82 return mAddressee;
83 }
84
85 private:
86 KABC::Addressee mAddressee;
87};
88
89MergeWidget::MergeWidget( KABCore *core, QWidget *parent, const char *name )
90 : ExtensionWidget( core, parent, name ), mBlockUpdate( false )
91{
92#ifdef KAB_EMBEDDED
93 if (KGlobal::getOrientation() == KGlobal::Portrait)
94 parent->setMaximumSize( KGlobal::getDesktopWidth() , 180);
95#endif //KAB_EMBEDDED
96
97 QGridLayout *topLayout = new QGridLayout( this, 3, 2, KDialog::marginHint(),
98 KDialog::spacingHint() );
99
100 mContactView = new KListView( this );
101 KABC::Field::List fieldList = KABC::Field::defaultFields();
102 KABC::Field::List::ConstIterator it;
103
104 for ( it = fieldList.begin(); it != fieldList.end(); ++it )
105 mContactView->addColumn( (*it)->label() );
106
107 mContactView->setEnabled( false );
108 mContactView->setAllColumnsShowFocus( true );
109 topLayout->addMultiCellWidget( mContactView, 0, 2, 0, 0 );
110
111 connect( mContactView, SIGNAL( selectionChanged() ),
112 SLOT( selectionContactViewChanged() ) );
113
114 mMergeAndRemoveButton = new QPushButton( i18n( "Merge and Remove" ), this );
115 mMergeAndRemoveButton->setEnabled( false );
116 topLayout->addWidget( mMergeAndRemoveButton, 0, 1 );
117 connect( mMergeAndRemoveButton, SIGNAL( clicked() ), SLOT( mergeAndRemove() ) );
118
119 mMergeButton = new QPushButton( i18n( "Merge" ), this );
120 mMergeButton->setEnabled( false );
121 topLayout->addWidget( mMergeButton, 1, 1 );
122 connect( mMergeButton, SIGNAL( clicked() ), SLOT( merge() ) );
123
124#ifndef KAB_EMBEDDED
125 KAcceleratorManager::manage( this );
126#endif //KAB_EMBEDDED
127}
128
129MergeWidget::~MergeWidget()
130{
131}
132
133void MergeWidget::selectionContactViewChanged()
134{
135#ifndef KAB_EMBEDDED
136 ContactItem *contactItem =
137 dynamic_cast<ContactItem*>( mContactView->selectedItem() );
138#else //KAB_EMBEDDED
139 ContactItem *contactItem =(ContactItem*)( mContactView->selectedItem() );
140#endif //KAB_EMBEDDED
141
142 bool state = (contactItem != 0);
143
144 mMergeAndRemoveButton->setEnabled( state );
145 mMergeButton->setEnabled( state );
146}
147
148void MergeWidget::contactsSelectionChanged()
149{
150 if ( mBlockUpdate )
151 return;
152
153 if ( !contactsSelected() ) {
154 mContactView->setEnabled( false );
155 mContactView->clear();
156 mMergeAndRemoveButton->setEnabled( false );
157 mMergeButton->setEnabled( false );
158 } else {
159 KABC::Addressee::List list = selectedContacts();
160 if ( list.count() > 1 ) {
161 mContactView->setEnabled( false );
162 mContactView->clear();
163 mMergeAndRemoveButton->setEnabled( false );
164 mMergeButton->setEnabled( false );
165 return;
166 } else {
167 mContactView->setEnabled( true );
168 mMasterAddressee = list[ 0 ];
169 updateView();
170 }
171 }
172}
173
174void MergeWidget::updateView()
175{
176 mContactView->clear();
177
178 KABC::AddressBook::Iterator it;
179 KABC::AddressBook *ab = core()->addressBook();
180 if ( !ab )
181 return;
182
183 for ( it = ab->begin(); it != ab->end(); ++it )
184 if ( (*it).uid() != mMasterAddressee.uid() )
185 new ContactItem( mContactView, *it );
186}
187
188QString MergeWidget::title() const
189{
190 return i18n( "Merge Contacts Editor" );
191}
192
193QString MergeWidget::identifier() const
194{
195 return "merge";
196}
197
198void MergeWidget::mergeAndRemove()
199{
200#ifndef KAB_EMBEDDED
201 ContactItem *item = dynamic_cast<ContactItem*>( mContactView->currentItem() );
202#else //KAB_EMBEDDED
203 ContactItem *item = (ContactItem*)( mContactView->currentItem() );
204#endif //KAB_EMBEDDED
205 if ( !item )
206 return;
207
208 QString oldUID = item->addressee().uid();
209
210 doMerge( item->addressee() );
211
212 KABC::Addressee::List retval;
213 retval << mMasterAddressee;
214 emit modified( retval );
215
216 mBlockUpdate = true;
217 core()->deleteContacts( oldUID );
218 core()->setContactSelected( mMasterAddressee.uid() );
219 mBlockUpdate = false;
220
221 updateView();
222}
223
224void MergeWidget::merge()
225{
226#ifndef KAB_EMBEDDED
227 ContactItem *item = dynamic_cast<ContactItem*>( mContactView->currentItem() );
228#else //KAB_EMBEDDED
229 ContactItem *item = (ContactItem*)( mContactView->currentItem() );
230#endif //KAB_EMBEDDED
231 if ( !item )
232 return;
233
234 doMerge( item->addressee() );
235
236 KABC::Addressee::List retval;
237 retval << mMasterAddressee;
238 emit modified( retval );
239
240 mBlockUpdate = true;
241 core()->setContactSelected( mMasterAddressee.uid() );
242 mBlockUpdate = false;
243
244 updateView();
245}
246
247void MergeWidget::doMerge( const KABC::Addressee &addr )
248{
249 // ADR + LABEL
250 KABC::Address::List addresses = addr.addresses();
251 KABC::Address::List masterAddresses = mMasterAddressee.addresses();
252 KABC::Address::List::Iterator addrIt ;
253 for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) {
254 if ( !masterAddresses.contains( *addrIt ) )
255 mMasterAddressee.insertAddress( *addrIt );
256 }
257
258 if ( mMasterAddressee.birthday().isNull() && !addr.birthday().isNull() )
259 mMasterAddressee.setBirthday( addr.birthday() );
260
261
262 // CATEGORIES
263 QStringList::Iterator it;
264 QStringList categories = addr.categories();
265 QStringList masterCategories = mMasterAddressee.categories();
266 QStringList newCategories( masterCategories );
267 for ( it = categories.begin(); it != categories.end(); ++it )
268 if ( !masterCategories.contains( *it ) )
269 newCategories.append( *it );
270 mMasterAddressee.setCategories( newCategories );
271
272 // CLASS
273 if ( !mMasterAddressee.secrecy().isValid() && addr.secrecy().isValid() )
274 mMasterAddressee.setSecrecy( addr.secrecy() );
275
276 // EMAIL
277 QStringList emails = addr.emails();
278 QStringList masterEmails = mMasterAddressee.emails();
279 for ( it = emails.begin(); it != emails.end(); ++it )
280 if ( !masterEmails.contains( *it ) )
281 mMasterAddressee.insertEmail( *it, false );
282
283 // FN
284 if ( mMasterAddressee.formattedName().isEmpty() && !addr.formattedName().isEmpty() )
285 mMasterAddressee.setFormattedName( addr.formattedName() );
286
287 // GEO
288 if ( !mMasterAddressee.geo().isValid() && addr.geo().isValid() )
289 mMasterAddressee.setGeo( addr.geo() );
290
291/*
292 // KEY
293 // LOGO
294*/
295
296 // MAILER
297 if ( mMasterAddressee.mailer().isEmpty() && !addr.mailer().isEmpty() )
298 mMasterAddressee.setMailer( addr.mailer() );
299
300 // N
301 if ( mMasterAddressee.assembledName().isEmpty() && !addr.assembledName().isEmpty() )
302 mMasterAddressee.setNameFromString( addr.assembledName() );
303
304 // NICKNAME
305 if ( mMasterAddressee.nickName().isEmpty() && !addr.nickName().isEmpty() )
306 mMasterAddressee.setNickName( addr.nickName() );
307
308 // NOTE
309 if ( mMasterAddressee.note().isEmpty() && !addr.note().isEmpty() )
310 mMasterAddressee.setNote( addr.note() );
311
312 // ORG
313 if ( mMasterAddressee.organization().isEmpty() && !addr.organization().isEmpty() )
314 mMasterAddressee.setOrganization( addr.organization() );
315
316/*
317 // PHOTO
318*/
319
320 // PROID
321 if ( mMasterAddressee.productId().isEmpty() && !addr.productId().isEmpty() )
322 mMasterAddressee.setProductId( addr.productId() );
323
324 // REV
325 if ( mMasterAddressee.revision().isNull() && !addr.revision().isNull() )
326 mMasterAddressee.setRevision( addr.revision() );
327
328 // ROLE
329 if ( mMasterAddressee.role().isEmpty() && !addr.role().isEmpty() )
330 mMasterAddressee.setRole( addr.role() );
331
332 // SORT-STRING
333 if ( mMasterAddressee.sortString().isEmpty() && !addr.sortString().isEmpty() )
334 mMasterAddressee.setSortString( addr.sortString() );
335
336/*
337 // SOUND
338*/
339
340 // TEL
341 KABC::PhoneNumber::List phones = addr.phoneNumbers();
342 KABC::PhoneNumber::List masterPhones = mMasterAddressee.phoneNumbers();
343 KABC::PhoneNumber::List::ConstIterator phoneIt;
344 for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt )
345 if ( !masterPhones.contains( *it ) )
346 mMasterAddressee.insertPhoneNumber( *it );
347
348 // TITLE
349 if ( mMasterAddressee.title().isEmpty() && !addr.title().isEmpty() )
350 mMasterAddressee.setTitle( addr.title() );
351
352 // TZ
353 if ( !mMasterAddressee.timeZone().isValid() && addr.timeZone().isValid() )
354 mMasterAddressee.setTimeZone( addr.timeZone() );
355
356 // UID // ignore UID
357
358 // URL
359 if ( mMasterAddressee.url().isEmpty() && !addr.url().isEmpty() )
360 mMasterAddressee.setUrl( addr.url() );
361
362 // X-
363 QStringList customs = addr.customs();
364 QStringList masterCustoms = mMasterAddressee.customs();
365 QStringList newCustoms( masterCustoms );
366 for ( it = customs.begin(); it != customs.end(); ++it )
367 if ( !masterCustoms.contains( *it ) )
368 newCustoms.append( *it );
369 mMasterAddressee.setCustoms( newCustoms );
370}
371
372#ifndef KAB_EMBEDDED
373#include "mergewidget.moc"
374#endif //KAB_EMBEDDED
diff --git a/kaddressbook/features/mergewidget.h b/kaddressbook/features/mergewidget.h
new file mode 100644
index 0000000..1063c80
--- a/dev/null
+++ b/kaddressbook/features/mergewidget.h
@@ -0,0 +1,87 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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#ifndef MERGEWIDGET_H
25#define MERGEWIDGET_H
26
27#include <kdialogbase.h>
28#include <klistview.h>
29
30#include "extensionwidget.h"
31
32class QListView;
33
34class KABCore;
35
36namespace KABC {
37class AddressBook;
38}
39
40class MergeWidget : public ExtensionWidget
41{
42 Q_OBJECT
43
44 public:
45 MergeWidget( KABCore*, QWidget *parent, const char *name = 0 );
46 virtual ~MergeWidget();
47
48 void contactsSelectionChanged();
49
50 QString title() const;
51 QString identifier() const;
52
53 private slots:
54 void mergeAndRemove();
55 void merge();
56
57 void selectionContactViewChanged();
58
59 private:
60 void updateView();
61 void doMerge( const KABC::Addressee &addr );
62
63 KListView *mContactView;
64 QPushButton *mMergeAndRemoveButton;
65 QPushButton *mMergeButton;
66
67 KABC::Addressee mMasterAddressee;
68 bool mBlockUpdate;
69};
70
71#ifdef KAB_EMBEDDED
72class MergeFactory : public ExtensionFactory
73{
74 public:
75 ExtensionWidget *extension( KABCore *core, QWidget *parent, const char *name )
76 {
77 return new MergeWidget( core, parent, name );
78 }
79
80 QString identifier() const
81 {
82 return "merge";
83 }
84};
85#endif //KAB_EMBEDDED
86
87#endif
diff --git a/kaddressbook/filter.cpp b/kaddressbook/filter.cpp
new file mode 100644
index 0000000..b0d04ca
--- a/dev/null
+++ b/kaddressbook/filter.cpp
@@ -0,0 +1,205 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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 <kconfig.h>
25#include <kconfigbase.h>
26#include <kdebug.h>
27
28#include "kabprefs.h"
29
30#include "filter.h"
31
32Filter::Filter()
33 : mName( QString::null ), mMatchRule( Matching ), mEnabled( true ),
34 mInternal( false )
35{
36}
37
38Filter::Filter( const QString &name )
39 : mName( name ), mMatchRule( Matching ), mEnabled( true ),
40 mInternal( false )
41{
42}
43
44Filter::~Filter()
45{
46}
47
48void Filter::setName( const QString &name )
49{
50 mName = name;
51}
52
53const QString &Filter::name() const
54{
55 return mName;
56}
57
58bool Filter::isInternal() const
59{
60 return mInternal;
61}
62
63void Filter::apply( KABC::Addressee::List &addresseeList )
64{
65 KABC::Addressee::List::Iterator iter;
66 for ( iter = addresseeList.begin(); iter != addresseeList.end(); ) {
67 if ( filterAddressee( *iter ) )
68 ++iter;
69 else
70 {
71#ifndef KAB_EMBEDDED
72 iter = addresseeList.erase( iter );
73#else //KAB_EMBEDDED
74 iter = addresseeList.remove( iter );
75#endif //KAB_EMBEDDED
76 }
77 }
78}
79
80bool Filter::filterAddressee( const KABC::Addressee &a )
81{
82 QStringList::Iterator iter;
83 iter = mCategoryList.begin();
84 // empty filter always matches
85
86 if ( iter == mCategoryList.end() )
87 return true;
88
89 for ( ; iter != mCategoryList.end(); ++iter ) {
90 if ( a.hasCategory( *iter ) )
91 return ( mMatchRule == Matching );
92 }
93
94 return !( mMatchRule == Matching );
95}
96
97void Filter::setEnabled( bool on )
98{
99 mEnabled = on;
100}
101
102bool Filter::isEnabled() const
103{
104 return mEnabled;
105}
106
107void Filter::setCategories( const QStringList &list )
108{
109 mCategoryList = list;
110}
111
112const QStringList &Filter::categories() const
113{
114 return mCategoryList;
115}
116
117void Filter::save( KConfig *config )
118{
119 config->writeEntry( "Name", mName );
120 config->writeEntry( "Enabled", mEnabled );
121 config->writeEntry( "Categories", mCategoryList );
122 config->writeEntry( "MatchRule", (int)mMatchRule );
123}
124
125void Filter::restore( KConfig *config )
126{
127 mName = config->readEntry( "Name", "<internal error>" );
128 mEnabled = config->readBoolEntry( "Enabled", true );
129 mCategoryList = config->readListEntry( "Categories" );
130 mMatchRule = (MatchRule)config->readNumEntry( "MatchRule", Matching );
131}
132
133void Filter::save( KConfig *config, QString baseGroup, Filter::List &list )
134{
135 {
136 KConfigGroupSaver s( config, baseGroup );
137
138 // remove the old filters
139 uint count = config->readNumEntry( "Count" );
140 /* // memory access violation here
141 for ( uint i = 0; i < count; ++i )
142 config->deleteGroup( QString( "%1_%2" ).arg( baseGroup ).arg( i ) );
143 */
144 }
145
146 int index = 0;
147 Filter::List::Iterator iter;
148 for ( iter = list.begin(); iter != list.end(); ++iter ) {
149 if ( !(*iter).mInternal ) {
150 KConfigGroupSaver s( config, QString( "%1_%2" ).arg( baseGroup ).arg( index ) );
151
152 (*iter).save( config );
153 index++;
154 }
155 }
156
157 KConfigGroupSaver s( config, baseGroup );
158
159 config->writeEntry( "Count", index );
160
161}
162
163Filter::List Filter::restore( KConfig *config, QString baseGroup )
164{
165 Filter::List list;
166 int count = 0;
167 Filter f;
168
169 {
170 KConfigGroupSaver s( config, baseGroup );
171 count = config->readNumEntry( "Count", 0 );
172 }
173
174 for ( int i = 0; i < count; i++ ) {
175 {
176 KConfigGroupSaver s( config, QString( "%1_%2" ).arg( baseGroup ).arg( i ) );
177 f.restore( config );
178 }
179
180 list.append( f );
181 }
182
183 QStringList cats = KABPrefs::instance()->mCustomCategories;
184 for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) {
185 Filter filter;
186 filter.mName = *it;
187 filter.mEnabled = true;
188 filter.mCategoryList = *it;
189 filter.mMatchRule = Matching;
190 filter.mInternal = true;
191 list.append( filter );
192 }
193
194 return list;
195}
196
197void Filter::setMatchRule( MatchRule rule )
198{
199 mMatchRule = rule;
200}
201
202Filter::MatchRule Filter::matchRule() const
203{
204 return mMatchRule;
205}
diff --git a/kaddressbook/filter.h b/kaddressbook/filter.h
new file mode 100644
index 0000000..cf2c0a1
--- a/dev/null
+++ b/kaddressbook/filter.h
@@ -0,0 +1,153 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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#ifndef FILTER_H
25#define FILTER_H
26
27#include <qstring.h>
28#include <qstringlist.h>
29#include <qvaluelist.h>
30
31#include <kabc/addressee.h>
32#include <kconfig.h>
33
34/**
35 Filter for AddressBook related objects (Addressees)
36
37 @todo This class should be switched to use shared data.
38 */
39class Filter
40{
41 public:
42 typedef QValueList<Filter> List;
43
44 enum MatchRule { Matching = 0, NotMatching = 1 };
45
46 Filter();
47 Filter( const QString& name );
48 ~Filter();
49
50 /**
51 Set the name of the filter.
52 */
53 void setName( const QString &name );
54
55 /**
56 @return The name of the filter.
57 */
58 const QString &name() const;
59
60 /**
61 @return Whether the filter is an internal one.
62 */
63 bool isInternal() const;
64
65 /**
66 Apply the filter to the addressee list. All addressees not passing
67 the filter criterias will be removed from the list.
68
69 If the MatchRule is NotMatch, then all the addressees matching the
70 filter will be removed from the list.
71 */
72 void apply( KABC::Addressee::List &addresseeList );
73
74 /**
75 Apply the filter to the addressee.
76
77 @return True if the addressee passes the criteria, false otherwise.
78 The return values are opposite if the MatchRule is NotMatch.
79 */
80 bool filterAddressee( const KABC::Addressee &a );
81
82 /**
83 Enable or disable the filter
84 */
85 void setEnabled( bool on );
86
87 /**
88 @return True if this filter is enabled, false otherwise.
89 */
90 bool isEnabled() const;
91
92 /**
93 Set the list of categories. This list is used to filter addressees.
94 */
95 void setCategories( const QStringList &list );
96
97 /**
98 @return The list of categories.
99 */
100 const QStringList &categories() const;
101
102 /**
103 Saves the filter to the config file. The group should already be set.
104 */
105 void save( KConfig *config );
106
107 /**
108 Loads the filter from the config file. The group should already be set.
109 */
110 void restore( KConfig *config );
111
112 /**
113 Saves a list of filters to the config file.
114
115 @param config The config file to use
116 @param baseGroup The base groupname to use. The number of filters
117 will be written to this group, then a _1, _2, etc
118 will be append for each filter saved.
119 @param list The list of filters to be saved.
120 */
121 static void save( KConfig *config, QString baseGroup, Filter::List &list );
122
123 /**
124 Restores a list of filters from a config file.
125
126 @param config The config file to read from.
127 @param baseGroup The base group name to be used to find the filters
128
129 @return The list of filters.
130 */
131 static Filter::List restore( KConfig *config, QString baseGroup );
132
133 /**
134 Sets the filter rule. If the rule is Filter::Matching (default),
135 then the filter will return true on items that match the filter.
136 If the rule is Filter::NotMatching, then the filter will return
137 true on items that do not match the filter.
138 */
139 void setMatchRule( MatchRule rule );
140
141 /** @return The current match rule.
142 */
143 MatchRule matchRule() const;
144
145 private:
146 QString mName;
147 QStringList mCategoryList;
148 MatchRule mMatchRule;
149 bool mEnabled;
150 bool mInternal;
151};
152
153#endif
diff --git a/kaddressbook/filtereditdialog.cpp b/kaddressbook/filtereditdialog.cpp
new file mode 100644
index 0000000..063585a
--- a/dev/null
+++ b/kaddressbook/filtereditdialog.cpp
@@ -0,0 +1,302 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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/*
25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk
27
28$Id$
29*/
30
31#include <qbuttongroup.h>
32#include <qhbox.h>
33#include <qlabel.h>
34#include <qlayout.h>
35#include <qpushbutton.h>
36#include <qradiobutton.h>
37#include <qregexp.h>
38#include <qstring.h>
39#include <qtoolbutton.h>
40#include <qtooltip.h>
41#include <qwidget.h>
42
43#include <kapplication.h>
44#include <kbuttonbox.h>
45#include <kdebug.h>
46#include <kiconloader.h>
47#include <klineedit.h>
48#include <klistbox.h>
49#include <klistview.h>
50#include <klocale.h>
51#include <kglobal.h>
52
53#include "kabprefs.h"
54#include "filtereditdialog.h"
55
56FilterEditDialog::FilterEditDialog( QWidget *parent, const char *name )
57 : KDialogBase( Plain, i18n( "Edit Address Book Filter" ),
58 Help | Ok | Cancel, Ok, parent, name, /*US false*/ true, true )
59{
60 initGUI();
61
62 QStringList cats = KABPrefs::instance()->mCustomCategories;
63
64 QStringList::Iterator iter;
65 for ( iter = cats.begin(); iter != cats.end(); ++iter )
66 mCategoriesView->insertItem( new QCheckListItem( mCategoriesView, (*iter), QCheckListItem::CheckBox ) );
67 filterNameTextChanged( mNameEdit->text() );
68}
69
70FilterEditDialog::~FilterEditDialog()
71{
72}
73
74void FilterEditDialog::setFilter( const Filter &filter )
75{
76 mNameEdit->setText( filter.name() );
77
78 QStringList categories = filter.categories();
79 QListViewItem *item = mCategoriesView->firstChild();
80 while ( item != 0 ) {
81 if ( categories.contains( item->text( 0 ) ) ) {
82 QCheckListItem *checkItem = static_cast<QCheckListItem*>( item );
83 checkItem->setOn( true );
84 }
85
86 item = item->nextSibling();
87 }
88
89 if ( filter.matchRule() == Filter::Matching )
90 mMatchRuleGroup->setButton( 0 );
91 else
92 mMatchRuleGroup->setButton( 1 );
93}
94
95Filter FilterEditDialog::filter()
96{
97 Filter filter;
98
99 filter.setName( mNameEdit->text() );
100
101 QStringList categories;
102 QListViewItem *item = mCategoriesView->firstChild();
103 while ( item != 0 ) {
104 QCheckListItem *checkItem = static_cast<QCheckListItem*>( item );
105 if ( checkItem->isOn() )
106 categories.append( item->text( 0 ) );
107
108 item = item->nextSibling();
109 }
110 filter.setCategories( categories );
111
112 if ( mMatchRuleGroup->find( 0 )->isOn() )
113 filter.setMatchRule( Filter::Matching );
114 else
115 filter.setMatchRule( Filter::NotMatching );
116
117 return filter;
118}
119
120void FilterEditDialog::initGUI()
121{
122#ifndef KAB_EMBEDDED
123 resize( 490, 300 );
124#else //KAB_EMBEDDED
125 resize( KMIN(KGlobal::getDesktopWidth()-10, 490), KMIN(KGlobal::getDesktopHeight()-50, 300));
126#endif //KAB_EMBEDDED
127
128
129 QWidget *page = plainPage();
130 QLabel *label;
131
132 QGridLayout *topLayout = new QGridLayout( page, 3, 2, 0, spacingHint() );
133
134 label = new QLabel( i18n( "Name" ), page );
135 mNameEdit = new KLineEdit( page );
136 mNameEdit->setFocus();
137 topLayout->addWidget( label, 0, 0 );
138 topLayout->addWidget( mNameEdit, 0, 1 );
139 connect( mNameEdit, SIGNAL( textChanged( const QString& ) ),
140 SLOT( filterNameTextChanged( const QString&) ) );
141
142 mCategoriesView = new KListView( page );
143 mCategoriesView->addColumn( i18n( "Categories" ) );
144 topLayout->addMultiCellWidget( mCategoriesView, 1, 1, 0, 1 );
145
146 mMatchRuleGroup = new QButtonGroup( page );
147 mMatchRuleGroup->setExclusive( true );
148
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 );
155 mMatchRuleGroup->insert( radio );
156 gbLayout->addWidget( radio );
157
158 radio = new QRadioButton( i18n( "Show all contacts except those\n matching the selected categories" ), mMatchRuleGroup );
159 mMatchRuleGroup->insert( radio );
160 gbLayout->addWidget( radio );
161
162 topLayout->addMultiCellWidget( mMatchRuleGroup, 2, 2, 0, 1 );
163}
164
165void FilterEditDialog::filterNameTextChanged( const QString &text )
166{
167 enableButtonOK( !text.isEmpty() );
168}
169
170void FilterEditDialog::slotHelp()
171{
172#ifndef KAB_EMBEDDED
173 kapp->invokeHelp( "using-filters" );
174#endif //KAB_EMBEDDED
175}
176
177FilterDialog::FilterDialog( QWidget *parent, const char *name )
178 : KDialogBase( Plain, i18n( "Edit Address Book Filters" ),
179 Ok | Cancel, Ok, parent, name, /*US false*/true, true )
180{
181 initGUI();
182}
183
184FilterDialog::~FilterDialog()
185{
186}
187
188void FilterDialog::setFilters( const Filter::List &list )
189{
190 mFilterList.clear();
191 mInternalFilterList.clear();
192
193 Filter::List::ConstIterator it;
194 for ( it = list.begin(); it != list.end(); ++it ) {
195 if ( (*it).isInternal() )
196 mInternalFilterList.append( *it );
197 else
198 mFilterList.append( *it );
199 }
200
201 refresh();
202}
203
204Filter::List FilterDialog::filters() const
205{
206 Filter::List list = mFilterList + mInternalFilterList;
207 return list;
208}
209
210void FilterDialog::add()
211{
212#ifndef KAB_EMBEDDED
213 FilterEditDialog dlg( this );
214#else //KAB_EMBEDDED
215 FilterEditDialog dlg( this->parentWidget() );
216#endif //KAB_EMBEDDED
217
218 if ( dlg.exec() )
219 mFilterList.append( dlg.filter() );
220
221 refresh();
222
223 mFilterListBox->setCurrentItem( mFilterListBox->count() - 1 );
224}
225
226void FilterDialog::edit()
227{
228 FilterEditDialog dlg( this );
229
230 uint pos = mFilterListBox->currentItem();
231
232 dlg.setFilter( mFilterList[ pos ] );
233
234 if ( dlg.exec() ) {
235 mFilterList.remove( mFilterList.at( pos ) );
236 mFilterList.insert( mFilterList.at( pos ), dlg.filter() );
237 }
238
239 refresh();
240
241 mFilterListBox->setCurrentItem( pos );
242}
243
244void FilterDialog::remove()
245{
246 mFilterList.remove( mFilterList.at( mFilterListBox->currentItem() ) );
247
248 selectionChanged( 0 );
249
250 refresh();
251}
252
253void FilterDialog::refresh()
254{
255 mFilterListBox->clear();
256
257 Filter::List::Iterator iter;
258 for ( iter = mFilterList.begin(); iter != mFilterList.end(); ++iter )
259 mFilterListBox->insertItem( (*iter).name() );
260}
261
262void FilterDialog::selectionChanged( QListBoxItem *item )
263{
264 bool state = ( item != 0 );
265
266 mEditButton->setEnabled( state );
267 mRemoveButton->setEnabled( state );
268}
269
270void FilterDialog::initGUI()
271{
272#ifndef KAB_EMBEDDED
273 resize( 330, 200 );
274#else //KAB_EMBEDDED
275 resize( KMIN(KGlobal::getDesktopWidth()-10, 330), KMIN(KGlobal::getDesktopHeight()-50, 200));
276#endif //KAB_EMBEDDED
277
278 QWidget *page = plainPage();
279
280 QGridLayout *topLayout = new QGridLayout( page, 1, 2, 0, spacingHint() );
281
282 mFilterListBox = new KListBox( page );
283 topLayout->addWidget( mFilterListBox, 0, 0 );
284 connect( mFilterListBox, SIGNAL( selectionChanged( QListBoxItem * ) ),
285 SLOT( selectionChanged( QListBoxItem * ) ) );
286 connect( mFilterListBox, SIGNAL( doubleClicked ( QListBoxItem * ) ),
287 SLOT( edit() ) );
288
289 KButtonBox *buttonBox = new KButtonBox( page, Vertical );
290 buttonBox->addButton( i18n( "&Add..." ), this, SLOT( add() ) );
291 mEditButton = buttonBox->addButton( i18n( "&Edit..." ), this, SLOT( edit() ) );
292 mEditButton->setEnabled( false );
293 mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), this, SLOT( remove() ) );
294 mRemoveButton->setEnabled( false );
295
296 buttonBox->layout();
297 topLayout->addWidget( buttonBox, 0, 1 );
298}
299
300#ifndef KAB_EMBEDDED
301#include "filtereditdialog.moc"
302#endif //KAB_EMBEDDED
diff --git a/kaddressbook/filtereditdialog.h b/kaddressbook/filtereditdialog.h
new file mode 100644
index 0000000..4dd75e4
--- a/dev/null
+++ b/kaddressbook/filtereditdialog.h
@@ -0,0 +1,104 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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/*
25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk
27
28$Id$
29*/
30
31#ifndef FILTEREDITDIALOG_H
32#define FILTEREDITDIALOG_H
33
34class QButtonGroup;
35class QString;
36class QToolButton;
37class QWidget;
38class QListBoxItem;
39
40class KLineEdit;
41class KListBox;
42class KListView;
43
44#include <kdialogbase.h>
45
46#include "filter.h"
47
48class FilterDialog : public KDialogBase
49{
50 Q_OBJECT
51
52 public:
53 FilterDialog( QWidget *parent, const char *name = 0 );
54 ~FilterDialog();
55
56 void setFilters( const Filter::List &list );
57 Filter::List filters() const;
58
59 protected slots:
60 void add();
61 void edit();
62 void remove();
63 void selectionChanged( QListBoxItem* );
64
65 private:
66 void initGUI();
67 void refresh();
68
69 Filter::List mFilterList;
70 Filter::List mInternalFilterList;
71
72 KListBox *mFilterListBox;
73 QPushButton *mAddButton;
74 QPushButton *mEditButton;
75 QPushButton *mRemoveButton;
76};
77
78class FilterEditDialog : public KDialogBase
79{
80 Q_OBJECT
81 public:
82 FilterEditDialog( QWidget *parent, const char *name = 0 );
83 ~FilterEditDialog();
84
85 void setFilter( const Filter &filter );
86 Filter filter();
87
88 protected slots:
89 void filterNameTextChanged( const QString& );
90 void slotHelp();
91
92 private:
93 void initGUI();
94
95 Filter mFilter;
96
97 KLineEdit *mNameEdit;
98 KListView *mCategoriesView;
99 QButtonGroup *mMatchRuleGroup;
100 QPushButton *mEditButton;
101 QPushButton *mRemoveButton;
102};
103
104#endif
diff --git a/kaddressbook/geowidget.cpp b/kaddressbook/geowidget.cpp
new file mode 100644
index 0000000..13cd084
--- a/dev/null
+++ b/kaddressbook/geowidget.cpp
@@ -0,0 +1,629 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Tobias Koenig <tokoe@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 <kabc/geo.h>
25
26#ifndef KAB_EMBEDDED
27#include <kaccelmanager.h>
28#else //KAB_EMBEDDED
29
30#include <qtextstream.h>
31#include <kglobal.h>
32#endif //KAB_EMBEDDED
33
34#include <knuminput.h>
35#include <kcombobox.h>
36#include <kdebug.h>
37#include <kiconloader.h>
38#include <klocale.h>
39#include <kstandarddirs.h>
40
41#include <qcheckbox.h>
42#include <qfile.h>
43#include <qapplication.h>
44#include <qgroupbox.h>
45#include <qlabel.h>
46#include <qlayout.h>
47#include <qlistbox.h>
48#include <qpainter.h>
49#include <qpixmap.h>
50#include <qpushbutton.h>
51#include <qregexp.h>
52#include <qstring.h>
53#include <stdlib.h>
54
55#include "geowidget.h"
56
57GeoWidget::GeoWidget( QWidget *parent, const char *name )
58 : QWidget( parent, name )
59{
60 QLabel *label = 0;
61
62 QGridLayout *topLayout = new QGridLayout( this, 4, 3 );
63 topLayout->setMargin( KDialog::marginHint() );
64 topLayout->setSpacing( KDialog::spacingHint() );
65
66 label = new QLabel( this );
67//US ambiguous call to loadIcon. Add an additional parameter
68//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "package_network", KIcon::Desktop ) );
69 label->setPixmap( KGlobal::iconLoader()->loadIcon( "package_network", KIcon::Desktop, 0 ) );
70 label->setAlignment( Qt::AlignTop );
71 topLayout->addMultiCellWidget( label, 0, 3, 0, 0 );
72 label->setAlignment( AlignCenter );
73 mGeoIsValid = new QCheckBox( i18n( "Use geo data" ), this );
74 topLayout->addMultiCellWidget( mGeoIsValid, 0, 0, 1, 2 );
75
76 label = new QLabel( i18n( "Latitude:" ), this );
77 topLayout->addWidget( label, 1, 1 );
78
79 mLatitudeBox = new KDoubleSpinBox( -90, 90, 1, 0, 6, this );
80 mLatitudeBox->setEnabled( false );
81 mLatitudeBox->setSuffix( "" );
82 topLayout->addWidget( mLatitudeBox, 1, 2 );
83 label->setBuddy( mLatitudeBox );
84
85 label = new QLabel( i18n( "Longitude:" ), this );
86 topLayout->addWidget( label, 2, 1 );
87
88 mLongitudeBox = new KDoubleSpinBox( -180, 180, 1, 0, 6, this );
89 mLongitudeBox->setEnabled( false );
90 mLongitudeBox->setSuffix( "" );
91 topLayout->addWidget( mLongitudeBox, 2, 2 );
92 label->setBuddy( mLongitudeBox );
93
94 mExtendedButton = new QPushButton( i18n( "Edit Geo Data..." ), this );
95 mExtendedButton->setEnabled( false );
96 topLayout->addMultiCellWidget( mExtendedButton, 3, 3, 1, 2 );
97
98 connect( mLatitudeBox, SIGNAL( valueChanged( double ) ),
99 SIGNAL( changed() ) );
100 connect( mLongitudeBox, SIGNAL( valueChanged( double ) ),
101 SIGNAL( changed() ) );
102 connect( mExtendedButton, SIGNAL( clicked() ),
103 SLOT( editGeoData() ) );
104
105 connect( mGeoIsValid, SIGNAL( toggled( bool ) ),
106 mLatitudeBox, SLOT( setEnabled( bool ) ) );
107 connect( mGeoIsValid, SIGNAL( toggled( bool ) ),
108 mLongitudeBox, SLOT( setEnabled( bool ) ) );
109 connect( mGeoIsValid, SIGNAL( toggled( bool ) ),
110 mExtendedButton, SLOT( setEnabled( bool ) ) );
111 connect( mGeoIsValid, SIGNAL( toggled( bool ) ),
112 SIGNAL( changed() ) );
113
114#ifndef KAB_EMBEDDED
115 KAcceleratorManager::manage( this );
116#endif //KAB_EMBEDDED
117}
118
119GeoWidget::~GeoWidget()
120{
121}
122
123void GeoWidget::setGeo( const KABC::Geo &geo )
124{
125 if ( geo.isValid() ) {
126 mGeoIsValid->setChecked( true );
127 mLatitudeBox->setValue( geo.latitude() );
128 mLongitudeBox->setValue( geo.longitude() );
129 } else
130 mGeoIsValid->setChecked( false );
131}
132
133KABC::Geo GeoWidget::geo() const
134{
135 KABC::Geo geo;
136
137 if ( mGeoIsValid->isChecked() ) {
138 geo.setLatitude( mLatitudeBox->value() );
139 geo.setLongitude( mLongitudeBox->value() );
140 } else {
141 geo.setLatitude( 91 );
142 geo.setLongitude( 181 );
143 }
144
145 return geo;
146}
147
148void GeoWidget::editGeoData()
149{
150 GeoDialog dlg( this );
151
152 dlg.setLatitude( mLatitudeBox->value() );
153 dlg.setLongitude( mLongitudeBox->value() );
154
155 if ( dlg.exec() ) {
156 mLatitudeBox->setValue( dlg.latitude() );
157 mLongitudeBox->setValue( dlg.longitude() );
158
159 emit changed();
160 }
161}
162
163
164
165GeoDialog::GeoDialog( QWidget *parent, const char *name )
166 : KDialogBase( Plain, i18n( "Geo Data Input" ), Ok | Cancel, Ok,
167 parent, name, true, true ),
168 mUpdateSexagesimalInput( true )
169{
170 QFrame *page = plainPage();
171
172 QGridLayout *topLayout = new QGridLayout( page, 1, 1, marginHintSmall(),
173 spacingHint() );
174 //topLayout->setRowStretch( 1, 1 );
175
176 mMapWidget = new GeoMapWidget( page );
177 mCityCombo = new KComboBox( page );
178 QGroupBox *sexagesimalGroup = new QGroupBox( 0, Vertical, i18n( "Sexagesimal" ), page );
179 QGridLayout *sexagesimalLayout = new QGridLayout( sexagesimalGroup->layout(),
180 2, 5, spacingHint() );
181 QLabel *label;
182 if ( QApplication::desktop()->width() < 320 ) {
183 label = new QLabel( i18n( "La." ), sexagesimalGroup );
184 sexagesimalLayout->setSpacing ( spacingHintSmall() );
185 sexagesimalLayout->setMargin ( marginHintSmall() );
186 topLayout->setMargin ( 0 );
187 mCityCombo->setMaximumWidth( 220 );
188 sexagesimalGroup->setMaximumWidth( 220 );
189 }
190 else
191 label = new QLabel( i18n( "Latitude:" ), sexagesimalGroup );
192 sexagesimalLayout->addWidget( label, 0, 0 );
193
194 int maxWid = 60;
195 if ( QApplication::desktop()->width() < 320 )
196 maxWid = 40;
197 mLatDegrees = new QSpinBox( 0, 90, 1, sexagesimalGroup );
198 mLatDegrees->setSuffix( "" );
199 mLatDegrees->setWrapping( false );
200 sexagesimalLayout->addWidget( mLatDegrees, 0, 1 );
201 mLatDegrees->setMaximumWidth( maxWid );
202
203 mLatMinutes = new QSpinBox( 0, 59, 1, sexagesimalGroup );
204 mLatMinutes->setSuffix( "'" );
205 sexagesimalLayout->addWidget( mLatMinutes, 0, 2 );
206 mLatMinutes->setMaximumWidth( maxWid );
207
208 mLatSeconds = new QSpinBox( 0, 59, 1, sexagesimalGroup );
209 mLatSeconds->setSuffix( "\"" );
210 sexagesimalLayout->addWidget( mLatSeconds, 0, 3 );
211 mLatSeconds->setMaximumWidth( maxWid );
212
213 mLatDirection = new KComboBox( sexagesimalGroup );
214 mLatDirection->insertItem( i18n( "North" ) );
215 mLatDirection->insertItem( i18n( "South" ) );
216 sexagesimalLayout->addWidget( mLatDirection, 0, 4 );
217
218
219 if ( QApplication::desktop()->width() < 320 )
220 label = new QLabel( i18n( "Lo." ), sexagesimalGroup );
221 else
222 label = new QLabel( i18n( "Longitude:" ), sexagesimalGroup );
223
224
225 sexagesimalLayout->addWidget( label, 1, 0 );
226
227 mLongDegrees = new QSpinBox( 0, 180, 1, sexagesimalGroup );
228 mLongDegrees->setSuffix( "" );
229 sexagesimalLayout->addWidget( mLongDegrees, 1, 1 );
230 mLongDegrees->setMaximumWidth( maxWid );
231
232 mLongMinutes = new QSpinBox( 0, 59, 1, sexagesimalGroup );
233 mLongMinutes->setSuffix( "'" );
234 sexagesimalLayout->addWidget( mLongMinutes, 1, 2 );
235 mLongMinutes->setMaximumWidth( maxWid );
236
237 mLongSeconds = new QSpinBox( 0, 59, 1, sexagesimalGroup );
238 mLongSeconds->setSuffix( "\"" );
239 sexagesimalLayout->addWidget( mLongSeconds, 1, 3 );
240 mLongSeconds->setMaximumWidth( maxWid );
241
242 mLongDirection = new KComboBox( sexagesimalGroup );
243 mLongDirection->insertItem( i18n( "East" ) );
244 mLongDirection->insertItem( i18n( "West" ) );
245 sexagesimalLayout->addWidget( mLongDirection, 1, 4 );
246 if ( true /*QApplication::desktop()->width() < 640*/ ) {
247
248 topLayout->addWidget( mMapWidget, 0, 0 );
249 topLayout->addWidget( mCityCombo, 1, 0 );
250 topLayout->addWidget( sexagesimalGroup, 2, 0 );
251
252 } else {
253 topLayout->addMultiCellWidget( mMapWidget, 0, 1, 0, 0 );
254 topLayout->addWidget( mCityCombo, 0, 1 );
255 topLayout->addWidget( sexagesimalGroup, 1, 1 );
256 }
257
258 loadCityList();
259
260 connect( mMapWidget, SIGNAL( changed() ),
261 SLOT( geoMapChanged() ) );
262 connect( mCityCombo, SIGNAL( activated( int ) ),
263 SLOT( cityInputChanged() ) );
264 connect( mLatDegrees, SIGNAL( valueChanged( int ) ),
265 SLOT( sexagesimalInputChanged() ) );
266 connect( mLatMinutes, SIGNAL( valueChanged( int ) ),
267 SLOT( sexagesimalInputChanged() ) );
268 connect( mLatSeconds, SIGNAL( valueChanged( int ) ),
269 SLOT( sexagesimalInputChanged() ) );
270 connect( mLatDirection, SIGNAL( activated( int ) ),
271 SLOT( sexagesimalInputChanged() ) );
272 connect( mLongDegrees, SIGNAL( valueChanged( int ) ),
273 SLOT( sexagesimalInputChanged() ) );
274 connect( mLongMinutes, SIGNAL( valueChanged( int ) ),
275 SLOT( sexagesimalInputChanged() ) );
276 connect( mLongSeconds, SIGNAL( valueChanged( int ) ),
277 SLOT( sexagesimalInputChanged() ) );
278 connect( mLongDirection, SIGNAL( activated( int ) ),
279 SLOT( sexagesimalInputChanged() ) );
280 mLongitude = 0.0;
281 mLatitude = 0.0;
282#ifndef DESKTOP_VERSION
283 showMaximized();
284#endif
285}
286
287GeoDialog::~GeoDialog()
288{
289}
290
291void GeoDialog::setLatitude( double latitude )
292{
293 mLatitude = latitude;
294 updateInputs();
295}
296
297double GeoDialog::latitude() const
298{
299 return mLatitude;
300}
301
302void GeoDialog::setLongitude( double longitude )
303{
304 mLongitude = longitude;
305 updateInputs();
306}
307
308double GeoDialog::longitude() const
309{
310 return mLongitude;
311}
312
313void GeoDialog::sexagesimalInputChanged()
314{
315 mLatitude = (double)( mLatDegrees->value() + (double)mLatMinutes->value() /
316 60 + (double)mLatSeconds->value() / 3600 );
317
318 mLatitude *= ( mLatDirection->currentItem() == 1 ? -1 : 1 );
319
320 mLongitude = (double)( mLongDegrees->value() + (double)mLongMinutes->value() /
321 60 + (double)mLongSeconds->value() / 3600 );
322
323 mLongitude *= ( mLongDirection->currentItem() == 1 ? -1 : 1 );
324
325 mUpdateSexagesimalInput = false;
326
327 updateInputs();
328}
329
330void GeoDialog::geoMapChanged()
331{
332 mLatitude = mMapWidget->latitude();
333 mLongitude = mMapWidget->longitude();
334
335 updateInputs();
336}
337
338void GeoDialog::cityInputChanged()
339{
340 if ( mCityCombo->currentItem() != 0 ) {
341 GeoData data = mGeoDataMap[ mCityCombo->currentText() ];
342 mLatitude = data.latitude;
343 mLongitude = data.longitude;
344 } else
345 mLatitude = mLongitude = 0;
346
347 updateInputs();
348}
349
350void GeoDialog::updateInputs()
351{
352 // hmm, doesn't look nice, but there is no better way AFAIK
353 mCityCombo->blockSignals( true );
354 mLatDegrees->blockSignals( true );
355 mLatMinutes->blockSignals( true );
356 mLatSeconds->blockSignals( true );
357 mLatDirection->blockSignals( true );
358 mLongDegrees->blockSignals( true );
359 mLongMinutes->blockSignals( true );
360 mLongSeconds->blockSignals( true );
361 mLongDirection->blockSignals( true );
362
363 mMapWidget->setLatitude( mLatitude );
364 mMapWidget->setLongitude( mLongitude );
365 mMapWidget->update();
366
367 if ( mUpdateSexagesimalInput ) {
368 int degrees, minutes, seconds;
369 double latitude = mLatitude;
370 double longitude = mLongitude;
371
372 latitude *= ( mLatitude < 0 ? -1 : 1 );
373 longitude *= ( mLongitude < 0 ? -1 : 1 );
374
375 degrees = (int)( latitude * 1 );
376 minutes = (int)( ( latitude - degrees ) * 60 );
377 seconds = (int)( (double)( (double)latitude - (double)degrees - ( (double)minutes / (double)60 ) ) * (double)3600 );
378
379 mLatDegrees->setValue( degrees );
380 mLatMinutes->setValue( minutes );
381 mLatSeconds->setValue( seconds );
382
383 mLatDirection->setCurrentItem( mLatitude < 0 ? 1 : 0 );
384
385 degrees = (int)( longitude * 1 );
386 minutes = (int)( ( longitude - degrees ) * 60 );
387 seconds = (int)( (double)( longitude - (double)degrees - ( (double)minutes / 60 ) ) * 3600 );
388
389 mLongDegrees->setValue( degrees );
390 mLongMinutes->setValue( minutes );
391 mLongSeconds->setValue( seconds );
392 mLongDirection->setCurrentItem( mLongitude < 0 ? 1 : 0 );
393 }
394 mUpdateSexagesimalInput = true;
395
396 int pos = nearestCity( mLongitude, mLatitude );
397 if ( pos != -1 )
398 mCityCombo->setCurrentItem( pos + 1 );
399 else
400 mCityCombo->setCurrentItem( 0 );
401
402 mCityCombo->blockSignals( false );
403 mLatDegrees->blockSignals( false );
404 mLatMinutes->blockSignals( false );
405 mLatSeconds->blockSignals( false );
406 mLatDirection->blockSignals( false );
407 mLongDegrees->blockSignals( false );
408 mLongMinutes->blockSignals( false );
409 mLongSeconds->blockSignals( false );
410 mLongDirection->blockSignals( false );
411}
412
413void GeoDialog::loadCityList()
414{
415 mCityCombo->clear();
416 mGeoDataMap.clear();
417
418 QString fileName ;
419#ifdef DESKTOP_VERSION
420#ifndef _WIN32_
421 fileName = qApp->applicationDirPath () + "/kdepim/kaddressbook/zone.tab";
422#else
423 fileName = qApp->applicationDirPath () + "\\kdepim\\kaddressbook\\zone.tab";
424#endif
425#else
426 fileName = getenv("QPEDIR");
427 fileName += "/pics/kdepim/kaddressbook/zone.tab";
428#endif
429
430 QFile file( fileName);
431
432 if ( file.open( IO_ReadOnly ) ) {
433 QTextStream s( &file );
434
435 QString line, country;
436 QRegExp coord( "[+-]\\d+[+-]\\d+" );
437 QRegExp name( "[^\\s]+/[^\\s]+" );
438 int posc, posn, pos;
439
440 while ( !s.eof() ) {
441 line = s.readLine().stripWhiteSpace();
442 if ( line.isEmpty() || line[ 0 ] == '#' )
443 continue;
444
445 country = line.left( 2 );
446 QString c, n;
447#ifdef DESKTOP_VERSION
448 posc = coord.search( line, 0 );
449#else
450 posc = coord.find( line, 0 );
451#endif
452 // if ( pos >= 0 )
453 //c = line.mid( pos, coord.matchedLength() );
454
455#ifdef DESKTOP_VERSION
456 posn = name.search(line, posc);
457#else
458 posn = name.find(line, posc);
459#endif
460 if ( posn > 0 ) {
461 c = line.mid( posc, posn-posc ).stripWhiteSpace();
462 //qDebug("*%s* ", c.latin1());
463 int nend = line.find(" ", posn );
464 if ( nend < 0 )
465 nend = line.length();
466 n = line.mid( posn, nend-posn).stripWhiteSpace();
467 //n.replace( '_', " " );
468 }
469
470 if ( !c.isEmpty() && !n.isEmpty() ) {
471 pos = c.find( "+", 1 );
472 if ( pos < 0 )
473 pos = c.find( "-", 1 );
474 if ( pos > 0 ) {
475 GeoData data;
476 data.latitude = calculateCoordinate( c.left( pos ) );
477 data.longitude = calculateCoordinate( c.mid( pos ) );
478 data.country = country;
479
480 mGeoDataMap.insert( n, data );
481 }
482 }
483 }
484//US I have no mGeoDataMap.keys().
485//US QStringList items( mGeoDataMap.keys() );
486 QStringList items;
487
488 QMap<QString, GeoData>::ConstIterator it;
489 for( it = mGeoDataMap.begin(); it != mGeoDataMap.end(); ++it )
490 items << it.key().latin1();
491
492 items.prepend( i18n( "Undefined" ) );
493 mCityCombo->insertStringList( items );
494
495 file.close();
496 }
497}
498
499double GeoDialog::calculateCoordinate( const QString &coordinate )
500{
501 int neg;
502 int d = 0, m = 0, s = 0;
503 QString str = coordinate;
504
505 neg = str.left( 1 ) == "-";
506 str.remove( 0, 1 );
507
508 switch ( str.length() ) {
509 case 4:
510 d = str.left( 2 ).toInt();
511 m = str.mid( 2 ).toInt();
512 break;
513 case 5:
514 d = str.left( 3 ).toInt();
515 m = str.mid( 3 ).toInt();
516 break;
517 case 6:
518 d = str.left( 2 ).toInt();
519 m = str.mid( 2, 2 ).toInt();
520 s = str.right( 2 ).toInt();
521 break;
522 case 7:
523 d = str.left( 3 ).toInt();
524 m = str.mid( 3, 2 ).toInt();
525 s = str.right( 2 ).toInt();
526 break;
527 default:
528 break;
529 }
530
531 if ( neg )
532 return - ( d + m / 60.0 + s / 3600.0 );
533 else
534 return d + m / 60.0 + s / 3600.0;
535}
536
537int GeoDialog::nearestCity( double x, double y )
538{
539 QMap<QString, GeoData>::Iterator it;
540 int pos = 0;
541 for ( it = mGeoDataMap.begin(); it != mGeoDataMap.end(); ++it, pos++ ) {
542 double dist = ( (*it).longitude - x ) * ( (*it).longitude - x ) +
543 ( (*it).latitude - y ) * ( (*it).latitude - y );
544 if ( dist < 1.5 )
545 return pos;
546 }
547
548 return -1;
549}
550
551
552GeoMapWidget::GeoMapWidget( QWidget *parent, const char *name )
553 : QWidget( parent, name ), mLatitude( 0 ), mLongitude( 0 )
554{
555 setBackgroundMode( NoBackground );
556
557 setFixedSize( 240, 120 );
558
559 update();
560}
561
562GeoMapWidget::~GeoMapWidget()
563{
564}
565
566void GeoMapWidget::setLatitude( double latitude )
567{
568 mLatitude = latitude;
569}
570
571double GeoMapWidget::latitude()const
572{
573 return mLatitude;
574}
575
576void GeoMapWidget::setLongitude( double longitude )
577{
578 mLongitude = longitude;
579}
580
581double GeoMapWidget::longitude()const
582{
583 return mLongitude;
584}
585
586void GeoMapWidget::mousePressEvent( QMouseEvent *event )
587{
588 double latMid = height() / 2;
589 double longMid = width() / 2;
590
591 double latOffset = latMid - event->y();
592 double longOffset = event->x() - longMid;
593
594 mLatitude = ( latOffset * 90 ) / latMid;
595 mLongitude = ( longOffset * 180 ) / longMid;
596
597 emit changed();
598}
599
600void GeoMapWidget::paintEvent( QPaintEvent* )
601{
602 uint w = width();
603 uint h = height();
604
605 QPixmap world = KGlobal::iconLoader()->loadIcon( "world", KIcon::Desktop, 0 );
606
607 QPainter p;
608 p.begin( &world, this );
609
610 p.setPen( QColor( 255, 0, 0 ) );
611 p.setBrush( QColor( 255, 0, 0 ) );
612
613 double latMid = h / 2;
614 double longMid = w / 2;
615
616 double latOffset = ( mLatitude * latMid ) / 90;
617 double longOffset = ( mLongitude * longMid ) / 180;
618
619 int x = (int)(longMid + longOffset);
620 int y = (int)(latMid - latOffset);
621 p.drawEllipse( x, y, 4, 4 );
622
623 p.end();
624 bitBlt( this, 0, 0, &world );
625}
626
627#ifndef KAB_EMBEDDED
628#include "geowidget.moc"
629#endif //KAB_EMBEDDED
diff --git a/kaddressbook/geowidget.h b/kaddressbook/geowidget.h
new file mode 100644
index 0000000..3d39691
--- a/dev/null
+++ b/kaddressbook/geowidget.h
@@ -0,0 +1,155 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Tobias Koenig <tokoe@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#ifndef GEOWIDGET_H
25#define GEOWIDGET_H
26
27#include <qmap.h>
28
29#include <qwidget.h>
30#include <kdialogbase.h>
31
32namespace KABC {
33class Geo;
34}
35
36class GeoMapWidget;
37
38class KComboBox;
39class KDoubleSpinBox;
40
41class QCheckBox;
42class QLabel;
43class QSpinBox;
44class QPushButton;
45
46typedef struct {
47 double latitude;
48 double longitude;
49 QString country;
50} GeoData;
51
52class GeoWidget : public QWidget
53{
54 Q_OBJECT
55
56 public:
57 GeoWidget( QWidget *parent, const char *name = 0 );
58 ~GeoWidget();
59
60 /**
61 Sets the geo object.
62 */
63 void setGeo( const KABC::Geo &geo );
64
65 /**
66 Returns a geo object.
67 */
68 KABC::Geo geo() const;
69
70 signals:
71 void changed();
72
73 private slots:
74 void editGeoData();
75
76 private:
77 KDoubleSpinBox *mLatitudeBox;
78 KDoubleSpinBox *mLongitudeBox;
79
80 QCheckBox *mGeoIsValid;
81 QPushButton *mExtendedButton;
82};
83
84class GeoDialog : public KDialogBase
85{
86 Q_OBJECT
87
88 public:
89 GeoDialog( QWidget *parent, const char *name = 0 );
90 ~GeoDialog();
91
92 void setLatitude( double latitude );
93 double latitude() const;
94
95 void setLongitude( double longitude );
96 double longitude() const;
97
98 private slots:
99 void updateInputs();
100
101 void sexagesimalInputChanged();
102 void geoMapChanged();
103 void cityInputChanged();
104
105 private:
106 void loadCityList();
107 double calculateCoordinate( const QString& );
108 int nearestCity( double, double );
109
110 GeoMapWidget *mMapWidget;
111 KComboBox *mCityCombo;
112
113 QSpinBox *mLatDegrees;
114 QSpinBox *mLatMinutes;
115 QSpinBox *mLatSeconds;
116 KComboBox *mLatDirection;
117
118 QSpinBox *mLongDegrees;
119 QSpinBox *mLongMinutes;
120 QSpinBox *mLongSeconds;
121 KComboBox *mLongDirection;
122
123 double mLatitude;
124 double mLongitude;
125 QMap<QString, GeoData> mGeoDataMap;
126 bool mUpdateSexagesimalInput;
127};
128
129class GeoMapWidget : public QWidget
130{
131 Q_OBJECT
132
133 public:
134 GeoMapWidget( QWidget *parent, const char *name = 0 );
135 ~GeoMapWidget();
136
137 void setLatitude( double latitude );
138 double latitude()const;
139
140 void setLongitude( double longitude );
141 double longitude()const;
142
143 signals:
144 void changed();
145
146 protected:
147 virtual void mousePressEvent( QMouseEvent* );
148 virtual void paintEvent( QPaintEvent* );
149
150 private:
151 double mLatitude;
152 double mLongitude;
153};
154
155#endif
diff --git a/kaddressbook/imagewidget.cpp b/kaddressbook/imagewidget.cpp
new file mode 100644
index 0000000..49d456b
--- a/dev/null
+++ b/kaddressbook/imagewidget.cpp
@@ -0,0 +1,299 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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 <kabc/picture.h>
25
26#ifndef KAB_EMBEDDED
27#include <kaccelmanager.h>
28#include <kio/netaccess.h>
29#include <kimageio.h>
30#endif //KAB_EMBEDDED
31
32#include <kdebug.h>
33#include <kdialog.h>
34#include <kiconloader.h>
35#include <klocale.h>
36#include <kurlrequester.h>
37#include <kurl.h>
38
39#include <qcheckbox.h>
40#include <qgroupbox.h>
41#include <qlabel.h>
42#include <qlayout.h>
43#include <qpixmap.h>
44#include <qapplication.h>
45
46#include "imagewidget.h"
47
48ImageWidget::ImageWidget( QWidget *parent, const char *name )
49 : QWidget( parent, name )
50{
51 QGridLayout *topLayout = new QGridLayout( this, 2, 1, KDialog::marginHint(),
52 KDialog::spacingHint() );
53
54 QGroupBox *photoBox = new QGroupBox( 0, Qt::Vertical, i18n( "Photo" ), this );
55 QGridLayout *boxLayout = new QGridLayout( photoBox->layout(), 3, 2,
56 KDialog::spacingHint() );
57 boxLayout->setRowStretch( 2, 1 );
58
59 mPhotoLabel = new QLabel( photoBox );
60 int fac = 9;
61 if ( QApplication::desktop()->width() > 320 )
62 fac = 6;
63 mPhotoLabel->setFixedSize( 50*9/fac, 70*9/fac );
64 mPhotoLabel->setScaledContents( true );
65 mPhotoLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken );
66 boxLayout->addMultiCellWidget( mPhotoLabel, 0, 2, 0, 0 );
67
68 mPhotoUrl = new KURLRequester( photoBox );
69#ifndef KAB_EMBEDDED
70 mPhotoUrl->setFilter( KImageIO::pattern() );
71#else //KAB_EMBEDDED
72//US qDebug("ImageWidget::ImageWidget KImageIO not defined. Does this harm ???");
73#endif //KAB_EMBEDDED
74
75
76 boxLayout->addWidget( mPhotoUrl, 0, 1 );
77
78 mUsePhotoUrl = new QCheckBox( i18n( "Store as URL" ), photoBox );
79 mUsePhotoUrl->setEnabled( false );
80 boxLayout->addWidget( mUsePhotoUrl, 1, 1 );
81
82 topLayout->addWidget( photoBox, 0, 0 );
83
84 QGroupBox *logoBox = new QGroupBox( 0, Qt::Vertical, i18n( "Logo" ), this );
85 boxLayout = new QGridLayout( logoBox->layout(), 3, 2, KDialog::spacingHint() );
86 boxLayout->setRowStretch( 2, 1 );
87
88 mLogoLabel = new QLabel( logoBox );
89 mLogoLabel->setFixedSize( 50*9/fac, 70*9/fac );
90 mLogoLabel->setScaledContents( true );
91 mLogoLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken );
92 boxLayout->addMultiCellWidget( mLogoLabel, 0, 2, 0, 0 );
93
94 mLogoUrl = new KURLRequester( logoBox );
95#ifndef KAB_EMBEDDED
96 mLogoUrl->setFilter( KImageIO::pattern() );
97#else //KAB_EMBEDDED
98//US qDebug("ImageWidget::ImageWidget KImageIO not defined 2");
99#endif //KAB_EMBEDDED
100 boxLayout->addWidget( mLogoUrl, 0, 1 );
101
102 mUseLogoUrl = new QCheckBox( i18n( "Store as URL" ), logoBox );
103 mUseLogoUrl->setEnabled( false );
104 boxLayout->addWidget( mUseLogoUrl, 1, 1 );
105
106 topLayout->addWidget( logoBox, 1, 0 );
107
108 connect( mPhotoUrl, SIGNAL( textChanged( const QString& ) ),
109 SIGNAL( changed() ) );
110 connect( mPhotoUrl, SIGNAL( urlSelected( const QString& ) ),
111 SLOT( loadPhoto() ) );
112 connect( mPhotoUrl, SIGNAL( urlSelected( const QString& ) ),
113 SIGNAL( changed() ) );
114 connect( mPhotoUrl, SIGNAL( urlSelected( const QString& ) ),
115 SLOT( updateGUI() ) );
116 connect( mUsePhotoUrl, SIGNAL( toggled( bool ) ),
117 SIGNAL( changed() ) );
118
119 connect( mLogoUrl, SIGNAL( textChanged( const QString& ) ),
120 SIGNAL( changed() ) );
121 connect( mLogoUrl, SIGNAL( urlSelected( const QString& ) ),
122 SLOT( loadLogo() ) );
123 connect( mLogoUrl, SIGNAL( urlSelected( const QString& ) ),
124 SIGNAL( changed() ) );
125 connect( mLogoUrl, SIGNAL( urlSelected( const QString& ) ),
126 SLOT( updateGUI() ) );
127 connect( mUseLogoUrl, SIGNAL( toggled( bool ) ),
128 SIGNAL( changed() ) );
129
130#ifndef KAB_EMBEDDED
131 KAcceleratorManager::manage( this );
132#endif //KAB_EMBEDDED
133
134#ifndef DESKTOP_VERSION
135 mUsePhotoUrl->setChecked( true );
136 mUseLogoUrl->setChecked( true );
137#endif
138}
139
140ImageWidget::~ImageWidget()
141{
142}
143
144void ImageWidget::setPhoto( const KABC::Picture &photo )
145{
146 bool blocked = signalsBlocked();
147 blockSignals( true );
148
149 if ( photo.isIntern() ) {
150//US
151//US mPhotoLabel->setPixmap( photo.data() );
152 if (photo.data().isNull() != true)
153 {
154 QPixmap pm;
155 pm.convertFromImage(photo.data());
156
157 mPhotoLabel->setPixmap( pm );
158 }
159
160 mUsePhotoUrl->setChecked( false );
161 } else {
162 mPhotoUrl->setURL( photo.url() );
163 if ( !photo.url().isEmpty() )
164 mUsePhotoUrl->setChecked( true );
165 loadPhoto();
166 }
167
168 blockSignals( blocked );
169}
170
171KABC::Picture ImageWidget::photo() const
172{
173 KABC::Picture photo;
174
175 if ( mUsePhotoUrl->isChecked() )
176 photo.setUrl( mPhotoUrl->url() );
177 else {
178 QPixmap *px = mPhotoLabel->pixmap();
179 if ( px ) {
180#ifndef KAB_EMBEDDED
181 if ( px->height() > px->width() )
182 photo.setData( px->convertToImage().scaleHeight( 140 ) );
183 else
184 photo.setData( px->convertToImage().scaleWidth( 100 ) );
185#else //KAB_EMBEDDED
186//US add teh nullcheck
187 if (px->isNull() != true )
188 photo.setData( px->convertToImage() );
189#endif //KAB_EMBEDDED
190
191 photo.setType( "PNG" );
192 }
193 }
194
195 return photo;
196}
197
198void ImageWidget::setLogo( const KABC::Picture &logo )
199{
200 bool blocked = signalsBlocked();
201 blockSignals( true );
202
203 if ( logo.isIntern() ) {
204//US
205//US mLogoLabel->setPixmap( logo.data() );
206 if (logo.data().isNull() != true)
207 {
208 QPixmap pm;
209 pm.convertFromImage(logo.data());
210 mLogoLabel->setPixmap( pm );
211 }
212 mUseLogoUrl->setChecked( false );
213 } else {
214 mLogoUrl->setURL( logo.url() );
215 if ( !logo.url().isEmpty() )
216 mUseLogoUrl->setChecked( true );
217 loadLogo();
218 }
219
220 blockSignals( blocked );
221}
222
223KABC::Picture ImageWidget::logo() const
224{
225 KABC::Picture logo;
226
227 if ( mUseLogoUrl->isChecked() )
228 logo.setUrl( mLogoUrl->url() );
229 else {
230 QPixmap *px = mLogoLabel->pixmap();
231 if ( px ) {
232#ifndef KAB_EMBEDDED
233 if ( px->height() > px->width() )
234 logo.setData( px->convertToImage().scaleHeight( 140 ) );
235 else
236 logo.setData( px->convertToImage().scaleWidth( 100 ) );
237#else //KAB_EMBEDDED
238 logo.setData( px->convertToImage() );
239#endif //KAB_EMBEDDED
240
241 logo.setType( "PNG" );
242
243 }
244 }
245
246 return logo;
247}
248
249void ImageWidget::loadPhoto()
250{
251 mPhotoLabel->setPixmap( loadPixmap( mPhotoUrl->url() ) );
252}
253
254void ImageWidget::loadLogo()
255{
256 mLogoLabel->setPixmap( loadPixmap( mLogoUrl->url() ) );
257}
258
259void ImageWidget::updateGUI()
260{
261 KURLRequester *ptr = (KURLRequester*)sender();
262
263#ifdef DESKTOP_VERSION
264 if ( ptr == mPhotoUrl )
265 mUsePhotoUrl->setEnabled( true );
266 else if ( ptr == mLogoUrl )
267 mUseLogoUrl->setEnabled( true );
268#endif
269}
270
271QPixmap ImageWidget::loadPixmap( const KURL &url )
272{
273 QString tempFile;
274 QPixmap pixmap;
275
276 if ( url.isEmpty() )
277 return pixmap;
278
279 if ( url.isLocalFile() )
280 pixmap = QPixmap( url.path() );
281 else
282 {
283#ifndef KAB_EMBEDDED
284 if ( KIO::NetAccess::download( url, tempFile ) ) {
285 pixmap = QPixmap( tempFile );
286 KIO::NetAccess::removeTempFile( tempFile );
287 }
288#else //KAB_EMBEDDED
289 qDebug("ImageWidget::loadPixmap : only local pixmaps are allowed");
290#endif //KAB_EMBEDDED
291
292 }
293
294 return pixmap;
295}
296
297#ifndef KAB_EMBEDDED
298#include "imagewidget.moc"
299#endif //KAB_EMBEDDED
diff --git a/kaddressbook/imagewidget.h b/kaddressbook/imagewidget.h
new file mode 100644
index 0000000..b3ca0bd
--- a/dev/null
+++ b/kaddressbook/imagewidget.h
@@ -0,0 +1,86 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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#ifndef IMAGEWIDGET_H
25#define IMAGEWIDGET_H
26
27#include <qwidget.h>
28
29#include <kabc/picture.h>
30#include <kdialogbase.h>
31
32class KURL;
33class KURLRequester;
34
35class QCheckBox;
36class QLabel;
37
38class ImageWidget : public QWidget
39{
40 Q_OBJECT
41
42 public:
43 ImageWidget( QWidget *parent, const char *name = 0 );
44 ~ImageWidget();
45
46 /**
47 Sets the photo object.
48 */
49 void setPhoto( const KABC::Picture &photo );
50
51 /**
52 Returns a photo object.
53 */
54 KABC::Picture photo() const;
55
56 /**
57 Sets the logo object.
58 */
59 void setLogo( const KABC::Picture &photo );
60
61 /**
62 Returns a logo object.
63 */
64 KABC::Picture logo() const;
65
66 signals:
67 void changed();
68
69 private slots:
70 void loadPhoto();
71 void loadLogo();
72 void updateGUI();
73
74 private:
75 QPixmap loadPixmap( const KURL &url );
76
77 KURLRequester *mPhotoUrl;
78 KURLRequester *mLogoUrl;
79
80 QCheckBox *mUsePhotoUrl;
81 QCheckBox *mUseLogoUrl;
82 QLabel *mPhotoLabel;
83 QLabel *mLogoLabel;
84};
85
86#endif
diff --git a/kaddressbook/incsearchwidget.cpp b/kaddressbook/incsearchwidget.cpp
new file mode 100644
index 0000000..94c37e7
--- a/dev/null
+++ b/kaddressbook/incsearchwidget.cpp
@@ -0,0 +1,147 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Tobias Koenig <tokoe@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 <qlabel.h>
25#include <qlayout.h>
26#include <qtooltip.h>
27#include <qcombobox.h>
28
29#include <kdialog.h>
30#include <klineedit.h>
31#include <klocale.h>
32#include <kglobal.h>
33
34#include "incsearchwidget.h"
35
36IncSearchWidget::IncSearchWidget( QWidget *parent, const char *name )
37 : QWidget( parent, name )
38{
39#ifndef KAB_EMBEDDED
40//US setCaption( i18n( "Incremental Search" ) );
41#endif //KAB_EMBEDDED
42
43 QHBoxLayout *layout = new QHBoxLayout( this, 2, KDialog::spacingHint() );
44
45#ifdef DESKTOP_VERSION
46 QLabel *label = new QLabel( i18n( "Search:" ), this );
47 label->setAlignment( QLabel::AlignVCenter | QLabel::AlignRight );
48 layout->addWidget( label );
49#endif //KAB_EMBEDDED
50
51 mSearchText = new KLineEdit( this );
52 layout->addWidget( mSearchText );
53// #ifdef KAB_EMBEDDED
54// if (KGlobal::getOrientation() == KGlobal::Portrait)
55// mSearchText->setMaximumWidth(30);
56// #endif //KAB_EMBEDDED
57
58
59 mFieldCombo = new QComboBox( false, this );
60 layout->addWidget( mFieldCombo );
61 mFieldCombo->setMaximumHeight( 34 );
62 QToolTip::add( mFieldCombo, i18n( "Select Incremental Search Field" ) );
63
64// #ifndef KAB_EMBEDDED
65// resize( QSize(420, 50).expandedTo( sizeHint() ) );
66// #else //KAB_EMBEDDED
67// resize( QSize(30, 10).expandedTo( sizeHint() ) );
68// #endif //KAB_EMBEDDED
69
70 connect( mSearchText, SIGNAL( textChanged( const QString& ) ),
71 SLOT( announceDoSearch() ) );
72 connect( mSearchText, SIGNAL( returnPressed() ),
73 SLOT( announceDoSearch() ) );
74 connect( mFieldCombo, SIGNAL( activated( const QString& ) ),
75 SLOT( announceDoSearch() ) );
76 connect( mFieldCombo, SIGNAL( activated( const QString& ) ),
77 SLOT( announceFieldChanged() ) );
78
79 setFocusProxy( mSearchText );
80}
81
82IncSearchWidget::~IncSearchWidget()
83{
84
85}
86
87void IncSearchWidget::announceDoSearch()
88{
89 emit doSearch( mSearchText->text() );
90}
91
92void IncSearchWidget::announceFieldChanged()
93{
94 emit fieldChanged();
95}
96
97void IncSearchWidget::setFields( const KABC::Field::List &list )
98{
99
100 mFieldCombo->clear();
101 mFieldCombo->insertItem( i18n( "All Fields" ) );
102 QFontMetrics fm ( mFieldCombo->font() );
103 int wid = fm.width(i18n( "All Fields" ) );
104 int max = wid;
105
106 KABC::Field::List::ConstIterator it;
107 for ( it = list.begin(); it != list.end(); ++it ) {
108 mFieldCombo->insertItem( (*it)->label() );
109 // wid = fm.width((*it)->label() );
110 //if ( wid > max )
111 // max = wid;
112 }
113
114 mFieldList = list;
115
116 announceDoSearch();
117 announceFieldChanged();
118 mFieldCombo->setMaximumWidth( wid+60 );
119}
120
121KABC::Field::List IncSearchWidget::fields() const
122{
123 return mFieldList;
124}
125
126KABC::Field *IncSearchWidget::currentField()const
127{
128 if ( mFieldCombo->currentItem() == -1 || mFieldCombo->currentItem() == 0 )
129 return 0; // for error or 'use all fields'
130 else
131 return mFieldList[ mFieldCombo->currentItem() - 1 ];
132}
133
134void IncSearchWidget::setCurrentItem( int pos )
135{
136 mFieldCombo->setCurrentItem( pos );
137 announceFieldChanged();
138}
139
140int IncSearchWidget::currentItem() const
141{
142
143 return mFieldCombo->currentItem();
144}
145#ifndef KAB_EMBEDDED
146#include "incsearchwidget.moc"
147#endif //KAB_EMBEDDED
diff --git a/kaddressbook/incsearchwidget.h b/kaddressbook/incsearchwidget.h
new file mode 100644
index 0000000..09fb8ac
--- a/dev/null
+++ b/kaddressbook/incsearchwidget.h
@@ -0,0 +1,73 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Tobias Koenig <tokoe@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#ifndef INCSEARCHWIDGET_H
25#define INCSEARCHWIDGET_H
26
27#include <qwidget.h>
28
29#include <kabc/field.h>
30
31class QComboBox;
32class KLineEdit;
33
34class IncSearchWidget : public QWidget
35{
36 Q_OBJECT
37
38 public:
39 IncSearchWidget( QWidget *parent, const char *name = 0 );
40 ~IncSearchWidget();
41
42 void setFields( const KABC::Field::List &list );
43 KABC::Field::List fields() const;
44
45 KABC::Field *currentField() const;
46
47 void setCurrentItem( int pos );
48 int currentItem() const;
49
50 signals:
51 /**
52 This signal is emmited whenever the text in the input
53 widget is changed. You can get the sorting field by
54 @ref currentField.
55 */
56 void doSearch( const QString& text );
57
58 /**
59 This signal is emmited whenever the search field changes.
60 */
61 void fieldChanged();
62
63 private slots:
64 void announceDoSearch();
65 void announceFieldChanged();
66
67 private:
68 QComboBox* mFieldCombo;
69 KLineEdit* mSearchText;
70 KABC::Field::List mFieldList;
71};
72
73#endif
diff --git a/kaddressbook/jumpbuttonbar.cpp b/kaddressbook/jumpbuttonbar.cpp
new file mode 100644
index 0000000..ee5b44e
--- a/dev/null
+++ b/kaddressbook/jumpbuttonbar.cpp
@@ -0,0 +1,232 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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 <qevent.h>
25#include <qlayout.h>
26#include <qpushbutton.h>
27#include <qstring.h>
28#include <qtl.h>
29#include <qapplication.h>
30
31#include <kabc/addressbook.h>
32#include <kabc/field.h>
33#include <kdebug.h>
34#include <klocale.h>
35
36#include "kabcore.h"
37
38#include "jumpbuttonbar.h"
39
40class JumpButton : public QPushButton
41{
42 public:
43 JumpButton( const QString &text, QWidget *parent,
44 const QString &character );
45
46 void setCharacter( const QString &character );
47 QString character() const;
48
49 private:
50 QString mCharacter;
51};
52
53JumpButton::JumpButton( const QString &text, QWidget *parent,
54 const QString &character )
55 : QPushButton( text, parent )
56{
57 mCharacter = character;
58}
59
60void JumpButton::setCharacter( const QString &character )
61{
62 mCharacter = character;
63 setText(mCharacter.upper() );
64}
65
66QString JumpButton::character() const
67{
68 return mCharacter;
69}
70
71JumpButtonBar::JumpButtonBar( KABCore *core, QWidget *parent, const char *name )
72 : QWidget( parent, name ), mCore( core )
73{
74 if ( QApplication::desktop()->width() < 480 )
75
76 mButtonLayout = new QGridLayout( this, 2, 14 );
77 else
78 mButtonLayout = new QGridLayout( this, 1, 28 );
79 mButtonLayout->setAlignment( Qt::AlignTop );
80
81 recreateButtons();
82}
83
84JumpButtonBar::~JumpButtonBar()
85{
86}
87
88QSizePolicy JumpButtonBar::sizePolicy() const
89{
90#ifndef KAB_EMBEDDED
91 return QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Minimum,
92 QSizePolicy::Vertically );
93#else //KAB_EMBEDDED
94 return QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Minimum);
95#endif //KAB_EMBEDDED
96}
97
98void JumpButtonBar::letterClicked()
99{
100 JumpButton *button = (JumpButton*)sender();
101 QString character = button->character();
102 if ( !character.isNull() )
103 emit jumpToLetter( character );
104}
105
106void JumpButtonBar::recreateButtons()
107{
108 // the easiest way to remove all buttons ;)
109 //mButtons.setAutoDelete( true );
110 //mButtons.clear();
111 //mButtons.setAutoDelete( false );
112 mCharacters.clear();
113
114 QString character;
115
116 KABC::AddressBook *ab = mCore->addressBook();
117 KABC::AddressBook::Iterator it;
118 KABC::Field *field = mCore->currentSearchField();
119 if ( field ) {
120 setEnabled( true );
121 } else {
122 setEnabled( false );
123 return;
124 }
125 for ( it = ab->begin(); it != ab->end(); ++it ) {
126 if ( !field->value( *it ).isEmpty() )
127 character = field->value( *it )[ 0 ].lower();
128 if ( !character.isEmpty() && !mCharacters.contains( character ) )
129 mCharacters.append( character );
130 }
131 if ( mCharacters.count() == 0 ) {
132 setEnabled( false );
133 return;
134 }
135
136 int maxRows = mCharacters.count() / 2; // we use 2 columns
137 if ( mCharacters.count() % 2 )
138 maxRows++;
139 int fixwid = 20;
140 sortListLocaleAware( mCharacters );
141 bool skip2 = false;
142 int skipcount = 0;
143 int maxHei = 25;
144 if ( QApplication::desktop()->width() < 480 && mCharacters.count() > 13) {
145 skipcount = mCharacters.count()-13;
146 maxHei = (QApplication::desktop()->height()-65)/13;
147 }
148 else {
149 fixwid = 30;
150 if ( mCharacters.count() > 20 )
151 skipcount = mCharacters.count()- 20;
152 maxHei = (QApplication::desktop()->height()-120)/(mCharacters.count()-skipcount);
153
154 }
155 maxRows = 28;
156 bool skipcurrent = false;
157 bool state = isUpdatesEnabled();
158 setUpdatesEnabled( false );
159 //qDebug("cc %d ",mCharacters.count() );
160 JumpButton *button;
161 int row = 0, col = 0;
162 JumpButton* cur = mButtons.first();
163 for ( uint i = 0; i < mCharacters.count(); ++i ) {
164 if ( skipcount > 0 && skipcurrent ) {
165 --skipcount;
166 } else {
167 if ( cur ) {
168 button = cur ;
169 cur = mButtons.next();
170 button->setCharacter(mCharacters[ i ]);
171 } else {
172 button = new JumpButton( mCharacters[ i ].upper(), this, mCharacters[ i ] );
173 button->setFixedWidth( fixwid );
174 mButtons.append( button );
175 connect( button, SIGNAL( clicked() ), this, SLOT( letterClicked() ) );
176 mButtonLayout->addWidget( button, row, col );
177 }
178 button->setMaximumHeight( maxHei );
179 button->show();
180
181 if ( col == maxRows ) {
182 row = 0;
183 col++;
184 } else
185 row++;
186 }
187
188 skipcurrent = !skipcurrent;
189 }
190 while ( cur ) {
191 cur->hide();
192 cur = mButtons.next();
193 }
194
195 mButtonLayout->activate();
196 setUpdatesEnabled( state );
197 update();
198}
199
200void JumpButtonBar::sortListLocaleAware( QStringList &list )
201{
202 QStringList::Iterator beginIt = list.begin();
203 QStringList::Iterator endIt = list.end();
204
205 --endIt;
206 if ( beginIt == endIt ) // don't need sorting
207 return;
208
209 QStringList::Iterator walkBackIt = endIt;
210 while ( beginIt != endIt ) {
211 QStringList::Iterator j1 = list.begin();
212 QStringList::Iterator j2 = j1;
213 ++j2;
214 while ( j1 != walkBackIt ) {
215#ifndef KAB_EMBEDDED
216 if ( QString::localeAwareCompare( *j2, *j1 ) < 0 )
217#else //KAB_EMBEDDED
218 if ( QString::compare( *j2, *j1 ) < 0 )
219#endif //KAB_EMBEDDED
220 qSwap( *j1, *j2 );
221
222 ++j1;
223 ++j2;
224 }
225 ++beginIt;
226 --walkBackIt;
227 }
228}
229
230#ifndef KAB_EMBEDDED
231#include "jumpbuttonbar.moc"
232#endif //KAB_EMBEDDED
diff --git a/kaddressbook/jumpbuttonbar.h b/kaddressbook/jumpbuttonbar.h
new file mode 100644
index 0000000..d534f2b
--- a/dev/null
+++ b/kaddressbook/jumpbuttonbar.h
@@ -0,0 +1,84 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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#ifndef JUMPBUTTONBAR_H
25#define JUMPBUTTONBAR_H
26
27#include <qsizepolicy.h>
28#include <qwidget.h>
29#include <qptrlist.h>
30#include <qstringlist.h>
31
32class QChar;
33class QGridLayout;
34class QResizeEvent;
35class QPushButton;
36class JumpButton;
37
38namespace KABC {
39class Field;
40}
41
42class KABCore;
43
44/**
45 Used to draw the jump button bar on the right of the view.
46 */
47class JumpButtonBar : public QWidget
48{
49 Q_OBJECT
50
51 public:
52 JumpButtonBar( KABCore *core, QWidget *parent, const char *name = 0 );
53 ~JumpButtonBar();
54
55 QSizePolicy sizePolicy() const;
56
57 public slots:
58 /**
59 This method removes all buttons from the GUI and recreates them
60 according to the current global search field and the content of
61 the address book.
62 */
63 void recreateButtons();
64
65 signals:
66 /**
67 Emitted whenever a letter is selected by the user.
68 */
69 void jumpToLetter( const QString &character );
70
71 protected slots:
72 void letterClicked();
73
74 private:
75 void sortListLocaleAware( QStringList &list );
76
77 KABCore *mCore;
78
79 QGridLayout *mButtonLayout;
80 QStringList mCharacters;
81 QPtrList<JumpButton> mButtons;
82};
83
84#endif
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
new file mode 100644
index 0000000..3e578bc
--- a/dev/null
+++ b/kaddressbook/kabcore.cpp
@@ -0,0 +1,1571 @@
1/*
2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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 "kabcore.h"
25
26#include <stdaddressbook.h>
27#include <klocale.h>
28
29#ifndef KAB_EMBEDDED
30#include <qclipboard.h>
31#include <qdir.h>
32#include <qfile.h>
33#include <qapplicaton.h>
34#include <qlayout.h>
35#include <qregexp.h>
36#include <qvbox.h>
37#include <kabc/addresseelist.h>
38#include <kabc/errorhandler.h>
39#include <kabc/resource.h>
40#include <kabc/vcardconverter.h>
41#include <kapplication.h>
42#include <kactionclasses.h>
43#include <kcmultidialog.h>
44#include <kdebug.h>
45#include <kdeversion.h>
46#include <kkeydialog.h>
47#include <kmessagebox.h>
48#include <kprinter.h>
49#include <kprotocolinfo.h>
50#include <kresources/selectdialog.h>
51#include <kstandarddirs.h>
52#include <ktempfile.h>
53#include <kxmlguiclient.h>
54#include <kaboutdata.h>
55#include <libkdepim/categoryselectdialog.h>
56
57#include "addresseeutil.h"
58#include "addresseeeditordialog.h"
59#include "extensionmanager.h"
60#include "kstdaction.h"
61#include "kaddressbookservice.h"
62#include "ldapsearchdialog.h"
63#include "printing/printingwizard.h"
64#else // KAB_EMBEDDED
65
66#include "KDGanttMinimizeSplitter.h"
67#include "kaddressbookmain.h"
68#include "kactioncollection.h"
69#include <qapp.h>
70#include <qmenubar.h>
71//#include <qtoolbar.h>
72#include <qmessagebox.h>
73#include <kdebug.h>
74#include <kiconloader.h> // needed for SmallIcon
75#include <kresources/kcmkresources.h>
76#include <ktoolbar.h>
77
78#include <kcmkabconfig.h>
79
80//US#include <qpe/resource.h> // needed for Resource::loadPixmap
81//#include <qlabel.h>
82#endif // KAB_EMBEDDED
83#include <kcmkabconfig.h>
84
85
86#include <kresources/selectdialog.h>
87#include <kmessagebox.h>
88
89#include <picture.h>
90#include <resource.h>
91
92//US#include <qsplitter.h>
93#include <qvbox.h>
94#include <qlayout.h>
95#include <qclipboard.h>
96
97#include <libkdepim/categoryselectdialog.h>
98
99#include "addresseeutil.h"
100#include "undocmds.h"
101#include "addresseeeditordialog.h"
102#include "viewmanager.h"
103#include "details/detailsviewcontainer.h"
104#include "kabprefs.h"
105#include "xxportmanager.h"
106#include "incsearchwidget.h"
107#include "jumpbuttonbar.h"
108#include "extensionmanager.h"
109#include "addresseeconfig.h"
110#include <kcmultidialog.h>
111
112
113#ifdef KAB_EMBEDDED
114KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name )
115 : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ),
116 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/
117 mReadWrite( readWrite ), mModified( false ), mMainWindow(client)
118#else //KAB_EMBEDDED
119KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name )
120 : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ),
121 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ),
122 mReadWrite( readWrite ), mModified( false )
123#endif //KAB_EMBEDDED
124{
125#ifdef KAB_EMBEDDED
126 //US we define here our own global actioncollection.
127 //mActionCollection = new KActionCollection(this);
128#endif //KAB_EMBEDDED
129
130 mIsPart = !parent->inherits( "KAddressBookMain" );
131
132 mAddressBook = KABC::StdAddressBook::self();
133 KABC::StdAddressBook::setAutomaticSave( true );
134
135#ifndef KAB_EMBEDDED
136 mAddressBook->setErrorHandler( new KABC::GUIErrorHandler );
137#endif //KAB_EMBEDDED
138
139 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ),
140 SLOT( addressBookChanged() ) );
141
142 mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization,
143 "X-Department", "KADDRESSBOOK" );
144 mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization,
145 "X-Profession", "KADDRESSBOOK" );
146 mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
147 "X-AssistantsName", "KADDRESSBOOK" );
148 mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
149 "X-ManagersName", "KADDRESSBOOK" );
150 mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
151 "X-SpousesName", "KADDRESSBOOK" );
152 mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal,
153 "X-Office", "KADDRESSBOOK" );
154 mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
155 "X-IMAddress", "KADDRESSBOOK" );
156 mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
157 "X-Anniversary", "KADDRESSBOOK" );
158
159 initGUI();
160
161 mIncSearchWidget->setFocus();
162
163
164 connect( mViewManager, SIGNAL( selected( const QString& ) ),
165 SLOT( setContactSelected( const QString& ) ) );
166 connect( mViewManager, SIGNAL( executed( const QString& ) ),
167 SLOT( editContact( const QString& ) ) );
168 connect( mViewManager, SIGNAL( deleteRequest( ) ),
169 SLOT( deleteContacts( ) ) );
170 connect( mViewManager, SIGNAL( modified() ),
171 SLOT( setModified() ) );
172
173 connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) );
174
175 connect( mXXPortManager, SIGNAL( modified() ),
176 SLOT( setModified() ) );
177
178 connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ),
179 SLOT( incrementalSearch( const QString& ) ) );
180 connect( mIncSearchWidget, SIGNAL( fieldChanged() ),
181 mJumpButtonBar, SLOT( recreateButtons() ) );
182
183#ifndef KAB_EMBEDDED
184 connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ),
185 mXXPortManager, SLOT( importVCard( const KURL& ) ) );
186
187 connect( mDetails, SIGNAL( sendEmail( const QString& ) ),
188 SLOT( sendMail( const QString& ) ) );
189 connect( mDetails, SIGNAL( browse( const QString& ) ),
190 SLOT( browse( const QString& ) ) );
191
192 mAddressBookService = new KAddressBookService( this );
193
194#endif //KAB_EMBEDDED
195
196 setModified( false );
197}
198
199KABCore::~KABCore()
200{
201 // save();
202 //saveSettings();
203 //KABPrefs::instance()->writeConfig();
204 delete AddresseeConfig::instance();
205 mAddressBook = 0;
206 KABC::StdAddressBook::close();
207
208#ifdef KAB_EMBEDDED
209 //US we define here our own global actioncollection.
210 // delete mActionCollection;
211#endif //KAB_EMBEDDED
212
213}
214
215void KABCore::restoreSettings()
216{
217 bool state = KABPrefs::instance()->mJumpButtonBarVisible;
218
219 mActionJumpBar->setChecked( state );
220 setJumpButtonBarVisible( state );
221
222 state = KABPrefs::instance()->mDetailsPageVisible;
223
224 mActionDetails->setChecked( state );
225 setDetailsVisible( state );
226 QValueList<int> splitterSize = KABPrefs::instance()->mExtensionsSplitter;
227 if ( splitterSize.count() == 0 ) {
228 splitterSize.append( width() / 2 );
229 splitterSize.append( width() / 2 );
230 }
231 mMiniSplitter->setSizes( splitterSize );
232#ifndef KAB_EMBEDDED
233 QValueList<int> splitterSize = KABPrefs::instance()->mExtensionsSplitter;
234 if ( splitterSize.count() == 0 ) {
235 splitterSize.append( width() / 2 );
236 splitterSize.append( width() / 2 );
237 }
238 mExtensionBarSplitter->setSizes( splitterSize );
239
240 splitterSize = KABPrefs::instance()->mDetailsSplitter;
241 if ( splitterSize.count() == 0 ) {
242 splitterSize.append( height() / 2 );
243 splitterSize.append( height() / 2 );
244 }
245 mDetailsSplitter->setSizes( splitterSize );
246
247 mExtensionManager->restoreSettings();
248
249#endif //KAB_EMBEDDED
250
251 mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField );
252
253 mViewManager->restoreSettings();
254 mExtensionManager->restoreSettings();
255}
256
257void KABCore::saveSettings()
258{
259 KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked();
260 KABPrefs::instance()->mExtensionsSplitter = mMiniSplitter->sizes();
261 KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked();
262
263#ifndef KAB_EMBEDDED
264
265 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
266 KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes();
267#endif //KAB_EMBEDDED
268 mExtensionManager->saveSettings();
269 mViewManager->saveSettings();
270
271 KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem();
272
273}
274
275KABC::AddressBook *KABCore::addressBook() const
276{
277 return mAddressBook;
278}
279
280KConfig *KABCore::config()
281{
282#ifndef KAB_EMBEDDED
283 return KABPrefs::instance()->config();
284#else //KAB_EMBEDDED
285 return KABPrefs::instance()->getConfig();
286#endif //KAB_EMBEDDED
287}
288
289KActionCollection *KABCore::actionCollection() const
290{
291 return mGUIClient->actionCollection();
292}
293
294KABC::Field *KABCore::currentSearchField() const
295{
296 if (mIncSearchWidget)
297 return mIncSearchWidget->currentField();
298 else
299 return 0;
300}
301
302QStringList KABCore::selectedUIDs() const
303{
304 return mViewManager->selectedUids();
305}
306
307KABC::Resource *KABCore::requestResource( QWidget *parent )
308{
309 QPtrList<KABC::Resource> kabcResources = addressBook()->resources();
310
311 QPtrList<KRES::Resource> kresResources;
312 QPtrListIterator<KABC::Resource> resIt( kabcResources );
313 KABC::Resource *resource;
314 while ( ( resource = resIt.current() ) != 0 ) {
315 ++resIt;
316 if ( !resource->readOnly() ) {
317 KRES::Resource *res = static_cast<KRES::Resource*>( resource );
318 if ( res )
319 kresResources.append( res );
320 }
321 }
322
323 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent );
324 return static_cast<KABC::Resource*>( res );
325}
326
327#ifndef KAB_EMBEDDED
328KAboutData *KABCore::createAboutData()
329#else //KAB_EMBEDDED
330void KABCore::createAboutData()
331#endif //KAB_EMBEDDED
332{
333#ifndef KAB_EMBEDDED
334 KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ),
335 "3.1", I18N_NOOP( "The KDE Address Book" ),
336 KAboutData::License_GPL_V2,
337 I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) );
338 about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" );
339 about->addAuthor( "Don Sanders", I18N_NOOP( "Original author " ) );
340 about->addAuthor( "Cornelius Schumacher",
341 I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export " ),
342 "schumacher@kde.org" );
343 about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign " ),
344 "mpilone@slac.com" );
345 about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) );
346 about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) );
347 about->addAuthor( "Michel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup\n" ),
348 "michel@klaralvdalens-datakonsult.se" );
349 about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup " ),
350 "hansen@kde.org" );
351
352 return about;
353#endif //KAB_EMBEDDED
354
355 QString version;
356#include <../version>
357 QMessageBox::about( this, "About KAddressbook/Pi",
358 "KAddressbook/Platform-independent\n"
359 "(KA/Pi) " +version + " - " +
360#ifdef DESKTOP_VERSION
361 "Desktop Edition\n"
362#else
363 "PDA-Edition\n"
364 "for: Zaurus 5500 / 7x0 / 8x0\n"
365#endif
366
367 "(c) 2004 Ulf Schenk\n"
368 "(c) 1997-2003, The KDE PIM Team\n"
369 "Tobias Koenig Current maintainer tokoe@kde.org\n"
370 "Don Sanders Original author\n"
371 "Cornelius Schumacher Co-maintainer schumacher@kde.org\n"
372 "Mike Pilone GUI and framework redesign mpilone@slac.com\n"
373 "Greg Stern DCOP interface\n"
374 "Mark Westcot Contact pinning\n"
375 "Michel Boyer de la Giroday LDAP Lookup\n" "michel@klaralvdalens-datakonsult.se\n"
376 "Steffen Hansen LDAP Lookup hansen@kde.org\n" );
377}
378
379void KABCore::setContactSelected( const QString &uid )
380{
381 KABC::Addressee addr = mAddressBook->findByUid( uid );
382 if ( !mDetails->isHidden() )
383 mDetails->setAddressee( addr );
384
385 if ( !addr.isEmpty() ) {
386 emit contactSelected( addr.formattedName() );
387 KABC::Picture pic = addr.photo();
388 if ( pic.isIntern() ) {
389//US emit contactSelected( pic.data() );
390//US instead use:
391 QPixmap px;
392 if (pic.data().isNull() != true)
393 {
394 px.convertFromImage(pic.data());
395 }
396
397 emit contactSelected( px );
398 }
399 }
400
401
402 mExtensionManager->setSelectionChanged();
403
404 // update the actions
405 bool selected = !uid.isEmpty();
406
407 if ( mReadWrite ) {
408 mActionCut->setEnabled( selected );
409 mActionPaste->setEnabled( selected );
410 }
411
412 mActionCopy->setEnabled( selected );
413 mActionDelete->setEnabled( selected );
414 mActionEditAddressee->setEnabled( selected );
415 mActionMail->setEnabled( selected );
416 mActionMailVCard->setEnabled( selected );
417 mActionWhoAmI->setEnabled( selected );
418 mActionCategories->setEnabled( selected );
419}
420
421void KABCore::sendMail()
422{
423#ifndef KAB_EMBEDDED
424 sendMail( mViewManager->selectedEmails().join( ", " ) );
425#else //KAB_EMBEDDED
426 qDebug("KABCore::sendMail() ust be fixed");
427#endif //KAB_EMBEDDED
428}
429
430void KABCore::sendMail( const QString& email )
431{
432#ifndef KAB_EMBEDDED
433 kapp->invokeMailer( email, "" );
434#else //KAB_EMBEDDED
435 qDebug("KABCore::sendMail(const QString& email) ust be fixed");
436#endif //KAB_EMBEDDED
437}
438
439void KABCore::mailVCard()
440{
441#ifndef KAB_EMBEDDED
442 QStringList uids = mViewManager->selectedUids();
443 if ( !uids.isEmpty() )
444 mailVCard( uids );
445#else //KAB_EMBEDDED
446 qDebug("KABCore::mailVCard() must be fixed");
447#endif //KAB_EMBEDDED
448}
449
450void KABCore::mailVCard( const QStringList& uids )
451{
452#ifndef KAB_EMBEDDED
453 QStringList urls;
454
455 // Create a temp dir, so that we can put the files in it with proper names
456 KTempFile tempDir;
457 if ( tempDir.status() != 0 ) {
458 kdWarning() << strerror( tempDir.status() ) << endl;
459 return;
460 }
461
462 QString dirName = tempDir.name();
463 tempDir.unlink();
464 QDir().mkdir( dirName, true );
465
466 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
467 KABC::Addressee a = mAddressBook->findByUid( *it );
468
469 if ( a.isEmpty() )
470 continue;
471
472 QString name = a.givenName() + "_" + a.familyName() + ".vcf";
473
474 QString fileName = dirName + "/" + name;
475
476 QFile outFile(fileName);
477 if ( outFile.open(IO_WriteOnly) ) { // file opened successfully
478 KABC::VCardConverter converter;
479 QString vcard;
480
481 converter.addresseeToVCard( a, vcard );
482
483 QTextStream t( &outFile ); // use a text stream
484 t.setEncoding( QTextStream::UnicodeUTF8 );
485 t << vcard;
486
487 outFile.close();
488
489 urls.append( fileName );
490 }
491 }
492
493 kapp->invokeMailer( QString::null, QString::null, QString::null,
494 QString::null, // subject
495 QString::null, // body
496 QString::null,
497 urls ); // attachments
498#else //KAB_EMBEDDED
499 qDebug("KABCore::mailVCard( must be fixed");
500#endif //KAB_EMBEDDED
501
502}
503
504void KABCore::browse( const QString& url )
505{
506#ifndef KAB_EMBEDDED
507 kapp->invokeBrowser( url );
508#else //KAB_EMBEDDED
509 qDebug("KABCore::browse must be fixed");
510#endif //KAB_EMBEDDED
511}
512
513void KABCore::selectAllContacts()
514{
515 mViewManager->setSelected( QString::null, true );
516}
517
518void KABCore::deleteContacts()
519{
520 QStringList uidList = mViewManager->selectedUids();
521 deleteContacts( uidList );
522}
523
524void KABCore::deleteContacts( const QStringList &uids )
525{
526 if ( uids.count() > 0 ) {
527 PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids );
528 UndoStack::instance()->push( command );
529 RedoStack::instance()->clear();
530
531 // now if we deleted anything, refresh
532 setContactSelected( QString::null );
533 setModified( true );
534 }
535}
536
537void KABCore::copyContacts()
538{
539 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
540
541 QString clipText = AddresseeUtil::addresseesToClipboard( addrList );
542
543 kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl;
544
545 QClipboard *cb = QApplication::clipboard();
546 cb->setText( clipText );
547}
548
549void KABCore::cutContacts()
550{
551 QStringList uidList = mViewManager->selectedUids();
552
553//US if ( uidList.size() > 0 ) {
554 if ( uidList.count() > 0 ) {
555 PwCutCommand *command = new PwCutCommand( mAddressBook, uidList );
556 UndoStack::instance()->push( command );
557 RedoStack::instance()->clear();
558
559 setModified( true );
560 }
561}
562
563void KABCore::pasteContacts()
564{
565 QClipboard *cb = QApplication::clipboard();
566
567 KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() );
568
569 pasteContacts( list );
570}
571
572void KABCore::pasteContacts( KABC::Addressee::List &list )
573{
574 KABC::Resource *resource = requestResource( this );
575 KABC::Addressee::List::Iterator it;
576 for ( it = list.begin(); it != list.end(); ++it )
577 (*it).setResource( resource );
578
579 PwPasteCommand *command = new PwPasteCommand( this, list );
580 UndoStack::instance()->push( command );
581 RedoStack::instance()->clear();
582
583 setModified( true );
584}
585
586void KABCore::setWhoAmI()
587{
588 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
589
590 if ( addrList.count() > 1 ) {
591 KMessageBox::sorry( this, i18n( "Please select only one contact." ) );
592 return;
593 }
594
595 QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) );
596 if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes )
597 static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] );
598}
599
600void KABCore::setCategories()
601{
602 KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true );
603 if ( !dlg.exec() )
604 return;
605
606 bool merge = false;
607 QString msg = i18n( "Merge with existing categories?" );
608 if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes )
609 merge = true;
610
611 QStringList categories = dlg.selectedCategories();
612
613 QStringList uids = mViewManager->selectedUids();
614 QStringList::Iterator it;
615 for ( it = uids.begin(); it != uids.end(); ++it ) {
616 KABC::Addressee addr = mAddressBook->findByUid( *it );
617 if ( !addr.isEmpty() ) {
618 if ( !merge )
619 addr.setCategories( categories );
620 else {
621 QStringList addrCategories = addr.categories();
622 QStringList::Iterator catIt;
623 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) {
624 if ( !addrCategories.contains( *catIt ) )
625 addrCategories.append( *catIt );
626 }
627 addr.setCategories( addrCategories );
628 }
629
630 mAddressBook->insertAddressee( addr );
631 }
632 }
633
634 if ( uids.count() > 0 )
635 setModified( true );
636}
637
638void KABCore::setSearchFields( const KABC::Field::List &fields )
639{
640 mIncSearchWidget->setFields( fields );
641}
642
643void KABCore::incrementalSearch( const QString& text )
644{
645 mViewManager->setSelected( QString::null, false );
646
647 if ( !text.isEmpty() ) {
648 KABC::Field *field = mIncSearchWidget->currentField();
649
650 QString pattern = text.lower();
651
652#if KDE_VERSION >= 319
653 KABC::AddresseeList list( mAddressBook->allAddressees() );
654 if ( field ) {
655 list.sortByField( field );
656 KABC::AddresseeList::Iterator it;
657 for ( it = list.begin(); it != list.end(); ++it ) {
658 if ( field->value( *it ).lower().startsWith( pattern ) ) {
659 mViewManager->setSelected( (*it).uid(), true );
660 return;
661 }
662 }
663 } else {
664 KABC::AddresseeList::Iterator it;
665 for ( it = list.begin(); it != list.end(); ++it ) {
666 KABC::Field::List fieldList = mIncSearchWidget->fields();
667 KABC::Field::List::ConstIterator fieldIt;
668 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
669 if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) {
670 mViewManager->setSelected( (*it).uid(), true );
671 return;
672 }
673 }
674 }
675 }
676#else
677 KABC::AddressBook::Iterator it;
678 for ( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
679 if ( field ) {
680 if ( field->value( *it ).lower().startsWith( pattern ) ) {
681 mViewManager->setSelected( (*it).uid(), true );
682 return;
683 }
684 } else {
685 KABC::Field::List fieldList = mIncSearchWidget->fields();
686 KABC::Field::List::ConstIterator fieldIt;
687 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
688 if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) {
689 mViewManager->setSelected( (*it).uid(), true );
690 return;
691 }
692 }
693 }
694 }
695#endif
696 }
697}
698
699void KABCore::setModified()
700{
701 setModified( true );
702}
703
704void KABCore::setModifiedWOrefresh()
705{
706 // qDebug("KABCore::setModifiedWOrefresh() ");
707 mModified = true;
708 mActionSave->setEnabled( mModified );
709#ifdef DESKTOP_VERSION
710 mDetails->refreshView();
711#endif
712
713}
714void KABCore::setModified( bool modified )
715{
716 mModified = modified;
717 mActionSave->setEnabled( mModified );
718
719 if ( modified )
720 mJumpButtonBar->recreateButtons();
721
722 mViewManager->refreshView();
723 mDetails->refreshView();
724
725}
726
727bool KABCore::modified() const
728{
729 return mModified;
730}
731
732void KABCore::contactModified( const KABC::Addressee &addr )
733{
734
735 Command *command = 0;
736 QString uid;
737
738 // check if it exists already
739 KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() );
740 if ( origAddr.isEmpty() )
741 command = new PwNewCommand( mAddressBook, addr );
742 else {
743 command = new PwEditCommand( mAddressBook, origAddr, addr );
744 uid = addr.uid();
745 }
746
747 UndoStack::instance()->push( command );
748 RedoStack::instance()->clear();
749
750 setModified( true );
751}
752
753void KABCore::newContact()
754{
755 AddresseeEditorDialog *dialog = 0;
756
757 QPtrList<KABC::Resource> kabcResources = mAddressBook->resources();
758
759 QPtrList<KRES::Resource> kresResources;
760 QPtrListIterator<KABC::Resource> it( kabcResources );
761 KABC::Resource *resource;
762 while ( ( resource = it.current() ) != 0 ) {
763 ++it;
764 if ( !resource->readOnly() ) {
765 KRES::Resource *res = static_cast<KRES::Resource*>( resource );
766 if ( res )
767 kresResources.append( res );
768 }
769 }
770
771 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this );
772 resource = static_cast<KABC::Resource*>( res );
773
774 if ( resource ) {
775 KABC::Addressee addr;
776 addr.setResource( resource );
777 dialog = createAddresseeEditorDialog( this );
778 dialog->setAddressee( addr );
779
780 } else
781 return;
782
783 mEditorDict.insert( dialog->addressee().uid(), dialog );
784
785 dialog->show();
786
787}
788
789void KABCore::addEmail( QString aStr )
790{
791#ifndef KAB_EMBEDDED
792 QString fullName, email;
793
794 KABC::Addressee::parseEmailAddress( aStr, fullName, email );
795
796 // Try to lookup the addressee matching the email address
797 bool found = false;
798 QStringList emailList;
799 KABC::AddressBook::Iterator it;
800 for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) {
801 emailList = (*it).emails();
802 if ( emailList.contains( email ) > 0 ) {
803 found = true;
804 (*it).setNameFromString( fullName );
805 editContact( (*it).uid() );
806 }
807 }
808
809 if ( !found ) {
810 KABC::Addressee addr;
811 addr.setNameFromString( fullName );
812 addr.insertEmail( email, true );
813
814 mAddressBook->insertAddressee( addr );
815 mViewManager->refreshView( addr.uid() );
816 editContact( addr.uid() );
817 }
818#else //KAB_EMBEDDED
819 qDebug("KABCore::addEmail finsih method");
820#endif //KAB_EMBEDDED
821}
822
823void KABCore::importVCard( const KURL &url, bool showPreview )
824{
825 mXXPortManager->importVCard( url, showPreview );
826}
827
828void KABCore::importVCard( const QString &vCard, bool showPreview )
829{
830 mXXPortManager->importVCard( vCard, showPreview );
831}
832
833//US added a second method without defaultparameter
834void KABCore::editContact2() {
835 editContact( QString::null );
836}
837
838void KABCore::editContact( const QString &uid )
839{
840
841 if ( mExtensionManager->isQuickEditVisible() )
842 return;
843
844 // First, locate the contact entry
845 QString localUID = uid;
846 if ( localUID.isNull() ) {
847 QStringList uidList = mViewManager->selectedUids();
848 if ( uidList.count() > 0 )
849 localUID = *( uidList.at( 0 ) );
850 }
851
852 KABC::Addressee addr = mAddressBook->findByUid( localUID );
853 if ( !addr.isEmpty() ) {
854 AddresseeEditorDialog *dialog = mEditorDict.find( addr.uid() );
855 if ( !dialog ) {
856 dialog = createAddresseeEditorDialog( this );
857
858 mEditorDict.insert( addr.uid(), dialog );
859
860 dialog->setAddressee( addr );
861 }
862
863 dialog->raise();
864 dialog->show();
865 }
866}
867
868void KABCore::save()
869{
870 if ( !mModified )
871 return;
872 QString text = i18n( "There was an error while attempting to save\n the "
873 "address book. Please check that some \nother application is "
874 "not using it. " );
875 statusMessage(i18n("Saving addressbook ... "));
876#ifndef KAB_EMBEDDED
877 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook );
878 if ( !b || !b->save() ) {
879 KMessageBox::error( this, text, i18n( "Unable to Save" ) );
880 }
881#else //KAB_EMBEDDED
882 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook );
883 if ( !b || !b->save() ) {
884 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok"));
885 }
886#endif //KAB_EMBEDDED
887
888 statusMessage(i18n("Addressbook saved!"));
889 setModified( false );
890}
891
892void KABCore::statusMessage(QString mess , int time )
893{
894 //topLevelWidget()->setCaption( mess );
895 // pending setting timer to revome message
896}
897void KABCore::undo()
898{
899 UndoStack::instance()->undo();
900
901 // Refresh the view
902 mViewManager->refreshView();
903}
904
905void KABCore::redo()
906{
907 RedoStack::instance()->redo();
908
909 // Refresh the view
910 mViewManager->refreshView();
911}
912
913void KABCore::setJumpButtonBarVisible( bool visible )
914{
915 if ( visible )
916 mJumpButtonBar->show();
917 else
918 mJumpButtonBar->hide();
919}
920void KABCore::setDetailsToState()
921{
922 setDetailsVisible( mActionDetails->isChecked() );
923}
924
925void KABCore::setDetailsVisible( bool visible )
926{
927 if ( visible )
928 mDetails->show();
929 else
930 mDetails->hide();
931}
932
933void KABCore::extensionModified( const KABC::Addressee::List &list )
934{
935
936 if ( list.count() != 0 ) {
937 KABC::Addressee::List::ConstIterator it;
938 for ( it = list.begin(); it != list.end(); ++it )
939 mAddressBook->insertAddressee( *it );
940 if ( list.count() > 1 )
941 setModified();
942 else
943 setModifiedWOrefresh();
944 }
945 if ( list.count() == 0 )
946 mViewManager->refreshView();
947 else
948 mViewManager->refreshView( list[ 0 ].uid() );
949
950
951
952}
953
954QString KABCore::getNameByPhone( const QString &phone )
955{
956#ifndef KAB_EMBEDDED
957 QRegExp r( "[/*/-/ ]" );
958 QString localPhone( phone );
959
960 bool found = false;
961 QString ownerName = "";
962 KABC::AddressBook::Iterator iter;
963 KABC::PhoneNumber::List::Iterator phoneIter;
964 KABC::PhoneNumber::List phoneList;
965 for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) {
966 phoneList = (*iter).phoneNumbers();
967 for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() );
968 ++phoneIter) {
969 // Get rid of separator chars so just the numbers are compared.
970 if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) {
971 ownerName = (*iter).formattedName();
972 found = true;
973 }
974 }
975 }
976
977 return ownerName;
978#else //KAB_EMBEDDED
979 qDebug("KABCore::getNameByPhone finsih method");
980 return "";
981#endif //KAB_EMBEDDED
982
983}
984
985void KABCore::openConfigDialog()
986{
987 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true );
988 KCMKabConfig* kabcfg = new KCMKabConfig( ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" );
989 ConfigureDialog->addModule(kabcfg );
990 connect( ConfigureDialog, SIGNAL( applyClicked() ),
991 this, SLOT( configurationChanged() ) );
992 connect( ConfigureDialog, SIGNAL( okClicked() ),
993 this, SLOT( configurationChanged() ) );
994 saveSettings();
995 ConfigureDialog->exec();
996 delete ConfigureDialog;
997}
998
999void KABCore::openLDAPDialog()
1000{
1001#ifndef KAB_EMBEDDED
1002 if ( !mLdapSearchDialog ) {
1003 mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this );
1004 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager,
1005 SLOT( refreshView() ) );
1006 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this,
1007 SLOT( setModified() ) );
1008 } else
1009 mLdapSearchDialog->restoreSettings();
1010
1011 if ( mLdapSearchDialog->isOK() )
1012 mLdapSearchDialog->exec();
1013#else //KAB_EMBEDDED
1014 qDebug("KABCore::openLDAPDialog() finsih method");
1015#endif //KAB_EMBEDDED
1016}
1017
1018void KABCore::print()
1019{
1020#ifndef KAB_EMBEDDED
1021 KPrinter printer;
1022 if ( !printer.setup( this ) )
1023 return;
1024
1025 KABPrinting::PrintingWizard wizard( &printer, mAddressBook,
1026 mViewManager->selectedUids(), this );
1027
1028 wizard.exec();
1029#else //KAB_EMBEDDED
1030 qDebug("KABCore::print() finsih method");
1031#endif //KAB_EMBEDDED
1032
1033}
1034
1035
1036void KABCore::addGUIClient( KXMLGUIClient *client )
1037{
1038 if ( mGUIClient )
1039 mGUIClient->insertChildClient( client );
1040 else
1041 KMessageBox::error( this, "no KXMLGUICLient");
1042}
1043
1044
1045void KABCore::configurationChanged()
1046{
1047 mExtensionManager->reconfigure();
1048}
1049
1050void KABCore::addressBookChanged()
1051{
1052#ifndef KAB_EMBEDDED
1053 QDictIterator<AddresseeEditorDialog> it( mEditorDict );
1054 while ( it.current() ) {
1055 if ( it.current()->dirty() ) {
1056 QString text = i18n( "Data has been changed externally. Unsaved "
1057 "changes will be lost." );
1058 KMessageBox::information( this, text );
1059 }
1060 it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) );
1061 ++it;
1062 }
1063
1064 mViewManager->refreshView();
1065#else //KAB_EMBEDDED
1066 qDebug("KABCore::addressBookChanged() finsih method");
1067#endif //KAB_EMBEDDED
1068}
1069
1070AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent,
1071 const char *name )
1072{
1073 AddresseeEditorDialog *dialog = new AddresseeEditorDialog( this, parent,
1074 name ? name : "editorDialog" );
1075
1076//US
1077 dialog->setMaximumSize( 640, 480 );
1078 dialog->showMaximized();
1079
1080 connect( dialog, SIGNAL( contactModified( const KABC::Addressee& ) ),
1081 SLOT( contactModified( const KABC::Addressee& ) ) );
1082 connect( dialog, SIGNAL( editorDestroyed( const QString& ) ),
1083 SLOT( slotEditorDestroyed( const QString& ) ) );
1084
1085 return dialog;
1086}
1087
1088void KABCore::slotEditorDestroyed( const QString &uid )
1089{
1090 mEditorDict.remove( uid );
1091}
1092
1093void KABCore::initGUI()
1094{
1095#ifndef KAB_EMBEDDED
1096 QHBoxLayout *topLayout = new QHBoxLayout( this );
1097 topLayout->setSpacing( KDialogBase::spacingHint() );
1098
1099 mExtensionBarSplitter = new QSplitter( this );
1100 mExtensionBarSplitter->setOrientation( Qt::Vertical );
1101
1102 mDetailsSplitter = new QSplitter( mExtensionBarSplitter );
1103
1104 QVBox *viewSpace = new QVBox( mDetailsSplitter );
1105 mIncSearchWidget = new IncSearchWidget( viewSpace );
1106 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1107 SLOT( incrementalSearch( const QString& ) ) );
1108
1109 mViewManager = new ViewManager( this, viewSpace );
1110 viewSpace->setStretchFactor( mViewManager, 1 );
1111
1112 mDetails = new ViewContainer( mDetailsSplitter );
1113
1114 mJumpButtonBar = new JumpButtonBar( this, this );
1115
1116 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter );
1117
1118 topLayout->addWidget( mExtensionBarSplitter );
1119 topLayout->setStretchFactor( mExtensionBarSplitter, 100 );
1120 topLayout->addWidget( mJumpButtonBar );
1121 topLayout->setStretchFactor( mJumpButtonBar, 1 );
1122
1123 mXXPortManager = new XXPortManager( this, this );
1124
1125#else //KAB_EMBEDDED
1126 //US initialize viewMenu before settingup viewmanager.
1127 // Viewmanager needs this menu to plugin submenues.
1128 viewMenu = new QPopupMenu( this );
1129 settingsMenu = new QPopupMenu( this );
1130 //filterMenu = new QPopupMenu( this );
1131 ImportMenu = new QPopupMenu( this );
1132 ExportMenu = new QPopupMenu( this );
1133
1134
1135//US since we have no splitter for the embedded system, setup
1136// a layout with two frames. One left and one right.
1137
1138 QBoxLayout *topLayout;
1139
1140 // = new QHBoxLayout( this );
1141// QBoxLayout *topLayout = (QBoxLayout*)layout();
1142
1143// QWidget *mainBox = new QWidget( this );
1144// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox);
1145
1146
1147 if ( QApplication::desktop()->width() > 480 ) {
1148 topLayout = new QHBoxLayout( this );
1149 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
1150 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
1151 } else {
1152
1153 topLayout = new QVBoxLayout( this );
1154 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this);
1155 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
1156 }
1157
1158 topLayout->addWidget(mMiniSplitter );
1159 mViewManager = new ViewManager( this, mMiniSplitter );
1160 mDetails = new ViewContainer( mMiniSplitter );
1161
1162
1163 mExtensionManager = new ExtensionManager( this, mMiniSplitter );
1164
1165 //eh->hide();
1166 // topLayout->addWidget(mExtensionManager );
1167
1168
1169/*US
1170#ifndef KAB_NOSPLITTER
1171 QHBoxLayout *topLayout = new QHBoxLayout( this );
1172//US topLayout->setSpacing( KDialogBase::spacingHint() );
1173 topLayout->setSpacing( 10 );
1174
1175 mDetailsSplitter = new QSplitter( this );
1176
1177 QVBox *viewSpace = new QVBox( mDetailsSplitter );
1178
1179 mViewManager = new ViewManager( this, viewSpace );
1180 viewSpace->setStretchFactor( mViewManager, 1 );
1181
1182 mDetails = new ViewContainer( mDetailsSplitter );
1183
1184 topLayout->addWidget( mDetailsSplitter );
1185 topLayout->setStretchFactor( mDetailsSplitter, 100 );
1186#else //KAB_NOSPLITTER
1187 QHBoxLayout *topLayout = new QHBoxLayout( this );
1188//US topLayout->setSpacing( KDialogBase::spacingHint() );
1189 topLayout->setSpacing( 10 );
1190
1191// mDetailsSplitter = new QSplitter( this );
1192
1193 QVBox *viewSpace = new QVBox( this );
1194
1195 mViewManager = new ViewManager( this, viewSpace );
1196 viewSpace->setStretchFactor( mViewManager, 1 );
1197
1198 mDetails = new ViewContainer( this );
1199
1200 topLayout->addWidget( viewSpace );
1201// topLayout->setStretchFactor( mDetailsSplitter, 100 );
1202 topLayout->addWidget( mDetails );
1203#endif //KAB_NOSPLITTER
1204*/
1205
1206
1207#endif //KAB_EMBEDDED
1208 initActions();
1209
1210#ifdef KAB_EMBEDDED
1211 addActionsManually();
1212 //US make sure the export and import menues are initialized before creating the xxPortManager.
1213 mXXPortManager = new XXPortManager( this, this );
1214
1215 // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() );
1216 //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget);
1217 // mActionQuit->plug ( mMainWindow->toolBar());
1218 //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() );
1219 //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget);
1220 // mIncSearchWidget->hide();
1221 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1222 SLOT( incrementalSearch( const QString& ) ) );
1223
1224
1225 mJumpButtonBar = new JumpButtonBar( this, this );
1226
1227 topLayout->addWidget( mJumpButtonBar );
1228//US topLayout->setStretchFactor( mJumpButtonBar, 10 );
1229
1230// mMainWindow->getIconToolBar()->raise();
1231
1232#endif //KAB_EMBEDDED
1233
1234}
1235void KABCore::initActions()
1236{
1237//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
1238
1239#ifndef KAB_EMBEDDED
1240 connect( QApplication::clipboard(), SIGNAL( dataChanged() ),
1241 SLOT( clipboardDataChanged() ) );
1242#endif //KAB_EMBEDDED
1243
1244 // file menu
1245 if ( mIsPart ) {
1246 mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this,
1247 SLOT( sendMail() ), actionCollection(),
1248 "kaddressbook_mail" );
1249 mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this,
1250 SLOT( print() ), actionCollection(), "kaddressbook_print" );
1251
1252 } else {
1253 mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() );
1254 mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() );
1255 }
1256
1257 mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this,
1258 SLOT( save() ), actionCollection(), "file_sync" );
1259
1260 mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this,
1261 SLOT( newContact() ), actionCollection(), "file_new_contact" );
1262
1263 mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0,
1264 this, SLOT( mailVCard() ),
1265 actionCollection(), "file_mail_vcard");
1266
1267 mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0,
1268 this, SLOT( editContact2() ),
1269 actionCollection(), "file_properties" );
1270
1271#ifdef KAB_EMBEDDED
1272 // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() );
1273 mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0,
1274 mMainWindow, SLOT( exit() ),
1275 actionCollection(), "quit" );
1276#endif //KAB_EMBEDDED
1277
1278 // edit menu
1279 if ( mIsPart ) {
1280 mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this,
1281 SLOT( copyContacts() ), actionCollection(),
1282 "kaddressbook_copy" );
1283 mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this,
1284 SLOT( cutContacts() ), actionCollection(),
1285 "kaddressbook_cut" );
1286 mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this,
1287 SLOT( pasteContacts() ), actionCollection(),
1288 "kaddressbook_paste" );
1289 mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this,
1290 SLOT( selectAllContacts() ), actionCollection(),
1291 "kaddressbook_select_all" );
1292 mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this,
1293 SLOT( undo() ), actionCollection(),
1294 "kaddressbook_undo" );
1295 mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z,
1296 this, SLOT( redo() ), actionCollection(),
1297 "kaddressbook_redo" );
1298 } else {
1299 mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() );
1300 mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() );
1301 mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() );
1302 mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() );
1303 mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() );
1304 mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() );
1305 }
1306
1307 mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete",
1308 Key_Delete, this, SLOT( deleteContacts() ),
1309 actionCollection(), "edit_delete" );
1310
1311 mActionUndo->setEnabled( false );
1312 mActionRedo->setEnabled( false );
1313
1314 // settings menu
1315#ifdef KAB_EMBEDDED
1316//US special menuentry to configure the addressbook resources. On KDE
1317// you do that through the control center !!!
1318 mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this,
1319 SLOT( configureResources() ), actionCollection(),
1320 "kaddressbook_configure_resources" );
1321#endif //KAB_EMBEDDED
1322
1323 if ( mIsPart ) {
1324 mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this,
1325 SLOT( openConfigDialog() ), actionCollection(),
1326 "kaddressbook_configure" );
1327
1328 mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0,
1329 this, SLOT( configureKeyBindings() ), actionCollection(),
1330 "kaddressbook_configure_shortcuts" );
1331#ifdef KAB_EMBEDDED
1332 mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() );
1333#endif //KAB_EMBEDDED
1334
1335 } else {
1336 mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() );
1337
1338 mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() );
1339 }
1340
1341 mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0,
1342 actionCollection(), "options_show_jump_bar" );
1343 connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) );
1344
1345 mActionDetails = new KToggleAction( i18n( "Show Details" ), 0, 0,
1346 actionCollection(), "options_show_details" );
1347 connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) );
1348
1349 // misc
1350 // only enable LDAP lookup if we can handle the protocol
1351#ifndef KAB_EMBEDDED
1352 if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) {
1353 new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0,
1354 this, SLOT( openLDAPDialog() ), actionCollection(),
1355 "ldap_lookup" );
1356 }
1357#else //KAB_EMBEDDED
1358 //qDebug("KABCore::initActions() LDAP has to be implemented");
1359#endif //KAB_EMBEDDED
1360
1361
1362 mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this,
1363 SLOT( setWhoAmI() ), actionCollection(),
1364 "set_personal" );
1365
1366 mActionCategories = new KAction( i18n( "Set Categories" ), 0, this,
1367 SLOT( setCategories() ), actionCollection(),
1368 "edit_set_categories" );
1369
1370#ifdef KAB_EMBEDDED
1371
1372 mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0,
1373 this, SLOT( createAboutData() ), actionCollection(),
1374 "kaddressbook_about_data" );
1375#endif //KAB_EMBEDDED
1376
1377 clipboardDataChanged();
1378 connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
1379 connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
1380}
1381
1382//US we need this function, to plug all actions into the correct menues.
1383// KDE uses a XML format to plug the actions, but we work her without this overhead.
1384void KABCore::addActionsManually()
1385{
1386//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
1387
1388#ifdef KAB_EMBEDDED
1389 QPopupMenu *fileMenu = new QPopupMenu( this );
1390 QPopupMenu *editMenu = new QPopupMenu( this );
1391 QPopupMenu *helpMenu = new QPopupMenu( this );
1392
1393 KToolBar* tb = mMainWindow->toolBar();
1394
1395#ifdef DESKTOP_VERSION
1396 QMenuBar* mb = mMainWindow->menuBar();
1397
1398 //US setup menubar.
1399 //Disable the following block if you do not want to have a menubar.
1400 mb->insertItem( "&File", fileMenu );
1401 mb->insertItem( "&Edit", editMenu );
1402 mb->insertItem( "&View", viewMenu );
1403 mb->insertItem( "&Settings", settingsMenu );
1404 mb->insertItem( "&Help", helpMenu );
1405 mIncSearchWidget = new IncSearchWidget( tb );
1406 // tb->insertWidget(-1, 0, mIncSearchWidget);
1407
1408#else
1409 //US setup toolbar
1410 QMenuBar *menuBarTB = new QMenuBar( tb );
1411 QPopupMenu *popupBarTB = new QPopupMenu( this );
1412 menuBarTB->insertItem( "ME", popupBarTB);
1413 tb->insertWidget(-1, 0, menuBarTB);
1414 mIncSearchWidget = new IncSearchWidget( tb );
1415
1416 tb->enableMoving(false);
1417 popupBarTB->insertItem( "&File", fileMenu );
1418 popupBarTB->insertItem( "&Edit", editMenu );
1419 popupBarTB->insertItem( "&View", viewMenu );
1420 popupBarTB->insertItem( "&Settings", settingsMenu );
1421 mViewManager->getFilterAction()->plug ( popupBarTB);
1422 popupBarTB->insertItem( "&Help", helpMenu );
1423 if (QApplication::desktop()->width() > 320 ) {
1424 // mViewManager->getFilterAction()->plug ( tb);
1425 }
1426#endif
1427 // mActionQuit->plug ( mMainWindow->toolBar());
1428
1429
1430
1431 //US Now connect the actions with the menue entries.
1432 mActionPrint->plug( fileMenu );
1433 mActionMail->plug( fileMenu );
1434 fileMenu->insertSeparator();
1435
1436 mActionNewContact->plug( fileMenu );
1437 mActionNewContact->plug( tb );
1438
1439 mActionEditAddressee->plug( fileMenu );
1440 fileMenu->insertSeparator();
1441 mActionSave->plug( fileMenu );
1442 fileMenu->insertItem( "&Import", ImportMenu );
1443 fileMenu->insertItem( "&Emport", ExportMenu );
1444 fileMenu->insertSeparator();
1445 mActionMailVCard->plug( fileMenu );
1446 fileMenu->insertSeparator();
1447 mActionQuit->plug( fileMenu );
1448
1449
1450 // edit menu
1451 mActionUndo->plug( editMenu );
1452 mActionRedo->plug( editMenu );
1453 editMenu->insertSeparator();
1454 mActionCut->plug( editMenu );
1455 mActionCopy->plug( editMenu );
1456 mActionPaste->plug( editMenu );
1457 mActionDelete->plug( editMenu );
1458 editMenu->insertSeparator();
1459 mActionSelectAll->plug( editMenu );
1460
1461
1462 // settings menu
1463//US special menuentry to configure the addressbook resources. On KDE
1464// you do that through the control center !!!
1465 mActionConfigResources->plug( settingsMenu );
1466 settingsMenu->insertSeparator();
1467
1468 mActionConfigKAddressbook->plug( settingsMenu );
1469
1470 if ( mIsPart ) {
1471 mActionConfigShortcuts->plug( settingsMenu );
1472 mActionConfigureToolbars->plug( settingsMenu );
1473
1474 } else {
1475 mActionKeyBindings->plug( settingsMenu );
1476 }
1477
1478 settingsMenu->insertSeparator();
1479
1480 mActionJumpBar->plug( settingsMenu );
1481 mActionDetails->plug( settingsMenu );
1482 settingsMenu->insertSeparator();
1483
1484 mActionWhoAmI->plug( settingsMenu );
1485 mActionCategories->plug( settingsMenu );
1486
1487 mActionAboutKAddressbook->plug( helpMenu );
1488
1489 if (QApplication::desktop()->width() > 320 ) {
1490
1491 mActionEditAddressee->plug( tb );
1492 mActionSave->plug( tb );
1493 mViewManager->getFilterAction()->plug ( tb);
1494 if (QApplication::desktop()->width() > 480 )
1495 mActionDelete->plug( tb );
1496 }
1497 mActionQuit->plug ( tb );
1498 // tb->insertWidget(-1, 0, mIncSearchWidget, 6);
1499
1500 //US link the searchwidget first to this.
1501 // The real linkage to the toolbar happens later.
1502//US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE);
1503//US tb->insertItem( mIncSearchWidget );
1504/*US
1505 mIncSearchWidget = new IncSearchWidget( tb );
1506 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1507 SLOT( incrementalSearch( const QString& ) ) );
1508
1509 mJumpButtonBar = new JumpButtonBar( this, this );
1510
1511//US topLayout->addWidget( mJumpButtonBar );
1512 this->layout()->add( mJumpButtonBar );
1513*/
1514
1515#endif //KAB_EMBEDDED
1516}
1517
1518
1519
1520void KABCore::clipboardDataChanged()
1521{
1522
1523 if ( mReadWrite )
1524 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() );
1525
1526}
1527
1528void KABCore::updateActionMenu()
1529{
1530 UndoStack *undo = UndoStack::instance();
1531 RedoStack *redo = RedoStack::instance();
1532
1533 if ( undo->isEmpty() )
1534 mActionUndo->setText( i18n( "Undo" ) );
1535 else
1536 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) );
1537
1538 mActionUndo->setEnabled( !undo->isEmpty() );
1539
1540 if ( !redo->top() )
1541 mActionRedo->setText( i18n( "Redo" ) );
1542 else
1543 mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) );
1544
1545 mActionRedo->setEnabled( !redo->isEmpty() );
1546}
1547
1548void KABCore::configureKeyBindings()
1549{
1550#ifndef KAB_EMBEDDED
1551 KKeyDialog::configure( actionCollection(), true );
1552#else //KAB_EMBEDDED
1553 qDebug("KABCore::configureKeyBindings() not implemented");
1554#endif //KAB_EMBEDDED
1555}
1556
1557#ifdef KAB_EMBEDDED
1558void KABCore::configureResources()
1559{
1560 KRES::KCMKResources dlg( this, "" , 0 );
1561
1562 if ( !dlg.exec() )
1563 return;
1564}
1565#endif //KAB_EMBEDDED
1566
1567
1568
1569#ifndef KAB_EMBEDDED
1570#include "kabcore.moc"
1571#endif //KAB_EMBEDDED
diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h
new file mode 100644
index 0000000..edf98c2
--- a/dev/null
+++ b/kaddressbook/kabcore.h
@@ -0,0 +1,421 @@
1/*
2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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#ifndef KABCORE_H
25#define KABCORE_H
26
27#include <kabc/field.h>
28
29#ifndef KAB_EMBEDDED
30#endif //KAB_EMBEDDED
31#include <qdict.h>
32
33#include <qwidget.h>
34#include <qpopupmenu.h>
35
36namespace KABC {
37class AddressBook;
38}
39
40#ifndef KAB_EMBEDDED
41class KAboutData;
42class KConfig;
43
44class KAddressBookService;
45class LDAPSearchDialog;
46#else //KAB_EMBEDDED
47class KAddressBookMain;
48//US class QAction;
49#endif //KAB_EMBEDDED
50class KCMultiDialog;
51class KXMLGUIClient;
52class ExtensionManager;
53class XXPortManager;
54class JumpButtonBar;
55class IncSearchWidget;
56class KDGanttMinimizeSplitter;
57class KAction;
58class KActionCollection;
59class KToggleAction;
60
61class QAction;
62class QMenuBar;
63class QSplitter;
64class ViewContainer;
65class ViewManager;
66class AddresseeEditorDialog;
67
68class KABCore : public QWidget
69{
70 Q_OBJECT
71
72 public:
73 KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name = 0 );
74
75
76 ~KABCore();
77
78
79#ifdef KAB_EMBEDDED
80 //US added functionality
81 QPopupMenu* getViewMenu() {return viewMenu;}
82 QPopupMenu* getFilterMenu() {return filterMenu;}
83 QPopupMenu* getSettingsMenu() {return settingsMenu;}
84 void addActionsManually();
85#endif //KAB_EMBEDDED
86 /**
87 Restores the global settings.
88 */
89 void restoreSettings();
90
91 /**
92 Saves the global settings.
93 */
94 void saveSettings();
95
96 /**
97 Returns a pointer to the StdAddressBook of the application.
98 */
99 KABC::AddressBook *addressBook() const;
100
101 /**
102 Returns a pointer to the KConfig object of the application.
103 */
104 static KConfig *config();
105
106 /**
107 Returns a pointer to the global KActionCollection object. So
108 other classes can register their actions easily.
109 */
110 KActionCollection *actionCollection() const;
111
112 /**
113 Returns the current search field of the Incremental Search Widget.
114 */
115 KABC::Field *currentSearchField() const;
116
117 /**
118 Returns the uid list of the currently selected contacts.
119 */
120 QStringList selectedUIDs() const;
121
122 /**
123 Displays the ResourceSelectDialog and returns the selected
124 resource or a null pointer if no resource was selected by
125 the user.
126 */
127 KABC::Resource *requestResource( QWidget *parent );
128
129#ifndef KAB_EMBEDDED
130 static KAboutData *createAboutData();
131#endif //KAB_EMBEDDED
132
133#ifdef KAB_EMBEDDED
134 inline QPopupMenu* getImportMenu() { return ImportMenu;}
135 inline QPopupMenu* getExportMenu() { return ExportMenu;}
136#endif //KAB_EMBEDDED
137
138 public slots:
139#ifdef KAB_EMBEDDED
140 void createAboutData();
141#endif //KAB_EMBEDDED
142
143 void statusMessage(QString, int time = 0 );
144 /**
145 Is called whenever a contact is selected in the view.
146 */
147 void setContactSelected( const QString &uid );
148
149 /**
150 Opens the preferred mail composer with all selected contacts as
151 arguments.
152 */
153 void sendMail();
154
155 /**
156 Opens the preferred mail composer with the given contacts as
157 arguments.
158 */
159 void sendMail( const QString& email );
160
161
162 void mailVCard();
163 void mailVCard(const QStringList& uids);
164
165 /**
166 Starts the preferred web browser with the given URL as argument.
167 */
168 void browse( const QString& url );
169
170 /**
171 Select all contacts in the view.
172 */
173 void selectAllContacts();
174
175 /**
176 Deletes all selected contacts from the address book.
177 */
178 void deleteContacts();
179
180 /**
181 Deletes given contacts from the address book.
182
183 @param uids The uids of the contacts, which shall be deleted.
184 */
185 void deleteContacts( const QStringList &uids );
186
187 /**
188 Copys the selected contacts into clipboard for later pasting.
189 */
190 void copyContacts();
191
192 /**
193 Cuts the selected contacts and stores them for later pasting.
194 */
195 void cutContacts();
196
197 /**
198 Paste contacts from clipboard into the address book.
199 */
200 void pasteContacts();
201
202 /**
203 Paste given contacts into the address book.
204
205 @param list The list of addressee, which shall be pasted.
206 */
207 void pasteContacts( KABC::Addressee::List &list );
208
209 /**
210 Sets the whoAmI contact, that is used by many other programs to
211 get personal information about the current user.
212 */
213 void setWhoAmI();
214
215 /**
216 Displays the category dialog and applies the result to all
217 selected contacts.
218 */
219 void setCategories();
220
221 /**
222 Sets the field list of the Incremental Search Widget.
223 */
224 void setSearchFields( const KABC::Field::List &fields );
225
226 /**
227 Search with the current search field for a contact, that matches
228 the given text, and selects it in the view.
229 */
230 void incrementalSearch( const QString& text );
231
232 /**
233 Marks the address book as modified.
234 */
235 void setModified();
236 /**
237 Marks the address book as modified without refreshing the view.
238 */
239 void setModifiedWOrefresh();
240
241 /**
242 Marks the address book as modified concerning the argument.
243 */
244 void setModified( bool modified );
245
246 /**
247 Returns whether the address book is modified.
248 */
249 bool modified() const;
250
251 /**
252 Called whenever an contact is modified in the contact editor
253 dialog or the quick edit.
254 */
255 void contactModified( const KABC::Addressee &addr );
256
257 /**
258 DCOP METHODS.
259 */
260 void addEmail( QString addr );
261 void importVCard( const KURL& url, bool showPreview );
262 void importVCard( const QString& vCard, bool showPreview );
263 void newContact();
264 QString getNameByPhone( const QString& phone );
265 /**
266 END DCOP METHODS
267 */
268
269 /**
270 Saves the contents of the AddressBook back to disk.
271 */
272 void save();
273
274 /**
275 Undos the last command using the undo stack.
276 */
277 void undo();
278
279 /**
280 Redos the last command that was undone, using the redo stack.
281 */
282 void redo();
283
284 /**
285 Shows the edit dialog for the given uid. If the uid is QString::null,
286 the method will try to find a selected addressee in the view.
287 */
288 void editContact( const QString &uid /*US = QString::null*/ );
289//US added a second method without defaultparameter
290 void editContact2();
291
292 /**
293 Launches the configuration dialog.
294 */
295 void openConfigDialog();
296
297 /**
298 Launches the ldap search dialog.
299 */
300 void openLDAPDialog();
301
302 /**
303 Creates a KAddressBookPrinter, which will display the print
304 dialog and do the printing.
305 */
306 void print();
307
308 /**
309 Registers a new GUI client, so plugins can register its actions.
310 */
311 void addGUIClient( KXMLGUIClient *client );
312
313 signals:
314 void contactSelected( const QString &name );
315 void contactSelected( const QPixmap &pixmap );
316 public slots:
317 void setDetailsVisible( bool visible );
318 void setDetailsToState();
319 private slots:
320 void setJumpButtonBarVisible( bool visible );
321
322 void extensionModified( const KABC::Addressee::List &list );
323 void clipboardDataChanged();
324 void updateActionMenu();
325 void configureKeyBindings();
326#ifdef KAB_EMBEDDED
327 void configureResources();
328#endif //KAB_EMBEDDED
329
330 void slotEditorDestroyed( const QString &uid );
331 void configurationChanged();
332 void addressBookChanged();
333
334 private:
335 void initGUI();
336 void initActions();
337
338 AddresseeEditorDialog *createAddresseeEditorDialog( QWidget *parent,
339 const char *name = 0 );
340
341 KXMLGUIClient *mGUIClient;
342
343 KABC::AddressBook *mAddressBook;
344
345 ViewManager *mViewManager;
346 // QSplitter *mDetailsSplitter;
347 //QSplitter *mExtensionBarSplitter;
348 ViewContainer *mDetails;
349 KDGanttMinimizeSplitter* mMiniSplitter;
350 XXPortManager *mXXPortManager;
351 JumpButtonBar *mJumpButtonBar;
352 IncSearchWidget *mIncSearchWidget;
353 ExtensionManager *mExtensionManager;
354
355 KCMultiDialog *mConfigureDialog;
356
357#ifndef KAB_EMBEDDED
358
359 KCMultiDialog *mConfigureDialog;
360 LDAPSearchDialog *mLdapSearchDialog;
361#endif //KAB_EMBEDDED
362 QDict<AddresseeEditorDialog> mEditorDict;
363
364 bool mReadWrite;
365 bool mModified;
366 bool mIsPart;
367
368 //US file menu
369 KAction *mActionMail;
370 KAction* mActionPrint;
371 KAction* mActionNewContact;
372 KAction *mActionSave;
373 KAction *mActionEditAddressee;
374 KAction *mActionMailVCard;
375 KAction *mActionQuit;
376
377 //US edit menu
378 KAction *mActionCopy;
379 KAction *mActionCut;
380 KAction *mActionPaste;
381 KAction *mActionSelectAll;
382 KAction *mActionUndo;
383 KAction *mActionRedo;
384 KAction *mActionDelete;
385
386 //US settings menu
387 KAction *mActionConfigResources;
388 KAction *mActionConfigKAddressbook;
389 KAction *mActionConfigShortcuts;
390 KAction *mActionConfigureToolbars;
391 KAction *mActionKeyBindings;
392 KToggleAction *mActionJumpBar;
393 KToggleAction *mActionDetails;
394 KAction *mActionWhoAmI;
395 KAction *mActionCategories;
396 KAction *mActionAboutKAddressbook;
397
398 KAction *mActionDeleteView;
399
400 QPopupMenu *viewMenu;
401 QPopupMenu *filterMenu;
402 QPopupMenu *settingsMenu;
403
404//US QAction *mActionSave;
405 QPopupMenu *ImportMenu;
406 QPopupMenu *ExportMenu;
407
408#ifndef KAB_EMBEDDED
409 KAddressBookService *mAddressBookService;
410#endif //KAB_EMBEDDED
411
412 class KABCorePrivate;
413 KABCorePrivate *d;
414
415#ifdef KAB_EMBEDDED
416 KAddressBookMain *mMainWindow; // should be the same like mGUIClient
417#endif //KAB_EMBEDDED
418
419};
420
421#endif
diff --git a/kaddressbook/kabprefs.cpp b/kaddressbook/kabprefs.cpp
new file mode 100644
index 0000000..5b3b1ab
--- a/dev/null
+++ b/kaddressbook/kabprefs.cpp
@@ -0,0 +1,127 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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//US#ifdef KAB_EMBEDDED
25//#include <qstring.h>
26//#endif //KAB_EMBEDDED
27
28
29#include <kconfig.h>
30#include <klocale.h>
31#include <kstaticdeleter.h>
32//US#include <kdebug.h> // defines kdDebug()
33
34#include "kabprefs.h"
35
36KABPrefs *KABPrefs::sInstance = 0;
37static KStaticDeleter<KABPrefs> staticDeleter;
38
39KABPrefs::KABPrefs()
40 : KPimPrefs("kaddressbookrc")
41{
42 KPrefs::setCurrentGroup( "Views" );
43 addItemBool( "HonorSingleClick", &mHonorSingleClick, false );
44
45 KPrefs::setCurrentGroup( "General" );
46 addItemBool( "AutomaticNameParsing", &mAutomaticNameParsing, true );
47 addItemInt( "CurrentIncSearchField", &mCurrentIncSearchField, 0 );
48
49#ifdef KAB_EMBEDDED
50 addItemBool("AskForQuit",&mAskForQuit,false);
51 addItemBool("ToolBarHor",&mToolBarHor, true );
52 addItemBool("ToolBarUp",&mToolBarUp, false );
53#endif //KAB_EMBEDDED
54
55 KPrefs::setCurrentGroup( "MainWindow" );
56 addItemBool( "JumpButtonBarVisible", &mJumpButtonBarVisible, false );
57 addItemBool( "DetailsPageVisible", &mDetailsPageVisible, true );
58 addItemIntList( "ExtensionsSplitter", &mExtensionsSplitter );
59 addItemIntList( "DetailsSplitter", &mDetailsSplitter );
60
61 KPrefs::setCurrentGroup( "Extensions_General" );
62 QStringList defaultExtensions;
63 defaultExtensions << "merge";
64 defaultExtensions << "distribution_list_editor";
65 addItemInt( "CurrentExtension", &mCurrentExtension, 0 );
66 addItemStringList( "ActiveExtensions", &mActiveExtensions, defaultExtensions );
67
68 KPrefs::setCurrentGroup( "Views" );
69 QString defaultView = i18n( "Default Table View" );
70 addItemString( "CurrentView", &mCurrentView, defaultView );
71 addItemStringList( "ViewNames", &mViewNames, defaultView );
72
73 KPrefs::setCurrentGroup( "Filters" );
74 addItemInt( "CurrentFilter", &mCurrentFilter, 0 );
75
76}
77
78KABPrefs::~KABPrefs()
79{
80}
81
82KABPrefs *KABPrefs::instance()
83{
84 if ( !sInstance ) {
85#ifdef KAB_EMBEDDED
86 sInstance = staticDeleter.setObject( new KABPrefs() );
87#else //KAB_EMBEDDED
88 //US the following line has changed ???. Why
89 staticDeleter.setObject( sInstance, new KABPrefs() );
90#endif //KAB_EMBEDDED
91 sInstance->readConfig();
92 }
93
94 return sInstance;
95}
96
97void KABPrefs::setCategoryDefaults()
98{
99 mCustomCategories.clear();
100
101 mCustomCategories << i18n( "Business" ) << i18n( "Family" ) << i18n( "School" )
102 << i18n( "Customer" ) << i18n( "Friend" );
103}
104
105 // US introduce a nonconst way to return the config object.
106KConfig* KABPrefs::getConfig()
107{
108 return config();
109}
110
111
112/*US
113void KABPrefs::usrSetDefaults()
114{
115 KPimPrefs::usrSetDefaults();
116}
117
118void KABPrefs::usrReadConfig()
119{
120 KPimPrefs::usrReadConfig();
121}
122
123void KABPrefs::usrWriteConfig()
124{
125 KPimPrefs::usrWriteConfig();
126}
127*/
diff --git a/kaddressbook/kabprefs.h b/kaddressbook/kabprefs.h
new file mode 100644
index 0000000..370fc5b
--- a/dev/null
+++ b/kaddressbook/kabprefs.h
@@ -0,0 +1,88 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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#ifndef KABPREFS_H
25#define KABPREFS_H
26
27#include <qstringlist.h>
28
29#include <libkdepim/kpimprefs.h>
30
31class KConfig;
32
33class KABPrefs : public KPimPrefs
34{
35 public:
36 virtual ~KABPrefs();
37
38 static KABPrefs *instance();
39
40 // General
41 bool mHonorSingleClick;
42 bool mAutomaticNameParsing;
43 int mCurrentIncSearchField;
44
45#ifdef KAB_EMBEDDED
46 // US introduce a nonconst way to return the config object.
47 KConfig* getConfig();
48
49 bool mToolBarHor;
50 bool mToolBarUp;
51 bool mAskForQuit;
52 /** Set preferences to default values */
53// void usrSetDefaults();
54
55 /** Read preferences from config file */
56// void usrReadConfig();
57
58 /** Write preferences to config file */
59// void usrWriteConfig();
60#endif //KAB_EMBEDDED
61
62
63 // GUI
64 bool mJumpButtonBarVisible;
65 bool mDetailsPageVisible;
66 QValueList<int> mExtensionsSplitter;
67 QValueList<int> mDetailsSplitter;
68
69 // Extensions stuff
70 int mCurrentExtension;
71 QStringList mActiveExtensions;
72
73 // Views stuff
74 QString mCurrentView;
75 QStringList mViewNames;
76
77 // Filter
78 int mCurrentFilter;
79
80 void setCategoryDefaults();
81
82 private:
83 KABPrefs();
84
85 static KABPrefs *sInstance;
86};
87
88#endif
diff --git a/kaddressbook/kaddressbook.desktop b/kaddressbook/kaddressbook.desktop
new file mode 100644
index 0000000..9cee2aa
--- a/dev/null
+++ b/kaddressbook/kaddressbook.desktop
@@ -0,0 +1,8 @@
1[Desktop Entry]
2Comment = KAddressbook
3Display = 640x480/144dpi,480x640/144dpi
4Exec = kapi
5Icon = kdepim/kaddressbook/kaddressbook
6Name = KA/Pi
7Type = Application
8CanFastload = 1
diff --git a/kaddressbook/kaddressbook.pro b/kaddressbook/kaddressbook.pro
new file mode 100644
index 0000000..761c3e7
--- a/dev/null
+++ b/kaddressbook/kaddressbook.pro
@@ -0,0 +1,166 @@
1 TEMPLATE= app
2 CONFIG = qt warn_on
3 TARGET = kapi
4DESTDIR= ../bin
5
6include( ../variables.pri )
7
8
9INCLUDEPATH += . ./details ./features ./kcmconfigs ./xxport ../microkde ../microkde/kdecore ../microkde/kutils ../microkde/kio/kfile ../microkde/kdeui ../kabc ../ interfaces
10DEFINES += KAB_EMBEDDED KAB_NOSPLITTER DESKTOP_VERSION
11
12unix : {
13LIBS += ../bin/libmicrokdepim.so
14LIBS += ../bin/libmicrokde.so
15LIBS += ../bin/libmicrokabc.so
16LIBS += ../bin/libmicrokcal.so
17LIBS += -lldap
18OBJECTS_DIR = obj/unix
19MOC_DIR = moc/unix
20}
21win32: {
22DEFINES += _WIN32_
23LIBS += ../bin/microkdepim.lib
24LIBS += ../bin/microkcal.lib
25LIBS += ../bin/microkde.lib
26LIBS += ../bin/microkabc.lib
27QMAKE_LINK += /NODEFAULTLIB:LIBC
28OBJECTS_DIR = obj/win
29MOC_DIR = moc/win
30}
31
32
33
34
35
36
37
38
39INTERFACES = \
40# filteredit_base.ui \
41# kofilterview_base.ui \
42
43HEADERS = \
44features/mergewidget.h \
45features/distributionlistwidget.h \
46kcmconfigs/addresseewidget.h \
47kcmconfigs/extensionconfigdialog.h \
48kcmconfigs/kcmkabconfig.h \
49kcmconfigs/kabconfigwidget.h \
50addresseeeditordialog.h \
51addresseeeditorwidget.h \
52addresseditwidget.h \
53addresseeconfig.h \
54addresseeutil.h \
55emaileditwidget.h \
56filtereditdialog.h \
57kaddressbookmain.h \
58kabprefs.h \
59kabcore.h \
60viewmanager.h \
61extensionmanager.h \
62extensionwidget.h \
63kaddressbookview.h \
64geowidget.h \
65imagewidget.h \
66incsearchwidget.h \
67jumpbuttonbar.h \
68phoneeditwidget.h \
69secrecywidget.h \
70keywidget.h \
71nameeditdialog.h \
72filter.h \
73addviewdialog.h \
74configurewidget.h \
75viewconfigurewidget.h \
76viewconfigurefieldspage.h \
77viewconfigurefilterpage.h \
78typecombo.h \
79undo.h \
80undocmds.h \
81xxportmanager.h \
82xxportobject.h \
83xxportselectdialog.h \
84details/detailsviewcontainer.h \
85details/look_basic.h \
86details/look_html.h \
87views/kaddressbookiconview.h \
88views/kaddressbooktableview.h \
89views/kaddressbookcardview.h \
90views/configuretableviewdialog.h \
91views/configurecardviewdialog.h \
92views/cardview.h \
93views/colorlistbox.h \
94views/contactlistview.h \
95xxport/vcard_xxport.h \
96xxport/kde2_xxport.h \
97xxport/csv_xxport.h \
98xxport/csvimportdialog.h \
99#details/look_details.h \
100#mainwindoiw.h \
101# alarmclient.h \
102# calendarview.h \
103# customlistviewitem.h \
104# datenavigator.h
105
106SOURCES = \
107addresseeeditordialog.cpp \
108addresseeeditorwidget.cpp \
109addresseditwidget.cpp \
110addresseeconfig.cpp \
111addresseeutil.cpp \
112extensionmanager.cpp \
113features/mergewidget.cpp \
114features/distributionlistwidget.cpp \
115kcmconfigs/addresseewidget.cpp \
116kcmconfigs/extensionconfigdialog.cpp \
117kcmconfigs/kcmkabconfig.cpp \
118kcmconfigs/kabconfigwidget.cpp \
119emaileditwidget.cpp \
120filtereditdialog.cpp \
121mainembedded.cpp \
122kaddressbookmain.cpp \
123kabcore.cpp \
124kabprefs.cpp \
125viewmanager.cpp \
126kaddressbookview.cpp \
127extensionwidget.cpp \
128geowidget.cpp \
129imagewidget.cpp \
130incsearchwidget.cpp \
131jumpbuttonbar.cpp \
132phoneeditwidget.cpp \
133secrecywidget.cpp \
134keywidget.cpp \
135nameeditdialog.cpp \
136filter.cpp \
137addviewdialog.cpp \
138configurewidget.cpp \
139viewconfigurewidget.cpp \
140viewconfigurefieldspage.cpp \
141viewconfigurefilterpage.cpp \
142undo.cpp \
143undocmds.cpp \
144xxportmanager.cpp \
145xxportobject.cpp \
146xxportselectdialog.cpp \
147details/detailsviewcontainer.cpp \
148details/look_basic.cpp \
149details/look_html.cpp \
150views/kaddressbookiconview.cpp \
151views/kaddressbooktableview.cpp \
152views/kaddressbookcardview.cpp \
153views/configuretableviewdialog.cpp \
154views/configurecardviewdialog.cpp \
155views/cardview.cpp \
156views/contactlistview.cpp \
157views/colorlistbox.cpp \
158xxport/vcard_xxport.cpp \
159xxport/kde2_xxport.cpp \
160xxport/csv_xxport.cpp \
161xxport/csvimportdialog.cpp \
162#details/look_details.cpp \
163#mainwindow.cpp \
164# calendarview.cpp \
165# timespanview.cpp
166
diff --git a/kaddressbook/kaddressbookE.pro b/kaddressbook/kaddressbookE.pro
new file mode 100644
index 0000000..577dbf9
--- a/dev/null
+++ b/kaddressbook/kaddressbookE.pro
@@ -0,0 +1,154 @@
1 TEMPLATE= app
2 CONFIG += qt warn_on
3
4
5 TARGET = kapi
6OBJECTS_DIR = obj/$(PLATFORM)
7MOC_DIR = moc/$(PLATFORM)
8DESTDIR=$(QPEDIR)/bin
9
10
11INCLUDEPATH += . ./details ./features ./kcmconfigs ./xxport ../microkde ../microkde/kdecore ../microkde/kutils ../microkde/kio/kfile ../microkde/kdeui ../kabc ../qtcompat ../ interfaces $(QPEDIR)/include
12DEFINES += KAB_EMBEDDED KAB_NOSPLITTER
13#DEFINES += KORG_NODND KORG_NOPLUGINS KORG_NOKABC KORG_NOARCHIVE KORG_NOMAIL
14#DEFINES += KORG_NOPRINTER KORG_NODCOP KORG_NOKALARMD KORG_NORESOURCEVIEW KORG_NOSPLITTER
15#DEFINES += KORG_NOLVALTERNATION
16LIBS += -lmicrokdepim
17#LIBS += -lmicrokcal
18LIBS += -lmicrokde
19LIBS += -lmicrokcal
20LIBS += -lmicroqtcompat
21LIBS += -lmicrokabc
22LIBS += -lqpe
23LIBS += -ljpeg
24LIBS += $(QTOPIALIB)
25LIBS += -L$(QPEDIR)/lib
26
27INTERFACES = \
28# filteredit_base.ui \
29# kofilterview_base.ui \
30
31HEADERS = \
32features/mergewidget.h \
33features/distributionlistwidget.h \
34kcmconfigs/addresseewidget.h \
35kcmconfigs/extensionconfigdialog.h \
36kcmconfigs/kcmkabconfig.h \
37kcmconfigs/kabconfigwidget.h \
38addresseeeditordialog.h \
39addresseeeditorwidget.h \
40addresseditwidget.h \
41addresseeconfig.h \
42addresseeutil.h \
43emaileditwidget.h \
44filtereditdialog.h \
45kaddressbookmain.h \
46kabprefs.h \
47kabcore.h \
48viewmanager.h \
49extensionmanager.h \
50extensionwidget.h \
51kaddressbookview.h \
52geowidget.h \
53imagewidget.h \
54incsearchwidget.h \
55jumpbuttonbar.h \
56phoneeditwidget.h \
57secrecywidget.h \
58keywidget.h \
59nameeditdialog.h \
60filter.h \
61addviewdialog.h \
62configurewidget.h \
63viewconfigurewidget.h \
64viewconfigurefieldspage.h \
65viewconfigurefilterpage.h \
66typecombo.h \
67undo.h \
68undocmds.h \
69xxportmanager.h \
70xxportobject.h \
71xxportselectdialog.h \
72details/detailsviewcontainer.h \
73details/look_basic.h \
74details/look_html.h \
75views/kaddressbookiconview.h \
76views/kaddressbooktableview.h \
77views/kaddressbookcardview.h \
78views/configuretableviewdialog.h \
79views/configurecardviewdialog.h \
80views/cardview.h \
81views/colorlistbox.h \
82views/contactlistview.h \
83xxport/vcard_xxport.h \
84xxport/kde2_xxport.h \
85xxport/csv_xxport.h \
86xxport/csvimportdialog.h \
87#details/look_details.h \
88#mainwindoiw.h \
89# alarmclient.h \
90# calendarview.h \
91# customlistviewitem.h \
92# datenavigator.h
93
94SOURCES = \
95addresseeeditordialog.cpp \
96addresseeeditorwidget.cpp \
97addresseditwidget.cpp \
98addresseeconfig.cpp \
99addresseeutil.cpp \
100extensionmanager.cpp \
101features/mergewidget.cpp \
102features/distributionlistwidget.cpp \
103kcmconfigs/addresseewidget.cpp \
104kcmconfigs/extensionconfigdialog.cpp \
105kcmconfigs/kcmkabconfig.cpp \
106kcmconfigs/kabconfigwidget.cpp \
107emaileditwidget.cpp \
108filtereditdialog.cpp \
109mainembedded.cpp \
110kaddressbookmain.cpp \
111kabcore.cpp \
112kabprefs.cpp \
113viewmanager.cpp \
114kaddressbookview.cpp \
115extensionwidget.cpp \
116geowidget.cpp \
117imagewidget.cpp \
118incsearchwidget.cpp \
119jumpbuttonbar.cpp \
120phoneeditwidget.cpp \
121secrecywidget.cpp \
122keywidget.cpp \
123nameeditdialog.cpp \
124filter.cpp \
125addviewdialog.cpp \
126configurewidget.cpp \
127viewconfigurewidget.cpp \
128viewconfigurefieldspage.cpp \
129viewconfigurefilterpage.cpp \
130undo.cpp \
131undocmds.cpp \
132xxportmanager.cpp \
133xxportobject.cpp \
134xxportselectdialog.cpp \
135details/detailsviewcontainer.cpp \
136details/look_basic.cpp \
137details/look_html.cpp \
138views/kaddressbookiconview.cpp \
139views/kaddressbooktableview.cpp \
140views/kaddressbookcardview.cpp \
141views/configuretableviewdialog.cpp \
142views/configurecardviewdialog.cpp \
143views/cardview.cpp \
144views/contactlistview.cpp \
145views/colorlistbox.cpp \
146xxport/vcard_xxport.cpp \
147xxport/kde2_xxport.cpp \
148xxport/csv_xxport.cpp \
149xxport/csvimportdialog.cpp \
150#details/look_details.cpp \
151#mainwindow.cpp \
152# calendarview.cpp \
153# timespanview.cpp
154
diff --git a/kaddressbook/kaddressbookmain.cpp b/kaddressbook/kaddressbookmain.cpp
new file mode 100644
index 0000000..92c32ca
--- a/dev/null
+++ b/kaddressbook/kaddressbookmain.cpp
@@ -0,0 +1,293 @@
1/*
2 This file is part of KAddressbook.
3 Copyright (c) 1999 Don Sanders <dsanders@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#ifdef KAB_EMBEDDED
25#include "kabprefs.h"
26#include <kglobal.h>
27#include <qmessagebox.h>
28#include <qtoolbar.h>
29#include <qapplication.h>
30#else //KAB_EMBEDDED
31#include <kedittoolbar.h>
32#include <kkeydialog.h>
33#include <kmessagebox.h>
34#include <kstatusbar.h>
35#endif //KAB_EMBEDDED
36#include <klocale.h>
37
38#include "kabcore.h"
39#include "kaddressbookmain.h"
40#include "kactioncollection.h"
41
42#ifdef KAB_EMBEDDED
43KAddressBookMain::KAddressBookMain() : KMainWindow( 0, "adrressbook" )
44#else //KAB_EMBEDDED
45//MOC_SKIP_BEGIN
46KAddressBookMain::KAddressBookMain() : DCOPObject( "KAddressBookIface" ), KMainWindow( 0 )
47//MOC_SKIP_END
48#endif //KAB_EMBEDDED
49{
50
51 setIcon(SmallIcon( "ka24" ) );
52#if 0
53 //US for embedded systems, create the toolbar before we initiate KABCore.
54 // KABCore will fill the toolbar with menues and icons
55 QMainWindow::ToolBarDock tbd;
56 tbd = Top;
57 iconToolBar = new QToolBar( this );
58 addToolBar (iconToolBar , tbd );
59 iconToolBar->setHorizontalStretchable(true);
60//US iconToolBar->setWidth(300);
61#endif // 0
62
63 mCore = new KABCore( this, true, this );
64
65#ifdef KAB_EMBEDDED
66 setCaption( i18n( "KAddressbook/Pi" ) );
67#else //KAB_EMBEDDED
68 setCaption( i18n( "Address Book Browser" ) );
69#endif //KAB_EMBEDDED
70
71 //mCore->restoreSettings();
72
73 initActions();
74
75 setCentralWidget( mCore );
76
77//US statusBar()->show();
78
79#ifndef KAB_EMBEDDED
80 setStandardToolBarMenuEnabled(true);
81
82 createGUI( "kaddressbookui.rc", false );
83
84
85#endif //KAB_EMBEDDED
86 setAutoSaveSettings();
87 qApp->processEvents();
88 mCore->restoreSettings();
89}
90
91KAddressBookMain::~KAddressBookMain()
92{
93 // mCore->saveSettings();
94}
95#ifndef DESKTOP_VERSION
96void KAddressBookMain::show ()
97{
98 static bool block = false;
99 if( block ) {
100 QWidget::show();
101 return;
102 } else {
103 block = true ;
104 QWidget::showFullScreen();
105 }
106 int min = 20;
107 if ( QApplication::desktop()->width() > 320 )
108 min += 20;
109 setGeometry( 0,0,QApplication::desktop()->width(), QApplication::desktop()->height() - min );
110 block = false;
111}
112#endif
113void KAddressBookMain::showMinimized ()
114{
115 QWidget::showMinimized () ;
116}
117void KAddressBookMain::addEmail( QString addr )
118{
119 mCore->addEmail( addr );
120}
121
122#ifndef KAB_EMBEDDED
123ASYNC KAddressBookMain::showContactEditor( QString uid )
124{
125 mCore->editContact( uid );
126}
127#endif //KAB_EMBEDDED
128void KAddressBookMain::newContact()
129{
130 mCore->newContact();
131}
132
133QString KAddressBookMain::getNameByPhone( QString phone )
134{
135 return mCore->getNameByPhone( phone );
136}
137
138void KAddressBookMain::save()
139{
140 mCore->save();
141}
142
143void KAddressBookMain::exit()
144{
145 close( );
146}
147
148void KAddressBookMain::saveProperties( KConfig* )
149{
150}
151
152void KAddressBookMain::readProperties( KConfig* )
153{
154}
155
156void KAddressBookMain::initActions()
157{
158#ifndef KAB_EMBEDDED
159 KStdAction::quit( this, SLOT( close() ), actionCollection() );
160 KStdAction::configureToolbars( this, SLOT( configureToolbars() ), actionCollection() );
161#else //KAB_EMBEDDED
162 //US: transfered the setup of the actions into KABCore
163#endif //KAB_EMBEDDED
164
165
166}
167
168//US new method to setup menues and toolbars on embedded systems
169#ifdef KAB_EMBEDDED
170/*
171QToolBar * KAddressBookMain::getIconToolBar()
172{
173 return iconToolBar;
174}
175*/
176
177void KAddressBookMain::createGUI()
178{
179
180
181
182}
183#endif //KAB_EMBEDDED
184
185void KAddressBookMain::configureToolbars()
186{
187#ifndef KAB_EMBEDDED
188 saveMainWindowSettings( KGlobal::config(), "MainWindow" );
189
190 KEditToolbar dlg( factory() );
191 connect( &dlg, SIGNAL( newToolbarConfig() ), SLOT( slotNewToolbarConfig() ) );
192
193 dlg.exec();
194#else //KAB_EMBEDDED
195 qDebug("KAddressBookMain::configureToolbars() not implemented by ulf" );
196#endif //KAB_EMBEDDED
197}
198
199void KAddressBookMain::slotNewToolbarConfig()
200{
201#ifndef KAB_EMBEDDED
202 applyMainWindowSettings( KGlobal::config(), "MainWindow" );
203#else //KAB_EMBEDDED
204 qDebug("KAddressBookMain::slotNewToolbarConfig() not implemented by ulf" );
205#endif //KAB_EMBEDDED
206}
207
208void KAddressBookMain::configureKeys()
209{
210#ifndef KAB_EMBEDDED
211 KKeyDialog::configureKeys( actionCollection(), xmlFile(), true, this );
212#else //KAB_EMBEDDED
213 qDebug("KAddressBookMain::configureKeys() not implemented by ulf" );
214#endif //KAB_EMBEDDED
215}
216
217void KAddressBookMain::closeEvent( QCloseEvent* ce )
218{
219 QString mess = i18n( "Close KA/Pi?");
220 if ( mCore->modified() )
221 mess += i18n( "\n\nChanges will be saved!");
222 else
223 mess += i18n( "\n\nNo unsaved changes detected!\nNothing will be saved!");
224
225 switch( QMessageBox::information( this, "KA/Pi", mess ,
226 i18n("Yes!"), i18n("No"), 0, 0 ) ) {
227 case 0:
228
229 break;
230 case 1:
231 return;
232 break;
233 case 2:
234 return;
235 break;
236
237 default:
238 return;
239 break;
240 }
241
242#if 0
243
244 if ( mCore->modified() ) {
245 QString text = i18n( "The address book has been modified.\nDo you want to save your changes?" );
246
247#ifndef KAB_EMBEDDED
248 int ret = KMessageBox::warningYesNoCancel( this, text, "",
249 KStdGuiItem::yes(),
250 KStdGuiItem::no(), "AskForSave" );
251 switch ( ret ) {
252 case KMessageBox::Yes:
253 save();
254 break;
255 case KMessageBox::No:
256 return true;
257 break;
258 default: //cancel
259 return ;
260 break;
261 }
262
263#else //KAB_EMBEDDED
264 switch( QMessageBox::information( this, "KA/Pi",
265 text,
266 i18n("Yes!"), i18n("No"), 0, 0 ) ) {
267 case 0:
268 save();
269 break;
270 case 1:
271 break;
272 case 2:
273 return;
274 default:
275 return;
276 break;
277 }
278#endif //KAB_EMBEDDED
279 }
280
281#endif
282
283 save();
284 mCore->saveSettings();
285 KABPrefs::instance()->writeConfig();
286 ce->accept();
287
288}
289
290#ifndef KAB_EMBEDDED
291#include "kaddressbookmain.moc"
292#endif //KAB_EMBEDDED
293
diff --git a/kaddressbook/kaddressbookmain.h b/kaddressbook/kaddressbookmain.h
new file mode 100644
index 0000000..81ae09c
--- a/dev/null
+++ b/kaddressbook/kaddressbookmain.h
@@ -0,0 +1,126 @@
1/*
2 This file is part of KAddressbook.
3 Copyright (c) 1999 Don Sanders <dsanders@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#ifndef KADDRESSBOOKMAIN_H
25#define KADDRESSBOOKMAIN_H
26
27#include <qptrlist.h>
28
29#ifdef KAB_EMBEDDED
30class QToolBar;
31#include <qaction.h>
32//#include <qmainwindow.h>
33#include <kmainwindow.h>
34#else //KAB_EMBEDDED
35#include <kaction.h>
36#include <kapplication.h>
37#include <kmainwindow.h>
38#include "kaddressbookiface.h"
39#endif //KAB_EMBEDDED
40
41class KABCore;
42class KConfig;
43
44/**
45 This class serves as the main window for KAddressBook. It handles the
46 menus, toolbars, and status bars.
47
48 @short Main window class
49 @author Don Sanders <dsanders@kde.org>
50 @version 0.1
51 */
52#ifdef KAB_EMBEDDED
53class KAddressBookMain : public KMainWindow
54#else //KAB_EMBEDDED
55//MOC_SKIP_BEGIN
56class KAddressBookMain : public KMainWindow, virtual public KAddressBookIface
57//MOC_SKIP_END
58#endif //KAB_EMBEDDED
59{
60 Q_OBJECT
61
62 public:
63 KAddressBookMain();
64 virtual ~KAddressBookMain();
65
66#ifdef KAB_EMBEDDED
67// QPEToolBar * getIconToolBar();
68 // QToolBar * getIconToolBar();
69#endif //KAB_EMBEDDED
70
71
72 public slots:
73#ifndef DESKTOP_VERSION
74 void show();
75#endif
76
77 void showMinimized () ;
78 virtual void addEmail( QString addr );
79#ifndef KAB_EMBEDDED
80//MOC_SKIP_BEGIN
81 virtual ASYNC showContactEditor( QString uid );
82//MOC_SKIP_END
83#endif //KAB_EMBEDDED
84 virtual void newContact();
85 virtual QString getNameByPhone( QString phone );
86 virtual void save();
87 virtual void exit();
88
89 protected:
90 void initActions();
91#ifdef KAB_EMBEDDED
92 //US new method to setup menues and toolbars on embedded systems
93 void createGUI();
94#endif //KAB_EMBEDDED
95
96 /**
97 This function is called when it is time for the app to save its
98 properties for session management purposes.
99 */
100 void saveProperties( KConfig* );
101
102 /**
103 This function is called when this app is restored. The KConfig
104 object points to the session management config file that was saved
105 with @ref saveProperties
106 */
107 void readProperties( KConfig* );
108
109 void closeEvent( QCloseEvent* ce );
110
111 protected slots:
112 void configureToolbars();
113 void configureKeys();
114
115 void slotNewToolbarConfig();
116
117 private:
118 KABCore *mCore;
119
120#ifdef KAB_EMBEDDED
121 // QToolBar *iconToolBar;
122#endif //KAB_EMBEDDED
123
124};
125
126#endif
diff --git a/kaddressbook/kaddressbookview.cpp b/kaddressbook/kaddressbookview.cpp
new file mode 100644
index 0000000..a44fd82
--- a/dev/null
+++ b/kaddressbook/kaddressbookview.cpp
@@ -0,0 +1,171 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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#ifndef KAB_EMBEDDED
25#include <qapplication.h>
26
27#include <kabc/distributionlistdialog.h>
28#include <kconfig.h>
29#include <klocale.h>
30
31#include "viewmanager.h"
32
33#endif //KAB_EMBEDDED
34#include <qlayout.h>
35
36#include <kabc/addressbook.h>
37#include <kdebug.h>
38
39#include "kaddressbookview.h"
40
41KAddressBookView::KAddressBookView( KABC::AddressBook *ab, QWidget *parent,
42 const char *name )
43 : QWidget( parent, name ), mAddressBook( ab ), mFieldList()
44{
45 initGUI();
46}
47
48KAddressBookView::~KAddressBookView()
49{
50 kdDebug(5720) << "KAddressBookView::~KAddressBookView: destroying - "
51 << name() << endl;
52}
53
54void KAddressBookView::readConfig( KConfig *config )
55{
56 mFieldList = KABC::Field::restoreFields( config, "KABCFields" );
57
58 if ( mFieldList.isEmpty() )
59 mFieldList = KABC::Field::defaultFields();
60
61 mDefaultFilterType = (DefaultFilterType)config->readNumEntry( "DefaultFilterType", 1 );
62 mDefaultFilterName = config->readEntry( "DefaultFilterName", QString::null );
63}
64
65void KAddressBookView::writeConfig( KConfig* )
66{
67 // Most of writing the config is handled by the ConfigureViewDialog
68}
69
70QString KAddressBookView::selectedEmails()
71{
72#ifndef KAB_EMBEDDED
73
74 bool first = true;
75 QString emailAddrs;
76 QStringList uidList = selectedUids();
77 KABC::Addressee addr;
78 QString email;
79
80 QStringList::Iterator it;
81 for ( it = uidList.begin(); it != uidList.end(); ++it ) {
82 addr = mAddressBook->findByUid( *it );
83
84 if ( !addr.isEmpty() ) {
85 QString m = QString::null;
86
87 if ( addr.emails().count() > 1 )
88 m = KABC::EmailSelector::getEmail( addr.emails(), addr.preferredEmail(), this );
89
90 email = addr.fullEmail( m );
91
92 if ( !first )
93 emailAddrs += ", ";
94 else
95 first = false;
96
97 emailAddrs += email;
98 }
99 }
100
101 return emailAddrs;
102#else //KAB_EMBEDDED
103qDebug("KAddressBookView::selectedEmails() update method");
104return 0;
105#endif //KAB_EMBEDDED
106
107}
108
109KABC::Addressee::List KAddressBookView::addressees()
110{
111 KABC::Addressee::List addresseeList;
112
113 KABC::AddressBook::Iterator it;
114 for (it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
115 if ( mFilter.filterAddressee( *it ) )
116 addresseeList.append( *it );
117 }
118
119 return addresseeList;
120}
121
122void KAddressBookView::initGUI()
123{
124 // Create the layout
125 QVBoxLayout *layout = new QVBoxLayout( this );
126
127 // Add the view widget
128 mViewWidget = new QWidget( this );
129 layout->addWidget( mViewWidget );
130}
131
132KABC::Field::List KAddressBookView::fields() const
133{
134 return mFieldList;
135}
136
137void KAddressBookView::setFilter( const Filter &filter )
138{
139 mFilter = filter;
140}
141
142KAddressBookView::DefaultFilterType KAddressBookView::defaultFilterType() const
143{
144 return mDefaultFilterType;
145}
146
147const QString &KAddressBookView::defaultFilterName() const
148{
149 return mDefaultFilterName;
150}
151
152KABC::AddressBook *KAddressBookView::addressBook() const
153{
154 return mAddressBook;
155}
156
157QWidget *KAddressBookView::viewWidget()
158{
159 return mViewWidget;
160}
161
162ViewConfigureWidget *ViewFactory::configureWidget( KABC::AddressBook *ab,
163 QWidget *parent,
164 const char *name )
165{
166 return new ViewConfigureWidget( ab, parent, name );
167}
168
169#ifndef KAB_EMBEDDED
170#include "kaddressbookview.moc"
171#endif //KAB_EMBEDDED
diff --git a/kaddressbook/kaddressbookview.h b/kaddressbook/kaddressbookview.h
new file mode 100644
index 0000000..7457080
--- a/dev/null
+++ b/kaddressbook/kaddressbookview.h
@@ -0,0 +1,295 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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#ifndef KADDRESSBOOKVIEW_H
25#define KADDRESSBOOKVIEW_H
26
27#ifndef KAB_EMBEDDED
28#include <klibloader.h>
29#endif //KAB_EMBEDDED
30
31class KConfig;
32class QDropEvent;
33
34#include <qstringlist.h>
35#include <kabc/field.h>
36#include <qwidget.h>
37
38#include "viewconfigurewidget.h"
39#include "filter.h"
40
41namespace KABC { class AddressBook; }
42
43/**
44 Base class for all views in kaddressbook. This class implements
45 all the common methods needed to provide a view to the user.
46
47 To implement a specific view (table, card, etc), just inherit from
48 this class and implement all the pure virtuals.
49
50 @author Mike Pilone <mpilone@slac.com>
51 */
52class KAddressBookView : public QWidget
53{
54 Q_OBJECT
55
56 public:
57 enum DefaultFilterType { None = 0, Active = 1, Specific = 2 };
58
59 KAddressBookView( KABC::AddressBook *ab, QWidget *parent, const char *name );
60 virtual ~KAddressBookView();
61
62 /**
63 Must be overloaded in subclasses. Should return a list of
64 all the uids of selected contacts.
65 */
66 virtual QStringList selectedUids() = 0;
67
68 /**
69 Called whenever this view should read the config. This can be used
70 as a sign that the config has changed, therefore the view should
71 assume the worst and rebuild itself if necessary. For example,
72 in a table view this method may be called when the user adds or
73 removes columns from the view.
74
75 If overloaded in the subclass, do not forget to call super class's
76 method.
77
78 @param config The KConfig object to read from. The group will already
79 be set, so do not change the group.
80 */
81 virtual void readConfig( KConfig *config );
82
83 /**
84 Called whenever this view should write the config. The view should not
85 write out information handled by the application, such as which fields
86 are visible. The view should only write out information specific
87 to itself (i.e.: All information in the ViewConfigWidget)
88
89 If overloaded in the subclass, do not forget to call the super class's
90 method.
91
92 @param config The KConfig object to read from. The group will already
93 be set, so do not change the group.
94 */
95 virtual void writeConfig( KConfig *config );
96
97 /**
98 Returns a QString with all the selected email addresses concatenated
99 together with a ',' seperator.
100 */
101 virtual QString selectedEmails();
102
103 /**
104 Return the type of the view: Icon, Table, etc. Please make sure that
105 this is the same value that ViewWrapper::type() will return for your
106 view.
107 */
108 virtual QString type() const = 0;
109
110 /**
111 Returns a list of the fields that should be displayed. The list
112 is composed of the fields proper names (ie: Home Address), so
113 the view may need to translate them in order to get the
114 value from the addressee.
115
116 This list is generated from the config file, so it is advisable to call
117 this method whenever a readConfig() is called in order to get the newest
118 list of fields.
119 */
120 KABC::Field::List fields() const;
121
122 /**
123 Sets the active filter. This filter will be used for filtering
124 the list of addressees to display. The view will <b>not</b>
125 automatically refresh itself, so in most cases you will want to call
126 KAddressBookView::refresh() after this method.
127 */
128 void setFilter( const Filter& );
129
130 /**
131 @return The default filter type selection. If the selection
132 is SpecificFilter, the name of the filter can be retrieved with
133 defaultFilterName()
134 */
135 DefaultFilterType defaultFilterType() const;
136
137 /**
138 @return The name of the default filter. This string is
139 only valid if defaultFilterType() is returning SpecificFilter.
140 */
141 const QString &defaultFilterName() const;
142
143 /**
144 @return The address book.
145 */
146 KABC::AddressBook *addressBook() const;
147
148 public slots:
149 /**
150 Must be overloaded in subclasses to refresh the view.
151 Refreshing includes updating the view to ensure that only items
152 in the document are visible. If <i>uid</i> is valid, only the
153 addressee with uid needs to be refreshed. This is an optimization
154 only.
155 */
156 virtual void refresh( QString uid = QString::null ) = 0;
157
158 /**
159 This method must be overloaded in subclasses. Select (highlight)
160 the addressee matching <i>uid</i>. If uid
161 is equal to QString::null, then all addressees should be selected.
162 */
163#ifndef KAB_EMBEDDED
164//MOC_SKIP_BEGIN
165 virtual void setSelected( QString uid = QString::null, bool selected = true ) = 0;
166//MOC_SKIP_END
167#else //KAB_EMBEDDED
168 //US my moc can not handle the default parameters. Is this a problem ???
169 virtual void setSelected( QString uid, bool selected) = 0;
170#endif //KAB_EMBEDDED
171
172 signals:
173 /**
174 This signal should be emitted by a subclass whenever an addressee
175 is modified.
176 */
177 void modified();
178
179 /**
180 This signal should be emitted by a subclass whenever an addressee
181 is selected. Selected means that the addressee was given the focus.
182 Some widgets may call this 'highlighted'. The view is responsible for
183 emitting this signal multiple times if multiple items are selected,
184 with the last item selected being the last emit.
185
186 @param uid The uid of the selected addressee.
187
188 @see KListView
189 */
190 void selected( const QString &uid );
191 void deleteRequest();
192 /**
193 This signal should be emitted by a subclass whenever an addressee
194 is executed. This is defined by the KDE system wide config, but it
195 either means single or doubleclicked.
196
197 @param ui The uid of the selected addressee
198
199 @see KListView
200 */
201 void executed( const QString &uid );
202
203 /**
204 This signal is emitted whenever a user attempts to start a drag
205 in the view. The slot connected to this signal would usually want
206 to create a QDragObject.
207 */
208 void startDrag();
209
210 /**
211 This signal is emitted whenever the user drops something on the
212 view. The individual view should handle checking if the item is
213 droppable (ie: if it is a vcard).
214 */
215 void dropped( QDropEvent* );
216
217 protected:
218 /**
219 Returns a list of the addressees that should be displayed. This method
220 should always be used by the subclass to get a list of addressees. This
221 method internally takes many factors into account, including the current
222 filter.
223 */
224 KABC::Addressee::List addressees();
225
226 /**
227 This method returns the widget that should be used as the parent for
228 all view components. By using this widget as the parent and not
229 'this', the view subclass has the option of placing other widgets
230 around the view (ie: search fields, etc). Do not delete this widget!
231 */
232 QWidget *viewWidget();
233
234 private:
235 void initGUI();
236
237 DefaultFilterType mDefaultFilterType;
238 Filter mFilter;
239 QString mDefaultFilterName;
240 KABC::AddressBook *mAddressBook;
241 KABC::Field::List mFieldList;
242
243 QWidget *mViewWidget;
244};
245
246#ifndef KAB_EMBEDDED
247//MOC_SKIP_BEGIN
248class ViewFactory : public KLibFactory
249//MOC_SKIP_END
250#else //KAB_EMBEDDED
251class ViewFactory
252#endif //KAB_EMBEDDED
253{
254
255 public:
256 virtual KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent,
257 const char *name = 0 ) = 0;
258
259 /**
260 @return The type of the view. This is normally a small one word
261 string (ie: Table, Icon, Tree, etc).
262 */
263 virtual QString type() const = 0;
264
265 /**
266 @return The description of the view. This should be a 3 to
267 4 line string (don't actually use return characters in the string)
268 describing the features offered by the view.
269 */
270 virtual QString description() const = 0;
271
272 /**
273 Creates a config dialog for the view type. The default
274 implementation will return a ViewConfigDialog. This default
275 dialog will allow the user to set the visible fields only. If
276 you need more config options (as most views will), this method
277 can be overloaded to return your sublcass of ViewConfigDialog.
278 If this method is over loaded the base classes method should
279 <B>not</B> be called.
280 */
281 virtual ViewConfigureWidget *configureWidget( KABC::AddressBook *ab,
282 QWidget *parent,
283 const char *name = 0 );
284
285 protected:
286 virtual QObject* createObject( QObject*, const char*, const char*,
287 const QStringList & )
288 {
289 return 0;
290 }
291
292};
293
294
295#endif
diff --git a/kaddressbook/kcmconfigs/addresseewidget.cpp b/kaddressbook/kcmconfigs/addresseewidget.cpp
new file mode 100644
index 0000000..0f3c353
--- a/dev/null
+++ b/kaddressbook/kcmconfigs/addresseewidget.cpp
@@ -0,0 +1,236 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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 <qgroupbox.h>
25#include <qlabel.h>
26#include <qlayout.h>
27#include <qlistbox.h>
28#include <qpushbutton.h>
29
30#include <kbuttonbox.h>
31#include <kcombobox.h>
32#include <kconfig.h>
33#include <kdialog.h>
34#include <klocale.h>
35#include <kglobal.h>
36#include <klineedit.h>
37#include <kstandarddirs.h>
38
39#include "addresseewidget.h"
40
41NamePartWidget::NamePartWidget( const QString &title, QWidget *parent,
42 const char *name )
43 : QWidget( parent, name )
44{
45 if (KGlobal::getOrientation() == KGlobal::Portrait)
46 {
47 QGridLayout* layout = new QGridLayout( this, 1, 1, KDialog::marginHintSmall(),
48 KDialog::spacingHintSmall() );
49
50 QLabel *label = new QLabel( i18n( title ), this );
51 layout->addWidget( label, 0, 1 );
52
53 mBox = new QListBox( this );
54 mBox->setMaximumSize(70, 70);
55 layout->addMultiCellWidget( mBox, 0, 1, 0, 0 );
56
57 KButtonBox *bbox = new KButtonBox( this, Qt::Vertical );
58 mAddButton = bbox->addButton( i18n( "Add" ), this, SLOT( add() ) );
59 mRemoveButton = bbox->addButton( i18n( "Rem" ), this, SLOT( remove() ) );
60 bbox->layout();
61 layout->addMultiCellWidget( bbox, 0, 2, 2,2);
62
63 mEdit = new KLineEdit( this );
64 layout->addWidget( mEdit, 1, 1 );
65 //mEdit->setMinimumWidth(50);
66
67// layout->addWidget( group );
68
69 }
70 else
71 {
72 QHBoxLayout *layout = new QHBoxLayout( this );
73
74 QGroupBox *group = new QGroupBox( 0, Qt::Vertical, title, this );
75 QGridLayout *groupLayout = new QGridLayout( group->layout(), 2, 2,
76 KDialog::spacingHint() );
77
78 mBox = new QListBox( group );
79
80 groupLayout->addWidget( mBox, 0, 0 );
81
82 KButtonBox *bbox = new KButtonBox( group, Qt::Vertical );
83 mAddButton = bbox->addButton( i18n( "Add" ), this, SLOT( add() ) );
84 mRemoveButton = bbox->addButton( i18n( "Remove" ), this, SLOT( remove() ) );
85 bbox->layout();
86 groupLayout->addWidget( bbox, 0, 1 );
87
88 mEdit = new KLineEdit( group );
89 groupLayout->addMultiCellWidget( mEdit, 1, 1, 0, 1 );
90
91 layout->addWidget( group );
92
93 }
94
95 mAddButton->setEnabled( false );
96 mRemoveButton->setEnabled( false );
97
98
99 connect( mBox, SIGNAL( selectionChanged( QListBoxItem* ) ),
100 SLOT( selectionChanged( QListBoxItem* ) ) );
101 connect( mEdit, SIGNAL( textChanged( const QString& ) ),
102 SLOT( textChanged( const QString& ) ) );
103 connect( mEdit, SIGNAL( returnPressed() ), SLOT( add() ) );
104
105}
106
107NamePartWidget::~NamePartWidget()
108{
109}
110
111void NamePartWidget::setNameParts( const QStringList &list )
112{
113 mBox->clear();
114 mBox->insertStringList( list );
115}
116
117QStringList NamePartWidget::nameParts() const
118{
119 QStringList parts;
120 for ( uint i = 0; i < mBox->count(); ++i )
121 parts.append( mBox->text( i ) );
122
123 return parts;
124}
125
126void NamePartWidget::add()
127{
128 if ( !mEdit->text().isEmpty() ) {
129 mBox->insertItem( mEdit->text() );
130 emit modified();
131 }
132
133 mEdit->setText( "" );
134}
135
136void NamePartWidget::remove()
137{
138 mBox->removeItem( mBox->currentItem() );
139 if ( mBox->count() == 0 )
140 selectionChanged( 0 );
141
142 emit modified();
143}
144
145void NamePartWidget::selectionChanged( QListBoxItem *item )
146{
147 mRemoveButton->setEnabled( item != 0 );
148}
149
150void NamePartWidget::textChanged( const QString& text )
151{
152 mAddButton->setEnabled( !text.isEmpty() );
153}
154
155
156AddresseeWidget::AddresseeWidget( QWidget *parent, const char *name )
157 : QWidget( parent, name )
158{
159 QGridLayout *layout;
160
161 mPrefix = new NamePartWidget( i18n( "Prefixes" ), this );
162 mInclusion = new NamePartWidget( i18n( "Inclusions" ), this );
163 mSuffix = new NamePartWidget( i18n( "Suffixes" ), this );
164 QLabel *label = new QLabel( i18n( "Default formatted name:" ), this );
165
166 mFormattedNameCombo = new KComboBox( this );
167 mFormattedNameCombo->insertItem( i18n( "Empty" ) );
168 mFormattedNameCombo->insertItem( i18n( "Simple Name" ) );
169 mFormattedNameCombo->insertItem( i18n( "Full Name" ) );
170 mFormattedNameCombo->insertItem( i18n( "Reverse Name" ) );
171
172 if (KGlobal::getOrientation() == KGlobal::Portrait)
173 {
174 layout = new QGridLayout( this, 4, 2, KDialog::marginHint(),
175 KDialog::spacingHint() );
176
177 layout->addMultiCellWidget( mPrefix, 0, 0, 0, 1 );
178 layout->addMultiCellWidget( mInclusion, 1, 1, 0, 1 );
179 layout->addMultiCellWidget( mSuffix, 2, 2, 0, 1 );
180 layout->addWidget( label, 3, 0 );
181 layout->addWidget( mFormattedNameCombo, 3, 1 );
182
183 }
184 else
185 {
186 layout = new QGridLayout( this, 2, 3, KDialog::marginHint(),
187 KDialog::spacingHint() );
188
189 layout->addWidget( mPrefix, 0, 0 );
190 layout->addWidget( mInclusion, 0, 1 );
191 layout->addWidget( mSuffix, 0, 2 );
192 layout->addWidget( label, 1, 0 );
193 layout->addMultiCellWidget( mFormattedNameCombo, 1, 1, 1, 2 );
194 }
195
196 connect( mPrefix, SIGNAL( modified() ), SIGNAL( modified() ) );
197 connect( mInclusion, SIGNAL( modified() ), SIGNAL( modified() ) );
198 connect( mSuffix, SIGNAL( modified() ), SIGNAL( modified() ) );
199 connect( mFormattedNameCombo, SIGNAL( activated( int ) ), SIGNAL( modified() ) );
200}
201
202AddresseeWidget::~AddresseeWidget()
203{
204}
205
206void AddresseeWidget::restoreSettings()
207{
208 KConfig config( locateLocal("config", "kabcrc") );
209 config.setGroup( "General" );
210
211 mPrefix->setNameParts( config.readListEntry( "Prefixes" ) );
212 mInclusion->setNameParts( config.readListEntry( "Inclusions" ) );
213 mSuffix->setNameParts( config.readListEntry( "Suffixes" ) );
214
215 KConfig cfg( locateLocal("config","kaddressbookrc") );
216 cfg.setGroup( "General" );
217 mFormattedNameCombo->setCurrentItem( cfg.readNumEntry( "FormattedNameType", 1 ) );
218}
219
220void AddresseeWidget::saveSettings()
221{
222 KConfig config( locateLocal("config","kabcrc") );
223 config.setGroup( "General" );
224
225 config.writeEntry( "Prefixes", mPrefix->nameParts() );
226 config.writeEntry( "Inclusions", mInclusion->nameParts() );
227 config.writeEntry( "Suffixes", mSuffix->nameParts() );
228
229 KConfig cfg( locateLocal("config","kaddressbookrc") );
230 cfg.setGroup( "General" );
231 cfg.writeEntry( "FormattedNameType", mFormattedNameCombo->currentItem() );
232}
233
234#ifndef KAB_EMBEDDED
235#include "addresseewidget.moc"
236#endif //KAB_EMBEDDED
diff --git a/kaddressbook/kcmconfigs/addresseewidget.h b/kaddressbook/kcmconfigs/addresseewidget.h
new file mode 100644
index 0000000..09330c8
--- a/dev/null
+++ b/kaddressbook/kcmconfigs/addresseewidget.h
@@ -0,0 +1,87 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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#ifndef ADDRESSEEWIDGET_H
25#define ADDRESSEEWIDGET_H
26
27#include <qwidget.h>
28
29class KComboBox;
30class KLineEdit;
31
32class QListBox;
33class QListBoxItem;
34class QPushButton;
35
36class NamePartWidget : public QWidget
37{
38 Q_OBJECT
39
40 public:
41 NamePartWidget( const QString &title, QWidget *parent,
42 const char *name = 0 );
43 ~NamePartWidget();
44
45 void setNameParts( const QStringList &list );
46 QStringList nameParts() const;
47
48 signals:
49 void modified();
50
51 private slots:
52 void add();
53 void remove();
54
55 void selectionChanged( QListBoxItem* );
56 void textChanged( const QString& );
57
58 private:
59 KLineEdit *mEdit;
60
61 QListBox *mBox;
62 QPushButton *mAddButton;
63 QPushButton *mRemoveButton;
64};
65
66class AddresseeWidget : public QWidget
67{
68 Q_OBJECT
69
70 public:
71 AddresseeWidget( QWidget *parent, const char *name = 0 );
72 ~AddresseeWidget();
73
74 void restoreSettings();
75 void saveSettings();
76
77 signals:
78 void modified();
79
80 private:
81 KComboBox *mFormattedNameCombo;
82 NamePartWidget *mPrefix;
83 NamePartWidget *mInclusion;
84 NamePartWidget *mSuffix;
85};
86
87#endif
diff --git a/kaddressbook/kcmconfigs/extensionconfigdialog.cpp b/kaddressbook/kcmconfigs/extensionconfigdialog.cpp
new file mode 100644
index 0000000..e87b000
--- a/dev/null
+++ b/kaddressbook/kcmconfigs/extensionconfigdialog.cpp
@@ -0,0 +1,59 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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 <qlayout.h>
25
26#include <klocale.h>
27
28#include "configurewidget.h"
29
30#include "extensionconfigdialog.h"
31
32ExtensionConfigDialog::ExtensionConfigDialog( ExtensionFactory *factory, KConfig *config,
33 QWidget *parent, const char *name )
34 : KDialogBase( Plain, i18n( "Extension Settings" ), Ok | Cancel, Ok, parent,
35 name, true, true ), mWidget( 0 ), mConfig( config )
36{
37 QFrame *page = plainPage();
38 QGridLayout *layout = new QGridLayout( page, 1, 1, marginHint(), spacingHint() );
39
40 mWidget = factory->configureWidget( page, "ExtensionConfigWidget" );
41 layout->addWidget( mWidget, 0, 0 );
42
43 mWidget->restoreSettings( mConfig );
44}
45
46ExtensionConfigDialog::~ExtensionConfigDialog()
47{
48}
49
50void ExtensionConfigDialog::slotOk()
51{
52 mWidget->saveSettings( mConfig );
53
54 KDialogBase::slotOk();
55}
56
57#ifndef KAB_EMBEDDED
58#include "extensionconfigdialog.moc"
59#endif //KAB_EMBEDDED
diff --git a/kaddressbook/kcmconfigs/extensionconfigdialog.h b/kaddressbook/kcmconfigs/extensionconfigdialog.h
new file mode 100644
index 0000000..5a92034
--- a/dev/null
+++ b/kaddressbook/kcmconfigs/extensionconfigdialog.h
@@ -0,0 +1,48 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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#ifndef EXTENSIONCONFIGDIALOG_H
25#define EXTENSIONCONFIGDIALOG_H
26
27#include <kdialogbase.h>
28
29#include "extensionwidget.h"
30
31class ExtensionConfigDialog : public KDialogBase
32{
33 Q_OBJECT
34
35 public:
36 ExtensionConfigDialog( ExtensionFactory *factory, KConfig *config,
37 QWidget *parent, const char *name = 0 );
38 ~ExtensionConfigDialog();
39
40 protected slots:
41 void slotOk();
42
43 private:
44 ConfigureWidget *mWidget;
45 KConfig *mConfig;
46};
47
48#endif
diff --git a/kaddressbook/kcmconfigs/kabconfigwidget.cpp b/kaddressbook/kcmconfigs/kabconfigwidget.cpp
new file mode 100644
index 0000000..7b3e5c6
--- a/dev/null
+++ b/kaddressbook/kcmconfigs/kabconfigwidget.cpp
@@ -0,0 +1,357 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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 <qcheckbox.h>
25#include <qframe.h>
26#include <qgroupbox.h>
27#include <qlayout.h>
28#include <qpushbutton.h>
29#include <qtabwidget.h>
30
31#include <kconfig.h>
32#include <kdebug.h>
33#include <kdialog.h>
34#include <klistview.h>
35#include <klocale.h>
36#include <kglobal.h>
37#include <kmessagebox.h>
38#include <kstandarddirs.h>
39
40#ifndef KAB_EMBEDDED
41#include <ktrader.h>
42#else // KAB_EMBEDDED
43#include <mergewidget.h>
44#include <distributionlistwidget.h>
45#endif // KAB_EMBEDDED
46
47#include "addresseewidget.h"
48#include "extensionconfigdialog.h"
49#include "extensionwidget.h"
50#include "kabprefs.h"
51
52#include "kabconfigwidget.h"
53
54class ExtensionItem : public QCheckListItem
55{
56 public:
57
58#ifndef KAB_EMBEDDED
59 ExtensionItem( QListView *parent, const QString &text );
60 void setService( const KService::Ptr &ptr );
61#else //KAB_EMBEDDED
62 ExtensionItem( QListView *parent, const QString &text, const QString &name, const QString &comment );
63 void setFactory( ExtensionFactory* fac );
64#endif //KAB_EMBEDDED
65
66 bool configWidgetAvailable() const;
67 ExtensionFactory *factory() const;
68
69 virtual QString text( int column ) const;
70
71 private:
72#ifndef KAB_EMBEDDED
73 KService::Ptr mPtr;
74#else //KAB_EMBEDDED
75 ExtensionFactory* mFactory;
76 QString mName;
77 QString mComment;
78
79#endif //KAB_EMBEDDED
80
81};
82
83KABConfigWidget::KABConfigWidget( QWidget *parent, const char *name )
84 : QWidget( parent, name )
85{
86 QVBoxLayout *topLayout = new QVBoxLayout( this, 0,
87 KDialog::spacingHint() );
88
89 QTabWidget *tabWidget = new QTabWidget( this );
90 topLayout->addWidget( tabWidget );
91
92 // General page
93 QWidget *generalPage = new QWidget( this );
94 QVBoxLayout *layout = new QVBoxLayout( generalPage, KDialog::marginHint(),
95 KDialog::spacingHint() );
96
97 QGroupBox *groupBox = new QGroupBox( 0, Qt::Vertical, i18n( "General" ), generalPage );
98 QVBoxLayout *boxLayout = new QVBoxLayout( groupBox->layout() );
99 boxLayout->setAlignment( Qt::AlignTop );
100
101 mViewsSingleClickBox = new QCheckBox( i18n( "Honor KDE single click" ), groupBox, "msingle" );
102 boxLayout->addWidget( mViewsSingleClickBox );
103
104 mNameParsing = new QCheckBox( i18n( "Automatic name parsing for new addressees" ), groupBox, "mparse" );
105 boxLayout->addWidget( mNameParsing );
106
107 layout->addWidget( groupBox );
108
109 groupBox = new QGroupBox( 0, Qt::Vertical, i18n( "Extensions" ), generalPage );
110 boxLayout = new QVBoxLayout( groupBox->layout() );
111 boxLayout->setAlignment( Qt::AlignTop );
112
113 mExtensionView = new KListView( groupBox );
114 mExtensionView->setAllColumnsShowFocus( true );
115 mExtensionView->addColumn( i18n( "Name" ) );
116 mExtensionView->addColumn( i18n( "Description" ) );
117 mExtensionView->setMaximumHeight(80);
118
119 boxLayout->addWidget( mExtensionView );
120
121 mConfigureButton = new QPushButton( i18n( "Configure..." ), groupBox );
122 mConfigureButton->setEnabled( false );
123 boxLayout->addWidget( mConfigureButton );
124
125 layout->addWidget( groupBox );
126
127 connect( mNameParsing, SIGNAL( toggled( bool ) ), this, SLOT( modified() ) );
128 connect( mViewsSingleClickBox, SIGNAL( toggled( bool ) ), this, SLOT( modified() ) );
129 connect( mExtensionView, SIGNAL( selectionChanged( QListViewItem* ) ),
130 SLOT( selectionChanged( QListViewItem* ) ) );
131 connect( mExtensionView, SIGNAL( clicked( QListViewItem* ) ),
132 SLOT( itemClicked( QListViewItem* ) ) );
133 connect( mConfigureButton, SIGNAL( clicked() ),
134 SLOT( configureExtension() ) );
135
136 tabWidget->addTab( generalPage, i18n( "General" ) );
137
138 // Addressee page
139 mAddresseeWidget = new AddresseeWidget( this );
140 tabWidget->addTab( mAddresseeWidget, i18n( "Contact" ) );
141 connect( mAddresseeWidget, SIGNAL( modified() ), SLOT( modified() ) );
142}
143
144void KABConfigWidget::restoreSettings()
145{
146 bool blocked = signalsBlocked();
147 blockSignals( true );
148
149 mNameParsing->setChecked( KABPrefs::instance()->mAutomaticNameParsing );
150 mViewsSingleClickBox->setChecked( KABPrefs::instance()->mHonorSingleClick );
151 mAddresseeWidget->restoreSettings();
152
153 restoreExtensionSettings();
154
155 blockSignals( blocked );
156
157 emit changed( false );
158}
159
160void KABConfigWidget::saveSettings()
161{
162 KABPrefs::instance()->mAutomaticNameParsing = mNameParsing->isChecked();
163 KABPrefs::instance()->mHonorSingleClick = mViewsSingleClickBox->isChecked();
164 mAddresseeWidget->saveSettings();
165
166 saveExtensionSettings();
167 KABPrefs::instance()->writeConfig();
168
169 emit changed( false );
170}
171
172void KABConfigWidget::defaults()
173{
174 mNameParsing->setChecked( true );
175 mViewsSingleClickBox->setChecked( false );
176
177 emit changed( true );
178}
179
180void KABConfigWidget::modified()
181{
182 emit changed( true );
183}
184
185void KABConfigWidget::restoreExtensionSettings()
186{
187 QStringList activeExtensions = KABPrefs::instance()->mActiveExtensions;
188
189 mExtensionView->clear();
190
191#ifndef KAB_EMBEDDED
192 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/Extension" );
193 KTrader::OfferList::ConstIterator it;
194 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
195 if ( !(*it)->hasServiceType( "KAddressBook/Extension" ) )
196 continue;
197
198 ExtensionItem *item = new ExtensionItem( mExtensionView, (*it)->name() );
199 item->setService( *it );
200 if ( activeExtensions.contains( item->factory()->identifier() ) )
201 item->setOn( true );
202 }
203#else //KAB_EMBEDDED
204 ExtensionFactory *extensionFactory = new MergeFactory();
205
206 ExtensionItem *item = new ExtensionItem( mExtensionView, "Merge", "Merge", "Merge contacts");
207
208 item->setFactory( extensionFactory );
209 if ( activeExtensions.contains( extensionFactory->identifier() ) )
210 item->setOn( true );
211
212
213
214 extensionFactory = new DistributionListFactory();
215
216 item = new ExtensionItem( mExtensionView, "Distribution List", "Distribution List", "Manage Distribution Lists");
217
218 item->setFactory( extensionFactory );
219 if ( activeExtensions.contains( extensionFactory->identifier() ) )
220 item->setOn( true );
221
222
223#endif //KAB_EMBEDDED
224
225}
226
227void KABConfigWidget::saveExtensionSettings()
228{
229 QStringList activeExtensions;
230
231 QPtrList<QListViewItem> list;
232 QListViewItemIterator it( mExtensionView );
233 while ( it.current() ) {
234 ExtensionItem *item = static_cast<ExtensionItem*>( it.current() );
235 if ( item ) {
236 if ( item->isOn() )
237 activeExtensions.append( item->factory()->identifier() );
238 }
239 ++it;
240 }
241
242 KABPrefs::instance()->mActiveExtensions = activeExtensions;
243}
244
245void KABConfigWidget::configureExtension()
246{
247 ExtensionItem *item = static_cast<ExtensionItem*>( mExtensionView->currentItem() );
248 if ( !item )
249 return;
250
251#ifndef KAB_EMBEDDED
252 KConfig config( "kaddressbookrc" );
253#else //KAB_EMBEDDED
254 KConfig config( locateLocal("config", "kaddressbookrc") );
255#endif //KAB_EMBEDDED
256 config.setGroup( QString( "Extensions_%1" ).arg( item->factory()->identifier() ) );
257
258 ExtensionConfigDialog dlg( item->factory(), &config, this );
259 dlg.exec();
260
261 config.sync();
262}
263
264void KABConfigWidget::selectionChanged( QListViewItem *i )
265{
266 ExtensionItem *item = static_cast<ExtensionItem*>( i );
267 if ( !item )
268 return;
269
270 mConfigureButton->setEnabled( item->configWidgetAvailable() );
271}
272
273void KABConfigWidget::itemClicked( QListViewItem *item )
274{
275 if ( item != 0 )
276 modified();
277}
278
279#ifndef KAB_EMBEDDED
280ExtensionItem::ExtensionItem( QListView *parent, const QString &text )
281 : QCheckListItem( parent, text, CheckBox )
282{
283}
284
285void ExtensionItem::setService( const KService::Ptr &ptr )
286{
287 mPtr = ptr;
288}
289#else //KAB_EMBEDDED
290ExtensionItem::ExtensionItem( QListView *parent, const QString &text, const QString &name, const QString &comment )
291 : QCheckListItem( parent, text, CheckBox )
292{
293 mName = name;
294 mComment = comment;
295}
296
297
298void ExtensionItem::setFactory( ExtensionFactory* fac )
299{
300 mFactory = fac;
301}
302#endif //KAB_EMBEDDED
303
304bool ExtensionItem::configWidgetAvailable() const
305{
306#ifndef KAB_EMBEDDED
307 KLibFactory *factory = KLibLoader::self()->factory( mPtr->library().latin1() );
308 if ( !factory )
309 return false;
310
311 ExtensionFactory *extensionFactory = static_cast<ExtensionFactory*>( factory );
312 if ( !extensionFactory )
313 return false;
314
315 return extensionFactory->configureWidgetAvailable();
316#else //KAB_EMBEDDED
317 return mFactory->configureWidgetAvailable();
318#endif //KAB_EMBEDDED
319
320}
321
322ExtensionFactory *ExtensionItem::factory() const
323{
324#ifndef KAB_EMBEDDED
325 KLibFactory *factory = KLibLoader::self()->factory( mPtr->library().latin1() );
326 if ( !factory )
327 return 0;
328
329 return static_cast<ExtensionFactory*>( factory );
330#else //KAB_EMBEDDED
331 return mFactory;
332#endif //KAB_EMBEDDED
333}
334
335QString ExtensionItem::text( int column ) const
336{
337#ifndef KAB_EMBEDDED
338 if ( column == 0 )
339 return mPtr->name();
340 else if ( column == 1 )
341 return mPtr->comment();
342 else
343 return QString::null;
344#else //KAB_EMBEDDED
345 if ( column == 0 )
346 return mName;
347 else if ( column == 1 )
348 return mComment;
349 else
350 return QString::null;
351#endif //KAB_EMBEDDED
352}
353
354#ifndef KAB_EMBEDDED
355#include "kabconfigwidget.moc"
356#endif //KAB_EMBEDDED
357
diff --git a/kaddressbook/kcmconfigs/kabconfigwidget.h b/kaddressbook/kcmconfigs/kabconfigwidget.h
new file mode 100644
index 0000000..0f36d9e
--- a/dev/null
+++ b/kaddressbook/kcmconfigs/kabconfigwidget.h
@@ -0,0 +1,72 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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#ifndef KABCONFIGWIDGET_H
25#define KABCONFIGWIDGET_H
26
27#include <qwidget.h>
28
29class QCheckBox;
30class QListViewItem;
31class QPushButton;
32
33class KListView;
34
35class AddresseeWidget;
36
37class KABConfigWidget : public QWidget
38{
39 Q_OBJECT
40
41 public:
42 KABConfigWidget( QWidget *parent, const char *name = 0 );
43
44 void restoreSettings();
45 void saveSettings();
46 void defaults();
47
48 signals:
49 void changed( bool );
50
51 public slots:
52 void modified();
53
54 private slots:
55 void configureExtension();
56 void selectionChanged( QListViewItem* );
57 void itemClicked( QListViewItem* );
58
59 private:
60 void restoreExtensionSettings();
61 void saveExtensionSettings();
62
63 KListView *mExtensionView;
64
65 QCheckBox *mNameParsing;
66 QCheckBox *mViewsSingleClickBox;
67 QPushButton *mConfigureButton;
68
69 AddresseeWidget *mAddresseeWidget;
70};
71
72#endif
diff --git a/kaddressbook/kcmconfigs/kcmkabconfig.cpp b/kaddressbook/kcmconfigs/kcmkabconfig.cpp
new file mode 100644
index 0000000..791a940
--- a/dev/null
+++ b/kaddressbook/kcmconfigs/kcmkabconfig.cpp
@@ -0,0 +1,86 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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 <qlayout.h>
25
26#ifndef KAB_EMBEDDED
27#include <kaboutdata.h>
28#endif //KAB_EMBEDDED
29#include <kdebug.h>
30#include <klocale.h>
31
32#include "kabconfigwidget.h"
33
34#include "kcmkabconfig.h"
35
36extern "C"
37{
38 KCModule *create_kabconfig( QWidget *parent, const char * ) {
39 return new KCMKabConfig( parent, "kcmkabconfig" );
40 }
41}
42
43KCMKabConfig::KCMKabConfig( QWidget *parent, const char *name )
44 : KCModule( parent, name )
45{
46 QVBoxLayout *layout = new QVBoxLayout( this );
47 mConfigWidget = new KABConfigWidget( this, "mConfigWidget" );
48 layout->addWidget( mConfigWidget );
49
50 connect( mConfigWidget, SIGNAL( changed( bool ) ), SIGNAL( changed( bool ) ) );
51 load();
52}
53
54void KCMKabConfig::load()
55{
56 mConfigWidget->restoreSettings();
57}
58
59void KCMKabConfig::save()
60{
61 mConfigWidget->saveSettings();
62}
63
64void KCMKabConfig::defaults()
65{
66 mConfigWidget->defaults();
67}
68
69#ifndef KAB_EMBEDDED
70const KAboutData* KCMKabConfig::aboutData() const
71{
72 KAboutData *about = new KAboutData( I18N_NOOP( "kcmkabconfig" ),
73 I18N_NOOP( "KAddressBook Configure Dialog" ),
74 0, 0, KAboutData::License_GPL,
75 I18N_NOOP( "(c), 2003 Tobias Koenig" ) );
76
77 about->addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" );
78
79 return about;
80
81}
82#endif //KAB_EMBEDDED
83
84#ifndef KAB_EMBEDDED
85#include "kcmkabconfig.moc"
86#endif //KAB_EMBEDDED
diff --git a/kaddressbook/kcmconfigs/kcmkabconfig.h b/kaddressbook/kcmconfigs/kcmkabconfig.h
new file mode 100644
index 0000000..be345b8
--- a/dev/null
+++ b/kaddressbook/kcmconfigs/kcmkabconfig.h
@@ -0,0 +1,53 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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#ifndef KCMKABCONFIG_H
25#define KCMKABCONFIG_H
26
27#include <kcmodule.h>
28
29class KABConfigWidget;
30
31#ifndef KAB_EMBEDDED
32class KAboutData;
33#endif //KAB_EMBEDDED
34
35class KCMKabConfig : public KCModule
36{
37 Q_OBJECT
38
39 public:
40 KCMKabConfig( QWidget *parent = 0, const char *name = 0 );
41
42 virtual void load();
43 virtual void save();
44 virtual void defaults();
45#ifndef KAB_EMBEDDED
46 virtual const KAboutData* aboutData() const;
47#endif //KAB_EMBEDDED
48
49 private:
50 KABConfigWidget *mConfigWidget;
51};
52
53#endif
diff --git a/kaddressbook/keywidget.cpp b/kaddressbook/keywidget.cpp
new file mode 100644
index 0000000..c117d34
--- a/dev/null
+++ b/kaddressbook/keywidget.cpp
@@ -0,0 +1,277 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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 <qfile.h>
25
26#include <qinputdialog.h>
27
28#include <qlabel.h>
29#include <qlayout.h>
30#include <qpushbutton.h>
31
32#ifndef KAB_EMBEDDED
33#include <kaccelmanager.h>
34#include <kio/netaccess.h>
35#include <kmessagebox.h>
36#else //KAB_EMBEDDED
37#include <qmap.h>
38#include <qmessagebox.h>
39#include <qtextstream.h>
40#include <kurl.h>
41#endif //KAB_EMBEDDED
42
43#include <kapplication.h>
44#include <kcombobox.h>
45#include <kdialog.h>
46#include <kfiledialog.h>
47#include <klocale.h>
48#include <ktempfile.h>
49
50#include "keywidget.h"
51
52KeyWidget::KeyWidget( QWidget *parent, const char *name )
53 : QWidget( parent, name )
54{
55 QGridLayout *layout = new QGridLayout( this, 2, 2, KDialog::marginHint(),
56 KDialog::spacingHint() );
57
58 QLabel *label = new QLabel( i18n( "Keys:" ), this );
59 layout->addWidget( label, 0, 0 );
60
61 mKeyCombo = new KComboBox( this );
62 layout->addWidget( mKeyCombo, 0, 1 );
63
64 mAddButton = new QPushButton( i18n( "Add" ), this );
65 layout->addWidget( mAddButton, 1, 0 );
66
67 mRemoveButton = new QPushButton( i18n( "Remove" ), this );
68 mRemoveButton->setEnabled( false );
69 layout->addWidget( mRemoveButton, 1, 1 );
70
71 mExportButton = new QPushButton( i18n( "Export" ), this );
72 mExportButton->setEnabled( false );
73 layout->addMultiCellWidget( mExportButton, 2, 2, 0, 1 );
74
75 connect( mAddButton, SIGNAL( clicked() ), SLOT( addKey() ) );
76 connect( mRemoveButton, SIGNAL( clicked() ), SLOT( removeKey() ) );
77 connect( mExportButton, SIGNAL( clicked() ), SLOT( exportKey() ) );
78}
79
80KeyWidget::~KeyWidget()
81{
82}
83
84void KeyWidget::setKeys( const KABC::Key::List &list )
85{
86 mKeyList = list;
87
88 updateKeyCombo();
89}
90
91KABC::Key::List KeyWidget::keys() const
92{
93 return mKeyList;
94}
95
96void KeyWidget::addKey()
97{
98 QMap<QString, int> keyMap;
99 QStringList keyTypeNames;
100 QStringList existingKeyTypes;
101
102 KABC::Key::List::Iterator listIt;
103 for ( listIt = mKeyList.begin(); listIt != mKeyList.end(); ++listIt ) {
104 if ( (*listIt).type() != KABC::Key::Custom )
105 existingKeyTypes.append( KABC::Key::typeLabel( (*listIt).type() ) );
106 }
107
108 KABC::Key::TypeList typeList = KABC::Key::typeList();
109 KABC::Key::TypeList::Iterator it;
110 for ( it = typeList.begin(); it != typeList.end(); ++it ) {
111 if ( (*it) != KABC::Key::Custom &&
112 !existingKeyTypes.contains( KABC::Key::typeLabel( *it ) ) ) {
113 keyMap.insert( KABC::Key::typeLabel( *it ), *it );
114 keyTypeNames.append( KABC::Key::typeLabel( *it ) );
115 }
116 }
117
118 bool ok;
119 QString name = QInputDialog::getItem( i18n( "Key type" ), i18n( "Select the key type." ), keyTypeNames, 0, true, &ok );
120
121
122
123 if ( !ok || name.isEmpty() )
124 return;
125
126 int type = keyMap[ name ];
127 if ( !keyTypeNames.contains( name ) )
128 type = KABC::Key::Custom;
129
130#ifndef KAB_EMBEDDED
131 KURL url = KFileDialog::getOpenURL();
132
133 if ( url.isEmpty() )
134 return;
135
136 QString tmpFile;
137 if ( KIO::NetAccess::download( url, tmpFile ) ) {
138 QFile file( tmpFile );
139 if ( !file.open( IO_ReadOnly ) ) {
140 QString text( i18n( "<qt>Unable to open file <b>%1</b>.</qt>" ) );
141 KMessageBox::error( this, text.arg( url.url() ) );
142 return;
143 }
144
145
146#else //KAB_EMBEDDED
147 QString keyfile = KFileDialog::getOpenFileName( "huhu",
148 "Select Key", this );
149
150 if ( keyfile.isEmpty() )
151 return;
152
153 {
154 QFile file( keyfile );
155 if ( !file.open( IO_ReadOnly ) ) {
156 QString text( i18n( "<qt>Unable to open file <b>%1</b>.</qt>" ) );
157 QString caption( i18n( "Error" ) );
158 QMessageBox::critical( this, caption, text.arg( keyfile ) );
159 return;
160 }
161
162#endif //KAB_EMBEDDED
163
164
165
166 QTextStream s( &file );
167 QString data;
168
169 s.setEncoding( QTextStream::UnicodeUTF8 );
170 s >> data;
171 file.close();
172
173 KABC::Key key( data, type );
174 if ( type == KABC::Key::Custom )
175 key.setCustomTypeString( name );
176 mKeyList.append( key );
177
178 emit changed();
179
180#ifndef KAB_EMBEDDED
181 KIO::NetAccess::removeTempFile( tmpFile );
182#endif //KAB_EMBEDDED
183
184 }
185
186 updateKeyCombo();
187}
188
189void KeyWidget::removeKey()
190{
191 int pos = mKeyCombo->currentItem();
192 if ( pos == -1 )
193 return;
194
195 QString type = mKeyCombo->currentText();
196 QString text = i18n( "<qt>Do you really want to remove the key <b>%1</b>?</qt>" );
197
198
199#ifndef KAB_EMBEDDED
200 if ( KMessageBox::questionYesNo( this, text.arg( type ) ) == KMessageBox::No )
201 return;
202#else //KAB_EMBEDDED
203 QString caption = i18n( "Confirm Delete" );
204 if (QMessageBox::information( this, caption,
205 text.arg( type ),
206 i18n("Yes!"), i18n("No"), 0, 0 ) == 1)
207 return;
208#endif //KAB_EMBEDDED
209
210 mKeyList.remove( mKeyList.at( pos ) );
211 emit changed();
212
213 updateKeyCombo();
214}
215
216void KeyWidget::exportKey()
217{
218 KABC::Key key = (*mKeyList.at( mKeyCombo->currentItem() ) );
219
220#ifndef KAB_EMBEDDED
221 KURL url = KFileDialog::getSaveURL();
222
223 KTempFile tempFile;
224 QTextStream *s = tempFile.textStream();
225 s->setEncoding( QTextStream::UnicodeUTF8 );
226 (*s) << key.textData();
227 tempFile.close();
228
229 KIO::NetAccess::upload( tempFile.name(), url, kapp->mainWidget() );
230#else //KAB_EMBEDDED
231 QString keyfile = KFileDialog::getSaveFileName( "huhu",
232 "Save Key", this );
233
234 if ( keyfile.isEmpty() )
235 return;
236
237 QFile file( keyfile );
238 if ( !file.open( IO_ReadWrite ) ) {
239 QString text( i18n( "<qt>Unable to open file <b>%1</b>.</qt>" ) );
240 QString caption( i18n( "Error" ) );
241 QMessageBox::critical( this, caption, text.arg( keyfile ) );
242 return;
243 }
244
245 QTextStream s( &file );
246 s.setEncoding( QTextStream::UnicodeUTF8 );
247 s << key.textData();
248 file.close();
249
250
251#endif //KAB_EMBEDDED
252
253}
254
255void KeyWidget::updateKeyCombo()
256{
257 int pos = mKeyCombo->currentItem();
258 mKeyCombo->clear();
259
260 KABC::Key::List::Iterator it;
261 for ( it = mKeyList.begin(); it != mKeyList.end(); ++it ) {
262 if ( (*it).type() == KABC::Key::Custom )
263 mKeyCombo->insertItem( (*it).customTypeString() );
264 else
265 mKeyCombo->insertItem( KABC::Key::typeLabel( (*it).type() ) );
266 }
267
268 mKeyCombo->setCurrentItem( pos );
269
270 bool state = ( mKeyList.count() != 0 );
271 mRemoveButton->setEnabled( state );
272 mExportButton->setEnabled( state );
273}
274
275#ifndef KAB_EMBEDDED
276#include "keywidget.moc"
277#endif //KAB_EMBEDDED
diff --git a/kaddressbook/keywidget.h b/kaddressbook/keywidget.h
new file mode 100644
index 0000000..50bac53
--- a/dev/null
+++ b/kaddressbook/keywidget.h
@@ -0,0 +1,65 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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#ifndef KEYWIDGET_H
25#define KEYWIDGET_H
26
27#include <qwidget.h>
28#include <kabc/key.h>
29
30class KComboBox;
31
32class QPushButton;
33
34class KeyWidget : public QWidget
35{
36 Q_OBJECT
37
38 public:
39 KeyWidget( QWidget *parent, const char *name = 0 );
40 ~KeyWidget();
41
42 void setKeys( const KABC::Key::List &list );
43 KABC::Key::List keys() const;
44
45 signals:
46 void changed();
47
48 private slots:
49 void addKey();
50 void removeKey();
51 void exportKey();
52
53 private:
54 void updateKeyCombo();
55
56 KComboBox *mKeyCombo;
57
58 QPushButton *mAddButton;
59 QPushButton *mRemoveButton;
60 QPushButton *mExportButton;
61
62 KABC::Key::List mKeyList;
63};
64
65#endif
diff --git a/kaddressbook/mainembedded.cpp b/kaddressbook/mainembedded.cpp
new file mode 100644
index 0000000..ffa37a5
--- a/dev/null
+++ b/kaddressbook/mainembedded.cpp
@@ -0,0 +1,208 @@
1#ifndef DESKTOP_VERSION
2#include <qpe/qpeapplication.h>
3#include <qpe/global.h>
4#include <stdlib.h>
5#else
6#include <qapplication.h>
7#include <qwindowsstyle.h>
8#include <qplatinumstyle.h>
9#include <qmainwindow.h>
10#endif
11
12#include <kstandarddirs.h>
13#include <kglobal.h>
14#include <stdio.h>
15#include <qdir.h>
16#include "kaddressbookmain.h"
17
18int main( int argc, char **argv )
19{
20#ifndef DESKTOP_VERSION
21 QPEApplication a( argc, argv );
22 a.setKeepRunning ();
23#else
24 QApplication a( argc, argv );
25 QApplication::setStyle( new QPlatinumStyle ());
26#endif
27
28 bool exitHelp = false;
29 if ( argc > 1 ) {
30 QString command = argv[1];
31 if ( command == "-help" ){
32 printf("KA/E command line commands:\n");
33 printf(" no command: Start KA/E in usual way\n");
34 printf(" -help: This output\n");
35 printf(" KA/E is exiting now. Bye!\n");
36 exitHelp = true;
37 }
38 }
39 if ( ! exitHelp ) {
40
41 KGlobal::setAppName( "kaddressbook" );
42#ifndef DESKTOP_VERSION
43 KStandardDirs::setAppDir( Global::applicationFileName( "kaddressbook", "" ) );
44 KGlobal::iconLoader()->setIconPath(QString(getenv("QPEDIR"))+"/pics/kdepim/kaddressbook/icons16/");
45#else
46 QString fileName ;
47#ifndef _WIN32_
48 fileName = qApp->applicationDirPath () + "/kdepim/kaddressbook/icons16/";
49#else
50 fileName = qApp->applicationDirPath () + "\\kdepim\\kaddressbook\\icons16\\";
51#endif
52 KGlobal::iconLoader()->setIconPath(fileName);
53 QString appdir = QDir::homeDirPath();
54 if ( appdir.right(1) == "\\" || appdir.right(1) == "/" )
55 appdir += "kaddressbook";
56 else
57 appdir += "/kaddressbook";
58 KStandardDirs::setAppDir( QDir::convertSeparators( appdir ));
59 // qDebug(" %s ",KStandardDirs::appDir().latin1() );
60#endif // desktop
61 QDir app_dir;
62 if ( !app_dir.exists(KStandardDirs::appDir()) )
63 app_dir.mkdir (KStandardDirs::appDir());
64
65 KAddressBookMain* m = new KAddressBookMain();
66//US MainWindow m;
67//US QObject::connect( &a, SIGNAL (appMessage ( const QCString &, const QByteArray & )),&m, SLOT(recieve( const QCString&, const QByteArray& )));
68
69#ifndef DESKTOP_VERSION
70 a.showMainWidget(m );
71 m->showFullScreen();
72 int min = 20;
73 if ( QApplication::desktop()->width() > 320 )
74 min += 20;
75 m->setGeometry( 0,0,QApplication::desktop()->width(), QApplication::desktop()->height() - min );
76
77#else
78 a.setMainWidget(m );
79 m->show();
80 //m->resize( 640, 480 );
81#endif
82 a.exec();
83
84 }
85 qDebug("KA: Bye! ");
86}
87
88/*
89#include <stdlib.h>
90
91#include <qstring.h>
92
93#include <kabc/stdaddressbook.h>
94#include <kaboutdata.h>
95#include <kcmdlineargs.h>
96#include <kcrash.h>
97#include <kdebug.h>
98#include <klocale.h>
99#include <kstartupinfo.h>
100#include <kuniqueapplication.h>
101#include <kwin.h>
102
103#include "kaddressbookmain.h"
104#include "kabcore.h"
105
106extern "C" {
107
108void crashHandler( int )
109{
110 KABC::StdAddressBook::handleCrash();
111 ::exit( 0 );
112}
113
114}
115
116class KAddressBookApp : public KUniqueApplication {
117 public:
118 KAddressBookApp() : mMainWin( 0 ) {}
119 ~KAddressBookApp() {}
120
121 int newInstance();
122
123 private:
124 KAddressBookMain *mMainWin;
125};
126
127int KAddressBookApp::newInstance()
128{
129 if ( isRestored() ) {
130 // There can only be one main window
131 if ( KMainWindow::canBeRestored( 1 ) ) {
132 mMainWin = new KAddressBookMain;
133 mMainWin->show();
134 mMainWin->restore( 1 );
135 }
136 } else {
137 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
138
139 QCString addrStr = args->getOption( "addr" );
140 QCString uidStr = args->getOption( "uid" );
141 QString addr;
142 QString uid;
143 if ( !addrStr.isEmpty() )
144 addr = QString::fromLocal8Bit( addrStr );
145 if ( !uidStr.isEmpty() )
146 uid = QString::fromLocal8Bit( uidStr );
147
148
149 if ( args->isSet( "editor-only" ) ) {
150 if ( !mMainWin )
151 mMainWin = new KAddressBookMain;
152 KStartupInfo::appStarted();
153 mMainWin->hide();
154 } else {
155 if ( mMainWin ) {
156 mMainWin->show();
157 KWin::setActiveWindow( mMainWin->winId() );
158 } else {
159 mMainWin = new KAddressBookMain;
160 mMainWin->show();
161 }
162 }
163 // Can not see why anyone would pass both a uid and an email address, so I'll leave it that two contact editors will show if they do
164 if ( !addr.isEmpty() )
165 mMainWin->addEmail( addr );
166
167 if ( !uid.isEmpty() )
168 mMainWin->showContactEditor( uid );
169 if ( args->isSet( "new-contact" ) ) {
170 mMainWin->newContact();
171 }
172 }
173
174 KCrash::setEmergencySaveFunction( crashHandler );
175
176 return 0;
177}
178
179// the dummy argument is required, because KMail apparently sends an empty
180// argument.
181static KCmdLineOptions kmoptions[] =
182{
183 { "a", 0 , 0 },
184 { "addr <email>", I18N_NOOP( "Shows contact editor with given email address" ), 0 },
185 { "uid <uid>", I18N_NOOP( "Shows contact editor with given uid" ), 0 },
186 { "editor-only", I18N_NOOP( "Launches in editor only mode" ), 0 },
187 { "new-contact", I18N_NOOP( "Launches editor for the new contact" ), 0 },
188 { "+[argument]", I18N_NOOP( "dummy argument" ), 0},
189 { 0, 0, 0}
190};
191
192int main( int argc, char *argv[] )
193{
194 KLocale::setMainCatalogue( "kaddressbook" );
195
196 KCmdLineArgs::init( argc, argv, KABCore::createAboutData() );
197 KCmdLineArgs::addCmdLineOptions( kmoptions );
198 KUniqueApplication::addCmdLineOptions();
199
200 if ( !KAddressBookApp::start() )
201 exit( 0 );
202
203 KAddressBookApp app;
204 KGlobal::locale()->insertCatalogue( "libkdepim" );
205
206 return app.exec();
207}
208*/
diff --git a/kaddressbook/nameeditdialog.cpp b/kaddressbook/nameeditdialog.cpp
new file mode 100644
index 0000000..fb7eb22
--- a/dev/null
+++ b/kaddressbook/nameeditdialog.cpp
@@ -0,0 +1,296 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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 <qlayout.h>
25#include <qlabel.h>
26#include <qlistbox.h>
27#include <qlistview.h>
28#include <qtooltip.h>
29#include <qpushbutton.h>
30#include <qcheckbox.h>
31#include <qstring.h>
32
33#ifndef KAB_EMBEDDED
34#include <kaccelmanager.h>
35#else //KAB_EMBEDDED
36#include <kstandarddirs.h>
37#endif //KAB_EMBEDDED
38
39#include <kapplication.h>
40#include <kbuttonbox.h>
41#include <kconfig.h>
42#include <klineedit.h>
43#include <klistview.h>
44#include <kcombobox.h>
45#include <klocale.h>
46#include <kglobal.h>
47#include <kdebug.h>
48#include <kiconloader.h>
49#include <kmessagebox.h>
50
51#include "nameeditdialog.h"
52
53NameEditDialog::NameEditDialog( const KABC::Addressee &addr, int type,
54 QWidget *parent, const char *name )
55 : KDialogBase( Plain, i18n( "Edit Contact Name" ), Help | Ok | Cancel,
56 Ok, parent, name, true )
57{
58
59 QWidget *page = plainPage();
60 QGridLayout *layout = new QGridLayout( page, 5, 3 );
61 layout->setSpacing( spacingHint() );
62 layout->addColSpacing( 2, 100 );
63 QLabel *label;
64
65 label = new QLabel( i18n( "Honorific prefixes:" ), page );
66 layout->addWidget( label, 0, 0 );
67 mPrefixCombo = new KComboBox( page );
68 mPrefixCombo->setDuplicatesEnabled( false );
69 mPrefixCombo->setEditable( true );
70 label->setBuddy( mPrefixCombo );
71 layout->addMultiCellWidget( mPrefixCombo, 0, 0, 1, 2 );
72
73 label = new QLabel( i18n( "Given name:" ), page );
74 layout->addWidget( label, 1, 0 );
75 mGivenNameEdit = new KLineEdit( page );
76 label->setBuddy( mGivenNameEdit );
77 layout->addMultiCellWidget( mGivenNameEdit, 1, 1, 1, 2 );
78
79 label = new QLabel( i18n( "Additional names:" ), page );
80 layout->addWidget( label, 2, 0 );
81 mAdditionalNameEdit = new KLineEdit( page );
82 label->setBuddy( mAdditionalNameEdit );
83 layout->addMultiCellWidget( mAdditionalNameEdit, 2, 2, 1, 2 );
84
85 label = new QLabel( i18n( "Family names:" ), page );
86 layout->addWidget( label, 3, 0 );
87 mFamilyNameEdit = new KLineEdit( page );
88 label->setBuddy( mFamilyNameEdit );
89 layout->addMultiCellWidget( mFamilyNameEdit, 3, 3, 1, 2 );
90
91 label = new QLabel( i18n( "Honorific suffixes:" ), page );
92 layout->addWidget( label, 4, 0 );
93 mSuffixCombo = new KComboBox( page );
94 mSuffixCombo->setDuplicatesEnabled( false );
95 mSuffixCombo->setEditable( true );
96 label->setBuddy( mSuffixCombo );
97 layout->addMultiCellWidget( mSuffixCombo, 4, 4, 1, 2 );
98
99 mFormattedNameCombo = new KComboBox( page );
100 mFormattedNameCombo->setMaximumWidth(100);
101
102 layout->addMultiCellWidget( mFormattedNameCombo, 5, 5, 0, 0 );
103 connect( mFormattedNameCombo, SIGNAL( activated( int ) ), SLOT( typeChanged( int ) ) );
104
105 mFormattedNameEdit = new KLineEdit( page );
106 mFormattedNameEdit->setEnabled( type == CustomName );
107 layout->addMultiCellWidget( mFormattedNameEdit, 5, 5, 1, 2 );
108
109 mParseBox = new QCheckBox( i18n( "Parse name automatically" ), page );
110 connect( mParseBox, SIGNAL( toggled(bool) ), SLOT( parseBoxChanged(bool) ) );
111 connect( mParseBox, SIGNAL( toggled(bool) ), SLOT( modified() ) );
112 layout->addMultiCellWidget( mParseBox, 6, 6, 0, 1 );
113
114 // Fill in the values
115 mFamilyNameEdit->setText( addr.familyName() );
116 mGivenNameEdit->setText( addr.givenName() );
117 mAdditionalNameEdit->setText( addr.additionalName() );
118 mFormattedNameEdit->setText( addr.formattedName() );
119
120 // Prefix and suffix combos
121//US KConfig config( "kabcrc" );
122 KConfig config( locateLocal("config", "kabcrc") );
123 config.setGroup( "General" );
124
125 QStringList sTitle;
126 sTitle += i18n( "Dr." );
127 sTitle += i18n( "Miss" );
128 sTitle += i18n( "Mr." );
129 sTitle += i18n( "Mrs." );
130 sTitle += i18n( "Ms." );
131 sTitle += i18n( "Prof." );
132 sTitle += config.readListEntry( "Prefixes" );
133 sTitle.sort();
134
135 QStringList sSuffix;
136 sSuffix += i18n( "I" );
137 sSuffix += i18n( "II" );
138 sSuffix += i18n( "III" );
139 sSuffix += i18n( "Jr." );
140 sSuffix += i18n( "Sr." );
141 sSuffix += config.readListEntry( "Suffixes" );
142 sSuffix.sort();
143
144 mPrefixCombo->insertStringList( sTitle );
145 mSuffixCombo->insertStringList( sSuffix );
146
147#ifndef KAB_EMBEDDED
148 mPrefixCombo->setCurrentText( addr.prefix() );
149 mSuffixCombo->setCurrentText( addr.suffix() );
150#else //KAB_EMBEDDED
151 mPrefixCombo->setEditText( addr.prefix() );
152 mSuffixCombo->setEditText( addr.suffix() );
153#endif //KAB_EMBEDDED
154
155 AddresseeConfig::instance()->setUid( addr.uid() );
156 mParseBox->setChecked( AddresseeConfig::instance()->automaticNameParsing() );
157
158#ifndef KAB_EMBEDDED
159 KAcceleratorManager::manage( this );
160#endif //KAB_EMBEDDED
161
162 connect( mPrefixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
163 connect( mPrefixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) );
164 connect( mGivenNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
165 connect( mGivenNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) );
166 connect( mAdditionalNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
167 connect( mAdditionalNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) );
168 connect( mFamilyNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
169 connect( mFamilyNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) );
170 connect( mSuffixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
171 connect( mSuffixCombo, SIGNAL( textChanged( const QString& ) ), SLOT( updateTypeCombo() ) );
172 connect( mFormattedNameCombo, SIGNAL( activated( int ) ), SLOT( modified() ) );
173 connect( mFormattedNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( modified() ) );
174
175 updateTypeCombo();
176 mFormattedNameCombo->setCurrentItem( type );
177
178#ifdef KAB_EMBEDDED
179 resize( KMIN(KGlobal::getDesktopWidth()-10, 490), KMIN(KGlobal::getDesktopHeight()-50, 300));
180#endif //KAB_EMBEDDED
181
182 mChanged = false;
183}
184
185NameEditDialog::~NameEditDialog()
186{
187}
188
189QString NameEditDialog::familyName() const
190{
191 return mFamilyNameEdit->text();
192}
193
194QString NameEditDialog::givenName() const
195{
196 return mGivenNameEdit->text();
197}
198
199QString NameEditDialog::prefix() const
200{
201 return mPrefixCombo->currentText();
202}
203
204QString NameEditDialog::suffix() const
205{
206 return mSuffixCombo->currentText();
207}
208
209QString NameEditDialog::additionalName() const
210{
211 return mAdditionalNameEdit->text();
212}
213
214QString NameEditDialog::customFormattedName() const
215{
216 return mFormattedNameEdit->text();
217}
218
219int NameEditDialog::formattedNameType() const
220{
221 return mFormattedNameCombo->currentItem();
222}
223
224bool NameEditDialog::changed() const
225{
226 return mChanged;
227}
228
229QString NameEditDialog::formattedName( const KABC::Addressee &addr, int type )
230{
231 switch ( type ) {
232 case SimpleName:
233 return addr.givenName() + " " + addr.familyName();
234 break;
235 case FullName:
236 return addr.prefix() + " " + addr.givenName() + " " +
237 addr.additionalName() + " " + addr.familyName() + " " +
238 addr.suffix();
239 break;
240 case ReverseName:
241 return addr.familyName() + ", " + addr.givenName();
242 break;
243 default:
244 return "";
245 break;
246 }
247}
248
249void NameEditDialog::parseBoxChanged( bool value )
250{
251 //AddresseeConfig::instance()->setUid( addr.uid() );
252 AddresseeConfig::instance()->setAutomaticNameParsing( value );
253}
254
255void NameEditDialog::typeChanged( int pos )
256{
257 mFormattedNameEdit->setEnabled( pos == 0 );
258}
259
260void NameEditDialog::modified()
261{
262 mChanged = true;
263}
264
265void NameEditDialog::updateTypeCombo()
266{
267 KABC::Addressee addr;
268 addr.setPrefix( mPrefixCombo->currentText() );
269 addr.setGivenName( mGivenNameEdit->text() );
270 addr.setAdditionalName( mAdditionalNameEdit->text() );
271 addr.setFamilyName( mFamilyNameEdit->text() );
272 addr.setSuffix( mSuffixCombo->currentText() );
273
274 int pos = mFormattedNameCombo->currentItem();
275
276 mFormattedNameCombo->clear();
277 mFormattedNameCombo->insertItem( i18n( "Custom" ) );
278 mFormattedNameCombo->insertItem( formattedName( addr, SimpleName ) );
279 mFormattedNameCombo->insertItem( formattedName( addr, FullName ) );
280 mFormattedNameCombo->insertItem( formattedName( addr, ReverseName ) );
281
282 mFormattedNameCombo->setCurrentItem( pos );
283}
284
285void NameEditDialog::slotHelp()
286{
287#ifndef KAB_EMBEDDED
288 kapp->invokeHelp( "managing-contacts-automatic-nameparsing" );
289#else //KAB_EMBEDDED
290qDebug("NameEditDialog::slotHelp Help is not supported yet");
291#endif //KAB_EMBEDDED
292}
293
294#ifndef KAB_EMBEDDED
295#include "nameeditdialog.moc"
296#endif //KAB_EMBEDDED
diff --git a/kaddressbook/nameeditdialog.h b/kaddressbook/nameeditdialog.h
new file mode 100644
index 0000000..1d756c1
--- a/dev/null
+++ b/kaddressbook/nameeditdialog.h
@@ -0,0 +1,90 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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#ifndef NAMEEDITDIALOG_H
25#define NAMEEDITDIALOG_H
26
27#include <kdialogbase.h>
28#include <kabc/addressee.h>
29
30#include "addresseeconfig.h"
31
32class QCheckBox;
33
34class KLineEdit;
35class KComboBox;
36
37/**
38 Editor dialog for name details, like given name, family name etc.
39*/
40class NameEditDialog : public KDialogBase
41{
42 Q_OBJECT
43
44 public:
45 enum FormattedNameType
46 {
47 CustomName, // returned by @ref customFormattedName()
48 SimpleName, // form: givenName familyName
49 FullName, // form: prefix givenName additionalName familyName suffix
50 ReverseName // form: familyName, givenName
51 };
52
53 NameEditDialog( const KABC::Addressee &addr, int type,
54 QWidget *parent, const char *name = 0 );
55 ~NameEditDialog();
56
57 QString familyName() const;
58 QString givenName() const;
59 QString prefix() const;
60 QString suffix() const;
61 QString additionalName() const;
62 QString customFormattedName() const;
63 int formattedNameType() const;
64
65 bool changed() const;
66
67 static QString formattedName( const KABC::Addressee &addr, int type );
68
69 protected slots:
70 void slotHelp();
71
72 private slots:
73 void parseBoxChanged( bool );
74 void typeChanged( int );
75 void updateTypeCombo();
76 void modified();
77
78 private:
79 KComboBox *mSuffixCombo;
80 KComboBox *mPrefixCombo;
81 KComboBox *mFormattedNameCombo;
82 KLineEdit *mFamilyNameEdit;
83 KLineEdit *mGivenNameEdit;
84 KLineEdit *mAdditionalNameEdit;
85 KLineEdit *mFormattedNameEdit;
86 QCheckBox *mParseBox;
87 bool mChanged;
88};
89
90#endif
diff --git a/kaddressbook/old_mainwindow.cpp b/kaddressbook/old_mainwindow.cpp
new file mode 100644
index 0000000..0e886d9
--- a/dev/null
+++ b/kaddressbook/old_mainwindow.cpp
@@ -0,0 +1,1561 @@
1#include <qlabel.h>
2#include <qapp.h>
3#include <qmessagebox.h>
4#include <qaction.h>
5
6 #include <kdebug.h>// defined kdDebug()
7 #include <klocale.h>// defines i18n (microkde)
8
9#include "kabprefs.h"
10
11#ifndef DESKTOP_VERSION
12#include <qpe/qpetoolbar.h>
13#include <qpe/qpemenubar.h>
14#include <qpe/resource.h>
15#else
16#include <qtoolbar.h>
17#include <qmenubar.h>
18#include <resource.h>
19#endif
20
21/*
22#include <stdlib.h>
23
24#include <qaction.h>
25#include <qpainter.h>
26#include <qwhatsthis.h>
27#include <qpopupmenu.h>
28#include <qmessagebox.h>
29#include <qlineedit.h>
30#include <qfile.h>
31#include <qfileinfo.h>
32#include <qwmatrix.h>
33#ifndef DESKTOP_VERSION
34#include <qpe/global.h>
35#include <qpe/qpemenubar.h>
36#include <qpe/qpetoolbar.h>
37#include <qpe/resource.h>
38#include <qpe/qpeapplication.h>
39#include <qtopia/alarmserver.h>
40#include <qtopia/qcopenvelope_qws.h>
41#else
42#include <qtoolbar.h>
43#include <qdir.h>
44#include <qapplication.h>
45//#include <resource.h>
46#endif
47
48#include <libkcal/calendarlocal.h>
49#include <libkcal/todo.h>
50
51//#include "calendarview.h"
52//#include "koviewmanager.h"
53//#include "koagendaview.h"
54//#include "kodialogmanager.h"
55//#include "kdialogbase.h"
56//#include "koprefs.h"
57//#include "kfiledialog.h"
58//#include "koglobals.h"
59
60//#include "kconfig.h"
61//#include "simplealarmclient.h"
62*/
63//US using namespace KACore;
64
65
66#include "mainwindow.h"
67
68MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) :
69 QMainWindow( parent, name )
70{
71
72#ifdef DESKTOP_VERSION
73 setFont( QFont("Arial"), 14 );
74#endif
75// mBlockAtStartup = true;
76 kdDebug() << "MainWindow()::MainWindow()" << endl;
77// mFlagKeyPressed = false;
78 setCaption("KAddressbook/Pi");
79
80 KABPrefs *p = KABPrefs::instance();
81 if ( QApplication::desktop()->height() > 480 ) {
82//US if ( p->mHourSize == 4 )
83//US p->mHourSize = 6;
84 }
85
86 QMainWindow::ToolBarDock tbd;
87 if ( p->mToolBarHor ) {
88 if ( p->mToolBarUp )
89 tbd = Bottom;
90 else
91 tbd = Top;
92 }
93 else {
94 if ( p->mToolBarUp )
95 tbd = Right;
96 else
97 tbd = Left;
98 }
99
100 iconToolBar = new QPEToolBar( this );
101 addToolBar (iconToolBar , tbd );
102
103/*US
104 mBlockSaveFlag = false;
105 mCalendarModifiedFlag = false;
106*/
107 QLabel* splash = new QLabel(i18n("KA/Pi is starting ... "), this );
108 splash->setAlignment ( AlignCenter );
109 setCentralWidget( splash );
110#ifndef DESKTOP_VERSION
111 showMaximized();
112#endif
113 qDebug("Mainwidget x %d y %d w %d h %d", x(), y(), width(), height ());
114// setDefaultPreferences();
115/* mCalendar = new CalendarLocal();
116 mView = new CalendarView( mCalendar, this,"mCalendar " );
117 mView->hide();
118 //mView->resize(splash->size() );
119*/
120 initActions();
121
122#ifndef DESKTOP_VERSION
123//US iconToolBar->show();
124 qApp->processEvents();
125#endif
126 qDebug("Splashwidget x %d y %d w %d h %d", splash-> x(), splash->y(), splash->width(),splash-> height ());
127
128 int vh = height() ;
129 int vw = width();
130 qDebug("Toolbar hei %d ",iconToolBar->height() );
131/*US if ( iconToolBar->orientation () == Qt:: Horizontal ) {
132 vh -= iconToolBar->height();
133 } else {
134 vw -= iconToolBar->height();
135 }
136*/
137 //mView->setMaximumSize( splash->size() );
138 //mView->resize( splash->size() );
139 //qDebug("MainView x %d y %d w %d h %d", mView->x(),mView-> y(), mView->width(), mView->height ());
140/* mView->readSettings();
141 if( !QFile::exists( defaultFileName() ) ) {
142 mView->saveCalendar( defaultFileName() );
143 }
144 mView->openCalendar( defaultFileName() );
145 processIncidenceSelection( 0 );
146 connect( mView, SIGNAL( incidenceSelected( Incidence * ) ),
147 SLOT( processIncidenceSelection( Incidence * ) ) );
148 connect( mView, SIGNAL( modifiedChanged( bool ) ),
149 SLOT( slotModifiedChanged( bool ) ) );
150 connect( mView, SIGNAL( signalmodified() ),
151 SLOT( checkAlarms( ) ) );
152
153 connect( &mSaveTimer, SIGNAL( timeout() ), SLOT( save() ) );
154 connect( &alarmTimer, SIGNAL( timeout() ), SLOT( writeAlarm() ) );
155 mView->setModified( false );
156 mBlockAtStartup = false;
157 mView->setModified( false );
158 setCentralWidget( mView );
159 mView->show();
160*/
161 delete splash;
162
163 qApp->processEvents();
164//US qDebug("MainView x %d y %d w %d h %d", mView->x(),mView-> y(), mView->width(), mView->height ());
165
166}
167MainWindow::~MainWindow()
168{
169 qDebug("MainWindow::~MainWindow() ");
170 kdDebug() << "MainWindow()::~MainWindow()" << endl;
171 //save toolbar location
172/*
173 KOPrefs *p = KOPrefs::instance();
174 p->mToolBarHor = ( iconToolBar->orientation () == Qt:: Horizontal );
175 p->mToolBarUp = iconToolBar->x() > width()/2 ||
176 iconToolBar->y() > height()/2;
177 alarmTimer.stop();
178 mView->writeSettings();
179 writeAlarm();
180 if ( mCalendarModifiedFlag )
181 save();
182 delete mCalendar;
183*/
184}
185
186
187void MainWindow::closeEvent( QCloseEvent* ce )
188{
189
190 if ( ! KABPrefs::instance()->mAskForQuit ) {
191
192 ce->accept();
193 return;
194
195 }
196
197 switch( QMessageBox::information( this, "KA/Pi",
198 i18n("Do you really want\nto close KA/Pi?"),
199 i18n("Close!"), i18n("No"),
200 0, 0 ) ) {
201 case 0:
202 ce->accept();
203 break;
204 case 1:
205 ce->ignore();
206 break;
207 case 2:
208
209 default:
210 break;
211 }
212
213
214}
215
216
217void MainWindow::recieve( const QCString& cmsg, const QByteArray& data )
218{
219/*
220 QDataStream stream( data, IO_ReadOnly );
221 // QMessageBox::about( this, "About KOrganizer/Pi", "*" +msg +"*" );
222
223
224 if ( cmsg == "-writeFile" ) {
225 mView->viewManager()->showWhatsNextView();
226 save();
227 setCaption( i18n("File written on AD request"));
228 showMaximized();
229 raise();
230#ifndef DESKTOP_VERSION
231 QCopEnvelope e3("kosaved", "blabla");
232#endif
233 return;
234
235 }
236 if ( cmsg == "-newCountdown" ) {
237 qDebug("newCountdown ");
238
239 }
240 QString msg ;;
241 QString allmsg = cmsg;
242 while ( allmsg.length() > 0 ) {
243 int nextC = allmsg.find( "-", 1 );
244 if ( nextC == -1 ) {
245 msg = allmsg;
246 allmsg = "";
247 } else{
248 msg = allmsg.left( nextC );
249 allmsg = allmsg.mid( nextC, allmsg.length()-nextC );
250 }
251 //qDebug("msg: %s all: %s ", msg.latin1(), allmsg.latin1() );
252 if ( msg == "-newEvent" ) {
253 mView->newEvent();
254 }
255 if ( msg == "-newTodo" ) {
256 mView->newTodo();
257
258 }
259 if ( msg == "-showWN" ) {
260 mView->viewManager()->showWhatsNextView();
261 }
262 if ( msg == "-showTodo" ) {
263 mView->viewManager()->showTodoView();
264 }
265 if ( msg == "-showList" ) {
266 mView->viewManager()->showListView();
267 }
268 else if ( msg == "-showDay" ) {
269 mView->viewManager()->showDayView();
270 }
271 else if ( msg == "-showWWeek" ) {
272 mView->viewManager()->showWorkWeekView();
273 }
274 else if ( msg == "-showWeek" ) {
275 mView->viewManager()->showWeekView();
276 }
277 else if ( msg == "-showTodo" ) {
278 mView->viewManager()->showTodoView();
279 }
280 else if ( msg == "-showJournal" ) {
281 mView->viewManager()->showJournalView();
282 }
283 else if ( msg == "-showKO" ) {
284 mView->viewManager()->showNextXView();
285 }
286 else if ( msg == "-showWNext" ) {
287 mView->viewManager()->showWhatsNextView();
288 }
289 }
290
291 showMaximized();
292 raise();
293*/
294}
295
296
297QPixmap MainWindow::loadPixmap( QString name )
298{
299 return KGlobal::iconLoader().loadPixmap( name );
300/*US use the advanced version of the iconloader
301#ifdef DESKTOP_VERSION
302 QPixmap pixmapLoader;
303 QString file;
304 file = QDir::homeDirPath()+"/kaddressbook/pics/" + name+".png";
305 //qDebug("pixmap name %s ", file.latin1());
306 pixmapLoader.load( file );
307 return pixmapLoader;
308#else
309 return Resource::loadPixmap( name );
310#endif
311*/
312}
313
314void MainWindow::initActions()
315{
316 iconToolBar->clear();
317 KABPrefs *p = KABPrefs::instance();
318 QPEMenuBar *menuBar1 = new QPEMenuBar( iconToolBar );
319 QPopupMenu *menuBar = new QPopupMenu( this );
320 menuBar1->insertItem( "ME", menuBar);
321 QPopupMenu *fileMenu = new QPopupMenu( this );
322 QPopupMenu *editMenu = new QPopupMenu( this );
323 QPopupMenu *viewMenu = new QPopupMenu( this );
324 QPopupMenu *settingsMenu = new QPopupMenu( this );
325 QPopupMenu *importMenu = new QPopupMenu( this );
326
327 menuBar1->setMaximumWidth( menuBar1->sizeHint().width() );
328
329 QIconSet icon;
330
331
332 icon = loadPixmap( pathString + "newtodo" );
333 configureToolBarMenu->insertItem(icon, "New todo", 20 );
334 QAction* nt_action = new QAction( "New Todo", icon, "New Todo...", 0, this );
335 nt_action->addTo( actionMenu );
336 connect( nt_action, SIGNAL( activated() ),
337 mView, SLOT( newTodo() ) );
338
339/*
340 QAction *action;
341 QIconSet icon;
342 // QPopupMenu *configureMenu= new QPopupMenu( menuBar );
343 configureToolBarMenu = new QPopupMenu( this );
344 configureToolBarMenu->setCheckable( true );
345#ifdef DESKTOP_VERSION
346 QString pathString = "";
347#else
348 QString pathString = "kaddressbook/";
349#endif
350 if ( QApplication::desktop()->width() < 480 )
351 pathString += "icons16/";
352 configureAgendaMenu = new QPopupMenu( menuBar );
353 configureAgendaMenu->setCheckable( true );
354 configureAgendaMenu->insertItem("Toggle Allday", 1 );
355 configureAgendaMenu->insertSeparator();
356 configureAgendaMenu->insertItem("Tiny", 4 );
357 configureAgendaMenu->insertItem("Small", 6 );
358 configureAgendaMenu->insertItem("Medium", 8 );
359 configureAgendaMenu->insertItem("Normal", 10 );
360 configureAgendaMenu->insertItem("Large", 12 );
361 configureAgendaMenu->insertItem("Big", 14 );
362 configureAgendaMenu->insertItem("Bigger", 16 );
363 configureAgendaMenu->insertItem("Biggest", 18 );
364 //configureMenu->insertItem( "AgendaSize",configureAgendaMenu );
365 icon = loadPixmap( pathString + "newevent" );
366 icon = loadPixmap( pathString + "newevent" );
367 configureToolBarMenu->insertItem("Stretched TB", 5 );
368 configureToolBarMenu->insertSeparator();
369 configureToolBarMenu->insertItem(icon, "New event", 10 );
370 QAction* ne_action = new QAction( "New Event", icon, "New Event...", 0, this );
371 ne_action->addTo( actionMenu );
372*/
373/*
374 connect( ne_action, SIGNAL( activated() ),
375 mView, SLOT( newEvent() ) );
376 icon = loadPixmap( pathString + "newtodo" );
377 configureToolBarMenu->insertItem(icon, "New todo", 20 );
378 QAction* nt_action = new QAction( "New Todo", icon, "New Todo...", 0, this );
379 nt_action->addTo( actionMenu );
380 connect( nt_action, SIGNAL( activated() ),
381 mView, SLOT( newTodo() ) );
382
383 action = new QAction( "Toggle FilterView", QPixmap(), "Toggle FilterView", 0, this );
384 action->addTo( viewMenu );
385 connect( action, SIGNAL( activated() ),
386 mView, SLOT( toggleFilter() ) );
387
388 viewMenu->insertSeparator();
389 icon = loadPixmap( pathString + "picker" );
390 action = new QAction( "Date Picker", icon, "Date Picker", 0, this );
391 action->addTo( viewMenu );
392 connect( action, SIGNAL( activated() ),
393 mView, SLOT( showDatePicker() ) );
394 action->addTo( iconToolBar );
395 viewMenu->insertSeparator();
396 icon = loadPixmap( pathString + "list" );
397 configureToolBarMenu->insertItem(icon, "Event list", 30 );
398 QAction* showlist_action = new QAction( "List", icon, "List", 0, this );
399 showlist_action->addTo( viewMenu );
400 connect( showlist_action, SIGNAL( activated() ),
401 mView->viewManager(), SLOT( showListView() ) );
402
403
404 icon = loadPixmap( pathString + "day" );
405 configureToolBarMenu->insertItem(icon, "One day", 40 );
406 QAction* day1_action = new QAction( "Day", icon, "Day", 0, this );
407 day1_action->addTo( viewMenu );
408 // action->addTo( toolBar );
409 connect( day1_action, SIGNAL( activated() ),
410 mView->viewManager(), SLOT( showDayView() ) );
411
412 icon = loadPixmap( pathString + "workweek" );
413 configureToolBarMenu->insertItem(icon, "Work week", 50 );
414 QAction* day5_action = new QAction( "Work Week", icon, "Work Week", 0, this );
415 day5_action->addTo( viewMenu );
416 connect( day5_action, SIGNAL( activated() ),
417 mView->viewManager(), SLOT( showWorkWeekView() ) );
418
419 icon = loadPixmap( pathString + "week" );
420 configureToolBarMenu->insertItem(icon, "Week", 60 );
421 QAction* day7_action = new QAction( "Week", icon, "Week", 0, this );
422 day7_action->addTo( viewMenu );
423 connect( day7_action, SIGNAL( activated() ),
424 mView->viewManager(), SLOT( showWeekView() ) );
425
426 icon = loadPixmap( pathString + "month" );
427 configureToolBarMenu->insertItem(icon, "Month", 70 );
428 QAction* month_action = new QAction( "Month", icon, "Month", 0, this );
429 month_action->addTo( viewMenu );
430 connect( month_action, SIGNAL( activated() ),
431 mView->viewManager(), SLOT( showMonthView() ) );
432
433 icon = loadPixmap( pathString + "todo" );
434 configureToolBarMenu->insertItem(icon, "Todo list", 80 );
435 QAction* todoview_action = new QAction( "Todo", icon, "Todo", 0, this );
436 todoview_action->addTo( viewMenu );
437 connect( todoview_action, SIGNAL( activated() ),
438 mView->viewManager(), SLOT( showTodoView() ) );
439
440 icon = loadPixmap( pathString + "journal" );
441 configureToolBarMenu->insertItem(icon, "Journal", 90 );
442 QAction* viewjournal_action = new QAction( "Journal", icon, "Journal", 0, this );
443 viewjournal_action->addTo( viewMenu );
444 connect( viewjournal_action, SIGNAL( activated() ),
445 mView->viewManager(), SLOT( showJournalView() ) );
446
447 icon = loadPixmap( pathString + "xdays" );
448 configureToolBarMenu->insertItem(icon, "Next days", 100,4 );
449 QAction* xdays_action = new QAction( "Next days", icon, "Next Days", 0, this );
450 xdays_action->addTo( viewMenu );
451 connect( xdays_action, SIGNAL( activated() ),
452 mView->viewManager(), SLOT( showNextXView() ) );
453
454 icon = loadPixmap( pathString + "whatsnext" );
455 configureToolBarMenu->insertItem(icon, "Whats next", 110, 4 );
456 QAction* whatsnext_action = new QAction( "What's Next", icon, "What's Next", 0, this );
457 whatsnext_action->addTo( viewMenu );
458 connect( whatsnext_action, SIGNAL( activated() ),
459 mView->viewManager(), SLOT( showWhatsNextView() ) );
460
461#if 0
462 action = new QAction( "view_timespan", "Time Span", 0, this );
463 action->addTo( viewMenu );
464 connect( action, SIGNAL( activated() ),
465 mView->viewManager(), SLOT( showTimeSpanView() ) );
466#endif
467
468 menuBar->insertItem( "View", viewMenu );
469
470
471#if 0
472 QPopupMenu *navigationMenu = new QPopupMenu( menuBar );
473
474 action = new QAction( "Go backward", "Go Backward", 0, navigationMenu );
475 action->addTo( navigationMenu );
476 connect( action, SIGNAL( activated() ),
477 mView, SLOT( goPrevious() ) );
478
479 action = new QAction( "Go forward", "Go Forward", 0, navigationMenu );
480 action->addTo( navigationMenu );
481 connect( action, SIGNAL( activated() ),
482 mView, SLOT( goNext() ) );
483
484 menuBar->insertItem( "Go", navigationMenu );
485#endif
486
487
488
489
490
491
492 mNewSubTodoAction = new QAction( "new_subtodo", "New Sub-Todo...", 0,
493 this );
494 mNewSubTodoAction->addTo( actionMenu );
495 connect( mNewSubTodoAction, SIGNAL( activated() ),
496 mView, SLOT( newSubTodo() ) );
497
498 actionMenu->insertSeparator();
499
500 mShowAction = new QAction( "show_incidence", "Show...", 0, this );
501 mShowAction->addTo( actionMenu );
502 connect( mShowAction, SIGNAL( activated() ),
503 mView, SLOT( showIncidence() ) );
504
505 mEditAction = new QAction( "edit_incidence", "Edit...", 0, this );
506 mEditAction->addTo( actionMenu );
507 connect( mEditAction, SIGNAL( activated() ),
508 mView, SLOT( editIncidence() ) );
509
510 mDeleteAction = new QAction( "delete_incidence", "Delete...", 0, this );
511 mDeleteAction->addTo( actionMenu );
512 connect( mDeleteAction, SIGNAL( activated() ),
513 mView, SLOT( deleteIncidence() ) );
514
515 actionMenu->insertSeparator();
516
517 action = new QAction( "purge_completed", i18n("Purge Completed"), 0,
518 this );
519 action->addTo( actionMenu );
520 connect( action, SIGNAL( activated() ), mView, SLOT( purgeCompleted() ) );
521
522 icon = loadPixmap( pathString + "search" );
523 QAction* search_action = new QAction( "search", icon, "Search...", 0, this );
524 configureToolBarMenu->insertItem(icon, "Search", 120 , 4);
525 search_action->addTo( actionMenu );
526 connect( search_action, SIGNAL( activated() ),
527 mView->dialogManager(), SLOT( showSearchDialog() ) );
528
529 icon = loadPixmap( pathString + "today" );
530 configureToolBarMenu->insertItem(icon, "Today", 130);
531 QAction* today_action = new QAction( "Today", icon, "Go to Today", 0, this );
532 today_action->addTo( actionMenu );
533 connect( today_action, SIGNAL( activated() ),
534 mView, SLOT( goToday() ) );
535
536 //#if 0
537 actionMenu->insertSeparator();
538
539 action = new QAction( "configure", "Configure...", 0, this );
540 action->addTo( actionMenu );
541 connect( action, SIGNAL( activated() ),
542 mView, SLOT( edit_options() ) );
543 //#endif
544
545 // actionMenu->insertSeparator();
546 action = new QAction( "import_qtopia", "Import (*.ics/*.vcs) file", 0,
547 this );
548 action->addTo( importMenu );
549 connect( action, SIGNAL( activated() ), SLOT( importIcal() ) );
550 action = new QAction( "import_quick", "Import last file", 0,
551 this );
552 action->addTo( importMenu );
553 connect( action, SIGNAL( activated() ), SLOT( quickImportIcal() ) );
554 importMenu->insertSeparator();
555 action = new QAction( "import_qtopia", "Import Opie/Qtopia Cal.", 0,
556 this );
557 action->addTo( importMenu );
558 importMenu->insertSeparator();
559 connect( action, SIGNAL( activated() ), SLOT( importQtopia() ) );
560
561 action = new QAction( "load_cal", "Load Calendar Backup", 0,
562 this );
563 action->addTo( importMenu );
564 connect( action, SIGNAL( activated() ), SLOT( loadCalendar() ) );
565
566 action = new QAction( "save_cal", "Save Calendar Backup", 0,
567 this );
568 action->addTo( importMenu );
569 connect( action, SIGNAL( activated() ), SLOT( saveCalendar() ) );
570
571 importMenu->insertSeparator();
572 action = new QAction( "import_qtopia", "Export VCalendar", 0,
573 this );
574 action->addTo( importMenu );
575 connect( action, SIGNAL( activated() ), SLOT( exportVCalendar() ) );
576
577
578 QPopupMenu *syncMenu = new QPopupMenu( this );
579 action = new QAction( "syncssh", "Remote via ssh/scp(not implemented)", 0,
580 this );
581 action->addTo( syncMenu );
582 connect( action, SIGNAL( activated() ), SLOT( syncSSH() ) );
583 action = new QAction( "synclocal", "With local file(not implemented)", 0,
584 this );
585 action->addTo( syncMenu );
586 connect( action, SIGNAL( activated() ), SLOT( syncLocalFile() ) );
587 action = new QAction( "quicksynclocal", "With last file(not implemented)", 0,
588 this );
589 action->addTo( syncMenu );
590 connect( action, SIGNAL( activated() ), SLOT( quickSyncLocalFile() ) );
591
592 menuBar->insertItem( "Actions", actionMenu );
593 menuBar->insertItem( "Load/Save", importMenu );
594 menuBar->insertItem( "Synchronize", syncMenu );
595 //menuBar->insertItem( "Configure",configureMenu );
596 //configureMenu->insertItem( "Toolbar",configureToolBarMenu );
597 menuBar->insertItem( "AgendaSize",configureAgendaMenu );
598 menuBar->insertItem( "Toolbar",configureToolBarMenu );
599 QPopupMenu *helpMenu = new QPopupMenu( menuBar );
600 icon = loadPixmap( "korganizer/korganizer" );
601 action = new QAction( "Key bindings", "Key Bindings...", 0, this );
602 action->addTo( helpMenu );
603 connect( action, SIGNAL( activated() ),
604 SLOT( keyBindings() ) );
605 action = new QAction( "Auto saving", "Auto saving...", 0, this );
606 action->addTo( helpMenu );
607 connect( action, SIGNAL( activated() ),
608 SLOT( aboutAutoSaving() ) );
609 action = new QAction( "Problemd", "Known Problems...", 0,this );
610 action->addTo( helpMenu );
611 connect( action, SIGNAL( activated() ),
612 SLOT( aboutKnownBugs() ) );
613 action = new QAction( "about", "About...", 0, this );
614 action->addTo( helpMenu );
615 connect( action, SIGNAL( activated() ),
616 SLOT( about() ) );
617 menuBar->insertItem( "Help", helpMenu );
618*/
619 //menuBar->insertSeparator();
620
621 // ******************************************************
622 // menubar icons
623
624
625 iconToolBar->setHorizontalStretchable (true );
626 //menuBar->insertItem( iconToolBar );
627 //xdays_action
628/*
629 if (p-> mShowIconNewEvent)
630 ne_action->addTo( iconToolBar );
631 if (p->mShowIconNewTodo )
632 nt_action->addTo( iconToolBar );
633 if (p-> mShowIconSearch)
634 search_action->addTo( iconToolBar );
635 if (p-> mShowIconNext)
636 whatsnext_action->addTo( iconToolBar );
637 if (p-> mShowIconNextDays)
638 xdays_action->addTo( iconToolBar );
639 if (p-> mShowIconList)
640 showlist_action->addTo( iconToolBar );
641 if (p-> mShowIconDay1)
642 day1_action->addTo( iconToolBar );
643 if (p-> mShowIconDay5)
644 day5_action->addTo( iconToolBar );
645 if (p-> mShowIconDay7)
646 day7_action->addTo( iconToolBar );
647 if (p-> mShowIconMonth)
648 month_action->addTo( iconToolBar );
649 if (p-> mShowIconTodoview)
650 todoview_action->addTo( iconToolBar );
651 if (p-> mShowIconJournal)
652 viewjournal_action->addTo( iconToolBar );
653 icon = loadPixmap( pathString + "2leftarrowB" );
654 configureToolBarMenu->insertItem(icon, "Prev. month", 200, 14);
655 if (p-> mShowIconBackFast) {
656 action = new QAction( "Prev month", icon, "Go Backward",0 , this );
657 connect( action, SIGNAL( activated() ),
658 mView, SLOT( goPreviousMonth() ) );
659 action->addTo( iconToolBar );
660 }
661 icon = loadPixmap( pathString + "1leftarrowB" );
662 configureToolBarMenu->insertItem(icon, "Go previous", 210,15);
663 if (p-> mShowIconBack) {
664 action = new QAction( "Go previous", icon, "Go Backward",0 , this );
665 connect( action, SIGNAL( activated() ),
666 mView, SLOT( goPrevious() ) );
667 action->addTo( iconToolBar );
668 }
669 if (p-> mShowIconToday)
670 today_action->addTo( iconToolBar );
671 icon = loadPixmap( pathString + "1rightarrowB" );
672 configureToolBarMenu->insertItem(icon, "Go next", 220);
673 if (p-> mShowIconForward) {
674 action = new QAction( "Go next", icon, "Go Backward",0 , this );
675 connect( action, SIGNAL( activated() ),
676 mView, SLOT( goNext() ) );
677 action->addTo( iconToolBar );
678 }
679 icon = loadPixmap( pathString + "2rightarrowB" );
680 configureToolBarMenu->insertItem(icon, "Next month", 230);
681 if (p-> mShowIconForwardFast) {
682 action = new QAction( "Next month", icon, "Go Backward",0 , this );
683 connect( action, SIGNAL( activated() ),
684 mView, SLOT( goNextMonth() ) );
685 action->addTo( iconToolBar );
686 }
687*/
688
689 configureToolBarMenu->insertItem("WhatsThis", 300);
690/*
691 if (p-> mShowIconNewEvent)
692 configureToolBarMenu->setItemChecked( 10, true );
693 if (p->mShowIconNewTodo )
694 configureToolBarMenu->setItemChecked( 20, true );
695 if (p-> mShowIconSearch)
696 configureToolBarMenu->setItemChecked( 120, true );
697 if (p-> mShowIconList)
698 configureToolBarMenu->setItemChecked( 30, true );
699 if (p-> mShowIconDay1)
700 configureToolBarMenu->setItemChecked( 40, true );
701 if (p-> mShowIconDay5)
702 configureToolBarMenu->setItemChecked( 50, true );
703 if (p-> mShowIconDay7)
704 configureToolBarMenu->setItemChecked( 60, true );
705 if (p-> mShowIconMonth)
706 configureToolBarMenu->setItemChecked( 70, true );
707 if (p-> mShowIconTodoview)
708 configureToolBarMenu->setItemChecked( 80, true );
709 if (p-> mShowIconBackFast)
710 configureToolBarMenu->setItemChecked( 200, true );
711 if (p-> mShowIconBack)
712 configureToolBarMenu->setItemChecked( 210, true );
713 if (p-> mShowIconToday)
714 configureToolBarMenu->setItemChecked( 130, true );
715 if (p-> mShowIconForward)
716 configureToolBarMenu->setItemChecked( 220, true );
717 if (p-> mShowIconForwardFast)
718 configureToolBarMenu->setItemChecked( 230, true );
719 if (p-> mShowIconNextDays)
720 configureToolBarMenu->setItemChecked( 100, true );
721 if (p-> mShowIconNext)
722 configureToolBarMenu->setItemChecked( 110, true );
723 if (p-> mShowIconJournal)
724 configureToolBarMenu->setItemChecked( 90, true );
725 if (p-> mShowIconWhatsThis)
726 configureToolBarMenu->setItemChecked( 300, true );
727
728 QLabel* dummy = new QLabel( iconToolBar );
729 dummy->setBackgroundColor( iconToolBar->backgroundColor() );
730 if (!p-> mShowIconStretch)
731 iconToolBar->setStretchableWidget ( dummy ) ;
732 else
733 configureToolBarMenu->setItemChecked( 5, true );
734 if (p-> mShowIconWhatsThis)
735 QWhatsThis::whatsThisButton ( iconToolBar );
736 connect( configureToolBarMenu, SIGNAL( activated( int ) ),this, SLOT(configureToolBar( int ) ) );
737 configureAgenda( p->mHourSize );
738 connect( configureAgendaMenu, SIGNAL( activated( int ) ),this, SLOT(configureAgenda( int ) ) );
739*/
740}
741/*
742void MainWindow::setDefaultPreferences()
743{
744 KOPrefs *p = KOPrefs::instance();
745
746 p->mCompactDialogs = true;
747 p->mConfirm = true;
748 p->mEnableQuickTodo = false;
749}
750*/
751void MainWindow::about()
752{
753 QMessageBox::about( this, "About KOrganizer/Pi",
754 "KOrganizer/Platform-independent\n"
755 "(KO/Pi) 1.6.0e - "
756#ifdef DESKTOP_VERSION
757 "Desktop Edition\n"
758#else
759 "PDA-Edition\n"
760 "for: Zaurus 5500 / 7x0 / 8x0\n"
761#endif
762 "(c) 2004 Lutz Rogowski\n"
763 "Email:lutz@pi-sync.net\n"
764 "KO/Pi is based on KOrganizer\n"
765 "(c) 2002,2003 Cornelius Schumacher\n"
766 "Email: schumacher@kde.org\n"
767 "KOrganizer/Pi is licensed\n"
768 "under the GPL.\n"
769 "KO/Pi can be compiled for\n"
770 "Linux, Zaurus-PDA and Windows\n"
771 "www.korganizer.org\n" );
772}
773/*
774void MainWindow::keyBindings()
775{
776 QMessageBox* msg;
777 msg = new QMessageBox( "Key bindings KOrganizer/Pi",
778 "Space: Toggle Fullscreen | P: Date Picker\n"
779 "H: This dialog | I: Show info | S: Search\n"
780 "F: Toggle Filterview | 1-4: Select Filter\n"
781 "N: Show next days | W: Whats next\n "
782 "V: Todo view | L: Event list view\n"
783 "T: Goto today | T+<ctrl>: New Todo\n"
784 "E: Edit item | E+<ctrl>: New Event\n"
785 "5: Work week view | 7: Week view\n"
786 "D: One day view | M: Month view\n"
787 "+,- : Zoom in/out Agenda | A: Toggle Allday\n"
788 "<ctrl>+<up>/<down>: Scroll todo view\n"
789 "<right>,C: Next week | <right>+<ctrl>: Next month\n"
790 "<left>,X: Prev. week | <left>+<ctrl>: Prev. month\n"
791 "<del>,<backspace>: Delete sel. item\n",
792 QMessageBox::NoIcon,
793 QMessageBox::Ok,
794 QMessageBox::NoButton,
795 QMessageBox::NoButton );
796 msg->exec();
797 delete msg;
798
799}
800void MainWindow::aboutAutoSaving()
801{
802 QMessageBox* msg;
803 msg = new QMessageBox( "Auto Saving in KOrganizer/Pi",
804 "After changing something, the data is\n"
805 "automatically saved to the file\n"
806 "~/Applications/korganizer/mycalendar.ics\n "
807 "after (configureable) one minute.\n"
808 "For safety reasons there is one autosaving\n"
809 "after 10 minutes (of idle time) again. The \n"
810 "data is saved automatically when closing KO/Pi\n"
811 "You can create a backup file \n"
812 "with: Load/Save - Save Calendar Backup\n",
813 QMessageBox::NoIcon,
814 QMessageBox::Ok,
815 QMessageBox::NoButton,
816 QMessageBox::NoButton);
817 msg->exec();
818 delete msg;
819
820
821}
822void MainWindow::aboutKnownBugs()
823{
824 QMessageBox* msg;
825 msg = new QMessageBox( "Known Problems in KOrganizer/Pi",
826 "1) The QWhatsThis help is not working.\n"
827 "There is only a black rectangle displayed\n"
828 "when clicking on an event.\n "
829 "2) Audio alarm is available!\n"
830 "as an additional small application\n"
831 "3) Syncing is missing.\n"
832 "Syncing via ssh/scp will be available in\n"
833 "KOrganizer/Pi 2.0\n"
834 "\n"
835 "Please report unexpected behaviour to\n"
836 "lutz@pi-sync.net\n",
837 QMessageBox::NoIcon,
838 QMessageBox::Ok,
839 QMessageBox::NoButton,
840 QMessageBox::NoButton);
841 msg->exec();
842 delete msg;
843
844}
845
846QString MainWindow::defaultFileName()
847{
848#ifndef DESKTOP_VERSION
849 return Global::applicationFileName( "korganizer", "mycalendar.ics" );
850#else
851 // pending
852 QString file;
853 file = QDir::homeDirPath()+"/korganizer/mycalendar.ics";
854 return QDir::convertSeparators( file );
855#endif
856}
857
858void MainWindow::processIncidenceSelection( Incidence *incidence )
859{
860 if ( !incidence ) {
861 enableIncidenceActions( false );
862
863 mNewSubTodoAction->setEnabled( false );
864 setCaptionToDates();
865 return;
866
867 }
868
869 QString startString = "";
870 if ( incidence->type() != "Todo" ) {
871 if ( incidence->dtStart().date() < incidence->dtEnd().date() ) {
872 startString = ": "+incidence->dtStart().time().toString().left(5);
873 startString += " "+ incidence->dtStart().date().toString();
874 startString += "-"+incidence->dtEnd().time().toString().left(5);
875 startString += " "+ incidence->dtEnd().date().toString();
876
877 } else {
878 if ( incidence->dtStart().time() != incidence->dtEnd().time() )
879 startString = ": "+incidence->dtStart().time().toString().left(5)+"-"+incidence->dtEnd().time().toString().left(5);
880 startString +=" "+incidence->dtStart().date().toString();
881 }
882
883 }
884 else
885 startString = ": (Prio "+QString::number( (( KCal::Todo*)incidence)->priority() ) +") "+QString::number( (( KCal::Todo*)incidence)->percentComplete() ) +"\% completed";
886
887 setCaption( incidence->summary()+startString);
888
889 enableIncidenceActions( true );
890
891 if ( incidence->type() == "Event" ) {
892 mShowAction->setText( i18n("Show Event...") );
893 mEditAction->setText( i18n("Edit Event...") );
894 mDeleteAction->setText( i18n("Delete Event...") );
895
896 mNewSubTodoAction->setEnabled( false );
897 } else if ( incidence->type() == "Todo" ) {
898 mShowAction->setText( i18n("Show Todo...") );
899 mEditAction->setText( i18n("Edit Todo...") );
900 mDeleteAction->setText( i18n("Delete Todo...") );
901
902 mNewSubTodoAction->setEnabled( true );
903 } else {
904 mShowAction->setText( i18n("Show...") );
905 mShowAction->setText( i18n("Edit...") );
906 mShowAction->setText( i18n("Delete...") );
907
908 mNewSubTodoAction->setEnabled( false );
909 }
910}
911
912void MainWindow::enableIncidenceActions( bool enabled )
913{
914 mShowAction->setEnabled( enabled );
915 mEditAction->setEnabled( enabled );
916 mDeleteAction->setEnabled( enabled );
917}
918
919void MainWindow::importQtopia()
920{
921#ifndef DESKTOP_VERSION
922 int result = QMessageBox::warning( this, "KO/Pi: Warning!",
923 "When importing a calendar twice\n"
924 "duplicated events will be ignored!\n"
925 "You can create a backup file with\n"
926 "Load/Save - Save Calendar Backup\n"
927 "to revert importing",
928 "Import!", "Cancel", 0,
929 0, 1 );
930 if ( result == 0 ) {
931 QString datebook = Global::applicationFileName( "datebook", "datebook.xml");
932 QString todolist = Global::applicationFileName( "todolist", "todolist.xml");
933 QString categories = QString( getenv( "HOME" ) ) + "/Settings/Categories.xml";
934 mView->importQtopia( categories, datebook, todolist );
935 }
936#else
937 int result = QMessageBox::warning( this, "KO/Pi: Warning!",
938 "NOT SUPPORTED \n"
939 "ON DESKTOP!\n",
940 "OK", "Cancel", 0,
941 0, 1 );
942
943#endif
944}
945void MainWindow::checkAlarms()
946{
947 if ( mBlockAtStartup )
948 return;
949 alarmTimer.start( 1000 * 3);
950
951}
952void MainWindow::slotModifiedChanged( bool changed )
953{
954 if ( mBlockAtStartup )
955 return;
956 int msec;
957 // we store the changes after 1 minute,
958 // and for safety reasons after 10 minutes again
959 if ( !mBlockSaveFlag )
960 msec = (1000 * 60*KOPrefs::instance()->mAutoSaveInterval) +1000;
961 else
962 msec = 1000 * 600;
963 mSaveTimer.start( msec, true ); // 1 minute
964 qDebug("KO: Saving File in %d secs!", msec/1000);
965 mCalendarModifiedFlag = true;
966}
967void MainWindow::writeAlarm()
968{
969 if ( mBlockAtStartup )
970 return;
971 //QCopEnvelope e3("koalarm", "-showWN");
972 QDateTime nextA ;
973 QDateTime reference ( QDate( 2000, 1, 1 ) );
974 QString summary;
975 alarmTimer.stop();
976 Calendar* cal = mView->calendar();
977 if ( ! cal ){
978 qDebug("KO: Calendar undefined. No alarm notification");
979 return;
980 }
981 nextA = cal->nextAlarm( 720 );
982 summary = cal->nextSummary();
983 qDebug("KO: Next Alarm %s %s", nextA.toString().latin1(), summary.latin1());
984 if ( nextA < QDateTime::currentDateTime().addDays( 720-1 ) ) {
985 KConfig *config = KOGlobals::config();
986 config->setGroup("NextSystemAlarm");
987 QString date, sum;
988 date = config->readEntry("TimeDateinSecs", "xxx");
989 bool ok = false;
990 int shsecs = date.toInt(&ok );
991 QDateTime scheduledAlarm;
992 QDateTime eventDateTime = cal->nextAlarmEvent();
993 sum = config->readEntry("Summary", "sss");
994 if ( ok ) {
995 scheduledAlarm = reference.addSecs( shsecs );
996 //qDebug("sheduledAlarm %s ", scheduledAlarm.toString().latin1());
997 if ( scheduledAlarm == nextA && sum == summary ) {
998 qDebug("KO: Same alarm time+summary - nothing to do! ");
999 return;
1000 }
1001 }
1002 if ( ok ) {
1003 // delete alarm from system
1004 //qDebug("delete Alarm %s ", scheduledAlarm.toString().latin1());
1005#ifndef DESKTOP_VERSION
1006 AlarmServer::deleteAlarm ( scheduledAlarm,"koalarm" , sum.latin1() );
1007#endif
1008 }
1009 // add new alarm to system
1010 qDebug("KO: Add Alarm: %s ", nextA.toString().latin1() );
1011#ifndef DESKTOP_VERSION
1012 AlarmServer::addAlarm ( nextA,"koalarm", summary.latin1() );
1013#endif
1014 // write new alarm to config file
1015 //qDebug("Entry %s %s ", date.latin1(), sum.latin1());
1016 int secs = reference.secsTo( nextA );
1017 //qDebug(" secs %d ", secs);
1018 setCaption( i18n("Next Alarm: ")+ nextA.toString() +"-"+summary );
1019 config->writeEntry("TimeDateinSecs",QString::number ( secs ));
1020 config->writeEntry("Summary",summary);
1021 config->writeEntry("TimeDate",nextA.toString());
1022 config->writeEntry("WriteDateTime",QDateTime::currentDateTime().toString());
1023 config->writeEntry("EventStartDateTime",eventDateTime.toString());
1024 config->writeEntry("SystemNotifyInSecs",QString::number (QDateTime::currentDateTime().secsTo( nextA ) ));
1025 config->sync();
1026
1027 }
1028}
1029void MainWindow::save()
1030{
1031 if ( mBlockSaveFlag )
1032 return;
1033
1034 mBlockSaveFlag = true;
1035 QTime neededSaveTime = QDateTime::currentDateTime().time();
1036 setCaption("KO/Pi:Saving Data to File ..." );
1037 qDebug("KO: Start saving data to file!");
1038 mView->saveCalendar( defaultFileName() );
1039 int msNeeded = neededSaveTime.msecsTo( QDateTime::currentDateTime().time() );
1040 qDebug("KO: Needed %d ms for saving.",msNeeded );
1041 QString savemes;
1042 savemes.sprintf("KO/Pi:File Saved. Needed %d sec, %d ms",(msNeeded/1000)%100,msNeeded%1000 );
1043 setCaption(savemes);
1044 mCalendarModifiedFlag = false;
1045 mBlockSaveFlag = false;
1046}
1047
1048void MainWindow::keyReleaseEvent ( QKeyEvent * e)
1049{
1050 if ( !e->isAutoRepeat() ) {
1051 mFlagKeyPressed = false;
1052 }
1053}
1054void MainWindow::keyPressEvent ( QKeyEvent * e )
1055{
1056 qApp->processEvents();
1057 if ( e->isAutoRepeat() && !mFlagKeyPressed ) {
1058 e->ignore();
1059 // qDebug(" ignore %d",e->isAutoRepeat() );
1060 return;
1061 }
1062 if (! e->isAutoRepeat() )
1063 mFlagKeyPressed = true;
1064 KOPrefs *p = KOPrefs::instance();
1065 bool showSelectedDates = false;
1066 int size;
1067 //qDebug("MainWindow::keyPressEvent ");
1068 switch ( e->key() ) {
1069 case Qt::Key_Right:
1070 if ( e->state() == Qt::ControlButton )
1071 mView->goNextMonth();
1072 else
1073 mView->goNext();
1074 showSelectedDates = true;
1075 break;
1076 case Qt::Key_Left:
1077 if ( e->state() == Qt::ControlButton )
1078 mView->goPreviousMonth();
1079 else
1080 mView->goPrevious();
1081 showSelectedDates = true;
1082 break;
1083 case Qt::Key_Down:
1084 mView->viewManager()->agendaView()->scrollOneHourDown();
1085 break;
1086 case Qt::Key_Up:
1087 mView->viewManager()->agendaView()->scrollOneHourUp();
1088 break;
1089 case Qt::Key_I:
1090 mView->showIncidence();
1091 break;
1092 case Qt::Key_Delete:
1093 case Qt::Key_Backspace:
1094 mView->deleteIncidence();
1095 break;
1096 case Qt::Key_D:
1097 mView->viewManager()->showDayView();
1098 showSelectedDates = true;
1099 break;
1100 case Qt::Key_0:
1101 mView->toggleFilerEnabled( );
1102 break;
1103 case Qt::Key_1:
1104 mView->selectFilter( 0 );
1105 break;
1106 case Qt::Key_2:
1107 mView->selectFilter( 1 );
1108 break;
1109 case Qt::Key_3:
1110 mView->selectFilter( 2 );
1111 break;
1112 case Qt::Key_4:
1113 mView->selectFilter( 3 );
1114 break;
1115 case Qt::Key_5:
1116 mView->viewManager()->showWorkWeekView();
1117 showSelectedDates = true;
1118 break;
1119 case Qt::Key_7:
1120 mView->viewManager()->showWeekView();
1121 showSelectedDates = true;
1122 break;
1123 case Qt::Key_M:
1124 mView->viewManager()->showMonthView();
1125 showSelectedDates = true;
1126 break;
1127 case Qt::Key_Insert:
1128 mView->newEvent();
1129 break;
1130 case Qt::Key_S :
1131 mView->dialogManager()->showSearchDialog();
1132 break;
1133 case Qt::Key_H :
1134 keyBindings();
1135 break;
1136 case Qt::Key_W:
1137 mView->viewManager()->showWhatsNextView();
1138 break;
1139 case Qt::Key_L:
1140 mView->viewManager()->showListView();
1141 break;
1142 case Qt::Key_N:
1143 mView->viewManager()->showNextXView();
1144 showSelectedDates = true;
1145 break;
1146 case Qt::Key_V:
1147 mView->viewManager()->showTodoView();
1148 break;
1149 case Qt::Key_C:
1150 mView->goNext();
1151 showSelectedDates = true;
1152 break;
1153 case Qt::Key_P:
1154 mView->showDatePicker( );
1155 break;
1156 case Qt::Key_F:
1157 mView->toggleFilter();
1158 break;
1159 case Qt::Key_X:
1160 mView->goPrevious();
1161 showSelectedDates = true;
1162 break;
1163 case Qt::Key_Space:
1164 mView->toggleExpand();
1165 break;
1166 case Qt::Key_A:
1167 mView->toggleAllDaySize();
1168 break;
1169 case Qt::Key_T:
1170 if ( e->state() == Qt::ControlButton )
1171 mView->newTodo();
1172 else {
1173 mView->goToday();
1174 showSelectedDates = true;
1175 }
1176 break;
1177 case Qt::Key_J:
1178 mView->viewManager()->showJournalView();
1179 break;
1180 case Qt::Key_Return:
1181 case Qt::Key_E:
1182 if ( e->state() == Qt::ControlButton )
1183 mView->newEvent();
1184 else
1185 mView->editIncidence();
1186 break;
1187 case Qt::Key_Plus:
1188 size = p->mHourSize +2;
1189 if ( size <= 18 )
1190 configureAgenda( size );
1191 break;
1192 case Qt::Key_Minus:
1193 size = p->mHourSize - 2;
1194 if ( size >= 4 )
1195 configureAgenda( size );
1196 break;
1197
1198
1199 default:
1200 e->ignore();
1201 }
1202
1203 if ( showSelectedDates ) {
1204 ;// setCaptionToDates();
1205 }
1206
1207}
1208
1209void MainWindow::configureToolBar( int item )
1210{
1211
1212 configureToolBarMenu->setItemChecked( item, !configureToolBarMenu-> isItemChecked ( item ) );
1213 KOPrefs *p = KOPrefs::instance();
1214 p-> mShowIconStretch= configureToolBarMenu->isItemChecked( 5 );
1215 p-> mShowIconNewEvent= configureToolBarMenu->isItemChecked( 10 );
1216 p->mShowIconNewTodo = configureToolBarMenu->isItemChecked( 20 );
1217 p-> mShowIconSearch= configureToolBarMenu->isItemChecked( 120 );
1218 p-> mShowIconList= configureToolBarMenu->isItemChecked( 30 );
1219 p-> mShowIconDay1= configureToolBarMenu->isItemChecked( 40 );
1220 p-> mShowIconDay5= configureToolBarMenu->isItemChecked( 50 );
1221 p-> mShowIconDay7= configureToolBarMenu->isItemChecked( 60 );
1222 p-> mShowIconMonth= configureToolBarMenu->isItemChecked( 70 );
1223 p-> mShowIconTodoview= configureToolBarMenu->isItemChecked( 80 );
1224 p-> mShowIconBackFast= configureToolBarMenu->isItemChecked( 200 );
1225 p-> mShowIconBack = configureToolBarMenu->isItemChecked( 210 );
1226 p-> mShowIconToday= configureToolBarMenu->isItemChecked( 130 );
1227 p-> mShowIconForward= configureToolBarMenu->isItemChecked( 220 );
1228 p-> mShowIconForwardFast= configureToolBarMenu->isItemChecked( 230 );
1229 p-> mShowIconNextDays= configureToolBarMenu->isItemChecked( 100 );
1230 p-> mShowIconNext= configureToolBarMenu->isItemChecked( 110 );
1231 p-> mShowIconJournal= configureToolBarMenu->isItemChecked( 90 );
1232 p-> mShowIconWhatsThis= configureToolBarMenu->isItemChecked( 300 );
1233 initActions();
1234}
1235
1236void MainWindow::setCaptionToDates()
1237{
1238 QString selDates;
1239 selDates = mView->startDate().toString();
1240 if (mView->startDate() < mView->endDate() )
1241 selDates += " - " + mView->endDate().toString();
1242 setCaption( "Dates: " + selDates );
1243
1244}
1245// parameter item == 0: reinit
1246void MainWindow::configureAgenda( int item )
1247{
1248
1249 KOPrefs *p = KOPrefs::instance();
1250
1251 int i;
1252 if ( item == 1 ) {
1253 mView->toggleAllDaySize();
1254 return;
1255 }
1256 // do not allow 4 for widgets higher than 480
1257 if ( QApplication::desktop()->height() > 480 ) {
1258 if ( item == 4 )
1259 item = 6;
1260 }
1261 for ( i = 4; i <= 18; i= i+2 )
1262 configureAgendaMenu->setItemChecked( i, false );
1263 configureAgendaMenu->setItemChecked( item, true );
1264 if ( p->mHourSize == item )
1265 return;
1266 p->mHourSize=item;
1267 mView->viewManager()->agendaView()->updateConfig();
1268}
1269
1270void MainWindow::saveCalendar()
1271{
1272 QString fn = KOPrefs::instance()->mLastSaveFile;
1273 fn = KFileDialog::getSaveFileName( fn, "Save backup filename", this );
1274
1275 if ( fn == "" )
1276 return;
1277 QFileInfo info;
1278 info.setFile( fn );
1279 QString mes;
1280 bool createbup = true;
1281 if ( info. exists() ) {
1282 mes.sprintf( "Backup file\nalready exists!\nOld backup file from:\n%s\nOverwrite?\n",info.lastModified ().toString().latin1() );
1283 int result = QMessageBox::warning( this, "KO/Pi: Warning!",mes,
1284 "Overwrite!", "Cancel", 0,
1285 0, 1 );
1286 if ( result != 0 ) {
1287 createbup = false;
1288 }
1289 }
1290 if ( createbup ) {
1291 mView->saveCalendar( fn );
1292 mes.sprintf("KO/Pi:Saved %s",fn.latin1() );
1293 KOPrefs::instance()->mLastSaveFile = fn;
1294 setCaption(mes);
1295 }
1296}
1297void MainWindow::loadCalendar()
1298{
1299
1300 QString fn = KOPrefs::instance()->mLastLoadFile;
1301 fn = KFileDialog::getOpenFileName( fn, "Load backup filename", this );
1302
1303 if ( fn == "" )
1304 return;
1305 QFileInfo info;
1306 info.setFile( fn );
1307 QString mess;
1308 bool loadbup = true;
1309 if ( info. exists() ) {
1310 mess.sprintf( "Backup file from:\n%s\nLoading backup\nfile will delete\nyour current Data!\n",info.lastModified ().toString().latin1() );
1311 int result = QMessageBox::warning( this, "KO/Pi: Warning!",
1312 mess,
1313 "Load!", "Cancel", 0,
1314 0, 1 );
1315 if ( result != 0 ) {
1316 loadbup = false;
1317 }
1318 } else {
1319 QMessageBox::warning( this, "KO/Pi: Warning!",
1320 "Backup file\ndoes not exist!\n"
1321 "Nothing loaded!", 0, 0,
1322 0, 1 );
1323
1324 return;
1325 }
1326 if ( loadbup ) {
1327 mView->openCalendar( fn );
1328 KOPrefs::instance()->mLastLoadFile = fn;
1329 mess.sprintf("KO/Pi:Loaded %s",fn.latin1() );
1330 setCaption(mess);
1331 }
1332
1333}
1334void MainWindow::quickImportIcal()
1335{
1336 importFile( KOPrefs::instance()->mLastImportFile, false );
1337}
1338void MainWindow::importFile( QString fn, bool quick )
1339{
1340 QFileInfo info;
1341 info.setFile( fn );
1342 QString mess;
1343 bool loadbup = true;
1344 if ( !info. exists() ) {
1345 mess= "Import file \n..."+fn.right( 30)+ "\ndoes not exist!\nNothing imported!\n";
1346 int result = QMessageBox::warning( this, "KO/Pi: Warning!",
1347 mess );
1348 return;
1349 }
1350 int result = 0;
1351 if ( !quick ) {
1352 mess.sprintf( "Import file \n..."+fn.right( 25)+"\nfrom:\n%s\nDuplicated entries\nwill not be imported!\n",info.lastModified ().toString().latin1() );
1353 result = QMessageBox::warning( this, "KO/Pi: Warning!",
1354 mess,
1355 "Import", "Cancel", 0,
1356 0, 1 );
1357 }
1358 if ( result == 0 ) {
1359 if ( mView->openCalendar( fn, true )) {
1360 KOPrefs::instance()->mLastImportFile = fn;
1361 setCaption(i18n(" "));
1362 setCaption(i18n("Imported file successfully"));
1363 } else {
1364 setCaption(i18n("Error importing file"));
1365 }
1366 }
1367}
1368void MainWindow::importIcal()
1369{
1370
1371 QString fn =KOPrefs::instance()->mLastImportFile;
1372
1373 fn =KFileDialog:: getOpenFileName( fn, "Import filename(*.ics/*.vcs)", this );
1374 if ( fn == "" )
1375 return;
1376 importFile( fn, true );
1377
1378}
1379
1380void MainWindow::exportVCalendar()
1381{
1382 QString fn = KOPrefs::instance()->mLastVcalFile;
1383 fn = KFileDialog::getSaveFileName( fn, "Export vcal filename(*.vcs)", this );
1384 if ( fn == "" )
1385 return;
1386 QFileInfo info;
1387 info.setFile( fn );
1388 QString mes;
1389 bool createbup = true;
1390 if ( info. exists() ) {
1391 mes.sprintf( i18n("Save file\nalready exists!\nOld save file from:\n%s\nOverwrite?\n"),info.lastModified ().toString().latin1() );
1392 int result = QMessageBox::warning( this, "KO/Pi: Warning!",mes,
1393 "Overwrite!", "Cancel", 0,
1394 0, 1 );
1395 if ( result != 0 ) {
1396 createbup = false;
1397 }
1398 }
1399 if ( createbup ) {
1400 if ( mView->exportVCalendar( fn ) ) {
1401 KOPrefs::instance()->mLastVcalFile = fn;
1402 if ( fn.length() > 20 )
1403 mes.sprintf(i18n("KO/Pi:Exported to ...%s"),(fn.right(20)).latin1() );
1404 else
1405 mes.sprintf(i18n("KO/Pi:Exported to %s"),fn.latin1() );
1406 setCaption(mes);
1407 }
1408 }
1409
1410}
1411
1412QString MainWindow::getPassword( )
1413{
1414 QString retfile = "";
1415 QDialog dia ( this, "input-dialog", true );
1416 QLineEdit lab ( &dia );
1417 lab.setEchoMode( QLineEdit::Password );
1418 QVBoxLayout lay( &dia );
1419 lay.setMargin(7);
1420 lay.setSpacing(7);
1421 lay.addWidget( &lab);
1422 dia.setFixedSize( 230,50 );
1423 dia.setCaption( i18n("Input password") );
1424 dia.show();
1425 int res = dia.exec();
1426 if ( res )
1427 retfile = lab.text();
1428 return retfile;
1429
1430}
1431#ifndef _WIN32_
1432#include <unistd.h>
1433#endif
1434void MainWindow::syncLocalFile()
1435{
1436
1437 QString fn =KOPrefs::instance()->mLastSyncedLocalFile;
1438
1439 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this );
1440 if ( fn == "" )
1441 return;
1442 syncWithFile( fn, false );
1443
1444}
1445
1446void MainWindow::syncWithFile( QString fn , bool quick )
1447{
1448 QFileInfo info;
1449 info.setFile( fn );
1450 QString mess;
1451 bool loadbup = true;
1452 if ( !info. exists() ) {
1453 mess.sprintf( i18n( "Sync file \n...%s\ndoes not exist!\nNothing synced!\n"),fn.right( 30).latin1() );
1454 int result = QMessageBox::warning( this, "KO/Pi: Warning!",
1455 mess );
1456 return;
1457 }
1458 int result = 0;
1459 if ( !quick ) {
1460 mess.sprintf( "Sync with file \n..."+fn.right( 25)+"\nfrom:\n%s\n",info.lastModified ().toString().latin1() );
1461 result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
1462 mess,
1463 i18n("Sync"), i18n("Cancel"), 0,
1464 0, 1 );
1465 }
1466 if ( KOPrefs::instance()->mAskForPreferences )
1467 mView->edit_sync_options();
1468 if ( result == 0 ) {
1469 qDebug("Now sycing ... ");
1470 mView->syncCalendar( fn, true );
1471 if ( ! quick )
1472 KOPrefs::instance()->mLastSyncedLocalFile = fn;
1473 }
1474
1475}
1476
1477void MainWindow::quickSyncLocalFile()
1478{
1479 qDebug("quickSyncLocalFile() ");
1480 syncWithFile( KOPrefs::instance()->mLastSyncedLocalFile, false );
1481}
1482
1483void MainWindow::syncSSH()
1484{
1485 QTime timer;
1486 timer.start();
1487 qDebug("MainWindow::syncssh() ");
1488 KOPrefs *p = KOPrefs::instance();
1489 QString localFile = p->mLocalTempFile;
1490 QString remoteIP = p->mRemoteIP;
1491 QString remoteUser = p->mRemoteUser;
1492 QString remoteFile = p->mRemoteFile;
1493 if ( p->mUsePassWd && p->mRemotePassWd.length() > 0 )
1494 remoteUser += ":" + p->mRemotePassWd;
1495
1496 QString question = i18n("Do you really want\nto remote sync?\n \n") +
1497 i18n("IP: " ) +remoteIP +"\n" +
1498 i18n("User: " ) + remoteUser +"\n" ;
1499 int maxlen = 30;
1500 if ( QApplication::desktop()->width() > 320 )
1501 maxlen += 25;
1502 if ( remoteFile.length() > maxlen )
1503 question += i18n("Remote file:\n..." ) + remoteFile.right(maxlen) +"\n";
1504 else
1505 question += i18n("Remote file:\n " ) + remoteFile +"\n";
1506 if ( localFile.length() > maxlen )
1507 question += i18n("Local temp file:\n..." ) + localFile.right(maxlen) +"\n";
1508 else
1509 question += i18n("Local temp file:\n " ) + localFile +"\n";
1510
1511 if ( QMessageBox::information( this, "KO/Pi Sync",
1512 question,
1513 i18n("Yes"), i18n("No"),
1514 0, 0 ) != 0 )
1515 return;
1516 if ( !p->mUsePassWd ) {
1517 QString pass = getPassword();
1518 if ( pass.length() > 0 )
1519 remoteUser += ":" + pass;
1520 }
1521 QString command = "scp " + remoteUser + "@" + remoteIP +":" + remoteFile +" " +localFile;
1522 setCaption ( i18n( "Copy remote file to local machine..." ) );
1523 int fileSize = 0;
1524 int result = system ( command );
1525 // 0 : okay
1526 // 256: no such file or dir
1527 //
1528 qDebug("KO: Remote copy result(0 = okay): %d ",result );
1529 if ( result != 0 ) {
1530 int len = maxlen;
1531 while ( len < command.length() ) {
1532 command.insert( len , "\n" );
1533 len += maxlen +2;
1534 }
1535 question = i18n("Sorry, the copy command failed!\nCommand was:\n") + command + "\n \nTry command on console to get more\ndetailed info about the reason.\n";
1536 QMessageBox::information( this, "KO/Pi Sync - ERROR",
1537 question,
1538 i18n("Okay!")) ;
1539 return;
1540 }
1541
1542
1543 setCaption ( i18n( "Copying succeed. Syncing not yet implemented" ) );
1544 syncWithFile(localFile , true );
1545 return;
1546#if 0
1547 system ("scp zaurus@192.168.0.65:/home/zaurus/Applications/korganizer/mycalendar.ics /home/polo/Applications/korganizer/z_sync.ics");
1548 while ( timer.elapsed() < 5000 )
1549 qApp->processEvents();
1550
1551 qDebug("MainWindow::merging) ");
1552 mView->syncCalendar( "/home/polo/Applications/korganizer/z_sync.ics", 0 );
1553 while ( mBlockSaveFlag )
1554 qApp->processEvents();
1555 save();
1556 system ("scp /home/polo/Applications/korganizer/mycalendar.ics zaurus@192.168.0.65:/home/zaurus/Applications/korganizer/mycalendar.ics");
1557#endif
1558
1559}
1560*/
1561
diff --git a/kaddressbook/old_mainwindow.h b/kaddressbook/old_mainwindow.h
new file mode 100644
index 0000000..7b6f68c
--- a/dev/null
+++ b/kaddressbook/old_mainwindow.h
@@ -0,0 +1,122 @@
1#ifndef KADR_MAINWINDOW_H
2#define KADR_MAINWINDOW_H
3
4#include <qmainwindow.h>
5#include "kabcore.h"
6
7//US#include <qtimer.h>
8
9//US#include <libkcal/incidence.h>
10
11//US#include "simplealarmclient.h"
12
13//USclass QAction;
14//USclass CalendarView;
15
16//US#ifdef DESKTOP_VERSION
17//US#define QPEToolBar QToolBar
18//US#define QPEMenuBar QMenuBar
19//US#endif
20
21class KABCore;
22
23//USclass QPEToolBar;
24
25//US namespace KACore {
26//USclass CalendarLocal;
27//US}
28
29//USusing namespace KACore;
30
31class MainWindow : public QMainWindow
32{
33 Q_OBJECT
34 public:
35 MainWindow( QWidget *parent = 0, const char *name = 0, QString command = "");
36 ~MainWindow();
37
38 public slots:
39// void configureAgenda( int );
40 void recieve( const QCString& msg, const QByteArray& data );
41
42 protected slots:
43/*
44 void setCaptionToDates();
45
46 void about();
47
48 void keyBindings();
49 void aboutAutoSaving();;
50 void aboutKnownBugs();
51
52 void processIncidenceSelection( Incidence * );
53
54 void importQtopia();
55 void importIcal();
56 void importFile( QString, bool );
57 void quickImportIcal();
58
59 void slotModifiedChanged( bool );
60
61 void save();
62 void configureToolBar( int );
63 void saveCalendar();
64 void loadCalendar();
65 void exportVCalendar();
66 void checkAlarms();
67 void writeAlarm();
68
69
70 void syncSSH();
71 void syncLocalFile();
72 void syncWithFile( QString, bool );
73 void quickSyncLocalFile();
74
75
76 protected:
77 QString defaultFileName();
78
79 void enableIncidenceActions( bool );
80*/
81
82 private:
83/*
84 bool mFlagKeyPressed;
85 bool mBlockAtStartup;
86
87 QPEToolBar *iconToolBar;
88
89 void initActions();
90*/
91/* void setDefaultPreferences();
92 void keyPressEvent ( QKeyEvent * ) ;
93 void keyReleaseEvent ( QKeyEvent * ) ;
94
95 QPopupMenu *configureToolBarMenu;
96 QPopupMenu *configureAgendaMenu;
97 CalendarLocal *mCalendar;
98 CalendarView *mView;
99 QString getPassword();
100 QAction *mNewSubTodoAction;
101
102 QAction *mShowAction;
103 QAction *mEditAction;
104 QAction *mDeleteAction;
105
106 void closeEvent( QCloseEvent* ce );
107
108 SimpleAlarmClient mAlarmClient;
109
110 QTimer mSaveTimer;
111 QTimer alarmTimer;
112 bool mBlockSaveFlag;
113 bool mCalendarModifiedFlag;
114
115 QPixmap loadPixmap( QString );
116*/
117 private:
118 KABCore *mCore;
119
120};
121
122#endif
diff --git a/kaddressbook/phoneeditwidget.cpp b/kaddressbook/phoneeditwidget.cpp
new file mode 100644
index 0000000..78b9941
--- a/dev/null
+++ b/kaddressbook/phoneeditwidget.cpp
@@ -0,0 +1,532 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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 <qlayout.h>
25#include <qlabel.h>
26#include <qtooltip.h>
27#include <qpushbutton.h>
28#include <qcheckbox.h>
29#include <qstring.h>
30#include <qlistbox.h>
31#include <qlistview.h>
32#include <qbuttongroup.h>
33
34#include <kbuttonbox.h>
35#include <klistview.h>
36#include <kapplication.h>
37#include <qapplication.h>
38#include <kconfig.h>
39#include <klineedit.h>
40#include <kcombobox.h>
41#include <klocale.h>
42#include <kdebug.h>
43#include <kglobal.h>
44#include <kiconloader.h>
45
46#include <kabc/phonenumber.h>
47
48#include "typecombo.h"
49
50#include "phoneeditwidget.h"
51
52PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name )
53 : QWidget( parent, name )
54{
55 QGridLayout *layout = new QGridLayout( this, 4, 1 );
56//US layout->setSpacing( KDialog::spacingHint() );
57 layout->setSpacing( KDialogBase::spacingHintSmall() );
58
59
60
61 QLabel* label = new QLabel( this );
62//US loadIcon call is ambiguous. Add one more parameter
63//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) );
64 label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) );
65 label->setAlignment( AlignCenter );
66//US layout->addMultiCellWidget( label, 0, 1, 3, 3 );
67 layout->addWidget( label, 0, 0 );
68
69 QPushButton *editButton = new QPushButton( i18n( "Edit Phone Numbers..." ),
70 this );
71 if ( QApplication::desktop()->width() < 640 )
72 layout->addWidget( editButton, 0, 1 );
73 else
74 layout->addMultiCellWidget( editButton, 0, 0, 1, 3);
75
76 mPrefCombo = new PhoneTypeCombo( mPhoneList, this );
77 mPrefEdit = new KLineEdit( this );
78 //mPrefEdit->setMinimumWidth( int(mPrefEdit->sizeHint().width() * 1.5) );
79 mPrefCombo->setLineEdit( mPrefEdit );
80 layout->addWidget( mPrefCombo, 1, 0 );
81 layout->addWidget( mPrefEdit, 1, 1 );
82 int x = 1, y = 2;
83 if ( QApplication::desktop()->width() < 640 ) {
84 ++x;
85 y = 0;
86 }
87 mSecondCombo = new PhoneTypeCombo( mPhoneList, this );
88 mSecondEdit = new KLineEdit( this );
89 mSecondCombo->setLineEdit( mSecondEdit );
90 layout->addWidget( mSecondCombo, x, y++ );
91 layout->addWidget( mSecondEdit, x, y++ );
92
93 y = 0;
94 ++x;
95 mThirdCombo = new PhoneTypeCombo( mPhoneList, this );
96 mThirdEdit = new KLineEdit( this );
97 mThirdCombo->setLineEdit( mThirdEdit );
98 layout->addWidget( mThirdCombo, x, y++ );
99 layout->addWidget( mThirdEdit, x, y++ );
100 if ( QApplication::desktop()->width() < 640 ) {
101 ++x;
102 y = 0;
103 }
104 mFourthCombo = new PhoneTypeCombo( mPhoneList, this );
105 mFourthEdit = new KLineEdit( this );
106 mFourthCombo->setLineEdit( mFourthEdit );
107 layout->addWidget( mFourthCombo, x, y++ );
108 layout->addWidget( mFourthEdit, x, y++ );
109
110 // Four numbers don't fit in the current dialog
111 if ( QApplication::desktop()->width() < 640 ) {
112 mFourthCombo->hide();
113 mFourthEdit->hide();
114 } else {
115 QFontMetrics fm ( font () ) ;
116 int wid = fm.width( "Messenger" ) +60;
117 mPrefCombo->setMaximumWidth( wid );
118 mSecondCombo->setMaximumWidth( wid );
119 mThirdCombo->setMaximumWidth( wid );
120 mFourthCombo->setMaximumWidth( wid );
121 }
122
123
124 connect( mPrefEdit, SIGNAL( textChanged( const QString& ) ),
125 SLOT( slotPrefEditChanged() ) );
126 connect( mSecondEdit, SIGNAL( textChanged( const QString& ) ),
127 SLOT( slotSecondEditChanged() ) );
128 connect( mThirdEdit, SIGNAL( textChanged( const QString& ) ),
129 SLOT( slotThirdEditChanged() ) );
130 connect( mFourthEdit, SIGNAL( textChanged( const QString& ) ),
131 SLOT( slotFourthEditChanged() ) );
132
133 connect( editButton, SIGNAL( clicked() ), SLOT( edit() ) );
134
135 connect( mPrefCombo, SIGNAL( activated( int ) ),
136 SLOT( updatePrefEdit() ) );
137 connect( mSecondCombo, SIGNAL( activated( int ) ),
138 SLOT( updateSecondEdit() ) );
139 connect( mThirdCombo, SIGNAL( activated( int ) ),
140 SLOT( updateThirdEdit() ) );
141 connect( mFourthCombo, SIGNAL( activated( int ) ),
142 SLOT( updateFourthEdit() ) );
143}
144
145PhoneEditWidget::~PhoneEditWidget()
146{
147}
148
149void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &list )
150{
151 mPhoneList.clear();
152
153 // Insert types for existing numbers.
154 mPrefCombo->insertTypeList( list );
155
156 QValueList<int> defaultTypes;
157 defaultTypes << KABC::PhoneNumber::Home;
158 defaultTypes << KABC::PhoneNumber::Work;
159 defaultTypes << KABC::PhoneNumber::Cell;
160 defaultTypes << ( KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax );
161 defaultTypes << ( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax );
162
163 // Insert default types.
164 // Doing this for mPrefCombo is enough because the list is shared by all
165 // combos.
166 QValueList<int>::ConstIterator it;
167 for( it = defaultTypes.begin(); it != defaultTypes.end(); ++it ) {
168 if ( !mPrefCombo->hasType( *it ) )
169 mPrefCombo->insertType( list, *it, PhoneNumber( "", *it ) );
170 }
171
172 updateCombos();
173
174 mPrefCombo->selectType( defaultTypes[ 0 ] );
175 mSecondCombo->selectType( defaultTypes[ 1 ] );
176 mThirdCombo->selectType( defaultTypes[ 2 ] );
177 mFourthCombo->selectType( defaultTypes[ 3 ] );
178
179 updateLineEdits();
180}
181
182void PhoneEditWidget::updateLineEdits()
183{
184 updatePrefEdit();
185 updateSecondEdit();
186 updateThirdEdit();
187 updateFourthEdit();
188}
189
190void PhoneEditWidget::updateCombos()
191{
192 mPrefCombo->updateTypes();
193 mSecondCombo->updateTypes();
194 mThirdCombo->updateTypes();
195 mFourthCombo->updateTypes();
196}
197
198KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers()
199{
200 KABC::PhoneNumber::List retList;
201
202 KABC::PhoneNumber::List::Iterator it;
203 for ( it = mPhoneList.begin(); it != mPhoneList.end(); ++it )
204 if ( !(*it).number().isEmpty() )
205 retList.append( *it );
206
207 return retList;
208}
209
210void PhoneEditWidget::edit()
211{
212 PhoneEditDialog dlg( mPhoneList, this );
213
214 if ( dlg.exec() ) {
215 if ( dlg.changed() ) {
216 mPhoneList = dlg.phoneNumbers();
217 updateCombos();
218 emit modified();
219 }
220 }
221}
222
223void PhoneEditWidget::updatePrefEdit()
224{
225 updateEdit( mPrefCombo );
226}
227
228void PhoneEditWidget::updateSecondEdit()
229{
230 updateEdit( mSecondCombo );
231}
232
233void PhoneEditWidget::updateThirdEdit()
234{
235 updateEdit( mThirdCombo );
236}
237
238void PhoneEditWidget::updateFourthEdit()
239{
240 updateEdit( mFourthCombo );
241}
242
243void PhoneEditWidget::updateEdit( PhoneTypeCombo *combo )
244{
245 QLineEdit *edit = combo->lineEdit();
246 if ( !edit )
247 return;
248
249#if 0
250 if ( edit == mPrefEdit ) kdDebug(5720) << " prefEdit" << endl;
251 if ( edit == mSecondEdit ) kdDebug(5720) << " secondEdit" << endl;
252 if ( edit == mThirdEdit ) kdDebug(5720) << " thirdEdit" << endl;
253 if ( edit == mFourthEdit ) kdDebug(5720) << " fourthEdit" << endl;
254#endif
255
256 PhoneNumber::List::Iterator it = combo->selectedElement();
257 if ( it != mPhoneList.end() ) {
258 edit->setText( (*it).number() );
259 } else {
260 kdDebug(5720) << "PhoneEditWidget::updateEdit(): no selected element" << endl;
261 }
262}
263
264void PhoneEditWidget::slotPrefEditChanged()
265{
266 updatePhoneNumber( mPrefCombo );
267}
268
269void PhoneEditWidget::slotSecondEditChanged()
270{
271 updatePhoneNumber( mSecondCombo );
272}
273
274void PhoneEditWidget::slotThirdEditChanged()
275{
276 updatePhoneNumber( mThirdCombo );
277}
278
279void PhoneEditWidget::slotFourthEditChanged()
280{
281 updatePhoneNumber( mFourthCombo );
282}
283
284void PhoneEditWidget::updatePhoneNumber( PhoneTypeCombo *combo )
285{
286 QLineEdit *edit = combo->lineEdit();
287 if ( !edit ) return;
288
289 PhoneNumber::List::Iterator it = combo->selectedElement();
290 if ( it != mPhoneList.end() ) {
291 (*it).setNumber( edit->text() );
292 } else {
293 kdDebug(5720) << "PhoneEditWidget::updatePhoneNumber(): no selected element"
294 << endl;
295 }
296
297 updateOtherEdit( combo, mPrefCombo );
298 updateOtherEdit( combo, mSecondCombo );
299 updateOtherEdit( combo, mThirdCombo );
300 updateOtherEdit( combo, mFourthCombo );
301
302 emit modified();
303}
304
305void PhoneEditWidget::updateOtherEdit( PhoneTypeCombo *combo, PhoneTypeCombo *otherCombo )
306{
307 if ( combo == otherCombo ) return;
308
309 if ( combo->currentItem() == otherCombo->currentItem() ) {
310 updateEdit( otherCombo );
311 }
312}
313
314///////////////////////////////////////////
315// PhoneEditDialog
316
317class PhoneViewItem : public QListViewItem
318{
319public:
320 PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number );
321
322 void setPhoneNumber( const KABC::PhoneNumber &number )
323 {
324 mPhoneNumber = number;
325 makeText();
326 }
327
328 QString key() { return mPhoneNumber.id(); }
329 QString country() { return ""; }
330 QString region() { return ""; }
331 QString number() { return ""; }
332
333 KABC::PhoneNumber phoneNumber() { return mPhoneNumber; }
334
335private:
336 void makeText();
337
338 KABC::PhoneNumber mPhoneNumber;
339};
340
341PhoneViewItem::PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number )
342 : QListViewItem( parent ), mPhoneNumber( number )
343{
344 makeText();
345}
346
347void PhoneViewItem::makeText()
348{
349 /**
350 * Will be used in future versions of kaddressbook/libkabc
351
352 setText( 0, mPhoneNumber.country() );
353 setText( 1, mPhoneNumber.region() );
354 setText( 2, mPhoneNumber.number() );
355 setText( 3, mPhoneNumber.typeLabel() );
356 */
357
358 setText( 0, mPhoneNumber.number() );
359 setText( 1, mPhoneNumber.typeLabel() );
360}
361
362PhoneEditDialog::PhoneEditDialog( const KABC::PhoneNumber::List &list, QWidget *parent, const char *name )
363 : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Numbers" ),
364 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
365 parent, name, true)
366{
367 mPhoneNumberList = list;
368
369 QWidget *page = plainPage();
370
371 QGridLayout *layout = new QGridLayout( page, 1, 2 );
372 layout->setSpacing( spacingHint() );
373
374 mListView = new KListView( page );
375 mListView->setAllColumnsShowFocus( true );
376 mListView->addColumn( i18n( "Number" ) );
377 mListView->addColumn( i18n( "Type" ) );
378
379 KButtonBox *buttonBox = new KButtonBox( page, Vertical );
380
381 buttonBox->addButton( i18n( "&Add..." ), this, SLOT( slotAddPhoneNumber() ) );
382 mEditButton = buttonBox->addButton( i18n( "&Edit..." ), this, SLOT( slotEditPhoneNumber() ) );
383 mEditButton->setEnabled( false );
384 mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), this, SLOT( slotRemovePhoneNumber() ) );
385 mRemoveButton->setEnabled( false );
386 buttonBox->layout();
387
388 layout->addWidget( mListView, 0, 0 );
389 layout->addWidget( buttonBox, 0, 1 );
390
391 connect( mListView, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged()) );
392 connect( mListView, SIGNAL(doubleClicked( QListViewItem *, const QPoint &, int )), this, SLOT( slotEditPhoneNumber()));
393
394 KABC::PhoneNumber::List::Iterator it;
395 for ( it = mPhoneNumberList.begin(); it != mPhoneNumberList.end(); ++it )
396 new PhoneViewItem( mListView, *it );
397
398 mChanged = false;
399}
400
401PhoneEditDialog::~PhoneEditDialog()
402{
403}
404
405void PhoneEditDialog::slotAddPhoneNumber()
406{
407 KABC::PhoneNumber tmp( "", 0 );
408 PhoneTypeDialog dlg( tmp, this );
409
410 if ( dlg.exec() ) {
411 KABC::PhoneNumber phoneNumber = dlg.phoneNumber();
412 mPhoneNumberList.append( phoneNumber );
413 new PhoneViewItem( mListView, phoneNumber );
414
415 mChanged = true;
416 }
417}
418
419void PhoneEditDialog::slotRemovePhoneNumber()
420{
421 PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() );
422 if ( !item )
423 return;
424
425 mPhoneNumberList.remove( item->phoneNumber() );
426 QListViewItem *currItem = mListView->currentItem();
427 mListView->takeItem( currItem );
428 delete currItem;
429
430 mChanged = true;
431}
432
433void PhoneEditDialog::slotEditPhoneNumber()
434{
435 PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() );
436 if ( !item )
437 return;
438
439 PhoneTypeDialog dlg( item->phoneNumber(), this );
440
441 if ( dlg.exec() ) {
442 slotRemovePhoneNumber();
443 KABC::PhoneNumber phoneNumber = dlg.phoneNumber();
444 mPhoneNumberList.append( phoneNumber );
445 new PhoneViewItem( mListView, phoneNumber );
446
447 mChanged = true;
448 }
449}
450
451void PhoneEditDialog::slotSelectionChanged()
452{
453 bool state = ( mListView->currentItem() != 0 );
454
455 mRemoveButton->setEnabled( state );
456 mEditButton->setEnabled( state );
457}
458
459const KABC::PhoneNumber::List &PhoneEditDialog::phoneNumbers()
460{
461 return mPhoneNumberList;
462}
463
464bool PhoneEditDialog::changed() const
465{
466 return mChanged;
467}
468
469///////////////////////////////////////////
470// PhoneTypeDialog
471PhoneTypeDialog::PhoneTypeDialog( const KABC::PhoneNumber &phoneNumber,
472 QWidget *parent, const char *name)
473 : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Number" ),
474 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
475 parent, name, true), mPhoneNumber( phoneNumber )
476{
477 QWidget *page = plainPage();
478 QLabel *label = 0;
479 QGridLayout *layout = new QGridLayout( page, 3, 2, marginHint(), spacingHint() );
480
481 label = new QLabel( i18n( "Number:" ), page );
482 layout->addWidget( label, 0, 0 );
483 mNumber = new KLineEdit( page );
484 layout->addWidget( mNumber, 0, 1 );
485
486 mPreferredBox = new QCheckBox( i18n( "This is the preferred phone number" ), page );
487 layout->addMultiCellWidget( mPreferredBox, 1, 1, 0, 1 );
488
489 mGroup = new QButtonGroup( 2, Horizontal, i18n( "Types" ), page );
490 layout->addMultiCellWidget( mGroup, 2, 2, 0, 1 );
491
492 // fill widgets
493 mNumber->setText( mPhoneNumber.number() );
494
495 mTypeList = KABC::PhoneNumber::typeList();
496 mTypeList.remove( KABC::PhoneNumber::Pref );
497
498 KABC::PhoneNumber::TypeList::Iterator it;
499 for ( it = mTypeList.begin(); it != mTypeList.end(); ++it )
500 new QCheckBox( KABC::PhoneNumber::typeLabel( *it ), mGroup );
501
502 for ( int i = 0; i < mGroup->count(); ++i ) {
503 int type = mPhoneNumber.type();
504 QCheckBox *box = (QCheckBox*)mGroup->find( i );
505 box->setChecked( type & mTypeList[ i ] );
506 }
507
508 mPreferredBox->setChecked( mPhoneNumber.type() & KABC::PhoneNumber::Pref );
509}
510
511KABC::PhoneNumber PhoneTypeDialog::phoneNumber()
512{
513 mPhoneNumber.setNumber( mNumber->text() );
514
515 int type = 0;
516 for ( int i = 0; i < mGroup->count(); ++i ) {
517 QCheckBox *box = (QCheckBox*)mGroup->find( i );
518 if ( box->isChecked() )
519 type += mTypeList[ i ];
520 }
521
522 if ( mPreferredBox->isChecked() )
523 mPhoneNumber.setType( type | KABC::PhoneNumber::Pref );
524 else
525 mPhoneNumber.setType( type & ~KABC::PhoneNumber::Pref );
526
527 return mPhoneNumber;
528}
529
530#ifndef KAB_EMBEDDED
531#include "phoneeditwidget.moc"
532#endif //KAB_EMBEDDED
diff --git a/kaddressbook/phoneeditwidget.h b/kaddressbook/phoneeditwidget.h
new file mode 100644
index 0000000..7fe4bc0
--- a/dev/null
+++ b/kaddressbook/phoneeditwidget.h
@@ -0,0 +1,147 @@
1#ifndef PHONEEDITWIDGET_H
2#define PHONEEDITWIDGET_H
3/*
4 This file is part of KAddressBook.
5 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program 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
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
21 As a special exception, permission is given to link this program
22 with any edition of Qt, and distribute the resulting executable,
23 without including the source code for Qt in the source distribution.
24*/
25
26#include <kdialogbase.h>
27
28#include "addresseeconfig.h"
29#include "typecombo.h"
30
31class QButtonGroup;
32class QCheckBox;
33
34class KListView;
35class KLineEdit;
36class KComboBox;
37
38typedef TypeCombo<KABC::PhoneNumber> PhoneTypeCombo;
39
40/**
41 Widget for editing phone numbers.
42*/
43class PhoneEditWidget : public QWidget
44{
45 Q_OBJECT
46
47 public:
48 PhoneEditWidget( QWidget *parent, const char *name = 0 );
49 ~PhoneEditWidget();
50
51 void setPhoneNumbers( const KABC::PhoneNumber::List &list );
52 KABC::PhoneNumber::List phoneNumbers();
53
54 void updateTypeCombo( const KABC::PhoneNumber::List&, KComboBox* );
55 KABC::PhoneNumber currentPhoneNumber( KComboBox*, int );
56
57 signals:
58 void modified();
59
60 private slots:
61 void edit();
62
63 void updatePrefEdit();
64 void updateSecondEdit();
65 void updateThirdEdit();
66 void updateFourthEdit();
67
68 void slotPrefEditChanged();
69 void slotSecondEditChanged();
70 void slotThirdEditChanged();
71 void slotFourthEditChanged();
72
73 protected:
74 void updateLineEdits();
75 void updateCombos();
76
77 private:
78 void updateEdit( PhoneTypeCombo *combo );
79 void updatePhoneNumber( PhoneTypeCombo *combo );
80 void updateOtherEdit( PhoneTypeCombo *combo, PhoneTypeCombo *otherCombo );
81
82 PhoneTypeCombo *mPrefCombo;
83 PhoneTypeCombo *mSecondCombo;
84 PhoneTypeCombo *mThirdCombo;
85 PhoneTypeCombo *mFourthCombo;
86
87 KLineEdit *mPrefEdit;
88 KLineEdit *mSecondEdit;
89 KLineEdit *mThirdEdit;
90 KLineEdit *mFourthEdit;
91
92 KABC::PhoneNumber::List mPhoneList;
93};
94
95/**
96 Dialog for editing lists of phonenumbers.
97*/
98class PhoneEditDialog : public KDialogBase
99{
100 Q_OBJECT
101
102 public:
103 PhoneEditDialog( const KABC::PhoneNumber::List &list, QWidget *parent, const char *name = 0 );
104 ~PhoneEditDialog();
105
106 const KABC::PhoneNumber::List &phoneNumbers();
107 bool changed() const;
108
109 protected slots:
110 void slotAddPhoneNumber();
111 void slotRemovePhoneNumber();
112 void slotEditPhoneNumber();
113 void slotSelectionChanged();
114
115 private:
116 KABC::PhoneNumber::List mPhoneNumberList;
117 KABC::PhoneNumber::TypeList mTypeList;
118 KComboBox *mTypeBox;
119 KListView *mListView;
120
121 QPushButton *mRemoveButton;
122 QPushButton *mEditButton;
123
124 bool mChanged;
125};
126
127/**
128 Dialog for editing phone number types.
129*/
130class PhoneTypeDialog : public KDialogBase
131{
132 Q_OBJECT
133public:
134 PhoneTypeDialog( const KABC::PhoneNumber &phoneNumber, QWidget *parent, const char *name = 0 );
135
136 KABC::PhoneNumber phoneNumber();
137
138private:
139 KABC::PhoneNumber mPhoneNumber;
140 KABC::PhoneNumber::TypeList mTypeList;
141
142 QButtonGroup *mGroup;
143 QCheckBox *mPreferredBox;
144 KLineEdit *mNumber;
145};
146
147#endif
diff --git a/kaddressbook/secrecywidget.cpp b/kaddressbook/secrecywidget.cpp
new file mode 100644
index 0000000..4a2acc8
--- a/dev/null
+++ b/kaddressbook/secrecywidget.cpp
@@ -0,0 +1,70 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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 <qlayout.h>
25
26#include <kabc/secrecy.h>
27#include <kcombobox.h>
28#include <kdialog.h>
29
30#include "secrecywidget.h"
31
32SecrecyWidget::SecrecyWidget( QWidget *parent, const char *name )
33 : QWidget( parent, name )
34{
35 QVBoxLayout *layout = new QVBoxLayout( this, KDialog::marginHint(),
36 KDialog::spacingHint() );
37 mSecrecyCombo = new KComboBox( this );
38 layout->addWidget( mSecrecyCombo );
39
40 KABC::Secrecy::TypeList list = KABC::Secrecy::typeList();
41 KABC::Secrecy::TypeList::Iterator it;
42 for ( it = list.begin(); it != list.end(); ++it )
43 mSecrecyCombo->insertItem( KABC::Secrecy::typeLabel( *it ), *it );
44
45 connect( mSecrecyCombo, SIGNAL( activated( const QString& ) ),
46 SIGNAL( changed() ) );
47}
48
49SecrecyWidget::~SecrecyWidget()
50{
51}
52
53void SecrecyWidget::setSecrecy( const KABC::Secrecy &secrecy )
54{
55//US to avoid an indexoutofbounds error if value is invalid
56 if (secrecy.isValid())
57 mSecrecyCombo->setCurrentItem( secrecy.type() );
58}
59
60KABC::Secrecy SecrecyWidget::secrecy() const
61{
62 KABC::Secrecy secrecy;
63 secrecy.setType( mSecrecyCombo->currentItem() );
64
65 return secrecy;
66}
67
68#ifndef KAB_EMBEDDED
69#include "secrecywidget.moc"
70#endif //KAB_EMBEDDED
diff --git a/kaddressbook/secrecywidget.h b/kaddressbook/secrecywidget.h
new file mode 100644
index 0000000..96e6905
--- a/dev/null
+++ b/kaddressbook/secrecywidget.h
@@ -0,0 +1,50 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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#ifndef SECRECYWIDGET_H
25#define SECRECYWIDGET_H
26
27#include <qwidget.h>
28
29namespace KABC { class Secrecy; }
30class KComboBox;
31
32class SecrecyWidget : public QWidget
33{
34 Q_OBJECT
35
36 public:
37 SecrecyWidget( QWidget *parent, const char *name = 0 );
38 ~SecrecyWidget();
39
40 void setSecrecy( const KABC::Secrecy &secrecy );
41 KABC::Secrecy secrecy() const;
42
43 signals:
44 void changed();
45
46 private:
47 KComboBox *mSecrecyCombo;
48};
49
50#endif
diff --git a/kaddressbook/typecombo.h b/kaddressbook/typecombo.h
new file mode 100644
index 0000000..191273d
--- a/dev/null
+++ b/kaddressbook/typecombo.h
@@ -0,0 +1,193 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 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#ifndef TYPECOMBO_H
25#define TYPECOMBO_H
26
27#include <kabc/phonenumber.h>
28#include <kcombobox.h>
29
30/**
31 Combo box for type information of Addresses and Phone numbers.
32*/
33template <class T>
34class TypeCombo : public KComboBox
35{
36 public:
37 typedef typename T::List List;
38 typedef typename T::List::Iterator Iterator;
39
40 TypeCombo( List &list, QWidget *parent, const char *name = 0 );
41
42 void setLineEdit( QLineEdit *edit ) { mLineEdit = edit; }
43 QLineEdit *lineEdit() const { return mLineEdit; }
44
45 void updateTypes();
46
47 void selectType( int type );
48
49 int selectedType();
50
51 Iterator selectedElement();
52
53 void insertType( const List &list, int type,
54 const T &defaultObject );
55 void insertTypeList( const List &list );
56
57 bool hasType( int type );
58
59 private:
60 List &mTypeList;
61 QLineEdit *mLineEdit;
62};
63
64template <class T>
65#ifdef _WIN32_
66TypeCombo<T>::TypeCombo( typename TypeCombo::List &list, QWidget *parent,
67#else
68TypeCombo<T>::TypeCombo( TypeCombo::List &list, QWidget *parent,
69
70#endif
71 const char *name )
72 : KComboBox( parent),
73//US my kde version has no KComboBox constructor witgh two parameters
74//US : KComboBox( parent, name ),
75 mTypeList( list )
76{
77}
78
79template <class T>
80void TypeCombo<T>::updateTypes()
81{
82 // Remember current item
83 QString currentId;
84 int current = currentItem();
85 if ( current >= 0 ) currentId = mTypeList[ current ].id();
86
87 clear();
88
89 QMap<int,int> labelCount;
90
91 uint i;
92 for( i = 0; i < mTypeList.count(); ++i ) {
93 int type = ( mTypeList[ i ].type() & ~( T::Pref ) );
94 QString label = mTypeList[ i ].typeLabel( type );
95 int count = 1;
96 if ( labelCount.contains( type ) ) {
97 count = labelCount[ type ] + 1;
98 }
99 labelCount[ type ] = count;
100 if ( count > 1 ) {
101 label = i18n("label (number)", "%1 (%2)").arg( label )
102 .arg( QString::number( count ) );
103 }
104 insertItem( label );
105 }
106
107 // Restore previous current item
108 if ( !currentId.isEmpty() ) {
109 for( i = 0; i < mTypeList.count(); ++i ) {
110 if ( mTypeList[ i ].id() == currentId ) {
111 setCurrentItem( i );
112 break;
113 }
114 }
115 }
116}
117
118template <class T>
119void TypeCombo<T>::selectType( int type )
120{
121 uint i;
122 for( i = 0; i < mTypeList.count(); ++i ) {
123 if ( (mTypeList[ i ].type() & ~T::Pref) == type ) {
124 setCurrentItem( i );
125 break;
126 }
127 }
128}
129
130template <class T>
131int TypeCombo<T>::selectedType()
132{
133 return mTypeList[ currentItem() ].type();
134}
135
136template <class T>
137typename TypeCombo<T>::Iterator TypeCombo<T>::selectedElement()
138{
139 return mTypeList.at( currentItem() );
140}
141
142template <class T>
143#ifdef _WIN32_
144void TypeCombo<T>::insertType( typename const TypeCombo::List &list, int type,
145#else
146void TypeCombo<T>::insertType( const TypeCombo::List &list, int type,
147#endif
148 const T &defaultObject )
149{
150 uint i;
151 for ( i = 0; i < list.count(); ++i ) {
152 if ( list[ i ].type() == type ) {
153 mTypeList.append( list[ i ] );
154 break;
155 }
156 }
157 if ( i == list.count() ) {
158 mTypeList.append( defaultObject );
159 }
160}
161
162template <class T>
163#ifdef _WIN32_
164void TypeCombo<T>::insertTypeList( typename const TypeCombo::List &list )
165#else
166void TypeCombo<T>::insertTypeList( const TypeCombo::List &list )
167
168#endif
169{
170 uint i;
171 for ( i = 0; i < list.count(); ++i ) {
172 uint j;
173 for( j = 0; j < mTypeList.count(); ++j ) {
174 if ( list[ i ].id() == mTypeList[ j ].id() ) break;
175 }
176 if ( j == mTypeList.count() ) {
177 mTypeList.append( list[ i ] );
178 }
179 }
180}
181
182template <class T>
183bool TypeCombo<T>::hasType( int type )
184{
185 for( uint i = 0; i < mTypeList.count(); ++i ) {
186 if ( ( mTypeList[ i ].type() & ~T::Pref ) == type )
187 return true;
188 }
189
190 return false;
191}
192
193#endif
diff --git a/kaddressbook/undo.cpp b/kaddressbook/undo.cpp
new file mode 100644
index 0000000..4442087
--- a/dev/null
+++ b/kaddressbook/undo.cpp
@@ -0,0 +1,119 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (C) 1999 Don Sanders <sanders@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 "undo.h"
25
26///////////////////////////////
27// StackBase
28
29void StackBase::push(Command *c)
30{
31 mCommandStack.push(c);
32 emit changed();
33}
34
35bool StackBase::isEmpty()
36{
37 return mCommandStack.isEmpty();
38}
39
40Command *StackBase::top()
41{
42 return mCommandStack.top();
43}
44
45void StackBase::clear()
46{
47 mCommandStack.clear();
48 emit changed();
49}
50
51Command *StackBase::pop()
52{
53 Command *c = mCommandStack.pop();
54 if (c)
55 emit changed();
56
57 return c;
58}
59
60///////////////////////////////
61// UndoStack
62
63UndoStack* UndoStack::instance_ = 0;
64
65UndoStack::UndoStack()
66 : StackBase()
67{
68 // setAutoDelete( true );
69}
70
71UndoStack* UndoStack::instance()
72{
73 if (!instance_)
74 instance_ = new UndoStack();
75 return instance_;
76}
77
78void UndoStack::undo()
79{
80 if (isEmpty())
81 return;
82
83 Command *command = pop();
84 command->undo();
85
86 RedoStack::instance()->push( command );
87}
88
89////////////////////
90// RedoStack
91
92RedoStack* RedoStack::instance_ = 0;
93
94RedoStack::RedoStack()
95{
96 mCommandStack.setAutoDelete( true );
97}
98
99RedoStack* RedoStack::instance()
100{
101 if (!instance_)
102 instance_ = new RedoStack();
103 return instance_;
104}
105
106void RedoStack::redo()
107{
108 Command *command;
109 if (isEmpty())
110 return;
111
112 command = pop();
113 command->redo();
114 UndoStack::instance()->push( command );
115}
116
117#ifndef KAB_EMBEDDED
118#include "undo.moc"
119#endif //KAB_EMBEDDED
diff --git a/kaddressbook/undo.h b/kaddressbook/undo.h
new file mode 100644
index 0000000..843bc26
--- a/dev/null
+++ b/kaddressbook/undo.h
@@ -0,0 +1,95 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (C) 1999 Don Sanders <sanders@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#ifndef UNDO_H
25#define UNDO_H
26
27#include <qobject.h>
28#include <qptrstack.h>
29#include <qstring.h>
30
31class Command
32{
33public:
34 Command() {}
35 virtual ~Command() {};
36 virtual QString name() = 0;
37 virtual void redo() = 0; // egcs requires these methods to have
38 virtual void undo() = 0; // implementations (Seems like a bug)
39 // pure virtual may not work
40};
41
42/** The Undo and Redo stacks now no longer inherit directly from a stack.
43* They now contain a stack internally and inherit from StackBase, which
44* has a signal for when the stack is modified. This is need to keep
45* the edit menu and toolbar up to date.
46*
47* Really this is a simple observable stack.
48*/
49class StackBase : public QObject
50{
51 Q_OBJECT
52
53 public:
54 StackBase() : QObject() {}
55
56 void push(Command *c);
57 bool isEmpty();
58 Command *top();
59 void clear();
60
61 signals:
62 void changed();
63
64 protected:
65 /** Protect the pop method so users must call undo/redo to properly
66 * use the stack, however the subclasses need it to modify the stack.
67 */
68 Command *pop();
69
70 QPtrStack<Command> mCommandStack;
71};
72
73class UndoStack : public StackBase
74{
75public:
76 static UndoStack *instance();
77 void undo();
78
79protected:
80 UndoStack();
81 static UndoStack* instance_;
82};
83
84class RedoStack : public StackBase
85{
86public:
87 static RedoStack *instance();
88 void redo();
89
90protected:
91 RedoStack();
92 static RedoStack* instance_;
93};
94
95#endif
diff --git a/kaddressbook/undocmds.cpp b/kaddressbook/undocmds.cpp
new file mode 100644
index 0000000..db773be
--- a/dev/null
+++ b/kaddressbook/undocmds.cpp
@@ -0,0 +1,240 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (C) 1999 Don Sanders <sanders@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 <qtextstream.h>
25
26#include <qapplication.h>
27#include <qclipboard.h>
28
29#include <klocale.h>
30#include <kdebug.h>
31#include <kapplication.h>
32#include <kabc/addressbook.h>
33
34#include "addresseeutil.h"
35#include "addresseeconfig.h"
36#include "kabcore.h"
37
38#include "undocmds.h"
39
40/////////////////////////////////
41// PwDelete Methods
42
43PwDeleteCommand::PwDeleteCommand(KABC::AddressBook *doc,
44 const QStringList &uidList)
45 : Command(), mDocument(doc), mAddresseeList(), mUidList(uidList)
46{
47 redo();
48}
49
50PwDeleteCommand::~PwDeleteCommand()
51{
52}
53
54QString PwDeleteCommand::name()
55{
56 return i18n( "Delete" );
57}
58
59void PwDeleteCommand::undo()
60{
61 // Put it back in the document
62 KABC::Addressee::List::Iterator iter;
63 for (iter = mAddresseeList.begin(); iter != mAddresseeList.end(); ++iter)
64 {
65 mDocument->insertAddressee(*iter);
66 }
67
68 mAddresseeList.clear();
69}
70
71void PwDeleteCommand::redo()
72{
73 // Just remove it from the document. This is enough to make the user
74 // Think the item has been deleted
75 KABC::Addressee a;
76 QStringList::Iterator iter;
77 for (iter = mUidList.begin(); iter != mUidList.end(); ++iter)
78 {
79 a = mDocument->findByUid(*iter);
80 mDocument->removeAddressee(a);
81 mAddresseeList.append(a);
82 AddresseeConfig::instance()->remove(a.uid());
83 }
84}
85
86/////////////////////////////////
87// PwPaste Methods
88
89PwPasteCommand::PwPasteCommand( KABCore *core, const KABC::Addressee::List &list )
90 : Command(), mCore( core ), mAddresseeList( list )
91{
92 redo();
93}
94
95QString PwPasteCommand::name()
96{
97 return i18n( "Paste" );
98}
99
100void PwPasteCommand::undo()
101{
102 KABC::Addressee::List::Iterator it;
103 for ( it = mAddresseeList.begin(); it != mAddresseeList.end(); ++it )
104 mCore->addressBook()->removeAddressee( *it );
105}
106
107void PwPasteCommand::redo()
108{
109 QStringList uids;
110 KABC::Addressee::List::Iterator it;
111 for ( it = mAddresseeList.begin(); it != mAddresseeList.end(); ++it ) {
112 /* we have to set a new uid for the contact, otherwise insertAddressee()
113 ignore it.
114 */
115 (*it).setUid( KApplication::randomString( 10 ) );
116 uids.append( (*it).uid() );
117 mCore->addressBook()->insertAddressee( *it );
118 }
119
120 QStringList::Iterator uidIt;
121 for ( uidIt = uids.begin(); uidIt != uids.end(); ++uidIt )
122 mCore->editContact( *uidIt );
123}
124
125/////////////////////////////////
126// PwNew Methods
127
128PwNewCommand::PwNewCommand( KABC::AddressBook *doc, const KABC::Addressee &a )
129 : Command(), mDocument( doc ), mA( a )
130{
131 mDocument->insertAddressee(mA);
132}
133
134PwNewCommand::~PwNewCommand()
135{
136}
137
138QString PwNewCommand::name()
139{
140 return i18n( "New Contact" );
141}
142
143void PwNewCommand::undo()
144{
145 mDocument->removeAddressee( mA );
146}
147
148void PwNewCommand::redo()
149{
150 mDocument->insertAddressee( mA );
151}
152
153/////////////////////////////////
154// PwEdit Methods
155
156PwEditCommand::PwEditCommand(KABC::AddressBook *doc,
157 const KABC::Addressee &oldA,
158 const KABC::Addressee &newA )
159 : Command(), mDocument(doc), mOldA(oldA), mNewA(newA)
160{
161 redo();
162}
163
164PwEditCommand::~PwEditCommand()
165{
166}
167
168QString PwEditCommand::name()
169{
170 return i18n( "Entry Edit" );
171}
172
173void PwEditCommand::undo()
174{
175 mDocument->insertAddressee(mOldA);
176}
177
178void PwEditCommand::redo()
179{
180 mDocument->insertAddressee(mNewA);
181}
182
183/////////////////////////////////
184// PwCut Methods
185
186PwCutCommand::PwCutCommand(KABC::AddressBook *doc, const QStringList &uidList)
187 : Command(), mDocument(doc), mAddresseeList(), mUidList(uidList),
188 mClipText(), mOldText()
189{
190 redo();
191}
192
193QString PwCutCommand::name()
194{
195 return i18n( "Cut" );
196}
197
198void PwCutCommand::undo()
199{
200 KABC::Addressee::List::Iterator iter;
201 for (iter = mAddresseeList.begin(); iter != mAddresseeList.end(); ++iter)
202 {
203 mDocument->insertAddressee(*iter);
204 }
205 mAddresseeList.clear();
206
207 QClipboard *cb = QApplication::clipboard();
208//US
209#ifndef KAB_EMBEDDED
210 kapp->processEvents();
211#else //KAB_EMBEDDED
212 qApp->processEvents();
213#endif //KAB_EMBEDDED
214 cb->setText( mOldText );
215}
216
217void PwCutCommand::redo()
218{
219 KABC::Addressee a;
220 QStringList::Iterator iter;
221 for (iter = mUidList.begin(); iter != mUidList.end(); ++iter)
222 {
223 a = mDocument->findByUid(*iter);
224 mDocument->removeAddressee(a);
225 mAddresseeList.append(a);
226 }
227
228 // Convert to clipboard
229 mClipText = AddresseeUtil::addresseesToClipboard(mAddresseeList);
230
231 QClipboard *cb = QApplication::clipboard();
232 mOldText = cb->text();
233//US
234#ifndef KAB_EMBEDDED
235 kapp->processEvents();
236#else //KAB_EMBEDDED
237 qApp->processEvents();
238#endif //KAB_EMBEDDED
239 cb->setText( mClipText );
240}
diff --git a/kaddressbook/undocmds.h b/kaddressbook/undocmds.h
new file mode 100644
index 0000000..c3f23cc
--- a/dev/null
+++ b/kaddressbook/undocmds.h
@@ -0,0 +1,117 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (C) 1999 Don Sanders <sanders@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#ifndef UNDOCMDS_H
25#define UNDOCMDS_H
26//
27// Commands for undo/redo functionality.
28
29#include <qstring.h>
30#include <qstringlist.h>
31
32#include <kabc/addressee.h>
33
34#include "undo.h"
35
36namespace KABC {
37 class AddressBook;
38}
39
40class KABCore;
41
42class PwDeleteCommand : public Command
43{
44public:
45 PwDeleteCommand(KABC::AddressBook *doc, const QStringList &uidList );
46 virtual ~PwDeleteCommand();
47 virtual QString name();
48 virtual void undo();
49 virtual void redo();
50
51private:
52 KABC::AddressBook *mDocument;
53 KABC::Addressee::List mAddresseeList;
54 QStringList mUidList;
55};
56
57class PwPasteCommand : public Command
58{
59 public:
60 PwPasteCommand( KABCore *core, const KABC::Addressee::List &list );
61 virtual QString name();
62 virtual void undo();
63 virtual void redo();
64
65 private:
66 KABCore *mCore;
67 KABC::Addressee::List mAddresseeList;
68};
69
70class PwCutCommand : public Command
71{
72public:
73 PwCutCommand(KABC::AddressBook *doc, const QStringList &uidList);
74 virtual QString name();
75 virtual void undo();
76 virtual void redo();
77
78private:
79 KABC::AddressBook *mDocument;
80 KABC::Addressee::List mAddresseeList;
81 QStringList mUidList;
82 QString mClipText;
83 QString mOldText;
84};
85
86class PwNewCommand : public Command
87{
88public:
89 PwNewCommand(KABC::AddressBook *doc, const KABC::Addressee &a );
90 ~PwNewCommand();
91 virtual QString name();
92 virtual void undo();
93 virtual void redo();
94
95private:
96 KABC::AddressBook *mDocument;
97 KABC::Addressee mA;
98};
99
100class PwEditCommand : public Command
101{
102public:
103 PwEditCommand(KABC::AddressBook *doc,
104 const KABC::Addressee &oldA,
105 const KABC::Addressee &newA);
106 virtual ~PwEditCommand();
107 virtual QString name();
108 virtual void undo();
109 virtual void redo();
110
111private:
112 KABC::AddressBook *mDocument;
113 KABC::Addressee mOldA;
114 KABC::Addressee mNewA;
115};
116
117#endif
diff --git a/kaddressbook/viewconfigurefieldspage.cpp b/kaddressbook/viewconfigurefieldspage.cpp
new file mode 100644
index 0000000..2c827eb
--- a/dev/null
+++ b/kaddressbook/viewconfigurefieldspage.cpp
@@ -0,0 +1,345 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Tobias Koenig <tokoe@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#ifndef KAB_EMBEDDED
25#include <kcombobox.h>
26#include <qpushbutton.h>
27#include <kdebug.h>
28
29#else //KAB_EMBEDDED
30#include <qcombobox.h>
31#endif //KAB_EMBEDDED
32
33#include <kiconloader.h>
34#include <kdialog.h>
35#include <klocale.h>
36
37#include <qtoolbutton.h>
38#include <qlabel.h>
39#include <qlistbox.h>
40#include <qlayout.h>
41
42#include "viewconfigurefieldspage.h"
43
44class FieldItem : public QListBoxText
45{
46 public:
47 FieldItem( QListBox *parent, KABC::Field *field )
48 : QListBoxText( parent, field->label() ), mField( field ) {}
49
50 FieldItem( QListBox *parent, KABC::Field *field, int index )
51 : QListBoxText( parent, field->label(), parent->item( index ) ),
52 mField( field ) {}
53
54 KABC::Field *field() { return mField; }
55
56 private:
57 KABC::Field *mField;
58};
59
60
61ViewConfigureFieldsPage::ViewConfigureFieldsPage( KABC::AddressBook *ab,
62 QWidget *parent,
63 const char *name )
64 : QWidget( parent, name ), mAddressBook( ab )
65{
66 initGUI();
67}
68
69void ViewConfigureFieldsPage::restoreSettings( KConfig *config )
70{
71 KABC::Field::List fields = KABC::Field::restoreFields( config, "KABCFields" );
72
73 if ( fields.isEmpty() )
74 fields = KABC::Field::defaultFields();
75
76 KABC::Field::List::ConstIterator it;
77 for( it = fields.begin(); it != fields.end(); ++it )
78 new FieldItem( mSelectedBox, *it );
79
80 slotShowFields( mCategoryCombo->currentItem() );
81}
82
83void ViewConfigureFieldsPage::saveSettings( KConfig *config )
84{
85 KABC::Field::List fields;
86
87 for( uint i = 0; i < mSelectedBox->count(); ++i ) {
88 FieldItem *fieldItem = static_cast<FieldItem *>( mSelectedBox->item( i ) );
89 fields.append( fieldItem->field() );
90 }
91
92 KABC::Field::saveFields( config, "KABCFields", fields );
93}
94
95void ViewConfigureFieldsPage::slotShowFields( int index )
96{
97 int currentPos = mUnSelectedBox->currentItem();
98 mUnSelectedBox->clear();
99
100 int category;
101 if ( index == 0 ) category = KABC::Field::All;
102 else category = 1 << ( index - 1 );
103
104 KABC::Field::List allFields = mAddressBook->fields( category );
105
106 KABC::Field::List::ConstIterator it;
107 for ( it = allFields.begin(); it != allFields.end(); ++it ) {
108 QListBoxItem *item = mSelectedBox->firstItem();
109 while( item ) {
110 FieldItem *fieldItem = static_cast<FieldItem *>( item );
111 if ( (*it)->equals( fieldItem->field() ) )
112 break;
113 item = item->next();
114 }
115
116 if ( !item )
117 new FieldItem( mUnSelectedBox, *it );
118 }
119
120 mUnSelectedBox->sort();
121 mUnSelectedBox->setCurrentItem( currentPos );
122}
123
124void ViewConfigureFieldsPage::slotSelect()
125{
126 // insert selected items in the unselected list to the selected list,
127 // directoy under the current item if selected, or at the bottonm if
128 // nothing is selected in the selected list
129 int where = mSelectedBox->currentItem();
130//US QListBoxItem::isSelected()) is not available in QT 2.x. Use selected instead.
131 if ( !(where > -1 && mSelectedBox->item( where )->selected()) )
132 where = mSelectedBox->count() - 1;
133
134 for ( uint i = 0; i < mUnSelectedBox->count(); ++i )
135 if ( mUnSelectedBox->isSelected( mUnSelectedBox->item( i ) ) ) {
136 FieldItem *fieldItem = static_cast<FieldItem *>( mUnSelectedBox->item( i ) );
137 new FieldItem( mSelectedBox, fieldItem->field(), where );
138 where++;
139 }
140
141 slotShowFields( mCategoryCombo->currentItem() );
142}
143
144void ViewConfigureFieldsPage::slotUnSelect()
145{
146 for ( uint i = 0; i < mSelectedBox->count(); ++i )
147 if ( mSelectedBox->isSelected( mSelectedBox->item( i ) ) ) {
148 mSelectedBox->removeItem( i );
149 --i;
150 }
151
152 slotShowFields( mCategoryCombo->currentItem() );
153}
154
155void ViewConfigureFieldsPage::slotButtonsEnabled()
156{
157 bool state = false;
158 // add button: enabled if any items are selected in the unselected list
159 for( uint i = 0; i < mUnSelectedBox->count(); ++i )
160//US QListBoxItem::isSelected()) is not available in QT 2.x. Use selected instead.
161 if ( mUnSelectedBox->item( i )->selected() ) {
162 state = true;
163 break;
164 }
165 mAddButton->setEnabled( state );
166
167 int j = mSelectedBox->currentItem();
168 state = ( j > -1 && mSelectedBox->isSelected( j ) );
169
170 // up button: enabled if there is a current item > 0 and that is selected
171 mUpButton->setEnabled( ( j > 0 && state ) );
172
173 // down button: enabled if there is a current item < count - 2 and that is selected
174 mDownButton->setEnabled( ( j > -1 && j < (int)mSelectedBox->count() - 1 && state ) );
175
176 // remove button: enabled if any items are selected in the selected list
177 state = false;
178 for ( uint i = 0; i < mSelectedBox->count(); ++i )
179//US QListBoxItem::isSelected()) is not available in QT 2.x. Use selected instead.
180 if ( mSelectedBox->item( i )->selected() ) {
181 state = true;
182 break;
183 }
184 mRemoveButton->setEnabled( state );
185}
186
187void ViewConfigureFieldsPage::slotMoveUp()
188{
189 int i = mSelectedBox->currentItem();
190 if ( i > 0 ) {
191 QListBoxItem *item = mSelectedBox->item( i );
192 mSelectedBox->takeItem( item );
193 mSelectedBox->insertItem( item, i - 1 );
194 mSelectedBox->setCurrentItem( item );
195 mSelectedBox->setSelected( i - 1, true );
196 }
197}
198
199void ViewConfigureFieldsPage::slotMoveDown()
200{
201 int i = mSelectedBox->currentItem();
202 if ( i > -1 && i < (int)mSelectedBox->count() - 1 ) {
203 QListBoxItem *item = mSelectedBox->item( i );
204 mSelectedBox->takeItem( item );
205 mSelectedBox->insertItem( item, i + 1 );
206 mSelectedBox->setCurrentItem( item );
207 mSelectedBox->setSelected( i + 1, true );
208 }
209}
210
211void ViewConfigureFieldsPage::initGUI()
212{
213 //US change the orientation dependent on the following flag
214 // right the flag is set only staticly.
215 // 0 = 640x480 ; 1 = 240x320
216 bool orientation = 1;
217
218
219 setCaption( i18n("Select Fields to Display") );
220
221 QGridLayout *gl = 0;
222
223 if (orientation == 0)
224 gl = new QGridLayout( this , 6, 4, 0, KDialog::spacingHint() );
225 else
226 gl = new QGridLayout( this , 4, 6, 0, KDialog::spacingHint() );
227
228 #ifndef KAB_EMBEDDED
229 mCategoryCombo = new KComboBox( false, this );
230 #else //KAB_EMBEDDED
231 mCategoryCombo = new QComboBox( false, this );
232 #endif //KAB_EMBEDDED
233
234 mCategoryCombo->insertItem( KABC::Field::categoryLabel( KABC::Field::All ) );
235 mCategoryCombo->insertItem( KABC::Field::categoryLabel( KABC::Field::Frequent ) );
236 mCategoryCombo->insertItem( KABC::Field::categoryLabel( KABC::Field::Address ) );
237 mCategoryCombo->insertItem( KABC::Field::categoryLabel( KABC::Field::Email ) );
238 mCategoryCombo->insertItem( KABC::Field::categoryLabel( KABC::Field::Personal ) );
239 mCategoryCombo->insertItem( KABC::Field::categoryLabel( KABC::Field::Organization ) );
240 mCategoryCombo->insertItem( KABC::Field::categoryLabel( KABC::Field::CustomCategory ) );
241 connect( mCategoryCombo, SIGNAL( activated(int) ), SLOT( slotShowFields(int) ) );
242 gl->addWidget( mCategoryCombo, 0, 0 );
243
244 QLabel *label = new QLabel( i18n( "&Selected fields:" ), this );
245 if (orientation == 0)
246 gl->addWidget( label, 0, 2 );
247 else
248 gl->addWidget( label, 2, 0 );
249
250
251 mUnSelectedBox = new QListBox( this );
252 mUnSelectedBox->setSelectionMode( QListBox::Extended );
253 mUnSelectedBox->setMinimumHeight( 100 );
254 if (orientation == 0)
255 gl->addWidget( mUnSelectedBox, 1, 0 );
256 else
257 gl->addWidget( mUnSelectedBox, 0, 1 );
258
259 mSelectedBox = new QListBox( this );
260 mSelectedBox->setSelectionMode( QListBox::Extended );
261 label->setBuddy( mSelectedBox );
262 if (orientation == 0)
263 gl->addWidget( mSelectedBox, 1, 2 );
264 else
265 gl->addWidget( mSelectedBox, 2, 1 );
266
267 QBoxLayout *vb1 = 0;
268 if (orientation == 0)
269 vb1 = new QBoxLayout( QBoxLayout::TopToBottom, KDialog::spacingHint() );
270 else
271 vb1 = new QBoxLayout( QBoxLayout::LeftToRight, KDialog::spacingHint() );
272
273 vb1->addStretch();
274
275 mAddButton = new QToolButton( this );
276 if (orientation == 0)
277 mAddButton->setIconSet( SmallIconSet( "1rightarrow" ) );
278 else
279 mAddButton->setIconSet( SmallIconSet( "1downarrow" ) );
280 connect( mAddButton, SIGNAL( clicked() ), SLOT( slotSelect() ) );
281 vb1->addWidget( mAddButton );
282
283 mRemoveButton = new QToolButton( this );
284 if (orientation == 0)
285 mRemoveButton->setIconSet( SmallIconSet( "1leftarrow" ) );
286 else
287 mRemoveButton->setIconSet( SmallIconSet( "1uparrow" ) );
288
289 connect( mRemoveButton, SIGNAL( clicked() ), SLOT( slotUnSelect() ) );
290 vb1->addWidget( mRemoveButton );
291
292 vb1->addStretch();
293 if (orientation == 0)
294 gl->addLayout( vb1, 1, 1 );
295 else
296 gl->addLayout( vb1, 1, 1 );
297
298 QBoxLayout *vb2 = 0;
299 if (orientation == 0)
300 vb2 = new QBoxLayout( QBoxLayout::TopToBottom, KDialog::spacingHint() );
301 else
302 vb2 = new QBoxLayout( QBoxLayout::LeftToRight, KDialog::spacingHint() );
303
304 vb2->addStretch();
305
306 mUpButton = new QToolButton( this );
307 mUpButton->setIconSet( SmallIconSet( "1uparrow" ) );
308 connect( mUpButton, SIGNAL( clicked() ), SLOT( slotMoveUp() ) );
309 vb2->addWidget( mUpButton );
310
311 mDownButton = new QToolButton( this );
312 mDownButton->setIconSet( SmallIconSet( "1downarrow" ) );
313 connect( mDownButton, SIGNAL( clicked() ), SLOT( slotMoveDown() ) );
314 vb2->addWidget( mDownButton );
315
316 vb2->addStretch();
317 if (orientation == 0)
318 gl->addLayout( vb2, 1, 3 );
319 else
320 gl->addLayout( vb2, 3, 1 );
321
322 QSize sizeHint = mUnSelectedBox->sizeHint();
323
324 // make sure we fill the list with all items, so that we can
325 // get the maxItemWidth we need to not truncate the view
326 slotShowFields( 0 );
327
328 sizeHint = sizeHint.expandedTo( mSelectedBox->sizeHint() );
329 sizeHint.setWidth( mUnSelectedBox->maxItemWidth() );
330 mUnSelectedBox->setMinimumSize( sizeHint );
331 mSelectedBox->setMinimumSize( sizeHint );
332
333 gl->activate();
334
335 connect( mUnSelectedBox, SIGNAL( selectionChanged() ), SLOT( slotButtonsEnabled() ) );
336 connect( mSelectedBox, SIGNAL( selectionChanged() ), SLOT( slotButtonsEnabled() ) );
337 connect( mSelectedBox, SIGNAL( currentChanged( QListBoxItem * ) ), SLOT( slotButtonsEnabled() ) );
338
339 slotButtonsEnabled();
340}
341
342
343#ifndef KAB_EMBEDDED
344#include "viewconfigurefieldspage.moc"
345#endif //KAB_EMBEDDED
diff --git a/kaddressbook/viewconfigurefieldspage.h b/kaddressbook/viewconfigurefieldspage.h
new file mode 100644
index 0000000..b27668c
--- a/dev/null
+++ b/kaddressbook/viewconfigurefieldspage.h
@@ -0,0 +1,81 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Tobias Koenig <tokoe@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#ifndef VIEWCONFIGUREFIELDSPAGE_H
25#define VIEWCONFIGUREFIELDSPAGE_H
26
27#include <qwidget.h>
28
29#include <kabc/field.h>
30#include <kabc/addressbook.h>
31
32#ifndef KAB_EMBEDDED
33class KComboBox;
34#else //KAB_EMBEDDED
35class QComboBox;
36#endif //KAB_EMBEDDED
37
38class QListBox;
39class QListBoxItem;
40class QPushButton;
41class QToolButton;
42
43class ViewConfigureFieldsPage : public QWidget
44{
45 Q_OBJECT
46
47 public:
48 ViewConfigureFieldsPage( KABC::AddressBook *ab, QWidget *parent = 0,
49 const char *name = 0 );
50
51 void restoreSettings( KConfig* );
52 void saveSettings( KConfig* );
53
54 public slots:
55 void slotSelect();
56 void slotUnSelect();
57 void slotMoveUp();
58 void slotMoveDown();
59
60 void slotShowFields( int );
61 void slotButtonsEnabled();
62
63 private:
64 void initGUI();
65
66#ifndef KAB_EMBEDDED
67 KComboBox *mCategoryCombo;
68#else //KAB_EMBEDDED
69 QComboBox *mCategoryCombo;
70#endif //KAB_EMBEDDED
71 QListBox *mSelectedBox;
72 QListBox *mUnSelectedBox;
73 QToolButton *mAddButton;
74 QToolButton *mRemoveButton;
75 QToolButton *mUpButton;
76 QToolButton *mDownButton;
77
78 KABC::AddressBook *mAddressBook;
79};
80
81#endif
diff --git a/kaddressbook/viewconfigurefilterpage.cpp b/kaddressbook/viewconfigurefilterpage.cpp
new file mode 100644
index 0000000..b085a5e
--- a/dev/null
+++ b/kaddressbook/viewconfigurefilterpage.cpp
@@ -0,0 +1,137 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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#ifndef KAB_EMBEDDED
25#include <kcombobox.h>
26#else //KAB_EMBEDDED
27#include <qcombobox.h>
28#endif //KAB_EMBEDDED
29
30#include <qbuttongroup.h>
31#include <qlabel.h>
32#include <qlayout.h>
33#include <qradiobutton.h>
34
35#include <kconfig.h>
36#include <kdialog.h>
37#include <klocale.h>
38
39#include "filter.h"
40
41#include "viewconfigurefilterpage.h"
42
43ViewConfigureFilterPage::ViewConfigureFilterPage( QWidget *parent,
44 const char *name )
45 : QWidget( parent, name )
46{
47 QBoxLayout *topLayout = new QVBoxLayout( this, 0, KDialog::spacingHint() );
48
49 mFilterGroup = new QButtonGroup();
50 connect( mFilterGroup, SIGNAL( clicked( int ) ), SLOT( buttonClicked( int ) ) );
51
52 QLabel *label = new QLabel( i18n( "The default filter will be activated whenever"
53 " this view is displayed. This feature allows you to configure views that only"
54 " interact with certain types of information based on the filter. Once the view"
55 " is activated, the filter can be changed at anytime." ), this );
56 label->setAlignment( Qt::AlignLeft | Qt::AlignTop | Qt::WordBreak );
57 topLayout->addWidget( label );
58
59 QWidget *spacer = new QWidget( this );
60 spacer->setMinimumHeight( 5 );
61 topLayout->addWidget( spacer );
62
63 QRadioButton *button = new QRadioButton( i18n( "No default filter" ), this );
64 mFilterGroup->insert( button );
65 topLayout->addWidget( button );
66
67 button = new QRadioButton( i18n( "Use last active filter" ), this );
68 mFilterGroup->insert( button );
69 topLayout->addWidget( button );
70
71 QBoxLayout *comboLayout = new QHBoxLayout();
72 topLayout->addLayout( comboLayout );
73 button = new QRadioButton( i18n( "Use filter:" ), this );
74 mFilterGroup->insert( button );
75 comboLayout->addWidget( button );
76
77#ifndef KAB_EMBEDDED
78 mFilterCombo = new KComboBox( this );
79#else //KAB_EMBEDDED
80 mFilterCombo = new QComboBox( this );
81#endif //KAB_EMBEDDED
82
83 comboLayout->addWidget( mFilterCombo );
84}
85
86ViewConfigureFilterPage::~ViewConfigureFilterPage()
87{
88 delete mFilterGroup;
89}
90
91void ViewConfigureFilterPage::restoreSettings( KConfig *config )
92{
93 mFilterCombo->clear();
94
95//US I had to adjust the whole method in order to work with QComboBoxes
96// in case of the Platformindependent version
97 QString defaultfiltername = config->readEntry( "DefaultFilterName" );
98
99 int id = config->readNumEntry( "DefaultFilterType", 1 );
100 mFilterGroup->setButton( id );
101 buttonClicked( id );
102
103 // Load the filter combo
104 Filter::List list = Filter::restore( config, "Filter" );
105 Filter::List::Iterator it;
106 for ( it = list.begin(); it != list.end(); ++it )
107 {
108 mFilterCombo->insertItem( (*it).name() );
109
110 if ( id == 2 && (*it).name() == defaultfiltername) // has default filter
111 {
112 mFilterCombo->insertItem( (*it).name(), 0);
113 }
114 else
115 {
116 mFilterCombo->insertItem( (*it).name() );
117 }
118
119 }
120
121
122}
123
124void ViewConfigureFilterPage::saveSettings( KConfig *config )
125{
126 config->writeEntry( "DefaultFilterName", mFilterCombo->currentText() );
127 config->writeEntry( "DefaultFilterType", mFilterGroup->id( mFilterGroup->selected() ) );
128}
129
130void ViewConfigureFilterPage::buttonClicked( int id )
131{
132 mFilterCombo->setEnabled( id == 2 );
133}
134
135#ifndef KAB_EMBEDDED
136#include "viewconfigurefilterpage.moc"
137#endif //KAB_EMBEDDED
diff --git a/kaddressbook/viewconfigurefilterpage.h b/kaddressbook/viewconfigurefilterpage.h
new file mode 100644
index 0000000..3be9564
--- a/dev/null
+++ b/kaddressbook/viewconfigurefilterpage.h
@@ -0,0 +1,63 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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#ifndef VIEWCONFIGUREFILTERPAGE
25#define VIEWCONFIGUREFILTERPAGE
26
27#include <qwidget.h>
28
29class QButtonGroup;
30
31#ifndef KAB_EMBEDDED
32class KComboBox;
33#else //KAB_EMBEDDED
34class QComboBox;
35#endif //KAB_EMBEDDED
36
37class KConfig;
38
39class ViewConfigureFilterPage : public QWidget
40{
41 Q_OBJECT
42
43 public:
44 ViewConfigureFilterPage( QWidget *parent, const char *name = 0 );
45 ~ViewConfigureFilterPage();
46
47 void restoreSettings( KConfig* );
48 void saveSettings( KConfig* );
49
50 protected slots:
51 void buttonClicked( int id );
52
53 private:
54#ifndef KAB_EMBEDDED
55 KComboBox *mFilterCombo;
56#else //KAB_EMBEDDED
57 QComboBox *mFilterCombo;
58#endif //KAB_EMBEDDED
59
60 QButtonGroup *mFilterGroup;
61};
62
63#endif
diff --git a/kaddressbook/viewconfigurewidget.cpp b/kaddressbook/viewconfigurewidget.cpp
new file mode 100644
index 0000000..666e188
--- a/dev/null
+++ b/kaddressbook/viewconfigurewidget.cpp
@@ -0,0 +1,159 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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
25#ifndef KAB_EMBEDDED
26
27#include <qvbox.h>
28
29#include <kapplication.h>
30#include <kconfig.h>
31#include <kdebug.h>
32#include <kiconloader.h>
33
34#include "viewmanager.h"
35
36#endif //KAB_EMBEDDED
37
38
39#include <qlayout.h>
40
41#include <kjanuswidget.h>
42#include <kglobal.h>
43#include <klocale.h>
44
45#include "viewconfigurewidget.h"
46#include "viewconfigurefieldspage.h"
47#include "viewconfigurefilterpage.h"
48
49ViewConfigureWidget::ViewConfigureWidget( KABC::AddressBook *ab, QWidget *parent,
50 const char *name )
51 : ConfigureWidget( ab, parent, name )
52{
53 QVBoxLayout *topLayout = new QVBoxLayout( this );
54
55 mMainWidget = new KJanusWidget( this, "JanusWidget", KJanusWidget::Tabbed );
56
57 topLayout->addWidget( mMainWidget );
58
59 // Add the first page, the attributes
60 QVBox *page = addPage( i18n( "Fields" ), QString::null,
61 KGlobal::iconLoader()->loadIcon( "view_detailed",
62 KIcon::Panel, 16 ) );
63
64
65 // Add the select fields page
66 mFieldsPage = new ViewConfigureFieldsPage( addressBook(), (QWidget*)page );
67
68//US mFieldsPage->setMinimumSize(300,300);
69
70 // Add the second page, the filter selection
71 page = addPage( i18n( "Default Filter" ), QString::null,
72 KGlobal::iconLoader()->loadIcon( "filter",
73 KIcon::Panel, 16 ) );
74
75 mFilterPage = new ViewConfigureFilterPage( (QWidget*)page );
76 //qDebug("+++++ViewConfigureWidget::ViewConfigureWidget ");
77}
78
79ViewConfigureWidget::~ViewConfigureWidget()
80{
81 //qDebug("-----ViewConfigureWidget::~ViewConfigureWidget() ");
82}
83
84void ViewConfigureWidget::restoreSettings( KConfig *config )
85{
86 mFieldsPage->restoreSettings( config );
87 mFilterPage->restoreSettings( config );
88}
89
90void ViewConfigureWidget::saveSettings( KConfig *config )
91{
92 mFieldsPage->saveSettings( config );
93 mFilterPage->saveSettings( config );
94}
95
96QVBox *ViewConfigureWidget::addPage( const QString &item, const QString &header,
97 const QPixmap &pixmap )
98{
99 return mMainWidget->addVBoxPage( item, header, pixmap );
100}
101
102#include <qframe.h>
103#include <qlabel.h>
104#include <qlayout.h>
105#include <stdlib.h>
106
107ViewConfigureDialog::ViewConfigureDialog( ViewConfigureWidget *wdg, const QString &viewName,
108 QWidget *parent, const char *name )
109 : KDialogBase( Swallow, i18n( "Modify View: " ) + viewName, Help | Ok | Cancel,
110 Ok, parent, name, true, true ), mConfigWidget( wdg )
111{
112//US, I have to change the way, how to connect the ViewConfigureWidget. It looks
113// like it has changed.
114 //QFrame *topFrame = plainPage();
115 if ( mConfigWidget ) {
116 mConfigWidget->reparent(this, QPoint(0,0), true);
117 // QVBoxLayout * layout = new QVBoxLayout( this );
118 //layout->addWidget(mConfigWidget );
119 //mConfigWidget->reparent(topFrame, QPoint(1,1), true);
120
121 setMainWidget( mConfigWidget );
122 }
123
124}
125
126ViewConfigureDialog::~ViewConfigureDialog()
127{
128}
129void ViewConfigureDialog::setWidget( ViewConfigureWidget *wdg )
130{
131 mConfigWidget = wdg ;
132 setMainWidget( mConfigWidget );
133
134}
135
136void ViewConfigureDialog::restoreSettings( KConfig *config )
137{
138 mConfigWidget->restoreSettings( config );
139}
140
141void ViewConfigureDialog::saveSettings( KConfig *config )
142{
143 mConfigWidget->saveSettings( config );
144}
145
146void ViewConfigureDialog::slotHelp()
147{
148#ifndef KAB_EMBEDDED
149 kapp->invokeHelp( "using-views" );
150#else //KAB_EMBEDDED
151 qDebug("ViewConfigureDialog::slotHelp not yet implemented");
152#endif //KAB_EMBEDDED
153}
154
155#ifndef KAB_EMBEDDED
156#include "viewconfigurewidget.moc"
157#endif //KAB_EMBEDDED
158
159
diff --git a/kaddressbook/viewconfigurewidget.h b/kaddressbook/viewconfigurewidget.h
new file mode 100644
index 0000000..0c2b77c
--- a/dev/null
+++ b/kaddressbook/viewconfigurewidget.h
@@ -0,0 +1,106 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4
5 This program is free software; you can rremovePageedistribute 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#ifndef VIEWCONFIGUREWIDGET_H
25#define VIEWCONFIGUREWIDGET_H
26
27
28
29#include "configurewidget.h"
30
31class QVBox;
32
33#include <kdialogbase.h>
34#include <qpixmap.h>
35
36class KJanusWidget;
37class QString;
38class ViewConfigureFieldsPage;
39class ViewConfigureFilterPage;
40class ViewConfigureDialog;
41/**
42 This widget is the base class for all view configuration widgets. The
43 author of a view may wish to inherit from this widget and add config pages
44 that add custom config options. The default implementation of this widget
45 is to show a page with the select fields widget. For simple views this may
46 be sufficient.
47*/
48class ViewConfigureWidget : public ConfigureWidget
49{
50 Q_OBJECT
51
52 public:
53 ViewConfigureWidget( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
54 virtual ~ViewConfigureWidget();
55
56 /**
57 Reads the configuration from the config object and sets the values
58 in the GUI. If this method is overloaded, be sure to call the base
59 class's method.
60
61 Do not change the group of the config object in this method.
62 */
63 virtual void restoreSettings( KConfig *config );
64
65 /**
66 Writes the configuration from the GUI to the config object. If this
67 method is overloaded, be sure to call the base class's method.
68
69 Do not change the group of the config object in this method.
70 */
71 virtual void saveSettings( KConfig *config );
72
73
74 /**
75 Use this method to add new pages to the widget.
76 */
77 QVBox *addPage( const QString &item, const QString &header = QString::null,
78 const QPixmap &pixmap = QPixmap() );
79
80 private:
81 KJanusWidget *mMainWidget;
82
83 ViewConfigureFieldsPage *mFieldsPage;
84 ViewConfigureFilterPage *mFilterPage;
85};
86
87class ViewConfigureDialog : public KDialogBase
88{
89 Q_OBJECT
90
91 public:
92 ViewConfigureDialog( ViewConfigureWidget *wdg, const QString &viewName,
93 QWidget *parent, const char *name = 0 );
94 ~ViewConfigureDialog();
95
96 void restoreSettings( KConfig* );
97 void saveSettings( KConfig* );
98 void setWidget( ViewConfigureWidget *wdg );
99 protected slots:
100 void slotHelp();
101
102 private:
103 ViewConfigureWidget *mConfigWidget;
104};
105
106#endif
diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp
new file mode 100644
index 0000000..e8c5b45
--- a/dev/null
+++ b/kaddressbook/viewmanager.cpp
@@ -0,0 +1,685 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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/*
25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk
27
28$Id$
29*/
30
31
32#ifndef KAB_EMBEDDED
33#include <libkdepim/kvcarddrag.h>
34#include <kabc/vcardconverter.h>
35#include <kconfig.h>
36#include <kdeversion.h>
37#include <kiconloader.h>
38#include <klocale.h>
39#include <kmessagebox.h>
40#include <kmultipledrag.h>
41#include <ktrader.h>
42#include <kurldrag.h>
43
44#include "addresseeutil.h"
45#else //KAB_EMBEDDED
46#include "views/kaddressbookiconview.h"
47#include "views/kaddressbooktableview.h"
48#include "views/kaddressbookcardview.h"
49#include "kaddressbookview.h"
50
51#include <qaction.h>
52#include <qmessagebox.h>
53#include <qpopupmenu.h>
54#include <kconfigbase.h>
55
56#endif //KAB_EMBEDDED
57
58
59#include <kdebug.h>
60#include <kactionclasses.h>
61
62#include <qlayout.h>
63#include <qwidgetstack.h>
64
65#include <kabc/addressbook.h>
66#include "filtereditdialog.h"
67#include "addviewdialog.h"
68#include "kabcore.h"
69#include "kabprefs.h"
70#include "viewmanager.h"
71
72ViewManager::ViewManager( KABCore *core, QWidget *parent, const char *name )
73 : QWidget( parent, name ), mCore( core ), mActiveView( 0 )
74{
75 initGUI();
76 initActions();
77
78 mViewDict.setAutoDelete( true );
79
80 createViewFactories();
81}
82
83ViewManager::~ViewManager()
84{
85 unloadViews();
86 mViewFactoryDict.clear();
87}
88
89void ViewManager::restoreSettings()
90{
91 mViewNameList = KABPrefs::instance()->mViewNames;
92 QString activeViewName = KABPrefs::instance()->mCurrentView;
93
94 mActionSelectView->setItems( mViewNameList );
95
96 // Filter
97 mFilterList = Filter::restore( mCore->config(), "Filter" );
98 mActionSelectFilter->setItems( filterNames() );
99 mActionSelectFilter->setCurrentItem( KABPrefs::instance()->mCurrentFilter );
100
101 // Tell the views to reread their config, since they may have
102 // been modified by global settings
103 QString _oldgroup = mCore->config()->group();
104
105 QDictIterator<KAddressBookView> it( mViewDict );
106 for ( it.toFirst(); it.current(); ++it ) {
107 KConfigGroupSaver saver( mCore->config(), it.currentKey() );
108 it.current()->readConfig( mCore->config() );
109 }
110 setActiveView( activeViewName );
111
112 mActionDeleteView->setEnabled( mViewNameList.count() > 1 );
113}
114
115void ViewManager::saveSettings()
116{
117 QString _oldgroup = mCore->config()->group();
118
119 QDictIterator<KAddressBookView> it( mViewDict );
120 for ( it.toFirst(); it.current(); ++it ) {
121 KConfigGroupSaver saver( mCore->config(), it.currentKey() );
122#ifdef DESKTOP_VERSION
123 (*it)->writeConfig( mCore->config() );
124#else
125 (*it).writeConfig( mCore->config() );
126#endif
127 }
128
129 Filter::save( mCore->config(), "Filter", mFilterList );
130 KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem();
131
132 // write the view name list
133 KABPrefs::instance()->mViewNames = mViewNameList;
134 KABPrefs::instance()->mCurrentView = mActiveView->caption();
135
136}
137
138QStringList ViewManager::selectedUids() const
139{
140 if ( mActiveView )
141 return mActiveView->selectedUids();
142 else
143 return QStringList();
144}
145
146QStringList ViewManager::selectedEmails() const
147{
148 if ( mActiveView )
149 return mActiveView->selectedEmails();
150 else
151 return QStringList();
152}
153
154KABC::Addressee::List ViewManager::selectedAddressees() const
155{
156 KABC::Addressee::List list;
157 if ( mActiveView ) {
158 QStringList uids = mActiveView->selectedUids();
159 QStringList::Iterator it;
160 for ( it = uids.begin(); it != uids.end(); ++it ) {
161 KABC::Addressee addr = mCore->addressBook()->findByUid( *it );
162 if ( !addr.isEmpty() )
163 list.append( addr );
164 }
165 }
166
167 return list;
168}
169//US added another method with no parameter, since my moc compiler does not support default parameters.
170void ViewManager::setSelected()
171{
172 setSelected( QString::null, true );
173}
174
175void ViewManager::setSelected( const QString &uid, bool selected )
176{
177 if ( mActiveView )
178 mActiveView->setSelected( uid, selected );
179}
180
181void ViewManager::unloadViews()
182{
183 mViewDict.clear();
184 mActiveView = 0;
185}
186
187void ViewManager::setActiveView( const QString &name )
188{
189 KAddressBookView *view = 0;
190
191 // Check that this isn't the same as the current active view
192 if ( mActiveView && ( mActiveView->caption() == name ) )
193 return;
194
195 // At this point we know the view that should be active is not
196 // currently active. We will try to find the new on in the list. If
197 // we can't find it, it means it hasn't been instantiated, so we will
198 // create it on demand.
199
200 view = mViewDict.find( name );
201
202 // Check if we found the view. If we didn't, then we need to create it
203 if ( view == 0 ) {
204 KConfig *config = mCore->config();
205
206 KConfigGroupSaver saver( config, name );
207
208 QString type = config->readEntry( "Type", "Table" );
209
210 kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl;
211
212 ViewFactory *factory = mViewFactoryDict.find( type );
213 if ( factory )
214 view = factory->view( mCore->addressBook(), mViewWidgetStack );
215
216 if ( view ) {
217 view->setCaption( name );
218 mViewDict.insert( name, view );
219//US my version needs an int as second parameter to addWidget
220 mViewWidgetStack->addWidget( view, -1 );
221 view->readConfig( config );
222
223 // The manager just relays the signals
224 connect( view, SIGNAL( selected( const QString& ) ),
225 SIGNAL( selected( const QString & ) ) );
226 connect( view, SIGNAL( executed( const QString& ) ),
227 SIGNAL( executed( const QString& ) ) );
228
229 connect( view, SIGNAL( deleteRequest( ) ),
230 SIGNAL( deleteRequest( ) ) );
231
232 connect( view, SIGNAL( modified() ), SIGNAL( modified() ) );
233 connect( view, SIGNAL( dropped( QDropEvent* ) ),
234 SLOT( dropped( QDropEvent* ) ) );
235 connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) );
236 }
237 }
238
239 // If we found or created the view, raise it and refresh it
240 if ( view ) {
241 mActiveView = view;
242 mViewWidgetStack->raiseWidget( view );
243 // Set the proper filter in the view. By setting the combo
244 // box, the activated slot will be called, which will push
245 // the filter to the view and refresh it.
246
247 if ( view->defaultFilterType() == KAddressBookView::None ) {
248
249 mActionSelectFilter->setCurrentItem( 0 );
250 setActiveFilter( 0 );
251 } else if ( view->defaultFilterType() == KAddressBookView::Active ) {
252 setActiveFilter( mActionSelectFilter->currentItem() );
253 } else {
254 uint pos = filterPosition( view->defaultFilterName() );
255 mActionSelectFilter->setCurrentItem( pos );
256 setActiveFilter( pos );
257 }
258//US qDebug("ViewManager::setActiveView 6" );
259
260 // Update the inc search widget to show the fields in the new active
261 // view.
262 mCore->setSearchFields( mActiveView->fields() );
263
264 mActiveView->refresh();
265
266 }
267 else
268 {
269 qDebug("ViewManager::setActiveView: unable to find view" );
270 kdDebug(5720) << "ViewManager::setActiveView: unable to find view\n";
271 }
272}
273
274//US added another method with no parameter, since my moc compiler does not support default parameters.
275void ViewManager::refreshView()
276{
277 refreshView( QString::null );
278}
279
280void ViewManager::refreshView( const QString &uid )
281{
282 if ( mActiveView )
283 mActiveView->refresh( uid );
284}
285
286void ViewManager::editView()
287{
288 if ( !mActiveView )
289 return;
290
291 ViewFactory *factory = mViewFactoryDict.find( mActiveView->type() );
292 ViewConfigureWidget *wdg = 0;
293 ViewConfigureDialog* dlg = 0;
294 if ( factory ) {
295 // Save the filters so the dialog has the latest set
296 Filter::save( mCore->config(), "Filter", mFilterList );
297 dlg = new ViewConfigureDialog( 0, mActiveView->caption(), this, "conf_dlg" );
298 wdg = factory->configureWidget( mCore->addressBook(), dlg,"conf_wid" );
299 } else {
300 qDebug("ViewManager::editView()::cannot find viewfactory ");
301 return;
302 }
303 if ( wdg ) {
304 dlg->setWidget( wdg );
305
306#ifndef DESKTOP_VERSION
307 //dlg.setMaximumSize( 640, 480 );
308 //dlg->setGeometry( 40,40, 400, 300);
309 dlg->showMaximized();
310#endif
311
312 KConfigGroupSaver saver( mCore->config(), mActiveView->caption() );
313
314 dlg->restoreSettings( mCore->config() );
315
316 if ( dlg->exec() ) {
317 dlg->saveSettings( mCore->config() );
318 mActiveView->readConfig( mCore->config() );
319
320 // Set the proper filter in the view. By setting the combo
321 // box, the activated slot will be called, which will push
322 // the filter to the view and refresh it.
323 if ( mActiveView->defaultFilterType() == KAddressBookView::None ) {
324 mActionSelectFilter->setCurrentItem( 0 );
325 setActiveFilter( 0 );
326 } else if ( mActiveView->defaultFilterType() == KAddressBookView::Active ) {
327 setActiveFilter( mActionSelectFilter->currentItem() );
328 } else {
329 uint pos = filterPosition( mActiveView->defaultFilterName() );
330 mActionSelectFilter->setCurrentItem( pos );
331 setActiveFilter( pos );
332 }
333 mCore->setSearchFields( mActiveView->fields() );
334 mActiveView->refresh();
335 }
336
337 }
338 delete dlg;
339}
340
341void ViewManager::deleteView()
342{
343 QString text = i18n( "<qt>Are you sure that you want to delete the view <b>%1</b>?</qt>" )
344 .arg( mActiveView->caption() );
345 QString caption = i18n( "Confirm Delete" );
346
347
348 if (QMessageBox::information( this, caption,
349 text,
350 i18n("Yes!"), i18n("No"), 0, 0 ) == 0)
351 {
352 mViewNameList.remove( mActiveView->caption() );
353
354 // remove the view from the config file
355 KConfig *config = mCore->config();
356 config->deleteGroup( mActiveView->caption() );
357
358 mViewDict.remove( mActiveView->caption() );
359 mActiveView = 0;
360
361 // we are in an invalid state now, but that should be fixed after
362 // we emit the signal
363 mActionSelectView->setItems( mViewNameList );
364 if ( mViewNameList.count() > 0 ) {
365 mActionSelectView->setCurrentItem( 0 );
366 setActiveView( mViewNameList[ 0 ] );
367 }
368 mActionDeleteView->setEnabled( mViewNameList.count() > 1 );
369 }
370}
371
372void ViewManager::addView()
373{
374 AddViewDialog dialog( &mViewFactoryDict, this );
375
376 if ( dialog.exec() ) {
377 QString newName = dialog.viewName();
378 QString type = dialog.viewType();
379
380 // Check for name conflicts
381 bool firstConflict = true;
382 int numTries = 1;
383 while ( mViewNameList.contains( newName ) > 0 ) {
384 if ( !firstConflict ) {
385 newName = newName.left( newName.length() - 4 );
386 firstConflict = false;
387 }
388
389 newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries );
390 numTries++;
391 }
392
393 // Add the new one to the list
394 mViewNameList.append( newName );
395
396 // write the view to the config file,
397 KConfig *config = mCore->config();
398
399 config->deleteGroup( newName );
400
401 KConfigGroupSaver saver( config, newName );
402
403 config->writeEntry( "Type", type );
404
405 // try to set the active view
406 mActionSelectView->setItems( mViewNameList );
407 mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) );
408 setActiveView( newName );
409
410 editView();
411
412 mActionDeleteView->setEnabled( mViewNameList.count() > 1 );
413 }
414}
415
416void ViewManager::createViewFactories()
417{
418#ifndef KAB_EMBEDDED
419 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" );
420 KTrader::OfferList::ConstIterator it;
421 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
422 if ( !(*it)->hasServiceType( "KAddressBook/View" ) )
423 continue;
424
425 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
426
427 if ( !factory ) {
428 kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl;
429 continue;
430 }
431
432 ViewFactory *viewFactory = static_cast<ViewFactory*>( factory );
433
434 if ( !viewFactory ) {
435 kdDebug(5720) << "ViewManager::createViewFactories(): Cast failed" << endl;
436 continue;
437 }
438
439 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
440 }
441
442#else //KAB_EMBEDDED
443 ViewFactory* viewFactory = new IconViewFactory();
444 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
445// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
446
447 viewFactory = new TableViewFactory();
448 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
449// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
450
451 viewFactory = new CardViewFactory();
452 mViewFactoryDict.insert( viewFactory->type(), viewFactory );
453// qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1());
454
455#endif //KAB_EMBEDDED
456
457}
458
459void ViewManager::dropped( QDropEvent *e )
460{
461 kdDebug(5720) << "ViewManager::dropped: got a drop event" << endl;
462
463#ifndef KAB_EMBEDDED
464
465 QString clipText, vcards;
466 KURL::List urls;
467
468 if ( KURLDrag::decode( e, urls) ) {
469 KURL::List::Iterator it = urls.begin();
470 int c = urls.count();
471 if ( c > 1 ) {
472 QString questionString = i18n( "Import one contact into your addressbook?", "Import %n contacts into your addressbook?", c );
473 if ( KMessageBox::questionYesNo( this, questionString, i18n( "Import Contacts?" ) ) == KMessageBox::Yes ) {
474 for ( ; it != urls.end(); ++it )
475 emit urlDropped( *it );
476 }
477 } else if ( c == 1 )
478 emit urlDropped( *it );
479 } else if ( KVCardDrag::decode( e, vcards ) ) {
480 KABC::Addressee addr;
481 KABC::VCardConverter converter;
482 QStringList list = QStringList::split( "\r\n\r\n", vcards );
483 QStringList::Iterator it;
484 for ( it = list.begin(); it != list.end(); ++it ) {
485 if ( converter.vCardToAddressee( (*it).stripWhiteSpace(), addr ) ) {
486 KABC::Addressee a = mCore->addressBook()->findByUid( addr.uid() );
487 if ( a.isEmpty() ) {
488 mCore->addressBook()->insertAddressee( addr );
489 emit modified();
490 }
491 }
492 }
493
494 mActiveView->refresh();
495 }
496#else //KAB_EMBEDDED
497qDebug("ViewManager::dropped() has to be changed!!" );
498#endif //KAB_EMBEDDED
499
500}
501
502void ViewManager::startDrag()
503{
504 kdDebug(5720) << "ViewManager::startDrag: starting to drag" << endl;
505
506#ifndef KAB_EMBEDDED
507
508 // Get the list of all the selected addressees
509 KABC::Addressee::List addrList;
510 QStringList uidList = selectedUids();
511 QStringList::Iterator iter;
512 for ( iter = uidList.begin(); iter != uidList.end(); ++iter )
513 addrList.append( mCore->addressBook()->findByUid( *iter ) );
514
515 KMultipleDrag *drag = new KMultipleDrag( this );
516 drag->addDragObject( new QTextDrag( AddresseeUtil::addresseesToClipboard(addrList), this ) );
517 KABC::Addressee::List::Iterator it;
518 QStringList vcards;
519 for ( it = addrList.begin(); it != addrList.end(); ++it ) {
520 QString vcard = QString::null;
521 KABC::VCardConverter converter;
522 if ( converter.addresseeToVCard( *it, vcard ) )
523 vcards.append( vcard );
524 }
525 drag->addDragObject( new KVCardDrag( vcards.join( "\r\n" ), this ) );
526
527 drag->setPixmap( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop ) );
528 drag->dragCopy();
529
530#else //KAB_EMBEDDED
531qDebug("ViewManager::startDrag() has to be changed!!" );
532#endif //KAB_EMBEDDED
533
534}
535
536void ViewManager::setActiveFilter( int index )
537{
538 Filter currentFilter;
539
540 if ( ( index - 1 ) < 0 )
541 currentFilter = Filter();
542 else
543 currentFilter = mFilterList[ index - 1 ];
544
545 // Check if we have a view. Since the filter combo is created before
546 // the view, this slot could be called before there is a valid view.
547 if ( mActiveView ) {
548 mActiveView->setFilter( currentFilter );
549 mActiveView->refresh();
550 emit selected( QString::null );
551 }
552}
553
554void ViewManager::configureFilters()
555{
556 FilterDialog dlg( this );
557
558 dlg.setFilters( mFilterList );
559
560 if ( dlg.exec() )
561 mFilterList = dlg.filters();
562
563 uint pos = mActionSelectFilter->currentItem();
564 mActionSelectFilter->setItems( filterNames() );
565 mActionSelectFilter->setCurrentItem( pos );
566 setActiveFilter( pos );
567}
568
569QStringList ViewManager::filterNames() const
570{
571 QStringList names( i18n( "No Filter" ) );
572
573 Filter::List::ConstIterator it;
574 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it )
575 names.append( (*it).name() );
576
577 return names;
578}
579
580int ViewManager::filterPosition( const QString &name ) const
581{
582 int pos = 0;
583
584 Filter::List::ConstIterator it;
585 for ( it = mFilterList.begin(); it != mFilterList.end(); ++it, ++pos )
586 if ( name == (*it).name() )
587 return pos + 1;
588
589 return 0;
590}
591
592void ViewManager::initActions()
593{
594//US <ActionList name="view_loadedviews"/>
595//US <Separator/>
596
597#ifdef KAB_EMBEDDED
598 QPopupMenu *viewmenu = (QPopupMenu*)mCore->getViewMenu();
599 QPopupMenu *settingsmenu = (QPopupMenu*)mCore->getSettingsMenu();
600 QPopupMenu *filtermenu = (QPopupMenu*)mCore->getFilterMenu();
601#endif //KAB_EMBEDDED
602
603 mActionSelectView = new KSelectAction( i18n( "Select View" ), 0, mCore->actionCollection(), "select_view" );
604#if KDE_VERSION >= 309
605 mActionSelectView->setMenuAccelsEnabled( false );
606#endif
607 connect( mActionSelectView, SIGNAL( activated( const QString& ) ),
608 SLOT( setActiveView( const QString& ) ) );
609
610
611#ifdef KAB_EMBEDDED
612 mActionSelectView->plug(viewmenu);
613 viewmenu->insertSeparator();
614#endif //KAB_EMBEDDED
615
616 KAction *action;
617
618 action = new KAction( i18n( "Modify View..." ), "configure", 0, this,
619 SLOT( editView() ), mCore->actionCollection(), "view_modify" );
620#ifndef KAB_EMBEDDED
621 action->setWhatsThis( i18n( "By pressing this button a dialog opens that allows you to modify the view of the addressbook. There you can add or remove fields that you want to be shown or hidden in the addressbook like the name for example." ) );
622#else //KAB_EMBEDDED
623 action->plug(viewmenu);
624#endif //KAB_EMBEDDED
625
626 action = new KAction( i18n( "Add View..." ), "window_new", 0, this,
627 SLOT( addView() ), mCore->actionCollection(), "view_add" );
628#ifndef KAB_EMBEDDED
629 action->setWhatsThis( i18n( "You can add a new view by choosing one of the dialog that appears after pressing the button. You have to give the view a name, so that you can distinguish between the different views." ) );
630#else //KAB_EMBEDDED
631 action->plug(viewmenu);
632#endif //KAB_EMBEDDED
633
634 mActionDeleteView = new KAction( i18n( "Delete View" ), "view_remove", 0,
635 this, SLOT( deleteView() ),
636 mCore->actionCollection(), "view_delete" );
637#ifndef KAB_EMBEDDED
638 mActionDeleteView->setWhatsThis( i18n( "By pressing this button you can delete the actual view, which you have added before." ) );
639#else //KAB_EMBEDDED
640 mActionDeleteView->plug(viewmenu);
641 viewmenu->insertSeparator();
642#endif //KAB_EMBEDDED
643
644#ifndef KAB_EMBEDDED
645 action = new KAction( i18n( "Refresh View" ), "reload", 0, this,
646 SLOT( refreshView(const QString &) ), mCore->actionCollection(),
647 "view_refresh" );
648 action->setWhatsThis( i18n( "The view will be refreshed by pressing this button." ) );
649#else //KAB_EMBEDDED
650 action = new KAction( i18n( "Refresh View" ), "reload", 0, this,
651 SLOT( refreshView()), mCore->actionCollection(),
652 "view_refresh" );
653 action->plug(viewmenu);
654 viewmenu->insertSeparator();
655#endif //KAB_EMBEDDED
656
657 action = new KAction( i18n( "Edit &Filters..." ), "filter", 0, this,
658 SLOT( configureFilters() ), mCore->actionCollection(),
659 "options_edit_filters" );
660
661 mActionSelectFilter = new KSelectAction( i18n( "Select Filter" ), "filter", mCore->actionCollection(), "select_filter" );
662
663#if KDE_VERSION >= 309
664 mActionSelectFilter->setMenuAccelsEnabled( false );
665#endif
666 connect( mActionSelectFilter, SIGNAL( activated( int ) ),
667 SLOT( setActiveFilter( int ) ) );
668
669#ifdef KAB_EMBEDDED
670 action->plug(settingsmenu);
671 mActionSelectFilter->plug(viewmenu);
672#endif //KAB_EMBEDDED
673
674}
675
676void ViewManager::initGUI()
677{
678 QHBoxLayout *layout = new QHBoxLayout( this, 0, 0 );
679 mViewWidgetStack = new QWidgetStack( this );
680 layout->addWidget( mViewWidgetStack );
681}
682
683#ifndef KAB_EMBEDDED
684#include "viewmanager.moc"
685#endif //KAB_EMBEDDED
diff --git a/kaddressbook/viewmanager.h b/kaddressbook/viewmanager.h
new file mode 100644
index 0000000..a18e87d
--- a/dev/null
+++ b/kaddressbook/viewmanager.h
@@ -0,0 +1,152 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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#ifndef VIEWMANAGER_H
25#define VIEWMANAGER_H
26
27#include <qwidget.h>
28#include <qstringlist.h>
29#include <kaddressbookview.h>
30#include <qdict.h>
31
32class KAction;
33class KSelectAction;
34
35class KABCore;
36class QWidgetStack;
37class QDropEvent;
38
39namespace KABC { class AddressBook; }
40
41/**
42 The view manager manages the views and everything related to them. The
43 manager will load the views at startup and display a view when told to
44 make one active.
45
46 The view manager will also create and manage all dialogs directly related to
47 views (ie: AddView, ConfigureView, DeleteView, etc).
48 */
49class ViewManager : public QWidget
50{
51 Q_OBJECT
52 public:
53 ViewManager( KABCore *core, QWidget *parent, const char *name = 0 );
54 ~ViewManager();
55
56 void restoreSettings();
57 void saveSettings();
58
59 void unloadViews();
60 KSelectAction * getFilterAction() { return mActionSelectFilter; }
61
62 QStringList selectedUids() const;
63 QStringList selectedEmails() const;
64 KABC::Addressee::List selectedAddressees() const;
65
66 public slots:
67
68//US void setSelected( const QString &uid = QString::null, bool selected = true );
69 void setSelected( const QString &uid, bool);
70//US added another method with no parameter, since my moc compiler does not support default parameters.
71 void setSelected();
72
73
74
75//US added another method with no parameter, since my moc compiler does not support default parameters.
76 void refreshView();
77 void refreshView( const QString &uid);
78
79 void editView();
80 void deleteView();
81 void addView();
82
83 protected slots:
84 /**
85 Called whenever the user drops something in the active view.
86 This method will try to decode what was dropped, and if it was
87 a valid addressee, add it to the addressbook.
88 */
89 void dropped( QDropEvent* );
90
91 /**
92 Called whenever the user attempts to start a drag in the view.
93 This method will convert all the selected addressees into text (vcard)
94 and create a drag object.
95 */
96 void startDrag();
97
98 signals:
99 /**
100 Emitted whenever the user selects an entry in the view.
101 */
102 void selected( const QString &uid );
103 void deleteRequest( );
104
105 /**
106 Emitted whenever the user activates an entry in the view.
107 */
108 void executed( const QString &uid );
109
110 /**
111 Emitted whenever the address book is modified in some way.
112 */
113 void modified();
114
115 /**
116 Emitted whenever a url is dragged on a view.
117 */
118 void urlDropped( const KURL& );
119
120 private slots:
121 void setActiveView( const QString &name );
122 void setActiveFilter( int index );
123 void configureFilters();
124
125 private:
126 void createViewFactories();
127 QStringList filterNames() const;
128 int filterPosition( const QString &name ) const;
129 QStringList viewNames() const;
130 int viewPosition( const QString &name ) const;
131 void initActions();
132 void initGUI();
133
134 KABCore *mCore;
135
136 Filter mCurrentFilter;
137 Filter::List mFilterList;
138
139 QDict<KAddressBookView> mViewDict;
140 QDict<ViewFactory> mViewFactoryDict;
141 QStringList mViewNameList;
142
143 QWidgetStack *mViewWidgetStack;
144 KAddressBookView *mActiveView;
145
146 KAction *mActionDeleteView;
147 KSelectAction *mActionSelectFilter;
148 KSelectAction *mActionSelectView;
149
150};
151
152#endif
diff --git a/kaddressbook/views/cardview.cpp b/kaddressbook/views/cardview.cpp
new file mode 100644
index 0000000..65f793c
--- a/dev/null
+++ b/kaddressbook/views/cardview.cpp
@@ -0,0 +1,1719 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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//BEGIN Includes
25#include "cardview.h"
26
27#include <limits.h>
28
29#include <qpainter.h>
30#include <qtimer.h>
31#include <qdatetime.h>
32#include <qlabel.h>
33#include <qstyle.h>
34#include <qcursor.h>
35#include <qtooltip.h>
36
37#include <kdebug.h>
38#include <kglobalsettings.h>
39//END includes
40
41#define MIN_ITEM_WIDTH 80
42
43//BEGIN Helpers
44//////////////////////////////////////
45// CardViewTip
46class CardViewTip : public QLabel {
47 public:
48 CardViewTip(QWidget *parent=0, const char *name=0) : QLabel( parent, name )
49 {
50 setPalette( QToolTip::palette() );
51 setFrameStyle( Panel|Plain );
52 setMidLineWidth(0);
53 setIndent(1);
54 }
55
56 ~CardViewTip() {};
57 protected:
58 void leaveEvent( QEvent * )
59 {
60 hide();
61 }
62};
63
64//////////////////////////////////////
65// CardViewItemList
66
67
68//
69// Warning: make sure you use findRef() instead of find() to find an
70// item! Only the pointer value is unique in the list.
71//
72class CardViewItemList : public QPtrList<CardViewItem>
73{
74 protected:
75 virtual int compareItems(QPtrCollection::Item item1,
76 QPtrCollection::Item item2)
77 {
78 CardViewItem *cItem1 = (CardViewItem*)item1;
79 CardViewItem *cItem2 = (CardViewItem*)item2;
80
81 if ( cItem1 == cItem2 )
82 return 0;
83
84 if ((cItem1 == 0) || (cItem2 == 0))
85 return cItem1 ? -1 : 1;
86
87 if (cItem1->caption() < cItem2->caption())
88 return -1;
89
90 else if (cItem1->caption() > cItem2->caption())
91 return 1;
92
93 return 0;
94 }
95
96 private:
97 /*int find( const CardViewItem * )
98 {
99 qDebug("DON'T USE CardViewItemList::find( item )! Use findRef( item )!");
100 }*/
101};
102
103//////////////////////////////////////
104// CardViewSeparator
105class CardViewSeparator
106{
107 friend class CardView;
108
109 public:
110 CardViewSeparator(CardView *view)
111 : mView(view)
112 {
113 mRect = QRect(0, 0, view->separatorWidth(), 0);
114 }
115
116 ~CardViewSeparator() {}
117
118 void paintSeparator(QPainter *p, QColorGroup &cg)
119 {
120 p->fillRect(0, 0, mRect.width(), mRect.height(),
121 cg.brush(QColorGroup::Button));
122 }
123
124 void repaintSeparator()
125 {
126 mView->repaintContents(mRect);
127 }
128
129 private:
130 CardView *mView;
131 QRect mRect;
132};
133
134//END Helpers
135
136//BEGIN Private Data
137
138class CardViewPrivate
139{
140 public:
141 CardViewPrivate()
142 : mSelectionMode( CardView::Multi ),
143 mDrawCardBorder( true ),
144 mDrawFieldLabels( true ),
145 mDrawSeparators( true),
146 mSepWidth( 2 ),
147 mShowEmptyFields( false ),
148 mLayoutDirty( true ),
149 mLastClickOnItem( false ),
150 mItemMargin( 0 ),
151 mItemSpacing( 10 ),
152 mItemWidth( 200 ),
153 mMaxFieldLines( INT_MAX ),
154 mCurrentItem( 0L ),
155 mLastClickPos( QPoint(0, 0) ),
156 mRubberBandAnchor( 0 ),
157 mCompText( QString::null ),
158 mResizeAnchor(0)
159 {};
160
161 CardViewItemList mItemList;
162 QPtrList<CardViewSeparator> mSeparatorList;
163 QFontMetrics *mFm;
164 QFontMetrics *mBFm; // bold font
165 QFont mHeaderFont; // custom header font
166 CardView::SelectionMode mSelectionMode;
167 bool mDrawCardBorder;
168 bool mDrawFieldLabels;
169 bool mDrawSeparators;
170 int mSepWidth;
171 bool mShowEmptyFields;
172 bool mLayoutDirty;
173 bool mLastClickOnItem;
174 uint mItemMargin; // internal margin in items
175 uint mItemSpacing; // spacing between items, column seperators and border
176 int mItemWidth; // width of all items
177 uint mMaxFieldLines; // Max lines to dispaly pr field
178 CardViewItem *mCurrentItem;
179 QPoint mLastClickPos;
180 QTimer *mTimer; // times out if mouse rests for more than 500 msecs
181 CardViewTip *mTip; // passed to the item under a resting cursor to display full text
182 bool mOnSeparator; // set/reset on mouse movement
183 // for resizing by dragging the separators
184 int mResizeAnchor; // uint, ulong? the mouse down separator left
185 int mRubberBandAnchor; // for erasing rubber bands
186 // data used for resizing.
187 // as they are beeded by each mouse move while resizing, we store them here,
188 // saving 8 calculations in each mouse move.
189 int colspace; // amount of space between items pr column
190 uint first; // the first col to anchor at for painting rubber bands
191 int firstX; // X position of first in pixel
192 int pressed; // the colummn that was pressed on at resizing start
193 int span; // pressed - first
194 // key completion
195 QString mCompText; // current completion string
196 QDateTime mCompUpdated; // ...was updated at this time
197};
198
199class CardViewItemPrivate
200{
201 public:
202 CardViewItemPrivate() :
203 x( 0 ),
204 y( 0 ),
205 mSelected( false ){};
206
207
208 QString mCaption;
209 QPtrList< CardViewItem::Field > mFieldList;
210 bool mSelected;
211 int x; // horizontal position, set by the view
212 int y; // vertical position, set by the view
213 int maxLabelWidth; // the width of the widest label, according to the view font.
214 int hcache; // height cache
215};
216//END Private Data
217
218//BEGIN CardViewItem
219
220CardViewItem::CardViewItem(CardView *parent, QString caption)
221 : d(new CardViewItemPrivate()), mView(parent)
222{
223 d->mCaption = caption;
224
225 initialize();
226}
227
228CardViewItem::~CardViewItem()
229{
230 // Remove ourself from the view
231 if (mView != 0)
232 mView->takeItem(this);
233
234 delete d;
235 d = 0;
236}
237
238void CardViewItem::initialize()
239{
240 d->mSelected = false;
241 d->mFieldList.setAutoDelete(true);
242 d->maxLabelWidth = 0;
243 d->hcache=0;
244
245 //calcRect();
246
247 // Add ourself to the view
248 if (mView != 0)
249 mView->insertItem(this);
250}
251
252void CardViewItem::paintCard(QPainter *p, QColorGroup &cg)
253{
254
255 if (!mView)
256 return;
257
258 QPen pen;
259 QBrush brush;
260 QFontMetrics fm = *(mView->d->mFm);
261 QFontMetrics bFm = *(mView->d->mBFm);
262 bool drawLabels = mView->d->mDrawFieldLabels;
263 bool drawBorder = mView->d->mDrawCardBorder;
264 int mg = mView->itemMargin();
265 int w = mView->itemWidth() - (mg*2);
266 int h = height() - (mg*2);
267 const int colonWidth( fm.width(":") );
268 int labelXPos = 2 + mg;
269 int labelWidth = QMIN( w/2 - 4 - mg, d->maxLabelWidth + colonWidth + 4 );
270 int valueXPos = labelWidth + 4 + mg;
271 int valueWidth = w - labelWidth - 4 - mg;
272
273 p->setFont( mView->font() );
274 labelWidth -= colonWidth; // extra space for the colon
275
276 if (!drawLabels)
277 {
278 valueXPos = labelXPos;
279 valueWidth = w - 4;
280 }
281
282 // Draw a simple box
283 if (isSelected())
284 pen = QPen(cg.highlight(), 1);
285 else
286 pen = QPen(cg.button(), 1);
287 p->setPen(pen);
288
289 // Draw the border - this is only draw if the user asks for it.
290 if (drawBorder)
291 p->drawRect( mg, mg, w, h );
292
293 // set the proper pen color for the caption box
294 if (isSelected())
295 brush = cg.brush(QColorGroup::Highlight);
296 else
297 brush = cg.brush(QColorGroup::Button);
298
299 p->fillRect(mg, mg, w, 4 + bFm.height(), brush);
300
301 // Now paint the caption
302 p->save();
303 QFont bFont = mView->headerFont();
304 //bFont.setBold(true);
305 p->setFont(bFont);
306 if (isSelected())
307 p->setPen(cg.highlightedText());
308 else
309 p->setPen(cg.buttonText());
310 p->drawText(2+mg, 2+mg + bFm.ascent()/*bFm.height()*//*-bFm.descent()*//*-bFm.leading()*/, trimString(d->mCaption, w-4, bFm));
311 p->restore();
312
313 // Go through the fields and draw them
314 QPtrListIterator< CardViewItem::Field > iter(d->mFieldList);
315 QString label, value;
316 int yPos = mg + 4 + bFm.height()/* + 1*/ + fm.height(); // why the + 1 ??? (anders)
317 p->setPen(cg.text());
318
319 int fh = fm.height();
320 int cln( 0 );
321 QString tmp;
322 int maxLines = mView->maxFieldLines();
323 for (iter.toFirst(); iter.current(); ++iter)
324 {
325 value = (*iter)->second;
326 if ( value.isEmpty() && ! mView->d->mShowEmptyFields )
327 continue;
328
329 if (drawLabels)
330 {
331 label = trimString((*iter)->first, labelWidth, fm);
332 p->drawText(labelXPos, yPos, label + ":");
333 }
334/* US original
335 for (cln=0; cln <= maxLines; cln++)
336 {
337 tmp = value.section('\n',cln,cln);
338 if ( !tmp.isEmpty() ) p->drawText( valueXPos, yPos + cln*fh, trimString( tmp, valueWidth, fm ) );
339 else break;
340 }
341*/
342
343//US new implementation
344 QStringList strlst = QStringList::split('\n', value, true);
345
346 for (cln=0; cln <= maxLines && cln <= (int)strlst.count(); cln++)
347 {
348 tmp = strlst[cln];
349
350 if ( !tmp.isEmpty() )
351 p->drawText( valueXPos, yPos + cln*fh, trimString( tmp, valueWidth, fm ) );
352 else
353 break;
354
355 }
356
357 if ( cln == 0 ) cln = 1;
358 yPos += cln * fh + 2;
359 }
360
361 // if we are the current item and the view has focus, draw focus rect
362 if ( mView->currentItem() == this && mView->hasFocus() )
363 {
364/*US
365 mView->style().drawPrimitive( QStyle::PE_FocusRect, p,
366 QRect(0, 0, mView->itemWidth(), h+(2*mg)), cg,
367 QStyle::Style_FocusAtBorder,
368 QStyleOption( isSelected() ? cg.highlight() : cg.base() ) );
369*/
370
371 const QColor pHighl = isSelected() ? cg.highlight() : cg.base();
372 const QRect r(0, 0, mView->itemWidth(), h+(2*mg));
373#ifndef DESKTOP_VERSION
374 mView->style().drawFocusRect(p, r, cg, &pHighl, true);
375#endif
376 }
377}
378
379const QString &CardViewItem::caption() const
380{
381 return d->mCaption;
382}
383
384
385int CardViewItem::height( bool allowCache ) const
386{
387 // use cache
388 if ( allowCache && d->hcache )
389 return d->hcache;
390
391 // Base height:
392 // 2 for line width
393 // 2 for top caption pad
394 // 2 for bottom caption pad
395 // 2 pad for the end
396 // + 2 times the advised margin
397 int baseHeight = 8 + ( 2 * mView->itemMargin() );
398
399 // size of font for each field
400 // 2 pad for each field
401
402 // anders: if the view does not show empty fields, check for value
403 bool sef = mView->showEmptyFields();
404 int fh = mView->d->mFm->height();//lineSpacing(); // font height
405 //int sp = QMAX( 0, 2- mView->d->mFm->leading() ); // field spacing NOTE make a property
406 int fieldHeight = 0;
407 int lines;
408 int maxLines( mView->maxFieldLines() );
409 QPtrListIterator< CardViewItem::Field > iter(d->mFieldList);
410 for (iter.toFirst(); iter.current(); ++iter)
411 {
412 if ( !sef && (*iter)->second.isEmpty() )
413 continue;
414 lines = QMIN( (*iter)->second.contains('\n') + 1, maxLines );
415 fieldHeight += ( lines * fh ) + 2;//sp;
416 }
417
418 // height of caption font (bold)
419 fieldHeight += mView->d->mBFm->height();
420 d->hcache = baseHeight + fieldHeight;
421 return d->hcache;
422}
423
424bool CardViewItem::isSelected() const
425{
426 return d->mSelected;
427}
428
429void CardViewItem::setSelected(bool selected)
430{
431 d->mSelected = selected;
432}
433
434void CardViewItem::insertField(const QString &label, const QString &value)
435{
436 CardViewItem::Field *f = new CardViewItem::Field(label, value);
437 d->mFieldList.append(f);
438 d->hcache=0;
439
440 if (mView)
441 {
442 mView->setLayoutDirty(true);
443 d->maxLabelWidth = QMAX( mView->d->mFm->width( label ), d->maxLabelWidth );
444 }
445}
446
447void CardViewItem::removeField(const QString &label)
448{
449 CardViewItem::Field *f;
450
451 QPtrListIterator< CardViewItem::Field > iter(d->mFieldList);
452 for (iter.toFirst(); iter.current(); ++iter)
453 {
454 f = *iter;
455 if (f->first == label)
456 break;
457 }
458
459 if (*iter)
460 d->mFieldList.remove(*iter);
461 d->hcache = 0;
462
463 if (mView)
464 mView->setLayoutDirty(true);
465}
466
467void CardViewItem::clearFields()
468{
469 d->mFieldList.clear();
470 d->hcache = 0;
471
472 if (mView)
473 mView->setLayoutDirty(true);
474}
475
476QString CardViewItem::trimString(const QString &text, int width,
477 QFontMetrics &fm)
478{
479 if (fm.width(text) <= width)
480 return text;
481
482 QString dots = "...";
483 int dotWidth = fm.width(dots);
484 QString trimmed;
485 int charNum = 0;
486
487 while (fm.width(trimmed) + dotWidth < width)
488 {
489 trimmed += text[charNum];
490 charNum++;
491 }
492
493 // Now trim the last char, since it put the width over the top
494 trimmed = trimmed.left(trimmed.length()-1);
495 trimmed += dots;
496
497 return trimmed;
498}
499
500CardViewItem *CardViewItem::nextItem()
501{
502 CardViewItem *item = 0;
503
504 if (mView)
505 item = mView->itemAfter(this);
506
507 return item;
508}
509
510void CardViewItem::repaintCard()
511{
512 if (mView)
513 mView->repaintItem(this);
514}
515
516void CardViewItem::setCaption(const QString &caption)
517{
518 d->mCaption = caption;
519 repaintCard();
520}
521
522QString CardViewItem::fieldValue(const QString &label)
523{
524 QPtrListIterator< CardViewItem::Field > iter(d->mFieldList);
525 for (iter.toFirst(); iter.current(); ++iter)
526 if ((*iter)->first == label)
527 return (*iter)->second;
528
529 return QString();
530}
531
532
533void CardViewItem::showFullString( const QPoint &itempos, CardViewTip *tip )
534{
535 bool trimmed( false );
536 QString s;
537 int mrg = mView->itemMargin();
538 int y = mView->d->mBFm->height() + 6 + mrg;
539 int w = mView->itemWidth() - (2*mrg);
540 int lw;
541 bool drawLabels = mView->drawFieldLabels();
542 bool isLabel = drawLabels && itempos.x() < w/2 ? true : false;
543
544 if ( itempos.y() < y )
545 {
546 if ( itempos.y() < 8 + mrg || itempos.y() > y - 4 )
547 return;
548 // this is the caption
549 s = caption();
550 trimmed = mView->d->mBFm->width( s ) > w - 4;
551 y = 2 + mrg;
552 lw = 0;
553 isLabel=true;
554 } else {
555 // find the field
556 Field *f = fieldAt( itempos );
557 if ( !f || ( !mView->showEmptyFields() && f->second.isEmpty() ) )
558 return;
559
560 // y position:
561 // header font height + 4px hader margin + 2px leading + item margin
562 // + actual field index * (fontheight + 2px leading)
563 int maxLines = mView->maxFieldLines();
564 bool se = mView->showEmptyFields();
565 int fh = mView->d->mFm->height();
566// {
567 Field *_f;
568 for (_f = d->mFieldList.first(); _f != f; _f = d->mFieldList.next())
569 if ( se || ! _f->second.isEmpty() )
570 y += ( QMIN(_f->second.contains('\n')+1, maxLines) * fh ) + 2;
571// }
572 if ( isLabel && itempos.y() > y + fh )
573 return;
574 // label or data?
575 s = isLabel ? f->first : f->second;
576 // trimmed?
577 int colonWidth = mView->d->mFm->width(":");
578 lw = drawLabels ? // label width
579 QMIN( w/2 - 4 - mrg, d->maxLabelWidth + colonWidth + 4 ) :
580 0;
581 int mw = isLabel ? lw - colonWidth : w - lw - (mrg*2); // max width for string
582 if ( isLabel )
583 {
584 trimmed = mView->d->mFm->width( s ) > mw - colonWidth;
585 } else {
586 QRect r( mView->d->mFm->boundingRect( 0, 0, INT_MAX, INT_MAX, Qt::AlignTop|Qt::AlignLeft, s ) );
587 trimmed = r.width() > mw || r.height()/fh > QMIN(s.contains('\n') + 1, maxLines);
588 }
589 }
590 if ( trimmed )
591 {
592 tip->setFont( (isLabel && !lw) ? mView->headerFont() : mView->font() ); // if condition is true, a header
593 tip->setText( s );
594 tip->adjustSize();
595 // find a proper position
596 int lx;
597 lx = isLabel || !drawLabels ? mrg : lw + mrg + 2 /*-1*/;
598 QPoint pnt(mView->contentsToViewport( QPoint(d->x, d->y) ));
599 pnt += QPoint(lx, y);
600 if ( pnt.x() < 0 )
601 pnt.setX( 0 );
602 if ( pnt.x() + tip->width() > mView->visibleWidth() )
603 pnt.setX( mView->visibleWidth() - tip->width() );
604 if ( pnt.y() + tip->height() > mView->visibleHeight() )
605 pnt.setY( QMAX( 0, mView->visibleHeight() - tip->height() ) );
606 // show
607 tip->move( pnt );
608 tip->show();
609 }
610}
611
612CardViewItem::Field *CardViewItem::fieldAt( const QPoint & itempos ) const
613{
614 int ypos = mView->d->mBFm->height() + 7 + mView->d->mItemMargin;
615 int iy = itempos.y();
616 // skip below caption
617 if ( iy <= ypos )
618 return 0;
619 // try find a field
620 bool showEmpty = mView->showEmptyFields();
621 int fh = mView->d->mFm->height();
622 int maxLines = mView->maxFieldLines();
623 Field *f;
624 for ( f = d->mFieldList.first(); f; f = d->mFieldList.next() )
625 {
626 if ( showEmpty || !f->second.isEmpty() )
627 ypos += ( QMIN( f->second.contains('\n')+1, maxLines ) *fh)+2;
628 if ( iy <= ypos )
629 break;
630 }
631 return f ? f : 0;
632}
633//END CardViewItem
634
635//BEGIN CardView
636
637CardView::CardView(QWidget *parent, const char *name)
638 : QScrollView(parent, name),
639 d(new CardViewPrivate())
640{
641 d->mItemList.setAutoDelete(true);
642 d->mSeparatorList.setAutoDelete(true);
643
644 QFont f = font();
645 d->mFm = new QFontMetrics(f);
646 f.setBold(true);
647 d->mHeaderFont = f;
648 d->mBFm = new QFontMetrics(f);
649 d->mTip = ( new CardViewTip( viewport() ) ),
650 d->mTip->hide();
651 d->mTimer = ( new QTimer(this, "mouseTimer") ),
652
653 viewport()->setMouseTracking( true );
654 viewport()->setFocusProxy(this);
655 viewport()->setFocusPolicy(WheelFocus);
656 viewport()->setBackgroundMode(PaletteBase);
657
658 connect( d->mTimer, SIGNAL(timeout()), this, SLOT(tryShowFullText()) );
659
660//US setBackgroundMode(PaletteBackground, PaletteBase);
661 setBackgroundMode(PaletteBackground);
662
663 // no reason for a vertical scrollbar
664 setVScrollBarMode(AlwaysOff);
665}
666
667CardView::~CardView()
668{
669 delete d->mFm;
670 delete d->mBFm;
671 delete d;
672 d = 0;
673}
674
675void CardView::insertItem(CardViewItem *item)
676{
677 d->mItemList.inSort(item);
678 setLayoutDirty(true);
679}
680
681void CardView::takeItem(CardViewItem *item)
682{
683 if ( d->mCurrentItem == item )
684 d->mCurrentItem = item->nextItem();
685 d->mItemList.take(d->mItemList.findRef(item));
686
687 setLayoutDirty(true);
688}
689
690void CardView::clear()
691{
692 d->mItemList.clear();
693
694 setLayoutDirty(true);
695}
696
697CardViewItem *CardView::currentItem()
698{
699 if ( ! d->mCurrentItem && d->mItemList.count() )
700 d->mCurrentItem = d->mItemList.first();
701 return d->mCurrentItem;
702}
703
704void CardView::setCurrentItem( CardViewItem *item )
705{
706 if ( !item )
707 return;
708 else if ( item->cardView() != this )
709 {
710 kdDebug(5720)<<"CardView::setCurrentItem: Item ("<<item<<") not owned! Backing out.."<<endl;
711 return;
712 }
713 else if ( item == currentItem() )
714 {
715 return;
716 }
717
718 if ( d->mSelectionMode == Single )
719 {
720 setSelected( item, true );
721 }
722 else
723 {
724 CardViewItem *it = d->mCurrentItem;
725 d->mCurrentItem = item;
726 if ( it )
727 it->repaintCard();
728 item->repaintCard();
729 }
730 if ( ! d->mOnSeparator )
731 ensureItemVisible( item );
732 emit currentChanged( item );
733}
734
735CardViewItem *CardView::itemAt(const QPoint &viewPos)
736{
737 CardViewItem *item = 0;
738 QPtrListIterator<CardViewItem> iter(d->mItemList);
739 bool found = false;
740 for (iter.toFirst(); iter.current() && !found; ++iter)
741 {
742 item = *iter;
743 //if (item->d->mRect.contains(viewPos))
744 if (QRect(item->d->x, item->d->y, d->mItemWidth, item->height()).contains(viewPos))
745 found = true;
746 }
747
748 if (found)
749 return item;
750
751 return 0;
752}
753
754QRect CardView::itemRect(const CardViewItem *item)
755{
756 //return item->d->mRect;
757 return QRect(item->d->x, item->d->y, d->mItemWidth, item->height());
758}
759
760void CardView::ensureItemVisible(const CardViewItem *item)
761{
762 ensureVisible(item->d->x , item->d->y, d->mItemSpacing, 0);
763 ensureVisible(item->d->x + d->mItemWidth, item->d->y, d->mItemSpacing, 0);
764}
765
766void CardView::repaintItem(const CardViewItem *item)
767{
768 //repaintContents(item->d->mRect);
769 repaintContents( QRect(item->d->x, item->d->y, d->mItemWidth, item->height()) );
770}
771
772void CardView::setSelectionMode(CardView::SelectionMode mode)
773{
774 selectAll(false);
775
776 d->mSelectionMode = mode;
777}
778
779CardView::SelectionMode CardView::selectionMode() const
780{
781 return d->mSelectionMode;
782}
783
784void CardView::selectAll(bool state)
785{
786 QPtrListIterator<CardViewItem> iter(d->mItemList);
787 if (!state)
788 {
789 for (iter.toFirst(); iter.current(); ++iter)
790 {
791 if ((*iter)->isSelected())
792 {
793 (*iter)->setSelected(false);
794 (*iter)->repaintCard();
795 }
796 }
797 //emit selectionChanged(); // WARNING FIXME
798 emit selectionChanged(0);
799 }
800 else if (d->mSelectionMode != CardView::Single)
801 {
802 for (iter.toFirst(); iter.current(); ++iter)
803 {
804 (*iter)->setSelected(true);
805 }
806
807 if (d->mItemList.count() > 0)
808 {
809 // emit, since there must have been at least one selected
810 emit selectionChanged();
811 //repaint();//???
812 viewport()->update();
813 }
814 }
815}
816
817void CardView::setSelected(CardViewItem *item, bool selected)
818{
819 if ((item == 0) || (item->isSelected() == selected))
820 return;
821
822 if ( selected && d->mCurrentItem != item )
823 {
824 CardViewItem *it = d->mCurrentItem;
825 d->mCurrentItem = item;
826 if ( it )
827 it->repaintCard();
828 }
829
830 if (d->mSelectionMode == CardView::Single)
831 {
832 bool b = signalsBlocked();
833 blockSignals(true);
834 selectAll(false);
835 blockSignals(b);
836
837 if (selected)
838 {
839 item->setSelected(selected);
840 item->repaintCard();
841 emit selectionChanged();
842 emit selectionChanged(item);
843 }
844 else
845 {
846 emit selectionChanged();
847 emit selectionChanged(0);
848 }
849 }
850 else if (d->mSelectionMode == CardView::Multi)
851 {
852 item->setSelected(selected);
853 item->repaintCard();
854 emit selectionChanged();
855 }
856 else if (d->mSelectionMode == CardView::Extended)
857 {
858 bool b = signalsBlocked();
859 blockSignals(true);
860 selectAll(false);
861 blockSignals(b);
862
863 item->setSelected(selected);
864 item->repaintCard();
865 emit selectionChanged();
866 }
867}
868
869bool CardView::isSelected(CardViewItem *item) const
870{
871 return (item && item->isSelected());
872}
873
874CardViewItem *CardView::selectedItem() const
875{
876 // find the first selected item
877 QPtrListIterator<CardViewItem> iter(d->mItemList);
878 for (iter.toFirst(); iter.current(); ++iter)
879 {
880 if ((*iter)->isSelected())
881 return *iter;
882 }
883
884 return 0;
885}
886
887CardViewItem *CardView::firstItem() const
888{
889 return d->mItemList.first();
890}
891
892int CardView::childCount() const
893{
894 return d->mItemList.count();
895}
896/*US
897CardViewItem *CardView::findItem(const QString &text, const QString &label,
898 Qt::StringComparisonMode compare)
899{
900 // IF the text is empty, we will return null, since empty text will
901 // match anything!
902 if (text.isEmpty())
903 return 0;
904
905 QPtrListIterator<CardViewItem> iter(d->mItemList);
906 if (compare & Qt::BeginsWith)
907 {
908 QString value;
909 for (iter.toFirst(); iter.current(); ++iter)
910 {
911 value = (*iter)->fieldValue(label).upper();
912 if (value.startsWith(text.upper()))
913 return *iter;
914 }
915 }
916 else
917 {
918 kdDebug(5720) << "CardView::findItem: search method not implemented" << endl;
919 }
920
921 return 0;
922}
923*/
924
925uint CardView::columnWidth()
926{
927 return d->mDrawSeparators ?
928 d->mItemWidth + ( 2 * d->mItemSpacing ) + d->mSepWidth :
929 d->mItemWidth + d->mItemSpacing;
930}
931
932void CardView::drawContents(QPainter *p, int clipx, int clipy,
933 int clipw, int cliph)
934{
935 QScrollView::drawContents(p, clipx, clipy, clipw, cliph);
936
937 if (d->mLayoutDirty)
938 calcLayout();
939
940 //kdDebug() << "CardView::drawContents: " << clipx << ", " << clipy
941 // << ", " << clipw << ", " << cliph << endl;
942
943 QColorGroup cg = viewport()->palette().active(); // allow setting costum colors in the viewport pale
944
945 QRect clipRect(clipx, clipy, clipw, cliph);
946 QRect cardRect;
947 QRect sepRect;
948 CardViewItem *item;
949 CardViewSeparator *sep;
950
951 // make sure the viewport is a pure background
952 viewport()->erase(clipRect);
953
954 // Now tell the cards to draw, if they are in the clip region
955 QPtrListIterator<CardViewItem> iter(d->mItemList);
956 for (iter.toFirst(); iter.current(); ++iter)
957 {
958 item = *iter;
959 cardRect.setRect( item->d->x, item->d->y, d->mItemWidth, item->height() );
960
961 if (clipRect.intersects(cardRect) || clipRect.contains(cardRect))
962 {
963 //kdDebug() << "\trepainting card at: " << cardRect.x() << ", "
964 // << cardRect.y() << endl;
965
966 // Tell the card to paint
967 p->save();
968 p->translate(cardRect.x(), cardRect.y());
969 item->paintCard(p, cg);
970 p->restore();
971 }
972 }
973
974 // Followed by the separators if they are in the clip region
975 QPtrListIterator<CardViewSeparator> sepIter(d->mSeparatorList);
976 for (sepIter.toFirst(); sepIter.current(); ++sepIter)
977 {
978 sep = *sepIter;
979 sepRect = sep->mRect;
980
981 if (clipRect.intersects(sepRect) || clipRect.contains(sepRect))
982 {
983 p->save();
984 p->translate(sepRect.x(), sepRect.y());
985 sep->paintSeparator(p, cg);
986 p->restore();
987 }
988 }
989}
990
991void CardView::resizeEvent(QResizeEvent *e)
992{
993 QScrollView::resizeEvent(e);
994
995 setLayoutDirty(true);
996}
997
998void CardView::calcLayout()
999{
1000 //kdDebug() << "CardView::calcLayout:" << endl;
1001
1002 // Start in the upper left corner and layout all the
1003 // cars using their height and width
1004 int maxWidth = 0;
1005 int maxHeight = 0;
1006 int xPos = 0;
1007 int yPos = 0;
1008 int cardSpacing = d->mItemSpacing;
1009
1010 // delete the old separators
1011 d->mSeparatorList.clear();
1012
1013 QPtrListIterator<CardViewItem> iter(d->mItemList);
1014 CardViewItem *item = 0;
1015 CardViewSeparator *sep = 0;
1016 xPos += cardSpacing;
1017
1018 for (iter.toFirst(); iter.current(); ++iter)
1019 {
1020 item = *iter;
1021
1022 yPos += cardSpacing;
1023
1024 if (yPos + item->height() + cardSpacing >= height() - horizontalScrollBar()->height())
1025 {
1026 maxHeight = QMAX(maxHeight, yPos);
1027
1028 // Drawing in this column would be greater than the height
1029 // of the scroll view, so move to next column
1030 yPos = cardSpacing;
1031 xPos += cardSpacing + maxWidth;
1032 if (d->mDrawSeparators)
1033 {
1034 // Create a separator since the user asked
1035 sep = new CardViewSeparator(this);
1036 sep->mRect.moveTopLeft(QPoint(xPos, yPos+d->mItemMargin));
1037 xPos += d->mSepWidth + cardSpacing;
1038 d->mSeparatorList.append(sep);
1039 }
1040
1041 maxWidth = 0;
1042 }
1043
1044 item->d->x = xPos;
1045 item->d->y = yPos;
1046
1047 yPos += item->height();
1048 maxWidth = QMAX(maxWidth, d->mItemWidth);
1049 }
1050
1051 xPos += maxWidth;
1052 resizeContents( xPos + cardSpacing, maxHeight );
1053
1054 // Update the height of all the separators now that we know the
1055 // max height of a column
1056 QPtrListIterator<CardViewSeparator> sepIter(d->mSeparatorList);
1057 for (sepIter.toFirst(); sepIter.current(); ++sepIter)
1058 {
1059 (*sepIter)->mRect.setHeight(maxHeight - 2*cardSpacing - 2*d->mItemMargin);
1060 }
1061
1062 d->mLayoutDirty = false;
1063}
1064
1065CardViewItem *CardView::itemAfter(CardViewItem *item)
1066{
1067 /*int pos = */d->mItemList.findRef(item);
1068 return d->mItemList.next();//at(pos+1);
1069}
1070
1071uint CardView::itemMargin()
1072{
1073 return d->mItemMargin;
1074}
1075
1076void CardView::setItemMargin( uint margin )
1077{
1078 if ( margin == d->mItemMargin )
1079 return;
1080
1081 d->mItemMargin = margin;
1082 setLayoutDirty( true );
1083}
1084
1085uint CardView::itemSpacing()
1086{
1087 return d->mItemSpacing;
1088}
1089
1090void CardView::setItemSpacing( uint spacing )
1091{
1092 if ( spacing == d->mItemSpacing )
1093 return;
1094
1095 d->mItemSpacing = spacing;
1096 setLayoutDirty( true );
1097}
1098
1099void CardView::contentsMousePressEvent(QMouseEvent *e)
1100{
1101 QScrollView::contentsMousePressEvent(e);
1102
1103 QPoint pos = e->pos();
1104 d->mLastClickPos = pos;
1105
1106 CardViewItem *item = itemAt(pos);
1107
1108 if (item == 0)
1109 {
1110 d->mLastClickOnItem = false;
1111 if ( d->mOnSeparator)
1112 {
1113 d->mResizeAnchor = e->x()+contentsX();
1114 d->colspace = (2*d->mItemSpacing) /*+ (2*d->mItemMargin)*/;
1115 int ccw = d->mItemWidth + d->colspace + d->mSepWidth;
1116 d->first = (contentsX()+d->mSepWidth)/ccw;
1117 d->pressed = (d->mResizeAnchor+d->mSepWidth)/ccw;
1118 d->span = d->pressed - d->first;
1119 d->firstX = d->first * ccw;
1120 if ( d->firstX ) d->firstX -= d->mSepWidth; // (no sep in col 0)
1121 }
1122 else
1123 {
1124 selectAll(false);
1125 }
1126 return;
1127 }
1128
1129 d->mLastClickOnItem = true;
1130
1131 CardViewItem *other = d->mCurrentItem;
1132 setCurrentItem( item );
1133
1134 // Always emit the selection
1135 emit clicked(item);
1136
1137 // Check the selection type and update accordingly
1138 if (d->mSelectionMode == CardView::Single)
1139 {
1140 // make sure it isn't already selected
1141 if (item->isSelected())
1142 return;
1143
1144 bool b = signalsBlocked();
1145 blockSignals(true);
1146 selectAll(false);
1147 blockSignals(b);
1148
1149 item->setSelected(true);
1150 item->repaintCard();
1151 emit selectionChanged(item);
1152 }
1153
1154 else if (d->mSelectionMode == CardView::Multi)
1155 {
1156 // toggle the selection
1157 item->setSelected(!item->isSelected());
1158 item->repaintCard();
1159 emit selectionChanged();
1160 }
1161
1162 else if (d->mSelectionMode == CardView::Extended)
1163 {
1164 if ((e->button() & Qt::LeftButton) &&
1165 (e->state() & Qt::ShiftButton))
1166 {
1167 if ( item == other ) return;
1168
1169 bool s = ! item->isSelected();
1170
1171 if ( s && ! (e->state() & ControlButton) )
1172 {
1173 bool b = signalsBlocked();
1174 blockSignals(true);
1175 selectAll(false);
1176 blockSignals(b);
1177 }
1178
1179 int from, to, a, b;
1180 a = d->mItemList.findRef( item );
1181 b = d->mItemList.findRef( other );
1182 from = a < b ? a : b;
1183 to = a > b ? a : b;
1184 //kdDebug()<<"selecting items "<<from<<" - "<<to<<" ( "<<s<<" )"<<endl;
1185 CardViewItem *aItem;
1186 for ( ; from <= to; from++ )
1187 {
1188 aItem = d->mItemList.at( from );
1189 aItem->setSelected( s );
1190 repaintItem( aItem );
1191 }
1192 emit selectionChanged();
1193 }
1194 else if ((e->button() & Qt::LeftButton) &&
1195 (e->state() & Qt::ControlButton))
1196 {
1197 item->setSelected(!item->isSelected());
1198 item->repaintCard();
1199 emit selectionChanged();
1200 }
1201
1202 else if (e->button() & Qt::LeftButton)
1203 {
1204 bool b = signalsBlocked();
1205 blockSignals(true);
1206 selectAll(false);
1207 blockSignals(b);
1208
1209 item->setSelected(true);
1210 item->repaintCard();
1211 emit selectionChanged();
1212 }
1213 }
1214
1215}
1216
1217void CardView::contentsMouseReleaseEvent(QMouseEvent *e)
1218{
1219 QScrollView::contentsMouseReleaseEvent(e);
1220
1221 if ( d->mResizeAnchor )
1222 {
1223 // finish the resizing:
1224 unsetCursor();
1225 // hide rubber bands
1226 int newiw = d->mItemWidth - ((d->mResizeAnchor - d->mRubberBandAnchor)/d->span);
1227 drawRubberBands( 0 );
1228 // we should move to reflect the new position if we are scrolled.
1229 if ( contentsX() )
1230 {
1231 int newX = QMAX( 0, ( d->pressed * ( newiw + d->colspace + d->mSepWidth ) ) - e->x() );
1232 setContentsPos( newX, contentsY() );
1233 }
1234 // set new item width
1235 setItemWidth( newiw );
1236 // reset anchors
1237 d->mResizeAnchor = 0;
1238 d->mRubberBandAnchor = 0;
1239 return;
1240 }
1241
1242 // If there are accel keys, we will not emit signals
1243 if ((e->state() & Qt::ShiftButton) || (e->state() & Qt::ControlButton))
1244 return;
1245
1246 // Get the item at this position
1247 CardViewItem *item = itemAt(e->pos());
1248
1249 if (item && KGlobalSettings::singleClick())
1250 {
1251 emit executed(item);
1252 }
1253}
1254
1255void CardView::contentsMouseDoubleClickEvent(QMouseEvent *e)
1256{
1257 QScrollView::contentsMouseDoubleClickEvent(e);
1258
1259 CardViewItem *item = itemAt(e->pos());
1260
1261 if (item)
1262 {
1263 d->mCurrentItem = item;
1264 }
1265
1266 if (item && !KGlobalSettings::singleClick())
1267 {
1268 emit executed(item);
1269 }
1270 emit doubleClicked(item);
1271}
1272
1273void CardView::contentsMouseMoveEvent( QMouseEvent *e )
1274{
1275 // resizing
1276 if ( d->mResizeAnchor )
1277 {
1278 int x = e->x();
1279 if ( x != d->mRubberBandAnchor )
1280 drawRubberBands( x );
1281 return;
1282 }
1283
1284 if (d->mLastClickOnItem && (e->state() & Qt::LeftButton) &&
1285 ((e->pos() - d->mLastClickPos).manhattanLength() > 4)) {
1286
1287 startDrag();
1288 return;
1289 }
1290
1291 d->mTimer->start( 500 );
1292
1293 // see if we are over a separator
1294 // only if we actually have them painted?
1295 if ( d->mDrawSeparators )
1296 {
1297 int colcontentw = d->mItemWidth + (2*d->mItemSpacing);
1298 int colw = colcontentw + d->mSepWidth;
1299 int m = e->x()%colw;
1300 if ( m >= colcontentw && m > 0 )
1301 {
1302 setCursor( SplitVCursor ); // Why does this fail sometimes?
1303 d->mOnSeparator = true;
1304 }
1305 else
1306 {
1307 setCursor( ArrowCursor );
1308 d->mOnSeparator = false;
1309 }
1310 }
1311}
1312
1313void CardView::enterEvent( QEvent * )
1314{
1315 d->mTimer->start( 500 );
1316}
1317
1318void CardView::leaveEvent( QEvent * )
1319{
1320 d->mTimer->stop();
1321 if (d->mOnSeparator)
1322 {
1323 d->mOnSeparator = false;
1324 setCursor( ArrowCursor );
1325 }
1326}
1327
1328void CardView::focusInEvent( QFocusEvent * )
1329{
1330 if (!d->mCurrentItem && d->mItemList.count() )
1331 {
1332 setCurrentItem( d->mItemList.first() );
1333 }
1334 else if ( d->mCurrentItem )
1335 {
1336 d->mCurrentItem->repaintCard();
1337 }
1338}
1339
1340void CardView::focusOutEvent( QFocusEvent * )
1341{
1342 if (d->mCurrentItem)
1343 d->mCurrentItem->repaintCard();
1344}
1345
1346void CardView::keyPressEvent( QKeyEvent *e )
1347{
1348 if ( ! ( childCount() && d->mCurrentItem ) )
1349 {
1350 e->ignore();
1351 return;
1352 }
1353
1354 uint pos = d->mItemList.findRef( d->mCurrentItem );
1355 CardViewItem *aItem = 0L; // item that gets the focus
1356 CardViewItem *old = d->mCurrentItem;
1357
1358 switch ( e->key() )
1359 {
1360 case Key_Up:
1361 if ( pos > 0 )
1362 {
1363 aItem = d->mItemList.at( pos - 1 );
1364 setCurrentItem( aItem );
1365 }
1366 break;
1367 case Key_Down:
1368 if ( pos < d->mItemList.count() - 1 )
1369 {
1370 aItem = d->mItemList.at( pos + 1 );
1371 setCurrentItem( aItem );
1372 }
1373 break;
1374 case Key_Left:
1375 {
1376 // look for an item in the previous/next column, starting from
1377 // the vertical middle of the current item.
1378 // FIXME use nice calculatd measures!!!
1379 QPoint aPoint( d->mCurrentItem->d->x, d->mCurrentItem->d->y );
1380 aPoint -= QPoint( 30,-(d->mCurrentItem->height()/2) );
1381 aItem = itemAt( aPoint );
1382 // maybe we hit some space below an item
1383 while ( !aItem && aPoint.y() > 27 )
1384 {
1385 aPoint -= QPoint( 0, 16 );
1386 aItem = itemAt( aPoint );
1387 }
1388 if ( aItem )
1389 setCurrentItem( aItem );
1390 }
1391 break;
1392 case Key_Right:
1393 {
1394 // FIXME use nice calculated measures!!!
1395 QPoint aPoint( d->mCurrentItem->d->x + d->mItemWidth, d->mCurrentItem->d->y );
1396 aPoint += QPoint( 30,(d->mCurrentItem->height()/2) );
1397 aItem = itemAt( aPoint );
1398 while ( !aItem && aPoint.y() > 27 )
1399 {
1400 aPoint -= QPoint( 0, 16 );
1401 aItem = itemAt( aPoint );
1402 }
1403 if ( aItem )
1404 setCurrentItem( aItem );
1405 }
1406 break;
1407 case Key_Home:
1408 aItem = d->mItemList.first();
1409 setCurrentItem( aItem );
1410 break;
1411 case Key_End:
1412 aItem = d->mItemList.last();
1413 setCurrentItem( aItem );
1414 break;
1415 case Key_Prior: // PageUp
1416 {
1417 // QListView: "Make the item above the top visible and current"
1418 // TODO if contentsY(), pick the top item of the leftmost visible column
1419 if ( contentsX() <= 0 )
1420 return;
1421 int cw = columnWidth();
1422 int theCol = ( QMAX( 0, ( contentsX()/cw) * cw ) ) + d->mItemSpacing;
1423 aItem = itemAt( QPoint( theCol + 1, d->mItemSpacing + 1 ) );
1424 if ( aItem )
1425 setCurrentItem( aItem );
1426 }
1427 break;
1428 case Key_Next: // PageDown
1429 {
1430 // QListView: "Make the item below the bottom visible and current"
1431 // find the first not fully visible column.
1432 // TODO: consider if a partly visible (or even hidden) item at the
1433 // bottom of the rightmost column exists
1434 int cw = columnWidth();
1435 int theCol = ( (( contentsX() + visibleWidth() )/cw) * cw ) + d->mItemSpacing + 1;
1436 // if separators are on, we may need to we may be one column further right if only the spacing/sep is hidden
1437 if ( d->mDrawSeparators && cw - (( contentsX() + visibleWidth() )%cw) <= int( d->mItemSpacing + d->mSepWidth ) )
1438 theCol += cw;
1439
1440 // make sure this is not too far right
1441 while ( theCol > contentsWidth() )
1442 theCol -= columnWidth();
1443
1444 aItem = itemAt( QPoint( theCol, d->mItemSpacing + 1 ) );
1445
1446 if ( aItem )
1447 setCurrentItem( aItem );
1448 }
1449 break;
1450 case Key_Space:
1451 setSelected( d->mCurrentItem, !d->mCurrentItem->isSelected() );
1452 emit selectionChanged();
1453 break;
1454 case Key_Return:
1455 case Key_Enter:
1456 emit returnPressed( d->mCurrentItem );
1457 emit executed( d->mCurrentItem );
1458 break;
1459 default:
1460 if ( (e->state() & ControlButton) && e->key() == Key_A )
1461 {
1462 // select all
1463 selectAll( true );
1464 break;
1465 }
1466 // if we have a string, do autosearch
1467 else if ( ! e->text().isEmpty() && e->text()[0].isPrint() )
1468 {
1469
1470 }
1471 break;
1472 }
1473 // handle selection
1474 if ( aItem )
1475 {
1476 if ( d->mSelectionMode == CardView::Extended )
1477 {
1478 if ( (e->state() & ShiftButton) )
1479 {
1480 // shift button: toggle range
1481 // if control button is pressed, leave all items
1482 // and toggle selection current->old current
1483 // otherwise, ??????
1484 bool s = ! aItem->isSelected();
1485 int from, to, a, b;
1486 a = d->mItemList.findRef( aItem );
1487 b = d->mItemList.findRef( old );
1488 from = a < b ? a : b;
1489 to = a > b ? a : b;
1490
1491 if ( to - from > 1 )
1492 {
1493 bool b = signalsBlocked();
1494 blockSignals(true);
1495 selectAll(false);
1496 blockSignals(b);
1497 }
1498
1499 //kdDebug()<<"selecting items "<<from<<" - "<<to<<" ( "<<s<<" )"<<endl;
1500 CardViewItem *item;
1501 for ( ; from <= to; from++ )
1502 {
1503 item = d->mItemList.at( from );
1504 item->setSelected( s );
1505 repaintItem( item );
1506 }
1507 emit selectionChanged();
1508 }
1509 else if ( (e->state() & ControlButton) )
1510 {
1511 // control button: do nothing
1512 }
1513 else
1514 {
1515 // no button: move selection to this item
1516 bool b = signalsBlocked();
1517 blockSignals(true);
1518 selectAll(false);
1519 blockSignals(b);
1520
1521 setSelected( aItem, true );
1522 emit selectionChanged();
1523 }
1524 }
1525 }
1526}
1527
1528void CardView::contentsWheelEvent( QWheelEvent * e )
1529{
1530 scrollBy(2*e->delta()/-3, 0);
1531}
1532
1533void CardView::setLayoutDirty(bool dirty)
1534{
1535 if (d->mLayoutDirty != dirty)
1536 {
1537 d->mLayoutDirty = dirty;
1538 repaint();
1539 }
1540}
1541
1542void CardView::setDrawCardBorder(bool enabled)
1543{
1544 if (enabled != d->mDrawCardBorder)
1545 {
1546 d->mDrawCardBorder = enabled;
1547 repaint();
1548 }
1549}
1550
1551bool CardView::drawCardBorder() const
1552{
1553 return d->mDrawCardBorder;
1554}
1555
1556void CardView::setDrawColSeparators(bool enabled)
1557{
1558 if (enabled != d->mDrawSeparators)
1559 {
1560 d->mDrawSeparators = enabled;
1561 setLayoutDirty(true);
1562 }
1563}
1564
1565bool CardView::drawColSeparators() const
1566{
1567 return d->mDrawSeparators;
1568}
1569
1570void CardView::setDrawFieldLabels(bool enabled)
1571{
1572 if (enabled != d->mDrawFieldLabels)
1573 {
1574 d->mDrawFieldLabels = enabled;
1575 repaint();
1576 }
1577}
1578
1579bool CardView::drawFieldLabels() const
1580{
1581 return d->mDrawFieldLabels;
1582}
1583
1584void CardView::setShowEmptyFields(bool show)
1585{
1586 if (show != d->mShowEmptyFields)
1587 {
1588 d->mShowEmptyFields = show;
1589 setLayoutDirty(true);
1590 }
1591}
1592
1593bool CardView::showEmptyFields() const
1594{
1595 return d->mShowEmptyFields;
1596}
1597
1598void CardView::startDrag()
1599{
1600 // The default implementation is a no-op. It must be
1601 // reimplemented in a subclass to be useful
1602}
1603void CardView::tryShowFullText()
1604{
1605 d->mTimer->stop();
1606 // if we have an item
1607 QPoint cpos = viewportToContents( viewport()->mapFromGlobal( QCursor::pos() ) );
1608 CardViewItem *item = itemAt( cpos );
1609 if ( item )
1610 {
1611 // query it for a value to display
1612 //QString s = item ? item->caption() : "(no item)";
1613 //kdDebug()<<"MOUSE REST: "<<s<<endl;
1614 QPoint ipos = cpos - itemRect( item ).topLeft();
1615 item->showFullString( ipos, d->mTip );
1616 }
1617}
1618
1619void CardView::drawRubberBands( int pos )
1620{
1621 if ( pos && ((pos-d->firstX)/d->span) - d->colspace - d->mSepWidth < MIN_ITEM_WIDTH ) return;
1622
1623 int tmpcw = (d->mRubberBandAnchor-d->firstX)/d->span;
1624 int x = d->firstX + tmpcw - d->mSepWidth - contentsX();
1625 int h = visibleHeight();
1626
1627 QPainter p( viewport() );
1628 p.setRasterOp( XorROP );
1629 p.setPen( gray );
1630 p.setBrush( gray );
1631 uint n = d->first;
1632 // erase
1633 if ( d->mRubberBandAnchor )
1634 do {
1635 p.drawRect( x, 0, 2, h );
1636 x += tmpcw;
1637 n++;
1638 } while ( x < visibleWidth() && n < d->mSeparatorList.count() );
1639 // paint new
1640 if ( ! pos ) return;
1641 tmpcw = (pos - d->firstX)/d->span;
1642 n = d->first;
1643 x = d->firstX + tmpcw - d->mSepWidth - contentsX();
1644 do {
1645 p.drawRect( x, 0, 2, h );
1646 x += tmpcw;
1647 n++;
1648 } while ( x < visibleWidth() && n < d->mSeparatorList.count() );
1649 d->mRubberBandAnchor = pos;
1650}
1651
1652
1653int CardView::itemWidth() const
1654{
1655 return d->mItemWidth;
1656}
1657
1658void CardView::setItemWidth( int w )
1659{
1660 if ( w == d->mItemWidth )
1661 return;
1662 if ( w < MIN_ITEM_WIDTH )
1663 w = MIN_ITEM_WIDTH;
1664 d->mItemWidth = w;
1665 setLayoutDirty( true );
1666#ifndef KAB_EMBEDDED
1667 updateContents();
1668#else //KAB_EMBEDDED
1669//US updateContents( d->contentsX(), d->contentsY(), visibleWidth(), visibleHeight() );
1670qDebug("CardView::setItemWidth has to be verified");
1671 updateContents( contentsX(), contentsY(), visibleWidth(), visibleHeight() );
1672#endif //KAB_EMBEDDED
1673}
1674
1675void CardView::setHeaderFont( const QFont &fnt )
1676{
1677 d->mHeaderFont = fnt;
1678 delete d->mBFm;
1679 d->mBFm = new QFontMetrics( fnt );
1680}
1681
1682QFont CardView::headerFont() const
1683{
1684 return d->mHeaderFont;
1685}
1686
1687void CardView::setFont( const QFont &fnt )
1688{
1689 QScrollView::setFont( fnt );
1690 delete d->mFm;
1691 d->mFm = new QFontMetrics( fnt );
1692}
1693
1694int CardView::separatorWidth()
1695{
1696 return d->mSepWidth;
1697}
1698
1699void CardView::setSeparatorWidth( int width )
1700{
1701 d->mSepWidth = width;
1702 setLayoutDirty( true ); // hmm, actually I could just adjust the x'es...
1703}
1704
1705int CardView::maxFieldLines() const
1706{
1707 return d->mMaxFieldLines;
1708}
1709
1710void CardView::setMaxFieldLines( int howmany )
1711{
1712 d->mMaxFieldLines = howmany ? howmany : INT_MAX;
1713 // FIXME update, forcing the items to recalc height!!
1714}
1715//END Cardview
1716
1717#ifndef KAB_EMBEDDED
1718#include "cardview.moc"
1719#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/cardview.desktop b/kaddressbook/views/cardview.desktop
new file mode 100644
index 0000000..8507360
--- a/dev/null
+++ b/kaddressbook/views/cardview.desktop
@@ -0,0 +1,18 @@
1[Desktop Entry]
2Encoding=UTF-8
3X-KDE-Library=libkaddrbk_cardview
4Name=Card View
5Name[be]=У выглядзе картак
6Name[ca]=Vista de targeta
7Name[da]=Kort-visning
8Name[el]=Προβολή καρτών
9Name[es]=Vista de tarjeta
10Name[hu]=Kártyanézet
11Name[pt_BR]=Visualização de Cartão
12Name[ru]=Карточка
13Name[sk]=Prezeranie karty
14Name[sv]=Kortvy
15Name[tr]=Kart Görünümü
16Name[zh_CN]=卡片视图
17Type=Service
18ServiceTypes=KAddressBook/View
diff --git a/kaddressbook/views/cardview.h b/kaddressbook/views/cardview.h
new file mode 100644
index 0000000..37dddb6
--- a/dev/null
+++ b/kaddressbook/views/cardview.h
@@ -0,0 +1,473 @@
1#ifndef CARDVIEW_H
2#define CARDVIEW_H
3
4#include <qscrollview.h>
5#include <qptrlist.h>
6#include <qstring.h>
7#include <qrect.h>
8#include <qpair.h>
9#include <qpoint.h>
10
11class QLabel;
12class QPainter;
13class QResizeEvent;
14class QMouseEvent;
15class CardView;
16class CardViewPrivate;
17class CardViewItemPrivate;
18class CardViewTip;
19
20/** Represents a single card (item) in the card view. A card has a caption
21* and a list of fields. A Field is a label<->value pair. The labels in a
22* card should be unique, since they will be used to index the values.
23*/
24class CardViewItem
25{
26 friend class CardView;
27
28 public:
29 /** A single field in the card view. The first item is the label
30 * and the second item is the value.
31 */
32 typedef QPair<QString, QString> Field;
33
34 /** Constructor.
35 *
36 * @param parent The CardView that this card should be displayed on.
37 * @param caption The caption of the card. This is the text that will
38 * appear at the top of the card. This is also the string that will
39 * be used to sort the cards in the view.
40 */
41 CardViewItem(CardView *parent, QString caption = QString::null);
42 virtual ~CardViewItem();
43
44 /** @return The caption of the card, or QString::null if none was ever
45 * set.
46 */
47 const QString &caption() const;
48
49 /** Sets the caption of the card. This is the text that will
50 * appear at the top of the card. This is also the string that will
51 * be used to sort the cards in the view.
52 */
53 void setCaption(const QString &caption);
54
55 /** Paints the card using the given painter and color group. The
56 * card will handle painting itself selected if it is selected.
57 */
58 virtual void paintCard(QPainter *p, QColorGroup &cg);
59
60 /** Repaints the card. This is done by sending a repaint event to the
61 * view with the clip rect defined as this card.
62 */
63 virtual void repaintCard();
64
65 /** Adds a field to the card.
66 *
67 * @param label The label of the field. The field labels must be unique
68 * within a card.
69 * @param The value of the field.
70 */
71 void insertField(const QString &label, const QString &value);
72
73 /** Removes the field with label <i>label</i> from the card.
74 */
75 void removeField(const QString &label);
76
77 /** @return The value of the field with label <i>label</i>.
78 */
79 QString fieldValue(const QString &label);
80
81 /** Removes all the fields from this card.
82 */
83 void clearFields();
84
85 /** @return The next card item. The order of the items will be the same
86 * as the display order in the view. 0 will be returned if this is the
87 * last card.
88 */
89 CardViewItem *nextItem();
90
91 /** @return True if this card is currently selected, false otherwise.
92 */
93 bool isSelected() const;
94
95 /** Called by the parent card view when the mouse has been resting for
96 * a certain amount of time. If the label or value at pos is obscured
97 * (trimmed) make the label display the full text.
98 */
99 void showFullString( const QPoint &pos, CardViewTip *tip );
100
101 /** @return a pointer to the Field at the position itempos
102 * in this item. 0 is returned if itempos is in the caption.
103 * @param itempos the position in item coordinates
104 */
105 Field *fieldAt( const QPoint &itempos ) const;
106
107 CardView *cardView() { return mView; };
108
109 /** @return The height of this item as rendered, in pixels.
110
111 if @p allowCache is true, the item may use an internally
112 cached value rather than recalculating from scratch. The
113 argument is mainly to allow the cardView to change global settings (like
114 maxFieldLines) that might influence the items heights
115 */
116 int height( bool allowCache=true ) const;
117
118 protected:
119 /** Sets the card as selected. This is usually only called from the
120 * card view.
121 */
122 void setSelected(bool selected);
123
124 private:
125 /** Sets the default values.
126 */
127 void initialize();
128
129 /** Trims a string to the width <i>width</i> using the font metrics
130 * to determine the width of each char. If the string is longer than
131 * <i>width</i>, then the string will be trimmed and a '...' will
132 * be appended.
133 */
134 QString trimString(const QString &text, int width, QFontMetrics &fm);
135
136 CardViewItemPrivate *d;
137 CardView *mView;
138};
139
140/** The CardView is a method of displaying data in cards. This idea is
141* similar to the idea of a rolodex or business cards. Each card has a
142* caption and a list of fields, which are label<->value pairs. The CardView
143* displays multiple cards in a grid. The Cards are sorted based on their
144* caption.
145*
146* The CardView class is designed to mirror the API of the QListView or
147* QIconView. The CardView is also completely independant of KAddressBook and
148* can be used elsewhere. With the exception of a few simple config checks,
149* the CardView is also 100% independant of KDE.
150*/
151class CardView : public QScrollView
152{
153 friend class CardViewItem;
154
155 Q_OBJECT
156
157 public:
158 /** Constructor.
159 */
160 CardView(QWidget *parent, const char *name);
161 virtual ~CardView();
162
163 /** Inserts the item into the card view. This method does not have
164 * to be called if you created the item with a proper parent. Once
165 * inserted, the CardView takes ownership of the item.
166 */
167 void insertItem(CardViewItem *item);
168
169 /** Takes the item from the view. The item will not be deleted and
170 * ownership of the item is returned to the caller.
171 */
172 void takeItem(CardViewItem *item);
173
174 /** Clears the view and deletes all card view items
175 */
176 void clear();
177
178 /** @return The current item, the item that has the focus.
179 * Whenever the view has focus, this item has a focus rectangle painted
180 * at it's border.
181 * @sa setCurrentItem()
182 */
183 CardViewItem *currentItem();
184
185 /** Sets the CardViewItem @p item to the current item in the view.
186 */
187 void setCurrentItem( CardViewItem *item );
188
189 /** @return The item found at the given point, or 0 if there is no item
190 * at that point.
191 */
192 CardViewItem *itemAt(const QPoint &viewPos);
193
194 /** @return The bounding rect of the given item.
195 */
196 QRect itemRect(const CardViewItem *item);
197
198 /** Ensures that the given item is in the viewable area of the widget
199 */
200 void ensureItemVisible(const CardViewItem *item);
201
202 /** Repaints the given item.
203 */
204 void repaintItem(const CardViewItem *item);
205
206 enum SelectionMode { Single, Multi, Extended, NoSelection };
207
208 /** Sets the selection mode.
209 *
210 * @see QListView
211 */
212 void setSelectionMode(SelectionMode mode);
213
214 /** @return The current selection mode.
215 */
216 SelectionMode selectionMode() const;
217
218 /** Selects or deselects the given item. This method honors the current
219 * selection mode, so if other items are selected, they may be unselected.
220 */
221 void setSelected(CardViewItem *item, bool selected);
222
223 /** Selects or deselects all items.
224 */
225 void selectAll(bool state);
226
227 /** @return True if the given item is selected, false otherwise.
228 */
229 bool isSelected(CardViewItem *item) const;
230
231 /** @return The first selected item. In single select mode, this will be
232 * the only selected item, in other modes this will be the first selected
233 * item, but others may exist. 0 if no item is selected.
234 */
235 CardViewItem *selectedItem() const;
236
237 /** @return The first item in the view. This may be 0 if no items have
238 * been inserted. This method combined with CardViewItem::nextItem()
239 * can be used to iterator through the list of items.
240 */
241 CardViewItem *firstItem() const;
242
243 /** @return The item after the given item or 0 if the item is the last
244 * item.
245 */
246 CardViewItem *itemAfter(CardViewItem *item);
247
248 /** @return The number of items in the view.
249 */
250 int childCount() const;
251
252 /** Attempts to find the first item matching the params.
253 *
254 * @param text The text to match.
255 * @param label The label of the field to match against.
256 * @param compare The compare method to use in doing the search.
257 *
258 * @return The first matching item, or 0 if no items match.
259 */
260/*US
261 CardViewItem *findItem(const QString &text, const QString &label,
262 Qt::StringComparisonMode compare = Qt::BeginsWith);
263*/
264
265 /** Returns the amounts of pixels required for one column.
266 * This depends on wheather drawSeparators is enabled:
267 * If so, it is itemWidth + 2*itemSpacing + separatorWidth
268 * If not, it is itemWidth + itemSpacing
269 * @see itemWidth(), setItemWidth(), itemSpacing() and setItemSpacing()
270 */
271 uint columnWidth();
272
273 /** Sets if the border around a card should be draw. The border is a thing
274 * (1 or 2 pixel) line that bounds the card. When drawn, it shows when
275 * a card is highlighted and when it isn't.
276 */
277 void setDrawCardBorder(bool enabled);
278
279 /** @return True if borders are drawn, false otherwise.
280 */
281 bool drawCardBorder() const;
282
283 /** Sets if the column separator should be drawn. The column separator
284 * is a thin verticle line (1 or 2 pixels) that is used to separate the
285 * columns in the list view. The separator is just for esthetics and it
286 * does not serve a functional purpose.
287 */
288 void setDrawColSeparators(bool enabled);
289
290 /** @return True if column separators are drawn, false otherwise.
291 */
292 bool drawColSeparators() const;
293
294 /** Sets if the field labels should be drawn. The field labels are the
295 * unique strings used to identify the fields. Sometimes drawing these
296 * labels makes sense as a source of clarity for the user, othertimes they
297 * waste too much space and do not assist the user.
298 */
299 void setDrawFieldLabels(bool enabled);
300
301 /** @return True if the field labels are drawn, false otherwise.
302 */
303 bool drawFieldLabels() const;
304
305 /** Sets if fields with no value should be drawn (of cause the label only,
306 * but it allows for embedded editing sometimes...)
307 */
308 void setShowEmptyFields(bool show);
309
310 /** @return Wheather empty fields should be shown
311 */
312 bool showEmptyFields() const;
313
314 /** @return the advisory internal margin in items. Setting a value above 1 means
315 * a space between the item contents and the focus recttangle drawn around
316 * the current item. The default value is 0.
317 * The value should be used by CardViewItem and derived classes.
318 * Note that this should not be greater than half of the minimal item width,
319 * which is 80. It is currently not checked, so setting a value greater than 40
320 * will probably mean a crash in the items painting routine.
321 * @private Note: I looked for a value in QStyle::PixelMetric to use, but I could
322 * not see a usefull one. One may turn up in a future version of Qt.
323 */
324 uint itemMargin();
325
326 /** Sets the internal item margin. @see itemMargin().
327 */
328 void setItemMargin( uint margin );
329
330 /** @return the item spacing.
331 * The item spacing is the space (in pixels) between each item in a
332 * column, between the items and column separators if drawn, and between
333 * the items and the borders of the widget. The default value is set to
334 * 10.
335 * @private Note: There is no usefull QStyle::PixelMetric to use for this atm.
336 * An option would be using KDialog::spacingHint().
337 */
338 uint itemSpacing();
339
340 /** Sets the item spacing.
341 * @see itemSpacing()
342 */
343 void setItemSpacing( uint spacing );
344
345 /** @return the width made available to the card items. */
346 int itemWidth() const;
347
348 /** Sets the width made available to card items. */
349 void setItemWidth( int width );
350
351 /** Sets the header font */
352 void setHeaderFont( const QFont &fnt );
353
354 /** @return the header font */
355 QFont headerFont() const;
356
357 /** @reimp */
358 void setFont( const QFont &fnt );
359
360 /** Sets the column separator width */
361 void setSeparatorWidth( int width );
362
363 /** @return the column separator width */
364 int separatorWidth();
365
366 /** Sets the maximum number of lines to display pr field.
367 If set to 0 (the default) all lines will be displayed.
368 */
369 void setMaxFieldLines( int howmany );
370
371 /** @return the maximum number of lines pr field */
372 int maxFieldLines() const;
373
374 signals:
375 /** Emitted whenever the selection changes. This means a user highlighted
376 * a new item or unhighlighted a currently selected item.
377 */
378 void selectionChanged();
379
380 /** Same as above method, only it carries the item that was selected. This
381 * method will only be emitted in single select mode, since it defineds
382 * which item was selected.
383 */
384 void selectionChanged(CardViewItem *);
385
386 /** This method is emitted whenever an item is clicked.
387 */
388 void clicked(CardViewItem *);
389
390 /** Emitted whenever the user 'executes' an item. This is dependant on
391 * the KDE global config. This could be a single click or a doubleclick.
392 * Also emitted when the return key is pressed on an item.
393 */
394 void executed(CardViewItem *);
395
396 /** Emitted whenever the user double clicks on an item.
397 */
398 void doubleClicked(CardViewItem *);
399
400 /** Emitted when the current item changes
401 */
402 void currentChanged( CardViewItem * );
403
404 /** Emitted when the return key is pressed in an item.
405 */
406 void returnPressed( CardViewItem * );
407
408 protected:
409 /** Determines which cards intersect that region and tells them to paint
410 * themselves.
411 */
412 void drawContents(QPainter *p, int clipx, int clipy, int clipw, int cliph);
413
414 /** Sets the layout to dirty and repaints.
415 */
416 void resizeEvent(QResizeEvent *e);
417
418 /** Changes the direction the canvas scolls.
419 */
420 void contentsWheelEvent(QWheelEvent *e);
421
422 /** Sets the layout to dirty and calls for a repaint.
423 */
424 void setLayoutDirty(bool dirty);
425
426 /** Does the math based on the bounding rect of the cards to properly
427 * lay the cards out on the screen. This is only done if the layout is
428 * marked as dirty.
429 */
430 void calcLayout();
431
432// virtual void mousePressEvent(QMouseEvent *e);
433// virtual void mouseReleaseEvent(QMouseEvent *e);
434// virtual void mouseMoveEvent(QMouseEvent *e);
435
436 virtual void contentsMousePressEvent(QMouseEvent *e);
437 virtual void contentsMouseMoveEvent(QMouseEvent *e);
438 virtual void contentsMouseReleaseEvent(QMouseEvent *e);
439 virtual void contentsMouseDoubleClickEvent(QMouseEvent *e);
440
441 virtual void enterEvent( QEvent * );
442 virtual void leaveEvent( QEvent * );
443
444 virtual void focusInEvent( QFocusEvent * );
445 virtual void focusOutEvent( QFocusEvent * );
446
447 virtual void keyPressEvent( QKeyEvent * );
448
449 /** Overload this method to be told when a drag should be started.
450 * In most cases you will want to start a drag event with the currently
451 * selected item.
452 */
453 virtual void startDrag();
454
455 private slots:
456 /** Called by a timer to display a label with truncated text.
457 * Pop up a label, if there is a field with obscured text or
458 * label at the cursor position.
459 */
460 void tryShowFullText();
461
462 private:
463 /** draws and erases the rubber bands while columns are resized.
464 * @p pos is the horizontal position inside the viewport to use as
465 * the anchor.
466 * If pos is 0, only erase is done.
467 */
468 void drawRubberBands( int pos );
469
470 CardViewPrivate *d;
471};
472
473#endif
diff --git a/kaddressbook/views/colorlistbox.cpp b/kaddressbook/views/colorlistbox.cpp
new file mode 100644
index 0000000..c243fa0
--- a/dev/null
+++ b/kaddressbook/views/colorlistbox.cpp
@@ -0,0 +1,230 @@
1/*
2 * kmail: KDE mail client
3 * This file: Copyright (C) 2000 Espen Sand, espen@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 */
20
21#include <qpainter.h>
22
23#include <kcolordialog.h>
24
25#ifndef KAB_EMBEDDED
26#include <kcolordrag.h>
27#endif //KAB_EMBEDDED
28
29#include "colorlistbox.h"
30
31ColorListBox::ColorListBox( QWidget *parent, const char *name, WFlags f )
32 :KListBox( parent, name, f ), mCurrentOnDragEnter(-1)
33{
34 connect( this, SIGNAL(selected(int)), this, SLOT(newColor(int)) );
35 setAcceptDrops( true);
36}
37
38
39void ColorListBox::setEnabled( bool state )
40{
41 if( state == isEnabled() )
42 {
43 return;
44 }
45
46 QListBox::setEnabled( state );
47 for( uint i=0; i<count(); i++ )
48 {
49 updateItem( i );
50 }
51}
52
53
54void ColorListBox::setColor( uint index, const QColor &color )
55{
56 if( index < count() )
57 {
58 ColorListItem *colorItem = (ColorListItem*)item(index);
59 colorItem->setColor(color);
60 updateItem( colorItem );
61 }
62}
63
64
65QColor ColorListBox::color( uint index ) const
66{
67 if( index < count() )
68 {
69 ColorListItem *colorItem = (ColorListItem*)item(index);
70 return( colorItem->color() );
71 }
72 else
73 {
74 return( black );
75 }
76}
77
78
79void ColorListBox::newColor( int index )
80{
81 if( isEnabled() == false )
82 {
83 return;
84 }
85
86 if( (uint)index < count() )
87 {
88 QColor c = color( index );
89#ifndef KAB_EMBEDDED
90 if( KColorDialog::getColor( c, this ) != QDialog::Rejected )
91 {
92 setColor( index, c );
93 }
94#else //KAB_EMBEDDED
95 KColorDialog* k = new KColorDialog( this );
96 k->setColor( c );
97 int res = k->exec();
98 if ( res ) {
99 setColor( index, k->getColor() );
100 }
101 delete k;
102#endif //KAB_EMBEDDED
103
104 }
105}
106
107
108void ColorListBox::dragEnterEvent( QDragEnterEvent *e )
109{
110#ifndef KAB_EMBEDDED
111 if( KColorDrag::canDecode(e) && isEnabled() )
112 {
113 mCurrentOnDragEnter = currentItem();
114 e->accept( true );
115 }
116 else
117 {
118 mCurrentOnDragEnter = -1;
119 e->accept( false );
120 }
121#else //KAB_EMBEDDED
122qDebug("ColorListBox::dragEnterEvent drag&drop currently not supported");
123#endif //KAB_EMBEDDED
124
125}
126
127
128void ColorListBox::dragLeaveEvent( QDragLeaveEvent * )
129{
130#ifndef KAB_EMBEDDED
131
132 if( mCurrentOnDragEnter != -1 )
133 {
134 setCurrentItem( mCurrentOnDragEnter );
135 mCurrentOnDragEnter = -1;
136 }
137#else //KAB_EMBEDDED
138qDebug("ColorListBox::dragLeaveEvent drag&drop currently not supported");
139#endif //KAB_EMBEDDED
140}
141
142
143void ColorListBox::dragMoveEvent( QDragMoveEvent *e )
144{
145#ifndef KAB_EMBEDDED
146 if( KColorDrag::canDecode(e) && isEnabled() )
147 {
148 ColorListItem *item = (ColorListItem*)itemAt( e->pos() );
149 if( item != 0 )
150 {
151 setCurrentItem ( item );
152 }
153 }
154#else //KAB_EMBEDDED
155qDebug("ColorListBox::dragMoveEvent drag&drop currently not supported");
156#endif //KAB_EMBEDDED
157
158}
159
160
161void ColorListBox::dropEvent( QDropEvent *e )
162{
163#ifndef KAB_EMBEDDED
164 QColor color;
165 if( KColorDrag::decode( e, color ) )
166 {
167 int index = currentItem();
168 if( index != -1 )
169 {
170 ColorListItem *colorItem = (ColorListItem*)item(index);
171 colorItem->setColor(color);
172 triggerUpdate( false ); // Redraw item
173 }
174 mCurrentOnDragEnter = -1;
175 }
176
177#else //KAB_EMBEDDED
178qDebug("ColorListBox::dropEvent drag&drop currently not supported");
179#endif //KAB_EMBEDDED
180
181}
182
183
184
185ColorListItem::ColorListItem( const QString &text, const QColor &color )
186 : QListBoxItem(), mColor( color ), mBoxWidth( 30 )
187{
188 setText( text );
189}
190
191
192const QColor &ColorListItem::color( void )
193{
194 return( mColor );
195}
196
197
198void ColorListItem::setColor( const QColor &color )
199{
200 mColor = color;
201}
202
203
204void ColorListItem::paint( QPainter *p )
205{
206 QFontMetrics fm = p->fontMetrics();
207 int h = fm.height();
208
209 p->drawText( mBoxWidth+3*2, fm.ascent() + fm.leading()/2, text() );
210
211 p->setPen( Qt::black );
212 p->drawRect( 3, 1, mBoxWidth, h-1 );
213 p->fillRect( 4, 2, mBoxWidth-2, h-3, mColor );
214}
215
216
217int ColorListItem::height(const QListBox *lb ) const
218{
219 return( lb->fontMetrics().lineSpacing()+1 );
220}
221
222
223int ColorListItem::width(const QListBox *lb ) const
224{
225 return( mBoxWidth + lb->fontMetrics().width( text() ) + 6 );
226}
227
228#ifndef KAB_EMBEDDED
229#include "colorlistbox.moc"
230#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/colorlistbox.h b/kaddressbook/views/colorlistbox.h
new file mode 100644
index 0000000..4a0e705
--- a/dev/null
+++ b/kaddressbook/views/colorlistbox.h
@@ -0,0 +1,76 @@
1/*
2 * kmail: KDE mail client
3 * This file: Copyright (C) 2000 Espen Sand, espen@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 */
20
21#ifndef _COLOR_LISTBOX_H_
22#define _COLOR_LISTBOX_H_
23
24#include <klistbox.h>
25
26class QDragEnterEvent;
27class QDragLeaveEvent;
28class QDragMoveEvent;
29class QDropEvent;
30
31class ColorListBox : public KListBox
32{
33 Q_OBJECT
34
35 public:
36 ColorListBox( QWidget *parent=0, const char * name=0, WFlags f=0 );
37 void setColor( uint index, const QColor &color );
38 QColor color( uint index ) const;
39
40 public slots:
41 virtual void setEnabled( bool state );
42
43 protected:
44 void dragEnterEvent( QDragEnterEvent *e );
45 void dragLeaveEvent( QDragLeaveEvent *e );
46 void dragMoveEvent( QDragMoveEvent *e );
47 void dropEvent( QDropEvent *e );
48
49 private slots:
50 void newColor( int index );
51
52 private:
53 int mCurrentOnDragEnter;
54
55};
56
57
58class ColorListItem : public QListBoxItem
59{
60 public:
61 ColorListItem( const QString &text, const QColor &color=Qt::black );
62 const QColor &color( void );
63 void setColor( const QColor &color );
64
65 protected:
66 virtual void paint( QPainter * );
67 virtual int height( const QListBox * ) const;
68 virtual int width( const QListBox * ) const;
69
70 private:
71 QColor mColor;
72 int mBoxWidth;
73};
74
75#endif
76
diff --git a/kaddressbook/views/configurecardviewdialog.cpp b/kaddressbook/views/configurecardviewdialog.cpp
new file mode 100644
index 0000000..d518cf7
--- a/dev/null
+++ b/kaddressbook/views/configurecardviewdialog.cpp
@@ -0,0 +1,364 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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 <qstring.h>
25#include <qlayout.h>
26#include <qlabel.h>
27#include <qcheckbox.h>
28#include <qvbox.h>
29#include <qgroupbox.h>
30#include <qspinbox.h>
31#include <qtabwidget.h>
32#include <qwhatsthis.h>
33
34#include <kdebug.h>
35#include <kglobal.h>
36#include <kglobalsettings.h>
37#include <klocale.h>
38#include <kiconloader.h>
39#include <kconfig.h>
40#include <kfontdialog.h>
41
42#ifndef KAB_EMBEDDED
43#include <kpushbutton.h>
44#else //KAB_EMBEDDED
45#include <qpushbutton.h>
46#endif //KAB_EMBEDDED
47
48#include "colorlistbox.h"
49
50#include "configurecardviewdialog.h"
51
52/////////////////////////////////
53// ConfigureCardViewDialog
54
55ConfigureCardViewWidget::ConfigureCardViewWidget( KABC::AddressBook *ab, QWidget *parent,
56 const char *name )
57 : ViewConfigureWidget( ab, parent, name )
58{
59#ifndef KAB_EMBEDDED
60 QWidget *page = addPage( i18n( "Look & Feel" ), QString::null,
61 DesktopIcon( "looknfeel" ) );
62#else //KAB_EMBEDDED
63 QWidget *page = addPage( i18n( "Look & Feel" ), QString::null,
64 KGlobal::iconLoader()->loadIcon( "looknfeel",
65 KIcon::Panel ) );
66#endif //KAB_EMBEDDED
67
68 mAdvancedPage = new CardViewLookNFeelPage( page );
69}
70
71ConfigureCardViewWidget::~ConfigureCardViewWidget()
72{
73}
74
75void ConfigureCardViewWidget::restoreSettings( KConfig *config )
76{
77 ViewConfigureWidget::restoreSettings( config );
78
79 mAdvancedPage->restoreSettings( config );
80}
81
82void ConfigureCardViewWidget::saveSettings( KConfig *config )
83{
84 ViewConfigureWidget::saveSettings( config );
85
86 mAdvancedPage->saveSettings( config );
87}
88
89////////////////////////
90// CardViewLookNFeelPage
91CardViewLookNFeelPage::CardViewLookNFeelPage( QWidget *parent, const char *name )
92 : QVBox( parent, name )
93{
94 initGUI();
95}
96
97CardViewLookNFeelPage::~CardViewLookNFeelPage()
98{
99}
100
101void CardViewLookNFeelPage::restoreSettings( KConfig *config )
102{
103 // colors
104 cbEnableCustomColors->setChecked( config->readBoolEntry( "EnableCustomColors", false ) );
105 QColor c;
106qDebug("CardViewLookNFeelPage::restoreSettings make base color configurable");
107
108#ifndef KAB_EMBEDDED
109 c = KGlobalSettings::baseColor();
110#else //KAB_EMBEDDED
111 c = QColor(0,0,0);
112#endif //KAB_EMBEDDED
113
114 lbColors->insertItem( new ColorListItem( i18n("Background Color"),
115 config->readColorEntry( "BackgroundColor", &c ) ) );
116 c = colorGroup().foreground();
117 lbColors->insertItem( new ColorListItem( i18n("Text Color"),
118 config->readColorEntry( "TextColor", &c ) ) );
119 c = colorGroup().button();
120 lbColors->insertItem( new ColorListItem( i18n("Header, Border and Separator Color"),
121 config->readColorEntry( "HeaderColor", &c ) ) );
122 c = colorGroup().buttonText();
123 lbColors->insertItem( new ColorListItem( i18n("Header Text Color"),
124 config->readColorEntry( "HeaderTextColor", &c ) ) );
125 c = colorGroup().highlight();
126 lbColors->insertItem( new ColorListItem( i18n("Highlight Color"),
127 config->readColorEntry( "HighlightColor", &c ) ) );
128 c = colorGroup().highlightedText();
129 lbColors->insertItem( new ColorListItem( i18n("Highlighted Text Color"),
130 config->readColorEntry( "HighlightedTextColor", &c ) ) );
131
132 enableColors();
133
134 // fonts
135 QFont fnt = font();
136 updateFontLabel( config->readFontEntry( "TextFont", &fnt ), (QLabel*)lTextFont );
137 fnt.setBold( true );
138 updateFontLabel( config->readFontEntry( "HeaderFont", &fnt ), (QLabel*)lHeaderFont );
139 cbEnableCustomFonts->setChecked( config->readBoolEntry( "EnableCustomFonts", false ) );
140 enableFonts();
141
142 // layout
143 sbMargin->setValue( config->readNumEntry( "ItemMargin", 0 ) );
144 sbSpacing->setValue( config->readNumEntry( "ItemSpacing", 10 ) );
145 sbSepWidth->setValue( config->readNumEntry( "SeparatorWidth", 2 ) );
146 cbDrawSeps->setChecked( config->readBoolEntry( "DrawSeparators", true ) );
147 cbDrawBorders->setChecked( config->readBoolEntry( "DrawBorder", true ) );
148
149 // behaviour
150 cbShowFieldLabels->setChecked( config->readBoolEntry( "DrawFieldLabels", false ) );
151 cbShowEmptyFields->setChecked( config->readBoolEntry( "ShowEmptyFields", false ) );
152}
153
154void CardViewLookNFeelPage::saveSettings( KConfig *config )
155{
156 // colors
157 config->writeEntry( "EnableCustomColors", cbEnableCustomColors->isChecked() );
158 if ( cbEnableCustomColors->isChecked() ) // ?? - Hmmm.
159 {
160 config->writeEntry( "BackgroundColor", lbColors->color( 0 ) );
161 config->writeEntry( "TextColor", lbColors->color( 1 ) );
162 config->writeEntry( "HeaderColor", lbColors->color( 2 ) );
163 config->writeEntry( "HeaderTextColor", lbColors->color( 3 ) );
164 config->writeEntry( "HighlightColor", lbColors->color( 4 ) );
165 config->writeEntry( "HighlightedTextColor", lbColors->color( 5 ) );
166 }
167 // fonts
168 config->writeEntry( "EnableCustomFonts", cbEnableCustomFonts->isChecked() );
169 if ( cbEnableCustomFonts->isChecked() )
170 {
171 config->writeEntry( "TextFont", lTextFont->font() );
172 config->writeEntry( "HeaderFont", lHeaderFont->font() );
173 }
174 // layout
175 config->writeEntry( "ItemMargin", sbMargin->value() );
176 config->writeEntry( "ItemSpacing", sbSpacing->value() );
177 config->writeEntry( "SeparatorWidth", sbSepWidth->value() );
178 config->writeEntry("DrawBorder", cbDrawBorders->isChecked());
179 config->writeEntry("DrawSeparators", cbDrawSeps->isChecked());
180
181 // behaviour
182 config->writeEntry("DrawFieldLabels", cbShowFieldLabels->isChecked());
183 config->writeEntry("ShowEmptyFields", cbShowEmptyFields->isChecked());
184}
185
186void CardViewLookNFeelPage::setTextFont()
187{
188 QFont f( lTextFont->font() );
189#ifndef KAB_EMBEDDED
190 if ( KFontDialog::getFont( f, false, this ) == QDialog::Accepted )
191 updateFontLabel( f, lTextFont );
192#else //KAB_EMBEDDED
193 bool ok;
194 QFont fout = KFontDialog::getFont( f, ok);
195 if ( ok )
196 updateFontLabel( fout, lTextFont );
197#endif //KAB_EMBEDDED
198}
199
200void CardViewLookNFeelPage::setHeaderFont()
201{
202 QFont f( lHeaderFont->font() );
203#ifndef KAB_EMBEDDED
204 if ( KFontDialog::getFont( f,false, this ) == QDialog::Accepted )
205 updateFontLabel( f, lHeaderFont );
206#else //KAB_EMBEDDED
207 bool ok;
208 QFont fout = KFontDialog::getFont( f, ok);
209 if ( ok )
210 updateFontLabel( fout, lHeaderFont );
211#endif //KAB_EMBEDDED
212}
213
214void CardViewLookNFeelPage::enableFonts()
215{
216 vbFonts->setEnabled( cbEnableCustomFonts->isChecked() );
217}
218
219void CardViewLookNFeelPage::enableColors()
220{
221 lbColors->setEnabled( cbEnableCustomColors->isChecked() );
222}
223
224void CardViewLookNFeelPage::initGUI()
225{
226 int spacing = KDialog::spacingHint();
227 int margin = KDialog::marginHint();
228
229 QTabWidget *tabs = new QTabWidget( this );
230
231 // Layout
232 QVBox *loTab = new QVBox( this, "layouttab" );
233
234 loTab->setSpacing( spacing );
235 loTab->setMargin( margin );
236
237 QGroupBox *gbGeneral = new QGroupBox( 1, Qt::Horizontal, i18n("General"), loTab );
238
239 cbDrawSeps = new QCheckBox( i18n("Draw &separators"), gbGeneral );
240
241 QHBox *hbSW = new QHBox( gbGeneral );
242 QLabel *lSW = new QLabel( i18n("Separator &width:"), hbSW );
243 sbSepWidth = new QSpinBox( 1, 50, 1, hbSW );
244 lSW->setBuddy( sbSepWidth);
245
246 QHBox *hbPadding = new QHBox( gbGeneral );
247 QLabel *lSpacing = new QLabel( i18n("&Padding:"), hbPadding );
248 sbSpacing = new QSpinBox( 0, 100, 1, hbPadding );
249 lSpacing->setBuddy( sbSpacing );
250
251 QGroupBox *gbCards = new QGroupBox( 1, Qt::Horizontal, i18n("Cards"), loTab );
252
253 QHBox *hbMargin = new QHBox( gbCards );
254 QLabel *lMargin = new QLabel( i18n("&Margin:"), hbMargin );
255 sbMargin = new QSpinBox( 0, 100, 1, hbMargin );
256 lMargin->setBuddy( sbMargin );
257
258 cbDrawBorders = new QCheckBox( i18n("Draw &borders"), gbCards );
259
260 loTab->setStretchFactor( new QWidget( loTab ), 1 );
261
262 QWhatsThis::add( sbMargin, i18n(
263 "The item margin is the distance (in pixels) between the item edge and the item data. Most noticeably, "
264 "incrementing the item margin will add space between the focus rectangle and the item data."
265 ) );
266 QWhatsThis::add( lMargin, QWhatsThis::textFor( sbMargin ) );
267 QWhatsThis::add( sbSpacing, i18n(
268 "The Item Spacing decides the distance (in pixels) between the items and anything else: the view "
269 "borders, other items or column separators."
270 ) );
271 QWhatsThis::add( lSpacing, QWhatsThis::textFor( sbSpacing ) );
272 QWhatsThis::add( sbSepWidth, i18n("Sets the width of column separators") );
273 QWhatsThis::add( lSW, QWhatsThis::textFor( sbSepWidth ) );
274
275 tabs->addTab( loTab, i18n("&Layout") );
276
277 // Colors
278 QVBox *colorTab = new QVBox( this, "colortab" );
279 colorTab->setSpacing( spacing );
280 colorTab->setMargin( spacing );
281 cbEnableCustomColors = new QCheckBox( i18n("&Enable custom Colors"), colorTab );
282 connect( cbEnableCustomColors, SIGNAL(clicked()), this, SLOT(enableColors()) );
283 lbColors = new ColorListBox( colorTab );
284 tabs->addTab( colorTab, i18n("&Colors") );
285
286 QWhatsThis::add( cbEnableCustomColors, i18n(
287 "If custom colors are enabled, you may choose the colors for the view below. "
288 "Otherwise colors from your current KDE color scheme are used."
289 ) );
290 QWhatsThis::add( lbColors, i18n(
291 "Double click or press RETURN on a item to select a color for the related strings in the view."
292 ) );
293
294 // Fonts
295 QVBox *fntTab = new QVBox( this, "fonttab" );
296
297 fntTab->setSpacing( spacing );
298 fntTab->setMargin( spacing );
299
300 cbEnableCustomFonts = new QCheckBox( i18n("&Enable custom fonts"), fntTab );
301 connect( cbEnableCustomFonts, SIGNAL(clicked()), this, SLOT(enableFonts()) );
302
303 vbFonts = new QWidget( fntTab );
304 QGridLayout *gFnts = new QGridLayout( vbFonts, 2, 3 );
305 gFnts->setSpacing( spacing );
306 gFnts->setAutoAdd( true );
307 gFnts->setColStretch( 1, 1 );
308 QLabel *lTFnt = new QLabel( i18n("&Text font:"), vbFonts );
309 lTextFont = new QLabel( vbFonts );
310 lTextFont->setFrameStyle( QFrame::Panel|QFrame::Sunken );
311#ifndef KAB_EMBEDDED
312 btnFont = new KPushButton( i18n("Choose..."), vbFonts );
313#else //KAB_EMBEDDED
314 btnFont = new QPushButton( i18n("Choose..."), vbFonts );
315#endif //KAB_EMBEDDED
316
317 lTFnt->setBuddy( btnFont );
318
319 connect( btnFont, SIGNAL(clicked()), this, SLOT(setTextFont()) );
320
321 QLabel *lHFnt = new QLabel( i18n("&Header font:"), vbFonts );
322 lHeaderFont = new QLabel( vbFonts );
323 lHeaderFont->setFrameStyle( QFrame::Panel|QFrame::Sunken );
324#ifndef KAB_EMBEDDED
325 btnHeaderFont = new KPushButton( i18n("Choose..."), vbFonts );
326#else //KAB_EMBEDDED
327 btnHeaderFont = new QPushButton( i18n("Choose..."), vbFonts );
328#endif //KAB_EMBEDDED
329 lHFnt->setBuddy( btnHeaderFont );
330 connect( btnHeaderFont, SIGNAL(clicked()), this, SLOT(setHeaderFont()) );
331
332 fntTab->setStretchFactor( new QWidget( fntTab ), 1 );
333
334 QWhatsThis::add( cbEnableCustomFonts, i18n(
335 "If custom fonts are enabled, you may choose which fonts to use for this view below. "
336 "Otherwise the default KDE font will be used, in bold style for the header and "
337 "normal style for the data."
338 ) );
339
340 tabs->addTab( fntTab, i18n("&Fonts") );
341
342 // Behaviour
343 QVBox *behaviourTab = new QVBox( this );
344 behaviourTab->setMargin( margin );
345 behaviourTab->setSpacing( spacing );
346
347 cbShowEmptyFields = new QCheckBox( i18n("Show &empty fields"), behaviourTab );
348 cbShowFieldLabels = new QCheckBox( i18n("Show field &labels"), behaviourTab );
349
350 behaviourTab->setStretchFactor( new QWidget( behaviourTab ), 1 );
351
352 tabs->addTab( behaviourTab, i18n("Be&havior") );
353
354}
355
356void CardViewLookNFeelPage::updateFontLabel( QFont fnt, QLabel *l )
357{
358 l->setFont( fnt );
359 l->setText( QString( fnt.family() + " %1" ).arg( fnt.pointSize() ) );
360}
361
362#ifndef KAB_EMBEDDED
363#include "configurecardviewdialog.moc"
364#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/configurecardviewdialog.h b/kaddressbook/views/configurecardviewdialog.h
new file mode 100644
index 0000000..7a62226
--- a/dev/null
+++ b/kaddressbook/views/configurecardviewdialog.h
@@ -0,0 +1,117 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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#ifndef CONFIGURECARDVIEWDIALOG_H
25#define CONFIGURECARDVIEWDIALOG_H
26
27#include "viewconfigurewidget.h"
28
29#include <qvbox.h>
30#include <qwidget.h>
31#include <qfont.h>
32
33class QString;
34class QWidget;
35class QCheckBox;
36class QLabel;
37class KConfig;
38
39namespace KABC { class AddressBook; }
40
41class CardViewLookAndFeelPage;
42
43/**
44 Configure dialog for the card view. This dialog inherits from the
45 standard view dialog in order to add a custom page for the card
46 view.
47 */
48class ConfigureCardViewWidget : public ViewConfigureWidget
49{
50 public:
51 ConfigureCardViewWidget( KABC::AddressBook *ab, QWidget *parent, const char *name );
52 virtual ~ConfigureCardViewWidget();
53
54 virtual void restoreSettings( KConfig* );
55 virtual void saveSettings( KConfig* );
56
57 private:
58 class CardViewLookNFeelPage *mAdvancedPage;
59};
60
61/**
62 Card View Advanced LookNFeel settings widget:
63 this is a tabbed widget with 3 tabs:
64 Fonts
65 * text font
66 * header font
67
68 Colors
69 * background color
70 * text color
71 * highlight color
72 * title/sep text color
73 * title/sep bg color
74
75 Layout
76 * item margin
77 * item spacing
78*/
79
80class CardViewLookNFeelPage : public QVBox {
81
82 Q_OBJECT
83
84 public:
85 CardViewLookNFeelPage( QWidget *parent=0, const char *name=0 );
86 ~CardViewLookNFeelPage();
87
88 void restoreSettings( KConfig* );
89 void saveSettings( KConfig* );
90
91 private slots:
92 void setTextFont();
93 void setHeaderFont();
94 void enableFonts();
95 void enableColors();
96
97 private:
98 void initGUI();
99 void updateFontLabel( QFont, QLabel * );
100
101 QCheckBox *cbEnableCustomFonts,
102 *cbEnableCustomColors,
103 *cbDrawSeps, *cbDrawBorders,
104 *cbShowFieldLabels, *cbShowEmptyFields;
105 class ColorListBox *lbColors;
106 QLabel *lTextFont, *lHeaderFont;
107#ifndef KAB_EMBEDDED
108 class KPushButton *btnFont, *btnHeaderFont;
109#else //KAB_EMBEDDED
110 class QPushButton *btnFont, *btnHeaderFont;
111#endif //KAB_EMBEDDED
112 class QSpinBox *sbMargin, *sbSpacing, *sbSepWidth;
113
114 class QWidget *vbFonts;
115};
116
117#endif
diff --git a/kaddressbook/views/configuretableviewdialog.cpp b/kaddressbook/views/configuretableviewdialog.cpp
new file mode 100644
index 0000000..e1cc63e
--- a/dev/null
+++ b/kaddressbook/views/configuretableviewdialog.cpp
@@ -0,0 +1,155 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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 <qstring.h>
25#include <qwidget.h>
26#include <qlayout.h>
27#include <qradiobutton.h>
28#include <qcheckbox.h>
29#include <qvbox.h>
30#include <qbuttongroup.h>
31
32#include <kglobal.h>
33#include <klocale.h>
34#include <klineedit.h>
35#include <kurlrequester.h>
36#include <kiconloader.h>
37
38#ifndef KAB_EMBEDDED
39#include <kimageio.h>
40#else //KAB_EMBEDDED
41#endif //KAB_EMBEDDED
42
43#include <kconfig.h>
44
45#include "configuretableviewdialog.h"
46
47ConfigureTableViewWidget::ConfigureTableViewWidget( KABC::AddressBook *ab,
48 QWidget *parent,
49 const char *name )
50 : ViewConfigureWidget( ab, parent, name )
51{
52 QWidget *page = addPage( i18n( "Look & Feel" ), QString::null,
53 KGlobal::iconLoader()->loadIcon( "looknfeel",
54 KIcon::Panel ) );
55
56 mPage = new LookAndFeelPage( page );
57}
58
59ConfigureTableViewWidget::~ConfigureTableViewWidget()
60{
61}
62
63void ConfigureTableViewWidget::restoreSettings( KConfig *config )
64{
65 ViewConfigureWidget::restoreSettings( config );
66
67 mPage->restoreSettings( config );
68}
69
70void ConfigureTableViewWidget::saveSettings( KConfig *config )
71{
72 ViewConfigureWidget::saveSettings( config );
73
74 mPage->saveSettings( config );
75}
76
77
78
79LookAndFeelPage::LookAndFeelPage(QWidget *parent, const char *name)
80 : QWidget(parent, name)
81{
82 initGUI();
83
84 // Set initial state
85 enableBackgroundToggled(mBackgroundBox->isChecked());
86}
87
88void LookAndFeelPage::restoreSettings( KConfig *config )
89{
90 mAlternateButton->setChecked(config->readBoolEntry("ABackground", true));
91 mLineButton->setChecked(config->readBoolEntry("SingleLine", false));
92 mToolTipBox->setChecked(config->readBoolEntry("ToolTips", true));
93
94 if (!mAlternateButton->isChecked() & !mLineButton->isChecked())
95 mNoneButton->setChecked(true);
96
97 mBackgroundBox->setChecked(config->readBoolEntry("Background", false));
98 mBackgroundName->lineEdit()->setText(config->readEntry("BackgroundName"));
99}
100
101void LookAndFeelPage::saveSettings( KConfig *config )
102{
103 config->writeEntry("ABackground", mAlternateButton->isChecked());
104 config->writeEntry("SingleLine", mLineButton->isChecked());
105 config->writeEntry("ToolTips", mToolTipBox->isChecked());
106 config->writeEntry("Background", mBackgroundBox->isChecked());
107 config->writeEntry("BackgroundName", mBackgroundName->lineEdit()->text());
108}
109
110void LookAndFeelPage::initGUI()
111{
112 QVBoxLayout *layout = new QVBoxLayout(this, 0, KDialogBase::spacingHint());
113
114 QButtonGroup *group = new QButtonGroup(1, Qt::Horizontal,
115 i18n("Row Separator"), this);
116 layout->addWidget(group);
117
118 mAlternateButton = new QRadioButton(i18n("Alternating backgrounds"),
119 group, "mAlternateButton");
120 mLineButton = new QRadioButton(i18n("Single line"), group, "mLineButton");
121 mNoneButton = new QRadioButton(i18n("None"), group, "mNoneButton");
122
123 // Background Checkbox/Selector
124 QHBoxLayout *backgroundLayout = new QHBoxLayout();
125 layout->addLayout(backgroundLayout);
126
127 mBackgroundBox = new QCheckBox(i18n("Enable background image:"), this,
128 "mBackgroundBox");
129 connect(mBackgroundBox, SIGNAL(toggled(bool)),
130 SLOT(enableBackgroundToggled(bool)));
131 backgroundLayout->addWidget(mBackgroundBox);
132
133 mBackgroundName = new KURLRequester(this, "mBackgroundName");
134#ifndef KAB_EMBEDDED
135 mBackgroundName->setMode(KFile::File | KFile::ExistingOnly |
136 KFile::LocalOnly);
137 mBackgroundName->setFilter(KImageIO::pattern(KImageIO::Reading));
138#endif //KAB_EMBEDDED
139
140 backgroundLayout->addWidget(mBackgroundName);
141
142 // ToolTip Checkbox
143 mToolTipBox = new QCheckBox(i18n("Enable contact tooltips"), this,
144 "mToolTipBox");
145 layout->addWidget(mToolTipBox);
146}
147
148void LookAndFeelPage::enableBackgroundToggled(bool enabled)
149{
150 mBackgroundName->setEnabled(enabled);
151}
152
153#ifndef KAB_EMBEDDED
154#include "configuretableviewdialog.moc"
155#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/configuretableviewdialog.h b/kaddressbook/views/configuretableviewdialog.h
new file mode 100644
index 0000000..8392710
--- a/dev/null
+++ b/kaddressbook/views/configuretableviewdialog.h
@@ -0,0 +1,88 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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#ifndef CONFIGURETABLEVIEWDIALOG_H
25#define CONFIGURETABLEVIEWDIALOG_H
26
27#include "viewconfigurewidget.h"
28
29class QString;
30class QWidget;
31class QRadioButton;
32class QCheckBox;
33class KURLRequester;
34class KConfig;
35
36namespace KABC { class AddressBook; }
37
38class LookAndFeelPage;
39
40/**
41 Configure dialog for the table view. This dialog inherits from the
42 standard view dialog in order to add a custom page for the table
43 view.
44 */
45class ConfigureTableViewWidget : public ViewConfigureWidget
46{
47 public:
48 ConfigureTableViewWidget( KABC::AddressBook *ab, QWidget *parent, const char *name );
49 virtual ~ConfigureTableViewWidget();
50
51 virtual void restoreSettings( KConfig* );
52 virtual void saveSettings( KConfig* );
53
54 private:
55 void initGUI();
56
57 LookAndFeelPage *mPage;
58};
59
60/**
61 Internal class. It is only defined here for moc
62*/
63class LookAndFeelPage : public QWidget
64{
65 Q_OBJECT
66
67 public:
68 LookAndFeelPage( QWidget *parent, const char *name = 0 );
69 ~LookAndFeelPage() {}
70
71 void restoreSettings( KConfig* );
72 void saveSettings( KConfig* );
73
74 protected slots:
75 void enableBackgroundToggled( bool );
76
77 private:
78 void initGUI();
79
80 QRadioButton *mAlternateButton;
81 QRadioButton *mLineButton;
82 QRadioButton *mNoneButton;
83 QCheckBox *mToolTipBox;
84 KURLRequester *mBackgroundName;
85 QCheckBox *mBackgroundBox;
86};
87
88#endif
diff --git a/kaddressbook/views/contactlistview.cpp b/kaddressbook/views/contactlistview.cpp
new file mode 100644
index 0000000..98b2fb2
--- a/dev/null
+++ b/kaddressbook/views/contactlistview.cpp
@@ -0,0 +1,340 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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 <qheader.h>
25#include <qiconset.h>
26#include <qimage.h>
27#include <qdragobject.h>
28#include <qcombobox.h>
29#include <qpainter.h>
30#include <qbrush.h>
31#include <qevent.h>
32
33#include <klocale.h>
34#include <kglobalsettings.h>
35#include <kiconloader.h>
36#include <kdebug.h>
37#include <kconfig.h>
38#include <kapplication.h>
39#include <kurl.h>
40
41#include "kaddressbooktableview.h"
42
43#include "contactlistview.h"
44
45/////////////////////////////////
46// DynamicTip Methods
47
48DynamicTip::DynamicTip( ContactListView *parent)
49 : QToolTip( parent )
50{
51}
52
53void DynamicTip::maybeTip( const QPoint &pos )
54{
55 static bool ishidden = true;
56 if (!parentWidget()->inherits( "ContactListView" ))
57 return;
58
59 ContactListView *plv = (ContactListView*)parentWidget();
60 if (!plv->tooltips())
61 return;
62
63 QPoint posVp = plv->viewport()->pos();
64
65 QListViewItem *lvi = plv->itemAt( pos - posVp );
66 if (!lvi)
67 return;
68
69#ifndef KAB_EMBEDDED
70 ContactListViewItem *plvi = dynamic_cast< ContactListViewItem* >(lvi);
71#else //KAB_EMBEDDED
72 ContactListViewItem *plvi = (ContactListViewItem*)(lvi);
73#endif //KAB_EMBEDDED
74
75 if (!plvi)
76 return;
77
78 if (ishidden) {
79 QString s;
80 QRect r = plv->itemRect( lvi );
81 r.moveBy( posVp.x(), posVp.y() );
82
83 //kdDebug() << "Tip rec: " << r.x() << "," << r.y() << "," << r.width()
84 // << "," << r.height() << endl;
85
86 KABC::Addressee a = plvi->addressee();
87 if (a.isEmpty())
88 return;
89
90 s += i18n("label: value", "%1: %2").arg(a.formattedNameLabel())
91 .arg(a.formattedName());
92
93 s += '\n';
94 s += i18n("label: value", "%1: %2").arg(a.organizationLabel())
95 .arg(a.organization());
96
97 QString notes = a.note().stripWhiteSpace();
98 if ( !notes.isEmpty() ) {
99 notes += '\n';
100 s += '\n' + i18n("label: value", "%1: \n").arg(a.noteLabel());
101 QFontMetrics fm( font() );
102
103 // Begin word wrap code based on QMultiLineEdit code
104 int i = 0;
105 bool doBreak = false;
106 int linew = 0;
107 int lastSpace = -1;
108 int a = 0;
109 int lastw = 0;
110
111 while ( i < int(notes.length()) ) {
112 doBreak = FALSE;
113 if ( notes[i] != '\n' )
114 linew += fm.width( notes[i] );
115
116 if ( lastSpace >= a && notes[i] != '\n' )
117 if (linew >= parentWidget()->width()) {
118 doBreak = TRUE;
119 if ( lastSpace > a ) {
120 i = lastSpace;
121 linew = lastw;
122 }
123 else
124 i = QMAX( a, i-1 );
125 }
126
127 if ( notes[i] == '\n' || doBreak ) {
128 s += notes.mid( a, i - a + (doBreak?1:0) ) +"\n";
129
130 a = i + 1;
131 lastSpace = a;
132 linew = 0;
133 }
134
135 if ( notes[i].isSpace() ) {
136 lastSpace = i;
137 lastw = linew;
138 }
139
140 if ( lastSpace <= a ) {
141 lastw = linew;
142 }
143
144 ++i;
145 }
146 }
147
148 tip( r, s );
149 }
150 else
151 hide();
152 ishidden = !ishidden;
153
154}
155
156///////////////////////////
157// ContactListViewItem Methods
158
159ContactListViewItem::ContactListViewItem(const KABC::Addressee &a,
160 ContactListView *parent,
161 KABC::AddressBook *doc,
162 const KABC::Field::List &fields )
163 : KListViewItem(parent), mAddressee(a), mFields( fields ),
164 parentListView( parent ), mDocument(doc)
165{
166 refresh();
167}
168
169QString ContactListViewItem::key(int column, bool ascending) const
170{
171 return QListViewItem::key(column, ascending).lower();
172}
173
174void ContactListViewItem::paintCell(QPainter * p,
175 const QColorGroup & cg,
176 int column,
177 int width,
178 int align)
179{
180 KListViewItem::paintCell(p, cg, column, width, align);
181
182 if ( !p )
183 return;
184
185 if (parentListView->singleLine()) {
186 p->setPen( parentListView->alternateColor() );
187 p->drawLine( 0, height() - 1, width, height() - 1 );
188 }
189}
190
191
192ContactListView *ContactListViewItem::parent()
193{
194 return parentListView;
195}
196
197
198void ContactListViewItem::refresh()
199{
200 // Update our addressee, since it may have changed else were
201 mAddressee = mDocument->findByUid(mAddressee.uid());
202 if (mAddressee.isEmpty())
203 return;
204
205 int i = 0;
206 KABC::Field::List::ConstIterator it;
207 for( it = mFields.begin(); it != mFields.end(); ++it ) {
208 setText( i++, (*it)->value( mAddressee ) );
209 }
210}
211
212///////////////////////////////
213// ContactListView
214
215ContactListView::ContactListView(KAddressBookTableView *view,
216 KABC::AddressBook* /* doc */,
217 QWidget *parent,
218 const char *name )
219 : KListView( parent, name ),
220 pabWidget( view ),
221 oldColumn( 0 )
222{
223 mABackground = true;
224 mSingleLine = false;
225 mToolTips = true;
226#ifndef KAB_EMBEDDED
227 mAlternateColor = KGlobalSettings::alternateBackgroundColor();
228#else //KAB_EMBEDDED
229 mAlternateColor = QColor(240, 240, 240);
230#endif //KAB_EMBEDDED
231
232 setAlternateBackgroundEnabled(mABackground);
233 setAcceptDrops( true );
234 viewport()->setAcceptDrops( true );
235 setAllColumnsShowFocus( true );
236 setShowSortIndicator(true);
237
238 setSelectionModeExt( KListView::Extended );
239 setDropVisualizer(false);
240 // setFrameStyle(QFrame::NoFrame);
241 setLineWidth ( 0 );
242 setMidLineWidth ( 0 );
243 setMargin ( 0 );
244#ifndef KAB_EMBEDDED
245 connect(this, SIGNAL(dropped(QDropEvent*)),
246 this, SLOT(itemDropped(QDropEvent*)));
247#endif //KAB_EMBEDDED
248
249
250 new DynamicTip( this );
251}
252
253void ContactListView::paintEmptyArea( QPainter * p, const QRect & rect )
254{
255 QBrush b = palette().brush(QPalette::Active, QColorGroup::Base);
256
257 // Get the brush, which will have the background pixmap if there is one.
258 if (b.pixmap())
259 {
260 p->drawTiledPixmap( rect.left(), rect.top(), rect.width(), rect.height(),
261 *(b.pixmap()),
262 rect.left() + contentsX(),
263 rect.top() + contentsY() );
264 }
265
266 else
267 {
268 // Do a normal paint
269 KListView::paintEmptyArea(p, rect);
270 }
271}
272
273void ContactListView::contentsMousePressEvent(QMouseEvent* e)
274{
275 presspos = e->pos();
276 KListView::contentsMousePressEvent(e);
277}
278
279
280// To initiate a drag operation
281void ContactListView::contentsMouseMoveEvent( QMouseEvent *e )
282{
283 if ((e->state() & LeftButton) && (e->pos() - presspos).manhattanLength() > 4 ) {
284 emit startAddresseeDrag();
285 }
286 else
287 KListView::contentsMouseMoveEvent( e );
288}
289
290bool ContactListView::acceptDrag(QDropEvent *e) const
291{
292#ifndef KAB_EMBEDDED
293 return QTextDrag::canDecode(e);
294#else //KAB_EMBEDDED
295qDebug("ContactListView::acceptDrag has to be fixed");
296 return false;
297#endif //KAB_EMBEDDED
298}
299
300void ContactListView::itemDropped(QDropEvent *e)
301{
302 contentsDropEvent(e);
303}
304
305void ContactListView::contentsDropEvent( QDropEvent *e )
306{
307 emit addresseeDropped(e);
308}
309
310void ContactListView::setAlternateBackgroundEnabled(bool enabled)
311{
312 mABackground = enabled;
313
314 if (mABackground)
315 {
316 setAlternateBackground(mAlternateColor);
317 }
318 else
319 {
320 setAlternateBackground(QColor());
321 }
322}
323
324void ContactListView::setBackgroundPixmap(const QString &filename)
325{
326 if (filename.isEmpty())
327 {
328 unsetPalette();
329 }
330 else
331 {
332 qDebug("ContactListView::setBackgroundPixmap has to be verified");
333//US setPaletteBackgroundPixmap(QPixmap(filename));
334 KListView::setBackgroundPixmap((const QPixmap&)QPixmap(filename));
335 }
336
337}
338#ifndef KAB_EMBEDDED
339#include "contactlistview.moc"
340#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/contactlistview.h b/kaddressbook/views/contactlistview.h
new file mode 100644
index 0000000..ae9c994
--- a/dev/null
+++ b/kaddressbook/views/contactlistview.h
@@ -0,0 +1,128 @@
1#ifndef CONTACTLISTVIEW_H
2#define CONTACTLISTVIEW_H
3
4#include <qcolor.h>
5#include <qpixmap.h>
6#include <qtooltip.h>
7#include <qstring.h>
8
9#include <klistview.h>
10
11#include <kabc/field.h>
12#include <kabc/addressee.h>
13#include <kabc/addressbook.h>
14
15
16class QDropEvent;
17class KAddressBookTableView;
18class ContactListView;
19
20/** The whole tooltip design needs a lot of work. Currently it is
21* hacked together to function.
22*/
23class DynamicTip : public QToolTip
24{
25 public:
26 DynamicTip( ContactListView * parent );
27
28 protected:
29 void maybeTip( const QPoint & );
30
31 private:
32};
33
34class ContactListViewItem : public KListViewItem
35{
36
37public:
38 ContactListViewItem(const KABC::Addressee &a, ContactListView* parent,
39 KABC::AddressBook *doc, const KABC::Field::List &fields );
40 const KABC::Addressee &addressee() const { return mAddressee; }
41 virtual void refresh();
42 virtual ContactListView* parent();
43 virtual QString key ( int, bool ) const;
44
45 /** Adds the border around the cell if the user wants it.
46 * This is how the single line config option is implemented.
47 */
48 virtual void paintCell(QPainter * p, const QColorGroup & cg,
49 int column, int width, int align );
50
51private:
52 KABC::Addressee mAddressee;
53 KABC::Field::List mFields;
54 ContactListView *parentListView;
55 KABC::AddressBook *mDocument;
56};
57
58
59/////////////////////////////////////////////
60// ContactListView
61
62class ContactListView : public KListView
63{
64 Q_OBJECT
65
66public:
67 ContactListView(KAddressBookTableView *view,
68 KABC::AddressBook *doc,
69 QWidget *parent,
70 const char *name = 0L );
71 virtual ~ContactListView() {}
72 //void resort();
73
74 /** Returns true if tooltips should be displayed, false otherwise
75 */
76 bool tooltips() const { return mToolTips; }
77 void setToolTipsEnabled(bool enabled) { mToolTips = enabled; }
78
79 bool alternateBackground() const { return mABackground; }
80 void setAlternateBackgroundEnabled(bool enabled);
81
82 bool singleLine() const { return mSingleLine; }
83 void setSingleLineEnabled(bool enabled) { mSingleLine = enabled; }
84
85 const QColor &alternateColor() const { return mAlternateColor; }
86
87 /** Sets the background pixmap to <i>filename</i>. If the
88 * QString is empty (QString::isEmpty()), then the background
89 * pixmap will be disabled.
90 */
91 void setBackgroundPixmap(const QString &filename);
92
93protected:
94 /** Paints the background pixmap in the empty area. This method is needed
95 * since Qt::FixedPixmap will not scroll with the list view.
96 */
97 virtual void paintEmptyArea( QPainter * p, const QRect & rect );
98 virtual void contentsMousePressEvent(QMouseEvent*);
99 void contentsMouseMoveEvent( QMouseEvent *e );
100 void contentsDropEvent( QDropEvent *e );
101 virtual bool acceptDrag(QDropEvent *e) const;
102
103protected slots:
104 void itemDropped(QDropEvent *e);
105
106public slots:
107
108signals:
109 void startAddresseeDrag();
110 void addresseeDropped(QDropEvent *);
111
112private:
113 KAddressBookTableView *pabWidget;
114 int oldColumn;
115 int column;
116 bool ascending;
117
118 bool mABackground;
119 bool mSingleLine;
120 bool mToolTips;
121
122 QColor mAlternateColor;
123
124 QPoint presspos;
125};
126
127
128#endif
diff --git a/kaddressbook/views/kaddressbookcardview.cpp b/kaddressbook/views/kaddressbookcardview.cpp
new file mode 100644
index 0000000..239429f
--- a/dev/null
+++ b/kaddressbook/views/kaddressbookcardview.cpp
@@ -0,0 +1,394 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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 <qdragobject.h>
25#include <qevent.h>
26#include <qiconview.h>
27#include <qlayout.h>
28#include <qstringlist.h>
29
30#include <kabc/addressbook.h>
31#include <kabc/addressee.h>
32#include <kconfig.h>
33#include <kdebug.h>
34#include <klocale.h>
35
36#include "kabprefs.h"
37#include "viewmanager.h"
38
39#include "kaddressbookcardview.h"
40
41#ifndef KAB_EMBEDDED
42extern "C" {
43 void *init_libkaddrbk_cardview()
44 {
45 return ( new CardViewFactory );
46 }
47}
48#endif //KAB_EMBEDDED
49
50////////////////////////////////
51// AddresseeCardViewItem (internal class)
52class AddresseeCardViewItem : public CardViewItem
53{
54 public:
55 AddresseeCardViewItem(const KABC::Field::List &fields,
56 bool showEmptyFields,
57 KABC::AddressBook *doc, const KABC::Addressee &a,
58 CardView *parent)
59 : CardViewItem(parent, a.formattedName()),
60 mFields( fields ), mShowEmptyFields(showEmptyFields),
61 mDocument(doc), mAddressee(a)
62 {
63 if ( mFields.isEmpty() ) {
64 mFields = KABC::Field::defaultFields();
65 }
66 refresh();
67 }
68
69 const KABC::Addressee &addressee() const { return mAddressee; }
70
71 void refresh()
72 {
73 // Update our addressee, since it may have changed elsewhere
74 mAddressee = mDocument->findByUid(mAddressee.uid());
75
76 if (!mAddressee.isEmpty())
77 {
78 clearFields();
79
80 // Try all the selected fields until we find one with text.
81 // This will limit the number of unlabeled icons in the view
82 KABC::Field::List::Iterator iter;
83 for (iter = mFields.begin(); iter != mFields.end(); ++iter)
84 {
85 // insert empty fields or not? not doing so saves a bit of memory and CPU
86 // (during geometry calculations), but prevents having equally
87 // wide label columns in all cards, unless CardViewItem/CardView search
88 // globally for the widest label. (anders)
89 //if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty())
90 insertField((*iter)->label(), (*iter)->value( mAddressee ));
91 }
92
93 // We might want to make this the first field. hmm... -mpilone
94 setCaption( mAddressee.realName() );
95 }
96 }
97
98 private:
99 KABC::Field::List mFields;
100 bool mShowEmptyFields;
101 KABC::AddressBook *mDocument;
102 KABC::Addressee mAddressee;
103};
104
105///////////////////////////////
106// AddresseeCardView
107
108AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name)
109 : CardView(parent, name)
110{
111 setAcceptDrops(true);
112}
113
114AddresseeCardView::~AddresseeCardView()
115{
116}
117
118void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e)
119{
120#ifndef KAB_EMBEDDED
121 if (QTextDrag::canDecode(e))
122 e->accept();
123#else //KAB_EMBEDDED
124qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented");
125#endif //KAB_EMBEDDED
126}
127
128void AddresseeCardView::dropEvent(QDropEvent *e)
129{
130 emit addresseeDropped(e);
131}
132
133void AddresseeCardView::startDrag()
134{
135 emit startAddresseeDrag();
136}
137
138
139///////////////////////////////
140// KAddressBookCardView
141
142KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab,
143 QWidget *parent, const char *name )
144 : KAddressBookView( ab, parent, name )
145{
146 mShowEmptyFields = false;
147
148 // Init the GUI
149 QVBoxLayout *layout = new QVBoxLayout(viewWidget());
150
151 mCardView = new AddresseeCardView(viewWidget(), "mCardView");
152 mCardView->setSelectionMode(CardView::Extended);
153 layout->addWidget(mCardView);
154
155 // Connect up the signals
156 connect(mCardView, SIGNAL(executed(CardViewItem *)),
157 this, SLOT(addresseeExecuted(CardViewItem *)));
158 connect(mCardView, SIGNAL(selectionChanged()),
159 this, SLOT(addresseeSelected()));
160 connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)),
161 this, SIGNAL(dropped(QDropEvent*)));
162 connect(mCardView, SIGNAL(startAddresseeDrag()),
163 this, SIGNAL(startDrag()));
164}
165
166KAddressBookCardView::~KAddressBookCardView()
167{
168}
169
170void KAddressBookCardView::readConfig(KConfig *config)
171{
172 KAddressBookView::readConfig(config);
173
174 // costum colors?
175 if ( config->readBoolEntry( "EnableCustomColors", false ) )
176 {
177 QPalette p( mCardView->palette() );
178 QColor c = p.color(QPalette::Normal, QColorGroup::Base );
179 p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) );
180 c = p.color(QPalette::Normal, QColorGroup::Text );
181 p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) );
182 c = p.color(QPalette::Normal, QColorGroup::Button );
183 p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) );
184 c = p.color(QPalette::Normal, QColorGroup::ButtonText );
185 p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) );
186 c = p.color(QPalette::Normal, QColorGroup::Highlight );
187 p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) );
188 c = p.color(QPalette::Normal, QColorGroup::HighlightedText );
189 p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) );
190 mCardView->viewport()->setPalette( p );
191 }
192 else
193 {
194 // needed if turned off during a session.
195 mCardView->viewport()->setPalette( mCardView->palette() );
196 }
197
198 //custom fonts?
199 QFont f( font() );
200 if ( config->readBoolEntry( "EnableCustomFonts", false ) )
201 {
202 mCardView->setFont( config->readFontEntry( "TextFont", &f) );
203 f.setBold( true );
204 mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) );
205 }
206 else
207 {
208 mCardView->setFont( f );
209 f.setBold( true );
210 mCardView->setHeaderFont( f );
211 }
212
213 mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true));
214 mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators",
215 true));
216 mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false));
217 mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false);
218
219 mCardView->setShowEmptyFields( mShowEmptyFields );
220
221 mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) );
222 mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) );
223 mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) );
224 mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) );
225
226 disconnect(mCardView, SIGNAL(executed(CardViewItem *)),
227 this, SLOT(addresseeExecuted(CardViewItem *)));
228
229 if (KABPrefs::instance()->mHonorSingleClick)
230 connect(mCardView, SIGNAL(executed(CardViewItem *)),
231 this, SLOT(addresseeExecuted(CardViewItem *)));
232 else
233 connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)),
234 this, SLOT(addresseeExecuted(CardViewItem *)));
235
236}
237
238void KAddressBookCardView::writeConfig( KConfig *config )
239{
240 config->writeEntry( "ItemWidth", mCardView->itemWidth() );
241 KAddressBookView::writeConfig( config );
242}
243
244QStringList KAddressBookCardView::selectedUids()
245{
246 QStringList uidList;
247 CardViewItem *item;
248 AddresseeCardViewItem *aItem;
249
250 for (item = mCardView->firstItem(); item; item = item->nextItem())
251 {
252 if (item->isSelected())
253 {
254#ifndef KAB_EMBEDDED
255 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
256#else //KAB_EMBEDDED
257 aItem = (AddresseeCardViewItem*)(item);
258#endif //KAB_EMBEDDED
259 if (aItem)
260 uidList << aItem->addressee().uid();
261 }
262 }
263
264 return uidList;
265}
266
267void KAddressBookCardView::refresh(QString uid)
268{
269 CardViewItem *item;
270 AddresseeCardViewItem *aItem;
271
272 if (uid.isNull())
273 {
274 // Rebuild the view
275 mCardView->viewport()->setUpdatesEnabled( false );
276 mCardView->clear();
277
278 KABC::Addressee::List addresseeList = addressees();
279 KABC::Addressee::List::Iterator iter;
280 for (iter = addresseeList.begin(); iter != addresseeList.end(); ++iter)
281 {
282 aItem = new AddresseeCardViewItem(fields(), mShowEmptyFields,
283 addressBook(), *iter, mCardView);
284 }
285 mCardView->viewport()->setUpdatesEnabled( true );
286 mCardView->viewport()->update();
287
288 // by default nothing is selected
289 emit selected(QString::null);
290 }
291 else
292 {
293 // Try to find the one to refresh
294 bool found = false;
295 for (item = mCardView->firstItem(); item && !found;
296 item = item->nextItem())
297 {
298#ifndef KAB_EMBEDDED
299 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
300#else //KAB_EMBEDDED
301 aItem = (AddresseeCardViewItem*)(item);
302#endif //KAB_EMBEDDED
303
304 if ((aItem) && (aItem->addressee().uid() == uid))
305 {
306 aItem->refresh();
307 found = true;
308 }
309 }
310 }
311}
312
313void KAddressBookCardView::setSelected(QString uid, bool selected)
314{
315 CardViewItem *item;
316 AddresseeCardViewItem *aItem;
317
318 if (uid.isNull())
319 {
320 mCardView->selectAll(selected);
321 }
322 else
323 {
324 bool found = false;
325 for (item = mCardView->firstItem(); item && !found;
326 item = item->nextItem())
327 {
328#ifndef KAB_EMBEDDED
329 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
330#else //KAB_EMBEDDED
331 aItem = (AddresseeCardViewItem*)(item);
332#endif //KAB_EMBEDDED
333
334 if ((aItem) && (aItem->addressee().uid() == uid))
335 {
336 mCardView->setSelected(aItem, selected);
337 mCardView->ensureItemVisible(item);
338 found = true;
339 }
340 }
341 }
342}
343
344//US added an additional method without parameter
345void KAddressBookCardView::setSelected()
346{
347 setSelected(QString::null, true);
348}
349
350void KAddressBookCardView::addresseeExecuted(CardViewItem *item)
351{
352#ifndef KAB_EMBEDDED
353 AddresseeCardViewItem *aItem = dynamic_cast<AddresseeCardViewItem*>(item);
354#else //KAB_EMBEDDED
355 AddresseeCardViewItem *aItem = (AddresseeCardViewItem*)(item);
356#endif //KAB_EMBEDDED
357 if (aItem)
358 {
359 //kdDebug()<<"... even has a valid item:)"<<endl;
360 emit executed(aItem->addressee().uid());
361 }
362}
363
364void KAddressBookCardView::addresseeSelected()
365{
366 CardViewItem *item;
367 AddresseeCardViewItem *aItem;
368
369 bool found = false;
370 for (item = mCardView->firstItem(); item && !found;
371 item = item->nextItem())
372 {
373 if (item->isSelected())
374 {
375#ifndef KAB_EMBEDDED
376 aItem = dynamic_cast<AddresseeCardViewItem*>(item);
377#else //KAB_EMBEDDED
378 aItem = (AddresseeCardViewItem*)(item);
379#endif //KAB_EMBEDDED
380 if ( aItem )
381 {
382 emit selected(aItem->addressee().uid());
383 found = true;
384 }
385 }
386 }
387
388 if (!found)
389 emit selected(QString::null);
390
391}
392#ifndef KAB_EMBEDDED
393#include "kaddressbookcardview.moc"
394#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/kaddressbookcardview.h b/kaddressbook/views/kaddressbookcardview.h
new file mode 100644
index 0000000..cd70371
--- a/dev/null
+++ b/kaddressbook/views/kaddressbookcardview.h
@@ -0,0 +1,117 @@
1#ifndef KADDRESSBOOKCARDVIEW_H
2#define KADDRESSBOOKCARDVIEW_H
3
4/*
5 This file is part of KAddressBook.
6 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
22 As a special exception, permission is given to link this program
23 with any edition of Qt, and distribute the resulting executable,
24 without including the source code for Qt in the source distribution.
25*/
26
27#include <qstring.h>
28#ifndef KAB_EMBEDDED
29#include <kiconview.h>
30#else //KAB_EMBEDDED
31#include <klocale.h>
32#endif //KAB_EMBEDDED
33
34#include "cardview.h"
35#include "kaddressbookview.h"
36#include "configurecardviewdialog.h"
37
38class QDragEnterEvent;
39class QDragEntryEvent;
40class QDropEvent;
41class KConfig;
42class AddresseeCardView;
43
44/**
45 This view uses the CardView class to create a card view. At some
46 point in the future I think this will be the default view of
47 KAddressBook.
48 */
49class KAddressBookCardView : public KAddressBookView
50{
51 Q_OBJECT
52
53 public:
54 KAddressBookCardView( KABC::AddressBook *ab, QWidget *parent,
55 const char *name = 0 );
56 virtual ~KAddressBookCardView();
57
58 virtual QStringList selectedUids();
59 virtual QString type() const { return "Card"; }
60
61 virtual void readConfig(KConfig *config);
62 virtual void writeConfig(KConfig *);
63
64 public slots:
65 void refresh(QString uid = QString::null);
66 void setSelected(QString uid/*US = QString::null*/, bool selected/*US = true*/);
67//US added an additional method without parameter
68 void setSelected();
69
70 protected slots:
71 void addresseeExecuted(CardViewItem *item);
72 void addresseeSelected();
73
74 private:
75 AddresseeCardView *mCardView;
76 bool mShowEmptyFields;
77};
78
79class AddresseeCardView : public CardView
80{
81 Q_OBJECT
82 public:
83 AddresseeCardView(QWidget *parent, const char *name = 0);
84 ~AddresseeCardView();
85
86 signals:
87 void startAddresseeDrag();
88 void addresseeDropped(QDropEvent *);
89
90 protected:
91 virtual void dragEnterEvent(QDragEnterEvent *);
92 virtual void dropEvent(QDropEvent *);
93 virtual void startDrag();
94};
95
96
97class CardViewFactory : public ViewFactory
98{
99 public:
100 KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name )
101 {
102 return new KAddressBookCardView( ab, parent, name );
103 }
104
105 QString type() const { return "Card"; }
106
107 QString description() const { return i18n( "Rolodex style cards represent contacts." ); }
108
109 ViewConfigureWidget *configureWidget( KABC::AddressBook *ab, QWidget *parent,
110 const char *name = 0 )
111 {
112 return new ConfigureCardViewWidget( ab, parent, name );
113 }
114};
115
116
117#endif
diff --git a/kaddressbook/views/kaddressbookiconview.cpp b/kaddressbook/views/kaddressbookiconview.cpp
new file mode 100644
index 0000000..50ff285
--- a/dev/null
+++ b/kaddressbook/views/kaddressbookiconview.cpp
@@ -0,0 +1,378 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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#ifndef KAB_EMBEDDED
25#include <qiconview.h>
26#include <qstringlist.h>
27
28#include <kabc/addressee.h>
29#include <kconfig.h>
30#include <kdebug.h>
31#include <kglobal.h>
32#include <kiconloader.h>
33#include <klocale.h>
34
35#else //KAB_EMBEDDED
36#endif //KAB_EMBEDDED
37
38#include <kabc/addressbook.h>
39#include "kabprefs.h"
40#include "viewmanager.h"
41#include "kaddressbookiconview.h"
42#include <qlayout.h>
43#include <kglobal.h>
44/*US transfered to the headerfile
45class IconViewFactory : public ViewFactory
46{
47 public:
48 KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name )
49 {
50 return new KAddressBookIconView( ab, parent, name );
51 }
52
53 QString type() const { return "Icon"; }
54
55 QString description() const { return i18n( "Icons represent contacts. Very simple view." ); }
56};
57
58*/
59
60extern "C" {
61 void *init_libkaddrbk_iconview()
62 {
63 return ( new IconViewFactory );
64 }
65}
66
67////////////////////////////////
68// AddresseeIconView (internal class)
69#ifndef KAB_EMBEDDED
70AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name)
71 : KIconView(parent, name)
72#else //KAB_EMBEDDED
73AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name)
74 : QIconView(parent, name)
75#endif //KAB_EMBEDDED
76
77{
78 setSelectionMode( QIconView::Extended );
79 setResizeMode( QIconView::Adjust );
80 setWordWrapIconText( true );
81 setGridX( 100 );
82 setItemsMovable(false);
83 setSorting(true, true);
84
85
86//US ??? setMode( KIconView::Select );
87
88#ifndef KAB_EMBEDDED
89
90 connect(this, SIGNAL(dropped(QDropEvent*, const QValueList<QIconDragItem>&)),
91 this, SLOT(itemDropped(QDropEvent*, const QValueList<QIconDragItem>&)));
92#endif //KAB_EMBEDDED
93}
94
95AddresseeIconView::~AddresseeIconView()
96{
97}
98
99void AddresseeIconView::itemDropped(QDropEvent *e,
100 const QValueList<QIconDragItem> &)
101{
102 emit addresseeDropped(e);
103}
104
105QDragObject *AddresseeIconView::dragObject()
106{
107 emit startAddresseeDrag();
108
109 // We never want IconView to start the drag
110 return 0;
111}
112////////////////////////////////
113// AddresseeIconViewItem (internal class)
114#ifndef KAB_EMBEDDED
115class AddresseeIconViewItem : public KIconViewItem
116#else //KAB_EMBEDDED
117class AddresseeIconViewItem : public QIconViewItem
118#endif //KAB_EMBEDDED
119{
120 public:
121#ifndef KAB_EMBEDDED
122 AddresseeIconViewItem(const KABC::Field::List &fields,
123 KABC::AddressBook *doc, const KABC::Addressee &a,
124 QIconView *parent)
125 : KIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a)
126#else //KAB_EMBEDDED
127 AddresseeIconViewItem(const KABC::Field::List &fields,
128 KABC::AddressBook *doc, const KABC::Addressee &a,
129 QIconView *parent)
130 : QIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a)
131#endif //KAB_EMBEDDED
132 {
133 if ( mFields.isEmpty() ) {
134 mFields = KABC::Field::defaultFields();
135 }
136 refresh();
137 }
138
139 const KABC::Addressee &addressee() const { return mAddressee; }
140
141 void refresh()
142 {
143 // Update our addressee, since it may have changed elsewhere
144 mAddressee = mDocument->findByUid(mAddressee.uid());
145
146 if (!mAddressee.isEmpty())
147 setText( mAddressee.givenName() + " " + mAddressee.familyName() );
148
149 QPixmap icon;
150 QPixmap defaultIcon( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop, 128 ) );
151 KABC::Picture pic = mAddressee.photo();
152 if ( pic.data().isNull() )
153 pic = mAddressee.logo();
154
155 if ( pic.isIntern() && !pic.data().isNull() ) {
156 QImage img = pic.data();
157#ifndef KAB_EMBEDDED
158 if ( img.width() > img.height() )
159 icon = img.scaleWidth( 32 );
160 else
161 icon = img.scaleHeight( 32 );
162#else //KAB_EMBEDDED
163 qDebug("AddresseeIconViewItem::refresh - scale here dependend of the displaysize and the right factor");
164 icon.convertFromImage(img.smoothScale(32, 32));
165#endif //KAB_EMBEDDED
166
167 } else
168 icon = defaultIcon;
169
170 setPixmap( icon );
171 }
172
173 private:
174 KABC::Field::List mFields;
175 KABC::AddressBook *mDocument;
176 KABC::Addressee mAddressee;
177};
178
179///////////////////////////////
180// KAddressBookView
181
182KAddressBookIconView::KAddressBookIconView( KABC::AddressBook *ab,
183 QWidget *parent, const char *name)
184 : KAddressBookView( ab, parent, name )
185{
186 // Init the GUI
187 QVBoxLayout *layout = new QVBoxLayout(viewWidget());
188
189 mIconView = new AddresseeIconView(viewWidget(), "mIconView");
190 layout->addWidget(mIconView);
191
192 // Connect up the signals
193
194//US method executed is part of KIconView
195//US connect(mIconView, SIGNAL(executed(QIconViewItem *)),
196//US this, SLOT(addresseeExecuted(QIconViewItem *)));
197 connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)),
198 this, SLOT(addresseeExecuted(QIconViewItem *)));
199
200 connect(mIconView, SIGNAL(selectionChanged()),
201 this, SLOT(addresseeSelected()));
202 connect(mIconView, SIGNAL(addresseeDropped(QDropEvent*)),
203 this, SIGNAL(dropped(QDropEvent*)));
204 connect(mIconView, SIGNAL(startAddresseeDrag()),
205 this, SIGNAL(startDrag()));
206}
207
208KAddressBookIconView::~KAddressBookIconView()
209{
210}
211
212void KAddressBookIconView::readConfig(KConfig *config)
213{
214 KAddressBookView::readConfig(config);
215
216//US method executed is part of KIconView
217//US disconnect(mIconView, SIGNAL(executed(QIconViewItem *)),
218//US this, SLOT(addresseeExecuted(QIconViewItem *)));
219 disconnect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)),
220 this, SLOT(addresseeExecuted(QIconViewItem *)));
221
222//US method executed is part of KIconView. Use selectionChanged instead
223/*US
224 if (KABPrefs::instance()->mHonorSingleClick)
225 connect(mIconView, SIGNAL(executed(QIconViewItem *)),
226 this, SLOT(addresseeExecuted(QIconViewItem *)));
227 else
228 connect(mIconView, SIGNAL(doubleClicked(QIconViewItem *)),
229 this, SLOT(addresseeExecuted(QIconViewItem *)));
230*/
231 connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)),
232 this, SLOT(addresseeExecuted(QIconViewItem *)));
233
234}
235
236QStringList KAddressBookIconView::selectedUids()
237{
238 QStringList uidList;
239 QIconViewItem *item;
240 AddresseeIconViewItem *aItem;
241
242 for (item = mIconView->firstItem(); item; item = item->nextItem())
243 {
244 if (item->isSelected())
245 {
246#ifndef KAB_EMBEDDED
247 aItem = dynamic_cast<AddresseeIconViewItem*>(item);
248#else //KAB_EMBEDDED
249 aItem = (AddresseeIconViewItem*)(item);
250#endif //KAB_EMBEDDED
251 if (aItem)
252 uidList << aItem->addressee().uid();
253 }
254 }
255
256 return uidList;
257}
258
259void KAddressBookIconView::refresh(QString uid)
260{
261 QIconViewItem *item;
262 AddresseeIconViewItem *aItem;
263
264 if ( uid.isNull() ) {
265 // Rebuild the view
266 mIconView->clear();
267 mIconList.clear();
268
269 KABC::Addressee::List addresseeList = addressees();
270 KABC::Addressee::List::Iterator iter;
271 for ( iter = addresseeList.begin(); iter != addresseeList.end(); ++iter )
272 aItem = new AddresseeIconViewItem( fields(), addressBook(), *iter, mIconView );
273
274 mIconView->arrangeItemsInGrid( true );
275
276 for ( item = mIconView->firstItem(); item; item = item->nextItem() )
277 {
278#ifndef KAB_EMBEDDED
279 AddresseeIconViewItem* aivi = dynamic_cast<AddresseeIconViewItem*>( item );
280#else //KAB_EMBEDDED
281 AddresseeIconViewItem* aivi = (AddresseeIconViewItem*)( item );
282#endif //KAB_EMBEDDED
283 mIconList.append( aivi );
284 }
285
286 } else {
287 // Try to find the one to refresh
288 for ( item = mIconView->firstItem(); item; item = item->nextItem() ) {
289#ifndef KAB_EMBEDDED
290 aItem = dynamic_cast<AddresseeIconViewItem*>(item);
291#else //KAB_EMBEDDED
292 aItem = (AddresseeIconViewItem*)(item);
293#endif //KAB_EMBEDDED
294 if ((aItem) && (aItem->addressee().uid() == uid)) {
295 aItem->refresh();
296 mIconView->arrangeItemsInGrid( true );
297 return;
298 }
299 }
300 refresh( QString::null );
301 }
302}
303
304void KAddressBookIconView::setSelected(QString uid, bool selected)
305{
306 QIconViewItem *item;
307 AddresseeIconViewItem *aItem;
308
309 if (uid.isNull())
310 {
311 mIconView->selectAll(selected);
312 }
313 else
314 {
315 bool found = false;
316 for (item = mIconView->firstItem(); item && !found;
317 item = item->nextItem())
318 {
319#ifndef KAB_EMBEDDED
320 aItem = dynamic_cast<AddresseeIconViewItem*>(item);
321#else //KAB_EMBEDDED
322 aItem = (AddresseeIconViewItem*)(item);
323#endif //KAB_EMBEDDED
324
325 if ((aItem) && (aItem->addressee().uid() == uid))
326 {
327 mIconView->setSelected(aItem, selected);
328 mIconView->ensureItemVisible( aItem );
329 found = true;
330 }
331 }
332 }
333}
334
335void KAddressBookIconView::addresseeExecuted(QIconViewItem *item)
336{
337#ifndef KAB_EMBEDDED
338 AddresseeIconViewItem *aItem = dynamic_cast<AddresseeIconViewItem*>(item);
339#else //KAB_EMBEDDED
340 AddresseeIconViewItem *aItem = (AddresseeIconViewItem*)(item);
341#endif //KAB_EMBEDDED
342
343 if (aItem) {
344 emit executed(aItem->addressee().uid());
345 }
346}
347
348void KAddressBookIconView::addresseeSelected()
349{
350 QIconViewItem *item;
351 AddresseeIconViewItem *aItem;
352
353 bool found = false;
354 for (item = mIconView->firstItem(); item && !found;
355 item = item->nextItem())
356 {
357 if (item->isSelected())
358 {
359#ifndef KAB_EMBEDDED
360 aItem = dynamic_cast<AddresseeIconViewItem*>(item);
361#else //KAB_EMBEDDED
362 aItem = (AddresseeIconViewItem*)(item);
363#endif //KAB_EMBEDDED
364 if (aItem)
365 {
366 emit selected(aItem->addressee().uid());
367 found = true;
368 }
369 }
370 }
371
372 if (!found)
373 emit selected(QString::null);
374}
375
376#ifndef KAB_EMBEDDED
377#include "kaddressbookiconview.moc"
378#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/kaddressbookiconview.h b/kaddressbook/views/kaddressbookiconview.h
new file mode 100644
index 0000000..3afada3
--- a/dev/null
+++ b/kaddressbook/views/kaddressbookiconview.h
@@ -0,0 +1,130 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
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#ifndef KADDRESSBOOKICONVIEW_H
25#define KADDRESSBOOKICONVIEW_H
26
27#include <qstring.h>
28#ifndef KAB_EMBEDDED
29#include <kiconview.h>
30#else //KAB_EMBEDDED
31#include <qiconview.h>
32#include <qptrlist.h>
33#include <klocale.h>
34#endif //KAB_EMBEDDED
35#include "kaddressbookview.h"
36
37class QIconViewItem;
38class KConfig;
39class AddresseeIconView;
40class AddresseeIconViewItem;
41class QIconDragItem;
42class KAddressBookIconView;
43
44namespace KABC { class AddressBook; }
45
46/** This is an example kaddressbook view that is implemented using
47* KIconView. This view is not the most useful view, but it displays
48* how simple implementing a new view can be.
49*/
50class KAddressBookIconView : public KAddressBookView
51{
52 Q_OBJECT
53
54 public:
55 KAddressBookIconView( KABC::AddressBook *ab, QWidget *parent,
56 const char *name = 0 );
57 virtual ~KAddressBookIconView();
58
59 virtual QStringList selectedUids();
60 virtual QString type() const { return "Icon"; }
61
62 virtual void readConfig(KConfig *config);
63
64 public slots:
65 void refresh(QString uid = QString::null);
66#ifndef KAB_EMBEDDED
67//MOC_SKIP_BEGIN
68 void setSelected(QString uid = QString::null, bool selected = true);
69//MOC_SKIP_END
70#else //KAB_EMBEDDED
71//US my MOC do not like default parameters ???
72 void setSelected(QString uid, bool selected);
73#endif //KAB_EMBEDDED
74
75 protected slots:
76 void addresseeExecuted(QIconViewItem *item);
77 void addresseeSelected();
78
79 private:
80 AddresseeIconView *mIconView;
81 QPtrList<AddresseeIconViewItem> mIconList;
82};
83
84
85#ifndef KAB_EMBEDDED
86//MOC_SKIP_BEGIN
87class AddresseeIconView : public KIconView
88//MOC_SKIP_END
89#else //KAB_EMBEDDED
90class AddresseeIconView : public QIconView
91#endif //KAB_EMBEDDED
92{
93 Q_OBJECT
94
95 public:
96 AddresseeIconView(QWidget *parent, const char *name);
97 ~AddresseeIconView();
98
99 signals:
100 void addresseeDropped(QDropEvent *);
101 void startAddresseeDrag();
102
103 protected:
104 virtual QDragObject *dragObject();
105
106 protected slots:
107 void itemDropped(QDropEvent *, const QValueList<QIconDragItem> &);
108};
109
110class IconViewFactory : public ViewFactory
111{
112 public:
113 KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name )
114 {
115 return new KAddressBookIconView( ab, parent, name );
116 }
117
118 QString type() const { return "Icon"; }
119
120 QString description() const { return i18n( "Icons represent contacts. Very simple view." ); }
121};
122/*
123extern "C" {
124 void *init_libkaddrbk_iconview()
125 {
126 return ( new IconViewFactory );
127 }
128}
129*/
130#endif
diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp
new file mode 100644
index 0000000..ee2fcf8
--- a/dev/null
+++ b/kaddressbook/views/kaddressbooktableview.cpp
@@ -0,0 +1,337 @@
1// $Id$
2
3#include <qvbox.h>
4#include <qlistbox.h>
5#include <qwidget.h>
6#include <qfile.h>
7#include <qimage.h>
8#include <qcombobox.h>
9#include <qapplication.h>
10#include <qdragobject.h>
11#include <qevent.h>
12#include <qurl.h>
13#include <qpixmap.h>
14
15#include <kabc/addressbook.h>
16#include <kapplication.h>
17#include <kconfig.h>
18#include <kcolorbutton.h>
19#include <kdebug.h>
20#include <kglobal.h>
21#include <kiconloader.h>
22#include <klineedit.h>
23#include <klocale.h>
24#include <kmessagebox.h>
25#include <kurl.h>
26#include <kurlrequester.h>
27
28//US#include "configuretableviewdialog.h"
29#include "contactlistview.h"
30#include "kabprefs.h"
31#include "undocmds.h"
32#include "viewmanager.h"
33
34#include <qlayout.h>
35
36
37#include "kaddressbooktableview.h"
38
39
40KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab,
41 QWidget *parent, const char *name )
42 : KAddressBookView( ab, parent, name )
43{
44 mainLayout = new QVBoxLayout( viewWidget(), 2 );
45
46 // The list view will be created when the config is read.
47 mListView = 0;
48}
49
50KAddressBookTableView::~KAddressBookTableView()
51{
52}
53
54void KAddressBookTableView::reconstructListView()
55{
56 if (mListView)
57 {
58 disconnect(mListView, SIGNAL(selectionChanged()),
59 this, SLOT(addresseeSelected()));
60 disconnect(mListView, SIGNAL(executed(QListViewItem*)),
61 this, SLOT(addresseeExecuted(QListViewItem*)));
62 disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)),
63 this, SLOT(addresseeExecuted(QListViewItem*)));
64 disconnect(mListView, SIGNAL(startAddresseeDrag()), this,
65 SIGNAL(startDrag()));
66 disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)),
67 this, SLOT(addresseeExecuted(QListViewItem*)));
68
69 disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this,
70 SIGNAL(dropped(QDropEvent*)));
71 delete mListView;
72 }
73
74 mListView = new ContactListView( this, addressBook(), viewWidget() );
75
76 // Add the columns
77 KABC::Field::List fieldList = fields();
78 KABC::Field::List::ConstIterator it;
79
80 int c = 0;
81 for( it = fieldList.begin(); it != fieldList.end(); ++it ) {
82 mListView->addColumn( (*it)->label() );
83 mListView->setColumnWidthMode(c++, QListView::Manual);
84//US
85 // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1());
86 }
87
88 connect(mListView, SIGNAL(selectionChanged()),
89 this, SLOT(addresseeSelected()));
90 connect(mListView, SIGNAL(startAddresseeDrag()), this,
91 SIGNAL(startDrag()));
92 connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this,
93 SIGNAL(dropped(QDropEvent*)));
94
95 if (KABPrefs::instance()->mHonorSingleClick)
96 connect(mListView, SIGNAL(executed(QListViewItem*)),
97 this, SLOT(addresseeExecuted(QListViewItem*)));
98 else
99 connect(mListView, SIGNAL(doubleClicked(QListViewItem*)),
100 this, SLOT(addresseeExecuted(QListViewItem*)));
101 connect(mListView, SIGNAL(returnPressed(QListViewItem*)),
102 this, SLOT(addresseeExecuted(QListViewItem*)));
103 connect(mListView, SIGNAL(signalDelete()),
104 this, SLOT(addresseeDeleted()));
105
106 refresh();
107
108 mListView->setSorting( 0, true );
109 mainLayout->addWidget( mListView );
110 mainLayout->activate();
111 mListView->show();
112}
113
114void KAddressBookTableView::writeConfig(KConfig *config)
115{
116 KAddressBookView::writeConfig(config);
117
118 mListView->saveLayout(config, config->group());
119}
120
121void KAddressBookTableView::readConfig(KConfig *config)
122{
123 KAddressBookView::readConfig( config );
124
125 // The config could have changed the fields, so we need to reconstruct
126 // the listview.
127 reconstructListView();
128
129 // Set the list view options
130 mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground",
131 true));
132 mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false));
133 mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true));
134
135 if (config->readBoolEntry("Background", false))
136 mListView->setBackgroundPixmap(config->readEntry("BackgroundName"));
137
138 // Restore the layout of the listview
139 mListView->restoreLayout(config, config->group());
140}
141
142void KAddressBookTableView::refresh(QString uid)
143{
144 // For now just repopulate. In reality this method should
145 // check the value of uid, and if valid iterate through
146 // the listview to find the entry, then tell it to refresh.
147
148 if (uid.isNull()) {
149 // Clear the list view
150 QString currentUID, nextUID;
151#ifndef KAB_EMBEDDED
152 ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() );
153#else //KAB_EMBEDDED
154 ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() );
155#endif //KAB_EMBEDDED
156
157 if ( currentItem ) {
158#ifndef KAB_EMBEDDED
159 ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() );
160#else //KAB_EMBEDDED
161 ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() );
162#endif //KAB_EMBEDDED
163 if ( nextItem )
164 nextUID = nextItem->addressee().uid();
165 currentUID = currentItem->addressee().uid();
166 }
167
168 mListView->clear();
169
170 currentItem = 0;
171 KABC::Addressee::List addresseeList = addressees();
172 KABC::Addressee::List::Iterator it;
173 for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) {
174 ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields());
175 if ( (*it).uid() == currentUID )
176 currentItem = item;
177 else if ( (*it).uid() == nextUID && !currentItem )
178 currentItem = item;
179 }
180
181 // Sometimes the background pixmap gets messed up when we add lots
182 // of items.
183 mListView->repaint();
184
185 if ( currentItem ) {
186 mListView->setCurrentItem( currentItem );
187 mListView->ensureItemVisible( currentItem );
188 }
189 } else {
190 // Only need to update on entry. Iterate through and try to find it
191 ContactListViewItem *ceItem;
192 QListViewItemIterator it( mListView );
193 while ( it.current() ) {
194#ifndef KAB_EMBEDDED
195 ceItem = dynamic_cast<ContactListViewItem*>( it.current() );
196#else //KAB_EMBEDDED
197 ceItem = (ContactListViewItem*)( it.current() );
198#endif //KAB_EMBEDDED
199
200 if ( ceItem && ceItem->addressee().uid() == uid ) {
201 ceItem->refresh();
202 return;
203 }
204 ++it;
205 }
206
207 refresh( QString::null );
208 }
209}
210
211QStringList KAddressBookTableView::selectedUids()
212{
213 QStringList uidList;
214 QListViewItem *item;
215 ContactListViewItem *ceItem;
216
217 for(item = mListView->firstChild(); item; item = item->itemBelow())
218 {
219 if (mListView->isSelected( item ))
220 {
221#ifndef KAB_EMBEDDED
222 ceItem = dynamic_cast<ContactListViewItem*>(item);
223#else //KAB_EMBEDDED
224 ceItem = (ContactListViewItem*)(item);
225#endif //KAB_EMBEDDED
226
227 if (ceItem != 0L)
228 uidList << ceItem->addressee().uid();
229 }
230 }
231 if ( uidList.count() == 0 )
232 if ( mListView->currentItem() ) {
233 ceItem = (ContactListViewItem*)(mListView->currentItem()) ;
234 uidList << ceItem->addressee().uid();
235 }
236
237 return uidList;
238}
239
240void KAddressBookTableView::setSelected(QString uid, bool selected)
241{
242 QListViewItem *item;
243 ContactListViewItem *ceItem;
244
245 if (uid.isNull())
246 {
247 mListView->selectAll(selected);
248 }
249 else
250 {
251 for(item = mListView->firstChild(); item; item = item->itemBelow())
252 {
253#ifndef KAB_EMBEDDED
254 ceItem = dynamic_cast<ContactListViewItem*>(item);
255#else //KAB_EMBEDDED
256 ceItem = (ContactListViewItem*)(item);
257#endif //KAB_EMBEDDED
258
259
260 if ((ceItem != 0L) && (ceItem->addressee().uid() == uid))
261 {
262 mListView->setSelected(item, selected);
263
264 if (selected)
265 mListView->ensureItemVisible(item);
266 }
267 }
268 }
269}
270
271void KAddressBookTableView::addresseeSelected()
272{
273 // We need to try to find the first selected item. This might not be the
274 // last selected item, but when QListView is in multiselection mode,
275 // there is no way to figure out which one was
276 // selected last.
277 QListViewItem *item;
278 bool found =false;
279 for (item = mListView->firstChild(); item && !found;
280 item = item->nextSibling())
281 {
282 if (item->isSelected())
283 {
284 found = true;
285#ifndef KAB_EMBEDDED
286 ContactListViewItem *ceItem
287 = dynamic_cast<ContactListViewItem*>(item);
288#else //KAB_EMBEDDED
289 ContactListViewItem *ceItem
290 = (ContactListViewItem*)(item);
291#endif //KAB_EMBEDDED
292
293 if ( ceItem ) emit selected(ceItem->addressee().uid());
294 }
295 }
296
297 if (!found)
298 emit selected(QString::null);
299}
300
301void KAddressBookTableView::addresseeExecuted(QListViewItem *item)
302{
303 if (item)
304 {
305#ifndef KAB_EMBEDDED
306 ContactListViewItem *ceItem
307 = dynamic_cast<ContactListViewItem*>(item);
308#else //KAB_EMBEDDED
309 ContactListViewItem *ceItem
310 = (ContactListViewItem*)(item);
311#endif //KAB_EMBEDDED
312
313 if (ceItem)
314 {
315 emit executed(ceItem->addressee().uid());
316 }
317 }
318 else
319 {
320 emit executed(QString::null);
321 }
322}
323
324void KAddressBookTableView::addresseeDeleted()
325{
326
327 emit deleteRequest();
328
329}
330
331
332
333
334
335#ifndef KAB_EMBEDDED
336#include "kaddressbooktableview.moc"
337#endif //KAB_EMBEDDED
diff --git a/kaddressbook/views/kaddressbooktableview.h b/kaddressbook/views/kaddressbooktableview.h
new file mode 100644
index 0000000..bb991bc
--- a/dev/null
+++ b/kaddressbook/views/kaddressbooktableview.h
@@ -0,0 +1,114 @@
1#ifndef KADDRESSBOOKTABLEVIEW_H
2#define KADDRESSBOOKTABLEVIEW_H
3
4
5#ifndef KAB_EMBEDDED
6
7
8#ifdef HAVE_CONFIG_H
9#include <config.h>
10#endif
11
12#include <qwidget.h>
13#include <qlistview.h>
14#include <qstring.h>
15#include <qdialog.h>
16#include <qtabdialog.h>
17#include <qstringlist.h>
18#include <qvaluelist.h>
19
20#include "undo.h"
21
22#else //KAB_EMBEDDED
23#include "views/configuretableviewdialog.h"
24#endif //KAB_EMBEDDED
25
26#include "klocale.h"
27#include "kaddressbookview.h"
28
29class QListViewItem;
30class QListBox;
31class QVBoxLayout;
32class KConfig;
33
34class ContactListViewItem;
35class ContactListView;
36
37
38namespace KABC { class AddressBook; }
39
40/**
41 * This class is the table view for kaddressbook. This view is a KListView
42 * with multiple columns for the selected fields.
43 *
44 * @short Table View
45 * @author Don Sanders <dsanders@kde.org>
46 * @version 0.1
47 */
48class KAddressBookTableView : public KAddressBookView
49{
50friend class ContactListView;
51
52 Q_OBJECT
53
54 public:
55 KAddressBookTableView( KABC::AddressBook *ab, QWidget *parent,
56 const char *name = 0 );
57 virtual ~KAddressBookTableView();
58
59 virtual void refresh(QString uid = QString::null);
60 virtual QStringList selectedUids();
61 virtual void setSelected(QString uid = QString::null, bool selected = false);
62 virtual void readConfig(KConfig *config);
63 virtual void writeConfig(KConfig *config);
64 virtual QString type() const { return "Table"; }
65
66 public slots:
67 virtual void reconstructListView();
68
69 protected slots:
70 /** Called whenever the user selects an addressee in the list view.
71 */
72 void addresseeSelected();
73 void addresseeDeleted();
74
75 /** Called whenever the user executes an addressee. In terms of the
76 * list view, this is probably a double click
77 */
78 void addresseeExecuted(QListViewItem*);
79
80 private:
81 QVBoxLayout *mainLayout;
82 ContactListView *mListView;
83};
84
85
86class TableViewFactory : public ViewFactory
87{
88 public:
89 KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name )
90 {
91 return new KAddressBookTableView( ab, parent, name );
92 }
93
94 QString type() const { return "Table"; }
95
96 QString description() const { return i18n( "A listing of contacts in a table. Each cell of "
97 "the table holds a field of the contact." ); }
98
99 ViewConfigureWidget *configureWidget( KABC::AddressBook *ab, QWidget *parent,
100 const char *name = 0 )
101 {
102 return new ConfigureTableViewWidget( ab, parent, name );
103 }
104};
105/*US
106extern "C" {
107 void *init_libkaddrbk_tableview()
108 {
109 return ( new TableViewFactory );
110 }
111}
112*/
113
114#endif
diff --git a/kaddressbook/xxport/csv_xxport.cpp b/kaddressbook/xxport/csv_xxport.cpp
new file mode 100644
index 0000000..ce35053
--- a/dev/null
+++ b/kaddressbook/xxport/csv_xxport.cpp
@@ -0,0 +1,187 @@
1/*
2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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/*
25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk
27
28$Id$
29*/
30
31#include <qfile.h>
32#include <qregexp.h>
33#include <qtextstream.h>
34
35#include <kfiledialog.h>
36#ifndef KAB_EMBEDDED
37#include <kio/netaccess.h>
38#endif //KAB_EMBEDDED
39
40#include <klocale.h>
41#include <kmessagebox.h>
42#include <ktempfile.h>
43#include <kurl.h>
44
45#include "csvimportdialog.h"
46
47#include "csv_xxport.h"
48
49
50#ifndef KAB_EMBEDDED
51
52class CSVXXPortFactory : public XXPortFactory
53{
54 public:
55 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
56 {
57 return new CSVXXPort( ab, parent, name );
58 }
59};
60
61
62extern "C"
63{
64 void *init_libkaddrbk_csv_xxport()
65 {
66 return ( new CSVXXPortFactory() );
67 }
68}
69#endif //KAB_EMBEDDED
70
71
72CSVXXPort::CSVXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
73 : XXPortObject( ab, parent, name )
74{
75 createImportAction( i18n( "Import CSV List..." ) );
76 createExportAction( i18n( "Export CSV List..." ) );
77}
78
79bool CSVXXPort::exportContacts( const KABC::AddresseeList &list, const QString& )
80{
81#ifndef KAB_EMBEDDED
82 KURL url = KFileDialog::getSaveURL( "addressbook.csv" );
83 if ( url.isEmpty() )
84 return true;
85
86 if ( !url.isLocalFile() ) {
87 KTempFile tmpFile;
88 if ( tmpFile.status() != 0 ) {
89 QString txt = i18n( "<qt>Unable to open file <b>%1</b>.%2.</qt>" );
90 KMessageBox::error( parentWidget(), txt.arg( url.url() )
91 .arg( strerror( tmpFile.status() ) ) );
92 return false;
93 }
94
95 doExport( tmpFile.file(), list );
96 tmpFile.close();
97
98 return KIO::NetAccess::upload( tmpFile.name(), url, parentWidget() );
99 } else {
100 QFile file( url.path() );
101 if ( !file.open( IO_WriteOnly ) ) {
102 QString txt = i18n( "<qt>Unable to open file <b>%1</b>.</qt>" );
103 KMessageBox::error( parentWidget(), txt.arg( url.path() ) );
104 return false;
105 }
106
107 doExport( &file, list );
108 file.close();
109
110 return true;
111 }
112
113#else //KAB_EMBEDDED
114
115 QString fileName = KFileDialog::getSaveFileName( "addressbook.csv", i18n("Save file"), parentWidget() );
116
117 if ( fileName.isEmpty() )
118 return true;
119
120 QFile file( fileName );
121 if ( !file.open( IO_WriteOnly ) ) {
122 QString txt = i18n( "<qt>Unable to open file <b>%1</b>.</qt>" );
123 KMessageBox::error( parentWidget(), txt.arg( fileName ) );
124 return false;
125 }
126
127 doExport( &file, list );
128 file.close();
129
130 return true;
131
132
133#endif //KAB_EMBEDDED
134
135}
136
137KABC::AddresseeList CSVXXPort::importContacts( const QString& ) const
138{
139 CSVImportDialog dlg( addressBook(), parentWidget() );
140 if ( dlg.exec() )
141 return dlg.contacts();
142 else
143 return KABC::AddresseeList();
144}
145
146void CSVXXPort::doExport( QFile *fp, const KABC::AddresseeList &list )
147{
148 QTextStream t( fp );
149
150 KABC::AddresseeList::ConstIterator iter;
151 KABC::Field::List fields = addressBook()->fields();
152 KABC::Field::List::Iterator fieldIter;
153 bool first = true;
154
155 // First output the column headings
156 for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) {
157 if ( !first )
158 t << ",";
159
160 t << "\"" << (*fieldIter)->label() << "\"";
161 first = false;
162 }
163 t << "\n";
164
165 // Then all the addressee objects
166 KABC::Addressee addr;
167 for ( iter = list.begin(); iter != list.end(); ++iter ) {
168 addr = *iter;
169 first = true;
170
171 for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) {
172 if ( !first )
173 t << ",";
174
175 t << "\"" << (*fieldIter)->value( addr ).replace( QRegExp("\n"), "\\n" ) << "\"";
176 first = false;
177 }
178
179 t << "\n";
180 }
181}
182
183#ifndef KAB_EMBEDDED
184#include "csv_xxport.moc"
185#endif //KAB_EMBEDDED
186
187
diff --git a/kaddressbook/xxport/csv_xxport.h b/kaddressbook/xxport/csv_xxport.h
new file mode 100644
index 0000000..fe6b3c6
--- a/dev/null
+++ b/kaddressbook/xxport/csv_xxport.h
@@ -0,0 +1,68 @@
1/*
2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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/*
25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk
27
28$Id$
29*/
30
31#ifndef CSV_XXPORT_H
32#define CSV_XXPORT_H
33
34#include <xxportobject.h>
35
36class QFile;
37
38
39class CSVXXPort : public XXPortObject
40{
41 Q_OBJECT
42
43 public:
44 CSVXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
45
46 QString identifier() const { return "csv"; }
47
48 public slots:
49 bool exportContacts( const KABC::AddresseeList &list, const QString &data );
50 KABC::AddresseeList importContacts( const QString &data ) const;
51
52 private:
53 void doExport( QFile *fp, const KABC::AddresseeList &list );
54};
55
56#ifdef KAB_EMBEDDED
57class CSVXXPortFactory : public XXPortFactory
58{
59 public:
60 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
61 {
62 return new CSVXXPort( ab, parent, name );
63 }
64};
65#endif //KAB_EMBEDDED
66
67
68#endif
diff --git a/kaddressbook/xxport/csvimportdialog.cpp b/kaddressbook/xxport/csvimportdialog.cpp
new file mode 100644
index 0000000..1093f9c
--- a/dev/null
+++ b/kaddressbook/xxport/csvimportdialog.cpp
@@ -0,0 +1,922 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (C) 2003 Tobias Koenig <tokoe@kde.org>
4 based on the code of KSpread's CSV Import Dialog
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library 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 GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20*/
21
22/*
23Enhanced Version of the file for platform independent KDE tools.
24Copyright (c) 2004 Ulf Schenk
25
26$Id$
27*/
28
29
30#include <qbuttongroup.h>
31#include <qcheckbox.h>
32#include <qcombobox.h>
33#include <qinputdialog.h>
34#include <qlabel.h>
35#include <qlineedit.h>
36#include <qpushbutton.h>
37#include <qradiobutton.h>
38#include <qtable.h>
39#include <qlayout.h>
40#include <qtextstream.h>
41#include <qfile.h>
42
43#include <kapplication.h>
44#include <kdebug.h>
45#include <kdialogbase.h>
46#include <kfiledialog.h>
47#include <klineedit.h>
48#include <klocale.h>
49#include <kglobal.h>
50#include <kmessagebox.h>
51#include <kstandarddirs.h>
52#include <kurlrequester.h>
53
54#ifdef DESKTOP_VERSION
55#include "qtable.h"
56#else
57#include "qcombotableitem.h"
58#endif
59#include "csvimportdialog.h"
60
61CSVImportDialog::CSVImportDialog( KABC::AddressBook *ab, QWidget *parent,
62 const char * name )
63 : KDialogBase( Plain, i18n ( "CSV Import Dialog" ), Ok | Cancel | User1 |
64 User2, Ok, parent, name, true, true ),
65 mAdjustRows( false ),
66 mStartLine( 0 ),
67 mTextQuote( '"' ),
68 mDelimiter( "," ),
69 mAddressBook( ab )
70{
71 initGUI();
72
73 mTypeMap.insert( i18n( "Undefined" ), Undefined );
74 mTypeMap.insert( KABC::Addressee::formattedNameLabel(), FormattedName );
75 mTypeMap.insert( KABC::Addressee::familyNameLabel(), FamilyName );
76 mTypeMap.insert( KABC::Addressee::givenNameLabel(), GivenName );
77 mTypeMap.insert( KABC::Addressee::additionalNameLabel(), AdditionalName );
78 mTypeMap.insert( KABC::Addressee::prefixLabel(), Prefix );
79 mTypeMap.insert( KABC::Addressee::suffixLabel(), Suffix );
80 mTypeMap.insert( KABC::Addressee::nickNameLabel(), NickName );
81 mTypeMap.insert( KABC::Addressee::birthdayLabel(), Birthday );
82
83 mTypeMap.insert( KABC::Addressee::homeAddressStreetLabel(), HomeAddressStreet );
84 mTypeMap.insert( KABC::Addressee::homeAddressLocalityLabel(),
85 HomeAddressLocality );
86 mTypeMap.insert( KABC::Addressee::homeAddressRegionLabel(), HomeAddressRegion );
87 mTypeMap.insert( KABC::Addressee::homeAddressPostalCodeLabel(),
88 HomeAddressPostalCode );
89 mTypeMap.insert( KABC::Addressee::homeAddressCountryLabel(),
90 HomeAddressCountry );
91 mTypeMap.insert( KABC::Addressee::homeAddressLabelLabel(), HomeAddressLabel );
92
93 mTypeMap.insert( KABC::Addressee::businessAddressStreetLabel(),
94 BusinessAddressStreet );
95 mTypeMap.insert( KABC::Addressee::businessAddressLocalityLabel(),
96 BusinessAddressLocality );
97 mTypeMap.insert( KABC::Addressee::businessAddressRegionLabel(),
98 BusinessAddressRegion );
99 mTypeMap.insert( KABC::Addressee::businessAddressPostalCodeLabel(),
100 BusinessAddressPostalCode );
101 mTypeMap.insert( KABC::Addressee::businessAddressCountryLabel(),
102 BusinessAddressCountry );
103 mTypeMap.insert( KABC::Addressee::businessAddressLabelLabel(),
104 BusinessAddressLabel );
105
106 mTypeMap.insert( KABC::Addressee::homePhoneLabel(), HomePhone );
107 mTypeMap.insert( KABC::Addressee::businessPhoneLabel(), BusinessPhone );
108 mTypeMap.insert( KABC::Addressee::mobilePhoneLabel(), MobilePhone );
109 mTypeMap.insert( KABC::Addressee::homeFaxLabel(), HomeFax );
110 mTypeMap.insert( KABC::Addressee::businessFaxLabel(), BusinessFax );
111 mTypeMap.insert( KABC::Addressee::carPhoneLabel(), CarPhone );
112 mTypeMap.insert( KABC::Addressee::isdnLabel(), Isdn );
113 mTypeMap.insert( KABC::Addressee::pagerLabel(), Pager );
114 mTypeMap.insert( KABC::Addressee::emailLabel(), Email );
115 mTypeMap.insert( KABC::Addressee::mailerLabel(), Mailer );
116 mTypeMap.insert( KABC::Addressee::titleLabel(), Title );
117 mTypeMap.insert( KABC::Addressee::roleLabel(), Role );
118 mTypeMap.insert( KABC::Addressee::organizationLabel(), Organization );
119 mTypeMap.insert( KABC::Addressee::noteLabel(), Note );
120 mTypeMap.insert( KABC::Addressee::urlLabel(), URL );
121
122 mCustomCounter = mTypeMap.count();
123 int count = mCustomCounter;
124
125 KABC::Field::List fields = mAddressBook->fields( KABC::Field::CustomCategory );
126 KABC::Field::List::Iterator it;
127 for ( it = fields.begin(); it != fields.end(); ++it, ++count )
128 mTypeMap.insert( (*it)->label(), count );
129
130 connect( mDelimiterBox, SIGNAL( clicked( int ) ),
131 this, SLOT( delimiterClicked( int ) ) );
132 connect( mDelimiterEdit, SIGNAL( returnPressed() ),
133 this, SLOT( returnPressed() ) );
134 connect( mDelimiterEdit, SIGNAL( textChanged ( const QString& ) ),
135 this, SLOT( textChanged ( const QString& ) ) );
136 connect( mComboLine, SIGNAL( activated( const QString& ) ),
137 this, SLOT( lineSelected( const QString& ) ) );
138 connect( mComboQuote, SIGNAL( activated( const QString& ) ),
139 this, SLOT( textquoteSelected( const QString& ) ) );
140 connect( mIgnoreDuplicates, SIGNAL( stateChanged( int ) ),
141 this, SLOT( ignoreDuplicatesChanged( int ) ) );
142
143 connect( mUrlRequester, SIGNAL( returnPressed( const QString& ) ),
144 this, SLOT( setFile( const QString& ) ) );
145 connect( mUrlRequester, SIGNAL( urlSelected( const QString& ) ),
146 this, SLOT( setFile( const QString& ) ) );
147 connect( mUrlRequester->lineEdit(), SIGNAL( textChanged ( const QString& ) ),
148 this, SLOT( urlChanged( const QString& ) ) );
149
150 connect( this, SIGNAL( user1Clicked() ),
151 this, SLOT( applyTemplate() ) );
152
153 connect( this, SIGNAL( user2Clicked() ),
154 this, SLOT( saveTemplate() ) );
155
156 // if ( QApplication::desktop()->width() < 321 )
157 QIconSet icon = SmallIcon("filesave");
158
159 findButton( User2 )->setIconSet (icon ) ;
160 icon = SmallIcon("fileopen");
161 findButton( User1 )->setIconSet (icon ) ;
162 int wid = findButton( User2 )->sizeHint().height();
163 findButton( User2 )->setMaximumWidth( wid+4 );
164 findButton( User1 )->setMaximumWidth( wid+4 );
165}
166
167CSVImportDialog::~CSVImportDialog()
168{
169}
170
171KABC::AddresseeList CSVImportDialog::contacts() const
172{
173 KABC::AddresseeList contacts;
174
175 for ( int row = 1; row < mTable->numRows(); ++row ) {
176 KABC::Addressee a;
177 bool emptyRow = true;
178 KABC::Address addrHome( KABC::Address::Home );
179 KABC::Address addrWork( KABC::Address::Work );
180 for ( int col = 0; col < mTable->numCols(); ++col ) {
181
182 QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, col ) );
183
184 if ( !item ) {
185 qDebug( "ERROR: item cast failed" );
186 continue;
187 }
188
189 QString value = mTable->text( row, col );
190 if ( !value.isEmpty() )
191 emptyRow = false;
192
193 switch ( posToType( item->currentItem() ) )
194 {
195 case Undefined:
196 continue;
197 break;
198 case FormattedName:
199 a.setFormattedName( value );
200 break;
201 case GivenName:
202 a.setGivenName( value );
203 break;
204 case FamilyName:
205 a.setFamilyName( value );
206 break;
207 case AdditionalName:
208 a.setAdditionalName( value );
209 break;
210 case Prefix:
211 a.setPrefix( value );
212 break;
213 case Suffix:
214 a.setSuffix( value );
215 break;
216 case NickName:
217 a.setNickName( value );
218 break;
219 case Birthday:
220//US
221//the generated code had the following format: a.setBirthday( QDate::fromString( value, Qt::ISODate ) );
222// But Qt::IsoDate and QDate::fromString was not specified. Do I have the wrong QT version ?
223 {
224 QDate dt = KGlobal::locale()->readDate( value, "%Y-%m-%d"); // = Qt::ISODate
225 a.setBirthday(dt);
226 }
227 break;
228 case Email:
229 if ( !value.isEmpty() )
230 a.insertEmail( value, true );
231 break;
232 case Role:
233 a.setRole( value );
234 break;
235 case Title:
236 a.setTitle( value );
237 break;
238 case Mailer:
239 a.setMailer( value );
240 break;
241 case URL:
242 a.setUrl( value );
243 break;
244 case Organization:
245 a.setOrganization( value );
246 break;
247 case Note:
248 a.setNote( value );
249 break;
250
251 case HomePhone:
252 if ( !value.isEmpty() ) {
253 KABC::PhoneNumber number( value, KABC::PhoneNumber::Home );
254 a.insertPhoneNumber( number );
255 }
256 break;
257 case BusinessPhone:
258 if ( !value.isEmpty() ) {
259 KABC::PhoneNumber number( value, KABC::PhoneNumber::Work );
260 a.insertPhoneNumber( number );
261 }
262 break;
263 case MobilePhone:
264 if ( !value.isEmpty() ) {
265 KABC::PhoneNumber number( value, KABC::PhoneNumber::Cell );
266 a.insertPhoneNumber( number );
267 }
268 break;
269 case HomeFax:
270 if ( !value.isEmpty() ) {
271 KABC::PhoneNumber number( value, KABC::PhoneNumber::Home |
272 KABC::PhoneNumber::Fax );
273 a.insertPhoneNumber( number );
274 }
275 break;
276 case BusinessFax:
277 if ( !value.isEmpty() ) {
278 KABC::PhoneNumber number( value, KABC::PhoneNumber::Work |
279 KABC::PhoneNumber::Fax );
280 a.insertPhoneNumber( number );
281 }
282 break;
283 case CarPhone:
284 if ( !value.isEmpty() ) {
285 KABC::PhoneNumber number( value, KABC::PhoneNumber::Car );
286 a.insertPhoneNumber( number );
287 }
288 break;
289 case Isdn:
290 if ( !value.isEmpty() ) {
291 KABC::PhoneNumber number( value, KABC::PhoneNumber::Isdn );
292 a.insertPhoneNumber( number );
293 }
294 break;
295 case Pager:
296 if ( !value.isEmpty() ) {
297 KABC::PhoneNumber number( value, KABC::PhoneNumber::Pager );
298 a.insertPhoneNumber( number );
299 }
300 break;
301
302 case HomeAddressStreet:
303 addrHome.setStreet( value );
304 break;
305 case HomeAddressLocality:
306 addrHome.setLocality( value );
307 break;
308 case HomeAddressRegion:
309 addrHome.setRegion( value );
310 break;
311 case HomeAddressPostalCode:
312 addrHome.setPostalCode( value );
313 break;
314 case HomeAddressCountry:
315 addrHome.setCountry( value );
316 break;
317 case HomeAddressLabel:
318 addrHome.setLabel( value );
319 break;
320
321 case BusinessAddressStreet:
322 addrWork.setStreet( value );
323 break;
324 case BusinessAddressLocality:
325 addrWork.setLocality( value );
326 break;
327 case BusinessAddressRegion:
328 addrWork.setRegion( value );
329 break;
330 case BusinessAddressPostalCode:
331 addrWork.setPostalCode( value );
332 break;
333 case BusinessAddressCountry:
334 addrWork.setCountry( value );
335 break;
336 case BusinessAddressLabel:
337 addrWork.setLabel( value );
338 break;
339 default:
340 KABC::Field::List fields = mAddressBook->fields( KABC::Field::CustomCategory );
341 KABC::Field::List::Iterator it;
342
343 int counter = 0;
344 for ( it = fields.begin(); it != fields.end(); ++it ) {
345 if ( counter == (int)( posToType( item->currentItem() ) - mCustomCounter ) )
346 {
347 (*it)->setValue( a, value );
348 continue;
349 }
350 ++counter;
351 }
352 break;
353 }
354 }
355
356 if ( !addrHome.isEmpty() )
357 a.insertAddress( addrHome );
358 if ( !addrWork.isEmpty() )
359 a.insertAddress( addrWork );
360
361 if ( !emptyRow && !a.isEmpty() )
362 contacts.append( a );
363 }
364
365 return contacts;
366}
367
368void CSVImportDialog::initGUI()
369{
370 QWidget* page = plainPage();
371
372 QGridLayout *layout = new QGridLayout( page, 1, 1, marginHintSmall(),
373 spacingHintSmall() );
374 QHBoxLayout *hbox = new QHBoxLayout();
375 hbox->setSpacing( spacingHint() );
376
377 QLabel *label = new QLabel( i18n( "File to import:" ), page );
378 hbox->addWidget( label );
379
380 mUrlRequester = new KURLRequester( page );
381 mUrlRequester->setFilter( "*.csv" );
382 hbox->addWidget( mUrlRequester );
383
384 layout->addMultiCellLayout( hbox, 0, 0, 0, 1 );
385
386 // Delimiter: comma, semicolon, tab, space, other
387 mDelimiterBox = new QButtonGroup( i18n( "Delimiter" ), page );
388 mDelimiterBox->setColumnLayout( 0, Qt::Vertical );
389 mDelimiterBox->layout()->setSpacing( spacingHint() );
390 mDelimiterBox->layout()->setMargin( marginHint() );
391 QGridLayout *delimiterLayout = new QGridLayout( mDelimiterBox->layout() );
392 delimiterLayout->setAlignment( Qt::AlignTop );
393 layout->addMultiCellWidget( mDelimiterBox, 1, 1, 0, 1 );
394
395 mRadioComma = new QRadioButton( i18n( "Comma" ), mDelimiterBox );
396 mRadioComma->setChecked( true );
397 delimiterLayout->addWidget( mRadioComma, 0, 0 );
398
399 mRadioSemicolon = new QRadioButton( i18n( "Semicolon" ), mDelimiterBox );
400 delimiterLayout->addWidget( mRadioSemicolon, 0, 1 );
401
402 mRadioTab = new QRadioButton( i18n( "Tabulator" ), mDelimiterBox );
403 delimiterLayout->addWidget( mRadioTab, 1, 0 );
404
405 mRadioSpace = new QRadioButton( i18n( "Space" ), mDelimiterBox );
406 delimiterLayout->addWidget( mRadioSpace, 1, 1 );
407
408 mRadioOther = new QRadioButton( i18n( "Other" ), mDelimiterBox );
409 delimiterLayout->addWidget( mRadioOther, 0, 2 );
410
411 mDelimiterEdit = new QLineEdit( mDelimiterBox );
412 delimiterLayout->addWidget( mDelimiterEdit, 1, 2 );
413
414 mComboLine = new QComboBox( false, page );
415 mComboLine->insertItem( i18n( "1" ) );
416 layout->addWidget( mComboLine, 3, 1 );
417
418 mComboQuote = new QComboBox( false, page );
419 mComboQuote->insertItem( i18n( "\"" ), 0 );
420 mComboQuote->insertItem( i18n( "'" ), 1 );
421 mComboQuote->insertItem( i18n( "None" ), 2 );
422 layout->addWidget( mComboQuote, 3, 0 );
423
424 label = new QLabel( i18n( "Start at line:" ), page );
425 layout->addWidget( label, 2, 1 );
426
427 label = new QLabel( i18n( "Textquote:" ), page );
428 layout->addWidget( label, 2, 0 );
429
430 mIgnoreDuplicates = new QCheckBox( page );
431 mIgnoreDuplicates->setText( i18n( "Ignore duplicate delimiters" ) );
432 layout->addMultiCellWidget( mIgnoreDuplicates, 4, 4, 0, 1 );
433
434 mTable = new QTable( 0, 0, page );
435 mTable->setSelectionMode( QTable::NoSelection );
436 //mTable->horizontalHeader()->hide();
437 layout->addMultiCellWidget( mTable, 5, 5, 0, 1 );
438/*US
439 setButtonText( User1, i18n( "Apply Template" ) );
440 setButtonText( User2, i18n( "Save Template" ) );
441*/
442
443 enableButtonOK( false );
444
445 findButton( User1 )->setEnabled( false );
446 findButton( User2 )->setEnabled( false );
447
448#ifdef DESKTOP_VERSION
449 resize( 500, 300 );
450#else
451 showMaximized();
452#endif
453}
454
455void CSVImportDialog::fillTable()
456{
457 int row, column;
458 bool lastCharDelimiter = false;
459 bool ignoreDups = mIgnoreDuplicates->isChecked();
460 enum { S_START, S_QUOTED_FIELD, S_MAYBE_END_OF_QUOTED_FIELD, S_END_OF_QUOTED_FIELD,
461 S_MAYBE_NORMAL_FIELD, S_NORMAL_FIELD } state = S_START;
462
463 QChar x;
464 QString field = "";
465
466 // store previous assignment
467 QValueList<int> mTypeOld = mTypeStore;
468
469 mTypeStore.clear();
470 for ( column = 0; column < mTable->numCols(); ++column ) {
471 QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0, column ) );
472
473 if ( !item || mClearTypeStore )
474 mTypeStore.append( typeToPos( Undefined ) );
475 else if ( item )
476 mTypeStore.append( item->currentItem() );
477 }
478
479 clearTable();
480
481 row = column = 1;
482 mData = QString( mFileArray );
483
484 QTextStream inputStream( mData, IO_ReadOnly );
485 inputStream.setEncoding( QTextStream::Locale );
486
487 int maxColumn = 0;
488 while ( !inputStream.atEnd() ) {
489 inputStream >> x; // read one char
490
491 if ( x == '\r' ) inputStream >> x; // eat '\r', to handle DOS/LOSEDOWS files correctly
492
493 switch ( state ) {
494 case S_START :
495 if ( x == mTextQuote ) {
496 state = S_QUOTED_FIELD;
497 } else if ( x == mDelimiter ) {
498 if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) )
499 ++column;
500 lastCharDelimiter = true;
501 } else if ( x == '\n' ) {
502 ++row;
503 column = 1;
504 } else {
505 field += x;
506 state = S_MAYBE_NORMAL_FIELD;
507 }
508 break;
509 case S_QUOTED_FIELD :
510 if ( x == mTextQuote ) {
511 state = S_MAYBE_END_OF_QUOTED_FIELD;
512 } else if ( x == '\n' ) {
513 setText( row - mStartLine + 1, column, field );
514 field = "";
515 if ( x == '\n' ) {
516 ++row;
517 column = 1;
518 } else {
519 if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) )
520 ++column;
521 lastCharDelimiter = true;
522 }
523 state = S_START;
524 } else {
525 field += x;
526 }
527 break;
528 case S_MAYBE_END_OF_QUOTED_FIELD :
529 if ( x == mTextQuote ) {
530 field += x;
531 state = S_QUOTED_FIELD;
532 } else if ( x == mDelimiter || x == '\n' ) {
533 setText( row - mStartLine + 1, column, field );
534 field = "";
535 if ( x == '\n' ) {
536 ++row;
537 column = 1;
538 } else {
539 if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) )
540 ++column;
541 lastCharDelimiter = true;
542 }
543 state = S_START;
544 } else {
545 state = S_END_OF_QUOTED_FIELD;
546 }
547 break;
548 case S_END_OF_QUOTED_FIELD :
549 if ( x == mDelimiter || x == '\n' ) {
550 setText( row - mStartLine + 1, column, field );
551 field = "";
552 if ( x == '\n' ) {
553 ++row;
554 column = 1;
555 } else {
556 if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) )
557 ++column;
558 lastCharDelimiter = true;
559 }
560 state = S_START;
561 } else {
562 state = S_END_OF_QUOTED_FIELD;
563 }
564 break;
565 case S_MAYBE_NORMAL_FIELD :
566 if ( x == mTextQuote ) {
567 field = "";
568 state = S_QUOTED_FIELD;
569 break;
570 }
571 case S_NORMAL_FIELD :
572 if ( x == mDelimiter || x == '\n' ) {
573 setText( row - mStartLine + 1, column, field );
574 field = "";
575 if ( x == '\n' ) {
576 ++row;
577 column = 1;
578 } else {
579 if ( ( ignoreDups == false ) || ( lastCharDelimiter == false ) )
580 ++column;
581 lastCharDelimiter = true;
582 }
583 state = S_START;
584 } else {
585 field += x;
586 }
587 }
588 if ( x != mDelimiter )
589 lastCharDelimiter = false;
590
591 if ( column > maxColumn )
592 maxColumn = column;
593 }
594
595 // file with only one line without '\n'
596 if ( field.length() > 0 ) {
597 setText( row - mStartLine + 1, column, field );
598 ++row;
599 field = "";
600 }
601
602 adjustRows( row - mStartLine );
603 mTable->setNumCols( maxColumn );
604
605//US begin
606 QStringList keys;
607 QMap<QString, uint>::ConstIterator it;
608 for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it)
609 keys << it.key();
610//US end
611
612 for ( column = 0; column < mTable->numCols(); ++column ) {
613
614//US QComboTableItem *item = new QComboTableItem( mTable, mTypeMap.keys() );
615 QComboTableItem *item = new QComboTableItem( mTable, keys );
616 mTable->setItem( 0, column, item );
617 if ( column < mTypeStore.count() )
618 item->setCurrentItem( mTypeStore[ column ] );
619 else
620 item->setCurrentItem( typeToPos( Undefined ) );
621
622 mTable->adjustColumn( column );
623 }
624}
625
626void CSVImportDialog::clearTable()
627{
628 for ( int row = 0; row < mTable->numRows(); ++row )
629 for ( int column = 0; column < mTable->numCols(); ++column )
630 mTable->clearCell( row, column );
631}
632
633void CSVImportDialog::fillComboBox()
634{
635 mComboLine->clear();
636 for ( int row = 1; row < mTable->numRows() + 1; ++row )
637 mComboLine->insertItem( QString::number( row ), row - 1 );
638}
639
640void CSVImportDialog::setText( int row, int col, const QString& text )
641{
642 if ( row < 1 ) // skipped by the user
643 return;
644
645 if ( mTable->numRows() < row ) {
646 mTable->setNumRows( row + 5000 ); // We add 5000 at a time to limit recalculations
647 mAdjustRows = true;
648 }
649
650 if ( mTable->numCols() < col )
651 mTable->setNumCols( col + 50 ); // We add 50 at a time to limit recalculation
652
653 mTable->setText( row - 1, col - 1, text );
654}
655
656/*
657 * Called after the first fillTable() when number of rows are unknown.
658 */
659void CSVImportDialog::adjustRows( int rows )
660{
661 if ( mAdjustRows ) {
662 mTable->setNumRows( rows );
663 mAdjustRows = false;
664 }
665}
666
667void CSVImportDialog::returnPressed()
668{
669 if ( mDelimiterBox->id( mDelimiterBox->selected() ) != 4 )
670 return;
671
672 mDelimiter = mDelimiterEdit->text();
673 fillTable();
674}
675
676void CSVImportDialog::textChanged ( const QString& )
677{
678 mRadioOther->setChecked ( true );
679 delimiterClicked( 4 ); // other
680}
681
682void CSVImportDialog::delimiterClicked( int id )
683{
684 switch ( id ) {
685 case 0: // comma
686 mDelimiter = ",";
687 break;
688 case 4: // other
689 mDelimiter = mDelimiterEdit->text();
690 break;
691 case 2: // tab
692 mDelimiter = "\t";
693 break;
694 case 3: // space
695 mDelimiter = " ";
696 break;
697 case 1: // semicolon
698 mDelimiter = ";";
699 break;
700 }
701
702 fillTable();
703}
704
705void CSVImportDialog::textquoteSelected( const QString& mark )
706{
707 if ( mComboQuote->currentItem() == 2 )
708 mTextQuote = 0;
709 else
710 mTextQuote = mark[ 0 ];
711
712 fillTable();
713}
714
715void CSVImportDialog::lineSelected( const QString& line )
716{
717 mStartLine = line.toInt() - 1;
718 fillTable();
719}
720
721void CSVImportDialog::slotOk()
722{
723 bool assigned = false;
724
725 for ( int column = 0; column < mTable->numCols(); ++column ) {
726 QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0,
727 column ) );
728 if ( item && posToType( item->currentItem() ) != Undefined )
729 assigned = true;
730 }
731
732 if ( assigned )
733 KDialogBase::slotOk();
734 else
735 KMessageBox::sorry( this, i18n( "You have to assign at least one column." ) );
736}
737
738void CSVImportDialog::applyTemplate()
739{
740 QMap<uint,int> columnMap;
741 QMap<QString, QString> fileMap;
742 QStringList templates;
743
744 // load all template files
745/*US QStringList list = KGlobal::dirs()->findAllResources( "data" , QString( kapp->name() ) +
746 "/csv-templates/*.desktop", true, true );
747*/
748 QStringList list = KGlobal::dirs()->findAllResources( "data" , KGlobal::getAppName() +
749 "/csv-templates/*.desktop", true, true );
750
751 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
752 {
753 qDebug("for ");
754//US KSimpleConfig config( *it, true );
755 KConfig config( *it );
756
757 if ( !config.hasGroup( "csv column map" ) )
758 continue;
759
760 config.setGroup( "Misc" );
761 templates.append( config.readEntry( "Name" ) );
762 fileMap.insert( config.readEntry( "Name" ), *it );
763 }
764 qDebug("weiter ");
765 // let the user chose, what to take
766 bool ok = false;
767 QString tmp;
768 tmp = QInputDialog::getItem( i18n( "Template Selection" ),
769 i18n( "Please select a template, that matches the CSV file." ),
770 templates, 0, false, &ok, this );
771
772 if ( !ok )
773 return;
774
775//US KSimpleConfig config( fileMap[ tmp ], true );
776 KConfig config( fileMap[ tmp ] );
777 config.setGroup( "General" );
778//US uint numColumns = config.readUnsignedNumEntry( "Columns" );
779 uint numColumns = (uint)config.readNumEntry( "Columns" );
780
781 mDelimiterEdit->setText( config.readEntry( "DelimiterOther" ) );
782 mDelimiterBox->setButton( config.readNumEntry( "DelimiterType" ) );
783 delimiterClicked( config.readNumEntry( "DelimiterType" ) );
784 int quoteType = config.readNumEntry( "QuoteType" );
785 mComboQuote->setCurrentItem( quoteType );
786 textquoteSelected( mComboQuote->currentText() );
787
788 // create the column map
789 config.setGroup( "csv column map" );
790 for ( uint i = 0; i < numColumns; ++i ) {
791 int col = config.readNumEntry( QString::number( i ) );
792 columnMap.insert( i, col );
793 }
794
795 // apply the column map
796 for ( uint column = 0; column < columnMap.count(); ++column ) {
797 int type = columnMap[ column ];
798 QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0,
799 column ) );
800 if ( item )
801 item->setCurrentItem( typeToPos( type ) );
802 }
803}
804
805void CSVImportDialog::saveTemplate()
806{
807/*US
808 QString fileName = KFileDialog::getSaveFileName(
809 locateLocal( "data", QString( kapp->name() ) + "/csv-templates/" ),
810 "*.desktop", this );
811*/
812 QString fileName = KFileDialog::getSaveFileName(
813 locateLocal( "data", KGlobal::getAppName() + "/csv-templates/" )+
814 "*.desktop",i18n("Save file name") , this );
815
816 if ( fileName.isEmpty() )
817 return;
818
819 if ( !fileName.contains( ".desktop" ) )
820 fileName += ".desktop";
821
822 QString name = QInputDialog::getText( i18n( "Template name" ), i18n( "Please enter a name for the template" ) );
823
824 if ( name.isEmpty() )
825 return;
826
827 KConfig config( fileName );
828 config.setGroup( "General" );
829 config.writeEntry( "Columns", mTable->numCols() );
830 config.writeEntry( "DelimiterType", mDelimiterBox->id( mDelimiterBox->selected() ) );
831 config.writeEntry( "DelimiterOther", mDelimiterEdit->text() );
832 config.writeEntry( "QuoteType", mComboQuote->currentItem() );
833
834 config.setGroup( "Misc" );
835 config.writeEntry( "Name", name );
836
837 config.setGroup( "csv column map" );
838
839 for ( uint column = 0; column < mTable->numCols(); ++column ) {
840 QComboTableItem *item = static_cast<QComboTableItem*>( mTable->item( 0,
841 column ) );
842 if ( item )
843 config.writeEntry( QString::number( column ), posToType(
844 item->currentItem() ) );
845 else
846 config.writeEntry( QString::number( column ), 0 );
847 }
848
849 config.sync();
850}
851
852QString CSVImportDialog::getText( int row, int col )
853{
854 return mTable->text( row, col );
855}
856
857uint CSVImportDialog::posToType( int pos ) const
858{
859 uint counter = 0;
860 QMap<QString, uint>::ConstIterator it;
861 for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it, ++counter )
862 if ( counter == (uint)pos )
863 return it.data();
864
865 return 0;
866}
867
868int CSVImportDialog::typeToPos( uint type ) const
869{
870 uint counter = 0;
871 QMap<QString, uint>::ConstIterator it;
872 for ( it = mTypeMap.begin(); it != mTypeMap.end(); ++it, ++counter )
873 if ( it.data() == type )
874 return counter;
875
876 return -1;
877}
878
879void CSVImportDialog::ignoreDuplicatesChanged( int )
880{
881 fillTable();
882}
883
884void CSVImportDialog::setFile( const QString &fileName )
885{
886 if ( fileName.isEmpty() )
887 return;
888
889 QFile file( fileName );
890 if ( !file.open( IO_ReadOnly ) ) {
891 KMessageBox::sorry( this, i18n( "Cannot open input file!" ) );
892 file.close();
893 return;
894 }
895
896 mFileArray = file.readAll();
897 file.close();
898
899 mClearTypeStore = true;
900 clearTable();
901 mTable->setNumCols( 0 );
902 mTable->setNumRows( 0 );
903 fillTable();
904 mClearTypeStore = false;
905
906 fillComboBox();
907}
908
909void CSVImportDialog::urlChanged( const QString &file )
910{
911 bool state = !file.isEmpty();
912
913 enableButtonOK( state );
914
915 findButton( User1 )->setEnabled( state );
916 findButton( User2 )->setEnabled( state );
917
918}
919
920#ifndef KAB_EMBEDDED
921#include <csvimportdialog.moc>
922#endif //KAB_EMBEDDED
diff --git a/kaddressbook/xxport/csvimportdialog.h b/kaddressbook/xxport/csvimportdialog.h
new file mode 100644
index 0000000..545b5f9
--- a/dev/null
+++ b/kaddressbook/xxport/csvimportdialog.h
@@ -0,0 +1,124 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (C) 2003 Tobias Koenig <tokoe@kde.org>
4 based on the code of KSpread's CSV Import Dialog
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library 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 GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20*/
21
22/*
23Enhanced Version of the file for platform independent KDE tools.
24Copyright (c) 2004 Ulf Schenk
25
26$Id$
27*/
28
29#ifndef CSV_IMPORT_DLG_H
30#define CSV_IMPORT_DLG_H
31
32#include <kabc/addressbook.h>
33#include <kabc/addresseelist.h>
34#include <kdialogbase.h>
35
36#include <qvaluelist.h>
37
38class KURLRequester;
39
40class QButtonGroup;
41class QComboBox;
42class QCheckBox;
43class QLineEdit;
44class QPushButton;
45class QRadioButton;
46class QTable;
47
48class CSVImportDialog : public KDialogBase
49{
50 Q_OBJECT
51
52 public:
53 CSVImportDialog( KABC::AddressBook *ab, QWidget *parent,
54 const char *name = 0 );
55 ~CSVImportDialog();
56
57 KABC::AddresseeList contacts() const;
58
59 protected slots:
60 virtual void slotOk();
61
62 private slots:
63 void returnPressed();
64 void delimiterClicked( int id );
65 void lineSelected( const QString& line );
66 void textquoteSelected( const QString& mark );
67 void textChanged ( const QString & );
68 void ignoreDuplicatesChanged( int );
69 void setFile( const QString& );
70 void urlChanged( const QString& );
71
72 void applyTemplate();
73 void saveTemplate();
74
75 private:
76 enum { Undefined, FormattedName, FamilyName, GivenName, AdditionalName,
77 Prefix, Suffix, NickName, Birthday,
78 HomeAddressStreet, HomeAddressLocality, HomeAddressRegion,
79 HomeAddressPostalCode, HomeAddressCountry, HomeAddressLabel,
80 BusinessAddressStreet, BusinessAddressLocality, BusinessAddressRegion,
81 BusinessAddressPostalCode, BusinessAddressCountry,
82 BusinessAddressLabel,
83 HomePhone, BusinessPhone, MobilePhone, HomeFax, BusinessFax, CarPhone,
84 Isdn, Pager, Email, Mailer, Title, Role, Organization, Note, URL
85 };
86
87 QTable* mTable;
88 QButtonGroup* mDelimiterBox;
89 QRadioButton* mRadioComma;
90 QRadioButton* mRadioSemicolon;
91 QRadioButton* mRadioTab;
92 QRadioButton* mRadioSpace;
93 QRadioButton* mRadioOther;
94 QLineEdit* mDelimiterEdit;
95 QComboBox* mComboLine;
96 QComboBox* mComboQuote;
97 QCheckBox* mIgnoreDuplicates;
98 KURLRequester* mUrlRequester;
99
100 void initGUI();
101 void fillTable();
102 void clearTable();
103 void fillComboBox();
104 void setText( int row, int col, const QString& text );
105 void adjustRows( int rows );
106 QString getText( int row, int col );
107 uint posToType( int pos ) const;
108 int typeToPos( uint type ) const;
109
110 bool mAdjustRows;
111 int mStartLine;
112 QChar mTextQuote;
113 QString mDelimiter;
114 QString mData;
115 QByteArray mFileArray;
116 QMap<QString, uint> mTypeMap;
117 KABC::AddressBook *mAddressBook;
118 int mCustomCounter;
119 bool mClearTypeStore;
120 QValueList<int> mTypeStore;
121
122};
123
124#endif
diff --git a/kaddressbook/xxport/kde2_xxport.cpp b/kaddressbook/xxport/kde2_xxport.cpp
new file mode 100644
index 0000000..d5fc075
--- a/dev/null
+++ b/kaddressbook/xxport/kde2_xxport.cpp
@@ -0,0 +1,116 @@
1/*
2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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/*
25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk
27
28$Id$
29*/
30
31#include <qfile.h>
32
33#include <kdebug.h>
34#include <kfiledialog.h>
35#ifndef KAB_EMBEDDED
36#include <kio/netaccess.h>
37#endif //KAB_EMBEDDED
38#include <klocale.h>
39#include <kmessagebox.h>
40#include <kprocess.h>
41#include <kstandarddirs.h>
42#include <ktempfile.h>
43#include <kurl.h>
44
45#include "xxportmanager.h"
46
47#include "kde2_xxport.h"
48
49#ifndef KAB_EMBEDDED
50
51class KDE2XXPortFactory : public XXPortFactory
52{
53 public:
54 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
55 {
56 return new KDE2XXPort( ab, parent, name );
57 }
58};
59
60
61extern "C"
62{
63 void *init_libkaddrbk_kde2_xxport()
64 {
65 return ( new KDE2XXPortFactory() );
66 }
67}
68#endif //KAB_EMBEDDED
69
70
71KDE2XXPort::KDE2XXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
72 : XXPortObject( ab, parent, name )
73{
74 createImportAction( i18n( "Import KDE 2 Addressbook..." ) );
75}
76
77KABC::AddresseeList KDE2XXPort::importContacts( const QString& ) const
78{
79 QString fileName = locateLocal( "data", "kabc/std.vcf" );
80 if ( !QFile::exists( fileName ) ) {
81 KMessageBox::sorry( parentWidget(), i18n( "<qt>Couldn't find a KDE 2 address book <b>%1</b>.</qt>" ).arg( fileName ) );
82 return KABC::AddresseeList();
83 }
84
85#ifndef KAB_EMBEDDED
86 int result = KMessageBox::questionYesNoCancel( parentWidget(),
87 i18n( "Override previously imported entries?" ),
88 i18n( "Import KDE 2 Addressbook" ) );
89#else //KAB_EMBEDDED
90 int result = KMessageBox::warningYesNoCancel( parentWidget(),
91 i18n( "Override previously imported entries?" ),
92 i18n( "Import KDE 2 Addressbook" ) );
93#endif //KAB_EMBEDDED
94
95 if ( !result ) return KABC::AddresseeList();
96
97 KProcess proc;
98
99 if ( result == KMessageBox::Yes ) {
100 proc << "kab2kabc";
101 proc << "--override";
102 } else if ( result == KMessageBox::No )
103 proc << "kab2kabc";
104 else
105 kdDebug(5720) << "KAddressBook::importKDE2(): Unknow return value." << endl;
106
107 proc.start( KProcess::Block );
108
109 addressBook()->load();
110
111 return KABC::AddresseeList();
112}
113
114#ifndef KAB_EMBEDDED
115#include "kde2_xxport.moc"
116#endif //KAB_EMBEDDED
diff --git a/kaddressbook/xxport/kde2_xxport.h b/kaddressbook/xxport/kde2_xxport.h
new file mode 100644
index 0000000..4fb1d0b
--- a/dev/null
+++ b/kaddressbook/xxport/kde2_xxport.h
@@ -0,0 +1,62 @@
1/*
2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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/*
25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk
27
28$Id$
29*/
30
31#ifndef KDE2_XXPORT_H
32#define KDE2_XXPORT_H
33
34#include <xxportobject.h>
35
36class KDE2XXPort : public XXPortObject
37{
38 Q_OBJECT
39
40 public:
41 KDE2XXPort( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
42
43 QString identifier() const { return "kde2"; }
44
45 public slots:
46 KABC::AddresseeList importContacts( const QString &data ) const;
47};
48
49
50#ifdef KAB_EMBEDDED
51class KDE2XXPortFactory : public XXPortFactory
52{
53 public:
54 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
55 {
56 return new KDE2XXPort( ab, parent, name );
57 }
58};
59#endif //KAB_EMBEDDED
60
61
62#endif
diff --git a/kaddressbook/xxport/vcard_xxport.cpp b/kaddressbook/xxport/vcard_xxport.cpp
new file mode 100644
index 0000000..dd49a9c
--- a/dev/null
+++ b/kaddressbook/xxport/vcard_xxport.cpp
@@ -0,0 +1,238 @@
1/*
2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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/*
25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk
27
28$Id$
29*/
30
31#include <qfile.h>
32#include <qtextstream.h>
33
34#include <kabc/vcardconverter.h>
35#include <kfiledialog.h>
36#ifndef KAB_EMBEDDED
37#include <kio/netaccess.h>
38#endif //KAB_EMBEDDED
39
40#include <klocale.h>
41#include <kmessagebox.h>
42#include <ktempfile.h>
43#include <kurl.h>
44
45#include "xxportmanager.h"
46
47#include "vcard_xxport.h"
48
49#ifndef KAB_EMBEDDED
50
51class VCardXXPortFactory : public XXPortFactory
52{
53 public:
54 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
55 {
56 return new VCardXXPort( ab, parent, name );
57 }
58};
59
60
61extern "C"
62{
63 void *init_libkaddrbk_vcard_xxport()
64 {
65 return ( new VCardXXPortFactory() );
66 }
67}
68#endif //KAB_EMBEDDED
69
70
71VCardXXPort::VCardXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
72 : XXPortObject( ab, parent, name )
73{
74 createImportAction( i18n( "Import vCard..." ) );
75 createExportAction( i18n( "Export vCard 2.1..." ), "v21" );
76 createExportAction( i18n( "Export vCard 3.0..." ), "v30" );
77}
78
79bool VCardXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data )
80{
81 QString name;
82
83 if ( list.count() == 1 )
84 name = list[ 0 ].givenName() + "_" + list[ 0 ].familyName() + ".vcf";
85 else
86 name = "addressbook.vcf";
87
88#ifndef KAB_EMBEDDED
89 QString fileName = KFileDialog::getSaveFileName( name );
90#else //KAB_EMBEDDED
91 QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() );
92#endif //KAB_EMBEDDED
93
94 if ( fileName.isEmpty() )
95 return true;
96
97 QFile outFile( fileName );
98 if ( !outFile.open( IO_WriteOnly ) ) {
99 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" );
100 KMessageBox::error( parentWidget(), text.arg( fileName ) );
101 return false;
102 }
103
104 QTextStream t( &outFile );
105 t.setEncoding( QTextStream::UnicodeUTF8 );
106
107 KABC::Addressee::List::ConstIterator it;
108 for ( it = list.begin(); it != list.end(); ++it ) {
109 KABC::VCardConverter converter;
110 QString vcard;
111
112 KABC::VCardConverter::Version version;
113 if ( data == "v21" )
114 version = KABC::VCardConverter::v2_1;
115 else
116 version = KABC::VCardConverter::v3_0;
117
118 converter.addresseeToVCard( *it, vcard, version );
119 t << vcard << "\r\n\r\n";
120 }
121
122 outFile.close();
123
124 return true;
125}
126
127KABC::AddresseeList VCardXXPort::importContacts( const QString& ) const
128{
129 QString fileName;
130 KABC::AddresseeList addrList;
131 KURL url;
132
133#ifndef KAB_EMBEDDED
134 if ( !XXPortManager::importData.isEmpty() )
135 addrList = parseVCard( XXPortManager::importData );
136 else {
137 if ( XXPortManager::importURL.isEmpty() )
138 {
139 url = KFileDialog::getLoadFileName( QString::null, i18n("Select vCard to Import"), parentWidget() );
140 }
141 else
142 url = XXPortManager::importURL;
143
144 if ( url.isEmpty() )
145 return addrList;
146
147 QString caption( i18n( "vCard Import Failed" ) );
148 if ( KIO::NetAccess::download( url, fileName ) ) {
149 QFile file( fileName );
150
151 file.open( IO_ReadOnly );
152 QByteArray rawData = file.readAll();
153 file.close();
154
155 QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
156 addrList = parseVCard( data );
157
158 if ( !url.isLocalFile() )
159 KIO::NetAccess::removeTempFile( fileName );
160
161 } else {
162 QString text = i18n( "<qt>Unable to access <b>%1</b>.</qt>" );
163 KMessageBox::error( parentWidget(), text.arg( url.url() ), caption );
164 }
165
166 }
167
168
169#else //KAB_EMBEDDED
170
171
172 if ( !XXPortManager::importData.isEmpty() )
173 addrList = parseVCard( XXPortManager::importData );
174 else {
175 if ( XXPortManager::importURL.isEmpty() )
176 {
177 fileName = KFileDialog::getOpenFileName( QString::null, i18n("Select vCard to Import"), parentWidget() );
178 }
179 else
180 {
181//US url = XXPortManager::importURL;
182 qDebug("VCardXXPort::importContacts Urls at the moment not supported");
183 }
184
185 if ( url.isEmpty() )
186 return addrList;
187
188 QFile file( fileName );
189
190 file.open( IO_ReadOnly );
191 QByteArray rawData = file.readAll();
192 file.close();
193
194 QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
195 addrList = parseVCard( data );
196
197 }
198#endif //KAB_EMBEDDED
199
200 return addrList;
201}
202
203KABC::AddresseeList VCardXXPort::parseVCard( const QString &data ) const
204{
205 KABC::VCardConverter converter;
206 KABC::AddresseeList addrList;
207
208 uint numVCards = data.contains( "BEGIN:VCARD", false );
209 QStringList dataList = QStringList::split( "\r\n\r\n", data );
210
211 for ( uint i = 0; i < numVCards && i < dataList.count(); ++i ) {
212 KABC::Addressee addr;
213 bool ok = false;
214
215 if ( dataList[ i ].contains( "VERSION:3.0" ) )
216 ok = converter.vCardToAddressee( dataList[ i ], addr, KABC::VCardConverter::v3_0 );
217 else if ( dataList[ i ].contains( "VERSION:2.1" ) )
218 ok = converter.vCardToAddressee( dataList[ i ], addr, KABC::VCardConverter::v2_1 );
219 else {
220 KMessageBox::sorry( parentWidget(), i18n( "Not supported vCard version." ) );
221 continue;
222 }
223
224 if ( !addr.isEmpty() && ok )
225 addrList.append( addr );
226 else {
227 QString text = i18n( "The selected file does not include a valid vCard. "
228 "Please check the file and try again." );
229 KMessageBox::sorry( parentWidget(), text );
230 }
231 }
232
233 return addrList;
234}
235
236#ifndef KAB_EMBEDDED
237#include "vcard_xxport.moc"
238#endif //KAB_EMBEDDED
diff --git a/kaddressbook/xxport/vcard_xxport.h b/kaddressbook/xxport/vcard_xxport.h
new file mode 100644
index 0000000..b9708a9
--- a/dev/null
+++ b/kaddressbook/xxport/vcard_xxport.h
@@ -0,0 +1,64 @@
1/*
2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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/*
25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk
27
28$Id$
29*/
30
31#ifndef VCARD_XXPORT_H
32#define VCARD_XXPORT_H
33
34#include <xxportobject.h>
35
36class VCardXXPort : public XXPortObject
37{
38 Q_OBJECT
39
40 public:
41 VCardXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
42
43 QString identifier() const { return "vcard"; }
44
45 public slots:
46 bool exportContacts( const KABC::AddresseeList &list, const QString &data );
47 KABC::AddresseeList importContacts( const QString &data ) const;
48
49 private:
50 KABC::AddresseeList parseVCard( const QString &data ) const;
51};
52
53#ifdef KAB_EMBEDDED
54class VCardXXPortFactory : public XXPortFactory
55{
56 public:
57 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
58 {
59 return new VCardXXPort( ab, parent, name );
60 }
61};
62#endif //KAB_EMBEDDED
63
64#endif
diff --git a/kaddressbook/xxportmanager.cpp b/kaddressbook/xxportmanager.cpp
new file mode 100644
index 0000000..6cfa9cb
--- a/dev/null
+++ b/kaddressbook/xxportmanager.cpp
@@ -0,0 +1,269 @@
1/*
2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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/*
25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk
27
28$Id$
29*/
30
31#include <qlayout.h>
32
33#include <kabc/addressbook.h>
34#include <kabc/resource.h>
35#include <kdebug.h>
36#include <kdialogbase.h>
37#include <klocale.h>
38#include <kmessagebox.h>
39
40#ifndef KAB_EMBEDDED
41#include <ktrader.h>
42#else //KAB_EMBEDDED
43#include "xxport/csv_xxport.h"
44#include "xxport/kde2_xxport.h"
45#include "xxport/vcard_xxport.h"
46#endif //KAB_EMBEDDED
47
48#include <libkdepim/addresseeview.h>
49
50#include "kabcore.h"
51#include "undocmds.h"
52#include "xxportselectdialog.h"
53
54#include "xxportmanager.h"
55
56KURL XXPortManager::importURL = KURL();
57QString XXPortManager::importData = QString::null;
58
59class PreviewDialog : public KDialogBase
60{
61 public:
62 PreviewDialog( const KABC::Addressee &addr,
63 QWidget *parent, const char *name = 0 );
64};
65
66XXPortManager::XXPortManager( KABCore *core, QObject *parent, const char *name )
67 : QObject( parent, name ), mCore( core ), mShowPreview( false )
68{
69 loadPlugins();
70}
71
72XXPortManager::~XXPortManager()
73{
74}
75
76void XXPortManager::restoreSettings()
77{
78}
79
80void XXPortManager::saveSettings()
81{
82}
83
84void XXPortManager::importVCard( const KURL &url )
85{
86 importVCard( url, false );
87}
88
89void XXPortManager::importVCard( const KURL &url, bool showPreview )
90{
91 importURL = url;
92 mShowPreview = showPreview;
93 slotImport( "vcard", "<empty>" );
94 mShowPreview = false;
95 importURL = KURL();
96}
97
98void XXPortManager::importVCard( const QString &vCard, bool showPreview )
99{
100 importData = vCard;
101 mShowPreview = showPreview;
102 slotImport( "vcard", "<empty>" );
103 mShowPreview = false;
104 importData = "";
105}
106
107void XXPortManager::slotImport( const QString &identifier, const QString &data )
108{
109 XXPortObject *obj = mXXPortObjects[ identifier ];
110 if ( !obj ) {
111 KMessageBox::error( mCore, i18n( "<qt>No import plugin available for <b>%1</b>.</qt>" ).arg( identifier ) );
112 return;
113 }
114
115 KABC::Resource *resource = mCore->requestResource( mCore );
116 if ( !resource )
117 return;
118
119 KABC::AddresseeList list = obj->importContacts( data );
120 KABC::AddresseeList::Iterator it;
121 bool imported = false;
122 for ( it = list.begin(); it != list.end(); ++it ) {
123 if ( mShowPreview ) {
124 PreviewDialog dlg( *it, mCore );
125 if ( !dlg.exec() )
126 continue;
127 }
128
129 (*it).setResource( resource );
130 // We use a PwNewCommand so the user can undo it.
131 PwNewCommand *command = new PwNewCommand( mCore->addressBook(), *it );
132 UndoStack::instance()->push( command );
133 RedoStack::instance()->clear();
134 imported = true;
135 }
136
137 if ( imported ) {
138 KMessageBox::information( mCore, i18n( "contacts successfully imported." ) );
139
140 emit modified();
141 }
142}
143
144void XXPortManager::slotExport( const QString &identifier, const QString &data )
145{
146 XXPortObject *obj = mXXPortObjects[ identifier ];
147 if ( !obj ) {
148 KMessageBox::error( mCore, i18n( "<qt>No export plugin available for <b>%1</b>.</qt>" ).arg( identifier ) );
149 return;
150 }
151
152 KABC::AddresseeList addrList;
153 XXPortSelectDialog dlg( mCore, obj->requiresSorting(), mCore );
154 if ( dlg.exec() )
155 addrList = dlg.contacts();
156 else
157 return;
158
159 if ( !obj->exportContacts( addrList, data ) )
160 KMessageBox::error( mCore, i18n( "Unable to export contacts." ) );
161 else
162 KMessageBox::information( mCore, i18n( "contacts successfully exported." ) );
163}
164
165void XXPortManager::loadPlugins()
166{
167 mXXPortObjects.clear();
168
169#ifndef KAB_EMBEDDED
170 KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/XXPort" );
171 KTrader::OfferList::ConstIterator it;
172 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
173 if ( !(*it)->hasServiceType( "KAddressBook/XXPort" ) )
174 continue;
175
176 KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() );
177 if ( !factory ) {
178 kdDebug(5720) << "XXPortManager::loadExtensions(): Factory creation failed" << endl;
179 continue;
180 }
181
182 XXPortFactory *xxportFactory = static_cast<XXPortFactory*>( factory );
183
184 if ( !xxportFactory ) {
185 kdDebug(5720) << "XXPortManager::loadExtensions(): Cast failed" << endl;
186 continue;
187 }
188
189 XXPortObject *obj = xxportFactory->xxportObject( mCore->addressBook(), mCore );
190 if ( obj ) {
191 mCore->addGUIClient( obj );
192 mXXPortObjects.insert( obj->identifier(), obj );
193 connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ),
194 this, SLOT( slotExport( const QString&, const QString& ) ) );
195 connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ),
196 this, SLOT( slotImport( const QString&, const QString& ) ) );
197 }
198 }
199
200#else //KAB_EMBEDDED
201//lets load the export/import stubs directly. Is dynamic loading necessary for KA/Pi?
202
203 // CVS import/export
204 XXPortFactory *xxportFactory = new CSVXXPortFactory();
205
206 XXPortObject *obj = xxportFactory->xxportObject( mCore->addressBook(), mCore );
207 if ( obj ) {
208 mCore->addGUIClient( obj );
209 mXXPortObjects.insert( obj->identifier(), obj );
210 connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ),
211 this, SLOT( slotExport( const QString&, const QString& ) ) );
212 connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ),
213 this, SLOT( slotImport( const QString&, const QString& ) ) );
214 }
215
216
217
218 // KDE2 import/export
219 xxportFactory = new KDE2XXPortFactory();
220
221 obj = xxportFactory->xxportObject( mCore->addressBook(), mCore );
222 if ( obj ) {
223 mCore->addGUIClient( obj );
224 mXXPortObjects.insert( obj->identifier(), obj );
225 connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ),
226 this, SLOT( slotExport( const QString&, const QString& ) ) );
227 connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ),
228 this, SLOT( slotImport( const QString&, const QString& ) ) );
229 }
230
231
232
233 // VCARD import/export
234 xxportFactory = new VCardXXPortFactory();
235
236 obj = xxportFactory->xxportObject( mCore->addressBook(), mCore );
237 if ( obj ) {
238 mCore->addGUIClient( obj );
239 mXXPortObjects.insert( obj->identifier(), obj );
240 connect( obj, SIGNAL( exportActivated( const QString&, const QString& ) ),
241 this, SLOT( slotExport( const QString&, const QString& ) ) );
242 connect( obj, SIGNAL( importActivated( const QString&, const QString& ) ),
243 this, SLOT( slotImport( const QString&, const QString& ) ) );
244 }
245#endif //KAB_EMBEDDED
246
247}
248
249
250PreviewDialog::PreviewDialog( const KABC::Addressee &addr, QWidget *parent,
251 const char *name )
252 : KDialogBase( Plain, i18n( "Contact Preview" ), Ok | Cancel, Ok, parent,
253 name, true, true )
254{
255 QWidget *page = plainPage();
256 QVBoxLayout *layout = new QVBoxLayout( page, marginHint(), spacingHint() );
257
258 KPIM::AddresseeView *view = new KPIM::AddresseeView( page );
259 view->setAddressee( addr );
260
261 layout->addWidget( view );
262
263 resize( 400, 300 );
264}
265
266#ifndef KAB_EMBEDDED
267#include "xxportmanager.moc"
268#endif //KAB_EMBEDDED
269
diff --git a/kaddressbook/xxportmanager.h b/kaddressbook/xxportmanager.h
new file mode 100644
index 0000000..f8436ed
--- a/dev/null
+++ b/kaddressbook/xxportmanager.h
@@ -0,0 +1,79 @@
1/*
2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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/*
25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk
27
28$Id$
29*/
30
31
32#ifndef XXPORTMANAGER_H
33#define XXPORTMANAGER_H
34
35#include <qdict.h>
36#include <qobject.h>
37
38#include <kurl.h>
39
40#include "xxportobject.h"
41
42class KABCore;
43
44class XXPortManager : public QObject
45{
46 Q_OBJECT
47
48 public:
49 XXPortManager( KABCore *core, QObject *parent, const char *name = 0 );
50 ~XXPortManager();
51
52 void restoreSettings();
53 void saveSettings();
54
55 static KURL importURL;
56 static QString importData;
57
58 public slots:
59 void importVCard( const KURL &url );
60 void importVCard( const KURL &url, bool showPreview );
61 void importVCard( const QString &vCard, bool showPreview );
62
63 signals:
64 void modified();
65
66 protected slots:
67 void slotImport( const QString&, const QString& );
68 void slotExport( const QString&, const QString& );
69
70 private:
71 void loadPlugins();
72
73 QDict<XXPortObject> mXXPortObjects;
74
75 KABCore *mCore;
76 bool mShowPreview;
77};
78
79#endif
diff --git a/kaddressbook/xxportobject.cpp b/kaddressbook/xxportobject.cpp
new file mode 100644
index 0000000..42ab0fb
--- a/dev/null
+++ b/kaddressbook/xxportobject.cpp
@@ -0,0 +1,152 @@
1/*
2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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/*
25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk
27
28$Id$
29*/
30
31#include <qmap.h>
32#include <qsignalmapper.h>
33
34#include <kaction.h>
35#include <kmessagebox.h>
36
37#include "kabcore.h"
38
39#include "xxportobject.h"
40
41class XXPortObject::XXPortObjectPrivate
42{
43 public:
44 QSignalMapper *mExportMapper;
45 QSignalMapper *mImportMapper;
46};
47
48XXPortObject::XXPortObject( KABC::AddressBook *ab, QWidget *parent,
49 const char *name )
50 : QObject( parent, name ), mAddressBook( ab ), mParentWidget( parent ),
51 d( new XXPortObjectPrivate )
52{
53 d->mExportMapper = new QSignalMapper( this );
54 d->mImportMapper = new QSignalMapper( this );
55
56 connect( d->mExportMapper, SIGNAL( mapped( const QString& ) ),
57 SLOT( slotExportActivated( const QString& ) ) );
58 connect( d->mImportMapper, SIGNAL( mapped( const QString& ) ),
59 SLOT( slotImportActivated( const QString& ) ) );
60}
61
62XXPortObject::~XXPortObject()
63{
64 delete d;
65 d = 0;
66}
67
68bool XXPortObject::exportContacts( const KABC::AddresseeList&, const QString& )
69{
70 // do nothing
71 return false;
72}
73
74KABC::AddresseeList XXPortObject::importContacts( const QString& ) const
75{
76 // do nothing
77 return KABC::AddresseeList();
78}
79
80void XXPortObject::createImportAction( const QString &label, const QString &data )
81{
82#ifdef KAB_EMBEDDED
83 KABCore* kabcore = (KABCore*)mParentWidget;
84#endif //KAB_EMBEDDED
85
86 QString id = "file_import_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data );
87#ifndef KAB_EMBEDDED
88 KAction *action = new KAction( label, 0, d->mImportMapper, SLOT( map() ), actionCollection(), id.latin1() );
89#else //KAB_EMBEDDED
90 KAction *action = new KAction( label, 0, d->mImportMapper, SLOT( map() ), kabcore->actionCollection(), id.latin1() );
91#endif //KAB_EMBEDDED
92
93 d->mImportMapper->setMapping( action, ( data.isEmpty() ? QString( "<empty>" ) : data ) );
94
95#ifndef KAB_EMBEDDED
96 setXMLFile( identifier() + "_xxportui.rc" );
97#endif //KAB_EMBEDDED
98
99#ifdef KAB_EMBEDDED
100 action->plug((QWidget*)kabcore->getImportMenu());
101#endif //KAB_EMBEDDED
102
103}
104
105void XXPortObject::createExportAction( const QString &label, const QString &data )
106{
107#ifdef KAB_EMBEDDED
108 KABCore* kabcore = (KABCore*)mParentWidget;
109#endif //KAB_EMBEDDED
110
111 QString id = "file_export_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data );
112#ifndef KAB_EMBEDDED
113 KAction *action = new KAction( label, 0, d->mExportMapper, SLOT( map() ), actionCollection(), id.latin1() );
114#else //KAB_EMBEDDED
115 KAction *action = new KAction( label, 0, d->mExportMapper, SLOT( map() ), kabcore->actionCollection(), id.latin1() );
116#endif //KAB_EMBEDDED
117
118 d->mExportMapper->setMapping( action, ( data.isEmpty() ? QString( "<empty>" ) : data ) );
119
120#ifndef KAB_EMBEDDED
121 setXMLFile( identifier() + "_xxportui.rc" );
122#endif //KAB_EMBEDDED
123
124#ifdef KAB_EMBEDDED
125 action->plug((QWidget*)kabcore->getExportMenu());
126#endif //KAB_EMBEDDED
127
128}
129
130KABC::AddressBook *XXPortObject::addressBook() const
131{
132 return mAddressBook;
133}
134
135QWidget *XXPortObject::parentWidget() const
136{
137 return mParentWidget;
138}
139
140void XXPortObject::slotExportActivated( const QString &data )
141{
142 emit exportActivated( identifier(), ( data == "<empty>" ? QString::null : data ) );
143}
144
145void XXPortObject::slotImportActivated( const QString &data )
146{
147 emit importActivated( identifier(), ( data == "<empty>" ? QString::null : data ) );
148}
149
150#ifndef KAB_EMBEDDED
151#include "xxportobject.moc"
152#endif //KAB_EMBEDDED
diff --git a/kaddressbook/xxportobject.h b/kaddressbook/xxportobject.h
new file mode 100644
index 0000000..d697700
--- a/dev/null
+++ b/kaddressbook/xxportobject.h
@@ -0,0 +1,157 @@
1/*
2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@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/*
25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk
27
28$Id$
29*/
30
31#ifndef XXPORTOBJECT_H
32#define XXPORTOBJECT_H
33
34#include <qobject.h>
35
36#include <kabc/addressbook.h>
37#include <kabc/addresseelist.h>
38#include <kxmlguiclient.h>
39#ifndef KAB_EMBEDDED
40#include <klibloader.h>
41#endif //KAB_EMBEDDED
42
43
44class XXPortObject : public QObject, virtual public KXMLGUIClient
45{
46 Q_OBJECT
47
48 public:
49 XXPortObject( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
50 ~XXPortObject();
51
52 /**
53 Returns the unique identifier of this xxport modul, it should
54 be the lowercase name of the import/export format e.g. 'vcard'
55 */
56 virtual QString identifier() const = 0;
57
58 /**
59 Reimplement this method if the XXPortManager shall
60 pass a sorted list to @ref exportContacts().
61 */
62 virtual bool requiresSorting() const { return false; }
63
64 public slots:
65 /**
66 Reimplement this method for exporting the contacts.
67 */
68 virtual bool exportContacts( const KABC::AddresseeList &list, const QString& identifier );
69
70 /**
71 Reimplement this method for importing the contacts.
72 */
73 virtual KABC::AddresseeList importContacts( const QString& identifier ) const;
74
75 signals:
76 /**
77 Emitted whenever the export action is activated.
78 The parameter contains the @ref identifier() for
79 unique identification.
80 */
81 void exportActivated( const QString&, const QString& );
82
83 /**
84 Emitted whenever the import action is activated.
85 The parameter contains the @ref identifier() for
86 unique identification.
87 */
88 void importActivated( const QString&, const QString& );
89
90 protected:
91 /**
92 Create the import action. The identifier is passed in the import slot.
93 */
94 void createImportAction( const QString &label, const QString &identifier = QString::null );
95
96 /**
97 Create the export action. The identifier is passed in the export slot.
98 */
99 void createExportAction( const QString &label, const QString &identifier = QString::null );
100
101 /**
102 Returns a pointer to the address book object.
103 */
104 KABC::AddressBook *addressBook() const;
105
106 /**
107 Returns a pointer to the parent widget. It can be used as parent for
108 message boxes.
109 */
110 QWidget *parentWidget() const;
111
112
113 private slots:
114 void slotImportActivated( const QString& );
115 void slotExportActivated( const QString& );
116
117 private:
118 KABC::AddressBook *mAddressBook;
119 QWidget *mParentWidget;
120
121 class XXPortObjectPrivate;
122 XXPortObjectPrivate *d;
123};
124
125#ifndef KAB_EMBEDDED
126class XXPortFactory : public KLibFactory
127{
128 public:
129 virtual XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent,
130 const char *name = 0 ) = 0;
131
132 protected:
133 virtual QObject* createObject( QObject*, const char*, const char*,
134 const QStringList & )
135 {
136 return 0;
137 }
138};
139
140#else //KAB_EMBEDDED
141class XXPortFactory
142{
143 public:
144 virtual XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent,
145 const char *name = 0 ) = 0;
146
147 protected:
148 virtual QObject* createObject( QObject*, const char*, const char*,
149 const QStringList & )
150 {
151 return 0;
152 }
153};
154#endif //KAB_EMBEDDED
155
156
157#endif
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
diff --git a/kaddressbook/xxportselectdialog.h b/kaddressbook/xxportselectdialog.h
new file mode 100644
index 0000000..8d56f66
--- a/dev/null
+++ b/kaddressbook/xxportselectdialog.h
@@ -0,0 +1,81 @@
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#ifndef XXPORTSELECTDIALOG_H
25#define XXPORTSELECTDIALOG_H
26
27#include <kabc/addresseelist.h>
28#include <kabc/field.h>
29#include <kdialogbase.h>
30
31#include "filter.h"
32
33class QButtonGroup;
34class QComboBox;
35class QListView;
36class QListViewItem;
37class QRadioButton;
38
39class KABCore;
40class KComboBox;
41
42class XXPortSelectDialog : public KDialogBase
43{
44 Q_OBJECT
45
46 public:
47 XXPortSelectDialog( KABCore *core, bool sort, QWidget* parent,
48 const char* name = 0 );
49
50 KABC::AddresseeList contacts();
51
52 private slots:
53 void filterChanged( int );
54 void categoryClicked( QListViewItem * i );
55
56 protected slots:
57 void slotHelp();
58
59 private:
60 void initGUI();
61 QStringList categories() const;
62
63 QButtonGroup* mButtonGroup;
64 QRadioButton* mUseCategories;
65 QRadioButton* mUseFilters;
66 QRadioButton* mUseWholeBook;
67 QRadioButton* mUseSelection;
68 QComboBox* mFiltersCombo;
69 QListView* mCategoriesView;
70
71 KComboBox *mFieldCombo;
72 KComboBox *mSortTypeCombo;
73
74 KABCore *mCore;
75 KABC::AddresseeList mAddresseeList;
76 Filter::List mFilters;
77 KABC::Field::List mFields;
78 bool mUseSorting;
79};
80
81#endif