summaryrefslogtreecommitdiffabout
path: root/kaddressbook/features/mergewidget.cpp
Unidiff
Diffstat (limited to 'kaddressbook/features/mergewidget.cpp') (more/less context) (show whitespace changes)
-rw-r--r--kaddressbook/features/mergewidget.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/kaddressbook/features/mergewidget.cpp b/kaddressbook/features/mergewidget.cpp
index 2476e42..1becc2f 100644
--- a/kaddressbook/features/mergewidget.cpp
+++ b/kaddressbook/features/mergewidget.cpp
@@ -2,120 +2,122 @@
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qlayout.h> 24#include <qlayout.h>
25#include <qpushbutton.h> 25#include <qpushbutton.h>
26//Added by qt3to4:
27#include <Q3GridLayout>
26 28
27#ifndef KAB_EMBEDDED 29#ifndef KAB_EMBEDDED
28#include <kaccelmanager.h> 30#include <kaccelmanager.h>
29#endif //KAB_EMBEDDED 31#endif //KAB_EMBEDDED
30 32
31#include <kdebug.h> 33#include <kdebug.h>
32#include <klistview.h> 34#include <klistview.h>
33#include <klocale.h> 35#include <klocale.h>
34#include <kglobal.h> 36#include <kglobal.h>
35#include <kmessagebox.h> 37#include <kmessagebox.h>
36 38
37#include <kabc/addressbook.h> 39#include <kabc/addressbook.h>
38 40
39#include "kabcore.h" 41#include "kabcore.h"
40 42
41#include "mergewidget.h" 43#include "mergewidget.h"
42 44
43#ifndef KAB_EMBEDDED 45#ifndef KAB_EMBEDDED
44class MergeFactory : public ExtensionFactory 46class MergeFactory : public ExtensionFactory
45{ 47{
46 public: 48 public:
47 ExtensionWidget *extension( KABCore *core, QWidget *parent, const char *name ) 49 ExtensionWidget *extension( KABCore *core, QWidget *parent, const char *name )
48 { 50 {
49 return new MergeWidget( core, parent, name ); 51 return new MergeWidget( core, parent, name );
50 } 52 }
51 53
52 QString identifier() const 54 QString identifier() const
53 { 55 {
54 return "merge"; 56 return "merge";
55 } 57 }
56}; 58};
57 59
58extern "C" { 60extern "C" {
59 void *init_libkaddrbk_merge() 61 void *init_libkaddrbk_merge()
60 { 62 {
61 return ( new MergeFactory ); 63 return ( new MergeFactory );
62 } 64 }
63} 65}
64#endif //KAB_EMBEDDED 66#endif //KAB_EMBEDDED
65 67
66class ContactItem : public QListViewItem 68class ContactItem : public Q3ListViewItem
67{ 69{
68 public: 70 public:
69 ContactItem( KListView *parent, const KABC::Addressee &addressee ) 71 ContactItem( KListView *parent, const KABC::Addressee &addressee )
70 : QListViewItem( parent ), mAddressee( addressee ) 72 : Q3ListViewItem( parent ), mAddressee( addressee )
71 { 73 {
72 KABC::Field::List fieldList = KABC::Field::defaultFields(); 74 KABC::Field::List fieldList = KABC::Field::defaultFields();
73 KABC::Field::List::ConstIterator it; 75 KABC::Field::List::ConstIterator it;
74 76
75 int i = 0; 77 int i = 0;
76 for ( it = fieldList.begin(); it != fieldList.end(); ++it ) 78 for ( it = fieldList.begin(); it != fieldList.end(); ++it )
77 setText( i++, (*it)->value( mAddressee ) ); 79 setText( i++, (*it)->value( mAddressee ) );
78 } 80 }
79 81
80 KABC::Addressee addressee() const 82 KABC::Addressee addressee() const
81 { 83 {
82 return mAddressee; 84 return mAddressee;
83 } 85 }
84 86
85 private: 87 private:
86 KABC::Addressee mAddressee; 88 KABC::Addressee mAddressee;
87}; 89};
88 90
89MergeWidget::MergeWidget( KABCore *core, QWidget *parent, const char *name ) 91MergeWidget::MergeWidget( KABCore *core, QWidget *parent, const char *name )
90 : ExtensionWidget( core, parent, name ), mBlockUpdate( false ) 92 : ExtensionWidget( core, parent, name ), mBlockUpdate( false )
91{ 93{
92#ifdef KAB_EMBEDDED 94#ifdef KAB_EMBEDDED
93 if (KGlobal::getOrientation() == KGlobal::Portrait) 95 if (KGlobal::getOrientation() == KGlobal::Portrait)
94 parent->setMaximumSize( KGlobal::getDesktopWidth() , 180); 96 parent->setMaximumSize( KGlobal::getDesktopWidth() , 180);
95#endif //KAB_EMBEDDED 97#endif //KAB_EMBEDDED
96 98
97 QGridLayout *topLayout = new QGridLayout( this, 3, 2, KDialog::marginHint(), 99 Q3GridLayout *topLayout = new Q3GridLayout( this, 3, 2, KDialog::marginHint(),
98 KDialog::spacingHint() ); 100 KDialog::spacingHint() );
99 101
100 mContactView = new KListView( this ); 102 mContactView = new KListView( this );
101 KABC::Field::List fieldList = KABC::Field::defaultFields(); 103 KABC::Field::List fieldList = KABC::Field::defaultFields();
102 KABC::Field::List::ConstIterator it; 104 KABC::Field::List::ConstIterator it;
103 105
104 for ( it = fieldList.begin(); it != fieldList.end(); ++it ) 106 for ( it = fieldList.begin(); it != fieldList.end(); ++it )
105 mContactView->addColumn( (*it)->label() ); 107 mContactView->addColumn( (*it)->label() );
106 108
107 mContactView->setEnabled( false ); 109 mContactView->setEnabled( false );
108 mContactView->setAllColumnsShowFocus( true ); 110 mContactView->setAllColumnsShowFocus( true );
109 topLayout->addMultiCellWidget( mContactView, 0, 2, 0, 0 ); 111 topLayout->addMultiCellWidget( mContactView, 0, 2, 0, 0 );
110 112
111 connect( mContactView, SIGNAL( selectionChanged() ), 113 connect( mContactView, SIGNAL( selectionChanged() ),
112 SLOT( selectionContactViewChanged() ) ); 114 SLOT( selectionContactViewChanged() ) );
113 115
114 mMergeAndRemoveButton = new QPushButton( i18n( "Merge and Remove" ), this ); 116 mMergeAndRemoveButton = new QPushButton( i18n( "Merge and Remove" ), this );
115 mMergeAndRemoveButton->setEnabled( false ); 117 mMergeAndRemoveButton->setEnabled( false );
116 topLayout->addWidget( mMergeAndRemoveButton, 0, 1 ); 118 topLayout->addWidget( mMergeAndRemoveButton, 0, 1 );
117 connect( mMergeAndRemoveButton, SIGNAL( clicked() ), SLOT( mergeAndRemove() ) ); 119 connect( mMergeAndRemoveButton, SIGNAL( clicked() ), SLOT( mergeAndRemove() ) );
118 120
119 mMergeButton = new QPushButton( i18n( "Merge" ), this ); 121 mMergeButton = new QPushButton( i18n( "Merge" ), this );
120 mMergeButton->setEnabled( false ); 122 mMergeButton->setEnabled( false );
121 topLayout->addWidget( mMergeButton, 1, 1 ); 123 topLayout->addWidget( mMergeButton, 1, 1 );
@@ -193,49 +195,49 @@ QString MergeWidget::title() const
193QString MergeWidget::identifier() const 195QString MergeWidget::identifier() const
194{ 196{
195 return "merge"; 197 return "merge";
196} 198}
197 199
198void MergeWidget::mergeAndRemove() 200void MergeWidget::mergeAndRemove()
199{ 201{
200#ifndef KAB_EMBEDDED 202#ifndef KAB_EMBEDDED
201 ContactItem *item = dynamic_cast<ContactItem*>( mContactView->currentItem() ); 203 ContactItem *item = dynamic_cast<ContactItem*>( mContactView->currentItem() );
202#else //KAB_EMBEDDED 204#else //KAB_EMBEDDED
203 ContactItem *item = (ContactItem*)( mContactView->currentItem() ); 205 ContactItem *item = (ContactItem*)( mContactView->currentItem() );
204#endif //KAB_EMBEDDED 206#endif //KAB_EMBEDDED
205 if ( !item ) 207 if ( !item )
206 return; 208 return;
207 209
208 QString oldUID = item->addressee().uid(); 210 QString oldUID = item->addressee().uid();
209 211
210 doMerge( item->addressee() ); 212 doMerge( item->addressee() );
211 213
212 KABC::Addressee::List retval; 214 KABC::Addressee::List retval;
213 retval << mMasterAddressee; 215 retval << mMasterAddressee;
214 emit modified( retval ); 216 emit modified( retval );
215 217
216 mBlockUpdate = true; 218 mBlockUpdate = true;
217 core()->deleteContacts( oldUID ); 219 core()->deleteContacts( QStringList(oldUID) );
218 core()->setContactSelected( mMasterAddressee.uid() ); 220 core()->setContactSelected( mMasterAddressee.uid() );
219 mBlockUpdate = false; 221 mBlockUpdate = false;
220 222
221 updateView(); 223 updateView();
222} 224}
223 225
224void MergeWidget::merge() 226void MergeWidget::merge()
225{ 227{
226#ifndef KAB_EMBEDDED 228#ifndef KAB_EMBEDDED
227 ContactItem *item = dynamic_cast<ContactItem*>( mContactView->currentItem() ); 229 ContactItem *item = dynamic_cast<ContactItem*>( mContactView->currentItem() );
228#else //KAB_EMBEDDED 230#else //KAB_EMBEDDED
229 ContactItem *item = (ContactItem*)( mContactView->currentItem() ); 231 ContactItem *item = (ContactItem*)( mContactView->currentItem() );
230#endif //KAB_EMBEDDED 232#endif //KAB_EMBEDDED
231 if ( !item ) 233 if ( !item )
232 return; 234 return;
233 235
234 doMerge( item->addressee() ); 236 doMerge( item->addressee() );
235 237
236 KABC::Addressee::List retval; 238 KABC::Addressee::List retval;
237 retval << mMasterAddressee; 239 retval << mMasterAddressee;
238 emit modified( retval ); 240 emit modified( retval );
239 241
240 mBlockUpdate = true; 242 mBlockUpdate = true;
241 core()->setContactSelected( mMasterAddressee.uid() ); 243 core()->setContactSelected( mMasterAddressee.uid() );
@@ -348,27 +350,27 @@ void MergeWidget::doMerge( const KABC::Addressee &addr )
348 // TITLE 350 // TITLE
349 if ( mMasterAddressee.title().isEmpty() && !addr.title().isEmpty() ) 351 if ( mMasterAddressee.title().isEmpty() && !addr.title().isEmpty() )
350 mMasterAddressee.setTitle( addr.title() ); 352 mMasterAddressee.setTitle( addr.title() );
351 353
352 // TZ 354 // TZ
353 if ( !mMasterAddressee.timeZone().isValid() && addr.timeZone().isValid() ) 355 if ( !mMasterAddressee.timeZone().isValid() && addr.timeZone().isValid() )
354 mMasterAddressee.setTimeZone( addr.timeZone() ); 356 mMasterAddressee.setTimeZone( addr.timeZone() );
355 357
356 // UID // ignore UID 358 // UID // ignore UID
357 359
358 // URL 360 // URL
359 if ( mMasterAddressee.url().isEmpty() && !addr.url().isEmpty() ) 361 if ( mMasterAddressee.url().isEmpty() && !addr.url().isEmpty() )
360 mMasterAddressee.setUrl( addr.url() ); 362 mMasterAddressee.setUrl( addr.url() );
361 363
362 // X- 364 // X-
363 QStringList customs = addr.customs(); 365 QStringList customs = addr.customs();
364 QStringList masterCustoms = mMasterAddressee.customs(); 366 QStringList masterCustoms = mMasterAddressee.customs();
365 QStringList newCustoms( masterCustoms ); 367 QStringList newCustoms( masterCustoms );
366 for ( it = customs.begin(); it != customs.end(); ++it ) 368 for ( it = customs.begin(); it != customs.end(); ++it )
367 if ( !masterCustoms.contains( *it ) ) 369 if ( !masterCustoms.contains( *it ) )
368 newCustoms.append( *it ); 370 newCustoms.append( *it );
369 mMasterAddressee.setCustoms( newCustoms ); 371 mMasterAddressee.setCustoms( newCustoms );
370} 372}
371 373
372#ifndef KAB_EMBEDDED 374#ifndef KAB_EMBEDDED_
373#include "mergewidget.moc" 375#include "moc_mergewidget.cpp"
374#endif //KAB_EMBEDDED 376#endif //KAB_EMBEDDED