summaryrefslogtreecommitdiffabout
path: root/kaddressbook
authorzautrix <zautrix>2004-10-10 16:00:04 (UTC)
committer zautrix <zautrix>2004-10-10 16:00:04 (UTC)
commitee6e29a5092d32165b7bf6b39069bd8a1dcd5b0a (patch) (unidiff)
tree1d908bfc23b8a49d43a58bbeadd82c4e08faeff6 /kaddressbook
parent213a9d993e5a4751b64e18320cfbebb000681d13 (diff)
downloadkdepimpi-ee6e29a5092d32165b7bf6b39069bd8a1dcd5b0a.zip
kdepimpi-ee6e29a5092d32165b7bf6b39069bd8a1dcd5b0a.tar.gz
kdepimpi-ee6e29a5092d32165b7bf6b39069bd8a1dcd5b0a.tar.bz2
many phone AB sync fixes
Diffstat (limited to 'kaddressbook') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp86
1 files changed, 17 insertions, 69 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index a7967cb..cd261f6 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -1,1276 +1,1221 @@
1/* 1/*
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/*s 24/*s
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (c) 2004 Ulf Schenk
27 27
28$Id$ 28$Id$
29*/ 29*/
30 30
31#include "kabcore.h" 31#include "kabcore.h"
32 32
33#include <stdaddressbook.h> 33#include <stdaddressbook.h>
34#include <klocale.h> 34#include <klocale.h>
35#include <kfiledialog.h> 35#include <kfiledialog.h>
36#include <qtimer.h> 36#include <qtimer.h>
37#include <qlabel.h> 37#include <qlabel.h>
38#include <qregexp.h> 38#include <qregexp.h>
39#include <qlineedit.h> 39#include <qlineedit.h>
40#include <qcheckbox.h> 40#include <qcheckbox.h>
41#include <qpushbutton.h> 41#include <qpushbutton.h>
42#include <qprogressbar.h> 42#include <qprogressbar.h>
43#include <libkdepim/phoneaccess.h> 43#include <libkdepim/phoneaccess.h>
44 44
45#ifndef KAB_EMBEDDED 45#ifndef KAB_EMBEDDED
46#include <qclipboard.h> 46#include <qclipboard.h>
47#include <qdir.h> 47#include <qdir.h>
48#include <qfile.h> 48#include <qfile.h>
49#include <qapplicaton.h> 49#include <qapplicaton.h>
50#include <qprogressbar.h> 50#include <qprogressbar.h>
51#include <qlayout.h> 51#include <qlayout.h>
52#include <qregexp.h> 52#include <qregexp.h>
53#include <qvbox.h> 53#include <qvbox.h>
54#include <kabc/addresseelist.h> 54#include <kabc/addresseelist.h>
55#include <kabc/errorhandler.h> 55#include <kabc/errorhandler.h>
56#include <kabc/resource.h> 56#include <kabc/resource.h>
57#include <kabc/vcardconverter.h> 57#include <kabc/vcardconverter.h>
58#include <kapplication.h> 58#include <kapplication.h>
59#include <kactionclasses.h> 59#include <kactionclasses.h>
60#include <kcmultidialog.h> 60#include <kcmultidialog.h>
61#include <kdebug.h> 61#include <kdebug.h>
62#include <kdeversion.h> 62#include <kdeversion.h>
63#include <kkeydialog.h> 63#include <kkeydialog.h>
64#include <kmessagebox.h> 64#include <kmessagebox.h>
65#include <kprinter.h> 65#include <kprinter.h>
66#include <kprotocolinfo.h> 66#include <kprotocolinfo.h>
67#include <kresources/selectdialog.h> 67#include <kresources/selectdialog.h>
68#include <kstandarddirs.h> 68#include <kstandarddirs.h>
69#include <ktempfile.h> 69#include <ktempfile.h>
70#include <kxmlguiclient.h> 70#include <kxmlguiclient.h>
71#include <kaboutdata.h> 71#include <kaboutdata.h>
72#include <libkdepim/categoryselectdialog.h> 72#include <libkdepim/categoryselectdialog.h>
73 73
74#include "addresseeutil.h" 74#include "addresseeutil.h"
75#include "addresseeeditordialog.h" 75#include "addresseeeditordialog.h"
76#include "extensionmanager.h" 76#include "extensionmanager.h"
77#include "kstdaction.h" 77#include "kstdaction.h"
78#include "kaddressbookservice.h" 78#include "kaddressbookservice.h"
79#include "ldapsearchdialog.h" 79#include "ldapsearchdialog.h"
80#include "printing/printingwizard.h" 80#include "printing/printingwizard.h"
81#else // KAB_EMBEDDED 81#else // KAB_EMBEDDED
82 82
83#include <kapplication.h> 83#include <kapplication.h>
84#include "KDGanttMinimizeSplitter.h" 84#include "KDGanttMinimizeSplitter.h"
85#include "kaddressbookmain.h" 85#include "kaddressbookmain.h"
86#include "kactioncollection.h" 86#include "kactioncollection.h"
87#include "addresseedialog.h" 87#include "addresseedialog.h"
88//US 88//US
89#include <addresseeview.h> 89#include <addresseeview.h>
90 90
91#include <qapp.h> 91#include <qapp.h>
92#include <qmenubar.h> 92#include <qmenubar.h>
93//#include <qtoolbar.h> 93//#include <qtoolbar.h>
94#include <qmessagebox.h> 94#include <qmessagebox.h>
95#include <kdebug.h> 95#include <kdebug.h>
96#include <kiconloader.h> // needed for SmallIcon 96#include <kiconloader.h> // needed for SmallIcon
97#include <kresources/kcmkresources.h> 97#include <kresources/kcmkresources.h>
98#include <ktoolbar.h> 98#include <ktoolbar.h>
99 99
100 100
101//#include <qlabel.h> 101//#include <qlabel.h>
102 102
103 103
104#ifndef DESKTOP_VERSION 104#ifndef DESKTOP_VERSION
105#include <qpe/ir.h> 105#include <qpe/ir.h>
106#include <qpe/qpemenubar.h> 106#include <qpe/qpemenubar.h>
107#include <qtopia/qcopenvelope_qws.h> 107#include <qtopia/qcopenvelope_qws.h>
108#else 108#else
109 109
110#include <qmenubar.h> 110#include <qmenubar.h>
111#endif 111#endif
112 112
113#endif // KAB_EMBEDDED 113#endif // KAB_EMBEDDED
114#include "kcmconfigs/kcmkabconfig.h" 114#include "kcmconfigs/kcmkabconfig.h"
115#include "kcmconfigs/kcmkdepimconfig.h" 115#include "kcmconfigs/kcmkdepimconfig.h"
116#include "kpimglobalprefs.h" 116#include "kpimglobalprefs.h"
117#include "externalapphandler.h" 117#include "externalapphandler.h"
118 118
119 119
120#include <kresources/selectdialog.h> 120#include <kresources/selectdialog.h>
121#include <kmessagebox.h> 121#include <kmessagebox.h>
122 122
123#include <picture.h> 123#include <picture.h>
124#include <resource.h> 124#include <resource.h>
125 125
126//US#include <qsplitter.h> 126//US#include <qsplitter.h>
127#include <qmap.h> 127#include <qmap.h>
128#include <qdir.h> 128#include <qdir.h>
129#include <qfile.h> 129#include <qfile.h>
130#include <qvbox.h> 130#include <qvbox.h>
131#include <qlayout.h> 131#include <qlayout.h>
132#include <qclipboard.h> 132#include <qclipboard.h>
133#include <qtextstream.h> 133#include <qtextstream.h>
134 134
135#include <libkdepim/categoryselectdialog.h> 135#include <libkdepim/categoryselectdialog.h>
136#include <kabc/vcardconverter.h> 136#include <kabc/vcardconverter.h>
137 137
138 138
139#include "addresseeutil.h" 139#include "addresseeutil.h"
140#include "undocmds.h" 140#include "undocmds.h"
141#include "addresseeeditordialog.h" 141#include "addresseeeditordialog.h"
142#include "viewmanager.h" 142#include "viewmanager.h"
143#include "details/detailsviewcontainer.h" 143#include "details/detailsviewcontainer.h"
144#include "kabprefs.h" 144#include "kabprefs.h"
145#include "xxportmanager.h" 145#include "xxportmanager.h"
146#include "incsearchwidget.h" 146#include "incsearchwidget.h"
147#include "jumpbuttonbar.h" 147#include "jumpbuttonbar.h"
148#include "extensionmanager.h" 148#include "extensionmanager.h"
149#include "addresseeconfig.h" 149#include "addresseeconfig.h"
150#include <kcmultidialog.h> 150#include <kcmultidialog.h>
151 151
152#ifdef _WIN32_ 152#ifdef _WIN32_
153 153
154#include "kaimportoldialog.h" 154#include "kaimportoldialog.h"
155#else 155#else
156#include <unistd.h> 156#include <unistd.h>
157#endif 157#endif
158// sync includes 158// sync includes
159#include <libkdepim/ksyncprofile.h> 159#include <libkdepim/ksyncprofile.h>
160#include <libkdepim/ksyncprefsdialog.h> 160#include <libkdepim/ksyncprefsdialog.h>
161 161
162class KAex2phonePrefs : public QDialog 162class KAex2phonePrefs : public QDialog
163{ 163{
164 public: 164 public:
165 KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) : 165 KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) :
166 QDialog( parent, name, true ) 166 QDialog( parent, name, true )
167 { 167 {
168 setCaption( i18n("Export to phone options") ); 168 setCaption( i18n("Export to phone options") );
169 QVBoxLayout* lay = new QVBoxLayout( this ); 169 QVBoxLayout* lay = new QVBoxLayout( this );
170 lay->setSpacing( 3 ); 170 lay->setSpacing( 3 );
171 lay->setMargin( 3 ); 171 lay->setMargin( 3 );
172 QLabel *lab; 172 QLabel *lab;
173 lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) ); 173 lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) );
174 lab->setAlignment (AlignHCenter ); 174 lab->setAlignment (AlignHCenter );
175 QHBox* temphb; 175 QHBox* temphb;
176 temphb = new QHBox( this ); 176 temphb = new QHBox( this );
177 new QLabel( i18n("I/O device: "), temphb ); 177 new QLabel( i18n("I/O device: "), temphb );
178 mPhoneDevice = new QLineEdit( temphb); 178 mPhoneDevice = new QLineEdit( temphb);
179 lay->addWidget( temphb ); 179 lay->addWidget( temphb );
180 temphb = new QHBox( this ); 180 temphb = new QHBox( this );
181 new QLabel( i18n("Connection: "), temphb ); 181 new QLabel( i18n("Connection: "), temphb );
182 mPhoneConnection = new QLineEdit( temphb); 182 mPhoneConnection = new QLineEdit( temphb);
183 lay->addWidget( temphb ); 183 lay->addWidget( temphb );
184 temphb = new QHBox( this ); 184 temphb = new QHBox( this );
185 new QLabel( i18n("Model(opt.): "), temphb ); 185 new QLabel( i18n("Model(opt.): "), temphb );
186 mPhoneModel = new QLineEdit( temphb); 186 mPhoneModel = new QLineEdit( temphb);
187 lay->addWidget( temphb ); 187 lay->addWidget( temphb );
188 mWriteToSim= new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this ); 188 // mWriteToSim = new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this );
189 lay->addWidget( mWriteToSim ); 189 // lay->addWidget( mWriteToSim );
190 lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) ); 190 lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) );
191 lab->setAlignment (AlignHCenter ); 191 lab->setAlignment (AlignHCenter );
192 QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this ); 192 QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this );
193 lay->addWidget( ok ); 193 lay->addWidget( ok );
194 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 194 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
195 lay->addWidget( cancel ); 195 lay->addWidget( cancel );
196 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 196 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
197 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 197 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
198 resize( 220, 240 ); 198 resize( 220, 240 );
199 199
200 } 200 }
201 201
202public: 202public:
203 QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel; 203 QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel;
204 QCheckBox* mWriteToSim; 204 QCheckBox* mWriteToSim;
205}; 205};
206 206
207bool pasteWithNewUid = true; 207bool pasteWithNewUid = true;
208 208
209#ifdef KAB_EMBEDDED 209#ifdef KAB_EMBEDDED
210KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) 210KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name )
211 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), 211 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ),
212 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/ 212 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/
213 mReadWrite( readWrite ), mModified( false ), mMainWindow(client) 213 mReadWrite( readWrite ), mModified( false ), mMainWindow(client)
214#else //KAB_EMBEDDED 214#else //KAB_EMBEDDED
215KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name ) 215KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name )
216 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), 216 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ),
217 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), 217 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ),
218 mReadWrite( readWrite ), mModified( false ) 218 mReadWrite( readWrite ), mModified( false )
219#endif //KAB_EMBEDDED 219#endif //KAB_EMBEDDED
220{ 220{
221 // syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); 221 // syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu);
222 // syncManager->setBlockSave(false); 222 // syncManager->setBlockSave(false);
223 mExtensionBarSplitter = 0; 223 mExtensionBarSplitter = 0;
224 mIsPart = !parent->inherits( "KAddressBookMain" ); 224 mIsPart = !parent->inherits( "KAddressBookMain" );
225 225
226 mAddressBook = KABC::StdAddressBook::self(); 226 mAddressBook = KABC::StdAddressBook::self();
227 KABC::StdAddressBook::setAutomaticSave( false ); 227 KABC::StdAddressBook::setAutomaticSave( false );
228 228
229#ifndef KAB_EMBEDDED 229#ifndef KAB_EMBEDDED
230 mAddressBook->setErrorHandler( new KABC::GUIErrorHandler ); 230 mAddressBook->setErrorHandler( new KABC::GUIErrorHandler );
231#endif //KAB_EMBEDDED 231#endif //KAB_EMBEDDED
232 232
233 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ), 233 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ),
234 SLOT( addressBookChanged() ) ); 234 SLOT( addressBookChanged() ) );
235 235
236#if 0 236#if 0
237 // LP moved to addressbook init method 237 // LP moved to addressbook init method
238 mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization, 238 mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization,
239 "X-Department", "KADDRESSBOOK" ); 239 "X-Department", "KADDRESSBOOK" );
240 mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization, 240 mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization,
241 "X-Profession", "KADDRESSBOOK" ); 241 "X-Profession", "KADDRESSBOOK" );
242 mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 242 mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
243 "X-AssistantsName", "KADDRESSBOOK" ); 243 "X-AssistantsName", "KADDRESSBOOK" );
244 mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 244 mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
245 "X-ManagersName", "KADDRESSBOOK" ); 245 "X-ManagersName", "KADDRESSBOOK" );
246 mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 246 mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
247 "X-SpousesName", "KADDRESSBOOK" ); 247 "X-SpousesName", "KADDRESSBOOK" );
248 mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal, 248 mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal,
249 "X-Office", "KADDRESSBOOK" ); 249 "X-Office", "KADDRESSBOOK" );
250 mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 250 mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
251 "X-IMAddress", "KADDRESSBOOK" ); 251 "X-IMAddress", "KADDRESSBOOK" );
252 mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 252 mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
253 "X-Anniversary", "KADDRESSBOOK" ); 253 "X-Anniversary", "KADDRESSBOOK" );
254 254
255 //US added this field to become compatible with Opie/qtopia addressbook 255 //US added this field to become compatible with Opie/qtopia addressbook
256 // values can be "female" or "male" or "". An empty field represents undefined. 256 // values can be "female" or "male" or "". An empty field represents undefined.
257 mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal, 257 mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal,
258 "X-Gender", "KADDRESSBOOK" ); 258 "X-Gender", "KADDRESSBOOK" );
259 mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal, 259 mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal,
260 "X-Children", "KADDRESSBOOK" ); 260 "X-Children", "KADDRESSBOOK" );
261 mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 261 mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
262 "X-FreeBusyUrl", "KADDRESSBOOK" ); 262 "X-FreeBusyUrl", "KADDRESSBOOK" );
263#endif 263#endif
264 initGUI(); 264 initGUI();
265 265
266 mIncSearchWidget->setFocus(); 266 mIncSearchWidget->setFocus();
267 267
268 268
269 connect( mViewManager, SIGNAL( selected( const QString& ) ), 269 connect( mViewManager, SIGNAL( selected( const QString& ) ),
270 SLOT( setContactSelected( const QString& ) ) ); 270 SLOT( setContactSelected( const QString& ) ) );
271 connect( mViewManager, SIGNAL( executed( const QString& ) ), 271 connect( mViewManager, SIGNAL( executed( const QString& ) ),
272 SLOT( executeContact( const QString& ) ) ); 272 SLOT( executeContact( const QString& ) ) );
273 273
274 connect( mViewManager, SIGNAL( deleteRequest( ) ), 274 connect( mViewManager, SIGNAL( deleteRequest( ) ),
275 SLOT( deleteContacts( ) ) ); 275 SLOT( deleteContacts( ) ) );
276 connect( mViewManager, SIGNAL( modified() ), 276 connect( mViewManager, SIGNAL( modified() ),
277 SLOT( setModified() ) ); 277 SLOT( setModified() ) );
278 278
279 connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) ); 279 connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) );
280 connect( mExtensionManager, SIGNAL( changedActiveExtension( int ) ), this, SLOT( extensionChanged( int ) ) ); 280 connect( mExtensionManager, SIGNAL( changedActiveExtension( int ) ), this, SLOT( extensionChanged( int ) ) );
281 281
282 connect( mXXPortManager, SIGNAL( modified() ), 282 connect( mXXPortManager, SIGNAL( modified() ),
283 SLOT( setModified() ) ); 283 SLOT( setModified() ) );
284 284
285 connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ), 285 connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ),
286 SLOT( incrementalSearch( const QString& ) ) ); 286 SLOT( incrementalSearch( const QString& ) ) );
287 connect( mIncSearchWidget, SIGNAL( fieldChanged() ), 287 connect( mIncSearchWidget, SIGNAL( fieldChanged() ),
288 mJumpButtonBar, SLOT( recreateButtons() ) ); 288 mJumpButtonBar, SLOT( recreateButtons() ) );
289 289
290 connect( mDetails, SIGNAL( sendEmail( const QString& ) ), 290 connect( mDetails, SIGNAL( sendEmail( const QString& ) ),
291 SLOT( sendMail( const QString& ) ) ); 291 SLOT( sendMail( const QString& ) ) );
292 292
293 293
294 connect( ExternalAppHandler::instance(), SIGNAL (requestForNameEmailUidList(const QString&, const QString&)),this, SLOT(requestForNameEmailUidList(const QString&, const QString&))); 294 connect( ExternalAppHandler::instance(), SIGNAL (requestForNameEmailUidList(const QString&, const QString&)),this, SLOT(requestForNameEmailUidList(const QString&, const QString&)));
295 connect( ExternalAppHandler::instance(), SIGNAL (requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&)),this, SLOT(requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&))); 295 connect( ExternalAppHandler::instance(), SIGNAL (requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&)),this, SLOT(requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&)));
296 connect( ExternalAppHandler::instance(), SIGNAL (requestForBirthdayList(const QString&, const QString&)),this, SLOT(requestForBirthdayList(const QString&, const QString&))); 296 connect( ExternalAppHandler::instance(), SIGNAL (requestForBirthdayList(const QString&, const QString&)),this, SLOT(requestForBirthdayList(const QString&, const QString&)));
297 297
298 298
299#ifndef KAB_EMBEDDED 299#ifndef KAB_EMBEDDED
300 connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ), 300 connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ),
301 mXXPortManager, SLOT( importVCard( const KURL& ) ) ); 301 mXXPortManager, SLOT( importVCard( const KURL& ) ) );
302 302
303 connect( mDetails, SIGNAL( browse( const QString& ) ), 303 connect( mDetails, SIGNAL( browse( const QString& ) ),
304 SLOT( browse( const QString& ) ) ); 304 SLOT( browse( const QString& ) ) );
305 305
306 306
307 mAddressBookService = new KAddressBookService( this ); 307 mAddressBookService = new KAddressBookService( this );
308 308
309#endif //KAB_EMBEDDED 309#endif //KAB_EMBEDDED
310 mEditorDialog = 0; 310 mEditorDialog = 0;
311 createAddresseeEditorDialog( this ); 311 createAddresseeEditorDialog( this );
312 setModified( false ); 312 setModified( false );
313} 313}
314 314
315KABCore::~KABCore() 315KABCore::~KABCore()
316{ 316{
317 // save(); 317 // save();
318 //saveSettings(); 318 //saveSettings();
319 //KABPrefs::instance()->writeConfig(); 319 //KABPrefs::instance()->writeConfig();
320 delete AddresseeConfig::instance(); 320 delete AddresseeConfig::instance();
321 mAddressBook = 0; 321 mAddressBook = 0;
322 KABC::StdAddressBook::close(); 322 KABC::StdAddressBook::close();
323 323
324 delete syncManager; 324 delete syncManager;
325 325
326} 326}
327 327
328void KABCore::recieve( QString fn ) 328void KABCore::recieve( QString fn )
329{ 329{
330 //qDebug("KABCore::recieve "); 330 //qDebug("KABCore::recieve ");
331 mAddressBook->importFromFile( fn, true ); 331 mAddressBook->importFromFile( fn, true );
332 mViewManager->refreshView(); 332 mViewManager->refreshView();
333 topLevelWidget()->raise(); 333 topLevelWidget()->raise();
334} 334}
335void KABCore::restoreSettings() 335void KABCore::restoreSettings()
336{ 336{
337 mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce; 337 mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce;
338 338
339 bool state; 339 bool state;
340 340
341 if (mMultipleViewsAtOnce) 341 if (mMultipleViewsAtOnce)
342 state = KABPrefs::instance()->mDetailsPageVisible; 342 state = KABPrefs::instance()->mDetailsPageVisible;
343 else 343 else
344 state = false; 344 state = false;
345 345
346 mActionDetails->setChecked( state ); 346 mActionDetails->setChecked( state );
347 setDetailsVisible( state ); 347 setDetailsVisible( state );
348 348
349 state = KABPrefs::instance()->mJumpButtonBarVisible; 349 state = KABPrefs::instance()->mJumpButtonBarVisible;
350 350
351 mActionJumpBar->setChecked( state ); 351 mActionJumpBar->setChecked( state );
352 setJumpButtonBarVisible( state ); 352 setJumpButtonBarVisible( state );
353/*US 353/*US
354 QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter; 354 QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter;
355 if ( splitterSize.count() == 0 ) { 355 if ( splitterSize.count() == 0 ) {
356 splitterSize.append( width() / 2 ); 356 splitterSize.append( width() / 2 );
357 splitterSize.append( width() / 2 ); 357 splitterSize.append( width() / 2 );
358 } 358 }
359 mMiniSplitter->setSizes( splitterSize ); 359 mMiniSplitter->setSizes( splitterSize );
360 if ( mExtensionBarSplitter ) { 360 if ( mExtensionBarSplitter ) {
361 splitterSize = KABPrefs::instance()->mExtensionsSplitter; 361 splitterSize = KABPrefs::instance()->mExtensionsSplitter;
362 if ( splitterSize.count() == 0 ) { 362 if ( splitterSize.count() == 0 ) {
363 splitterSize.append( width() / 2 ); 363 splitterSize.append( width() / 2 );
364 splitterSize.append( width() / 2 ); 364 splitterSize.append( width() / 2 );
365 } 365 }
366 mExtensionBarSplitter->setSizes( splitterSize ); 366 mExtensionBarSplitter->setSizes( splitterSize );
367 367
368 } 368 }
369*/ 369*/
370 mViewManager->restoreSettings(); 370 mViewManager->restoreSettings();
371 mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField ); 371 mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField );
372 mExtensionManager->restoreSettings(); 372 mExtensionManager->restoreSettings();
373#ifdef DESKTOP_VERSION 373#ifdef DESKTOP_VERSION
374 int wid = width(); 374 int wid = width();
375 if ( wid < 10 ) 375 if ( wid < 10 )
376 wid = 400; 376 wid = 400;
377#else 377#else
378 int wid = QApplication::desktop()->width(); 378 int wid = QApplication::desktop()->width();
379 if ( wid < 640 ) 379 if ( wid < 640 )
380 wid = QApplication::desktop()->height(); 380 wid = QApplication::desktop()->height();
381#endif 381#endif
382 QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter; 382 QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter;
383 if ( true /*splitterSize.count() == 0*/ ) { 383 if ( true /*splitterSize.count() == 0*/ ) {
384 splitterSize.append( wid / 2 ); 384 splitterSize.append( wid / 2 );
385 splitterSize.append( wid / 2 ); 385 splitterSize.append( wid / 2 );
386 } 386 }
387 mMiniSplitter->setSizes( splitterSize ); 387 mMiniSplitter->setSizes( splitterSize );
388 if ( mExtensionBarSplitter ) { 388 if ( mExtensionBarSplitter ) {
389 //splitterSize = KABPrefs::instance()->mExtensionsSplitter; 389 //splitterSize = KABPrefs::instance()->mExtensionsSplitter;
390 if ( true /*splitterSize.count() == 0*/ ) { 390 if ( true /*splitterSize.count() == 0*/ ) {
391 splitterSize.append( wid / 2 ); 391 splitterSize.append( wid / 2 );
392 splitterSize.append( wid / 2 ); 392 splitterSize.append( wid / 2 );
393 } 393 }
394 mExtensionBarSplitter->setSizes( splitterSize ); 394 mExtensionBarSplitter->setSizes( splitterSize );
395 395
396 } 396 }
397 397
398 398
399} 399}
400 400
401void KABCore::saveSettings() 401void KABCore::saveSettings()
402{ 402{
403 KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked(); 403 KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked();
404 if ( mExtensionBarSplitter ) 404 if ( mExtensionBarSplitter )
405 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); 405 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
406 KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked(); 406 KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked();
407 KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes(); 407 KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes();
408#ifndef KAB_EMBEDDED 408#ifndef KAB_EMBEDDED
409 409
410 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); 410 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
411 KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes(); 411 KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes();
412#endif //KAB_EMBEDDED 412#endif //KAB_EMBEDDED
413 mExtensionManager->saveSettings(); 413 mExtensionManager->saveSettings();
414 mViewManager->saveSettings(); 414 mViewManager->saveSettings();
415 415
416 KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem(); 416 KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem();
417} 417}
418 418
419KABC::AddressBook *KABCore::addressBook() const 419KABC::AddressBook *KABCore::addressBook() const
420{ 420{
421 return mAddressBook; 421 return mAddressBook;
422} 422}
423 423
424KConfig *KABCore::config() 424KConfig *KABCore::config()
425{ 425{
426#ifndef KAB_EMBEDDED 426#ifndef KAB_EMBEDDED
427 return KABPrefs::instance()->config(); 427 return KABPrefs::instance()->config();
428#else //KAB_EMBEDDED 428#else //KAB_EMBEDDED
429 return KABPrefs::instance()->getConfig(); 429 return KABPrefs::instance()->getConfig();
430#endif //KAB_EMBEDDED 430#endif //KAB_EMBEDDED
431} 431}
432 432
433KActionCollection *KABCore::actionCollection() const 433KActionCollection *KABCore::actionCollection() const
434{ 434{
435 return mGUIClient->actionCollection(); 435 return mGUIClient->actionCollection();
436} 436}
437 437
438KABC::Field *KABCore::currentSearchField() const 438KABC::Field *KABCore::currentSearchField() const
439{ 439{
440 if (mIncSearchWidget) 440 if (mIncSearchWidget)
441 return mIncSearchWidget->currentField(); 441 return mIncSearchWidget->currentField();
442 else 442 else
443 return 0; 443 return 0;
444} 444}
445 445
446QStringList KABCore::selectedUIDs() const 446QStringList KABCore::selectedUIDs() const
447{ 447{
448 return mViewManager->selectedUids(); 448 return mViewManager->selectedUids();
449} 449}
450 450
451KABC::Resource *KABCore::requestResource( QWidget *parent ) 451KABC::Resource *KABCore::requestResource( QWidget *parent )
452{ 452{
453 QPtrList<KABC::Resource> kabcResources = addressBook()->resources(); 453 QPtrList<KABC::Resource> kabcResources = addressBook()->resources();
454 454
455 QPtrList<KRES::Resource> kresResources; 455 QPtrList<KRES::Resource> kresResources;
456 QPtrListIterator<KABC::Resource> resIt( kabcResources ); 456 QPtrListIterator<KABC::Resource> resIt( kabcResources );
457 KABC::Resource *resource; 457 KABC::Resource *resource;
458 while ( ( resource = resIt.current() ) != 0 ) { 458 while ( ( resource = resIt.current() ) != 0 ) {
459 ++resIt; 459 ++resIt;
460 if ( !resource->readOnly() ) { 460 if ( !resource->readOnly() ) {
461 KRES::Resource *res = static_cast<KRES::Resource*>( resource ); 461 KRES::Resource *res = static_cast<KRES::Resource*>( resource );
462 if ( res ) 462 if ( res )
463 kresResources.append( res ); 463 kresResources.append( res );
464 } 464 }
465 } 465 }
466 466
467 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent ); 467 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent );
468 return static_cast<KABC::Resource*>( res ); 468 return static_cast<KABC::Resource*>( res );
469} 469}
470 470
471#ifndef KAB_EMBEDDED 471#ifndef KAB_EMBEDDED
472KAboutData *KABCore::createAboutData() 472KAboutData *KABCore::createAboutData()
473#else //KAB_EMBEDDED 473#else //KAB_EMBEDDED
474void KABCore::createAboutData() 474void KABCore::createAboutData()
475#endif //KAB_EMBEDDED 475#endif //KAB_EMBEDDED
476{ 476{
477#ifndef KAB_EMBEDDED 477#ifndef KAB_EMBEDDED
478 KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ), 478 KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ),
479 "3.1", I18N_NOOP( "The KDE Address Book" ), 479 "3.1", I18N_NOOP( "The KDE Address Book" ),
480 KAboutData::License_GPL_V2, 480 KAboutData::License_GPL_V2,
481 I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) ); 481 I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) );
482 about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" ); 482 about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" );
483 about->addAuthor( "Don Sanders", I18N_NOOP( "Original author " ) ); 483 about->addAuthor( "Don Sanders", I18N_NOOP( "Original author " ) );
484 about->addAuthor( "Cornelius Schumacher", 484 about->addAuthor( "Cornelius Schumacher",
485 I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export " ), 485 I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export " ),
486 "schumacher@kde.org" ); 486 "schumacher@kde.org" );
487 about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign " ), 487 about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign " ),
488 "mpilone@slac.com" ); 488 "mpilone@slac.com" );
489 about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) ); 489 about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) );
490 about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) ); 490 about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) );
491 about->addAuthor( "Michel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup\n" ), 491 about->addAuthor( "Michel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup\n" ),
492 "michel@klaralvdalens-datakonsult.se" ); 492 "michel@klaralvdalens-datakonsult.se" );
493 about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup " ), 493 about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup " ),
494 "hansen@kde.org" ); 494 "hansen@kde.org" );
495 495
496 return about; 496 return about;
497#endif //KAB_EMBEDDED 497#endif //KAB_EMBEDDED
498 498
499 QString version; 499 QString version;
500#include <../version> 500#include <../version>
501 QMessageBox::about( this, "About KAddressbook/Pi", 501 QMessageBox::about( this, "About KAddressbook/Pi",
502 "KAddressbook/Platform-independent\n" 502 "KAddressbook/Platform-independent\n"
503 "(KA/Pi) " +version + " - " + 503 "(KA/Pi) " +version + " - " +
504#ifdef DESKTOP_VERSION 504#ifdef DESKTOP_VERSION
505 "Desktop Edition\n" 505 "Desktop Edition\n"
506#else 506#else
507 "PDA-Edition\n" 507 "PDA-Edition\n"
508 "for: Zaurus 5500 / 7x0 / 8x0\n" 508 "for: Zaurus 5500 / 7x0 / 8x0\n"
509#endif 509#endif
510 510
511 "(c) 2004 Ulf Schenk\n" 511 "(c) 2004 Ulf Schenk\n"
512 "(c) 2004 Lutz Rogowski\n" 512 "(c) 2004 Lutz Rogowski\n"
513 "(c) 1997-2003, The KDE PIM Team\n" 513 "(c) 1997-2003, The KDE PIM Team\n"
514 "Tobias Koenig Current maintainer\ntokoe@kde.org\n" 514 "Tobias Koenig Current maintainer\ntokoe@kde.org\n"
515 "Don Sanders Original author\n" 515 "Don Sanders Original author\n"
516 "Cornelius Schumacher Co-maintainer\nschumacher@kde.org\n" 516 "Cornelius Schumacher Co-maintainer\nschumacher@kde.org\n"
517 "Mike Pilone GUI and framework redesign\nmpilone@slac.com\n" 517 "Mike Pilone GUI and framework redesign\nmpilone@slac.com\n"
518 "Greg Stern DCOP interface\n" 518 "Greg Stern DCOP interface\n"
519 "Mark Westcot Contact pinning\n" 519 "Mark Westcot Contact pinning\n"
520 "Michel Boyer de la Giroday LDAP Lookup\n" "michel@klaralvdalens-datakonsult.se\n" 520 "Michel Boyer de la Giroday LDAP Lookup\n" "michel@klaralvdalens-datakonsult.se\n"
521 "Steffen Hansen LDAP Lookup\nhansen@kde.org\n" 521 "Steffen Hansen LDAP Lookup\nhansen@kde.org\n"
522#ifdef _WIN32_ 522#ifdef _WIN32_
523 "(c) 2004 Lutz Rogowski Import from OL\nrogowski@kde.org\n" 523 "(c) 2004 Lutz Rogowski Import from OL\nrogowski@kde.org\n"
524#endif 524#endif
525 ); 525 );
526} 526}
527 527
528void KABCore::setContactSelected( const QString &uid ) 528void KABCore::setContactSelected( const QString &uid )
529{ 529{
530 KABC::Addressee addr = mAddressBook->findByUid( uid ); 530 KABC::Addressee addr = mAddressBook->findByUid( uid );
531 if ( !mDetails->isHidden() ) 531 if ( !mDetails->isHidden() )
532 mDetails->setAddressee( addr ); 532 mDetails->setAddressee( addr );
533 533
534 if ( !addr.isEmpty() ) { 534 if ( !addr.isEmpty() ) {
535 emit contactSelected( addr.formattedName() ); 535 emit contactSelected( addr.formattedName() );
536 KABC::Picture pic = addr.photo(); 536 KABC::Picture pic = addr.photo();
537 if ( pic.isIntern() ) { 537 if ( pic.isIntern() ) {
538//US emit contactSelected( pic.data() ); 538//US emit contactSelected( pic.data() );
539//US instead use: 539//US instead use:
540 QPixmap px; 540 QPixmap px;
541 if (pic.data().isNull() != true) 541 if (pic.data().isNull() != true)
542 { 542 {
543 px.convertFromImage(pic.data()); 543 px.convertFromImage(pic.data());
544 } 544 }
545 545
546 emit contactSelected( px ); 546 emit contactSelected( px );
547 } 547 }
548 } 548 }
549 549
550 550
551 mExtensionManager->setSelectionChanged(); 551 mExtensionManager->setSelectionChanged();
552 552
553 // update the actions 553 // update the actions
554 bool selected = !uid.isEmpty(); 554 bool selected = !uid.isEmpty();
555 555
556 if ( mReadWrite ) { 556 if ( mReadWrite ) {
557 mActionCut->setEnabled( selected ); 557 mActionCut->setEnabled( selected );
558 mActionPaste->setEnabled( selected ); 558 mActionPaste->setEnabled( selected );
559 } 559 }
560 560
561 mActionCopy->setEnabled( selected ); 561 mActionCopy->setEnabled( selected );
562 mActionDelete->setEnabled( selected ); 562 mActionDelete->setEnabled( selected );
563 mActionEditAddressee->setEnabled( selected ); 563 mActionEditAddressee->setEnabled( selected );
564 mActionMail->setEnabled( selected ); 564 mActionMail->setEnabled( selected );
565 mActionMailVCard->setEnabled( selected ); 565 mActionMailVCard->setEnabled( selected );
566 //if (mActionBeam) 566 //if (mActionBeam)
567 //mActionBeam->setEnabled( selected ); 567 //mActionBeam->setEnabled( selected );
568 568
569 if (mActionBeamVCard) 569 if (mActionBeamVCard)
570 mActionBeamVCard->setEnabled( selected ); 570 mActionBeamVCard->setEnabled( selected );
571 571
572 mActionExport2phone->setEnabled( selected ); 572 mActionExport2phone->setEnabled( selected );
573 mActionWhoAmI->setEnabled( selected ); 573 mActionWhoAmI->setEnabled( selected );
574 mActionCategories->setEnabled( selected ); 574 mActionCategories->setEnabled( selected );
575} 575}
576 576
577void KABCore::sendMail() 577void KABCore::sendMail()
578{ 578{
579 sendMail( mViewManager->selectedEmails().join( ", " ) ); 579 sendMail( mViewManager->selectedEmails().join( ", " ) );
580} 580}
581 581
582void KABCore::sendMail( const QString& emaillist ) 582void KABCore::sendMail( const QString& emaillist )
583{ 583{
584 // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... " 584 // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... "
585 if (emaillist.contains(",") > 0) 585 if (emaillist.contains(",") > 0)
586 ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null ); 586 ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null );
587 else 587 else
588 ExternalAppHandler::instance()->mailToOneContact( emaillist ); 588 ExternalAppHandler::instance()->mailToOneContact( emaillist );
589} 589}
590 590
591 591
592 592
593void KABCore::mailVCard() 593void KABCore::mailVCard()
594{ 594{
595 QStringList uids = mViewManager->selectedUids(); 595 QStringList uids = mViewManager->selectedUids();
596 if ( !uids.isEmpty() ) 596 if ( !uids.isEmpty() )
597 mailVCard( uids ); 597 mailVCard( uids );
598} 598}
599 599
600void KABCore::mailVCard( const QStringList& uids ) 600void KABCore::mailVCard( const QStringList& uids )
601{ 601{
602 QStringList urls; 602 QStringList urls;
603 603
604// QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); 604// QString tmpdir = locateLocal("tmp", KGlobal::getAppName());
605 605
606 QString dirName = "/tmp/" + KApplication::randomString( 8 ); 606 QString dirName = "/tmp/" + KApplication::randomString( 8 );
607 607
608 608
609 609
610 QDir().mkdir( dirName, true ); 610 QDir().mkdir( dirName, true );
611 611
612 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 612 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
613 KABC::Addressee a = mAddressBook->findByUid( *it ); 613 KABC::Addressee a = mAddressBook->findByUid( *it );
614 614
615 if ( a.isEmpty() ) 615 if ( a.isEmpty() )
616 continue; 616 continue;
617 617
618 QString name = a.givenName() + "_" + a.familyName() + ".vcf"; 618 QString name = a.givenName() + "_" + a.familyName() + ".vcf";
619 619
620 QString fileName = dirName + "/" + name; 620 QString fileName = dirName + "/" + name;
621 621
622 QFile outFile(fileName); 622 QFile outFile(fileName);
623 623
624 if ( outFile.open(IO_WriteOnly) ) { // file opened successfully 624 if ( outFile.open(IO_WriteOnly) ) { // file opened successfully
625 KABC::VCardConverter converter; 625 KABC::VCardConverter converter;
626 QString vcard; 626 QString vcard;
627 627
628 converter.addresseeToVCard( a, vcard ); 628 converter.addresseeToVCard( a, vcard );
629 629
630 QTextStream t( &outFile ); // use a text stream 630 QTextStream t( &outFile ); // use a text stream
631 t.setEncoding( QTextStream::UnicodeUTF8 ); 631 t.setEncoding( QTextStream::UnicodeUTF8 );
632 t << vcard; 632 t << vcard;
633 633
634 outFile.close(); 634 outFile.close();
635 635
636 urls.append( fileName ); 636 urls.append( fileName );
637 } 637 }
638 } 638 }
639 639
640 bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") ); 640 bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") );
641 641
642 642
643/*US 643/*US
644 kapp->invokeMailer( QString::null, QString::null, QString::null, 644 kapp->invokeMailer( QString::null, QString::null, QString::null,
645 QString::null, // subject 645 QString::null, // subject
646 QString::null, // body 646 QString::null, // body
647 QString::null, 647 QString::null,
648 urls ); // attachments 648 urls ); // attachments
649*/ 649*/
650 650
651} 651}
652 652
653/** 653/**
654 Beams the "WhoAmI contact. 654 Beams the "WhoAmI contact.
655*/ 655*/
656void KABCore::beamMySelf() 656void KABCore::beamMySelf()
657{ 657{
658 KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI(); 658 KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI();
659 if (!a.isEmpty()) 659 if (!a.isEmpty())
660 { 660 {
661 QStringList uids; 661 QStringList uids;
662 uids << a.uid(); 662 uids << a.uid();
663 663
664 beamVCard(uids); 664 beamVCard(uids);
665 } else { 665 } else {
666 KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) ); 666 KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) );
667 667
668 668
669 } 669 }
670} 670}
671 671
672void KABCore::export2phone() 672void KABCore::export2phone()
673{ 673{
674 674
675 KAex2phonePrefs ex2phone; 675 KAex2phonePrefs ex2phone;
676 ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection ); 676 ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection );
677 ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice ); 677 ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice );
678 ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel ); 678 ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel );
679 679
680 if ( !ex2phone.exec() ) { 680 if ( !ex2phone.exec() ) {
681 return; 681 return;
682 } 682 }
683 KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text(); 683 KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text();
684 KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text(); 684 KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text();
685 KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text(); 685 KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text();
686 686
687 687
688 PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice, 688 PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice,
689 KPimGlobalPrefs::instance()->mEx2PhoneConnection, 689 KPimGlobalPrefs::instance()->mEx2PhoneConnection,
690 KPimGlobalPrefs::instance()->mEx2PhoneModel ); 690 KPimGlobalPrefs::instance()->mEx2PhoneModel );
691 691
692 QStringList uids = mViewManager->selectedUids(); 692 QStringList uids = mViewManager->selectedUids();
693 if ( uids.isEmpty() ) 693 if ( uids.isEmpty() )
694 return; 694 return;
695 695
696#ifdef _WIN32_ 696#ifdef _WIN32_
697 QString fileName = locateLocal("tmp", "tempfile.vcf"); 697 QString fileName = locateLocal("tmp", "phonefile.vcf");
698#else 698#else
699 QString fileName = "/tmp/kdepimtemp.vcf"; 699 QString fileName = "/tmp/phonefile.vcf";
700#endif 700#endif
701 701
702 KABC::VCardConverter converter; 702 if ( ! mAddressBook->export2PhoneFormat( uids ,fileName ) )
703 QString description;
704 QString datastream;
705 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
706 KABC::Addressee a = mAddressBook->findByUid( *it );
707
708 if ( a.isEmpty() )
709 continue;
710 a.simplifyEmails();
711 a.simplifyPhoneNumbers();
712 a.simplifyPhoneNumberTypes();
713 a.simplifyAddresses();
714
715 if (description.isEmpty())
716 description = a.formattedName();
717 QString vcard;
718 QString vcardnew;
719 converter.addresseeToVCard( a, vcard );
720 int start = 0;
721 int next;
722 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
723 int semi = vcard.find(";", next);
724 int dopp = vcard.find(":", next);
725 int sep;
726 if ( semi < dopp && semi >= 0 )
727 sep = semi ;
728 else
729 sep = dopp;
730 vcardnew +=vcard.mid( start, next - start);
731 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper();
732 start = sep;
733 }
734 vcardnew += vcard.mid( start,vcard.length() );
735 vcard = "";
736 start = 0;
737 while ( (next = vcardnew.find("ADR", start) )>= 0 ) {
738 int sep = vcardnew.find(":", next);
739 vcard +=vcardnew.mid( start, next - start+3);
740 start = sep;
741 }
742 vcard += vcardnew.mid( start,vcardnew.length() );
743 vcard.replace ( QRegExp(";;;") , "" );
744 vcard.replace ( QRegExp(";;") , "" );
745 datastream += vcard;
746
747 }
748 QFile outFile(fileName);
749 if ( outFile.open(IO_WriteOnly) ) {
750 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
751 QTextStream t( &outFile ); // use a text stream
752 t.setEncoding( QTextStream::UnicodeUTF8 );
753 t <<datastream;
754 outFile.close();
755 if ( PhoneAccess::writeToPhone( fileName ) )
756 qDebug("Export okay ");
757 else
758 qDebug("Error export contacts ");
759
760 } else {
761 qDebug("Error open temp file ");
762 return; 703 return;
763 } 704
764 705 if ( PhoneAccess::writeToPhone( fileName ) )
706 qDebug("Export okay ");
707 else
708 qDebug("Error export contacts ");
709
765 710
766#if 0 711#if 0
767 712
768 setCaption( i18n("Writing to phone...")); 713 setCaption( i18n("Writing to phone..."));
769 if ( PhoneFormat::writeToPhone( cal ) ) 714 if ( PhoneFormat::writeToPhone( cal ) )
770 setCaption( i18n("Export to phone successful!")); 715 setCaption( i18n("Export to phone successful!"));
771 else 716 else
772 setCaption( i18n("Error exporting to phone!")); 717 setCaption( i18n("Error exporting to phone!"));
773#endif 718#endif
774 719
775 720
776} 721}
777void KABCore::beamVCard() 722void KABCore::beamVCard()
778{ 723{
779 QStringList uids = mViewManager->selectedUids(); 724 QStringList uids = mViewManager->selectedUids();
780 if ( !uids.isEmpty() ) 725 if ( !uids.isEmpty() )
781 beamVCard( uids ); 726 beamVCard( uids );
782} 727}
783 728
784 729
785void KABCore::beamVCard(const QStringList& uids) 730void KABCore::beamVCard(const QStringList& uids)
786{ 731{
787/*US 732/*US
788 QString beamFilename; 733 QString beamFilename;
789 Opie::OPimContact c; 734 Opie::OPimContact c;
790 if ( actionPersonal->isOn() ) { 735 if ( actionPersonal->isOn() ) {
791 beamFilename = addressbookPersonalVCardName(); 736 beamFilename = addressbookPersonalVCardName();
792 if ( !QFile::exists( beamFilename ) ) 737 if ( !QFile::exists( beamFilename ) )
793 return; // can't beam a non-existent file 738 return; // can't beam a non-existent file
794 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, 739 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null,
795 beamFilename ); 740 beamFilename );
796 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); 741 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true );
797 Opie::OPimContactAccess::List allList = access->allRecords(); 742 Opie::OPimContactAccess::List allList = access->allRecords();
798 Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first 743 Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first
799 c = *it; 744 c = *it;
800 745
801 delete access; 746 delete access;
802 } else { 747 } else {
803 unlink( beamfile ); // delete if exists 748 unlink( beamfile ); // delete if exists
804 mkdir("/tmp/obex/", 0755); 749 mkdir("/tmp/obex/", 0755);
805 c = m_abView -> currentEntry(); 750 c = m_abView -> currentEntry();
806 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, 751 Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null,
807 beamfile ); 752 beamfile );
808 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); 753 Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true );
809 access->add( c ); 754 access->add( c );
810 access->save(); 755 access->save();
811 delete access; 756 delete access;
812 757
813 beamFilename = beamfile; 758 beamFilename = beamfile;
814 } 759 }
815 760
816 owarn << "Beaming: " << beamFilename << oendl; 761 owarn << "Beaming: " << beamFilename << oendl;
817*/ 762*/
818 763
819#if 0 764#if 0
820 QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); 765 QString tmpdir = locateLocal("tmp", KGlobal::getAppName());
821 766
822 QString dirName = tmpdir + "/" + KApplication::randomString( 8 ); 767 QString dirName = tmpdir + "/" + KApplication::randomString( 8 );
823 768
824 QString name = "contact.vcf"; 769 QString name = "contact.vcf";
825 770
826 QString fileName = dirName + "/" + name; 771 QString fileName = dirName + "/" + name;
827#endif 772#endif
828 // LR: we should use the /tmp dir, because: /tmp = RAM, (HOME)/kdepim = flash memory 773 // LR: we should use the /tmp dir, because: /tmp = RAM, (HOME)/kdepim = flash memory
829 // 774 //
830 QString fileName = "/tmp/kapibeamfile.vcf"; 775 QString fileName = "/tmp/kapibeamfile.vcf";
831 776
832 777
833 //QDir().mkdir( dirName, true ); 778 //QDir().mkdir( dirName, true );
834 779
835 780
836 KABC::VCardConverter converter; 781 KABC::VCardConverter converter;
837 QString description; 782 QString description;
838 QString datastream; 783 QString datastream;
839 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 784 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
840 KABC::Addressee a = mAddressBook->findByUid( *it ); 785 KABC::Addressee a = mAddressBook->findByUid( *it );
841 786
842 if ( a.isEmpty() ) 787 if ( a.isEmpty() )
843 continue; 788 continue;
844 789
845 if (description.isEmpty()) 790 if (description.isEmpty())
846 description = a.formattedName(); 791 description = a.formattedName();
847 792
848 QString vcard; 793 QString vcard;
849 converter.addresseeToVCard( a, vcard ); 794 converter.addresseeToVCard( a, vcard );
850 int start = 0; 795 int start = 0;
851 int next; 796 int next;
852 while ( (next = vcard.find("TYPE=", start) )>= 0 ) { 797 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
853 int semi = vcard.find(";", next); 798 int semi = vcard.find(";", next);
854 int dopp = vcard.find(":", next); 799 int dopp = vcard.find(":", next);
855 int sep; 800 int sep;
856 if ( semi < dopp && semi >= 0 ) 801 if ( semi < dopp && semi >= 0 )
857 sep = semi ; 802 sep = semi ;
858 else 803 else
859 sep = dopp; 804 sep = dopp;
860 datastream +=vcard.mid( start, next - start); 805 datastream +=vcard.mid( start, next - start);
861 datastream +=vcard.mid( next+5,sep -next -5 ).upper(); 806 datastream +=vcard.mid( next+5,sep -next -5 ).upper();
862 start = sep; 807 start = sep;
863 } 808 }
864 datastream += vcard.mid( start,vcard.length() ); 809 datastream += vcard.mid( start,vcard.length() );
865 } 810 }
866#ifndef DESKTOP_VERSION 811#ifndef DESKTOP_VERSION
867 QFile outFile(fileName); 812 QFile outFile(fileName);
868 if ( outFile.open(IO_WriteOnly) ) { 813 if ( outFile.open(IO_WriteOnly) ) {
869 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); 814 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
870 QTextStream t( &outFile ); // use a text stream 815 QTextStream t( &outFile ); // use a text stream
871 t.setEncoding( QTextStream::UnicodeUTF8 ); 816 t.setEncoding( QTextStream::UnicodeUTF8 );
872 t <<datastream; 817 t <<datastream;
873 outFile.close(); 818 outFile.close();
874 Ir *ir = new Ir( this ); 819 Ir *ir = new Ir( this );
875 connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); 820 connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) );
876 ir->send( fileName, description, "text/x-vCard" ); 821 ir->send( fileName, description, "text/x-vCard" );
877 } else { 822 } else {
878 qDebug("Error open temp beam file "); 823 qDebug("Error open temp beam file ");
879 return; 824 return;
880 } 825 }
881#endif 826#endif
882 827
883} 828}
884 829
885void KABCore::beamDone( Ir *ir ) 830void KABCore::beamDone( Ir *ir )
886{ 831{
887#ifndef DESKTOP_VERSION 832#ifndef DESKTOP_VERSION
888 delete ir; 833 delete ir;
889#endif 834#endif
890} 835}
891 836
892 837
893void KABCore::browse( const QString& url ) 838void KABCore::browse( const QString& url )
894{ 839{
895#ifndef KAB_EMBEDDED 840#ifndef KAB_EMBEDDED
896 kapp->invokeBrowser( url ); 841 kapp->invokeBrowser( url );
897#else //KAB_EMBEDDED 842#else //KAB_EMBEDDED
898 qDebug("KABCore::browse must be fixed"); 843 qDebug("KABCore::browse must be fixed");
899#endif //KAB_EMBEDDED 844#endif //KAB_EMBEDDED
900} 845}
901 846
902void KABCore::selectAllContacts() 847void KABCore::selectAllContacts()
903{ 848{
904 mViewManager->setSelected( QString::null, true ); 849 mViewManager->setSelected( QString::null, true );
905} 850}
906 851
907void KABCore::deleteContacts() 852void KABCore::deleteContacts()
908{ 853{
909 QStringList uidList = mViewManager->selectedUids(); 854 QStringList uidList = mViewManager->selectedUids();
910 deleteContacts( uidList ); 855 deleteContacts( uidList );
911} 856}
912 857
913void KABCore::deleteContacts( const QStringList &uids ) 858void KABCore::deleteContacts( const QStringList &uids )
914{ 859{
915 if ( uids.count() > 0 ) { 860 if ( uids.count() > 0 ) {
916 PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids ); 861 PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids );
917 UndoStack::instance()->push( command ); 862 UndoStack::instance()->push( command );
918 RedoStack::instance()->clear(); 863 RedoStack::instance()->clear();
919 864
920 // now if we deleted anything, refresh 865 // now if we deleted anything, refresh
921 setContactSelected( QString::null ); 866 setContactSelected( QString::null );
922 setModified( true ); 867 setModified( true );
923 } 868 }
924} 869}
925 870
926void KABCore::copyContacts() 871void KABCore::copyContacts()
927{ 872{
928 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 873 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
929 874
930 QString clipText = AddresseeUtil::addresseesToClipboard( addrList ); 875 QString clipText = AddresseeUtil::addresseesToClipboard( addrList );
931 876
932 kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl; 877 kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl;
933 878
934 QClipboard *cb = QApplication::clipboard(); 879 QClipboard *cb = QApplication::clipboard();
935 cb->setText( clipText ); 880 cb->setText( clipText );
936} 881}
937 882
938void KABCore::cutContacts() 883void KABCore::cutContacts()
939{ 884{
940 QStringList uidList = mViewManager->selectedUids(); 885 QStringList uidList = mViewManager->selectedUids();
941 886
942//US if ( uidList.size() > 0 ) { 887//US if ( uidList.size() > 0 ) {
943 if ( uidList.count() > 0 ) { 888 if ( uidList.count() > 0 ) {
944 PwCutCommand *command = new PwCutCommand( mAddressBook, uidList ); 889 PwCutCommand *command = new PwCutCommand( mAddressBook, uidList );
945 UndoStack::instance()->push( command ); 890 UndoStack::instance()->push( command );
946 RedoStack::instance()->clear(); 891 RedoStack::instance()->clear();
947 892
948 setModified( true ); 893 setModified( true );
949 } 894 }
950} 895}
951 896
952void KABCore::pasteContacts() 897void KABCore::pasteContacts()
953{ 898{
954 QClipboard *cb = QApplication::clipboard(); 899 QClipboard *cb = QApplication::clipboard();
955 900
956 KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() ); 901 KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() );
957 902
958 pasteContacts( list ); 903 pasteContacts( list );
959} 904}
960 905
961void KABCore::pasteContacts( KABC::Addressee::List &list ) 906void KABCore::pasteContacts( KABC::Addressee::List &list )
962{ 907{
963 KABC::Resource *resource = requestResource( this ); 908 KABC::Resource *resource = requestResource( this );
964 KABC::Addressee::List::Iterator it; 909 KABC::Addressee::List::Iterator it;
965 for ( it = list.begin(); it != list.end(); ++it ) 910 for ( it = list.begin(); it != list.end(); ++it )
966 (*it).setResource( resource ); 911 (*it).setResource( resource );
967 912
968 PwPasteCommand *command = new PwPasteCommand( this, list ); 913 PwPasteCommand *command = new PwPasteCommand( this, list );
969 UndoStack::instance()->push( command ); 914 UndoStack::instance()->push( command );
970 RedoStack::instance()->clear(); 915 RedoStack::instance()->clear();
971 916
972 setModified( true ); 917 setModified( true );
973} 918}
974 919
975void KABCore::setWhoAmI() 920void KABCore::setWhoAmI()
976{ 921{
977 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 922 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
978 923
979 if ( addrList.count() > 1 ) { 924 if ( addrList.count() > 1 ) {
980 KMessageBox::sorry( this, i18n( "Please select only one contact." ) ); 925 KMessageBox::sorry( this, i18n( "Please select only one contact." ) );
981 return; 926 return;
982 } 927 }
983 928
984 QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) ); 929 QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) );
985 if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes ) 930 if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes )
986 static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] ); 931 static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] );
987} 932}
988 933
989void KABCore::setCategories() 934void KABCore::setCategories()
990{ 935{
991 KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true ); 936 KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true );
992 if ( !dlg.exec() ) 937 if ( !dlg.exec() )
993 return; 938 return;
994 939
995 bool merge = false; 940 bool merge = false;
996 QString msg = i18n( "Merge with existing categories?" ); 941 QString msg = i18n( "Merge with existing categories?" );
997 if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes ) 942 if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes )
998 merge = true; 943 merge = true;
999 944
1000 QStringList categories = dlg.selectedCategories(); 945 QStringList categories = dlg.selectedCategories();
1001 946
1002 QStringList uids = mViewManager->selectedUids(); 947 QStringList uids = mViewManager->selectedUids();
1003 QStringList::Iterator it; 948 QStringList::Iterator it;
1004 for ( it = uids.begin(); it != uids.end(); ++it ) { 949 for ( it = uids.begin(); it != uids.end(); ++it ) {
1005 KABC::Addressee addr = mAddressBook->findByUid( *it ); 950 KABC::Addressee addr = mAddressBook->findByUid( *it );
1006 if ( !addr.isEmpty() ) { 951 if ( !addr.isEmpty() ) {
1007 if ( !merge ) 952 if ( !merge )
1008 addr.setCategories( categories ); 953 addr.setCategories( categories );
1009 else { 954 else {
1010 QStringList addrCategories = addr.categories(); 955 QStringList addrCategories = addr.categories();
1011 QStringList::Iterator catIt; 956 QStringList::Iterator catIt;
1012 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { 957 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) {
1013 if ( !addrCategories.contains( *catIt ) ) 958 if ( !addrCategories.contains( *catIt ) )
1014 addrCategories.append( *catIt ); 959 addrCategories.append( *catIt );
1015 } 960 }
1016 addr.setCategories( addrCategories ); 961 addr.setCategories( addrCategories );
1017 } 962 }
1018 963
1019 mAddressBook->insertAddressee( addr ); 964 mAddressBook->insertAddressee( addr );
1020 } 965 }
1021 } 966 }
1022 967
1023 if ( uids.count() > 0 ) 968 if ( uids.count() > 0 )
1024 setModified( true ); 969 setModified( true );
1025} 970}
1026 971
1027void KABCore::setSearchFields( const KABC::Field::List &fields ) 972void KABCore::setSearchFields( const KABC::Field::List &fields )
1028{ 973{
1029 mIncSearchWidget->setFields( fields ); 974 mIncSearchWidget->setFields( fields );
1030} 975}
1031 976
1032void KABCore::incrementalSearch( const QString& text ) 977void KABCore::incrementalSearch( const QString& text )
1033{ 978{
1034 mViewManager->doSearch( text, mIncSearchWidget->currentField() ); 979 mViewManager->doSearch( text, mIncSearchWidget->currentField() );
1035} 980}
1036 981
1037void KABCore::setModified() 982void KABCore::setModified()
1038{ 983{
1039 setModified( true ); 984 setModified( true );
1040} 985}
1041 986
1042void KABCore::setModifiedWOrefresh() 987void KABCore::setModifiedWOrefresh()
1043{ 988{
1044 // qDebug("KABCore::setModifiedWOrefresh() "); 989 // qDebug("KABCore::setModifiedWOrefresh() ");
1045 mModified = true; 990 mModified = true;
1046 mActionSave->setEnabled( mModified ); 991 mActionSave->setEnabled( mModified );
1047#ifdef DESKTOP_VERSION 992#ifdef DESKTOP_VERSION
1048 mDetails->refreshView(); 993 mDetails->refreshView();
1049#endif 994#endif
1050 995
1051} 996}
1052void KABCore::setModified( bool modified ) 997void KABCore::setModified( bool modified )
1053{ 998{
1054 mModified = modified; 999 mModified = modified;
1055 mActionSave->setEnabled( mModified ); 1000 mActionSave->setEnabled( mModified );
1056 1001
1057 if ( modified ) 1002 if ( modified )
1058 mJumpButtonBar->recreateButtons(); 1003 mJumpButtonBar->recreateButtons();
1059 1004
1060 mViewManager->refreshView(); 1005 mViewManager->refreshView();
1061 mDetails->refreshView(); 1006 mDetails->refreshView();
1062 1007
1063} 1008}
1064 1009
1065bool KABCore::modified() const 1010bool KABCore::modified() const
1066{ 1011{
1067 return mModified; 1012 return mModified;
1068} 1013}
1069 1014
1070void KABCore::contactModified( const KABC::Addressee &addr ) 1015void KABCore::contactModified( const KABC::Addressee &addr )
1071{ 1016{
1072 1017
1073 Command *command = 0; 1018 Command *command = 0;
1074 QString uid; 1019 QString uid;
1075 1020
1076 // check if it exists already 1021 // check if it exists already
1077 KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() ); 1022 KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() );
1078 if ( origAddr.isEmpty() ) 1023 if ( origAddr.isEmpty() )
1079 command = new PwNewCommand( mAddressBook, addr ); 1024 command = new PwNewCommand( mAddressBook, addr );
1080 else { 1025 else {
1081 command = new PwEditCommand( mAddressBook, origAddr, addr ); 1026 command = new PwEditCommand( mAddressBook, origAddr, addr );
1082 uid = addr.uid(); 1027 uid = addr.uid();
1083 } 1028 }
1084 1029
1085 UndoStack::instance()->push( command ); 1030 UndoStack::instance()->push( command );
1086 RedoStack::instance()->clear(); 1031 RedoStack::instance()->clear();
1087 1032
1088 setModified( true ); 1033 setModified( true );
1089} 1034}
1090 1035
1091void KABCore::newContact() 1036void KABCore::newContact()
1092{ 1037{
1093 1038
1094 1039
1095 QPtrList<KABC::Resource> kabcResources = mAddressBook->resources(); 1040 QPtrList<KABC::Resource> kabcResources = mAddressBook->resources();
1096 1041
1097 QPtrList<KRES::Resource> kresResources; 1042 QPtrList<KRES::Resource> kresResources;
1098 QPtrListIterator<KABC::Resource> it( kabcResources ); 1043 QPtrListIterator<KABC::Resource> it( kabcResources );
1099 KABC::Resource *resource; 1044 KABC::Resource *resource;
1100 while ( ( resource = it.current() ) != 0 ) { 1045 while ( ( resource = it.current() ) != 0 ) {
1101 ++it; 1046 ++it;
1102 if ( !resource->readOnly() ) { 1047 if ( !resource->readOnly() ) {
1103 KRES::Resource *res = static_cast<KRES::Resource*>( resource ); 1048 KRES::Resource *res = static_cast<KRES::Resource*>( resource );
1104 if ( res ) 1049 if ( res )
1105 kresResources.append( res ); 1050 kresResources.append( res );
1106 } 1051 }
1107 } 1052 }
1108 1053
1109 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this ); 1054 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this );
1110 resource = static_cast<KABC::Resource*>( res ); 1055 resource = static_cast<KABC::Resource*>( res );
1111 1056
1112 if ( resource ) { 1057 if ( resource ) {
1113 KABC::Addressee addr; 1058 KABC::Addressee addr;
1114 addr.setResource( resource ); 1059 addr.setResource( resource );
1115 mEditorDialog->setAddressee( addr ); 1060 mEditorDialog->setAddressee( addr );
1116 KApplication::execDialog ( mEditorDialog ); 1061 KApplication::execDialog ( mEditorDialog );
1117 1062
1118 } else 1063 } else
1119 return; 1064 return;
1120 1065
1121 // mEditorDict.insert( dialog->addressee().uid(), dialog ); 1066 // mEditorDict.insert( dialog->addressee().uid(), dialog );
1122 1067
1123 1068
1124} 1069}
1125 1070
1126void KABCore::addEmail( QString aStr ) 1071void KABCore::addEmail( QString aStr )
1127{ 1072{
1128#ifndef KAB_EMBEDDED 1073#ifndef KAB_EMBEDDED
1129 QString fullName, email; 1074 QString fullName, email;
1130 1075
1131 KABC::Addressee::parseEmailAddress( aStr, fullName, email ); 1076 KABC::Addressee::parseEmailAddress( aStr, fullName, email );
1132 1077
1133 // Try to lookup the addressee matching the email address 1078 // Try to lookup the addressee matching the email address
1134 bool found = false; 1079 bool found = false;
1135 QStringList emailList; 1080 QStringList emailList;
1136 KABC::AddressBook::Iterator it; 1081 KABC::AddressBook::Iterator it;
1137 for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) { 1082 for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) {
1138 emailList = (*it).emails(); 1083 emailList = (*it).emails();
1139 if ( emailList.contains( email ) > 0 ) { 1084 if ( emailList.contains( email ) > 0 ) {
1140 found = true; 1085 found = true;
1141 (*it).setNameFromString( fullName ); 1086 (*it).setNameFromString( fullName );
1142 editContact( (*it).uid() ); 1087 editContact( (*it).uid() );
1143 } 1088 }
1144 } 1089 }
1145 1090
1146 if ( !found ) { 1091 if ( !found ) {
1147 KABC::Addressee addr; 1092 KABC::Addressee addr;
1148 addr.setNameFromString( fullName ); 1093 addr.setNameFromString( fullName );
1149 addr.insertEmail( email, true ); 1094 addr.insertEmail( email, true );
1150 1095
1151 mAddressBook->insertAddressee( addr ); 1096 mAddressBook->insertAddressee( addr );
1152 mViewManager->refreshView( addr.uid() ); 1097 mViewManager->refreshView( addr.uid() );
1153 editContact( addr.uid() ); 1098 editContact( addr.uid() );
1154 } 1099 }
1155#else //KAB_EMBEDDED 1100#else //KAB_EMBEDDED
1156 qDebug("KABCore::addEmail finsih method"); 1101 qDebug("KABCore::addEmail finsih method");
1157#endif //KAB_EMBEDDED 1102#endif //KAB_EMBEDDED
1158} 1103}
1159 1104
1160void KABCore::importVCard( const KURL &url, bool showPreview ) 1105void KABCore::importVCard( const KURL &url, bool showPreview )
1161{ 1106{
1162 mXXPortManager->importVCard( url, showPreview ); 1107 mXXPortManager->importVCard( url, showPreview );
1163} 1108}
1164void KABCore::importFromOL() 1109void KABCore::importFromOL()
1165{ 1110{
1166#ifdef _WIN32_ 1111#ifdef _WIN32_
1167 KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this ); 1112 KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this );
1168 idgl->exec(); 1113 idgl->exec();
1169 KABC::Addressee::List list = idgl->getAddressList(); 1114 KABC::Addressee::List list = idgl->getAddressList();
1170 if ( list.count() > 0 ) { 1115 if ( list.count() > 0 ) {
1171 KABC::Addressee::List listNew; 1116 KABC::Addressee::List listNew;
1172 KABC::Addressee::List listExisting; 1117 KABC::Addressee::List listExisting;
1173 KABC::Addressee::List::Iterator it; 1118 KABC::Addressee::List::Iterator it;
1174 KABC::AddressBook::Iterator iter; 1119 KABC::AddressBook::Iterator iter;
1175 for ( it = list.begin(); it != list.end(); ++it ) { 1120 for ( it = list.begin(); it != list.end(); ++it ) {
1176 if ( mAddressBook->findByUid((*it).uid() ).isEmpty()) 1121 if ( mAddressBook->findByUid((*it).uid() ).isEmpty())
1177 listNew.append( (*it) ); 1122 listNew.append( (*it) );
1178 else 1123 else
1179 listExisting.append( (*it) ); 1124 listExisting.append( (*it) );
1180 } 1125 }
1181 if ( listExisting.count() > 0 ) 1126 if ( listExisting.count() > 0 )
1182 KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() )); 1127 KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() ));
1183 if ( listNew.count() > 0 ) { 1128 if ( listNew.count() > 0 ) {
1184 pasteWithNewUid = false; 1129 pasteWithNewUid = false;
1185 pasteContacts( listNew ); 1130 pasteContacts( listNew );
1186 pasteWithNewUid = true; 1131 pasteWithNewUid = true;
1187 } 1132 }
1188 } 1133 }
1189 delete idgl; 1134 delete idgl;
1190#endif 1135#endif
1191} 1136}
1192 1137
1193void KABCore::importVCard( const QString &vCard, bool showPreview ) 1138void KABCore::importVCard( const QString &vCard, bool showPreview )
1194{ 1139{
1195 mXXPortManager->importVCard( vCard, showPreview ); 1140 mXXPortManager->importVCard( vCard, showPreview );
1196} 1141}
1197 1142
1198//US added a second method without defaultparameter 1143//US added a second method without defaultparameter
1199void KABCore::editContact2() { 1144void KABCore::editContact2() {
1200 editContact( QString::null ); 1145 editContact( QString::null );
1201} 1146}
1202 1147
1203void KABCore::editContact( const QString &uid ) 1148void KABCore::editContact( const QString &uid )
1204{ 1149{
1205 1150
1206 if ( mExtensionManager->isQuickEditVisible() ) 1151 if ( mExtensionManager->isQuickEditVisible() )
1207 return; 1152 return;
1208 1153
1209 // First, locate the contact entry 1154 // First, locate the contact entry
1210 QString localUID = uid; 1155 QString localUID = uid;
1211 if ( localUID.isNull() ) { 1156 if ( localUID.isNull() ) {
1212 QStringList uidList = mViewManager->selectedUids(); 1157 QStringList uidList = mViewManager->selectedUids();
1213 if ( uidList.count() > 0 ) 1158 if ( uidList.count() > 0 )
1214 localUID = *( uidList.at( 0 ) ); 1159 localUID = *( uidList.at( 0 ) );
1215 } 1160 }
1216 1161
1217 KABC::Addressee addr = mAddressBook->findByUid( localUID ); 1162 KABC::Addressee addr = mAddressBook->findByUid( localUID );
1218 if ( !addr.isEmpty() ) { 1163 if ( !addr.isEmpty() ) {
1219 mEditorDialog->setAddressee( addr ); 1164 mEditorDialog->setAddressee( addr );
1220 KApplication::execDialog ( mEditorDialog ); 1165 KApplication::execDialog ( mEditorDialog );
1221 } 1166 }
1222} 1167}
1223 1168
1224/** 1169/**
1225 Shows or edits the detail view for the given uid. If the uid is QString::null, 1170 Shows or edits the detail view for the given uid. If the uid is QString::null,
1226 the method will try to find a selected addressee in the view. 1171 the method will try to find a selected addressee in the view.
1227 */ 1172 */
1228void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) 1173void KABCore::executeContact( const QString &uid /*US = QString::null*/ )
1229{ 1174{
1230 if ( mMultipleViewsAtOnce ) 1175 if ( mMultipleViewsAtOnce )
1231 { 1176 {
1232 editContact( uid ); 1177 editContact( uid );
1233 } 1178 }
1234 else 1179 else
1235 { 1180 {
1236 setDetailsVisible( true ); 1181 setDetailsVisible( true );
1237 mActionDetails->setChecked(true); 1182 mActionDetails->setChecked(true);
1238 } 1183 }
1239 1184
1240} 1185}
1241 1186
1242void KABCore::save() 1187void KABCore::save()
1243{ 1188{
1244 if (syncManager->blockSave()) 1189 if (syncManager->blockSave())
1245 return; 1190 return;
1246 if ( !mModified ) 1191 if ( !mModified )
1247 return; 1192 return;
1248 1193
1249 syncManager->setBlockSave(true); 1194 syncManager->setBlockSave(true);
1250 QString text = i18n( "There was an error while attempting to save\n the " 1195 QString text = i18n( "There was an error while attempting to save\n the "
1251 "address book. Please check that some \nother application is " 1196 "address book. Please check that some \nother application is "
1252 "not using it. " ); 1197 "not using it. " );
1253 statusMessage(i18n("Saving addressbook ... ")); 1198 statusMessage(i18n("Saving addressbook ... "));
1254#ifndef KAB_EMBEDDED 1199#ifndef KAB_EMBEDDED
1255 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); 1200 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook );
1256 if ( !b || !b->save() ) { 1201 if ( !b || !b->save() ) {
1257 KMessageBox::error( this, text, i18n( "Unable to Save" ) ); 1202 KMessageBox::error( this, text, i18n( "Unable to Save" ) );
1258 } 1203 }
1259#else //KAB_EMBEDDED 1204#else //KAB_EMBEDDED
1260 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); 1205 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook );
1261 if ( !b || !b->save() ) { 1206 if ( !b || !b->save() ) {
1262 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); 1207 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok"));
1263 } 1208 }
1264#endif //KAB_EMBEDDED 1209#endif //KAB_EMBEDDED
1265 1210
1266 statusMessage(i18n("Addressbook saved!")); 1211 statusMessage(i18n("Addressbook saved!"));
1267 setModified( false ); 1212 setModified( false );
1268 syncManager->setBlockSave(false); 1213 syncManager->setBlockSave(false);
1269} 1214}
1270 1215
1271void KABCore::statusMessage(QString mess , int time ) 1216void KABCore::statusMessage(QString mess , int time )
1272{ 1217{
1273 //topLevelWidget()->setCaption( mess ); 1218 //topLevelWidget()->setCaption( mess );
1274 // pending setting timer to revome message 1219 // pending setting timer to revome message
1275} 1220}
1276void KABCore::undo() 1221void KABCore::undo()
@@ -2334,591 +2279,594 @@ void KABCore::requestForDetails(const QString& sourceChannel, const QString& ses
2334 2279
2335void KABCore::faq() 2280void KABCore::faq()
2336{ 2281{
2337 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); 2282 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" );
2338} 2283}
2339 2284
2340#include <libkcal/syncdefines.h> 2285#include <libkcal/syncdefines.h>
2341 2286
2342KABC::Addressee KABCore::getLastSyncAddressee() 2287KABC::Addressee KABCore::getLastSyncAddressee()
2343{ 2288{
2344 Addressee lse; 2289 Addressee lse;
2345 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2290 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2346 2291
2347 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 2292 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
2348 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2293 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2349 if (lse.isEmpty()) { 2294 if (lse.isEmpty()) {
2350 qDebug("Creating new last-syncAddressee "); 2295 qDebug("Creating new last-syncAddressee ");
2351 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2296 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice );
2352 QString sum = ""; 2297 QString sum = "";
2353 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 2298 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
2354 sum = "E: "; 2299 sum = "E: ";
2355 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); 2300 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event"));
2356 lse.setRevision( mLastAddressbookSync ); 2301 lse.setRevision( mLastAddressbookSync );
2357 lse.setCategories( i18n("SyncEvent") ); 2302 lse.setCategories( i18n("SyncEvent") );
2358 mAddressBook->insertAddressee( lse ); 2303 mAddressBook->insertAddressee( lse );
2359 } 2304 }
2360 return lse; 2305 return lse;
2361} 2306}
2362int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) 2307int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full )
2363{ 2308{
2364 2309
2365 //void setZaurusId(int id); 2310 //void setZaurusId(int id);
2366 // int zaurusId() const; 2311 // int zaurusId() const;
2367 // void setZaurusUid(int id); 2312 // void setZaurusUid(int id);
2368 // int zaurusUid() const; 2313 // int zaurusUid() const;
2369 // void setZaurusStat(int id); 2314 // void setZaurusStat(int id);
2370 // int zaurusStat() const; 2315 // int zaurusStat() const;
2371 // 0 equal 2316 // 0 equal
2372 // 1 take local 2317 // 1 take local
2373 // 2 take remote 2318 // 2 take remote
2374 // 3 cancel 2319 // 3 cancel
2375 QDateTime lastSync = mLastAddressbookSync; 2320 QDateTime lastSync = mLastAddressbookSync;
2376 QDateTime localMod = local->revision(); 2321 QDateTime localMod = local->revision();
2377 QDateTime remoteMod = remote->revision(); 2322 QDateTime remoteMod = remote->revision();
2378 2323
2379 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2324 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2380 2325
2381 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2326 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2382 bool remCh, locCh; 2327 bool remCh, locCh;
2383 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 2328 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
2384 2329
2385 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 2330 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
2386 locCh = ( localMod > mLastAddressbookSync ); 2331 locCh = ( localMod > mLastAddressbookSync );
2387 if ( !remCh && ! locCh ) { 2332 if ( !remCh && ! locCh ) {
2388 //qDebug("both not changed "); 2333 //qDebug("both not changed ");
2389 lastSync = localMod.addDays(1); 2334 lastSync = localMod.addDays(1);
2390 if ( mode <= SYNC_PREF_ASK ) 2335 if ( mode <= SYNC_PREF_ASK )
2391 return 0; 2336 return 0;
2392 } else { 2337 } else {
2393 if ( locCh ) { 2338 if ( locCh ) {
2394 //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); 2339 //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1());
2395 lastSync = localMod.addDays( -1 ); 2340 lastSync = localMod.addDays( -1 );
2396 if ( !remCh ) 2341 if ( !remCh )
2397 remoteMod =( lastSync.addDays( -1 ) ); 2342 remoteMod =( lastSync.addDays( -1 ) );
2398 } else { 2343 } else {
2399 //qDebug(" not loc changed "); 2344 //qDebug(" not loc changed ");
2400 lastSync = localMod.addDays( 1 ); 2345 lastSync = localMod.addDays( 1 );
2401 if ( remCh ) 2346 if ( remCh )
2402 remoteMod =( lastSync.addDays( 1 ) ); 2347 remoteMod =( lastSync.addDays( 1 ) );
2403 2348
2404 } 2349 }
2405 } 2350 }
2406 full = true; 2351 full = true;
2407 if ( mode < SYNC_PREF_ASK ) 2352 if ( mode < SYNC_PREF_ASK )
2408 mode = SYNC_PREF_ASK; 2353 mode = SYNC_PREF_ASK;
2409 } else { 2354 } else {
2410 if ( localMod == remoteMod ) 2355 if ( localMod == remoteMod )
2411 return 0; 2356 return 0;
2412 2357
2413 } 2358 }
2414 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 2359 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
2415 2360
2416 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); 2361 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
2417 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 2362 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
2418 //full = true; //debug only 2363 //full = true; //debug only
2419 if ( full ) { 2364 if ( full ) {
2420 bool equ = ( (*local) == (*remote) ); 2365 bool equ = ( (*local) == (*remote) );
2421 if ( equ ) { 2366 if ( equ ) {
2422 //qDebug("equal "); 2367 //qDebug("equal ");
2423 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2368 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2424 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 2369 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
2425 } 2370 }
2426 if ( mode < SYNC_PREF_FORCE_LOCAL ) 2371 if ( mode < SYNC_PREF_FORCE_LOCAL )
2427 return 0; 2372 return 0;
2428 2373
2429 }//else //debug only 2374 }//else //debug only
2430 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 2375 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
2431 } 2376 }
2432 int result; 2377 int result;
2433 bool localIsNew; 2378 bool localIsNew;
2434 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); 2379 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() );
2435 2380
2436 if ( full && mode < SYNC_PREF_NEWEST ) 2381 if ( full && mode < SYNC_PREF_NEWEST )
2437 mode = SYNC_PREF_ASK; 2382 mode = SYNC_PREF_ASK;
2438 2383
2439 switch( mode ) { 2384 switch( mode ) {
2440 case SYNC_PREF_LOCAL: 2385 case SYNC_PREF_LOCAL:
2441 if ( lastSync > remoteMod ) 2386 if ( lastSync > remoteMod )
2442 return 1; 2387 return 1;
2443 if ( lastSync > localMod ) 2388 if ( lastSync > localMod )
2444 return 2; 2389 return 2;
2445 return 1; 2390 return 1;
2446 break; 2391 break;
2447 case SYNC_PREF_REMOTE: 2392 case SYNC_PREF_REMOTE:
2448 if ( lastSync > remoteMod ) 2393 if ( lastSync > remoteMod )
2449 return 1; 2394 return 1;
2450 if ( lastSync > localMod ) 2395 if ( lastSync > localMod )
2451 return 2; 2396 return 2;
2452 return 2; 2397 return 2;
2453 break; 2398 break;
2454 case SYNC_PREF_NEWEST: 2399 case SYNC_PREF_NEWEST:
2455 if ( localMod > remoteMod ) 2400 if ( localMod > remoteMod )
2456 return 1; 2401 return 1;
2457 else 2402 else
2458 return 2; 2403 return 2;
2459 break; 2404 break;
2460 case SYNC_PREF_ASK: 2405 case SYNC_PREF_ASK:
2461 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 2406 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
2462 if ( lastSync > remoteMod ) 2407 if ( lastSync > remoteMod )
2463 return 1; 2408 return 1;
2464 if ( lastSync > localMod ) 2409 if ( lastSync > localMod )
2465 return 2; 2410 return 2;
2466 localIsNew = localMod >= remoteMod; 2411 localIsNew = localMod >= remoteMod;
2467 //qDebug("conflict! ************************************** "); 2412 //qDebug("conflict! ************************************** ");
2468 { 2413 {
2469 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); 2414 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this );
2470 result = acd.executeD(localIsNew); 2415 result = acd.executeD(localIsNew);
2471 return result; 2416 return result;
2472 } 2417 }
2473 break; 2418 break;
2474 case SYNC_PREF_FORCE_LOCAL: 2419 case SYNC_PREF_FORCE_LOCAL:
2475 return 1; 2420 return 1;
2476 break; 2421 break;
2477 case SYNC_PREF_FORCE_REMOTE: 2422 case SYNC_PREF_FORCE_REMOTE:
2478 return 2; 2423 return 2;
2479 break; 2424 break;
2480 2425
2481 default: 2426 default:
2482 // SYNC_PREF_TAKE_BOTH not implemented 2427 // SYNC_PREF_TAKE_BOTH not implemented
2483 break; 2428 break;
2484 } 2429 }
2485 return 0; 2430 return 0;
2486} 2431}
2487 2432
2488 2433
2489bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2434bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2490{ 2435{
2491 bool syncOK = true; 2436 bool syncOK = true;
2492 int addedAddressee = 0; 2437 int addedAddressee = 0;
2493 int addedAddresseeR = 0; 2438 int addedAddresseeR = 0;
2494 int deletedAddresseeR = 0; 2439 int deletedAddresseeR = 0;
2495 int deletedAddresseeL = 0; 2440 int deletedAddresseeL = 0;
2496 int changedLocal = 0; 2441 int changedLocal = 0;
2497 int changedRemote = 0; 2442 int changedRemote = 0;
2498 2443
2499 QString mCurrentSyncName = syncManager->getCurrentSyncName(); 2444 QString mCurrentSyncName = syncManager->getCurrentSyncName();
2500 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2445 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2501 2446
2502 //QPtrList<Addressee> el = local->rawAddressees(); 2447 //QPtrList<Addressee> el = local->rawAddressees();
2503 Addressee addresseeR; 2448 Addressee addresseeR;
2504 QString uid; 2449 QString uid;
2505 int take; 2450 int take;
2506 Addressee addresseeL; 2451 Addressee addresseeL;
2507 Addressee addresseeRSync; 2452 Addressee addresseeRSync;
2508 Addressee addresseeLSync; 2453 Addressee addresseeLSync;
2509 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2454 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2510 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2455 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2511 bool fullDateRange = false; 2456 bool fullDateRange = false;
2512 local->resetTempSyncStat(); 2457 local->resetTempSyncStat();
2513 mLastAddressbookSync = QDateTime::currentDateTime(); 2458 mLastAddressbookSync = QDateTime::currentDateTime();
2514 QDateTime modifiedCalendar = mLastAddressbookSync;; 2459 QDateTime modifiedCalendar = mLastAddressbookSync;;
2515 addresseeLSync = getLastSyncAddressee(); 2460 addresseeLSync = getLastSyncAddressee();
2516 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); 2461 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1());
2517 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); 2462 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2518 if ( !addresseeR.isEmpty() ) { 2463 if ( !addresseeR.isEmpty() ) {
2519 addresseeRSync = addresseeR; 2464 addresseeRSync = addresseeR;
2520 remote->removeAddressee(addresseeR ); 2465 remote->removeAddressee(addresseeR );
2521 2466
2522 } else { 2467 } else {
2523 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2468 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2524 addresseeRSync = addresseeLSync ; 2469 addresseeRSync = addresseeLSync ;
2525 } else { 2470 } else {
2526 qDebug("FULLDATE 1"); 2471 qDebug("FULLDATE 1");
2527 fullDateRange = true; 2472 fullDateRange = true;
2528 Addressee newAdd; 2473 Addressee newAdd;
2529 addresseeRSync = newAdd; 2474 addresseeRSync = newAdd;
2530 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); 2475 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
2531 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); 2476 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
2532 addresseeRSync.setRevision( mLastAddressbookSync ); 2477 addresseeRSync.setRevision( mLastAddressbookSync );
2533 addresseeRSync.setCategories( i18n("SyncAddressee") ); 2478 addresseeRSync.setCategories( i18n("SyncAddressee") );
2534 } 2479 }
2535 } 2480 }
2536 if ( addresseeLSync.revision() == mLastAddressbookSync ) { 2481 if ( addresseeLSync.revision() == mLastAddressbookSync ) {
2537 qDebug("FULLDATE 2"); 2482 qDebug("FULLDATE 2");
2538 fullDateRange = true; 2483 fullDateRange = true;
2539 } 2484 }
2540 if ( ! fullDateRange ) { 2485 if ( ! fullDateRange ) {
2541 if ( addresseeLSync.revision() != addresseeRSync.revision() ) { 2486 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2542 2487
2543 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2488 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2544 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2489 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2545 fullDateRange = true; 2490 fullDateRange = true;
2546 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); 2491 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
2547 } 2492 }
2548 } 2493 }
2549 // fullDateRange = true; // debug only! 2494 // fullDateRange = true; // debug only!
2550 if ( fullDateRange ) 2495 if ( fullDateRange )
2551 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2496 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2552 else 2497 else
2553 mLastAddressbookSync = addresseeLSync.revision(); 2498 mLastAddressbookSync = addresseeLSync.revision();
2554 // for resyncing if own file has changed 2499 // for resyncing if own file has changed
2555 // PENDING fixme later when implemented 2500 // PENDING fixme later when implemented
2556#if 0 2501#if 0
2557 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2502 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2558 mLastAddressbookSync = loadedFileVersion; 2503 mLastAddressbookSync = loadedFileVersion;
2559 qDebug("setting mLastAddressbookSync "); 2504 qDebug("setting mLastAddressbookSync ");
2560 } 2505 }
2561#endif 2506#endif
2562 2507
2563 //qDebug("*************************** "); 2508 //qDebug("*************************** ");
2564 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2509 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2565 QStringList er = remote->uidList(); 2510 QStringList er = remote->uidList();
2566 Addressee inR ;//= er.first(); 2511 Addressee inR ;//= er.first();
2567 Addressee inL; 2512 Addressee inL;
2568 2513
2569 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 2514 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
2570 2515
2571 int modulo = (er.count()/10)+1; 2516 int modulo = (er.count()/10)+1;
2572 int incCounter = 0; 2517 int incCounter = 0;
2573 while ( incCounter < er.count()) { 2518 while ( incCounter < er.count()) {
2574 if (syncManager->isProgressBarCanceled()) 2519 if (syncManager->isProgressBarCanceled())
2575 return false; 2520 return false;
2576 if ( incCounter % modulo == 0 ) 2521 if ( incCounter % modulo == 0 )
2577 syncManager->showProgressBar(incCounter); 2522 syncManager->showProgressBar(incCounter);
2578 2523
2579 uid = er[ incCounter ]; 2524 uid = er[ incCounter ];
2580 bool skipIncidence = false; 2525 bool skipIncidence = false;
2581 if ( uid.left(19) == QString("last-syncAddressee-") ) 2526 if ( uid.left(19) == QString("last-syncAddressee-") )
2582 skipIncidence = true; 2527 skipIncidence = true;
2583 QString idS,OidS; 2528 QString idS,OidS;
2584 qApp->processEvents(); 2529 qApp->processEvents();
2585 if ( !skipIncidence ) { 2530 if ( !skipIncidence ) {
2586 inL = local->findByUid( uid ); 2531 inL = local->findByUid( uid );
2587 inR = remote->findByUid( uid ); 2532 inR = remote->findByUid( uid );
2588 //inL.setResource( 0 ); 2533 //inL.setResource( 0 );
2589 //inR.setResource( 0 ); 2534 //inR.setResource( 0 );
2590 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars 2535 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
2591 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { 2536 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) {
2592 //qDebug("take %d %s ", take, inL.summary().latin1()); 2537 //qDebug("take %d %s ", take, inL.summary().latin1());
2593 if ( take == 3 ) 2538 if ( take == 3 )
2594 return false; 2539 return false;
2595 if ( take == 1 ) {// take local 2540 if ( take == 1 ) {// take local
2596 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2541 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2597 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2542 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2598 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2543 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2599 local->insertAddressee( inL, false ); 2544 local->insertAddressee( inL, false );
2600 idS = inR.externalUID(); 2545 idS = inR.externalUID();
2601 OidS = inR.originalExternalUID(); 2546 OidS = inR.originalExternalUID();
2602 } 2547 }
2603 else 2548 else
2604 idS = inR.IDStr(); 2549 idS = inR.IDStr();
2605 remote->removeAddressee( inR ); 2550 remote->removeAddressee( inR );
2606 inR = inL; 2551 inR = inL;
2607 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2552 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2608 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2553 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2609 inR.setOriginalExternalUID( OidS ); 2554 inR.setOriginalExternalUID( OidS );
2610 inR.setExternalUID( idS ); 2555 inR.setExternalUID( idS );
2611 } else { 2556 } else {
2612 inR.setIDStr( idS ); 2557 inR.setIDStr( idS );
2613 } 2558 }
2614 inR.setResource( 0 ); 2559 inR.setResource( 0 );
2615 remote->insertAddressee( inR , false); 2560 remote->insertAddressee( inR , false);
2616 ++changedRemote; 2561 ++changedRemote;
2617 } else { // take == 2 take remote 2562 } else { // take == 2 take remote
2618 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2563 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2619 if ( inR.revision().date().year() < 2004 ) 2564 if ( inR.revision().date().year() < 2004 )
2620 inR.setRevision( modifiedCalendar ); 2565 inR.setRevision( modifiedCalendar );
2621 } 2566 }
2622 idS = inL.IDStr(); 2567 idS = inL.IDStr();
2623 local->removeAddressee( inL ); 2568 local->removeAddressee( inL );
2624 inL = inR; 2569 inL = inR;
2625 inL.setIDStr( idS ); 2570 inL.setIDStr( idS );
2626 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2571 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2627 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2572 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2628 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2573 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2629 } 2574 }
2630 inL.setResource( 0 ); 2575 inL.setResource( 0 );
2631 local->insertAddressee( inL , false ); 2576 local->insertAddressee( inL , false );
2632 ++changedLocal; 2577 ++changedLocal;
2633 } 2578 }
2634 } 2579 }
2635 } else { // no conflict 2580 } else { // no conflict
2636 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2581 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2637 QString des = addresseeLSync.note(); 2582 QString des = addresseeLSync.note();
2638 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 2583 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2639 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 2584 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2640 remote->insertAddressee( inR, false ); 2585 remote->insertAddressee( inR, false );
2641 ++deletedAddresseeR; 2586 ++deletedAddresseeR;
2642 } else { 2587 } else {
2643 inR.setRevision( modifiedCalendar ); 2588 inR.setRevision( modifiedCalendar );
2644 remote->insertAddressee( inR, false ); 2589 remote->insertAddressee( inR, false );
2645 inL = inR; 2590 inL = inR;
2646 inL.setResource( 0 ); 2591 inL.setResource( 0 );
2647 local->insertAddressee( inL , false); 2592 local->insertAddressee( inL , false);
2648 ++addedAddressee; 2593 ++addedAddressee;
2649 } 2594 }
2650 } else { 2595 } else {
2651 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { 2596 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2652 inR.setRevision( modifiedCalendar ); 2597 inR.setRevision( modifiedCalendar );
2653 remote->insertAddressee( inR, false ); 2598 remote->insertAddressee( inR, false );
2654 inR.setResource( 0 ); 2599 inR.setResource( 0 );
2655 local->insertAddressee( inR, false ); 2600 local->insertAddressee( inR, false );
2656 ++addedAddressee; 2601 ++addedAddressee;
2657 } else { 2602 } else {
2658 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2603 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2659 remote->removeAddressee( inR ); 2604 remote->removeAddressee( inR );
2660 ++deletedAddresseeR; 2605 ++deletedAddresseeR;
2661 } 2606 }
2662 } 2607 }
2663 } 2608 }
2664 } 2609 }
2665 ++incCounter; 2610 ++incCounter;
2666 } 2611 }
2667 er.clear(); 2612 er.clear();
2668 QStringList el = local->uidList(); 2613 QStringList el = local->uidList();
2669 modulo = (el.count()/10)+1; 2614 modulo = (el.count()/10)+1;
2670 2615
2671 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 2616 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
2672 incCounter = 0; 2617 incCounter = 0;
2673 while ( incCounter < el.count()) { 2618 while ( incCounter < el.count()) {
2674 qApp->processEvents(); 2619 qApp->processEvents();
2675 if (syncManager->isProgressBarCanceled()) 2620 if (syncManager->isProgressBarCanceled())
2676 return false; 2621 return false;
2677 if ( incCounter % modulo == 0 ) 2622 if ( incCounter % modulo == 0 )
2678 syncManager->showProgressBar(incCounter); 2623 syncManager->showProgressBar(incCounter);
2679 uid = el[ incCounter ]; 2624 uid = el[ incCounter ];
2680 bool skipIncidence = false; 2625 bool skipIncidence = false;
2681 if ( uid.left(19) == QString("last-syncAddressee-") ) 2626 if ( uid.left(19) == QString("last-syncAddressee-") )
2682 skipIncidence = true; 2627 skipIncidence = true;
2683 if ( !skipIncidence ) { 2628 if ( !skipIncidence ) {
2684 inL = local->findByUid( uid ); 2629 inL = local->findByUid( uid );
2685 inR = remote->findByUid( uid ); 2630 inR = remote->findByUid( uid );
2686 if ( inR.isEmpty() ) { 2631 if ( inR.isEmpty() ) {
2687 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2632 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2688 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 2633 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
2689 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2634 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2690 local->removeAddressee( inL ); 2635 local->removeAddressee( inL );
2691 ++deletedAddresseeL; 2636 ++deletedAddresseeL;
2692 } else { 2637 } else {
2693 if ( ! syncManager->mWriteBackExistingOnly ) { 2638 if ( ! syncManager->mWriteBackExistingOnly ) {
2694 inL.removeID(mCurrentSyncDevice ); 2639 inL.removeID(mCurrentSyncDevice );
2695 ++addedAddresseeR; 2640 ++addedAddresseeR;
2696 inL.setRevision( modifiedCalendar ); 2641 inL.setRevision( modifiedCalendar );
2697 local->insertAddressee( inL, false ); 2642 local->insertAddressee( inL, false );
2698 inR = inL; 2643 inR = inL;
2699 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); 2644 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL );
2700 inR.setResource( 0 ); 2645 inR.setResource( 0 );
2701 remote->insertAddressee( inR, false ); 2646 remote->insertAddressee( inR, false );
2702 } 2647 }
2703 } 2648 }
2704 } else { 2649 } else {
2705 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { 2650 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
2706 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2651 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2707 local->removeAddressee( inL ); 2652 local->removeAddressee( inL );
2708 ++deletedAddresseeL; 2653 ++deletedAddresseeL;
2709 } else { 2654 } else {
2710 if ( ! syncManager->mWriteBackExistingOnly ) { 2655 if ( ! syncManager->mWriteBackExistingOnly ) {
2711 ++addedAddresseeR; 2656 ++addedAddresseeR;
2712 inL.setRevision( modifiedCalendar ); 2657 inL.setRevision( modifiedCalendar );
2713 local->insertAddressee( inL, false ); 2658 local->insertAddressee( inL, false );
2714 inR = inL; 2659 inR = inL;
2715 inR.setResource( 0 ); 2660 inR.setResource( 0 );
2716 remote->insertAddressee( inR, false ); 2661 remote->insertAddressee( inR, false );
2717 } 2662 }
2718 } 2663 }
2719 } 2664 }
2720 } 2665 }
2721 } 2666 }
2722 ++incCounter; 2667 ++incCounter;
2723 } 2668 }
2724 el.clear(); 2669 el.clear();
2725 syncManager->hideProgressBar(); 2670 syncManager->hideProgressBar();
2726 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 2671 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
2727 // get rid of micro seconds 2672 // get rid of micro seconds
2728 QTime t = mLastAddressbookSync.time(); 2673 QTime t = mLastAddressbookSync.time();
2729 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 2674 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
2730 addresseeLSync.setRevision( mLastAddressbookSync ); 2675 addresseeLSync.setRevision( mLastAddressbookSync );
2731 addresseeRSync.setRevision( mLastAddressbookSync ); 2676 addresseeRSync.setRevision( mLastAddressbookSync );
2732 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 2677 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
2733 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 2678 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
2734 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; 2679 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ;
2735 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); 2680 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") );
2736 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; 2681 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ;
2737 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); 2682 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() );
2738 addresseeRSync.setNote( "" ) ; 2683 addresseeRSync.setNote( "" ) ;
2739 addresseeLSync.setNote( "" ); 2684 addresseeLSync.setNote( "" );
2740 2685
2741 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2686 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2742 remote->insertAddressee( addresseeRSync, false ); 2687 remote->insertAddressee( addresseeRSync, false );
2743 local->insertAddressee( addresseeLSync, false ); 2688 local->insertAddressee( addresseeLSync, false );
2744 QString mes; 2689 QString mes;
2745 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); 2690 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR );
2746 if ( syncManager->mShowSyncSummary ) { 2691 if ( syncManager->mShowSyncSummary ) {
2747 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); 2692 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") );
2748 } 2693 }
2749 qDebug( mes ); 2694 qDebug( mes );
2750 return syncOK; 2695 return syncOK;
2751} 2696}
2752 2697
2753 2698
2754//this is a overwritten callbackmethods from the syncinterface 2699//this is a overwritten callbackmethods from the syncinterface
2755bool KABCore::sync(KSyncManager* manager, QString filename, int mode) 2700bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
2756{ 2701{
2757 2702
2758 //pending prepare addresseeview for output 2703 //pending prepare addresseeview for output
2759 //pending detect, if remote file has REV field. if not switch to external sync 2704 //pending detect, if remote file has REV field. if not switch to external sync
2760 mGlobalSyncMode = SYNC_MODE_NORMAL; 2705 mGlobalSyncMode = SYNC_MODE_NORMAL;
2761 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2706 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2762 2707
2763 AddressBook abLocal(filename,"syncContact"); 2708 AddressBook abLocal(filename,"syncContact");
2764 bool syncOK = false; 2709 bool syncOK = false;
2765 if ( abLocal.load() ) { 2710 if ( abLocal.load() ) {
2766 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); 2711 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode );
2767 bool external = false; 2712 bool external = false;
2768 bool isXML = false; 2713 bool isXML = false;
2769 if ( filename.right(4) == ".xml") { 2714 if ( filename.right(4) == ".xml") {
2770 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2715 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2771 isXML = true; 2716 isXML = true;
2772 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); 2717 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
2773 } else { 2718 } else {
2774 Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2719 Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2775 if ( ! lse.isEmpty() ) { 2720 if ( ! lse.isEmpty() ) {
2776 if ( lse.familyName().left(4) == "!E: " ) 2721 if ( lse.familyName().left(4) == "!E: " )
2777 external = true; 2722 external = true;
2778 } else { 2723 } else {
2779 bool found = false; 2724 bool found = false;
2780 AddressBook::Iterator it; 2725 AddressBook::Iterator it;
2781 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2726 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2782 if ( (*it).revision().date().year() > 2003 ) { 2727 if ( (*it).revision().date().year() > 2003 ) {
2783 found = true; 2728 found = true;
2784 break; 2729 break;
2785 } 2730 }
2786 } 2731 }
2787 external = ! found; 2732 external = ! found;
2788 } 2733 }
2789 2734
2790 if ( external ) { 2735 if ( external ) {
2791 qDebug("Setting vcf mode to external "); 2736 qDebug("Setting vcf mode to external ");
2792 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2737 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2793 AddressBook::Iterator it; 2738 AddressBook::Iterator it;
2794 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2739 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2795 (*it).setID( mCurrentSyncDevice, (*it).uid() ); 2740 (*it).setID( mCurrentSyncDevice, (*it).uid() );
2796 (*it).computeCsum( mCurrentSyncDevice ); 2741 (*it).computeCsum( mCurrentSyncDevice );
2797 } 2742 }
2798 } 2743 }
2799 } 2744 }
2800 //AddressBook::Iterator it; 2745 //AddressBook::Iterator it;
2801 //QStringList vcards; 2746 //QStringList vcards;
2802 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2747 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2803 // qDebug("Name %s ", (*it).familyName().latin1()); 2748 // qDebug("Name %s ", (*it).familyName().latin1());
2804 //} 2749 //}
2805 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2750 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2806 if ( syncOK ) { 2751 if ( syncOK ) {
2807 if ( syncManager->mWriteBackFile ) 2752 if ( syncManager->mWriteBackFile )
2808 { 2753 {
2809 if ( external ) 2754 if ( external )
2810 abLocal.removeSyncAddressees( !isXML); 2755 abLocal.removeSyncAddressees( !isXML);
2811 qDebug("Saving remote AB "); 2756 qDebug("Saving remote AB ");
2812 if ( ! abLocal.saveAB()) 2757 if ( ! abLocal.saveAB())
2813 qDebug("Error writing back AB to file "); 2758 qDebug("Error writing back AB to file ");
2814 if ( isXML ) { 2759 if ( isXML ) {
2815 // afterwrite processing 2760 // afterwrite processing
2816 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2761 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2817 } 2762 }
2818 } 2763 }
2819 } 2764 }
2820 setModified(); 2765 setModified();
2821 2766
2822 } 2767 }
2823 if ( syncOK ) 2768 if ( syncOK )
2824 mViewManager->refreshView(); 2769 mViewManager->refreshView();
2825 return syncOK; 2770 return syncOK;
2826 2771
2827} 2772}
2828 2773
2829 2774
2830//this is a overwritten callbackmethods from the syncinterface 2775//this is a overwritten callbackmethods from the syncinterface
2831bool KABCore::syncExternal(KSyncManager* manager, QString resource) 2776bool KABCore::syncExternal(KSyncManager* manager, QString resource)
2832{ 2777{
2833 if ( resource == "phone" ) 2778 if ( resource == "phone" )
2834 return syncPhone(); 2779 return syncPhone();
2835 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2780 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2836 2781
2837 AddressBook abLocal( resource,"syncContact"); 2782 AddressBook abLocal( resource,"syncContact");
2838 bool syncOK = false; 2783 bool syncOK = false;
2839 if ( abLocal.load() ) { 2784 if ( abLocal.load() ) {
2840 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2785 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1());
2841 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2786 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2842 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); 2787 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
2843 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2788 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2844 if ( syncOK ) { 2789 if ( syncOK ) {
2845 if ( syncManager->mWriteBackFile ) { 2790 if ( syncManager->mWriteBackFile ) {
2791 abLocal.removeSyncAddressees( false );
2846 abLocal.saveAB(); 2792 abLocal.saveAB();
2847 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2793 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2848 } 2794 }
2849 } 2795 }
2850 setModified(); 2796 setModified();
2851 } 2797 }
2852 if ( syncOK ) 2798 if ( syncOK )
2853 mViewManager->refreshView(); 2799 mViewManager->refreshView();
2854 return syncOK; 2800 return syncOK;
2855 2801
2856} 2802}
2857void KABCore::message( QString m ) 2803void KABCore::message( QString m )
2858{ 2804{
2859 2805
2860 topLevelWidget()->setCaption( m ); 2806 topLevelWidget()->setCaption( m );
2861 QTimer::singleShot( 15000, this , SLOT ( setCaptionBack())); 2807 QTimer::singleShot( 15000, this , SLOT ( setCaptionBack()));
2862} 2808}
2863bool KABCore::syncPhone() 2809bool KABCore::syncPhone()
2864{ 2810{
2865 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2811 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2866 QString fileName; 2812 QString fileName;
2867#ifdef _WIN32_ 2813#ifdef _WIN32_
2868 fileName = locateLocal("tmp", "phonefile.vcf"); 2814 fileName = locateLocal("tmp", "phonefile.vcf");
2869#else 2815#else
2870 fileName = "/tmp/phonefile.vcf"; 2816 fileName = "/tmp/phonefile.vcf";
2871#endif 2817#endif
2872 if ( !PhoneAccess::readFromPhone( fileName) ) { 2818 if ( !PhoneAccess::readFromPhone( fileName) ) {
2873 message(i18n("Phone access failed!")); 2819 message(i18n("Phone access failed!"));
2874 return false; 2820 return false;
2875 } 2821 }
2876 AddressBook abLocal( fileName,"syncContact"); 2822 AddressBook abLocal( fileName,"syncContact");
2877 bool syncOK = false; 2823 bool syncOK = false;
2878 if ( abLocal.load() ) { 2824 {
2825 abLocal.importFromFile( fileName );
2879 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2826 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1());
2880 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2827 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2881 abLocal.preparePhoneSync( mCurrentSyncDevice, true ); 2828 abLocal.preparePhoneSync( mCurrentSyncDevice, true );
2882 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); 2829 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
2883 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2830 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2884 if ( syncOK ) { 2831 if ( syncOK ) {
2885 if ( syncManager->mWriteBackFile ) { 2832 if ( syncManager->mWriteBackFile ) {
2833 abLocal.removeSyncAddressees( true );
2886 abLocal.saveABphone( fileName ); 2834 abLocal.saveABphone( fileName );
2887 abLocal.preparePhoneSync( mCurrentSyncDevice, false ); 2835 abLocal.findNewExtIds( fileName, mCurrentSyncDevice );
2888 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); 2836 //abLocal.preparePhoneSync( mCurrentSyncDevice, false );
2889 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2837 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2890 } 2838 }
2891 } 2839 }
2892 setModified(); 2840 setModified();
2893 } 2841 }
2894 if ( syncOK ) 2842 if ( syncOK )
2895 mViewManager->refreshView(); 2843 mViewManager->refreshView();
2896 return syncOK; 2844 return syncOK;
2897} 2845}
2898void KABCore::getFile( bool success ) 2846void KABCore::getFile( bool success )
2899{ 2847{
2900 if ( ! success ) { 2848 if ( ! success ) {
2901 message( i18n("Error receiving file. Nothing changed!") ); 2849 message( i18n("Error receiving file. Nothing changed!") );
2902 return; 2850 return;
2903 } 2851 }
2904 mAddressBook->importFromFile( sentSyncFile() , false, true ); 2852 mAddressBook->importFromFile( sentSyncFile() , false, true );
2905 message( i18n("Pi-Sync successful!") ); 2853 message( i18n("Pi-Sync successful!") );
2906 mViewManager->refreshView(); 2854 mViewManager->refreshView();
2907} 2855}
2908void KABCore::syncFileRequest() 2856void KABCore::syncFileRequest()
2909{ 2857{
2910 mAddressBook->export2File( sentSyncFile() ); 2858 mAddressBook->export2File( sentSyncFile() );
2911} 2859}
2912QString KABCore::sentSyncFile() 2860QString KABCore::sentSyncFile()
2913{ 2861{
2914#ifdef _WIN32_ 2862#ifdef _WIN32_
2915 return locateLocal( "tmp", "copysyncab.vcf" ); 2863 return locateLocal( "tmp", "copysyncab.vcf" );
2916#else 2864#else
2917 return QString( "/tmp/copysyncab.vcf" ); 2865 return QString( "/tmp/copysyncab.vcf" );
2918#endif 2866#endif
2919} 2867}
2920 2868
2921void KABCore::setCaptionBack() 2869void KABCore::setCaptionBack()
2922{ 2870{
2923 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); 2871 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") );
2924} 2872}