summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp11
-rw-r--r--kabc/addressbook.h1
-rw-r--r--kabc/addressee.cpp2
-rw-r--r--kabc/plugins/sharpdtm/resourcesharpdtm.cpp215
-rw-r--r--kabc/tmpaddressbook.cpp9
-rw-r--r--kaddressbook/kabcore.cpp31
6 files changed, 78 insertions, 191 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 4c4ae09..8487ff3 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -1,1248 +1,1259 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library 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 GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28/*US 28/*US
29 29
30#include <qfile.h> 30#include <qfile.h>
31#include <qregexp.h> 31#include <qregexp.h>
32#include <qtimer.h> 32#include <qtimer.h>
33 33
34#include <kapplication.h> 34#include <kapplication.h>
35#include <kinstance.h> 35#include <kinstance.h>
36#include <kstandarddirs.h> 36#include <kstandarddirs.h>
37 37
38#include "errorhandler.h" 38#include "errorhandler.h"
39*/ 39*/
40#include <qptrlist.h> 40#include <qptrlist.h>
41#include <qtextstream.h> 41#include <qtextstream.h>
42#include <qfile.h> 42#include <qfile.h>
43#include <qregexp.h> 43#include <qregexp.h>
44 44
45#include <kglobal.h> 45#include <kglobal.h>
46#include <klocale.h> 46#include <klocale.h>
47#include <kmessagebox.h> 47#include <kmessagebox.h>
48#include <kdebug.h> 48#include <kdebug.h>
49#include <libkcal/syncdefines.h> 49#include <libkcal/syncdefines.h>
50#include <libkdepim/phoneaccess.h> 50#include <libkdepim/phoneaccess.h>
51#include "addressbook.h" 51#include "addressbook.h"
52#include "resource.h" 52#include "resource.h"
53#include "vcardconverter.h" 53#include "vcardconverter.h"
54#include "vcardparser/vcardtool.h" 54#include "vcardparser/vcardtool.h"
55 55
56//US #include "addressbook.moc" 56//US #include "addressbook.moc"
57 57
58using namespace KABC; 58using namespace KABC;
59 59
60struct AddressBook::AddressBookData 60struct AddressBook::AddressBookData
61{ 61{
62 Addressee::List mAddressees; 62 Addressee::List mAddressees;
63 Addressee::List mRemovedAddressees; 63 Addressee::List mRemovedAddressees;
64 Field::List mAllFields; 64 Field::List mAllFields;
65 KConfig *mConfig; 65 KConfig *mConfig;
66 KRES::Manager<Resource> *mManager; 66 KRES::Manager<Resource> *mManager;
67//US ErrorHandler *mErrorHandler; 67//US ErrorHandler *mErrorHandler;
68}; 68};
69 69
70struct AddressBook::Iterator::IteratorData 70struct AddressBook::Iterator::IteratorData
71{ 71{
72 Addressee::List::Iterator mIt; 72 Addressee::List::Iterator mIt;
73}; 73};
74 74
75struct AddressBook::ConstIterator::ConstIteratorData 75struct AddressBook::ConstIterator::ConstIteratorData
76{ 76{
77 Addressee::List::ConstIterator mIt; 77 Addressee::List::ConstIterator mIt;
78}; 78};
79 79
80AddressBook::Iterator::Iterator() 80AddressBook::Iterator::Iterator()
81{ 81{
82 d = new IteratorData; 82 d = new IteratorData;
83} 83}
84 84
85AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) 85AddressBook::Iterator::Iterator( const AddressBook::Iterator &i )
86{ 86{
87 d = new IteratorData; 87 d = new IteratorData;
88 d->mIt = i.d->mIt; 88 d->mIt = i.d->mIt;
89} 89}
90 90
91AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) 91AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i )
92{ 92{
93 if( this == &i ) return *this; // guard against self assignment 93 if( this == &i ) return *this; // guard against self assignment
94 delete d; // delete the old data the Iterator was completely constructed before 94 delete d; // delete the old data the Iterator was completely constructed before
95 d = new IteratorData; 95 d = new IteratorData;
96 d->mIt = i.d->mIt; 96 d->mIt = i.d->mIt;
97 return *this; 97 return *this;
98} 98}
99 99
100AddressBook::Iterator::~Iterator() 100AddressBook::Iterator::~Iterator()
101{ 101{
102 delete d; 102 delete d;
103} 103}
104 104
105const Addressee &AddressBook::Iterator::operator*() const 105const Addressee &AddressBook::Iterator::operator*() const
106{ 106{
107 return *(d->mIt); 107 return *(d->mIt);
108} 108}
109 109
110Addressee &AddressBook::Iterator::operator*() 110Addressee &AddressBook::Iterator::operator*()
111{ 111{
112 return *(d->mIt); 112 return *(d->mIt);
113} 113}
114 114
115Addressee *AddressBook::Iterator::operator->() 115Addressee *AddressBook::Iterator::operator->()
116{ 116{
117 return &(*(d->mIt)); 117 return &(*(d->mIt));
118} 118}
119 119
120AddressBook::Iterator &AddressBook::Iterator::operator++() 120AddressBook::Iterator &AddressBook::Iterator::operator++()
121{ 121{
122 (d->mIt)++; 122 (d->mIt)++;
123 return *this; 123 return *this;
124} 124}
125 125
126AddressBook::Iterator &AddressBook::Iterator::operator++(int) 126AddressBook::Iterator &AddressBook::Iterator::operator++(int)
127{ 127{
128 (d->mIt)++; 128 (d->mIt)++;
129 return *this; 129 return *this;
130} 130}
131 131
132AddressBook::Iterator &AddressBook::Iterator::operator--() 132AddressBook::Iterator &AddressBook::Iterator::operator--()
133{ 133{
134 (d->mIt)--; 134 (d->mIt)--;
135 return *this; 135 return *this;
136} 136}
137 137
138AddressBook::Iterator &AddressBook::Iterator::operator--(int) 138AddressBook::Iterator &AddressBook::Iterator::operator--(int)
139{ 139{
140 (d->mIt)--; 140 (d->mIt)--;
141 return *this; 141 return *this;
142} 142}
143 143
144bool AddressBook::Iterator::operator==( const Iterator &it ) 144bool AddressBook::Iterator::operator==( const Iterator &it )
145{ 145{
146 return ( d->mIt == it.d->mIt ); 146 return ( d->mIt == it.d->mIt );
147} 147}
148 148
149bool AddressBook::Iterator::operator!=( const Iterator &it ) 149bool AddressBook::Iterator::operator!=( const Iterator &it )
150{ 150{
151 return ( d->mIt != it.d->mIt ); 151 return ( d->mIt != it.d->mIt );
152} 152}
153 153
154 154
155AddressBook::ConstIterator::ConstIterator() 155AddressBook::ConstIterator::ConstIterator()
156{ 156{
157 d = new ConstIteratorData; 157 d = new ConstIteratorData;
158} 158}
159 159
160AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) 160AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i )
161{ 161{
162 d = new ConstIteratorData; 162 d = new ConstIteratorData;
163 d->mIt = i.d->mIt; 163 d->mIt = i.d->mIt;
164} 164}
165 165
166AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) 166AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i )
167{ 167{
168 if( this == &i ) return *this; // guard for self assignment 168 if( this == &i ) return *this; // guard for self assignment
169 delete d; // delete the old data because the Iterator was really constructed before 169 delete d; // delete the old data because the Iterator was really constructed before
170 d = new ConstIteratorData; 170 d = new ConstIteratorData;
171 d->mIt = i.d->mIt; 171 d->mIt = i.d->mIt;
172 return *this; 172 return *this;
173} 173}
174 174
175AddressBook::ConstIterator::~ConstIterator() 175AddressBook::ConstIterator::~ConstIterator()
176{ 176{
177 delete d; 177 delete d;
178} 178}
179 179
180const Addressee &AddressBook::ConstIterator::operator*() const 180const Addressee &AddressBook::ConstIterator::operator*() const
181{ 181{
182 return *(d->mIt); 182 return *(d->mIt);
183} 183}
184 184
185const Addressee* AddressBook::ConstIterator::operator->() const 185const Addressee* AddressBook::ConstIterator::operator->() const
186{ 186{
187 return &(*(d->mIt)); 187 return &(*(d->mIt));
188} 188}
189 189
190AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() 190AddressBook::ConstIterator &AddressBook::ConstIterator::operator++()
191{ 191{
192 (d->mIt)++; 192 (d->mIt)++;
193 return *this; 193 return *this;
194} 194}
195 195
196AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) 196AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int)
197{ 197{
198 (d->mIt)++; 198 (d->mIt)++;
199 return *this; 199 return *this;
200} 200}
201 201
202AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() 202AddressBook::ConstIterator &AddressBook::ConstIterator::operator--()
203{ 203{
204 (d->mIt)--; 204 (d->mIt)--;
205 return *this; 205 return *this;
206} 206}
207 207
208AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) 208AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int)
209{ 209{
210 (d->mIt)--; 210 (d->mIt)--;
211 return *this; 211 return *this;
212} 212}
213 213
214bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) 214bool AddressBook::ConstIterator::operator==( const ConstIterator &it )
215{ 215{
216 return ( d->mIt == it.d->mIt ); 216 return ( d->mIt == it.d->mIt );
217} 217}
218 218
219bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) 219bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
220{ 220{
221 return ( d->mIt != it.d->mIt ); 221 return ( d->mIt != it.d->mIt );
222} 222}
223 223
224 224
225AddressBook::AddressBook() 225AddressBook::AddressBook()
226{ 226{
227 init(0, "contact"); 227 init(0, "contact");
228} 228}
229 229
230AddressBook::AddressBook( const QString &config ) 230AddressBook::AddressBook( const QString &config )
231{ 231{
232 init(config, "contact"); 232 init(config, "contact");
233} 233}
234 234
235AddressBook::AddressBook( const QString &config, const QString &family ) 235AddressBook::AddressBook( const QString &config, const QString &family )
236{ 236{
237 init(config, family); 237 init(config, family);
238 238
239} 239}
240 240
241// the default family is "contact" 241// the default family is "contact"
242void AddressBook::init(const QString &config, const QString &family ) 242void AddressBook::init(const QString &config, const QString &family )
243{ 243{
244 blockLSEchange = false; 244 blockLSEchange = false;
245 d = new AddressBookData; 245 d = new AddressBookData;
246 QString fami = family; 246 QString fami = family;
247 if (config != 0) { 247 if (config != 0) {
248 if ( family == "syncContact" ) { 248 if ( family == "syncContact" ) {
249 qDebug("creating sync config "); 249 qDebug("creating sync config ");
250 fami = "contact"; 250 fami = "contact";
251 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); 251 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") );
252 con->setGroup( "General" ); 252 con->setGroup( "General" );
253 con->writeEntry( "ResourceKeys", QString("sync") ); 253 con->writeEntry( "ResourceKeys", QString("sync") );
254 con->writeEntry( "Standard", QString("sync") ); 254 con->writeEntry( "Standard", QString("sync") );
255 con->setGroup( "Resource_sync" ); 255 con->setGroup( "Resource_sync" );
256 con->writeEntry( "FileName", config ); 256 con->writeEntry( "FileName", config );
257 con->writeEntry( "FileFormat", QString("vcard") ); 257 con->writeEntry( "FileFormat", QString("vcard") );
258 con->writeEntry( "ResourceIdentifier", QString("sync") ); 258 con->writeEntry( "ResourceIdentifier", QString("sync") );
259 con->writeEntry( "ResourceName", QString("sync_res") ); 259 con->writeEntry( "ResourceName", QString("sync_res") );
260 if ( config.right(4) == ".xml" ) 260 if ( config.right(4) == ".xml" )
261 con->writeEntry( "ResourceType", QString("qtopia") ); 261 con->writeEntry( "ResourceType", QString("qtopia") );
262 else if ( config == "sharp" ) { 262 else if ( config == "sharp" ) {
263 con->writeEntry( "ResourceType", QString("sharp") ); 263 con->writeEntry( "ResourceType", QString("sharp") );
264 } else { 264 } else {
265 con->writeEntry( "ResourceType", QString("file") ); 265 con->writeEntry( "ResourceType", QString("file") );
266 } 266 }
267 //con->sync(); 267 //con->sync();
268 d->mConfig = con; 268 d->mConfig = con;
269 } 269 }
270 else 270 else
271 d->mConfig = new KConfig( locateLocal("config", config) ); 271 d->mConfig = new KConfig( locateLocal("config", config) );
272// qDebug("AddressBook::init 1 config=%s",config.latin1() ); 272// qDebug("AddressBook::init 1 config=%s",config.latin1() );
273 } 273 }
274 else { 274 else {
275 d->mConfig = 0; 275 d->mConfig = 0;
276// qDebug("AddressBook::init 1 config=0"); 276// qDebug("AddressBook::init 1 config=0");
277 } 277 }
278 278
279//US d->mErrorHandler = 0; 279//US d->mErrorHandler = 0;
280 d->mManager = new KRES::Manager<Resource>( fami ); 280 d->mManager = new KRES::Manager<Resource>( fami );
281 d->mManager->readConfig( d->mConfig ); 281 d->mManager->readConfig( d->mConfig );
282 if ( family == "syncContact" ) { 282 if ( family == "syncContact" ) {
283 KRES::Manager<Resource> *manager = d->mManager; 283 KRES::Manager<Resource> *manager = d->mManager;
284 KRES::Manager<Resource>::ActiveIterator it; 284 KRES::Manager<Resource>::ActiveIterator it;
285 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 285 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
286 (*it)->setAddressBook( this ); 286 (*it)->setAddressBook( this );
287 if ( !(*it)->open() ) 287 if ( !(*it)->open() )
288 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 288 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
289 } 289 }
290 Resource *res = standardResource(); 290 Resource *res = standardResource();
291 if ( !res ) { 291 if ( !res ) {
292 qDebug("ERROR: no standard resource"); 292 qDebug("ERROR: no standard resource");
293 res = manager->createResource( "file" ); 293 res = manager->createResource( "file" );
294 if ( res ) 294 if ( res )
295 { 295 {
296 addResource( res ); 296 addResource( res );
297 } 297 }
298 else 298 else
299 qDebug(" No resource available!!!"); 299 qDebug(" No resource available!!!");
300 } 300 }
301 setStandardResource( res ); 301 setStandardResource( res );
302 manager->writeConfig(); 302 manager->writeConfig();
303 } 303 }
304 addCustomField( i18n( "Department" ), KABC::Field::Organization, 304 addCustomField( i18n( "Department" ), KABC::Field::Organization,
305 "X-Department", "KADDRESSBOOK" ); 305 "X-Department", "KADDRESSBOOK" );
306 addCustomField( i18n( "Profession" ), KABC::Field::Organization, 306 addCustomField( i18n( "Profession" ), KABC::Field::Organization,
307 "X-Profession", "KADDRESSBOOK" ); 307 "X-Profession", "KADDRESSBOOK" );
308 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 308 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
309 "X-AssistantsName", "KADDRESSBOOK" ); 309 "X-AssistantsName", "KADDRESSBOOK" );
310 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 310 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
311 "X-ManagersName", "KADDRESSBOOK" ); 311 "X-ManagersName", "KADDRESSBOOK" );
312 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 312 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
313 "X-SpousesName", "KADDRESSBOOK" ); 313 "X-SpousesName", "KADDRESSBOOK" );
314 addCustomField( i18n( "Office" ), KABC::Field::Personal, 314 addCustomField( i18n( "Office" ), KABC::Field::Personal,
315 "X-Office", "KADDRESSBOOK" ); 315 "X-Office", "KADDRESSBOOK" );
316 addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 316 addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
317 "X-IMAddress", "KADDRESSBOOK" ); 317 "X-IMAddress", "KADDRESSBOOK" );
318 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 318 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
319 "X-Anniversary", "KADDRESSBOOK" ); 319 "X-Anniversary", "KADDRESSBOOK" );
320 320
321 //US added this field to become compatible with Opie/qtopia addressbook 321 //US added this field to become compatible with Opie/qtopia addressbook
322 // values can be "female" or "male" or "". An empty field represents undefined. 322 // values can be "female" or "male" or "". An empty field represents undefined.
323 addCustomField( i18n( "Gender" ), KABC::Field::Personal, 323 addCustomField( i18n( "Gender" ), KABC::Field::Personal,
324 "X-Gender", "KADDRESSBOOK" ); 324 "X-Gender", "KADDRESSBOOK" );
325 addCustomField( i18n( "Children" ), KABC::Field::Personal, 325 addCustomField( i18n( "Children" ), KABC::Field::Personal,
326 "X-Children", "KADDRESSBOOK" ); 326 "X-Children", "KADDRESSBOOK" );
327 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 327 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
328 "X-FreeBusyUrl", "KADDRESSBOOK" ); 328 "X-FreeBusyUrl", "KADDRESSBOOK" );
329 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, 329 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal,
330 "X-ExternalID", "KADDRESSBOOK" ); 330 "X-ExternalID", "KADDRESSBOOK" );
331} 331}
332 332
333AddressBook::~AddressBook() 333AddressBook::~AddressBook()
334{ 334{
335 delete d->mConfig; d->mConfig = 0; 335 delete d->mConfig; d->mConfig = 0;
336 delete d->mManager; d->mManager = 0; 336 delete d->mManager; d->mManager = 0;
337//US delete d->mErrorHandler; d->mErrorHandler = 0; 337//US delete d->mErrorHandler; d->mErrorHandler = 0;
338 delete d; d = 0; 338 delete d; d = 0;
339} 339}
340 340
341bool AddressBook::load() 341bool AddressBook::load()
342{ 342{
343 343
344 clear(); 344 clear();
345 KRES::Manager<Resource>::ActiveIterator it; 345 KRES::Manager<Resource>::ActiveIterator it;
346 bool ok = true; 346 bool ok = true;
347 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 347 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
348 if ( !(*it)->load() ) { 348 if ( !(*it)->load() ) {
349 qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 349 qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
350 ok = false; 350 ok = false;
351 } else { 351 } else {
352 qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); 352 qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) );
353 } 353 }
354 // mark all addressees as unchanged 354 // mark all addressees as unchanged
355 Addressee::List::Iterator addrIt; 355 Addressee::List::Iterator addrIt;
356 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { 356 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) {
357 (*addrIt).setChanged( false ); 357 (*addrIt).setChanged( false );
358 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); 358 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" );
359 if ( !id.isEmpty() ) { 359 if ( !id.isEmpty() ) {
360 //qDebug("setId aa %s ", id.latin1()); 360 //qDebug("setId aa %s ", id.latin1());
361 (*addrIt).setIDStr(id ); 361 (*addrIt).setIDStr(id );
362 } 362 }
363 } 363 }
364 blockLSEchange = true; 364 blockLSEchange = true;
365 return ok; 365 return ok;
366} 366}
367 367
368bool AddressBook::save( Ticket *ticket ) 368bool AddressBook::save( Ticket *ticket )
369{ 369{
370 kdDebug(5700) << "AddressBook::save()"<< endl; 370 kdDebug(5700) << "AddressBook::save()"<< endl;
371 371
372 if ( ticket->resource() ) { 372 if ( ticket->resource() ) {
373 deleteRemovedAddressees(); 373 deleteRemovedAddressees();
374 return ticket->resource()->save( ticket ); 374 return ticket->resource()->save( ticket );
375 } 375 }
376 376
377 return false; 377 return false;
378} 378}
379// exports all Addressees, which are syncable 379// exports all Addressees, which are syncable
380void AddressBook::export2File( QString fileName ) 380void AddressBook::export2File( QString fileName )
381{ 381{
382 382
383 QFile outFile( fileName ); 383 QFile outFile( fileName );
384 if ( !outFile.open( IO_WriteOnly ) ) { 384 if ( !outFile.open( IO_WriteOnly ) ) {
385 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); 385 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" );
386 KMessageBox::error( 0, text.arg( fileName ) ); 386 KMessageBox::error( 0, text.arg( fileName ) );
387 return ; 387 return ;
388 } 388 }
389 QTextStream t( &outFile ); 389 QTextStream t( &outFile );
390 t.setEncoding( QTextStream::UnicodeUTF8 ); 390 t.setEncoding( QTextStream::UnicodeUTF8 );
391 Iterator it; 391 Iterator it;
392 KABC::VCardConverter::Version version; 392 KABC::VCardConverter::Version version;
393 version = KABC::VCardConverter::v3_0; 393 version = KABC::VCardConverter::v3_0;
394 for ( it = begin(); it != end(); ++it ) { 394 for ( it = begin(); it != end(); ++it ) {
395 if ( (*it).resource() && (*it).resource()->includeInSync() ) { 395 if ( (*it).resource() && (*it).resource()->includeInSync() ) {
396 if ( !(*it).IDStr().isEmpty() ) { 396 if ( !(*it).IDStr().isEmpty() ) {
397 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); 397 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() );
398 } 398 }
399 KABC::VCardConverter converter; 399 KABC::VCardConverter converter;
400 QString vcard; 400 QString vcard;
401 //Resource *resource() const; 401 //Resource *resource() const;
402 converter.addresseeToVCard( *it, vcard, version ); 402 converter.addresseeToVCard( *it, vcard, version );
403 t << vcard << "\r\n"; 403 t << vcard << "\r\n";
404 } 404 }
405 } 405 }
406 t << "\r\n\r\n"; 406 t << "\r\n\r\n";
407 outFile.close(); 407 outFile.close();
408} 408}
409// if QStringList uids is empty, all are exported 409// if QStringList uids is empty, all are exported
410bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) 410bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName )
411{ 411{
412 KABC::VCardConverter converter; 412 KABC::VCardConverter converter;
413 QString datastream; 413 QString datastream;
414 Iterator it; 414 Iterator it;
415 bool all = uids.isEmpty(); 415 bool all = uids.isEmpty();
416 for ( it = begin(); it != end(); ++it ) { 416 for ( it = begin(); it != end(); ++it ) {
417 // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 417 // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
418 if ( ! all ) { 418 if ( ! all ) {
419 if ( ! ( uids.contains((*it).uid() ) )) 419 if ( ! ( uids.contains((*it).uid() ) ))
420 continue; 420 continue;
421 } 421 }
422 KABC::Addressee a = ( *it ); 422 KABC::Addressee a = ( *it );
423 if ( a.isEmpty() ) 423 if ( a.isEmpty() )
424 continue; 424 continue;
425 if ( all && a.resource() && !a.resource()->includeInSync() ) 425 if ( all && a.resource() && !a.resource()->includeInSync() )
426 continue; 426 continue;
427 a.simplifyEmails(); 427 a.simplifyEmails();
428 a.simplifyPhoneNumbers(); 428 a.simplifyPhoneNumbers();
429 a.simplifyPhoneNumberTypes(); 429 a.simplifyPhoneNumberTypes();
430 a.simplifyAddresses(); 430 a.simplifyAddresses();
431 431
432 QString vcard; 432 QString vcard;
433 QString vcardnew; 433 QString vcardnew;
434 converter.addresseeToVCard( a, vcard ); 434 converter.addresseeToVCard( a, vcard );
435 int start = 0; 435 int start = 0;
436 int next; 436 int next;
437 while ( (next = vcard.find("TYPE=", start) )>= 0 ) { 437 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
438 int semi = vcard.find(";", next); 438 int semi = vcard.find(";", next);
439 int dopp = vcard.find(":", next); 439 int dopp = vcard.find(":", next);
440 int sep; 440 int sep;
441 if ( semi < dopp && semi >= 0 ) 441 if ( semi < dopp && semi >= 0 )
442 sep = semi ; 442 sep = semi ;
443 else 443 else
444 sep = dopp; 444 sep = dopp;
445 vcardnew +=vcard.mid( start, next - start); 445 vcardnew +=vcard.mid( start, next - start);
446 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); 446 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper();
447 start = sep; 447 start = sep;
448 } 448 }
449 vcardnew += vcard.mid( start,vcard.length() ); 449 vcardnew += vcard.mid( start,vcard.length() );
450 vcard = ""; 450 vcard = "";
451 start = 0; 451 start = 0;
452 while ( (next = vcardnew.find("ADR", start) )>= 0 ) { 452 while ( (next = vcardnew.find("ADR", start) )>= 0 ) {
453 int sep = vcardnew.find(":", next); 453 int sep = vcardnew.find(":", next);
454 vcard +=vcardnew.mid( start, next - start+3); 454 vcard +=vcardnew.mid( start, next - start+3);
455 start = sep; 455 start = sep;
456 } 456 }
457 vcard += vcardnew.mid( start,vcardnew.length() ); 457 vcard += vcardnew.mid( start,vcardnew.length() );
458 vcard.replace ( QRegExp(";;;") , "" ); 458 vcard.replace ( QRegExp(";;;") , "" );
459 vcard.replace ( QRegExp(";;") , "" ); 459 vcard.replace ( QRegExp(";;") , "" );
460 datastream += vcard; 460 datastream += vcard;
461 461
462 } 462 }
463 463
464 QFile outFile(fileName); 464 QFile outFile(fileName);
465 if ( outFile.open(IO_WriteOnly) ) { 465 if ( outFile.open(IO_WriteOnly) ) {
466 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); 466 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
467 QTextStream t( &outFile ); // use a text stream 467 QTextStream t( &outFile ); // use a text stream
468 t.setEncoding( QTextStream::UnicodeUTF8 ); 468 t.setEncoding( QTextStream::UnicodeUTF8 );
469 t <<datastream; 469 t <<datastream;
470 t << "\r\n\r\n"; 470 t << "\r\n\r\n";
471 outFile.close(); 471 outFile.close();
472 472
473 } else { 473 } else {
474 qDebug("Error open temp file "); 474 qDebug("Error open temp file ");
475 return false; 475 return false;
476 } 476 }
477 return true; 477 return true;
478 478
479} 479}
480int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) 480int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld )
481{ 481{
482 482
483 if ( removeOld ) 483 if ( removeOld )
484 setUntagged( true ); 484 setUntagged( true );
485 KABC::Addressee::List list; 485 KABC::Addressee::List list;
486 QFile file( fileName ); 486 QFile file( fileName );
487 file.open( IO_ReadOnly ); 487 file.open( IO_ReadOnly );
488 QByteArray rawData = file.readAll(); 488 QByteArray rawData = file.readAll();
489 file.close(); 489 file.close();
490 QString data; 490 QString data;
491 if ( replaceLabel ) { 491 if ( replaceLabel ) {
492 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); 492 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 );
493 data.replace ( QRegExp("LABEL") , "ADR" ); 493 data.replace ( QRegExp("LABEL") , "ADR" );
494 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); 494 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" );
495 } else 495 } else
496 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 496 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
497 KABC::VCardTool tool; 497 KABC::VCardTool tool;
498 list = tool.parseVCards( data ); 498 list = tool.parseVCards( data );
499 KABC::Addressee::List::Iterator it; 499 KABC::Addressee::List::Iterator it;
500 for ( it = list.begin(); it != list.end(); ++it ) { 500 for ( it = list.begin(); it != list.end(); ++it ) {
501 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); 501 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
502 if ( !id.isEmpty() ) 502 if ( !id.isEmpty() )
503 (*it).setIDStr(id ); 503 (*it).setIDStr(id );
504 (*it).setResource( 0 ); 504 (*it).setResource( 0 );
505 if ( replaceLabel ) 505 if ( replaceLabel )
506 (*it).removeVoice(); 506 (*it).removeVoice();
507 if ( removeOld ) 507 if ( removeOld )
508 (*it).setTagged( true ); 508 (*it).setTagged( true );
509 insertAddressee( (*it), false, true ); 509 insertAddressee( (*it), false, true );
510 } 510 }
511 if ( removeOld ) 511 if ( removeOld )
512 removeUntagged(); 512 removeUntagged();
513 return list.count(); 513 return list.count();
514} 514}
515void AddressBook::setUntagged(bool setNonSyncTagged) // = false) 515void AddressBook::setUntagged(bool setNonSyncTagged) // = false)
516{ 516{
517 Iterator ait; 517 Iterator ait;
518 for ( ait = begin(); ait != end(); ++ait ) { 518 for ( ait = begin(); ait != end(); ++ait ) {
519 if ( setNonSyncTagged ) { 519 if ( setNonSyncTagged ) {
520 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { 520 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) {
521 (*ait).setTagged( true ); 521 (*ait).setTagged( true );
522 } else 522 } else
523 (*ait).setTagged( false ); 523 (*ait).setTagged( false );
524 } else 524 } else
525 (*ait).setTagged( false ); 525 (*ait).setTagged( false );
526 } 526 }
527} 527}
528void AddressBook::removeUntagged() 528void AddressBook::removeUntagged()
529{ 529{
530 Iterator ait; 530 Iterator ait;
531 bool todelete = false; 531 bool todelete = false;
532 Iterator todel; 532 Iterator todel;
533 for ( ait = begin(); ait != end(); ++ait ) { 533 for ( ait = begin(); ait != end(); ++ait ) {
534 if ( todelete ) 534 if ( todelete )
535 removeAddressee( todel ); 535 removeAddressee( todel );
536 if (!(*ait).tagged()) { 536 if (!(*ait).tagged()) {
537 todelete = true; 537 todelete = true;
538 todel = ait; 538 todel = ait;
539 } else 539 } else
540 todelete = false; 540 todelete = false;
541 } 541 }
542 if ( todelete ) 542 if ( todelete )
543 removeAddressee( todel ); 543 removeAddressee( todel );
544 deleteRemovedAddressees(); 544 deleteRemovedAddressees();
545} 545}
546void AddressBook::smplifyAddressees() 546void AddressBook::smplifyAddressees()
547{ 547{
548 Iterator ait; 548 Iterator ait;
549 for ( ait = begin(); ait != end(); ++ait ) { 549 for ( ait = begin(); ait != end(); ++ait ) {
550 (*ait).simplifyEmails(); 550 (*ait).simplifyEmails();
551 (*ait).simplifyPhoneNumbers(); 551 (*ait).simplifyPhoneNumbers();
552 (*ait).simplifyPhoneNumberTypes(); 552 (*ait).simplifyPhoneNumberTypes();
553 (*ait).simplifyAddresses(); 553 (*ait).simplifyAddresses();
554 } 554 }
555} 555}
556void AddressBook::removeSyncInfo( QString syncProfile) 556void AddressBook::removeSyncInfo( QString syncProfile)
557{ 557{
558 Iterator ait; 558 Iterator ait;
559 for ( ait = begin(); ait != end(); ++ait ) { 559 for ( ait = begin(); ait != end(); ++ait ) {
560 (*ait).removeID( syncProfile ); 560 (*ait).removeID( syncProfile );
561 } 561 }
562 if ( syncProfile.isEmpty() ) { 562 if ( syncProfile.isEmpty() ) {
563 Iterator it = begin(); 563 Iterator it = begin();
564 Iterator it2 ; 564 Iterator it2 ;
565 while ( it != end() ) { 565 while ( it != end() ) {
566 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 566 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
567 it2 = it; 567 it2 = it;
568 //qDebug("removing %s ",(*it).uid().latin1() ); 568 //qDebug("removing %s ",(*it).uid().latin1() );
569 ++it; 569 ++it;
570 removeAddressee( it2 ); 570 removeAddressee( it2 );
571 } else { 571 } else {
572 //qDebug("skipping %s ",(*it).uid().latin1() ); 572 //qDebug("skipping %s ",(*it).uid().latin1() );
573 ++it; 573 ++it;
574 } 574 }
575 } 575 }
576 } else { 576 } else {
577 Addressee lse; 577 Addressee lse;
578 lse = findByUid( "last-syncAddressee-"+ syncProfile ); 578 lse = findByUid( "last-syncAddressee-"+ syncProfile );
579 if ( ! lse.isEmpty() ) 579 if ( ! lse.isEmpty() )
580 removeAddressee( lse ); 580 removeAddressee( lse );
581 } 581 }
582 582
583} 583}
584void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) 584void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync )
585{ 585{
586 Iterator ait; 586 Iterator ait;
587 for ( ait = begin(); ait != end(); ++ait ) { 587 for ( ait = begin(); ait != end(); ++ait ) {
588 QString id = (*ait).IDStr(); 588 QString id = (*ait).IDStr();
589 (*ait).setIDStr( ":"); 589 (*ait).setIDStr( ":");
590 (*ait).setExternalUID( id ); 590 (*ait).setExternalUID( id );
591 (*ait).setOriginalExternalUID( id ); 591 (*ait).setOriginalExternalUID( id );
592 if ( isPreSync ) 592 if ( isPreSync )
593 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 593 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
594 else { 594 else {
595 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 595 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
596 (*ait).setID( currentSyncDevice,id ); 596 (*ait).setID( currentSyncDevice,id );
597 597
598 } 598 }
599 } 599 }
600} 600}
601void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) 601void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice )
602{ 602{
603 603
604 setUntagged(); 604 setUntagged();
605 KABC::Addressee::List list; 605 KABC::Addressee::List list;
606 QFile file( fileName ); 606 QFile file( fileName );
607 file.open( IO_ReadOnly ); 607 file.open( IO_ReadOnly );
608 QByteArray rawData = file.readAll(); 608 QByteArray rawData = file.readAll();
609 file.close(); 609 file.close();
610 QString data; 610 QString data;
611 611
612 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 612 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
613 KABC::VCardTool tool; 613 KABC::VCardTool tool;
614 list = tool.parseVCards( data ); 614 list = tool.parseVCards( data );
615 KABC::Addressee::List::Iterator it; 615 KABC::Addressee::List::Iterator it;
616 for ( it = list.begin(); it != list.end(); ++it ) { 616 for ( it = list.begin(); it != list.end(); ++it ) {
617 Iterator ait; 617 Iterator ait;
618 for ( ait = begin(); ait != end(); ++ait ) { 618 for ( ait = begin(); ait != end(); ++ait ) {
619 if ( !(*ait).tagged() ) { 619 if ( !(*ait).tagged() ) {
620 if ( (*ait).containsAdr(*it)) { 620 if ( (*ait).containsAdr(*it)) {
621 (*ait).setTagged(true); 621 (*ait).setTagged(true);
622 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); 622 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
623 (*it).setIDStr( ":"); 623 (*it).setIDStr( ":");
624 (*it).setID( currentSyncDevice,id ); 624 (*it).setID( currentSyncDevice,id );
625 (*it).setExternalUID( id ); 625 (*it).setExternalUID( id );
626 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 626 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
627 (*it).setUid( ( (*ait).uid() )); 627 (*it).setUid( ( (*ait).uid() ));
628 break; 628 break;
629 } 629 }
630 } 630 }
631 631
632 } 632 }
633 if ( ait == end() ) 633 if ( ait == end() )
634 qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); 634 qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1());
635 } 635 }
636 clear(); 636 clear();
637 for ( it = list.begin(); it != list.end(); ++it ) { 637 for ( it = list.begin(); it != list.end(); ++it ) {
638 insertAddressee( (*it) ); 638 insertAddressee( (*it) );
639 } 639 }
640} 640}
641 641
642bool AddressBook::saveABphone( QString fileName ) 642bool AddressBook::saveABphone( QString fileName )
643{ 643{
644 //smplifyAddressees(); 644 //smplifyAddressees();
645 qDebug("saveABphone:: saving AB... "); 645 qDebug("saveABphone:: saving AB... ");
646 if ( ! export2PhoneFormat( QStringList() ,fileName ) ) 646 if ( ! export2PhoneFormat( QStringList() ,fileName ) )
647 return false; 647 return false;
648 qDebug("saveABphone:: writing to phone... "); 648 qDebug("saveABphone:: writing to phone... ");
649 if ( !PhoneAccess::writeToPhone( fileName) ) { 649 if ( !PhoneAccess::writeToPhone( fileName) ) {
650 return false; 650 return false;
651 } 651 }
652 qDebug("saveABphone:: re-reading from phone... "); 652 qDebug("saveABphone:: re-reading from phone... ");
653 if ( !PhoneAccess::readFromPhone( fileName) ) { 653 if ( !PhoneAccess::readFromPhone( fileName) ) {
654 return false; 654 return false;
655 } 655 }
656 return true; 656 return true;
657} 657}
658bool AddressBook::saveAB() 658bool AddressBook::saveAB()
659{ 659{
660 bool ok = true; 660 bool ok = true;
661 661
662 deleteRemovedAddressees(); 662 deleteRemovedAddressees();
663 Iterator ait; 663 Iterator ait;
664 for ( ait = begin(); ait != end(); ++ait ) { 664 for ( ait = begin(); ait != end(); ++ait ) {
665 if ( !(*ait).IDStr().isEmpty() ) { 665 if ( !(*ait).IDStr().isEmpty() ) {
666 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); 666 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
667 } 667 }
668 } 668 }
669 KRES::Manager<Resource>::ActiveIterator it; 669 KRES::Manager<Resource>::ActiveIterator it;
670 KRES::Manager<Resource> *manager = d->mManager; 670 KRES::Manager<Resource> *manager = d->mManager;
671 qDebug("SaveAB::saving..." ); 671 qDebug("SaveAB::saving..." );
672 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 672 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
673 qDebug("SaveAB::checking resource..." ); 673 qDebug("SaveAB::checking resource..." );
674 if ( (*it)->readOnly() ) 674 if ( (*it)->readOnly() )
675 qDebug("resource is readonly." ); 675 qDebug("resource is readonly." );
676 if ( (*it)->isOpen() ) 676 if ( (*it)->isOpen() )
677 qDebug("resource is open" ); 677 qDebug("resource is open" );
678 678
679 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 679 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
680 Ticket *ticket = requestSaveTicket( *it ); 680 Ticket *ticket = requestSaveTicket( *it );
681 qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 681 qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
682 if ( !ticket ) { 682 if ( !ticket ) {
683 qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) 683 qDebug( i18n( "Unable to save to resource '%1'. It is locked." )
684 .arg( (*it)->resourceName() ) ); 684 .arg( (*it)->resourceName() ) );
685 return false; 685 return false;
686 } 686 }
687 687
688 //if ( !save( ticket ) ) 688 //if ( !save( ticket ) )
689 if ( ticket->resource() ) { 689 if ( ticket->resource() ) {
690 QString name = ticket->resource()->resourceName(); 690 QString name = ticket->resource()->resourceName();
691 if ( ! ticket->resource()->save( ticket ) ) 691 if ( ! ticket->resource()->save( ticket ) )
692 ok = false; 692 ok = false;
693 else 693 else
694 qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); 694 qDebug("StdAddressBook::resource saved '%s'", name.latin1() );
695 695
696 } else 696 } else
697 ok = false; 697 ok = false;
698 698
699 } 699 }
700 } 700 }
701 return ok; 701 return ok;
702} 702}
703 703
704AddressBook::Iterator AddressBook::begin() 704AddressBook::Iterator AddressBook::begin()
705{ 705{
706 Iterator it = Iterator(); 706 Iterator it = Iterator();
707 it.d->mIt = d->mAddressees.begin(); 707 it.d->mIt = d->mAddressees.begin();
708 return it; 708 return it;
709} 709}
710 710
711AddressBook::ConstIterator AddressBook::begin() const 711AddressBook::ConstIterator AddressBook::begin() const
712{ 712{
713 ConstIterator it = ConstIterator(); 713 ConstIterator it = ConstIterator();
714 it.d->mIt = d->mAddressees.begin(); 714 it.d->mIt = d->mAddressees.begin();
715 return it; 715 return it;
716} 716}
717 717
718AddressBook::Iterator AddressBook::end() 718AddressBook::Iterator AddressBook::end()
719{ 719{
720 Iterator it = Iterator(); 720 Iterator it = Iterator();
721 it.d->mIt = d->mAddressees.end(); 721 it.d->mIt = d->mAddressees.end();
722 return it; 722 return it;
723} 723}
724 724
725AddressBook::ConstIterator AddressBook::end() const 725AddressBook::ConstIterator AddressBook::end() const
726{ 726{
727 ConstIterator it = ConstIterator(); 727 ConstIterator it = ConstIterator();
728 it.d->mIt = d->mAddressees.end(); 728 it.d->mIt = d->mAddressees.end();
729 return it; 729 return it;
730} 730}
731 731
732void AddressBook::clear() 732void AddressBook::clear()
733{ 733{
734 d->mAddressees.clear(); 734 d->mAddressees.clear();
735} 735}
736 736
737Ticket *AddressBook::requestSaveTicket( Resource *resource ) 737Ticket *AddressBook::requestSaveTicket( Resource *resource )
738{ 738{
739 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 739 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
740 740
741 if ( !resource ) 741 if ( !resource )
742 { 742 {
743 qDebug("AddressBook::requestSaveTicket no resource" ); 743 qDebug("AddressBook::requestSaveTicket no resource" );
744 resource = standardResource(); 744 resource = standardResource();
745 } 745 }
746 746
747 KRES::Manager<Resource>::ActiveIterator it; 747 KRES::Manager<Resource>::ActiveIterator it;
748 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 748 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
749 if ( (*it) == resource ) { 749 if ( (*it) == resource ) {
750 if ( (*it)->readOnly() || !(*it)->isOpen() ) 750 if ( (*it)->readOnly() || !(*it)->isOpen() )
751 return 0; 751 return 0;
752 else 752 else
753 return (*it)->requestSaveTicket(); 753 return (*it)->requestSaveTicket();
754 } 754 }
755 } 755 }
756 756
757 return 0; 757 return 0;
758} 758}
759//void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); 759//void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
760void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) 760void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource )
761{ 761{
762 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { 762 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
763 //qDebug("block insert "); 763 //qDebug("block insert ");
764 return; 764 return;
765 } 765 }
766 //qDebug("inserting.... %s ",a.uid().latin1() ); 766 //qDebug("inserting.... %s ",a.uid().latin1() );
767 bool found = false; 767 bool found = false;
768 Addressee::List::Iterator it; 768 Addressee::List::Iterator it;
769 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 769 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
770 if ( a.uid() == (*it).uid() ) { 770 if ( a.uid() == (*it).uid() ) {
771 771
772 bool changed = false; 772 bool changed = false;
773 Addressee addr = a; 773 Addressee addr = a;
774 if ( addr != (*it) ) 774 if ( addr != (*it) )
775 changed = true; 775 changed = true;
776 776
777 if ( takeResource ) { 777 if ( takeResource ) {
778 Resource * res = (*it).resource(); 778 Resource * res = (*it).resource();
779 (*it) = a; 779 (*it) = a;
780 (*it).setResource( res ); 780 (*it).setResource( res );
781 } else { 781 } else {
782 (*it) = a; 782 (*it) = a;
783 if ( (*it).resource() == 0 ) 783 if ( (*it).resource() == 0 )
784 (*it).setResource( standardResource() ); 784 (*it).setResource( standardResource() );
785 } 785 }
786 if ( changed ) { 786 if ( changed ) {
787 if ( setRev ) { 787 if ( setRev ) {
788 (*it).setRevision( QDateTime::currentDateTime() ); 788 (*it).setRevision( QDateTime::currentDateTime() );
789 } 789 }
790 (*it).setChanged( true ); 790 (*it).setChanged( true );
791 } 791 }
792 792
793 found = true; 793 found = true;
794 } else { 794 } else {
795 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 795 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
796 QString name = (*it).uid().mid( 19 ); 796 QString name = (*it).uid().mid( 19 );
797 Addressee b = a; 797 Addressee b = a;
798 QString id = b.getID( name ); 798 QString id = b.getID( name );
799 if ( ! id.isEmpty() ) { 799 if ( ! id.isEmpty() ) {
800 QString des = (*it).note(); 800 QString des = (*it).note();
801 int startN; 801 int startN;
802 if( (startN = des.find( id ) ) >= 0 ) { 802 if( (startN = des.find( id ) ) >= 0 ) {
803 int endN = des.find( ",", startN+1 ); 803 int endN = des.find( ",", startN+1 );
804 des = des.left( startN ) + des.mid( endN+1 ); 804 des = des.left( startN ) + des.mid( endN+1 );
805 (*it).setNote( des ); 805 (*it).setNote( des );
806 } 806 }
807 } 807 }
808 } 808 }
809 } 809 }
810 } 810 }
811 if ( found ) 811 if ( found )
812 return; 812 return;
813 813
814 d->mAddressees.append( a ); 814 d->mAddressees.append( a );
815 Addressee& addr = d->mAddressees.last(); 815 Addressee& addr = d->mAddressees.last();
816 if ( addr.resource() == 0 ) 816 if ( addr.resource() == 0 )
817 addr.setResource( standardResource() ); 817 addr.setResource( standardResource() );
818 addr.setChanged( true ); 818 addr.setChanged( true );
819} 819}
820 820
821void AddressBook::removeAddressee( const Addressee &a ) 821void AddressBook::removeAddressee( const Addressee &a )
822{ 822{
823 Iterator it; 823 Iterator it;
824 Iterator it2; 824 Iterator it2;
825 bool found = false; 825 bool found = false;
826 for ( it = begin(); it != end(); ++it ) { 826 for ( it = begin(); it != end(); ++it ) {
827 if ( a.uid() == (*it).uid() ) { 827 if ( a.uid() == (*it).uid() ) {
828 found = true; 828 found = true;
829 it2 = it; 829 it2 = it;
830 } else { 830 } else {
831 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 831 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
832 QString name = (*it).uid().mid( 19 ); 832 QString name = (*it).uid().mid( 19 );
833 Addressee b = a; 833 Addressee b = a;
834 QString id = b.getID( name ); 834 QString id = b.getID( name );
835 if ( ! id.isEmpty() ) { 835 if ( ! id.isEmpty() ) {
836 QString des = (*it).note(); 836 QString des = (*it).note();
837 if( des.find( id ) < 0 ) { 837 if( des.find( id ) < 0 ) {
838 des += id + ","; 838 des += id + ",";
839 (*it).setNote( des ); 839 (*it).setNote( des );
840 } 840 }
841 } 841 }
842 } 842 }
843 843
844 } 844 }
845 } 845 }
846 846
847 if ( found ) 847 if ( found )
848 removeAddressee( it2 ); 848 removeAddressee( it2 );
849 849
850} 850}
851 851
852void AddressBook::removeSyncAddressees( bool removeDeleted ) 852void AddressBook::removeSyncAddressees( bool removeDeleted )
853{ 853{
854 Iterator it = begin(); 854 Iterator it = begin();
855 Iterator it2 ; 855 Iterator it2 ;
856 QDateTime dt ( QDate( 2003,1,1) ); 856 QDateTime dt ( QDate( 2003,1,1) );
857 while ( it != end() ) { 857 while ( it != end() ) {
858 (*it).setRevision( dt ); 858 (*it).setRevision( dt );
859 if (( *it).IDStr() != "changed" ) { 859 if (( *it).IDStr() != "changed" ) {
860 // "changed" is used for tagging changed addressees when syncing with KDE or OL 860 // "changed" is used for tagging changed addressees when syncing with KDE or OL
861 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); 861 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" );
862 (*it).setIDStr(":"); 862 (*it).setIDStr(":");
863 } 863 }
864 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { 864 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) {
865 it2 = it; 865 it2 = it;
866 //qDebug("removing %s ",(*it).uid().latin1() ); 866 //qDebug("removing %s ",(*it).uid().latin1() );
867 ++it; 867 ++it;
868 removeAddressee( it2 ); 868 removeAddressee( it2 );
869 } else { 869 } else {
870 //qDebug("skipping %s ",(*it).uid().latin1() ); 870 //qDebug("skipping %s ",(*it).uid().latin1() );
871 if ( removeDeleted ) { 871 if ( removeDeleted ) {
872 // we have no postprocessing in the resource, we have to do it here 872 // we have no postprocessing in the resource, we have to do it here
873 // we have to compute csum for all, because it could be the first sync 873 // we have to compute csum for all, because it could be the first sync
874 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 874 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
875 } 875 }
876 ++it; 876 ++it;
877 } 877 }
878 } 878 }
879 deleteRemovedAddressees(); 879 deleteRemovedAddressees();
880} 880}
881 881
882void AddressBook::removeAddressee( const Iterator &it ) 882void AddressBook::removeAddressee( const Iterator &it )
883{ 883{
884 d->mRemovedAddressees.append( (*it) ); 884 d->mRemovedAddressees.append( (*it) );
885 d->mAddressees.remove( it.d->mIt ); 885 d->mAddressees.remove( it.d->mIt );
886} 886}
887 887
888AddressBook::Iterator AddressBook::find( const Addressee &a ) 888AddressBook::Iterator AddressBook::find( const Addressee &a )
889{ 889{
890 Iterator it; 890 Iterator it;
891 for ( it = begin(); it != end(); ++it ) { 891 for ( it = begin(); it != end(); ++it ) {
892 if ( a.uid() == (*it).uid() ) { 892 if ( a.uid() == (*it).uid() ) {
893 return it; 893 return it;
894 } 894 }
895 } 895 }
896 return end(); 896 return end();
897} 897}
898 898
899Addressee AddressBook::findByUid( const QString &uid ) 899Addressee AddressBook::findByUid( const QString &uid )
900{ 900{
901 Iterator it; 901 Iterator it;
902 for ( it = begin(); it != end(); ++it ) { 902 for ( it = begin(); it != end(); ++it ) {
903 if ( uid == (*it).uid() ) { 903 if ( uid == (*it).uid() ) {
904 return *it; 904 return *it;
905 } 905 }
906 } 906 }
907 return Addressee(); 907 return Addressee();
908} 908}
909void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) 909void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset )
910{ 910{
911 //qDebug("AddressBook::preExternSync "); 911 //qDebug("AddressBook::preExternSync ");
912 AddressBook::Iterator it; 912 AddressBook::Iterator it;
913 for ( it = begin(); it != end(); ++it ) { 913 for ( it = begin(); it != end(); ++it ) {
914 (*it).setID( csd, (*it).externalUID() ); 914 (*it).setID( csd, (*it).externalUID() );
915 (*it).computeCsum( csd ); 915 (*it).computeCsum( csd );
916 } 916 }
917 mergeAB( aBook ,csd, isSubset ); 917 mergeAB( aBook ,csd, isSubset );
918} 918}
919void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool setID) 919void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool setID)
920{ 920{
921 //qDebug("AddressBook::postExternSync "); 921 //qDebug("AddressBook::postExternSync ");
922 AddressBook::Iterator it; 922 AddressBook::Iterator it;
923 for ( it = begin(); it != end(); ++it ) { 923 for ( it = begin(); it != end(); ++it ) {
924 //qDebug("check uid %s ", (*it).uid().latin1() ); 924 //qDebug("check uid %s ", (*it).uid().latin1() );
925 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || 925 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ||
926 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM || 926 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ||
927 (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL) { 927 (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL) {
928 Addressee ad = aBook->findByUid( ( (*it).uid() )); 928 Addressee ad = aBook->findByUid( ( (*it).uid() ));
929 if ( ad.isEmpty() ) { 929 if ( ad.isEmpty() ) {
930 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); 930 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1());
931 } else { 931 } else {
932 (*it).setIDStr(":"); 932 (*it).setIDStr(":");
933 if ( setID ) { 933 if ( setID ) {
934 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) 934 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID )
935 ad.setID( csd, (*it).externalUID() ); 935 ad.setID( csd, (*it).externalUID() );
936 } else 936 } else
937 ad.setID( csd, (*it).uid() ); 937 ad.setID( csd, (*it).uid() );
938 (*it).computeCsum( csd ); 938 (*it).computeCsum( csd );
939 ad.setCsum( csd, (*it).getCsum( csd ) ); 939 ad.setCsum( csd, (*it).getCsum( csd ) );
940 //qDebug("CSUM %s ",(*it).getCsum( csd ).latin1() ); 940 //qDebug("CSUM %s ",(*it).getCsum( csd ).latin1() );
941 aBook->insertAddressee( ad , false); 941 aBook->insertAddressee( ad , false);
942 } 942 }
943 } 943 }
944 } 944 }
945} 945}
946 946
947bool AddressBook::containsExternalUid( const QString& uid ) 947bool AddressBook::containsExternalUid( const QString& uid )
948{ 948{
949 Iterator it; 949 Iterator it;
950 for ( it = begin(); it != end(); ++it ) { 950 for ( it = begin(); it != end(); ++it ) {
951 if ( uid == (*it).externalUID( ) ) 951 if ( uid == (*it).externalUID( ) )
952 return true; 952 return true;
953 } 953 }
954 return false; 954 return false;
955} 955}
956Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) 956Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile )
957{ 957{
958 Iterator it; 958 Iterator it;
959 for ( it = begin(); it != end(); ++it ) { 959 for ( it = begin(); it != end(); ++it ) {
960 if ( uid == (*it).getID( profile ) ) 960 if ( uid == (*it).getID( profile ) )
961 return (*it); 961 return (*it);
962 } 962 }
963 return Addressee(); 963 return Addressee();
964} 964}
965void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) 965void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset )
966{ 966{
967 Iterator it; 967 Iterator it;
968 Addressee ad; 968 Addressee ad;
969 for ( it = begin(); it != end(); ++it ) { 969 for ( it = begin(); it != end(); ++it ) {
970 ad = aBook->findByExternUid( (*it).externalUID(), profile ); 970 ad = aBook->findByExternUid( (*it).externalUID(), profile );
971 if ( !ad.isEmpty() ) { 971 if ( !ad.isEmpty() ) {
972 (*it).mergeContact( ad ,isSubset); 972 (*it).mergeContact( ad ,isSubset);
973 } 973 }
974 } 974 }
975#if 0 975#if 0
976 // test only 976 // test only
977 for ( it = begin(); it != end(); ++it ) { 977 for ( it = begin(); it != end(); ++it ) {
978 978
979 qDebug("uid %s ", (*it).uid().latin1()); 979 qDebug("uid %s ", (*it).uid().latin1());
980 } 980 }
981#endif 981#endif
982} 982}
983 983
984#if 0 984#if 0
985Addressee::List AddressBook::getExternLastSyncAddressees() 985Addressee::List AddressBook::getExternLastSyncAddressees()
986{ 986{
987 Addressee::List results; 987 Addressee::List results;
988 988
989 Iterator it; 989 Iterator it;
990 for ( it = begin(); it != end(); ++it ) { 990 for ( it = begin(); it != end(); ++it ) {
991 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { 991 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
992 if ( (*it).familyName().left(4) == "!E: " ) 992 if ( (*it).familyName().left(4) == "!E: " )
993 results.append( *it ); 993 results.append( *it );
994 } 994 }
995 } 995 }
996 996
997 return results; 997 return results;
998} 998}
999#endif 999#endif
1000void AddressBook::resetTempSyncStat() 1000void AddressBook::resetTempSyncStat()
1001{ 1001{
1002 Iterator it; 1002 Iterator it;
1003 for ( it = begin(); it != end(); ++it ) { 1003 for ( it = begin(); it != end(); ++it ) {
1004 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); 1004 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
1005 } 1005 }
1006 1006
1007} 1007}
1008 1008
1009QStringList AddressBook:: uidList() 1009QStringList AddressBook:: uidList()
1010{ 1010{
1011 QStringList results; 1011 QStringList results;
1012 Iterator it; 1012 Iterator it;
1013 for ( it = begin(); it != end(); ++it ) { 1013 for ( it = begin(); it != end(); ++it ) {
1014 results.append( (*it).uid() ); 1014 results.append( (*it).uid() );
1015 } 1015 }
1016 return results; 1016 return results;
1017} 1017}
1018 1018
1019 1019
1020Addressee::List AddressBook::allAddressees() 1020Addressee::List AddressBook::allAddressees()
1021{ 1021{
1022 return d->mAddressees; 1022 return d->mAddressees;
1023 1023
1024} 1024}
1025 1025
1026Addressee::List AddressBook::findByName( const QString &name ) 1026Addressee::List AddressBook::findByName( const QString &name )
1027{ 1027{
1028 Addressee::List results; 1028 Addressee::List results;
1029 1029
1030 Iterator it; 1030 Iterator it;
1031 for ( it = begin(); it != end(); ++it ) { 1031 for ( it = begin(); it != end(); ++it ) {
1032 if ( name == (*it).realName() ) { 1032 if ( name == (*it).realName() ) {
1033 results.append( *it ); 1033 results.append( *it );
1034 } 1034 }
1035 } 1035 }
1036 1036
1037 return results; 1037 return results;
1038} 1038}
1039 1039
1040Addressee::List AddressBook::findByEmail( const QString &email ) 1040Addressee::List AddressBook::findByEmail( const QString &email )
1041{ 1041{
1042 Addressee::List results; 1042 Addressee::List results;
1043 QStringList mailList; 1043 QStringList mailList;
1044 1044
1045 Iterator it; 1045 Iterator it;
1046 for ( it = begin(); it != end(); ++it ) { 1046 for ( it = begin(); it != end(); ++it ) {
1047 mailList = (*it).emails(); 1047 mailList = (*it).emails();
1048 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 1048 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
1049 if ( email == (*ite) ) { 1049 if ( email == (*ite) ) {
1050 results.append( *it ); 1050 results.append( *it );
1051 } 1051 }
1052 } 1052 }
1053 } 1053 }
1054 1054
1055 return results; 1055 return results;
1056} 1056}
1057 1057
1058Addressee::List AddressBook::findByCategory( const QString &category ) 1058Addressee::List AddressBook::findByCategory( const QString &category )
1059{ 1059{
1060 Addressee::List results; 1060 Addressee::List results;
1061 1061
1062 Iterator it; 1062 Iterator it;
1063 for ( it = begin(); it != end(); ++it ) { 1063 for ( it = begin(); it != end(); ++it ) {
1064 if ( (*it).hasCategory( category) ) { 1064 if ( (*it).hasCategory( category) ) {
1065 results.append( *it ); 1065 results.append( *it );
1066 } 1066 }
1067 } 1067 }
1068 1068
1069 return results; 1069 return results;
1070} 1070}
1071 1071
1072void AddressBook::dump() const 1072void AddressBook::dump() const
1073{ 1073{
1074 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; 1074 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
1075 1075
1076 ConstIterator it; 1076 ConstIterator it;
1077 for( it = begin(); it != end(); ++it ) { 1077 for( it = begin(); it != end(); ++it ) {
1078 (*it).dump(); 1078 (*it).dump();
1079 } 1079 }
1080 1080
1081 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; 1081 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
1082} 1082}
1083 1083
1084QString AddressBook::identifier() 1084QString AddressBook::identifier()
1085{ 1085{
1086 QStringList identifier; 1086 QStringList identifier;
1087 1087
1088 1088
1089 KRES::Manager<Resource>::ActiveIterator it; 1089 KRES::Manager<Resource>::ActiveIterator it;
1090 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 1090 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
1091 if ( !(*it)->identifier().isEmpty() ) 1091 if ( !(*it)->identifier().isEmpty() )
1092 identifier.append( (*it)->identifier() ); 1092 identifier.append( (*it)->identifier() );
1093 } 1093 }
1094 1094
1095 return identifier.join( ":" ); 1095 return identifier.join( ":" );
1096} 1096}
1097 1097
1098Field::List AddressBook::fields( int category ) 1098Field::List AddressBook::fields( int category )
1099{ 1099{
1100 if ( d->mAllFields.isEmpty() ) { 1100 if ( d->mAllFields.isEmpty() ) {
1101 d->mAllFields = Field::allFields(); 1101 d->mAllFields = Field::allFields();
1102 } 1102 }
1103 1103
1104 if ( category == Field::All ) return d->mAllFields; 1104 if ( category == Field::All ) return d->mAllFields;
1105 1105
1106 Field::List result; 1106 Field::List result;
1107 Field::List::ConstIterator it; 1107 Field::List::ConstIterator it;
1108 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { 1108 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
1109 if ( (*it)->category() & category ) result.append( *it ); 1109 if ( (*it)->category() & category ) result.append( *it );
1110 } 1110 }
1111 1111
1112 return result; 1112 return result;
1113} 1113}
1114 1114
1115bool AddressBook::addCustomField( const QString &label, int category, 1115bool AddressBook::addCustomField( const QString &label, int category,
1116 const QString &key, const QString &app ) 1116 const QString &key, const QString &app )
1117{ 1117{
1118 if ( d->mAllFields.isEmpty() ) { 1118 if ( d->mAllFields.isEmpty() ) {
1119 d->mAllFields = Field::allFields(); 1119 d->mAllFields = Field::allFields();
1120 } 1120 }
1121//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; 1121//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app;
1122 QString a = app.isNull() ? KGlobal::getAppName() : app; 1122 QString a = app.isNull() ? KGlobal::getAppName() : app;
1123 1123
1124 QString k = key.isNull() ? label : key; 1124 QString k = key.isNull() ? label : key;
1125 1125
1126 Field *field = Field::createCustomField( label, category, k, a ); 1126 Field *field = Field::createCustomField( label, category, k, a );
1127 1127
1128 if ( !field ) return false; 1128 if ( !field ) return false;
1129 1129
1130 d->mAllFields.append( field ); 1130 d->mAllFields.append( field );
1131 1131
1132 return true; 1132 return true;
1133} 1133}
1134 1134
1135QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) 1135QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab )
1136{ 1136{
1137 if (!ab.d) return s; 1137 if (!ab.d) return s;
1138 1138
1139 return s << ab.d->mAddressees; 1139 return s << ab.d->mAddressees;
1140} 1140}
1141 1141
1142QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) 1142QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
1143{ 1143{
1144 if (!ab.d) return s; 1144 if (!ab.d) return s;
1145 1145
1146 s >> ab.d->mAddressees; 1146 s >> ab.d->mAddressees;
1147 1147
1148 return s; 1148 return s;
1149} 1149}
1150 1150
1151bool AddressBook::addResource( Resource *resource ) 1151bool AddressBook::addResource( Resource *resource )
1152{ 1152{
1153 if ( !resource->open() ) { 1153 if ( !resource->open() ) {
1154 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; 1154 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
1155 return false; 1155 return false;
1156 } 1156 }
1157 1157
1158 resource->setAddressBook( this ); 1158 resource->setAddressBook( this );
1159 1159
1160 d->mManager->add( resource ); 1160 d->mManager->add( resource );
1161 return true; 1161 return true;
1162} 1162}
1163void AddressBook::removeResources()
1164{
1165 //remove all possible resources. This should cleanup the configfile.
1166 QPtrList<KABC::Resource> mResources = resources();
1167
1168 QPtrListIterator<KABC::Resource> it(mResources);
1169 for ( ; it.current(); ++it ) {
1170 KABC::Resource *res = it.current();
1171 removeResource(res);
1172 }
1173}
1163 1174
1164bool AddressBook::removeResource( Resource *resource ) 1175bool AddressBook::removeResource( Resource *resource )
1165{ 1176{
1166 resource->close(); 1177 resource->close();
1167 1178
1168 if ( resource == standardResource() ) 1179 if ( resource == standardResource() )
1169 d->mManager->setStandardResource( 0 ); 1180 d->mManager->setStandardResource( 0 );
1170 1181
1171 resource->setAddressBook( 0 ); 1182 resource->setAddressBook( 0 );
1172 1183
1173 d->mManager->remove( resource ); 1184 d->mManager->remove( resource );
1174 return true; 1185 return true;
1175} 1186}
1176 1187
1177QPtrList<Resource> AddressBook::resources() 1188QPtrList<Resource> AddressBook::resources()
1178{ 1189{
1179 QPtrList<Resource> list; 1190 QPtrList<Resource> list;
1180 1191
1181// qDebug("AddressBook::resources() 1"); 1192// qDebug("AddressBook::resources() 1");
1182 1193
1183 KRES::Manager<Resource>::ActiveIterator it; 1194 KRES::Manager<Resource>::ActiveIterator it;
1184 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 1195 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
1185 list.append( *it ); 1196 list.append( *it );
1186 1197
1187 return list; 1198 return list;
1188} 1199}
1189 1200
1190/*US 1201/*US
1191void AddressBook::setErrorHandler( ErrorHandler *handler ) 1202void AddressBook::setErrorHandler( ErrorHandler *handler )
1192{ 1203{
1193 delete d->mErrorHandler; 1204 delete d->mErrorHandler;
1194 d->mErrorHandler = handler; 1205 d->mErrorHandler = handler;
1195} 1206}
1196*/ 1207*/
1197 1208
1198void AddressBook::error( const QString& msg ) 1209void AddressBook::error( const QString& msg )
1199{ 1210{
1200/*US 1211/*US
1201 if ( !d->mErrorHandler ) // create default error handler 1212 if ( !d->mErrorHandler ) // create default error handler
1202 d->mErrorHandler = new ConsoleErrorHandler; 1213 d->mErrorHandler = new ConsoleErrorHandler;
1203 1214
1204 if ( d->mErrorHandler ) 1215 if ( d->mErrorHandler )
1205 d->mErrorHandler->error( msg ); 1216 d->mErrorHandler->error( msg );
1206 else 1217 else
1207 kdError(5700) << "no error handler defined" << endl; 1218 kdError(5700) << "no error handler defined" << endl;
1208*/ 1219*/
1209 kdDebug(5700) << "msg" << endl; 1220 kdDebug(5700) << "msg" << endl;
1210 qDebug(msg); 1221 qDebug(msg);
1211} 1222}
1212 1223
1213void AddressBook::deleteRemovedAddressees() 1224void AddressBook::deleteRemovedAddressees()
1214{ 1225{
1215 Addressee::List::Iterator it; 1226 Addressee::List::Iterator it;
1216 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { 1227 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) {
1217 Resource *resource = (*it).resource(); 1228 Resource *resource = (*it).resource();
1218 if ( resource && !resource->readOnly() && resource->isOpen() ) 1229 if ( resource && !resource->readOnly() && resource->isOpen() )
1219 resource->removeAddressee( *it ); 1230 resource->removeAddressee( *it );
1220 } 1231 }
1221 1232
1222 d->mRemovedAddressees.clear(); 1233 d->mRemovedAddressees.clear();
1223} 1234}
1224 1235
1225void AddressBook::setStandardResource( Resource *resource ) 1236void AddressBook::setStandardResource( Resource *resource )
1226{ 1237{
1227// qDebug("AddressBook::setStandardResource 1"); 1238// qDebug("AddressBook::setStandardResource 1");
1228 d->mManager->setStandardResource( resource ); 1239 d->mManager->setStandardResource( resource );
1229} 1240}
1230 1241
1231Resource *AddressBook::standardResource() 1242Resource *AddressBook::standardResource()
1232{ 1243{
1233 return d->mManager->standardResource(); 1244 return d->mManager->standardResource();
1234} 1245}
1235 1246
1236KRES::Manager<Resource> *AddressBook::resourceManager() 1247KRES::Manager<Resource> *AddressBook::resourceManager()
1237{ 1248{
1238 return d->mManager; 1249 return d->mManager;
1239} 1250}
1240 1251
1241void AddressBook::cleanUp() 1252void AddressBook::cleanUp()
1242{ 1253{
1243 KRES::Manager<Resource>::ActiveIterator it; 1254 KRES::Manager<Resource>::ActiveIterator it;
1244 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 1255 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
1245 if ( !(*it)->readOnly() && (*it)->isOpen() ) 1256 if ( !(*it)->readOnly() && (*it)->isOpen() )
1246 (*it)->cleanUp(); 1257 (*it)->cleanUp();
1247 } 1258 }
1248} 1259}
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 75f8b51..2351add 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -1,349 +1,350 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library 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 GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#ifndef KABC_ADDRESSBOOK_H 28#ifndef KABC_ADDRESSBOOK_H
29#define KABC_ADDRESSBOOK_H 29#define KABC_ADDRESSBOOK_H
30 30
31#include <qobject.h> 31#include <qobject.h>
32 32
33#include <kresources/manager.h> 33#include <kresources/manager.h>
34#include <qptrlist.h> 34#include <qptrlist.h>
35 35
36#include "addressee.h" 36#include "addressee.h"
37#include "field.h" 37#include "field.h"
38 38
39namespace KABC { 39namespace KABC {
40 40
41class ErrorHandler; 41class ErrorHandler;
42class Resource; 42class Resource;
43class Ticket; 43class Ticket;
44 44
45/** 45/**
46 @short Address Book 46 @short Address Book
47 47
48 This class provides access to a collection of address book entries. 48 This class provides access to a collection of address book entries.
49*/ 49*/
50class AddressBook : public QObject 50class AddressBook : public QObject
51{ 51{
52 Q_OBJECT 52 Q_OBJECT
53 53
54 friend QDataStream &operator<<( QDataStream &, const AddressBook & ); 54 friend QDataStream &operator<<( QDataStream &, const AddressBook & );
55 friend QDataStream &operator>>( QDataStream &, AddressBook & ); 55 friend QDataStream &operator>>( QDataStream &, AddressBook & );
56 friend class StdAddressBook; 56 friend class StdAddressBook;
57 57
58 public: 58 public:
59 /** 59 /**
60 @short Address Book Iterator 60 @short Address Book Iterator
61 61
62 This class provides an iterator for address book entries. 62 This class provides an iterator for address book entries.
63 */ 63 */
64 class Iterator 64 class Iterator
65 { 65 {
66 public: 66 public:
67 Iterator(); 67 Iterator();
68 Iterator( const Iterator & ); 68 Iterator( const Iterator & );
69 ~Iterator(); 69 ~Iterator();
70 70
71 Iterator &operator=( const Iterator & ); 71 Iterator &operator=( const Iterator & );
72 const Addressee &operator*() const; 72 const Addressee &operator*() const;
73 Addressee &operator*(); 73 Addressee &operator*();
74 Addressee* operator->(); 74 Addressee* operator->();
75 Iterator &operator++(); 75 Iterator &operator++();
76 Iterator &operator++(int); 76 Iterator &operator++(int);
77 Iterator &operator--(); 77 Iterator &operator--();
78 Iterator &operator--(int); 78 Iterator &operator--(int);
79 bool operator==( const Iterator &it ); 79 bool operator==( const Iterator &it );
80 bool operator!=( const Iterator &it ); 80 bool operator!=( const Iterator &it );
81 81
82 struct IteratorData; 82 struct IteratorData;
83 IteratorData *d; 83 IteratorData *d;
84 }; 84 };
85 85
86 /** 86 /**
87 @short Address Book Const Iterator 87 @short Address Book Const Iterator
88 88
89 This class provides a const iterator for address book entries. 89 This class provides a const iterator for address book entries.
90 */ 90 */
91 class ConstIterator 91 class ConstIterator
92 { 92 {
93 public: 93 public:
94 ConstIterator(); 94 ConstIterator();
95 ConstIterator( const ConstIterator & ); 95 ConstIterator( const ConstIterator & );
96 ~ConstIterator(); 96 ~ConstIterator();
97 97
98 ConstIterator &operator=( const ConstIterator & ); 98 ConstIterator &operator=( const ConstIterator & );
99 const Addressee &operator*() const; 99 const Addressee &operator*() const;
100 const Addressee* operator->() const; 100 const Addressee* operator->() const;
101 ConstIterator &operator++(); 101 ConstIterator &operator++();
102 ConstIterator &operator++(int); 102 ConstIterator &operator++(int);
103 ConstIterator &operator--(); 103 ConstIterator &operator--();
104 ConstIterator &operator--(int); 104 ConstIterator &operator--(int);
105 bool operator==( const ConstIterator &it ); 105 bool operator==( const ConstIterator &it );
106 bool operator!=( const ConstIterator &it ); 106 bool operator!=( const ConstIterator &it );
107 107
108 struct ConstIteratorData; 108 struct ConstIteratorData;
109 ConstIteratorData *d; 109 ConstIteratorData *d;
110 }; 110 };
111 111
112 /** 112 /**
113 Constructs a address book object. 113 Constructs a address book object.
114 114
115 @param format File format class. 115 @param format File format class.
116 */ 116 */
117 AddressBook(); 117 AddressBook();
118 AddressBook( const QString &config ); 118 AddressBook( const QString &config );
119 AddressBook( const QString &config, const QString &family ); 119 AddressBook( const QString &config, const QString &family );
120 virtual ~AddressBook(); 120 virtual ~AddressBook();
121 121
122 /** 122 /**
123 Requests a ticket for saving the addressbook. Calling this function locks 123 Requests a ticket for saving the addressbook. Calling this function locks
124 the addressbook for all other processes. If the address book is already 124 the addressbook for all other processes. If the address book is already
125 locked the function returns 0. You need the returned @ref Ticket object 125 locked the function returns 0. You need the returned @ref Ticket object
126 for calling the @ref save() function. 126 for calling the @ref save() function.
127 127
128 @see save() 128 @see save()
129 */ 129 */
130 Ticket *requestSaveTicket( Resource *resource=0 ); 130 Ticket *requestSaveTicket( Resource *resource=0 );
131 131
132 /** 132 /**
133 Load address book from file. 133 Load address book from file.
134 */ 134 */
135 bool load(); 135 bool load();
136 136
137 /** 137 /**
138 Save address book. The address book is saved to the file, the Ticket 138 Save address book. The address book is saved to the file, the Ticket
139 object has been requested for by @ref requestSaveTicket(). 139 object has been requested for by @ref requestSaveTicket().
140 140
141 @param ticket a ticket object returned by @ref requestSaveTicket() 141 @param ticket a ticket object returned by @ref requestSaveTicket()
142 */ 142 */
143 bool save( Ticket *ticket ); 143 bool save( Ticket *ticket );
144 bool saveAB( ); 144 bool saveAB( );
145 bool saveABphone( QString fileName ); 145 bool saveABphone( QString fileName );
146 void smplifyAddressees(); 146 void smplifyAddressees();
147 void removeSyncInfo( QString syncProfile); 147 void removeSyncInfo( QString syncProfile);
148 void preparePhoneSync( QString currentSyncDevice, bool isPreSync ); 148 void preparePhoneSync( QString currentSyncDevice, bool isPreSync );
149 void export2File( QString fileName ); 149 void export2File( QString fileName );
150 bool export2PhoneFormat( QStringList uids ,QString fileName ); 150 bool export2PhoneFormat( QStringList uids ,QString fileName );
151 int importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); 151 int importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false );
152 void setUntagged( bool setNonSyncTagged = false ); 152 void setUntagged( bool setNonSyncTagged = false );
153 void removeUntagged(); 153 void removeUntagged();
154 void findNewExtIds( QString fileName, QString currentSyncDevice ); 154 void findNewExtIds( QString fileName, QString currentSyncDevice );
155 /** 155 /**
156 Returns a iterator for first entry of address book. 156 Returns a iterator for first entry of address book.
157 */ 157 */
158 Iterator begin(); 158 Iterator begin();
159 159
160 /** 160 /**
161 Returns a const iterator for first entry of address book. 161 Returns a const iterator for first entry of address book.
162 */ 162 */
163 ConstIterator begin() const; 163 ConstIterator begin() const;
164 164
165 /** 165 /**
166 Returns a iterator for first entry of address book. 166 Returns a iterator for first entry of address book.
167 */ 167 */
168 Iterator end(); 168 Iterator end();
169 169
170 /** 170 /**
171 Returns a const iterator for first entry of address book. 171 Returns a const iterator for first entry of address book.
172 */ 172 */
173 ConstIterator end() const; 173 ConstIterator end() const;
174 174
175 /** 175 /**
176 Removes all entries from address book. 176 Removes all entries from address book.
177 */ 177 */
178 void clear(); 178 void clear();
179 179
180 /** 180 /**
181 Insert an Addressee object into address book. If an object with the same 181 Insert an Addressee object into address book. If an object with the same
182 unique id already exists in the address book it it replaced by the new 182 unique id already exists in the address book it it replaced by the new
183 one. If not the new object is appended to the address book. 183 one. If not the new object is appended to the address book.
184 */ 184 */
185 void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); 185 void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
186 186
187 /** 187 /**
188 Removes entry from the address book. 188 Removes entry from the address book.
189 */ 189 */
190 void removeAddressee( const Addressee & ); 190 void removeAddressee( const Addressee & );
191 191
192 /** 192 /**
193 This is like @ref removeAddressee() just above, with the difference that 193 This is like @ref removeAddressee() just above, with the difference that
194 the first element is a iterator, returned by @ref begin(). 194 the first element is a iterator, returned by @ref begin().
195 */ 195 */
196 void removeAddressee( const Iterator & ); 196 void removeAddressee( const Iterator & );
197 197
198 /** 198 /**
199 Find the specified entry in address book. Returns end(), if the entry 199 Find the specified entry in address book. Returns end(), if the entry
200 couldn't be found. 200 couldn't be found.
201 */ 201 */
202 Iterator find( const Addressee & ); 202 Iterator find( const Addressee & );
203 203
204 /** 204 /**
205 Find the entry specified by an unique id. Returns an empty Addressee 205 Find the entry specified by an unique id. Returns an empty Addressee
206 object, if the address book does not contain an entry with this id. 206 object, if the address book does not contain an entry with this id.
207 */ 207 */
208 Addressee findByUid( const QString & ); 208 Addressee findByUid( const QString & );
209 209
210 210
211 /** 211 /**
212 Returns a list of all addressees in the address book. This list can 212 Returns a list of all addressees in the address book. This list can
213 be sorted with @ref KABC::AddresseeList for example. 213 be sorted with @ref KABC::AddresseeList for example.
214 */ 214 */
215 Addressee::List allAddressees(); 215 Addressee::List allAddressees();
216 216
217 /** 217 /**
218 Find all entries with the specified name in the address book. Returns 218 Find all entries with the specified name in the address book. Returns
219 an empty list, if no entries could be found. 219 an empty list, if no entries could be found.
220 */ 220 */
221 Addressee::List findByName( const QString & ); 221 Addressee::List findByName( const QString & );
222 222
223 /** 223 /**
224 Find all entries with the specified email address in the address book. 224 Find all entries with the specified email address in the address book.
225 Returns an empty list, if no entries could be found. 225 Returns an empty list, if no entries could be found.
226 */ 226 */
227 Addressee::List findByEmail( const QString & ); 227 Addressee::List findByEmail( const QString & );
228 228
229 /** 229 /**
230 Find all entries wich have the specified category in the address book. 230 Find all entries wich have the specified category in the address book.
231 Returns an empty list, if no entries could be found. 231 Returns an empty list, if no entries could be found.
232 */ 232 */
233 Addressee::List findByCategory( const QString & ); 233 Addressee::List findByCategory( const QString & );
234 234
235 /** 235 /**
236 Return a string identifying this addressbook. 236 Return a string identifying this addressbook.
237 */ 237 */
238 virtual QString identifier(); 238 virtual QString identifier();
239 239
240 /** 240 /**
241 Used for debug output. 241 Used for debug output.
242 */ 242 */
243 void dump() const; 243 void dump() const;
244 244
245 void emitAddressBookLocked() { emit addressBookLocked( this ); } 245 void emitAddressBookLocked() { emit addressBookLocked( this ); }
246 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } 246 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); }
247 void emitAddressBookChanged() { emit addressBookChanged( this ); } 247 void emitAddressBookChanged() { emit addressBookChanged( this ); }
248 248
249 /** 249 /**
250 Return list of all Fields known to the address book which are associated 250 Return list of all Fields known to the address book which are associated
251 with the given field category. 251 with the given field category.
252 */ 252 */
253 Field::List fields( int category = Field::All ); 253 Field::List fields( int category = Field::All );
254 254
255 /** 255 /**
256 Add custom field to address book. 256 Add custom field to address book.
257 257
258 @param label User visible label of the field. 258 @param label User visible label of the field.
259 @param category Ored list of field categories. 259 @param category Ored list of field categories.
260 @param key Identifier used as key for reading and writing the field. 260 @param key Identifier used as key for reading and writing the field.
261 @param app String used as application key for reading and writing 261 @param app String used as application key for reading and writing
262 the field. 262 the field.
263 */ 263 */
264 bool addCustomField( const QString &label, int category = Field::All, 264 bool addCustomField( const QString &label, int category = Field::All,
265 const QString &key = QString::null, 265 const QString &key = QString::null,
266 const QString &app = QString::null ); 266 const QString &app = QString::null );
267 267
268 268
269 /** 269 /**
270 Add address book resource. 270 Add address book resource.
271 */ 271 */
272 bool addResource( Resource * ); 272 bool addResource( Resource * );
273 273
274 /** 274 /**
275 Remove address book resource. 275 Remove address book resource.
276 */ 276 */
277 void removeResources();
277 bool removeResource( Resource * ); 278 bool removeResource( Resource * );
278 279
279 /** 280 /**
280 Return pointer list of all resources. 281 Return pointer list of all resources.
281 */ 282 */
282 QPtrList<Resource> resources(); 283 QPtrList<Resource> resources();
283 284
284 /** 285 /**
285 Set the @p ErrorHandler, that is used by @ref error() to 286 Set the @p ErrorHandler, that is used by @ref error() to
286 provide gui-independend error messages. 287 provide gui-independend error messages.
287 */ 288 */
288 void setErrorHandler( ErrorHandler * ); 289 void setErrorHandler( ErrorHandler * );
289 290
290 /** 291 /**
291 Shows gui independend error messages. 292 Shows gui independend error messages.
292 */ 293 */
293 void error( const QString& ); 294 void error( const QString& );
294 295
295 /** 296 /**
296 Query all resources to clean up their lock files 297 Query all resources to clean up their lock files
297 */ 298 */
298 void cleanUp(); 299 void cleanUp();
299 300
300 // sync stuff 301 // sync stuff
301 //Addressee::List getExternLastSyncAddressees(); 302 //Addressee::List getExternLastSyncAddressees();
302 void resetTempSyncStat(); 303 void resetTempSyncStat();
303 QStringList uidList(); 304 QStringList uidList();
304 void removeSyncAddressees( bool removeDeleted = false ); 305 void removeSyncAddressees( bool removeDeleted = false );
305 void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset ); 306 void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset );
306 Addressee findByExternUid( const QString& uid , const QString& profile ); 307 Addressee findByExternUid( const QString& uid , const QString& profile );
307 bool containsExternalUid( const QString& uid ); 308 bool containsExternalUid( const QString& uid );
308 309
309 void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset ); 310 void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset );
310 void postExternSync( AddressBook* aBook, const QString& csd , bool setID ); 311 void postExternSync( AddressBook* aBook, const QString& csd , bool setID );
311 signals: 312 signals:
312 /** 313 /**
313 Emitted, when the address book has changed on disk. 314 Emitted, when the address book has changed on disk.
314 */ 315 */
315 void addressBookChanged( AddressBook * ); 316 void addressBookChanged( AddressBook * );
316 317
317 /** 318 /**
318 Emitted, when the address book has been locked for writing. 319 Emitted, when the address book has been locked for writing.
319 */ 320 */
320 void addressBookLocked( AddressBook * ); 321 void addressBookLocked( AddressBook * );
321 322
322 /** 323 /**
323 Emitted, when the address book has been unlocked. 324 Emitted, when the address book has been unlocked.
324 */ 325 */
325 void addressBookUnlocked( AddressBook * ); 326 void addressBookUnlocked( AddressBook * );
326 327
327 protected: 328 protected:
328 void deleteRemovedAddressees(); 329 void deleteRemovedAddressees();
329 void setStandardResource( Resource * ); 330 void setStandardResource( Resource * );
330 Resource *standardResource(); 331 Resource *standardResource();
331 KRES::Manager<Resource> *resourceManager(); 332 KRES::Manager<Resource> *resourceManager();
332 333
333 void init(const QString &config, const QString &family); 334 void init(const QString &config, const QString &family);
334 335
335 private: 336 private:
336//US QPtrList<Resource> mDummy; // Remove in KDE 4 337//US QPtrList<Resource> mDummy; // Remove in KDE 4
337 338
338 339
339 struct AddressBookData; 340 struct AddressBookData;
340 AddressBookData *d; 341 AddressBookData *d;
341 bool blockLSEchange; 342 bool blockLSEchange;
342}; 343};
343 344
344QDataStream &operator<<( QDataStream &, const AddressBook & ); 345QDataStream &operator<<( QDataStream &, const AddressBook & );
345QDataStream &operator>>( QDataStream &, AddressBook & ); 346QDataStream &operator>>( QDataStream &, AddressBook & );
346 347
347} 348}
348 349
349#endif 350#endif
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 3d4992c..028d3bb 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -1,2132 +1,2132 @@
1/*** Warning! This file has been generated by the script makeaddressee ***/ 1/*** Warning! This file has been generated by the script makeaddressee ***/
2/* 2/*
3 This file is part of libkabc. 3 This file is part of libkabc.
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22/* 22/*
23Enhanced Version of the file for platform independent KDE tools. 23Enhanced Version of the file for platform independent KDE tools.
24Copyright (c) 2004 Ulf Schenk 24Copyright (c) 2004 Ulf Schenk
25 25
26$Id$ 26$Id$
27*/ 27*/
28 28
29#include <kconfig.h> 29#include <kconfig.h>
30 30
31#include <ksharedptr.h> 31#include <ksharedptr.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <kapplication.h> 33#include <kapplication.h>
34#include <klocale.h> 34#include <klocale.h>
35#include <kidmanager.h> 35#include <kidmanager.h>
36//US 36//US
37#include <kstandarddirs.h> 37#include <kstandarddirs.h>
38#include <libkcal/syncdefines.h> 38#include <libkcal/syncdefines.h>
39 39
40//US #include "resource.h" 40//US #include "resource.h"
41#include "addressee.h" 41#include "addressee.h"
42 42
43using namespace KABC; 43using namespace KABC;
44 44
45static bool matchBinaryPattern( int value, int pattern ); 45static bool matchBinaryPattern( int value, int pattern );
46static bool matchBinaryPatternA( int value, int pattern ); 46static bool matchBinaryPatternA( int value, int pattern );
47static bool matchBinaryPatternP( int value, int pattern ); 47static bool matchBinaryPatternP( int value, int pattern );
48 48
49struct Addressee::AddresseeData : public KShared 49struct Addressee::AddresseeData : public KShared
50{ 50{
51 QString uid; 51 QString uid;
52 QString name; 52 QString name;
53 QString formattedName; 53 QString formattedName;
54 QString familyName; 54 QString familyName;
55 QString givenName; 55 QString givenName;
56 QString additionalName; 56 QString additionalName;
57 QString prefix; 57 QString prefix;
58 QString suffix; 58 QString suffix;
59 QString nickName; 59 QString nickName;
60 QDateTime birthday; 60 QDateTime birthday;
61 QString mailer; 61 QString mailer;
62 TimeZone timeZone; 62 TimeZone timeZone;
63 Geo geo; 63 Geo geo;
64 QString title; 64 QString title;
65 QString role; 65 QString role;
66 QString organization; 66 QString organization;
67 QString note; 67 QString note;
68 QString productId; 68 QString productId;
69 QDateTime revision; 69 QDateTime revision;
70 QString sortString; 70 QString sortString;
71 QString externalUID; 71 QString externalUID;
72 QString originalExternalUID; 72 QString originalExternalUID;
73 KURL url; 73 KURL url;
74 Secrecy secrecy; 74 Secrecy secrecy;
75 Picture logo; 75 Picture logo;
76 Picture photo; 76 Picture photo;
77 Sound sound; 77 Sound sound;
78 Agent agent; 78 Agent agent;
79 QString mExternalId; 79 QString mExternalId;
80 PhoneNumber::List phoneNumbers; 80 PhoneNumber::List phoneNumbers;
81 Address::List addresses; 81 Address::List addresses;
82 Key::List keys; 82 Key::List keys;
83 QStringList emails; 83 QStringList emails;
84 QStringList categories; 84 QStringList categories;
85 QStringList custom; 85 QStringList custom;
86 int mTempSyncStat; 86 int mTempSyncStat;
87 Resource *resource; 87 Resource *resource;
88 88
89 bool empty :1; 89 bool empty :1;
90 bool changed :1; 90 bool changed :1;
91 bool tagged :1; 91 bool tagged :1;
92}; 92};
93 93
94Addressee::Addressee() 94Addressee::Addressee()
95{ 95{
96 mData = new AddresseeData; 96 mData = new AddresseeData;
97 mData->empty = true; 97 mData->empty = true;
98 mData->changed = false; 98 mData->changed = false;
99 mData->resource = 0; 99 mData->resource = 0;
100 mData->mExternalId = ":"; 100 mData->mExternalId = ":";
101 mData->revision = QDateTime ( QDate( 2003,1,1)); 101 mData->revision = QDateTime ( QDate( 2003,1,1));
102 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 102 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
103} 103}
104 104
105Addressee::~Addressee() 105Addressee::~Addressee()
106{ 106{
107} 107}
108 108
109Addressee::Addressee( const Addressee &a ) 109Addressee::Addressee( const Addressee &a )
110{ 110{
111 mData = a.mData; 111 mData = a.mData;
112} 112}
113 113
114Addressee &Addressee::operator=( const Addressee &a ) 114Addressee &Addressee::operator=( const Addressee &a )
115{ 115{
116 mData = a.mData; 116 mData = a.mData;
117 return (*this); 117 return (*this);
118} 118}
119 119
120Addressee Addressee::copy() 120Addressee Addressee::copy()
121{ 121{
122 Addressee a; 122 Addressee a;
123 *(a.mData) = *mData; 123 *(a.mData) = *mData;
124 return a; 124 return a;
125} 125}
126 126
127void Addressee::detach() 127void Addressee::detach()
128{ 128{
129 if ( mData.count() == 1 ) return; 129 if ( mData.count() == 1 ) return;
130 *this = copy(); 130 *this = copy();
131} 131}
132 132
133bool Addressee::operator==( const Addressee &a ) const 133bool Addressee::operator==( const Addressee &a ) const
134{ 134{
135 if ( uid() != a.uid() ) return false; 135 if ( uid() != a.uid() ) return false;
136 if ( mData->name != a.mData->name ) return false; 136 if ( mData->name != a.mData->name ) return false;
137 if ( mData->formattedName != a.mData->formattedName ) return false; 137 if ( mData->formattedName != a.mData->formattedName ) return false;
138 if ( mData->familyName != a.mData->familyName ) return false; 138 if ( mData->familyName != a.mData->familyName ) return false;
139 if ( mData->givenName != a.mData->givenName ) return false; 139 if ( mData->givenName != a.mData->givenName ) return false;
140 if ( mData->additionalName != a.mData->additionalName ) return false; 140 if ( mData->additionalName != a.mData->additionalName ) return false;
141 if ( mData->prefix != a.mData->prefix ) return false; 141 if ( mData->prefix != a.mData->prefix ) return false;
142 if ( mData->suffix != a.mData->suffix ) return false; 142 if ( mData->suffix != a.mData->suffix ) return false;
143 if ( mData->nickName != a.mData->nickName ) return false; 143 if ( mData->nickName != a.mData->nickName ) return false;
144 if ( mData->birthday != a.mData->birthday ) return false; 144 if ( mData->birthday != a.mData->birthday ) return false;
145 if ( mData->mailer != a.mData->mailer ) return false; 145 if ( mData->mailer != a.mData->mailer ) return false;
146 if ( mData->timeZone != a.mData->timeZone ) return false; 146 if ( mData->timeZone != a.mData->timeZone ) return false;
147 if ( mData->geo != a.mData->geo ) return false; 147 if ( mData->geo != a.mData->geo ) return false;
148 if ( mData->title != a.mData->title ) return false; 148 if ( mData->title != a.mData->title ) return false;
149 if ( mData->role != a.mData->role ) return false; 149 if ( mData->role != a.mData->role ) return false;
150 if ( mData->organization != a.mData->organization ) return false; 150 if ( mData->organization != a.mData->organization ) return false;
151 if ( mData->note != a.mData->note ) return false; 151 if ( mData->note != a.mData->note ) return false;
152 if ( mData->productId != a.mData->productId ) return false; 152 if ( mData->productId != a.mData->productId ) return false;
153 //if ( mData->revision != a.mData->revision ) return false; 153 //if ( mData->revision != a.mData->revision ) return false;
154 if ( mData->sortString != a.mData->sortString ) return false; 154 if ( mData->sortString != a.mData->sortString ) return false;
155 if ( mData->secrecy != a.mData->secrecy ) return false; 155 if ( mData->secrecy != a.mData->secrecy ) return false;
156 if ( mData->logo != a.mData->logo ) return false; 156 if ( mData->logo != a.mData->logo ) return false;
157 if ( mData->photo != a.mData->photo ) return false; 157 if ( mData->photo != a.mData->photo ) return false;
158 if ( mData->sound != a.mData->sound ) return false; 158 if ( mData->sound != a.mData->sound ) return false;
159 if ( mData->agent != a.mData->agent ) return false; 159 if ( mData->agent != a.mData->agent ) return false;
160 if ( ( mData->url.isValid() || a.mData->url.isValid() ) && 160 if ( ( mData->url.isValid() || a.mData->url.isValid() ) &&
161 ( mData->url != a.mData->url ) ) return false; 161 ( mData->url != a.mData->url ) ) return false;
162 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; 162 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false;
163 if ( mData->addresses != a.mData->addresses ) return false; 163 if ( mData->addresses != a.mData->addresses ) return false;
164 if ( mData->keys != a.mData->keys ) return false; 164 if ( mData->keys != a.mData->keys ) return false;
165 if ( mData->emails != a.mData->emails ) return false; 165 if ( mData->emails != a.mData->emails ) return false;
166 if ( mData->categories != a.mData->categories ) return false; 166 if ( mData->categories != a.mData->categories ) return false;
167 if ( mData->custom != a.mData->custom ) return false; 167 if ( mData->custom != a.mData->custom ) return false;
168 168
169 return true; 169 return true;
170} 170}
171 171
172bool Addressee::operator!=( const Addressee &a ) const 172bool Addressee::operator!=( const Addressee &a ) const
173{ 173{
174 return !( a == *this ); 174 return !( a == *this );
175} 175}
176 176
177bool Addressee::isEmpty() const 177bool Addressee::isEmpty() const
178{ 178{
179 return mData->empty; 179 return mData->empty;
180} 180}
181ulong Addressee::getCsum4List( const QStringList & attList) 181ulong Addressee::getCsum4List( const QStringList & attList)
182{ 182{
183 int max = attList.count(); 183 int max = attList.count();
184 ulong cSum = 0; 184 ulong cSum = 0;
185 int j,k,i; 185 int j,k,i;
186 int add; 186 int add;
187 for ( i = 0; i < max ; ++i ) { 187 for ( i = 0; i < max ; ++i ) {
188 QString s = attList[i]; 188 QString s = attList[i];
189 if ( ! s.isEmpty() ){ 189 if ( ! s.isEmpty() ){
190 j = s.length(); 190 j = s.length();
191 for ( k = 0; k < j; ++k ) { 191 for ( k = 0; k < j; ++k ) {
192 int mul = k +1; 192 int mul = k +1;
193 add = s[k].unicode (); 193 add = s[k].unicode ();
194 if ( k < 16 ) 194 if ( k < 16 )
195 mul = mul * mul; 195 mul = mul * mul;
196 int ii = i+1; 196 int ii = i+1;
197 add = add * mul *ii*ii*ii; 197 add = add * mul *ii*ii*ii;
198 cSum += add; 198 cSum += add;
199 } 199 }
200 } 200 }
201 201
202 } 202 }
203 //QString dump = attList.join(","); 203 //QString dump = attList.join(",");
204 //qDebug("csum: %d %s", cSum,dump.latin1()); 204 //qDebug("csum: %d %s", cSum,dump.latin1());
205 205
206 return cSum; 206 return cSum;
207 207
208} 208}
209void Addressee::computeCsum(const QString &dev) 209void Addressee::computeCsum(const QString &dev)
210{ 210{
211 QStringList l; 211 QStringList l;
212 //if ( !mData->name.isEmpty() ) l.append(mData->name); 212 //if ( !mData->name.isEmpty() ) l.append(mData->name);
213 //if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); 213 //if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName );
214 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); 214 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName );
215 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); 215 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName );
216 if ( !mData->additionalName.isEmpty() ) l.append( mData->additionalName ); 216 if ( !mData->additionalName.isEmpty() ) l.append( mData->additionalName );
217 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); 217 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix );
218 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); 218 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix );
219 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); 219 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName );
220 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); 220 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() );
221 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); 221 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer );
222 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); 222 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() );
223 if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); 223 if ( mData->geo.isValid() ) l.append( mData->geo.asString() );
224 if ( !mData->title .isEmpty() ) l.append( mData->title ); 224 if ( !mData->title .isEmpty() ) l.append( mData->title );
225 if ( !mData->role.isEmpty() ) l.append( mData->role ); 225 if ( !mData->role.isEmpty() ) l.append( mData->role );
226 if ( !mData->organization.isEmpty() ) l.append( mData->organization ); 226 if ( !mData->organization.isEmpty() ) l.append( mData->organization );
227 if ( !mData->note.isEmpty() ) l.append( mData->note ); 227 if ( !mData->note.isEmpty() ) l.append( mData->note );
228 if ( !mData->productId.isEmpty() ) l.append(mData->productId ); 228 if ( !mData->productId.isEmpty() ) l.append(mData->productId );
229 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); 229 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString );
230 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); 230 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString());
231 // if ( !mData->logo.isEmpty() ) l.append( ); 231 // if ( !mData->logo.isEmpty() ) l.append( );
232 //if ( !mData->photo.isEmpty() ) l.append( ); 232 //if ( !mData->photo.isEmpty() ) l.append( );
233 //if ( !mData->sound.isEmpty() ) l.append( ); 233 //if ( !mData->sound.isEmpty() ) l.append( );
234 //if ( !mData->agent.isEmpty() ) l.append( ); 234 //if ( !mData->agent.isEmpty() ) l.append( );
235 if ( mData->url.isValid() ) 235 if ( mData->url.isValid() )
236 if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() ); 236 if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() );
237 KABC::PhoneNumber::List phoneNumbers; 237 KABC::PhoneNumber::List phoneNumbers;
238 KABC::PhoneNumber::List::Iterator phoneIter; 238 KABC::PhoneNumber::List::Iterator phoneIter;
239 239
240 QStringList t; 240 QStringList t;
241 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 241 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
242 ++phoneIter ) 242 ++phoneIter )
243 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); 243 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) );
244 t.sort(); 244 t.sort();
245 uint iii; 245 uint iii;
246 for ( iii = 0; iii < t.count(); ++iii) 246 for ( iii = 0; iii < t.count(); ++iii)
247 l.append( t[iii] ); 247 l.append( t[iii] );
248 t = mData->emails; 248 t = mData->emails;
249 t.sort(); 249 t.sort();
250 for ( iii = 0; iii < t.count(); ++iii) 250 for ( iii = 0; iii < t.count(); ++iii)
251 l.append( t[iii] ); 251 l.append( t[iii] );
252 t = mData->categories; 252 t = mData->categories;
253 t.sort(); 253 t.sort();
254 for ( iii = 0; iii < t.count(); ++iii) 254 for ( iii = 0; iii < t.count(); ++iii)
255 l.append( t[iii] ); 255 l.append( t[iii] );
256 t = mData->custom; 256 t = mData->custom;
257 t.sort(); 257 t.sort();
258 for ( iii = 0; iii < t.count(); ++iii) 258 for ( iii = 0; iii < t.count(); ++iii)
259 if ( t[iii].left( 25 ) != "KADDRESSBOOK-X-ExternalID" ) { 259 if ( t[iii].left( 25 ) != "KADDRESSBOOK-X-ExternalID" ) {
260 int find = t[iii].find (':')+1; 260 int find = t[iii].find (':')+1;
261 //qDebug("lennnn %d %d ", find, t[iii].length()); 261 //qDebug("lennnn %d %d ", find, t[iii].length());
262 if ( find < t[iii].length()) 262 if ( find < t[iii].length())
263 l.append( t[iii] ); 263 l.append( t[iii] );
264 264
265 } 265 }
266 KABC::Address::List::Iterator addressIter; 266 KABC::Address::List::Iterator addressIter;
267 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 267 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
268 ++addressIter ) { 268 ++addressIter ) {
269 t = (*addressIter).asList(); 269 t = (*addressIter).asList();
270 t.sort(); 270 t.sort();
271 for ( iii = 0; iii < t.count(); ++iii) 271 for ( iii = 0; iii < t.count(); ++iii)
272 l.append( t[iii] ); 272 l.append( t[iii] );
273 } 273 }
274 uint cs = getCsum4List(l); 274 uint cs = getCsum4List(l);
275#if 1 275#if 0
276 for ( iii = 0; iii < l.count(); ++iii) 276 for ( iii = 0; iii < l.count(); ++iii)
277 qDebug("%d***%s***",iii,l[iii].latin1()); 277 qDebug("%d***%s***",iii,l[iii].latin1());
278 qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); 278 qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() );
279#endif 279#endif
280 setCsum( dev, QString::number (cs )); 280 setCsum( dev, QString::number (cs ));
281} 281}
282 282
283void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) 283void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false)
284{ 284{
285 285
286 detach(); 286 detach();
287 if ( mData->name.isEmpty() ) mData->name = ad.mData->name; 287 if ( mData->name.isEmpty() ) mData->name = ad.mData->name;
288 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; 288 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName;
289 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; 289 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName;
290 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; 290 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ;
291 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; 291 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName;
292 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; 292 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix;
293 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; 293 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix;
294 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; 294 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName;
295 if ( !mData->birthday.isValid() ) 295 if ( !mData->birthday.isValid() )
296 if ( ad.mData->birthday.isValid()) 296 if ( ad.mData->birthday.isValid())
297 mData->birthday = ad.mData->birthday; 297 mData->birthday = ad.mData->birthday;
298 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; 298 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer;
299 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; 299 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone;
300 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; 300 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo;
301 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; 301 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ;
302 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; 302 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ;
303 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; 303 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ;
304 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; 304 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ;
305 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; 305 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId;
306 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; 306 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString;
307 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; 307 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy;
308 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; 308 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ;
309 QStringList t; 309 QStringList t;
310 QStringList tAD; 310 QStringList tAD;
311 uint iii; 311 uint iii;
312 312
313 // ********** phone numbers 313 // ********** phone numbers
314 PhoneNumber::List phoneAD = ad.phoneNumbers(); 314 PhoneNumber::List phoneAD = ad.phoneNumbers();
315 PhoneNumber::List::Iterator phoneItAD; 315 PhoneNumber::List::Iterator phoneItAD;
316 for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { 316 for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) {
317 bool found = false; 317 bool found = false;
318 PhoneNumber::List::Iterator it; 318 PhoneNumber::List::Iterator it;
319 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 319 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
320 if ( ( *phoneItAD ).contains( (*it) ) ) { 320 if ( ( *phoneItAD ).contains( (*it) ) ) {
321 found = true; 321 found = true;
322 (*it).setType( ( *phoneItAD ).type() ); 322 (*it).setType( ( *phoneItAD ).type() );
323 (*it).setNumber( ( *phoneItAD ).number() ); 323 (*it).setNumber( ( *phoneItAD ).number() );
324 break; 324 break;
325 } 325 }
326 } 326 }
327 if ( isSubSet && ! found ) 327 if ( isSubSet && ! found )
328 mData->phoneNumbers.append( *phoneItAD ); 328 mData->phoneNumbers.append( *phoneItAD );
329 } 329 }
330 if ( isSubSet ) { 330 if ( isSubSet ) {
331 // ************* emails; 331 // ************* emails;
332 t = mData->emails; 332 t = mData->emails;
333 tAD = ad.mData->emails; 333 tAD = ad.mData->emails;
334 for ( iii = 0; iii < tAD.count(); ++iii) 334 for ( iii = 0; iii < tAD.count(); ++iii)
335 if ( !t.contains(tAD[iii] ) ) 335 if ( !t.contains(tAD[iii] ) )
336 mData->emails.append( tAD[iii] ); 336 mData->emails.append( tAD[iii] );
337 } 337 }
338 338
339 // ************* categories; 339 // ************* categories;
340 t = mData->categories; 340 t = mData->categories;
341 tAD = ad.mData->categories; 341 tAD = ad.mData->categories;
342 for ( iii = 0; iii < tAD.count(); ++iii) 342 for ( iii = 0; iii < tAD.count(); ++iii)
343 if ( !t.contains(tAD[iii] ) ) 343 if ( !t.contains(tAD[iii] ) )
344 mData->categories.append( tAD[iii] ); 344 mData->categories.append( tAD[iii] );
345 QStringList::ConstIterator it; 345 QStringList::ConstIterator it;
346 for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { 346 for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) {
347 QString qualifiedName = (*it).left( (*it).find( ":" )); 347 QString qualifiedName = (*it).left( (*it).find( ":" ));
348 bool found = false; 348 bool found = false;
349 QStringList::ConstIterator itL; 349 QStringList::ConstIterator itL;
350 for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { 350 for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) {
351 if ( (*itL).startsWith( qualifiedName ) ) { 351 if ( (*itL).startsWith( qualifiedName ) ) {
352 found = true; 352 found = true;
353 break; 353 break;
354 } 354 }
355 } 355 }
356 if ( ! found ) { 356 if ( ! found ) {
357 mData->custom.append( *it ); 357 mData->custom.append( *it );
358 } 358 }
359 } 359 }
360 if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo; 360 if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo;
361 if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo; 361 if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo;
362 if ( !mData->sound.isIntern() ) { 362 if ( !mData->sound.isIntern() ) {
363 if ( mData->sound.url().isEmpty() ) { 363 if ( mData->sound.url().isEmpty() ) {
364 mData->sound = ad.mData->sound; 364 mData->sound = ad.mData->sound;
365 } 365 }
366 } 366 }
367 if ( !mData->agent.isIntern() ) { 367 if ( !mData->agent.isIntern() ) {
368 if ( mData->agent.url().isEmpty() ) { 368 if ( mData->agent.url().isEmpty() ) {
369 mData->agent = ad.mData->agent; 369 mData->agent = ad.mData->agent;
370 } 370 }
371 } 371 }
372 { 372 {
373 Key::List::Iterator itA; 373 Key::List::Iterator itA;
374 for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { 374 for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) {
375 bool found = false; 375 bool found = false;
376 Key::List::Iterator it; 376 Key::List::Iterator it;
377 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 377 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
378 if ( (*it) == (*itA)) { 378 if ( (*it) == (*itA)) {
379 found = true; 379 found = true;
380 break; 380 break;
381 381
382 } 382 }
383 } 383 }
384 if ( ! found ) { 384 if ( ! found ) {
385 mData->keys.append( *itA ); 385 mData->keys.append( *itA );
386 } 386 }
387 } 387 }
388 } 388 }
389 KABC::Address::List::Iterator addressIterA; 389 KABC::Address::List::Iterator addressIterA;
390 for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { 390 for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) {
391 bool found = false; 391 bool found = false;
392 KABC::Address::List::Iterator addressIter; 392 KABC::Address::List::Iterator addressIter;
393 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 393 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
394 ++addressIter ) { 394 ++addressIter ) {
395 if ( (*addressIter) == (*addressIterA)) { 395 if ( (*addressIter) == (*addressIterA)) {
396 found = true; 396 found = true;
397 (*addressIter).setType( (*addressIterA).type() ); 397 (*addressIter).setType( (*addressIterA).type() );
398 break; 398 break;
399 } 399 }
400 400
401 } 401 }
402 if ( isSubSet && ! found ) { 402 if ( isSubSet && ! found ) {
403 mData->addresses.append( *addressIterA ); 403 mData->addresses.append( *addressIterA );
404 } 404 }
405 } 405 }
406 //qDebug("merge contact %s ", ad.uid().latin1()); 406 //qDebug("merge contact %s ", ad.uid().latin1());
407 setUid( ad.uid() ); 407 setUid( ad.uid() );
408 setRevision( ad.revision() ); 408 setRevision( ad.revision() );
409} 409}
410 410
411bool Addressee::removeVoice() 411bool Addressee::removeVoice()
412{ 412{
413 PhoneNumber::List phoneN = phoneNumbers(); 413 PhoneNumber::List phoneN = phoneNumbers();
414 PhoneNumber::List::Iterator phoneIt; 414 PhoneNumber::List::Iterator phoneIt;
415 bool found = false; 415 bool found = false;
416 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { 416 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
417 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found 417 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found
418 if ((*phoneIt).type() - PhoneNumber::Voice ) { 418 if ((*phoneIt).type() - PhoneNumber::Voice ) {
419 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); 419 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice );
420 insertPhoneNumber( (*phoneIt) ); 420 insertPhoneNumber( (*phoneIt) );
421 found = true; 421 found = true;
422 } 422 }
423 } 423 }
424 424
425 } 425 }
426 return found; 426 return found;
427} 427}
428 428
429bool Addressee::containsAdr(const Addressee& ad ) 429bool Addressee::containsAdr(const Addressee& ad )
430{ 430{
431 if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; 431 if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false;
432 if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; 432 if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false;
433 if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; 433 if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ;
434 if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; 434 if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ;
435 if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ; 435 if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ;
436 if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ; 436 if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ;
437 if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; 437 if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ;
438 438
439 // compare phone numbers 439 // compare phone numbers
440 PhoneNumber::List phoneN = ad.phoneNumbers(); 440 PhoneNumber::List phoneN = ad.phoneNumbers();
441 PhoneNumber::List::Iterator phoneIt; 441 PhoneNumber::List::Iterator phoneIt;
442 bool found = false; 442 bool found = false;
443 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { 443 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
444 bool found = false; 444 bool found = false;
445 PhoneNumber::List phoneL = ad.phoneNumbers(); 445 PhoneNumber::List phoneL = ad.phoneNumbers();
446 PhoneNumber::List::Iterator phoneItL; 446 PhoneNumber::List::Iterator phoneItL;
447 for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { 447 for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) {
448 if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { 448 if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) {
449 found = true; 449 found = true;
450 break; 450 break;
451 } 451 }
452 } 452 }
453 if ( ! found ) 453 if ( ! found )
454 return false; 454 return false;
455 } 455 }
456 return true; 456 return true;
457 457
458} 458}
459void Addressee::simplifyAddresses() 459void Addressee::simplifyAddresses()
460{ 460{
461 461
462 462
463 Address::List list; 463 Address::List list;
464 Address::List::Iterator it; 464 Address::List::Iterator it;
465 Address::List::Iterator it2; 465 Address::List::Iterator it2;
466 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 466 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
467 it2 = it; 467 it2 = it;
468 ++it2; 468 ++it2;
469 for( ; it2 != mData->addresses.end(); ++it2 ) { 469 for( ; it2 != mData->addresses.end(); ++it2 ) {
470 if ( (*it) == (*it2) ) { 470 if ( (*it) == (*it2) ) {
471 list.append( *it ); 471 list.append( *it );
472 break; 472 break;
473 } 473 }
474 } 474 }
475 } 475 }
476 for( it = list.begin(); it != list.end(); ++it ) { 476 for( it = list.begin(); it != list.end(); ++it ) {
477 removeAddress( (*it) ); 477 removeAddress( (*it) );
478 } 478 }
479 479
480 list.clear(); 480 list.clear();
481 int max = 2; 481 int max = 2;
482 if ( mData->url.isValid() ) 482 if ( mData->url.isValid() )
483 max = 1; 483 max = 1;
484 if ( mData->addresses.count() <= max ) return ; 484 if ( mData->addresses.count() <= max ) return ;
485 int count = 0; 485 int count = 0;
486 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 486 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
487 if ( count >= max ) 487 if ( count >= max )
488 list.append( *it ); 488 list.append( *it );
489 ++count; 489 ++count;
490 } 490 }
491 for( it = list.begin(); it != list.end(); ++it ) { 491 for( it = list.begin(); it != list.end(); ++it ) {
492 removeAddress( (*it) ); 492 removeAddress( (*it) );
493 } 493 }
494} 494}
495 495
496// removes all emails but the first 496// removes all emails but the first
497// needed by phone sync 497// needed by phone sync
498void Addressee::simplifyEmails() 498void Addressee::simplifyEmails()
499{ 499{
500 if ( mData->emails.count() == 0 ) return ; 500 if ( mData->emails.count() == 0 ) return ;
501 QString email = mData->emails.first(); 501 QString email = mData->emails.first();
502 detach(); 502 detach();
503 mData->emails.clear(); 503 mData->emails.clear();
504 mData->emails.append( email ); 504 mData->emails.append( email );
505} 505}
506 506
507void Addressee::simplifyPhoneNumbers() 507void Addressee::simplifyPhoneNumbers()
508{ 508{
509 int max = 4; 509 int max = 4;
510 int inList = mData->phoneNumbers.count(); 510 int inList = mData->phoneNumbers.count();
511 KABC::PhoneNumber::List removeNumbers; 511 KABC::PhoneNumber::List removeNumbers;
512 KABC::PhoneNumber::List::Iterator phoneIter; 512 KABC::PhoneNumber::List::Iterator phoneIter;
513 if ( inList > max ) { 513 if ( inList > max ) {
514 // delete non-preferred numbers 514 // delete non-preferred numbers
515 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 515 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
516 ++phoneIter ) { 516 ++phoneIter ) {
517 if ( inList > max ) { 517 if ( inList > max ) {
518 if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) { 518 if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) {
519 removeNumbers.append( ( *phoneIter ) ); 519 removeNumbers.append( ( *phoneIter ) );
520 --inList; 520 --inList;
521 } 521 }
522 } else 522 } else
523 break; 523 break;
524 } 524 }
525 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 525 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
526 ++phoneIter ) { 526 ++phoneIter ) {
527 removePhoneNumber(( *phoneIter )); 527 removePhoneNumber(( *phoneIter ));
528 } 528 }
529 // delete preferred numbers 529 // delete preferred numbers
530 if ( inList > max ) { 530 if ( inList > max ) {
531 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 531 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
532 ++phoneIter ) { 532 ++phoneIter ) {
533 if ( inList > max ) { 533 if ( inList > max ) {
534 removeNumbers.append( ( *phoneIter ) ); 534 removeNumbers.append( ( *phoneIter ) );
535 --inList; 535 --inList;
536 } else 536 } else
537 break; 537 break;
538 } 538 }
539 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 539 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
540 ++phoneIter ) { 540 ++phoneIter ) {
541 removePhoneNumber(( *phoneIter )); 541 removePhoneNumber(( *phoneIter ));
542 } 542 }
543 } 543 }
544 } 544 }
545 // remove non-numeric characters 545 // remove non-numeric characters
546 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 546 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
547 ++phoneIter ) { 547 ++phoneIter ) {
548 if ( ! ( *phoneIter ).simplifyNumber() ) 548 if ( ! ( *phoneIter ).simplifyNumber() )
549 removeNumbers.append( ( *phoneIter ) ); 549 removeNumbers.append( ( *phoneIter ) );
550 } 550 }
551 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 551 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
552 ++phoneIter ) { 552 ++phoneIter ) {
553 removePhoneNumber(( *phoneIter )); 553 removePhoneNumber(( *phoneIter ));
554 } 554 }
555} 555}
556void Addressee::simplifyPhoneNumberTypes() 556void Addressee::simplifyPhoneNumberTypes()
557{ 557{
558 KABC::PhoneNumber::List::Iterator phoneIter; 558 KABC::PhoneNumber::List::Iterator phoneIter;
559 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 559 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
560 ++phoneIter ) 560 ++phoneIter )
561 ( *phoneIter ).simplifyType(); 561 ( *phoneIter ).simplifyType();
562} 562}
563void Addressee::removeID(const QString &prof) 563void Addressee::removeID(const QString &prof)
564{ 564{
565 detach(); 565 detach();
566 if ( prof.isEmpty() ) 566 if ( prof.isEmpty() )
567 mData->mExternalId = ":"; 567 mData->mExternalId = ":";
568 else 568 else
569 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); 569 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
570 570
571} 571}
572void Addressee::setID( const QString & prof , const QString & id ) 572void Addressee::setID( const QString & prof , const QString & id )
573{ 573{
574 detach(); 574 detach();
575 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); 575 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
576 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 576 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
577} 577}
578void Addressee::setTempSyncStat( int id ) 578void Addressee::setTempSyncStat( int id )
579{ 579{
580 if ( mData->mTempSyncStat == id ) return; 580 if ( mData->mTempSyncStat == id ) return;
581 detach(); 581 detach();
582 mData->mTempSyncStat = id; 582 mData->mTempSyncStat = id;
583} 583}
584int Addressee::tempSyncStat() const 584int Addressee::tempSyncStat() const
585{ 585{
586 return mData->mTempSyncStat; 586 return mData->mTempSyncStat;
587} 587}
588 588
589QString Addressee::getID( const QString & prof) 589QString Addressee::getID( const QString & prof)
590{ 590{
591 return KIdManager::getId ( mData->mExternalId, prof ); 591 return KIdManager::getId ( mData->mExternalId, prof );
592} 592}
593 593
594void Addressee::setCsum( const QString & prof , const QString & id ) 594void Addressee::setCsum( const QString & prof , const QString & id )
595{ 595{
596 detach(); 596 detach();
597 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 597 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
598 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); 598 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id );
599 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); 599 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() );
600} 600}
601 601
602QString Addressee::getCsum( const QString & prof) 602QString Addressee::getCsum( const QString & prof)
603{ 603{
604 return KIdManager::getCsum ( mData->mExternalId, prof ); 604 return KIdManager::getCsum ( mData->mExternalId, prof );
605} 605}
606 606
607void Addressee::setIDStr( const QString & s ) 607void Addressee::setIDStr( const QString & s )
608{ 608{
609 detach(); 609 detach();
610 mData->mExternalId = s; 610 mData->mExternalId = s;
611} 611}
612 612
613QString Addressee::IDStr() const 613QString Addressee::IDStr() const
614{ 614{
615 return mData->mExternalId; 615 return mData->mExternalId;
616} 616}
617 617
618void Addressee::setExternalUID( const QString &id ) 618void Addressee::setExternalUID( const QString &id )
619{ 619{
620 if ( id == mData->externalUID ) return; 620 if ( id == mData->externalUID ) return;
621 detach(); 621 detach();
622 mData->empty = false; 622 mData->empty = false;
623 mData->externalUID = id; 623 mData->externalUID = id;
624} 624}
625 625
626QString Addressee::externalUID() const 626QString Addressee::externalUID() const
627{ 627{
628 return mData->externalUID; 628 return mData->externalUID;
629} 629}
630void Addressee::setOriginalExternalUID( const QString &id ) 630void Addressee::setOriginalExternalUID( const QString &id )
631{ 631{
632 if ( id == mData->originalExternalUID ) return; 632 if ( id == mData->originalExternalUID ) return;
633 detach(); 633 detach();
634 mData->empty = false; 634 mData->empty = false;
635 //qDebug("*******Set orig uid %s ", id.latin1()); 635 //qDebug("*******Set orig uid %s ", id.latin1());
636 mData->originalExternalUID = id; 636 mData->originalExternalUID = id;
637} 637}
638 638
639QString Addressee::originalExternalUID() const 639QString Addressee::originalExternalUID() const
640{ 640{
641 return mData->originalExternalUID; 641 return mData->originalExternalUID;
642} 642}
643 643
644void Addressee::setUid( const QString &id ) 644void Addressee::setUid( const QString &id )
645{ 645{
646 if ( id == mData->uid ) return; 646 if ( id == mData->uid ) return;
647 detach(); 647 detach();
648 //qDebug("****setuid %s ", id.latin1()); 648 //qDebug("****setuid %s ", id.latin1());
649 mData->empty = false; 649 mData->empty = false;
650 mData->uid = id; 650 mData->uid = id;
651} 651}
652 652
653QString Addressee::uid() const 653QString Addressee::uid() const
654{ 654{
655 if ( mData->uid.isEmpty() ) 655 if ( mData->uid.isEmpty() )
656 mData->uid = KApplication::randomString( 10 ); 656 mData->uid = KApplication::randomString( 10 );
657 657
658 return mData->uid; 658 return mData->uid;
659} 659}
660 660
661QString Addressee::uidLabel() 661QString Addressee::uidLabel()
662{ 662{
663 return i18n("Unique Identifier"); 663 return i18n("Unique Identifier");
664} 664}
665 665
666void Addressee::setName( const QString &name ) 666void Addressee::setName( const QString &name )
667{ 667{
668 if ( name == mData->name ) return; 668 if ( name == mData->name ) return;
669 detach(); 669 detach();
670 mData->empty = false; 670 mData->empty = false;
671 mData->name = name; 671 mData->name = name;
672} 672}
673 673
674QString Addressee::name() const 674QString Addressee::name() const
675{ 675{
676 return mData->name; 676 return mData->name;
677} 677}
678 678
679QString Addressee::nameLabel() 679QString Addressee::nameLabel()
680{ 680{
681 return i18n("Name"); 681 return i18n("Name");
682} 682}
683 683
684 684
685void Addressee::setFormattedName( const QString &formattedName ) 685void Addressee::setFormattedName( const QString &formattedName )
686{ 686{
687 if ( formattedName == mData->formattedName ) return; 687 if ( formattedName == mData->formattedName ) return;
688 detach(); 688 detach();
689 mData->empty = false; 689 mData->empty = false;
690 mData->formattedName = formattedName; 690 mData->formattedName = formattedName;
691} 691}
692 692
693QString Addressee::formattedName() const 693QString Addressee::formattedName() const
694{ 694{
695 return mData->formattedName; 695 return mData->formattedName;
696} 696}
697 697
698QString Addressee::formattedNameLabel() 698QString Addressee::formattedNameLabel()
699{ 699{
700 return i18n("Formatted Name"); 700 return i18n("Formatted Name");
701} 701}
702 702
703 703
704void Addressee::setFamilyName( const QString &familyName ) 704void Addressee::setFamilyName( const QString &familyName )
705{ 705{
706 if ( familyName == mData->familyName ) return; 706 if ( familyName == mData->familyName ) return;
707 detach(); 707 detach();
708 mData->empty = false; 708 mData->empty = false;
709 mData->familyName = familyName; 709 mData->familyName = familyName;
710} 710}
711 711
712QString Addressee::familyName() const 712QString Addressee::familyName() const
713{ 713{
714 return mData->familyName; 714 return mData->familyName;
715} 715}
716 716
717QString Addressee::familyNameLabel() 717QString Addressee::familyNameLabel()
718{ 718{
719 return i18n("Family Name"); 719 return i18n("Family Name");
720} 720}
721 721
722 722
723void Addressee::setGivenName( const QString &givenName ) 723void Addressee::setGivenName( const QString &givenName )
724{ 724{
725 if ( givenName == mData->givenName ) return; 725 if ( givenName == mData->givenName ) return;
726 detach(); 726 detach();
727 mData->empty = false; 727 mData->empty = false;
728 mData->givenName = givenName; 728 mData->givenName = givenName;
729} 729}
730 730
731QString Addressee::givenName() const 731QString Addressee::givenName() const
732{ 732{
733 return mData->givenName; 733 return mData->givenName;
734} 734}
735 735
736QString Addressee::givenNameLabel() 736QString Addressee::givenNameLabel()
737{ 737{
738 return i18n("Given Name"); 738 return i18n("Given Name");
739} 739}
740 740
741 741
742void Addressee::setAdditionalName( const QString &additionalName ) 742void Addressee::setAdditionalName( const QString &additionalName )
743{ 743{
744 if ( additionalName == mData->additionalName ) return; 744 if ( additionalName == mData->additionalName ) return;
745 detach(); 745 detach();
746 mData->empty = false; 746 mData->empty = false;
747 mData->additionalName = additionalName; 747 mData->additionalName = additionalName;
748} 748}
749 749
750QString Addressee::additionalName() const 750QString Addressee::additionalName() const
751{ 751{
752 return mData->additionalName; 752 return mData->additionalName;
753} 753}
754 754
755QString Addressee::additionalNameLabel() 755QString Addressee::additionalNameLabel()
756{ 756{
757 return i18n("Additional Names"); 757 return i18n("Additional Names");
758} 758}
759 759
760 760
761void Addressee::setPrefix( const QString &prefix ) 761void Addressee::setPrefix( const QString &prefix )
762{ 762{
763 if ( prefix == mData->prefix ) return; 763 if ( prefix == mData->prefix ) return;
764 detach(); 764 detach();
765 mData->empty = false; 765 mData->empty = false;
766 mData->prefix = prefix; 766 mData->prefix = prefix;
767} 767}
768 768
769QString Addressee::prefix() const 769QString Addressee::prefix() const
770{ 770{
771 return mData->prefix; 771 return mData->prefix;
772} 772}
773 773
774QString Addressee::prefixLabel() 774QString Addressee::prefixLabel()
775{ 775{
776 return i18n("Honorific Prefixes"); 776 return i18n("Honorific Prefixes");
777} 777}
778 778
779 779
780void Addressee::setSuffix( const QString &suffix ) 780void Addressee::setSuffix( const QString &suffix )
781{ 781{
782 if ( suffix == mData->suffix ) return; 782 if ( suffix == mData->suffix ) return;
783 detach(); 783 detach();
784 mData->empty = false; 784 mData->empty = false;
785 mData->suffix = suffix; 785 mData->suffix = suffix;
786} 786}
787 787
788QString Addressee::suffix() const 788QString Addressee::suffix() const
789{ 789{
790 return mData->suffix; 790 return mData->suffix;
791} 791}
792 792
793QString Addressee::suffixLabel() 793QString Addressee::suffixLabel()
794{ 794{
795 return i18n("Honorific Suffixes"); 795 return i18n("Honorific Suffixes");
796} 796}
797 797
798 798
799void Addressee::setNickName( const QString &nickName ) 799void Addressee::setNickName( const QString &nickName )
800{ 800{
801 if ( nickName == mData->nickName ) return; 801 if ( nickName == mData->nickName ) return;
802 detach(); 802 detach();
803 mData->empty = false; 803 mData->empty = false;
804 mData->nickName = nickName; 804 mData->nickName = nickName;
805} 805}
806 806
807QString Addressee::nickName() const 807QString Addressee::nickName() const
808{ 808{
809 return mData->nickName; 809 return mData->nickName;
810} 810}
811 811
812QString Addressee::nickNameLabel() 812QString Addressee::nickNameLabel()
813{ 813{
814 return i18n("Nick Name"); 814 return i18n("Nick Name");
815} 815}
816 816
817 817
818void Addressee::setBirthday( const QDateTime &birthday ) 818void Addressee::setBirthday( const QDateTime &birthday )
819{ 819{
820 if ( birthday == mData->birthday ) return; 820 if ( birthday == mData->birthday ) return;
821 detach(); 821 detach();
822 mData->empty = false; 822 mData->empty = false;
823 mData->birthday = birthday; 823 mData->birthday = birthday;
824} 824}
825 825
826QDateTime Addressee::birthday() const 826QDateTime Addressee::birthday() const
827{ 827{
828 return mData->birthday; 828 return mData->birthday;
829} 829}
830 830
831QString Addressee::birthdayLabel() 831QString Addressee::birthdayLabel()
832{ 832{
833 return i18n("Birthday"); 833 return i18n("Birthday");
834} 834}
835 835
836 836
837QString Addressee::homeAddressStreetLabel() 837QString Addressee::homeAddressStreetLabel()
838{ 838{
839 return i18n("Home Address Street"); 839 return i18n("Home Address Street");
840} 840}
841 841
842 842
843QString Addressee::homeAddressLocalityLabel() 843QString Addressee::homeAddressLocalityLabel()
844{ 844{
845 return i18n("Home Address Locality"); 845 return i18n("Home Address Locality");
846} 846}
847 847
848 848
849QString Addressee::homeAddressRegionLabel() 849QString Addressee::homeAddressRegionLabel()
850{ 850{
851 return i18n("Home Address Region"); 851 return i18n("Home Address Region");
852} 852}
853 853
854 854
855QString Addressee::homeAddressPostalCodeLabel() 855QString Addressee::homeAddressPostalCodeLabel()
856{ 856{
857 return i18n("Home Address Postal Code"); 857 return i18n("Home Address Postal Code");
858} 858}
859 859
860 860
861QString Addressee::homeAddressCountryLabel() 861QString Addressee::homeAddressCountryLabel()
862{ 862{
863 return i18n("Home Address Country"); 863 return i18n("Home Address Country");
864} 864}
865 865
866 866
867QString Addressee::homeAddressLabelLabel() 867QString Addressee::homeAddressLabelLabel()
868{ 868{
869 return i18n("Home Address Label"); 869 return i18n("Home Address Label");
870} 870}
871 871
872 872
873QString Addressee::businessAddressStreetLabel() 873QString Addressee::businessAddressStreetLabel()
874{ 874{
875 return i18n("Business Address Street"); 875 return i18n("Business Address Street");
876} 876}
877 877
878 878
879QString Addressee::businessAddressLocalityLabel() 879QString Addressee::businessAddressLocalityLabel()
880{ 880{
881 return i18n("Business Address Locality"); 881 return i18n("Business Address Locality");
882} 882}
883 883
884 884
885QString Addressee::businessAddressRegionLabel() 885QString Addressee::businessAddressRegionLabel()
886{ 886{
887 return i18n("Business Address Region"); 887 return i18n("Business Address Region");
888} 888}
889 889
890 890
891QString Addressee::businessAddressPostalCodeLabel() 891QString Addressee::businessAddressPostalCodeLabel()
892{ 892{
893 return i18n("Business Address Postal Code"); 893 return i18n("Business Address Postal Code");
894} 894}
895 895
896 896
897QString Addressee::businessAddressCountryLabel() 897QString Addressee::businessAddressCountryLabel()
898{ 898{
899 return i18n("Business Address Country"); 899 return i18n("Business Address Country");
900} 900}
901 901
902 902
903QString Addressee::businessAddressLabelLabel() 903QString Addressee::businessAddressLabelLabel()
904{ 904{
905 return i18n("Business Address Label"); 905 return i18n("Business Address Label");
906} 906}
907 907
908 908
909QString Addressee::homePhoneLabel() 909QString Addressee::homePhoneLabel()
910{ 910{
911 return i18n("Home Phone"); 911 return i18n("Home Phone");
912} 912}
913 913
914 914
915QString Addressee::businessPhoneLabel() 915QString Addressee::businessPhoneLabel()
916{ 916{
917 return i18n("Business Phone"); 917 return i18n("Business Phone");
918} 918}
919 919
920 920
921QString Addressee::mobilePhoneLabel() 921QString Addressee::mobilePhoneLabel()
922{ 922{
923 return i18n("Mobile Phone"); 923 return i18n("Mobile Phone");
924} 924}
925 925
926 926
927QString Addressee::homeFaxLabel() 927QString Addressee::homeFaxLabel()
928{ 928{
929 return i18n("Home Fax"); 929 return i18n("Home Fax");
930} 930}
931 931
932 932
933QString Addressee::businessFaxLabel() 933QString Addressee::businessFaxLabel()
934{ 934{
935 return i18n("Business Fax"); 935 return i18n("Business Fax");
936} 936}
937 937
938 938
939QString Addressee::carPhoneLabel() 939QString Addressee::carPhoneLabel()
940{ 940{
941 return i18n("Car Phone"); 941 return i18n("Car Phone");
942} 942}
943 943
944 944
945QString Addressee::isdnLabel() 945QString Addressee::isdnLabel()
946{ 946{
947 return i18n("ISDN"); 947 return i18n("ISDN");
948} 948}
949 949
950 950
951QString Addressee::pagerLabel() 951QString Addressee::pagerLabel()
952{ 952{
953 return i18n("Pager"); 953 return i18n("Pager");
954} 954}
955 955
956QString Addressee::sipLabel() 956QString Addressee::sipLabel()
957{ 957{
958 return i18n("SIP"); 958 return i18n("SIP");
959} 959}
960 960
961QString Addressee::emailLabel() 961QString Addressee::emailLabel()
962{ 962{
963 return i18n("Email Address"); 963 return i18n("Email Address");
964} 964}
965 965
966 966
967void Addressee::setMailer( const QString &mailer ) 967void Addressee::setMailer( const QString &mailer )
968{ 968{
969 if ( mailer == mData->mailer ) return; 969 if ( mailer == mData->mailer ) return;
970 detach(); 970 detach();
971 mData->empty = false; 971 mData->empty = false;
972 mData->mailer = mailer; 972 mData->mailer = mailer;
973} 973}
974 974
975QString Addressee::mailer() const 975QString Addressee::mailer() const
976{ 976{
977 return mData->mailer; 977 return mData->mailer;
978} 978}
979 979
980QString Addressee::mailerLabel() 980QString Addressee::mailerLabel()
981{ 981{
982 return i18n("Mail Client"); 982 return i18n("Mail Client");
983} 983}
984 984
985 985
986void Addressee::setTimeZone( const TimeZone &timeZone ) 986void Addressee::setTimeZone( const TimeZone &timeZone )
987{ 987{
988 if ( timeZone == mData->timeZone ) return; 988 if ( timeZone == mData->timeZone ) return;
989 detach(); 989 detach();
990 mData->empty = false; 990 mData->empty = false;
991 mData->timeZone = timeZone; 991 mData->timeZone = timeZone;
992} 992}
993 993
994TimeZone Addressee::timeZone() const 994TimeZone Addressee::timeZone() const
995{ 995{
996 return mData->timeZone; 996 return mData->timeZone;
997} 997}
998 998
999QString Addressee::timeZoneLabel() 999QString Addressee::timeZoneLabel()
1000{ 1000{
1001 return i18n("Time Zone"); 1001 return i18n("Time Zone");
1002} 1002}
1003 1003
1004 1004
1005void Addressee::setGeo( const Geo &geo ) 1005void Addressee::setGeo( const Geo &geo )
1006{ 1006{
1007 if ( geo == mData->geo ) return; 1007 if ( geo == mData->geo ) return;
1008 detach(); 1008 detach();
1009 mData->empty = false; 1009 mData->empty = false;
1010 mData->geo = geo; 1010 mData->geo = geo;
1011} 1011}
1012 1012
1013Geo Addressee::geo() const 1013Geo Addressee::geo() const
1014{ 1014{
1015 return mData->geo; 1015 return mData->geo;
1016} 1016}
1017 1017
1018QString Addressee::geoLabel() 1018QString Addressee::geoLabel()
1019{ 1019{
1020 return i18n("Geographic Position"); 1020 return i18n("Geographic Position");
1021} 1021}
1022 1022
1023 1023
1024void Addressee::setTitle( const QString &title ) 1024void Addressee::setTitle( const QString &title )
1025{ 1025{
1026 if ( title == mData->title ) return; 1026 if ( title == mData->title ) return;
1027 detach(); 1027 detach();
1028 mData->empty = false; 1028 mData->empty = false;
1029 mData->title = title; 1029 mData->title = title;
1030} 1030}
1031 1031
1032QString Addressee::title() const 1032QString Addressee::title() const
1033{ 1033{
1034 return mData->title; 1034 return mData->title;
1035} 1035}
1036 1036
1037QString Addressee::titleLabel() 1037QString Addressee::titleLabel()
1038{ 1038{
1039 return i18n("Title"); 1039 return i18n("Title");
1040} 1040}
1041 1041
1042 1042
1043void Addressee::setRole( const QString &role ) 1043void Addressee::setRole( const QString &role )
1044{ 1044{
1045 if ( role == mData->role ) return; 1045 if ( role == mData->role ) return;
1046 detach(); 1046 detach();
1047 mData->empty = false; 1047 mData->empty = false;
1048 mData->role = role; 1048 mData->role = role;
1049} 1049}
1050 1050
1051QString Addressee::role() const 1051QString Addressee::role() const
1052{ 1052{
1053 return mData->role; 1053 return mData->role;
1054} 1054}
1055 1055
1056QString Addressee::roleLabel() 1056QString Addressee::roleLabel()
1057{ 1057{
1058 return i18n("Role"); 1058 return i18n("Role");
1059} 1059}
1060 1060
1061 1061
1062void Addressee::setOrganization( const QString &organization ) 1062void Addressee::setOrganization( const QString &organization )
1063{ 1063{
1064 if ( organization == mData->organization ) return; 1064 if ( organization == mData->organization ) return;
1065 detach(); 1065 detach();
1066 mData->empty = false; 1066 mData->empty = false;
1067 mData->organization = organization; 1067 mData->organization = organization;
1068} 1068}
1069 1069
1070QString Addressee::organization() const 1070QString Addressee::organization() const
1071{ 1071{
1072 return mData->organization; 1072 return mData->organization;
1073} 1073}
1074 1074
1075QString Addressee::organizationLabel() 1075QString Addressee::organizationLabel()
1076{ 1076{
1077 return i18n("Organization"); 1077 return i18n("Organization");
1078} 1078}
1079 1079
1080 1080
1081void Addressee::setNote( const QString &note ) 1081void Addressee::setNote( const QString &note )
1082{ 1082{
1083 if ( note == mData->note ) return; 1083 if ( note == mData->note ) return;
1084 detach(); 1084 detach();
1085 mData->empty = false; 1085 mData->empty = false;
1086 mData->note = note; 1086 mData->note = note;
1087} 1087}
1088 1088
1089QString Addressee::note() const 1089QString Addressee::note() const
1090{ 1090{
1091 return mData->note; 1091 return mData->note;
1092} 1092}
1093 1093
1094QString Addressee::noteLabel() 1094QString Addressee::noteLabel()
1095{ 1095{
1096 return i18n("Note"); 1096 return i18n("Note");
1097} 1097}
1098 1098
1099 1099
1100void Addressee::setProductId( const QString &productId ) 1100void Addressee::setProductId( const QString &productId )
1101{ 1101{
1102 if ( productId == mData->productId ) return; 1102 if ( productId == mData->productId ) return;
1103 detach(); 1103 detach();
1104 mData->empty = false; 1104 mData->empty = false;
1105 mData->productId = productId; 1105 mData->productId = productId;
1106} 1106}
1107 1107
1108QString Addressee::productId() const 1108QString Addressee::productId() const
1109{ 1109{
1110 return mData->productId; 1110 return mData->productId;
1111} 1111}
1112 1112
1113QString Addressee::productIdLabel() 1113QString Addressee::productIdLabel()
1114{ 1114{
1115 return i18n("Product Identifier"); 1115 return i18n("Product Identifier");
1116} 1116}
1117 1117
1118 1118
1119void Addressee::setRevision( const QDateTime &revision ) 1119void Addressee::setRevision( const QDateTime &revision )
1120{ 1120{
1121 if ( revision == mData->revision ) return; 1121 if ( revision == mData->revision ) return;
1122 detach(); 1122 detach();
1123 mData->empty = false; 1123 mData->empty = false;
1124 mData->revision = QDateTime( revision.date(), 1124 mData->revision = QDateTime( revision.date(),
1125 QTime (revision.time().hour(), 1125 QTime (revision.time().hour(),
1126 revision.time().minute(), 1126 revision.time().minute(),
1127 revision.time().second())); 1127 revision.time().second()));
1128} 1128}
1129 1129
1130QDateTime Addressee::revision() const 1130QDateTime Addressee::revision() const
1131{ 1131{
1132 return mData->revision; 1132 return mData->revision;
1133} 1133}
1134 1134
1135QString Addressee::revisionLabel() 1135QString Addressee::revisionLabel()
1136{ 1136{
1137 return i18n("Revision Date"); 1137 return i18n("Revision Date");
1138} 1138}
1139 1139
1140 1140
1141void Addressee::setSortString( const QString &sortString ) 1141void Addressee::setSortString( const QString &sortString )
1142{ 1142{
1143 if ( sortString == mData->sortString ) return; 1143 if ( sortString == mData->sortString ) return;
1144 detach(); 1144 detach();
1145 mData->empty = false; 1145 mData->empty = false;
1146 mData->sortString = sortString; 1146 mData->sortString = sortString;
1147} 1147}
1148 1148
1149QString Addressee::sortString() const 1149QString Addressee::sortString() const
1150{ 1150{
1151 return mData->sortString; 1151 return mData->sortString;
1152} 1152}
1153 1153
1154QString Addressee::sortStringLabel() 1154QString Addressee::sortStringLabel()
1155{ 1155{
1156 return i18n("Sort String"); 1156 return i18n("Sort String");
1157} 1157}
1158 1158
1159 1159
1160void Addressee::setUrl( const KURL &url ) 1160void Addressee::setUrl( const KURL &url )
1161{ 1161{
1162 if ( url == mData->url ) return; 1162 if ( url == mData->url ) return;
1163 detach(); 1163 detach();
1164 mData->empty = false; 1164 mData->empty = false;
1165 mData->url = url; 1165 mData->url = url;
1166} 1166}
1167 1167
1168KURL Addressee::url() const 1168KURL Addressee::url() const
1169{ 1169{
1170 return mData->url; 1170 return mData->url;
1171} 1171}
1172 1172
1173QString Addressee::urlLabel() 1173QString Addressee::urlLabel()
1174{ 1174{
1175 return i18n("URL"); 1175 return i18n("URL");
1176} 1176}
1177 1177
1178 1178
1179void Addressee::setSecrecy( const Secrecy &secrecy ) 1179void Addressee::setSecrecy( const Secrecy &secrecy )
1180{ 1180{
1181 if ( secrecy == mData->secrecy ) return; 1181 if ( secrecy == mData->secrecy ) return;
1182 detach(); 1182 detach();
1183 mData->empty = false; 1183 mData->empty = false;
1184 mData->secrecy = secrecy; 1184 mData->secrecy = secrecy;
1185} 1185}
1186 1186
1187Secrecy Addressee::secrecy() const 1187Secrecy Addressee::secrecy() const
1188{ 1188{
1189 return mData->secrecy; 1189 return mData->secrecy;
1190} 1190}
1191 1191
1192QString Addressee::secrecyLabel() 1192QString Addressee::secrecyLabel()
1193{ 1193{
1194 return i18n("Security Class"); 1194 return i18n("Security Class");
1195} 1195}
1196 1196
1197 1197
1198void Addressee::setLogo( const Picture &logo ) 1198void Addressee::setLogo( const Picture &logo )
1199{ 1199{
1200 if ( logo == mData->logo ) return; 1200 if ( logo == mData->logo ) return;
1201 detach(); 1201 detach();
1202 mData->empty = false; 1202 mData->empty = false;
1203 mData->logo = logo; 1203 mData->logo = logo;
1204} 1204}
1205 1205
1206Picture Addressee::logo() const 1206Picture Addressee::logo() const
1207{ 1207{
1208 return mData->logo; 1208 return mData->logo;
1209} 1209}
1210 1210
1211QString Addressee::logoLabel() 1211QString Addressee::logoLabel()
1212{ 1212{
1213 return i18n("Logo"); 1213 return i18n("Logo");
1214} 1214}
1215 1215
1216 1216
1217void Addressee::setPhoto( const Picture &photo ) 1217void Addressee::setPhoto( const Picture &photo )
1218{ 1218{
1219 if ( photo == mData->photo ) return; 1219 if ( photo == mData->photo ) return;
1220 detach(); 1220 detach();
1221 mData->empty = false; 1221 mData->empty = false;
1222 mData->photo = photo; 1222 mData->photo = photo;
1223} 1223}
1224 1224
1225Picture Addressee::photo() const 1225Picture Addressee::photo() const
1226{ 1226{
1227 return mData->photo; 1227 return mData->photo;
1228} 1228}
1229 1229
1230QString Addressee::photoLabel() 1230QString Addressee::photoLabel()
1231{ 1231{
1232 return i18n("Photo"); 1232 return i18n("Photo");
1233} 1233}
1234 1234
1235 1235
1236void Addressee::setSound( const Sound &sound ) 1236void Addressee::setSound( const Sound &sound )
1237{ 1237{
1238 if ( sound == mData->sound ) return; 1238 if ( sound == mData->sound ) return;
1239 detach(); 1239 detach();
1240 mData->empty = false; 1240 mData->empty = false;
1241 mData->sound = sound; 1241 mData->sound = sound;
1242} 1242}
1243 1243
1244Sound Addressee::sound() const 1244Sound Addressee::sound() const
1245{ 1245{
1246 return mData->sound; 1246 return mData->sound;
1247} 1247}
1248 1248
1249QString Addressee::soundLabel() 1249QString Addressee::soundLabel()
1250{ 1250{
1251 return i18n("Sound"); 1251 return i18n("Sound");
1252} 1252}
1253 1253
1254 1254
1255void Addressee::setAgent( const Agent &agent ) 1255void Addressee::setAgent( const Agent &agent )
1256{ 1256{
1257 if ( agent == mData->agent ) return; 1257 if ( agent == mData->agent ) return;
1258 detach(); 1258 detach();
1259 mData->empty = false; 1259 mData->empty = false;
1260 mData->agent = agent; 1260 mData->agent = agent;
1261} 1261}
1262 1262
1263Agent Addressee::agent() const 1263Agent Addressee::agent() const
1264{ 1264{
1265 return mData->agent; 1265 return mData->agent;
1266} 1266}
1267 1267
1268QString Addressee::agentLabel() 1268QString Addressee::agentLabel()
1269{ 1269{
1270 return i18n("Agent"); 1270 return i18n("Agent");
1271} 1271}
1272 1272
1273 1273
1274 1274
1275void Addressee::setNameFromString( const QString &str ) 1275void Addressee::setNameFromString( const QString &str )
1276{ 1276{
1277 setFormattedName( str ); 1277 setFormattedName( str );
1278 setName( str ); 1278 setName( str );
1279 1279
1280 static bool first = true; 1280 static bool first = true;
1281 static QStringList titles; 1281 static QStringList titles;
1282 static QStringList suffixes; 1282 static QStringList suffixes;
1283 static QStringList prefixes; 1283 static QStringList prefixes;
1284 1284
1285 if ( first ) { 1285 if ( first ) {
1286 first = false; 1286 first = false;
1287 titles += i18n( "Dr." ); 1287 titles += i18n( "Dr." );
1288 titles += i18n( "Miss" ); 1288 titles += i18n( "Miss" );
1289 titles += i18n( "Mr." ); 1289 titles += i18n( "Mr." );
1290 titles += i18n( "Mrs." ); 1290 titles += i18n( "Mrs." );
1291 titles += i18n( "Ms." ); 1291 titles += i18n( "Ms." );
1292 titles += i18n( "Prof." ); 1292 titles += i18n( "Prof." );
1293 1293
1294 suffixes += i18n( "I" ); 1294 suffixes += i18n( "I" );
1295 suffixes += i18n( "II" ); 1295 suffixes += i18n( "II" );
1296 suffixes += i18n( "III" ); 1296 suffixes += i18n( "III" );
1297 suffixes += i18n( "Jr." ); 1297 suffixes += i18n( "Jr." );
1298 suffixes += i18n( "Sr." ); 1298 suffixes += i18n( "Sr." );
1299 1299
1300 prefixes += "van"; 1300 prefixes += "van";
1301 prefixes += "von"; 1301 prefixes += "von";
1302 prefixes += "de"; 1302 prefixes += "de";
1303 1303
1304 KConfig config( locateLocal( "config", "kabcrc") ); 1304 KConfig config( locateLocal( "config", "kabcrc") );
1305 config.setGroup( "General" ); 1305 config.setGroup( "General" );
1306 titles += config.readListEntry( "Prefixes" ); 1306 titles += config.readListEntry( "Prefixes" );
1307 titles.remove( "" ); 1307 titles.remove( "" );
1308 prefixes += config.readListEntry( "Inclusions" ); 1308 prefixes += config.readListEntry( "Inclusions" );
1309 prefixes.remove( "" ); 1309 prefixes.remove( "" );
1310 suffixes += config.readListEntry( "Suffixes" ); 1310 suffixes += config.readListEntry( "Suffixes" );
1311 suffixes.remove( "" ); 1311 suffixes.remove( "" );
1312 } 1312 }
1313 1313
1314 // clear all name parts 1314 // clear all name parts
1315 setPrefix( "" ); 1315 setPrefix( "" );
1316 setGivenName( "" ); 1316 setGivenName( "" );
1317 setAdditionalName( "" ); 1317 setAdditionalName( "" );
1318 setFamilyName( "" ); 1318 setFamilyName( "" );
1319 setSuffix( "" ); 1319 setSuffix( "" );
1320 1320
1321 if ( str.isEmpty() ) 1321 if ( str.isEmpty() )
1322 return; 1322 return;
1323 1323
1324 int i = str.find(','); 1324 int i = str.find(',');
1325 if( i < 0 ) { 1325 if( i < 0 ) {
1326 QStringList parts = QStringList::split( " ", str ); 1326 QStringList parts = QStringList::split( " ", str );
1327 int leftOffset = 0; 1327 int leftOffset = 0;
1328 int rightOffset = parts.count() - 1; 1328 int rightOffset = parts.count() - 1;
1329 1329
1330 QString suffix; 1330 QString suffix;
1331 while ( rightOffset >= 0 ) { 1331 while ( rightOffset >= 0 ) {
1332 if ( suffixes.contains( parts[ rightOffset ] ) ) { 1332 if ( suffixes.contains( parts[ rightOffset ] ) ) {
1333 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); 1333 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " "));
1334 rightOffset--; 1334 rightOffset--;
1335 } else 1335 } else
1336 break; 1336 break;
1337 } 1337 }
1338 setSuffix( suffix ); 1338 setSuffix( suffix );
1339 1339
1340 if ( rightOffset < 0 ) 1340 if ( rightOffset < 0 )
1341 return; 1341 return;
1342 1342
1343 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { 1343 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) {
1344 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); 1344 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] );
1345 rightOffset--; 1345 rightOffset--;
1346 } else 1346 } else
1347 setFamilyName( parts[ rightOffset ] ); 1347 setFamilyName( parts[ rightOffset ] );
1348 1348
1349 QString prefix; 1349 QString prefix;
1350 while ( leftOffset < rightOffset ) { 1350 while ( leftOffset < rightOffset ) {
1351 if ( titles.contains( parts[ leftOffset ] ) ) { 1351 if ( titles.contains( parts[ leftOffset ] ) ) {
1352 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1352 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1353 leftOffset++; 1353 leftOffset++;
1354 } else 1354 } else
1355 break; 1355 break;
1356 } 1356 }
1357 setPrefix( prefix ); 1357 setPrefix( prefix );
1358 1358
1359 if ( leftOffset < rightOffset ) { 1359 if ( leftOffset < rightOffset ) {
1360 setGivenName( parts[ leftOffset ] ); 1360 setGivenName( parts[ leftOffset ] );
1361 leftOffset++; 1361 leftOffset++;
1362 } 1362 }
1363 1363
1364 QString additionalName; 1364 QString additionalName;
1365 while ( leftOffset < rightOffset ) { 1365 while ( leftOffset < rightOffset ) {
1366 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1366 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1367 leftOffset++; 1367 leftOffset++;
1368 } 1368 }
1369 setAdditionalName( additionalName ); 1369 setAdditionalName( additionalName );
1370 } else { 1370 } else {
1371 QString part1 = str.left( i ); 1371 QString part1 = str.left( i );
1372 QString part2 = str.mid( i + 1 ); 1372 QString part2 = str.mid( i + 1 );
1373 1373
1374 QStringList parts = QStringList::split( " ", part1 ); 1374 QStringList parts = QStringList::split( " ", part1 );
1375 int leftOffset = 0; 1375 int leftOffset = 0;
1376 int rightOffset = parts.count() - 1; 1376 int rightOffset = parts.count() - 1;
1377 1377
1378 QString suffix; 1378 QString suffix;
1379 while ( rightOffset >= 0 ) { 1379 while ( rightOffset >= 0 ) {
1380 if ( suffixes.contains( parts[ rightOffset ] ) ) { 1380 if ( suffixes.contains( parts[ rightOffset ] ) ) {
1381 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); 1381 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " "));
1382 rightOffset--; 1382 rightOffset--;
1383 } else 1383 } else
1384 break; 1384 break;
1385 } 1385 }
1386 setSuffix( suffix ); 1386 setSuffix( suffix );
1387 1387
1388 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { 1388 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) {
1389 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); 1389 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] );
1390 rightOffset--; 1390 rightOffset--;
1391 } else 1391 } else
1392 setFamilyName( parts[ rightOffset ] ); 1392 setFamilyName( parts[ rightOffset ] );
1393 1393
1394 QString prefix; 1394 QString prefix;
1395 while ( leftOffset < rightOffset ) { 1395 while ( leftOffset < rightOffset ) {
1396 if ( titles.contains( parts[ leftOffset ] ) ) { 1396 if ( titles.contains( parts[ leftOffset ] ) ) {
1397 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1397 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1398 leftOffset++; 1398 leftOffset++;
1399 } else 1399 } else
1400 break; 1400 break;
1401 } 1401 }
1402 1402
1403 parts = QStringList::split( " ", part2 ); 1403 parts = QStringList::split( " ", part2 );
1404 1404
1405 leftOffset = 0; 1405 leftOffset = 0;
1406 rightOffset = parts.count(); 1406 rightOffset = parts.count();
1407 1407
1408 while ( leftOffset < rightOffset ) { 1408 while ( leftOffset < rightOffset ) {
1409 if ( titles.contains( parts[ leftOffset ] ) ) { 1409 if ( titles.contains( parts[ leftOffset ] ) ) {
1410 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1410 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1411 leftOffset++; 1411 leftOffset++;
1412 } else 1412 } else
1413 break; 1413 break;
1414 } 1414 }
1415 setPrefix( prefix ); 1415 setPrefix( prefix );
1416 1416
1417 if ( leftOffset < rightOffset ) { 1417 if ( leftOffset < rightOffset ) {
1418 setGivenName( parts[ leftOffset ] ); 1418 setGivenName( parts[ leftOffset ] );
1419 leftOffset++; 1419 leftOffset++;
1420 } 1420 }
1421 1421
1422 QString additionalName; 1422 QString additionalName;
1423 while ( leftOffset < rightOffset ) { 1423 while ( leftOffset < rightOffset ) {
1424 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1424 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1425 leftOffset++; 1425 leftOffset++;
1426 } 1426 }
1427 setAdditionalName( additionalName ); 1427 setAdditionalName( additionalName );
1428 } 1428 }
1429} 1429}
1430 1430
1431QString Addressee::realName() const 1431QString Addressee::realName() const
1432{ 1432{
1433 if ( !formattedName().isEmpty() ) 1433 if ( !formattedName().isEmpty() )
1434 return formattedName(); 1434 return formattedName();
1435 1435
1436 QString n = assembledName(); 1436 QString n = assembledName();
1437 1437
1438 if ( n.isEmpty() ) 1438 if ( n.isEmpty() )
1439 n = name(); 1439 n = name();
1440 1440
1441 return n; 1441 return n;
1442} 1442}
1443 1443
1444QString Addressee::assembledName() const 1444QString Addressee::assembledName() const
1445{ 1445{
1446 QString name = prefix() + " " + givenName() + " " + additionalName() + " " + 1446 QString name = prefix() + " " + givenName() + " " + additionalName() + " " +
1447 familyName() + " " + suffix(); 1447 familyName() + " " + suffix();
1448 1448
1449 return name.simplifyWhiteSpace(); 1449 return name.simplifyWhiteSpace();
1450} 1450}
1451 1451
1452QString Addressee::fullEmail( const QString &email ) const 1452QString Addressee::fullEmail( const QString &email ) const
1453{ 1453{
1454 QString e; 1454 QString e;
1455 if ( email.isNull() ) { 1455 if ( email.isNull() ) {
1456 e = preferredEmail(); 1456 e = preferredEmail();
1457 } else { 1457 } else {
1458 e = email; 1458 e = email;
1459 } 1459 }
1460 if ( e.isEmpty() ) return QString::null; 1460 if ( e.isEmpty() ) return QString::null;
1461 1461
1462 QString text; 1462 QString text;
1463 if ( realName().isEmpty() ) 1463 if ( realName().isEmpty() )
1464 text = e; 1464 text = e;
1465 else 1465 else
1466 text = assembledName() + " <" + e + ">"; 1466 text = assembledName() + " <" + e + ">";
1467 1467
1468 return text; 1468 return text;
1469} 1469}
1470 1470
1471void Addressee::insertEmail( const QString &email, bool preferred ) 1471void Addressee::insertEmail( const QString &email, bool preferred )
1472{ 1472{
1473 detach(); 1473 detach();
1474 1474
1475 QStringList::Iterator it = mData->emails.find( email ); 1475 QStringList::Iterator it = mData->emails.find( email );
1476 1476
1477 if ( it != mData->emails.end() ) { 1477 if ( it != mData->emails.end() ) {
1478 if ( !preferred || it == mData->emails.begin() ) return; 1478 if ( !preferred || it == mData->emails.begin() ) return;
1479 mData->emails.remove( it ); 1479 mData->emails.remove( it );
1480 mData->emails.prepend( email ); 1480 mData->emails.prepend( email );
1481 } else { 1481 } else {
1482 if ( preferred ) { 1482 if ( preferred ) {
1483 mData->emails.prepend( email ); 1483 mData->emails.prepend( email );
1484 } else { 1484 } else {
1485 mData->emails.append( email ); 1485 mData->emails.append( email );
1486 } 1486 }
1487 } 1487 }
1488} 1488}
1489 1489
1490void Addressee::removeEmail( const QString &email ) 1490void Addressee::removeEmail( const QString &email )
1491{ 1491{
1492 detach(); 1492 detach();
1493 1493
1494 QStringList::Iterator it = mData->emails.find( email ); 1494 QStringList::Iterator it = mData->emails.find( email );
1495 if ( it == mData->emails.end() ) return; 1495 if ( it == mData->emails.end() ) return;
1496 1496
1497 mData->emails.remove( it ); 1497 mData->emails.remove( it );
1498} 1498}
1499 1499
1500QString Addressee::preferredEmail() const 1500QString Addressee::preferredEmail() const
1501{ 1501{
1502 if ( mData->emails.count() == 0 ) return QString::null; 1502 if ( mData->emails.count() == 0 ) return QString::null;
1503 else return mData->emails.first(); 1503 else return mData->emails.first();
1504} 1504}
1505 1505
1506QStringList Addressee::emails() const 1506QStringList Addressee::emails() const
1507{ 1507{
1508 return mData->emails; 1508 return mData->emails;
1509} 1509}
1510void Addressee::setEmails( const QStringList& emails ) { 1510void Addressee::setEmails( const QStringList& emails ) {
1511 detach(); 1511 detach();
1512 mData->emails = emails; 1512 mData->emails = emails;
1513} 1513}
1514void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber ) 1514void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber )
1515{ 1515{
1516 detach(); 1516 detach();
1517 mData->empty = false; 1517 mData->empty = false;
1518 1518
1519 PhoneNumber::List::Iterator it; 1519 PhoneNumber::List::Iterator it;
1520 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1520 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1521 if ( (*it).id() == phoneNumber.id() ) { 1521 if ( (*it).id() == phoneNumber.id() ) {
1522 *it = phoneNumber; 1522 *it = phoneNumber;
1523 return; 1523 return;
1524 } 1524 }
1525 } 1525 }
1526 mData->phoneNumbers.append( phoneNumber ); 1526 mData->phoneNumbers.append( phoneNumber );
1527} 1527}
1528 1528
1529void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber ) 1529void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber )
1530{ 1530{
1531 detach(); 1531 detach();
1532 1532
1533 PhoneNumber::List::Iterator it; 1533 PhoneNumber::List::Iterator it;
1534 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1534 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1535 if ( (*it).id() == phoneNumber.id() ) { 1535 if ( (*it).id() == phoneNumber.id() ) {
1536 mData->phoneNumbers.remove( it ); 1536 mData->phoneNumbers.remove( it );
1537 return; 1537 return;
1538 } 1538 }
1539 } 1539 }
1540} 1540}
1541 1541
1542PhoneNumber Addressee::phoneNumber( int type ) const 1542PhoneNumber Addressee::phoneNumber( int type ) const
1543{ 1543{
1544 PhoneNumber phoneNumber( "", type ); 1544 PhoneNumber phoneNumber( "", type );
1545 PhoneNumber::List::ConstIterator it; 1545 PhoneNumber::List::ConstIterator it;
1546 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1546 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1547 if ( matchBinaryPatternP( (*it).type(), type ) ) { 1547 if ( matchBinaryPatternP( (*it).type(), type ) ) {
1548 if ( (*it).type() & PhoneNumber::Pref ) 1548 if ( (*it).type() & PhoneNumber::Pref )
1549 return (*it); 1549 return (*it);
1550 else if ( phoneNumber.number().isEmpty() ) 1550 else if ( phoneNumber.number().isEmpty() )
1551 phoneNumber = (*it); 1551 phoneNumber = (*it);
1552 } 1552 }
1553 } 1553 }
1554 1554
1555 return phoneNumber; 1555 return phoneNumber;
1556} 1556}
1557 1557
1558PhoneNumber::List Addressee::phoneNumbers() const 1558PhoneNumber::List Addressee::phoneNumbers() const
1559{ 1559{
1560 return mData->phoneNumbers; 1560 return mData->phoneNumbers;
1561} 1561}
1562 1562
1563PhoneNumber::List Addressee::phoneNumbers( int type ) const 1563PhoneNumber::List Addressee::phoneNumbers( int type ) const
1564{ 1564{
1565 PhoneNumber::List list; 1565 PhoneNumber::List list;
1566 1566
1567 PhoneNumber::List::ConstIterator it; 1567 PhoneNumber::List::ConstIterator it;
1568 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1568 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1569 if ( matchBinaryPattern( (*it).type(), type ) ) { 1569 if ( matchBinaryPattern( (*it).type(), type ) ) {
1570 list.append( *it ); 1570 list.append( *it );
1571 } 1571 }
1572 } 1572 }
1573 return list; 1573 return list;
1574} 1574}
1575 1575
1576PhoneNumber Addressee::findPhoneNumber( const QString &id ) const 1576PhoneNumber Addressee::findPhoneNumber( const QString &id ) const
1577{ 1577{
1578 PhoneNumber::List::ConstIterator it; 1578 PhoneNumber::List::ConstIterator it;
1579 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1579 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1580 if ( (*it).id() == id ) { 1580 if ( (*it).id() == id ) {
1581 return *it; 1581 return *it;
1582 } 1582 }
1583 } 1583 }
1584 return PhoneNumber(); 1584 return PhoneNumber();
1585} 1585}
1586 1586
1587void Addressee::insertKey( const Key &key ) 1587void Addressee::insertKey( const Key &key )
1588{ 1588{
1589 detach(); 1589 detach();
1590 mData->empty = false; 1590 mData->empty = false;
1591 1591
1592 Key::List::Iterator it; 1592 Key::List::Iterator it;
1593 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1593 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1594 if ( (*it).id() == key.id() ) { 1594 if ( (*it).id() == key.id() ) {
1595 *it = key; 1595 *it = key;
1596 return; 1596 return;
1597 } 1597 }
1598 } 1598 }
1599 mData->keys.append( key ); 1599 mData->keys.append( key );
1600} 1600}
1601 1601
1602void Addressee::removeKey( const Key &key ) 1602void Addressee::removeKey( const Key &key )
1603{ 1603{
1604 detach(); 1604 detach();
1605 1605
1606 Key::List::Iterator it; 1606 Key::List::Iterator it;
1607 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1607 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1608 if ( (*it).id() == key.id() ) { 1608 if ( (*it).id() == key.id() ) {
1609 mData->keys.remove( key ); 1609 mData->keys.remove( key );
1610 return; 1610 return;
1611 } 1611 }
1612 } 1612 }
1613} 1613}
1614 1614
1615Key Addressee::key( int type, QString customTypeString ) const 1615Key Addressee::key( int type, QString customTypeString ) const
1616{ 1616{
1617 Key::List::ConstIterator it; 1617 Key::List::ConstIterator it;
1618 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1618 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1619 if ( (*it).type() == type ) { 1619 if ( (*it).type() == type ) {
1620 if ( type == Key::Custom ) { 1620 if ( type == Key::Custom ) {
1621 if ( customTypeString.isEmpty() ) { 1621 if ( customTypeString.isEmpty() ) {
1622 return *it; 1622 return *it;
1623 } else { 1623 } else {
1624 if ( (*it).customTypeString() == customTypeString ) 1624 if ( (*it).customTypeString() == customTypeString )
1625 return (*it); 1625 return (*it);
1626 } 1626 }
1627 } else { 1627 } else {
1628 return *it; 1628 return *it;
1629 } 1629 }
1630 } 1630 }
1631 } 1631 }
1632 return Key( QString(), type ); 1632 return Key( QString(), type );
1633} 1633}
1634void Addressee::setKeys( const Key::List& list ) { 1634void Addressee::setKeys( const Key::List& list ) {
1635 detach(); 1635 detach();
1636 mData->keys = list; 1636 mData->keys = list;
1637} 1637}
1638 1638
1639Key::List Addressee::keys() const 1639Key::List Addressee::keys() const
1640{ 1640{
1641 return mData->keys; 1641 return mData->keys;
1642} 1642}
1643 1643
1644Key::List Addressee::keys( int type, QString customTypeString ) const 1644Key::List Addressee::keys( int type, QString customTypeString ) const
1645{ 1645{
1646 Key::List list; 1646 Key::List list;
1647 1647
1648 Key::List::ConstIterator it; 1648 Key::List::ConstIterator it;
1649 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1649 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1650 if ( (*it).type() == type ) { 1650 if ( (*it).type() == type ) {
1651 if ( type == Key::Custom ) { 1651 if ( type == Key::Custom ) {
1652 if ( customTypeString.isEmpty() ) { 1652 if ( customTypeString.isEmpty() ) {
1653 list.append(*it); 1653 list.append(*it);
1654 } else { 1654 } else {
1655 if ( (*it).customTypeString() == customTypeString ) 1655 if ( (*it).customTypeString() == customTypeString )
1656 list.append(*it); 1656 list.append(*it);
1657 } 1657 }
1658 } else { 1658 } else {
1659 list.append(*it); 1659 list.append(*it);
1660 } 1660 }
1661 } 1661 }
1662 } 1662 }
1663 return list; 1663 return list;
1664} 1664}
1665 1665
1666Key Addressee::findKey( const QString &id ) const 1666Key Addressee::findKey( const QString &id ) const
1667{ 1667{
1668 Key::List::ConstIterator it; 1668 Key::List::ConstIterator it;
1669 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1669 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1670 if ( (*it).id() == id ) { 1670 if ( (*it).id() == id ) {
1671 return *it; 1671 return *it;
1672 } 1672 }
1673 } 1673 }
1674 return Key(); 1674 return Key();
1675} 1675}
1676 1676
1677QString Addressee::asString() const 1677QString Addressee::asString() const
1678{ 1678{
1679 return "Smith, agent Smith..."; 1679 return "Smith, agent Smith...";
1680} 1680}
1681 1681
1682void Addressee::dump() const 1682void Addressee::dump() const
1683{ 1683{
1684 return; 1684 return;
1685 kdDebug(5700) << "Addressee {" << endl; 1685 kdDebug(5700) << "Addressee {" << endl;
1686 1686
1687 kdDebug(5700) << " Uid: '" << uid() << "'" << endl; 1687 kdDebug(5700) << " Uid: '" << uid() << "'" << endl;
1688 1688
1689 kdDebug(5700) << " Name: '" << name() << "'" << endl; 1689 kdDebug(5700) << " Name: '" << name() << "'" << endl;
1690 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl; 1690 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl;
1691 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl; 1691 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl;
1692 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl; 1692 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl;
1693 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl; 1693 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl;
1694 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl; 1694 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl;
1695 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl; 1695 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl;
1696 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl; 1696 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl;
1697 kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl; 1697 kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl;
1698 kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl; 1698 kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl;
1699 kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl; 1699 kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl;
1700 kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl; 1700 kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl;
1701 kdDebug(5700) << " Title: '" << title() << "'" << endl; 1701 kdDebug(5700) << " Title: '" << title() << "'" << endl;
1702 kdDebug(5700) << " Role: '" << role() << "'" << endl; 1702 kdDebug(5700) << " Role: '" << role() << "'" << endl;
1703 kdDebug(5700) << " Organization: '" << organization() << "'" << endl; 1703 kdDebug(5700) << " Organization: '" << organization() << "'" << endl;
1704 kdDebug(5700) << " Note: '" << note() << "'" << endl; 1704 kdDebug(5700) << " Note: '" << note() << "'" << endl;
1705 kdDebug(5700) << " ProductId: '" << productId() << "'" << endl; 1705 kdDebug(5700) << " ProductId: '" << productId() << "'" << endl;
1706 kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl; 1706 kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl;
1707 kdDebug(5700) << " SortString: '" << sortString() << "'" << endl; 1707 kdDebug(5700) << " SortString: '" << sortString() << "'" << endl;
1708 kdDebug(5700) << " Url: '" << url().url() << "'" << endl; 1708 kdDebug(5700) << " Url: '" << url().url() << "'" << endl;
1709 kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl; 1709 kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl;
1710 kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl; 1710 kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl;
1711 kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl; 1711 kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl;
1712 kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl; 1712 kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl;
1713 kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl; 1713 kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl;
1714 1714
1715 kdDebug(5700) << " Emails {" << endl; 1715 kdDebug(5700) << " Emails {" << endl;
1716 QStringList e = emails(); 1716 QStringList e = emails();
1717 QStringList::ConstIterator it; 1717 QStringList::ConstIterator it;
1718 for( it = e.begin(); it != e.end(); ++it ) { 1718 for( it = e.begin(); it != e.end(); ++it ) {
1719 kdDebug(5700) << " " << (*it) << endl; 1719 kdDebug(5700) << " " << (*it) << endl;
1720 } 1720 }
1721 kdDebug(5700) << " }" << endl; 1721 kdDebug(5700) << " }" << endl;
1722 1722
1723 kdDebug(5700) << " PhoneNumbers {" << endl; 1723 kdDebug(5700) << " PhoneNumbers {" << endl;
1724 PhoneNumber::List p = phoneNumbers(); 1724 PhoneNumber::List p = phoneNumbers();
1725 PhoneNumber::List::ConstIterator it2; 1725 PhoneNumber::List::ConstIterator it2;
1726 for( it2 = p.begin(); it2 != p.end(); ++it2 ) { 1726 for( it2 = p.begin(); it2 != p.end(); ++it2 ) {
1727 kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl; 1727 kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl;
1728 } 1728 }
1729 kdDebug(5700) << " }" << endl; 1729 kdDebug(5700) << " }" << endl;
1730 1730
1731 Address::List a = addresses(); 1731 Address::List a = addresses();
1732 Address::List::ConstIterator it3; 1732 Address::List::ConstIterator it3;
1733 for( it3 = a.begin(); it3 != a.end(); ++it3 ) { 1733 for( it3 = a.begin(); it3 != a.end(); ++it3 ) {
1734 (*it3).dump(); 1734 (*it3).dump();
1735 } 1735 }
1736 1736
1737 kdDebug(5700) << " Keys {" << endl; 1737 kdDebug(5700) << " Keys {" << endl;
1738 Key::List k = keys(); 1738 Key::List k = keys();
1739 Key::List::ConstIterator it4; 1739 Key::List::ConstIterator it4;
1740 for( it4 = k.begin(); it4 != k.end(); ++it4 ) { 1740 for( it4 = k.begin(); it4 != k.end(); ++it4 ) {
1741 kdDebug(5700) << " Type: " << int((*it4).type()) << 1741 kdDebug(5700) << " Type: " << int((*it4).type()) <<
1742 " Key: " << (*it4).textData() << 1742 " Key: " << (*it4).textData() <<
1743 " CustomString: " << (*it4).customTypeString() << endl; 1743 " CustomString: " << (*it4).customTypeString() << endl;
1744 } 1744 }
1745 kdDebug(5700) << " }" << endl; 1745 kdDebug(5700) << " }" << endl;
1746 1746
1747 kdDebug(5700) << "}" << endl; 1747 kdDebug(5700) << "}" << endl;
1748} 1748}
1749 1749
1750 1750
1751void Addressee::insertAddress( const Address &address ) 1751void Addressee::insertAddress( const Address &address )
1752{ 1752{
1753 detach(); 1753 detach();
1754 mData->empty = false; 1754 mData->empty = false;
1755 1755
1756 Address::List::Iterator it; 1756 Address::List::Iterator it;
1757 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1757 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1758 if ( (*it).id() == address.id() ) { 1758 if ( (*it).id() == address.id() ) {
1759 *it = address; 1759 *it = address;
1760 return; 1760 return;
1761 } 1761 }
1762 } 1762 }
1763 mData->addresses.append( address ); 1763 mData->addresses.append( address );
1764} 1764}
1765 1765
1766void Addressee::removeAddress( const Address &address ) 1766void Addressee::removeAddress( const Address &address )
1767{ 1767{
1768 detach(); 1768 detach();
1769 1769
1770 Address::List::Iterator it; 1770 Address::List::Iterator it;
1771 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1771 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1772 if ( (*it).id() == address.id() ) { 1772 if ( (*it).id() == address.id() ) {
1773 mData->addresses.remove( it ); 1773 mData->addresses.remove( it );
1774 return; 1774 return;
1775 } 1775 }
1776 } 1776 }
1777} 1777}
1778 1778
1779Address Addressee::address( int type ) const 1779Address Addressee::address( int type ) const
1780{ 1780{
1781 Address address( type ); 1781 Address address( type );
1782 Address::List::ConstIterator it; 1782 Address::List::ConstIterator it;
1783 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1783 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1784 if ( matchBinaryPatternA( (*it).type(), type ) ) { 1784 if ( matchBinaryPatternA( (*it).type(), type ) ) {
1785 if ( (*it).type() & Address::Pref ) 1785 if ( (*it).type() & Address::Pref )
1786 return (*it); 1786 return (*it);
1787 else if ( address.isEmpty() ) 1787 else if ( address.isEmpty() )
1788 address = (*it); 1788 address = (*it);
1789 } 1789 }
1790 } 1790 }
1791 1791
1792 return address; 1792 return address;
1793} 1793}
1794 1794
1795Address::List Addressee::addresses() const 1795Address::List Addressee::addresses() const
1796{ 1796{
1797 return mData->addresses; 1797 return mData->addresses;
1798} 1798}
1799 1799
1800Address::List Addressee::addresses( int type ) const 1800Address::List Addressee::addresses( int type ) const
1801{ 1801{
1802 Address::List list; 1802 Address::List list;
1803 1803
1804 Address::List::ConstIterator it; 1804 Address::List::ConstIterator it;
1805 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1805 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1806 if ( matchBinaryPattern( (*it).type(), type ) ) { 1806 if ( matchBinaryPattern( (*it).type(), type ) ) {
1807 list.append( *it ); 1807 list.append( *it );
1808 } 1808 }
1809 } 1809 }
1810 1810
1811 return list; 1811 return list;
1812} 1812}
1813 1813
1814Address Addressee::findAddress( const QString &id ) const 1814Address Addressee::findAddress( const QString &id ) const
1815{ 1815{
1816 Address::List::ConstIterator it; 1816 Address::List::ConstIterator it;
1817 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1817 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1818 if ( (*it).id() == id ) { 1818 if ( (*it).id() == id ) {
1819 return *it; 1819 return *it;
1820 } 1820 }
1821 } 1821 }
1822 return Address(); 1822 return Address();
1823} 1823}
1824 1824
1825void Addressee::insertCategory( const QString &c ) 1825void Addressee::insertCategory( const QString &c )
1826{ 1826{
1827 detach(); 1827 detach();
1828 mData->empty = false; 1828 mData->empty = false;
1829 1829
1830 if ( mData->categories.contains( c ) ) return; 1830 if ( mData->categories.contains( c ) ) return;
1831 1831
1832 mData->categories.append( c ); 1832 mData->categories.append( c );
1833} 1833}
1834 1834
1835void Addressee::removeCategory( const QString &c ) 1835void Addressee::removeCategory( const QString &c )
1836{ 1836{
1837 detach(); 1837 detach();
1838 1838
1839 QStringList::Iterator it = mData->categories.find( c ); 1839 QStringList::Iterator it = mData->categories.find( c );
1840 if ( it == mData->categories.end() ) return; 1840 if ( it == mData->categories.end() ) return;
1841 1841
1842 mData->categories.remove( it ); 1842 mData->categories.remove( it );
1843} 1843}
1844 1844
1845bool Addressee::hasCategory( const QString &c ) const 1845bool Addressee::hasCategory( const QString &c ) const
1846{ 1846{
1847 return ( mData->categories.contains( c ) ); 1847 return ( mData->categories.contains( c ) );
1848} 1848}
1849 1849
1850void Addressee::setCategories( const QStringList &c ) 1850void Addressee::setCategories( const QStringList &c )
1851{ 1851{
1852 detach(); 1852 detach();
1853 mData->empty = false; 1853 mData->empty = false;
1854 1854
1855 mData->categories = c; 1855 mData->categories = c;
1856} 1856}
1857 1857
1858QStringList Addressee::categories() const 1858QStringList Addressee::categories() const
1859{ 1859{
1860 return mData->categories; 1860 return mData->categories;
1861} 1861}
1862 1862
1863void Addressee::insertCustom( const QString &app, const QString &name, 1863void Addressee::insertCustom( const QString &app, const QString &name,
1864 const QString &value ) 1864 const QString &value )
1865{ 1865{
1866 if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return; 1866 if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return;
1867 1867
1868 detach(); 1868 detach();
1869 mData->empty = false; 1869 mData->empty = false;
1870 1870
1871 QString qualifiedName = app + "-" + name + ":"; 1871 QString qualifiedName = app + "-" + name + ":";
1872 1872
1873 QStringList::Iterator it; 1873 QStringList::Iterator it;
1874 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1874 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1875 if ( (*it).startsWith( qualifiedName ) ) { 1875 if ( (*it).startsWith( qualifiedName ) ) {
1876 (*it) = qualifiedName + value; 1876 (*it) = qualifiedName + value;
1877 return; 1877 return;
1878 } 1878 }
1879 } 1879 }
1880 mData->custom.append( qualifiedName + value ); 1880 mData->custom.append( qualifiedName + value );
1881} 1881}
1882 1882
1883void Addressee::removeCustom( const QString &app, const QString &name) 1883void Addressee::removeCustom( const QString &app, const QString &name)
1884{ 1884{
1885 detach(); 1885 detach();
1886 1886
1887 QString qualifiedName = app + "-" + name + ":"; 1887 QString qualifiedName = app + "-" + name + ":";
1888 1888
1889 QStringList::Iterator it; 1889 QStringList::Iterator it;
1890 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1890 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1891 if ( (*it).startsWith( qualifiedName ) ) { 1891 if ( (*it).startsWith( qualifiedName ) ) {
1892 mData->custom.remove( it ); 1892 mData->custom.remove( it );
1893 return; 1893 return;
1894 } 1894 }
1895 } 1895 }
1896} 1896}
1897 1897
1898QString Addressee::custom( const QString &app, const QString &name ) const 1898QString Addressee::custom( const QString &app, const QString &name ) const
1899{ 1899{
1900 QString qualifiedName = app + "-" + name + ":"; 1900 QString qualifiedName = app + "-" + name + ":";
1901 QString value; 1901 QString value;
1902 1902
1903 QStringList::ConstIterator it; 1903 QStringList::ConstIterator it;
1904 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1904 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1905 if ( (*it).startsWith( qualifiedName ) ) { 1905 if ( (*it).startsWith( qualifiedName ) ) {
1906 value = (*it).mid( (*it).find( ":" ) + 1 ); 1906 value = (*it).mid( (*it).find( ":" ) + 1 );
1907 break; 1907 break;
1908 } 1908 }
1909 } 1909 }
1910 1910
1911 return value; 1911 return value;
1912} 1912}
1913 1913
1914void Addressee::setCustoms( const QStringList &l ) 1914void Addressee::setCustoms( const QStringList &l )
1915{ 1915{
1916 detach(); 1916 detach();
1917 mData->empty = false; 1917 mData->empty = false;
1918 1918
1919 mData->custom = l; 1919 mData->custom = l;
1920} 1920}
1921 1921
1922QStringList Addressee::customs() const 1922QStringList Addressee::customs() const
1923{ 1923{
1924 return mData->custom; 1924 return mData->custom;
1925} 1925}
1926 1926
1927void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName, 1927void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName,
1928 QString &email) 1928 QString &email)
1929{ 1929{
1930 int startPos, endPos, len; 1930 int startPos, endPos, len;
1931 QString partA, partB, result; 1931 QString partA, partB, result;
1932 char endCh = '>'; 1932 char endCh = '>';
1933 1933
1934 startPos = rawEmail.find('<'); 1934 startPos = rawEmail.find('<');
1935 if (startPos < 0) 1935 if (startPos < 0)
1936 { 1936 {
1937 startPos = rawEmail.find('('); 1937 startPos = rawEmail.find('(');
1938 endCh = ')'; 1938 endCh = ')';
1939 } 1939 }
1940 if (startPos < 0) 1940 if (startPos < 0)
1941 { 1941 {
1942 // We couldn't find any separators, so we assume the whole string 1942 // We couldn't find any separators, so we assume the whole string
1943 // is the email address 1943 // is the email address
1944 email = rawEmail; 1944 email = rawEmail;
1945 fullName = ""; 1945 fullName = "";
1946 } 1946 }
1947 else 1947 else
1948 { 1948 {
1949 // We have a start position, try to find an end 1949 // We have a start position, try to find an end
1950 endPos = rawEmail.find(endCh, startPos+1); 1950 endPos = rawEmail.find(endCh, startPos+1);
1951 1951
1952 if (endPos < 0) 1952 if (endPos < 0)
1953 { 1953 {
1954 // We couldn't find the end of the email address. We can only 1954 // We couldn't find the end of the email address. We can only
1955 // assume the entire string is the email address. 1955 // assume the entire string is the email address.
1956 email = rawEmail; 1956 email = rawEmail;
1957 fullName = ""; 1957 fullName = "";
1958 } 1958 }
1959 else 1959 else
1960 { 1960 {
1961 // We have a start and end to the email address 1961 // We have a start and end to the email address
1962 1962
1963 // Grab the name part 1963 // Grab the name part
1964 fullName = rawEmail.left(startPos).stripWhiteSpace(); 1964 fullName = rawEmail.left(startPos).stripWhiteSpace();
1965 1965
1966 // grab the email part 1966 // grab the email part
1967 email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace(); 1967 email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace();
1968 1968
1969 // Check that we do not have any extra characters on the end of the 1969 // Check that we do not have any extra characters on the end of the
1970 // strings 1970 // strings
1971 len = fullName.length(); 1971 len = fullName.length();
1972 if (fullName[0]=='"' && fullName[len-1]=='"') 1972 if (fullName[0]=='"' && fullName[len-1]=='"')
1973 fullName = fullName.mid(1, len-2); 1973 fullName = fullName.mid(1, len-2);
1974 else if (fullName[0]=='<' && fullName[len-1]=='>') 1974 else if (fullName[0]=='<' && fullName[len-1]=='>')
1975 fullName = fullName.mid(1, len-2); 1975 fullName = fullName.mid(1, len-2);
1976 else if (fullName[0]=='(' && fullName[len-1]==')') 1976 else if (fullName[0]=='(' && fullName[len-1]==')')
1977 fullName = fullName.mid(1, len-2); 1977 fullName = fullName.mid(1, len-2);
1978 } 1978 }
1979 } 1979 }
1980} 1980}
1981 1981
1982void Addressee::setResource( Resource *resource ) 1982void Addressee::setResource( Resource *resource )
1983{ 1983{
1984 detach(); 1984 detach();
1985 mData->resource = resource; 1985 mData->resource = resource;
1986} 1986}
1987 1987
1988Resource *Addressee::resource() const 1988Resource *Addressee::resource() const
1989{ 1989{
1990 return mData->resource; 1990 return mData->resource;
1991} 1991}
1992 1992
1993//US 1993//US
1994QString Addressee::resourceLabel() 1994QString Addressee::resourceLabel()
1995{ 1995{
1996 return i18n("Resource"); 1996 return i18n("Resource");
1997} 1997}
1998 1998
1999void Addressee::setChanged( bool value ) 1999void Addressee::setChanged( bool value )
2000{ 2000{
2001 detach(); 2001 detach();
2002 mData->changed = value; 2002 mData->changed = value;
2003} 2003}
2004 2004
2005bool Addressee::changed() const 2005bool Addressee::changed() const
2006{ 2006{
2007 return mData->changed; 2007 return mData->changed;
2008} 2008}
2009 2009
2010void Addressee::setTagged( bool value ) 2010void Addressee::setTagged( bool value )
2011{ 2011{
2012 detach(); 2012 detach();
2013 mData->tagged = value; 2013 mData->tagged = value;
2014} 2014}
2015 2015
2016bool Addressee::tagged() const 2016bool Addressee::tagged() const
2017{ 2017{
2018 return mData->tagged; 2018 return mData->tagged;
2019} 2019}
2020 2020
2021QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) 2021QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a )
2022{ 2022{
2023 if (!a.mData) return s; 2023 if (!a.mData) return s;
2024 2024
2025 s << a.uid(); 2025 s << a.uid();
2026 2026
2027 s << a.mData->name; 2027 s << a.mData->name;
2028 s << a.mData->formattedName; 2028 s << a.mData->formattedName;
2029 s << a.mData->familyName; 2029 s << a.mData->familyName;
2030 s << a.mData->givenName; 2030 s << a.mData->givenName;
2031 s << a.mData->additionalName; 2031 s << a.mData->additionalName;
2032 s << a.mData->prefix; 2032 s << a.mData->prefix;
2033 s << a.mData->suffix; 2033 s << a.mData->suffix;
2034 s << a.mData->nickName; 2034 s << a.mData->nickName;
2035 s << a.mData->birthday; 2035 s << a.mData->birthday;
2036 s << a.mData->mailer; 2036 s << a.mData->mailer;
2037 s << a.mData->timeZone; 2037 s << a.mData->timeZone;
2038 s << a.mData->geo; 2038 s << a.mData->geo;
2039 s << a.mData->title; 2039 s << a.mData->title;
2040 s << a.mData->role; 2040 s << a.mData->role;
2041 s << a.mData->organization; 2041 s << a.mData->organization;
2042 s << a.mData->note; 2042 s << a.mData->note;
2043 s << a.mData->productId; 2043 s << a.mData->productId;
2044 s << a.mData->revision; 2044 s << a.mData->revision;
2045 s << a.mData->sortString; 2045 s << a.mData->sortString;
2046 s << a.mData->url; 2046 s << a.mData->url;
2047 s << a.mData->secrecy; 2047 s << a.mData->secrecy;
2048 s << a.mData->logo; 2048 s << a.mData->logo;
2049 s << a.mData->photo; 2049 s << a.mData->photo;
2050 s << a.mData->sound; 2050 s << a.mData->sound;
2051 s << a.mData->agent; 2051 s << a.mData->agent;
2052 s << a.mData->phoneNumbers; 2052 s << a.mData->phoneNumbers;
2053 s << a.mData->addresses; 2053 s << a.mData->addresses;
2054 s << a.mData->emails; 2054 s << a.mData->emails;
2055 s << a.mData->categories; 2055 s << a.mData->categories;
2056 s << a.mData->custom; 2056 s << a.mData->custom;
2057 s << a.mData->keys; 2057 s << a.mData->keys;
2058 return s; 2058 return s;
2059} 2059}
2060 2060
2061QDataStream &KABC::operator>>( QDataStream &s, Addressee &a ) 2061QDataStream &KABC::operator>>( QDataStream &s, Addressee &a )
2062{ 2062{
2063 if (!a.mData) return s; 2063 if (!a.mData) return s;
2064 2064
2065 s >> a.mData->uid; 2065 s >> a.mData->uid;
2066 2066
2067 s >> a.mData->name; 2067 s >> a.mData->name;
2068 s >> a.mData->formattedName; 2068 s >> a.mData->formattedName;
2069 s >> a.mData->familyName; 2069 s >> a.mData->familyName;
2070 s >> a.mData->givenName; 2070 s >> a.mData->givenName;
2071 s >> a.mData->additionalName; 2071 s >> a.mData->additionalName;
2072 s >> a.mData->prefix; 2072 s >> a.mData->prefix;
2073 s >> a.mData->suffix; 2073 s >> a.mData->suffix;
2074 s >> a.mData->nickName; 2074 s >> a.mData->nickName;
2075 s >> a.mData->birthday; 2075 s >> a.mData->birthday;
2076 s >> a.mData->mailer; 2076 s >> a.mData->mailer;
2077 s >> a.mData->timeZone; 2077 s >> a.mData->timeZone;
2078 s >> a.mData->geo; 2078 s >> a.mData->geo;
2079 s >> a.mData->title; 2079 s >> a.mData->title;
2080 s >> a.mData->role; 2080 s >> a.mData->role;
2081 s >> a.mData->organization; 2081 s >> a.mData->organization;
2082 s >> a.mData->note; 2082 s >> a.mData->note;
2083 s >> a.mData->productId; 2083 s >> a.mData->productId;
2084 s >> a.mData->revision; 2084 s >> a.mData->revision;
2085 s >> a.mData->sortString; 2085 s >> a.mData->sortString;
2086 s >> a.mData->url; 2086 s >> a.mData->url;
2087 s >> a.mData->secrecy; 2087 s >> a.mData->secrecy;
2088 s >> a.mData->logo; 2088 s >> a.mData->logo;
2089 s >> a.mData->photo; 2089 s >> a.mData->photo;
2090 s >> a.mData->sound; 2090 s >> a.mData->sound;
2091 s >> a.mData->agent; 2091 s >> a.mData->agent;
2092 s >> a.mData->phoneNumbers; 2092 s >> a.mData->phoneNumbers;
2093 s >> a.mData->addresses; 2093 s >> a.mData->addresses;
2094 s >> a.mData->emails; 2094 s >> a.mData->emails;
2095 s >> a.mData->categories; 2095 s >> a.mData->categories;
2096 s >> a.mData->custom; 2096 s >> a.mData->custom;
2097 s >> a.mData->keys; 2097 s >> a.mData->keys;
2098 2098
2099 a.mData->empty = false; 2099 a.mData->empty = false;
2100 2100
2101 return s; 2101 return s;
2102} 2102}
2103bool matchBinaryPattern( int value, int pattern ) 2103bool matchBinaryPattern( int value, int pattern )
2104{ 2104{
2105 /** 2105 /**
2106 We want to match all telephonnumbers/addresses which have the bits in the 2106 We want to match all telephonnumbers/addresses which have the bits in the
2107 pattern set. More are allowed. 2107 pattern set. More are allowed.
2108 if pattern == 0 we have a special handling, then we want only those with 2108 if pattern == 0 we have a special handling, then we want only those with
2109 exactly no bit set. 2109 exactly no bit set.
2110 */ 2110 */
2111 if ( pattern == 0 ) 2111 if ( pattern == 0 )
2112 return ( value == 0 ); 2112 return ( value == 0 );
2113 else 2113 else
2114 return ( pattern == ( pattern & value ) ); 2114 return ( pattern == ( pattern & value ) );
2115} 2115}
2116 2116
2117bool matchBinaryPatternP( int value, int pattern ) 2117bool matchBinaryPatternP( int value, int pattern )
2118{ 2118{
2119 2119
2120 if ( pattern == 0 ) 2120 if ( pattern == 0 )
2121 return ( value == 0 ); 2121 return ( value == 0 );
2122 else 2122 else
2123 return ( (pattern |PhoneNumber::Pref ) == ( value |PhoneNumber::Pref ) ); 2123 return ( (pattern |PhoneNumber::Pref ) == ( value |PhoneNumber::Pref ) );
2124} 2124}
2125bool matchBinaryPatternA( int value, int pattern ) 2125bool matchBinaryPatternA( int value, int pattern )
2126{ 2126{
2127 2127
2128 if ( pattern == 0 ) 2128 if ( pattern == 0 )
2129 return ( value == 0 ); 2129 return ( value == 0 );
2130 else 2130 else
2131 return ( (pattern | Address::Pref) == ( value | Address::Pref ) ); 2131 return ( (pattern | Address::Pref) == ( value | Address::Pref ) );
2132} 2132}
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
index ba17c50..48b7d91 100644
--- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
+++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
@@ -1,406 +1,285 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library 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 GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#include <sys/types.h> 28#include <sys/types.h>
29#include <sys/stat.h> 29#include <sys/stat.h>
30#include <unistd.h> 30#include <unistd.h>
31 31
32#include <qdir.h> 32#include <qdir.h>
33#include <qfile.h> 33#include <qfile.h>
34#include <qfileinfo.h> 34#include <qfileinfo.h>
35#include <qregexp.h> 35#include <qregexp.h>
36//US #include <qtimer.h> 36//US #include <qtimer.h>
37 37
38#include <kapplication.h> 38#include <kapplication.h>
39#include <kconfig.h> 39#include <kconfig.h>
40#include <kdebug.h> 40#include <kdebug.h>
41#include <klocale.h> 41#include <klocale.h>
42//US #include <ksavefile.h> 42//US #include <ksavefile.h>
43#include <kstandarddirs.h> 43#include <kstandarddirs.h>
44#include <kmessagebox.h> 44#include <kmessagebox.h>
45 45
46#include <sl/slzdb.h> 46#include <sl/slzdb.h>
47 47
48#include <libkdepim/ksyncprofile.h> 48#include <libkdepim/ksyncprofile.h>
49 49
50#include "resourcesharpdtmconfig.h" 50#include "resourcesharpdtmconfig.h"
51#include "resourcesharpdtm.h" 51#include "resourcesharpdtm.h"
52 52
53#include "stdaddressbook.h" 53#include "stdaddressbook.h"
54 54
55#include "sharpdtmconverter.h" 55#include "sharpdtmconverter.h"
56//#define ALLOW_LOCKING 56//#define ALLOW_LOCKING
57using namespace KABC; 57using namespace KABC;
58extern "C" 58extern "C"
59{ 59{
60 void *init_microkabc_sharpdtm() 60 void *init_microkabc_sharpdtm()
61 { 61 {
62 return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig>(); 62 return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig>();
63 } 63 }
64} 64}
65 65
66ResourceSharpDTM::ResourceSharpDTM( const KConfig *config ) 66ResourceSharpDTM::ResourceSharpDTM( const KConfig *config )
67 : Resource( config ), mConverter (0) 67 : Resource( config ), mConverter (0)
68{ 68{
69 // we can not choose the filename. Therefore use the default to display 69 // we can not choose the filename. Therefore use the default to display
70 70 mAccess = 0;
71 QString fileName = SlZDataBase::addressbookFileName(); 71 QString fileName = SlZDataBase::addressbookFileName();
72 init( fileName ); 72 init( fileName );
73} 73}
74 74
75ResourceSharpDTM::ResourceSharpDTM( const QString &fileName ) 75ResourceSharpDTM::ResourceSharpDTM( const QString &fileName )
76 : Resource( 0 ) 76 : Resource( 0 )
77{ 77{
78 init( fileName ); 78 mAccess = 0;
79 init( fileName );
79} 80}
80 81
81void ResourceSharpDTM::init( const QString &fileName ) 82void ResourceSharpDTM::init( const QString &fileName )
82{ 83{
83
84 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
85 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
86 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
87
88 setFileName( fileName ); 84 setFileName( fileName );
89} 85}
90 86
91ResourceSharpDTM::~ResourceSharpDTM() 87ResourceSharpDTM::~ResourceSharpDTM()
92{ 88{
93 if (mConverter != 0) 89 if (mConverter != 0)
94 delete mConverter; 90 delete mConverter;
95 91
96 if(mAccess != 0) 92 if(mAccess != 0)
97 delete mAccess; 93 delete mAccess;
98} 94}
99 95
100void ResourceSharpDTM::writeConfig( KConfig *config ) 96void ResourceSharpDTM::writeConfig( KConfig *config )
101{ 97{
102 Resource::writeConfig( config ); 98 Resource::writeConfig( config );
103} 99}
104 100
105Ticket *ResourceSharpDTM::requestSaveTicket() 101Ticket *ResourceSharpDTM::requestSaveTicket()
106{ 102{
107
108 103
109 qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); 104 qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1());
110 105
111 if ( !addressBook() ) return 0; 106 if ( !addressBook() ) return 0;
112
113#ifdef ALLOW_LOCKING
114 if ( !lock( fileName() ) ) {
115 qDebug("ResourceSharpDTM::requestSaveTicket(): Unable to lock file ");
116 return 0;
117 }
118#endif
119 return createTicket( this ); 107 return createTicket( this );
120} 108}
121 109
122 110
123bool ResourceSharpDTM::doOpen() 111bool ResourceSharpDTM::doOpen()
124{ 112{
125 qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1()); 113 qDebug("%xResourceSharpDTM::doOpen: %s", this,fileName().latin1());
126
127 // the last parameter in the SlZDataBase constructor means "readonly"
128 mAccess = new SlZDataBase(fileName(),
129 SlZDataBase::addressbookItems(),
130 NULL, false);
131 114
132 if ( !mAccess ) { 115 if ( ! mAccess ) {
133 qDebug("Unable to load file() %s", fileName().latin1()); 116 // the last parameter in the SlZDataBase constructor means "readonly"
134 return false; 117 mAccess = new SlZDataBase(fileName(),
135 } 118 SlZDataBase::addressbookItems(),
136 119 NULL, false);
137 if (mConverter == 0)
138 {
139 mConverter = new SharpDTMConverter();
140 bool res = mConverter->init();
141 if ( !res )
142 {
143 QString msg("Unable to initialize sharp converter. Most likely a problem with the category file");
144
145 qDebug(msg);
146 delete mAccess;
147 mAccess = 0;
148 return false;
149 } 120 }
150 } 121 if ( !mAccess ) {
151 122 qDebug("Unable to load file() %s", fileName().latin1());
152 return true; 123 return false;
124 }
125 if (mConverter == 0) {
126 mConverter = new SharpDTMConverter();
127 bool res = mConverter->init();
128 if ( !res )
129 {
130 QString msg("Unable to initialize sharp converter. Most likely a problem with the category file");
131 qDebug(msg);
132 delete mAccess;
133 mAccess = 0;
134 return false;
135 }
136 }
137 return true;
153} 138}
154 139
155void ResourceSharpDTM::doClose() 140void ResourceSharpDTM::doClose()
156{ 141{
157 qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1());
158
159 if(mAccess)
160 {
161 delete mAccess;
162 mAccess = 0;
163 }
164 // it seems so, that deletion of access deletes backend as well
165 //delete backend;
166
167 return; 142 return;
168} 143}
169 144
170bool ResourceSharpDTM::load() 145bool ResourceSharpDTM::load()
171{ 146{
172 qDebug("ResourceSharpDTM::load: %s", fileName().latin1()); 147 qDebug("%xResourceSharpDTM::load: %s",this, fileName().latin1());
173 148 bool res = false;
174 bool res = false; 149 CardId id;
175 150 for (bool res=mAccess->first(); res == true; res=mAccess->next())
176 CardId id; 151 {
177 152 id = mAccess->cardId();
178 for (bool res=mAccess->first(); res == true; res=mAccess->next()) 153 KABC::Addressee addressee;
179 { 154 res = mConverter->sharpToAddressee( id, mAccess, addressee );
180 id = mAccess->cardId(); 155 if ( !addressee.isEmpty() && res )
181 156 {
182 KABC::Addressee addressee; 157 addressee.setResource( this );
183 158 addressBook()->insertAddressee( addressee );
184 res = mConverter->sharpToAddressee( id, mAccess, addressee ); 159 }
185 160 }
186 if ( !addressee.isEmpty() && res ) 161 return true;
187 {
188 addressee.setResource( this );
189 addressBook()->insertAddressee( addressee );
190 }
191 }
192
193 return true;
194} 162}
195 163
196bool ResourceSharpDTM::save( Ticket *ticket ) 164bool ResourceSharpDTM::save( Ticket *ticket )
197{ 165{
198 qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); 166 qDebug("ResourceSharpDTM::save: %s", fileName().latin1());
199
200 mDirWatch.stopScan();
201
202 KABC::AddressBook::Iterator it; 167 KABC::AddressBook::Iterator it;
203 bool res; 168 bool res;
204 KABC::Addressee::List changedAddressees; 169 KABC::Addressee::List changedAddressees;
205 typedef QMap<int,QString> AddresseeMap; 170 typedef QMap<int,QString> AddresseeMap;
206 AddresseeMap map; 171 AddresseeMap map;
207 CardId id ; 172 CardId id ;
208
209 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 173 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
210 174
211 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 175 if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
212 QString uid = (*it).originalExternalUID(); 176 QString uid = (*it).originalExternalUID();
213 bool res; 177 bool res;
214 if ( uid.isEmpty() ) 178 if ( uid.isEmpty() )
215 id = 0; 179 id = 0;
216 else 180 else
217 id = uid.toUInt(); 181 id = uid.toUInt();
218 KABC::Addressee addressee = (*it); 182 KABC::Addressee addressee = (*it);
219 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { 183 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) {
220 res = mAccess->startEditCard(id); 184 res = mAccess->startEditCard(id);
221 if (res == true) 185 if (res == true)
222 { 186 {
223 res = mConverter->addresseeToSharp( (*it), mAccess, id ); 187 res = mConverter->addresseeToSharp( (*it), mAccess, id );
224 if (res == true) 188 if (res == true)
225 { 189 {
226 res = mAccess->finishEditCard(&id); 190 res = mAccess->finishEditCard(&id);;
227 //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
228 //(*it).setExternalUID( QString::number( id ) );
229 //(*it).setOriginalExternalUID( QString::number( id ) );
230 map.insert(id,(*it).uid()); 191 map.insert(id,(*it).uid());
231 if (res == false) 192 if (res == false)
232 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); 193 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
233 194
234 } 195 }
235 else 196 else
236 { 197 {
237 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); 198 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1());
238 mAccess->cancelEditCard(); 199 mAccess->cancelEditCard();
239 } 200 }
240 } 201 }
241 202
242 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 203 } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
243 res = mAccess->deleteCard(&id); 204 res = mAccess->deleteCard(&id);
244 if ( !res ) 205 if ( !res )
245 qDebug("delete error "); 206 qDebug("delete error ");
246 207
247 208
248 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 209 } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
249 //changed 210 //changed
250 res = mAccess->startEditCard(id); 211 res = mAccess->startEditCard(id);
251 if (res == true) 212 if (res == true)
252 { 213 {
253 res = mConverter->addresseeToSharp( (*it), mAccess, id ); 214 res = mConverter->addresseeToSharp( (*it), mAccess, id );
254 if (res == true) 215 if (res == true)
255 { 216 {
256 res = mAccess->finishEditCard(&id); 217 res = mAccess->finishEditCard(&id);
257 //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM );
258 map.insert(id,(*it).uid()); 218 map.insert(id,(*it).uid());
259 if (res == false) 219 if (res == false)
260 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); 220 qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
261
262 } 221 }
263 else 222 else
264 { 223 {
265 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); 224 qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1());
266 mAccess->cancelEditCard(); 225 mAccess->cancelEditCard();
267 } 226 }
268 } 227 }
269 } 228 }
270 } 229 }
271 230
272 } 231 }
273 AddresseeMap::Iterator itam; 232 AddresseeMap::Iterator itam;
274 for ( res=mAccess->first(); res == true; res=mAccess->next()) 233 for ( res=mAccess->first(); res == true; res=mAccess->next())
275 { 234 {
276 id = mAccess->cardId(); 235 id = mAccess->cardId();
277 int idint = id; 236 int idint = id;
278 itam = map.find( idint ); 237 itam = map.find( idint );
279 if ( itam != map.end() ) { 238 if ( itam != map.end() ) {
280 KABC::Addressee addressee; 239 KABC::Addressee addressee;
281 res = mConverter->sharpToAddressee( id, mAccess, addressee ); 240 res = mConverter->sharpToAddressee( id, mAccess, addressee );
282 241
283 if ( !addressee.isEmpty() && res ) 242 if ( !addressee.isEmpty() && res )
284 { 243 {
285 addressee.setResource( this ); 244 addressee.setResource( this );
286 addressee.setUid( itam.data() ); 245 addressee.setUid( itam.data() );
287 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 246 addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
288 addressBook()->insertAddressee( addressee , false ); 247 addressBook()->insertAddressee( addressee , false );
289 } 248 }
290 } 249 }
291 } 250 }
292
293 //US mAccess->save();
294
295 mDirWatch.startScan();
296 delete ticket; 251 delete ticket;
297 unlock( fileName() );
298 252
299 return true; 253 return true;
300} 254}
301 255
302bool ResourceSharpDTM::lock( const QString &lockfileName ) 256bool ResourceSharpDTM::lock( const QString &lockfileName )
303{ 257{
304#ifdef ALLOW_LOCKING
305 qDebug("ResourceSharpDTM::lock: %s", fileName().latin1());
306
307 kdDebug(5700) << "ResourceSharpDTM::lock()" << endl;
308
309 QString fn = lockfileName;
310
311 KURL url(fn);
312 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
313
314 kdDebug(5700) << "-- lock name: " << lockName << endl;
315
316 if (QFile::exists( lockName ))
317 {
318 qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName());
319 return false;
320 }
321
322
323 QString lockUniqueName;
324 lockUniqueName = fn + KApplication::randomString( 8 );
325
326 url = lockUniqueName;
327//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
328 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
329 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
330
331 // Create unique file
332 QFile file( mLockUniqueName );
333 file.open( IO_WriteOnly );
334 file.close();
335
336 // Create lock file
337 int result = 0;
338#ifndef _WIN32_
339 result = ::link( QFile::encodeName( mLockUniqueName ),
340 QFile::encodeName( lockName ) );
341#endif
342 if ( result == 0 ) {
343 addressBook()->emitAddressBookLocked();
344 return true;
345 }
346
347 // TODO: check stat
348
349 return false;
350#else
351 return true;
352#endif
353} 258}
354 259
355void ResourceSharpDTM::unlock( const QString &fileName ) 260void ResourceSharpDTM::unlock( const QString &fileName )
356{ 261{
357#ifdef ALLOW_LOCKING
358 qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1());
359 262
360 QString fn = fileName;
361 KURL url(fn);
362 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
363
364 QFile::remove( lockName );
365 QFile::remove( mLockUniqueName );
366 addressBook()->emitAddressBookUnlocked();
367#endif
368} 263}
369 264
370void ResourceSharpDTM::setFileName( const QString &newFileName ) 265void ResourceSharpDTM::setFileName( const QString &newFileName )
371{ 266{
372 mDirWatch.stopScan(); 267 Resource::setFileName( newFileName );
373 mDirWatch.removeFile( fileName() );
374
375 Resource::setFileName( newFileName );
376
377 mDirWatch.addFile( fileName() );
378 mDirWatch.startScan();
379
380} 268}
381 269
382void ResourceSharpDTM::fileChanged() 270void ResourceSharpDTM::fileChanged()
383{ 271{
384 // There is a small theoretical chance that KDirWatch calls us before 272
385 // we are fully constructed
386 if (!addressBook())
387 return;
388
389 QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) );
390 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
391 load();
392 addressBook()->emitAddressBookChanged();
393 }
394} 273}
395 274
396void ResourceSharpDTM::removeAddressee( const Addressee &addr ) 275void ResourceSharpDTM::removeAddressee( const Addressee &addr )
397{ 276{
398} 277}
399 278
400void ResourceSharpDTM::cleanUp() 279void ResourceSharpDTM::cleanUp()
401{ 280{
402 unlock( fileName() ); 281 unlock( fileName() );
403} 282}
404 283
405 284
406 285
diff --git a/kabc/tmpaddressbook.cpp b/kabc/tmpaddressbook.cpp
index 6e24302..cfa57e3 100644
--- a/kabc/tmpaddressbook.cpp
+++ b/kabc/tmpaddressbook.cpp
@@ -1,56 +1,49 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library 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 GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27#include <qptrlist.h> 27#include <qptrlist.h>
28 28
29#include "tmpaddressbook.h" 29#include "tmpaddressbook.h"
30 30
31using namespace KABC; 31using namespace KABC;
32 32
33#include "resource.h" 33#include "resource.h"
34 34
35TmpAddressBook::TmpAddressBook() 35TmpAddressBook::TmpAddressBook()
36 : AddressBook(0, "tmpcontact") 36 : AddressBook(0, "tmpcontact")
37{ 37{
38} 38}
39 39
40TmpAddressBook::TmpAddressBook( const QString &config ) 40TmpAddressBook::TmpAddressBook( const QString &config )
41 : AddressBook( config, "tmpcontact" ) 41 : AddressBook( config, "tmpcontact" )
42{ 42{
43} 43}
44 44
45TmpAddressBook::~TmpAddressBook() 45TmpAddressBook::~TmpAddressBook()
46{ 46{
47 //remove all possible resources. This should cleanup the configfile. 47 removeResources();
48 QPtrList<KABC::Resource> mResources = resources();
49
50 QPtrListIterator<KABC::Resource> it(mResources);
51 for ( ; it.current(); ++it ) {
52 KABC::Resource *res = it.current();
53 removeResource(res);
54 }
55} 48}
56 49
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 6e482b5..e6bdde9 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -197,2776 +197,2779 @@ class KAex2phonePrefs : public QDialog
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
207 207
208bool pasteWithNewUid = true; 208bool pasteWithNewUid = true;
209 209
210#ifdef KAB_EMBEDDED 210#ifdef KAB_EMBEDDED
211KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) 211KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name )
212 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), 212 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ),
213 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/ 213 mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/
214 mReadWrite( readWrite ), mModified( false ), mMainWindow(client) 214 mReadWrite( readWrite ), mModified( false ), mMainWindow(client)
215#else //KAB_EMBEDDED 215#else //KAB_EMBEDDED
216KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name ) 216KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name )
217 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ), 217 : QWidget( parent, name ), KSyncInterface(), mGUIClient( client ), mViewManager( 0 ),
218 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), 218 mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ),
219 mReadWrite( readWrite ), mModified( false ) 219 mReadWrite( readWrite ), mModified( false )
220#endif //KAB_EMBEDDED 220#endif //KAB_EMBEDDED
221{ 221{
222 // syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); 222 // syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu);
223 // syncManager->setBlockSave(false); 223 // syncManager->setBlockSave(false);
224 mExtensionBarSplitter = 0; 224 mExtensionBarSplitter = 0;
225 mIsPart = !parent->inherits( "KAddressBookMain" ); 225 mIsPart = !parent->inherits( "KAddressBookMain" );
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 connect( ExternalAppHandler::instance(), SIGNAL (nextView()),this, SLOT(setDetailsToggle())); 297 connect( ExternalAppHandler::instance(), SIGNAL (nextView()),this, SLOT(setDetailsToggle()));
298 298
299 299
300#ifndef KAB_EMBEDDED 300#ifndef KAB_EMBEDDED
301 connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ), 301 connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ),
302 mXXPortManager, SLOT( importVCard( const KURL& ) ) ); 302 mXXPortManager, SLOT( importVCard( const KURL& ) ) );
303 303
304 connect( mDetails, SIGNAL( browse( const QString& ) ), 304 connect( mDetails, SIGNAL( browse( const QString& ) ),
305 SLOT( browse( const QString& ) ) ); 305 SLOT( browse( const QString& ) ) );
306 306
307 307
308 mAddressBookService = new KAddressBookService( this ); 308 mAddressBookService = new KAddressBookService( this );
309 309
310#endif //KAB_EMBEDDED 310#endif //KAB_EMBEDDED
311 311
312 mMessageTimer = new QTimer( this ); 312 mMessageTimer = new QTimer( this );
313 connect( mMessageTimer, SIGNAL( timeout() ), this, SLOT( setCaptionBack() ) ); 313 connect( mMessageTimer, SIGNAL( timeout() ), this, SLOT( setCaptionBack() ) );
314 mEditorDialog = 0; 314 mEditorDialog = 0;
315 createAddresseeEditorDialog( this ); 315 createAddresseeEditorDialog( this );
316 setModified( false ); 316 setModified( false );
317 mBRdisabled = false; 317 mBRdisabled = false;
318#ifndef DESKTOP_VERSION 318#ifndef DESKTOP_VERSION
319 infrared = 0; 319 infrared = 0;
320#endif 320#endif
321 //toggleBeamReceive( ); 321 //toggleBeamReceive( );
322} 322}
323 323
324KABCore::~KABCore() 324KABCore::~KABCore()
325{ 325{
326 // save(); 326 // save();
327 //saveSettings(); 327 //saveSettings();
328 //KABPrefs::instance()->writeConfig(); 328 //KABPrefs::instance()->writeConfig();
329 delete AddresseeConfig::instance(); 329 delete AddresseeConfig::instance();
330 mAddressBook = 0; 330 mAddressBook = 0;
331 KABC::StdAddressBook::close(); 331 KABC::StdAddressBook::close();
332 332
333 delete syncManager; 333 delete syncManager;
334#ifndef DESKTOP_VERSION 334#ifndef DESKTOP_VERSION
335 if ( infrared ) 335 if ( infrared )
336 delete infrared; 336 delete infrared;
337#endif 337#endif
338} 338}
339void KABCore::receive( const QCString& cmsg, const QByteArray& data ) 339void KABCore::receive( const QCString& cmsg, const QByteArray& data )
340{ 340{
341 qDebug("KA: QCOP message received: %s ", cmsg.data() ); 341 qDebug("KA: QCOP message received: %s ", cmsg.data() );
342 if ( cmsg == "setDocument(QString)" ) { 342 if ( cmsg == "setDocument(QString)" ) {
343 QDataStream stream( data, IO_ReadOnly ); 343 QDataStream stream( data, IO_ReadOnly );
344 QString fileName; 344 QString fileName;
345 stream >> fileName; 345 stream >> fileName;
346 recieve( fileName ); 346 recieve( fileName );
347 return; 347 return;
348 } 348 }
349} 349}
350void KABCore::toggleBeamReceive( ) 350void KABCore::toggleBeamReceive( )
351{ 351{
352 if ( mBRdisabled ) 352 if ( mBRdisabled )
353 return; 353 return;
354#ifndef DESKTOP_VERSION 354#ifndef DESKTOP_VERSION
355 if ( infrared ) { 355 if ( infrared ) {
356 qDebug("AB disable BeamReceive "); 356 qDebug("AB disable BeamReceive ");
357 delete infrared; 357 delete infrared;
358 infrared = 0; 358 infrared = 0;
359 mActionBR->setChecked(false); 359 mActionBR->setChecked(false);
360 return; 360 return;
361 } 361 }
362 qDebug("AB enable BeamReceive "); 362 qDebug("AB enable BeamReceive ");
363 mActionBR->setChecked(true); 363 mActionBR->setChecked(true);
364 364
365 infrared = new QCopChannel("QPE/Application/addressbook",this, "channelAB" ) ; 365 infrared = new QCopChannel("QPE/Application/addressbook",this, "channelAB" ) ;
366 QObject::connect( infrared, SIGNAL (received ( const QCString &, const QByteArray & )),this, SLOT(receive( const QCString&, const QByteArray& ))); 366 QObject::connect( infrared, SIGNAL (received ( const QCString &, const QByteArray & )),this, SLOT(receive( const QCString&, const QByteArray& )));
367#endif 367#endif
368} 368}
369 369
370 370
371void KABCore::disableBR(bool b) 371void KABCore::disableBR(bool b)
372{ 372{
373#ifndef DESKTOP_VERSION 373#ifndef DESKTOP_VERSION
374 if ( b ) { 374 if ( b ) {
375 if ( infrared ) { 375 if ( infrared ) {
376 toggleBeamReceive( ); 376 toggleBeamReceive( );
377 } 377 }
378 mBRdisabled = true; 378 mBRdisabled = true;
379 } else { 379 } else {
380 if ( mBRdisabled ) { 380 if ( mBRdisabled ) {
381 mBRdisabled = false; 381 mBRdisabled = false;
382 //toggleBeamReceive( ); 382 //toggleBeamReceive( );
383 } 383 }
384 } 384 }
385#endif 385#endif
386 386
387} 387}
388void KABCore::recieve( QString fn ) 388void KABCore::recieve( QString fn )
389{ 389{
390 //qDebug("KABCore::recieve "); 390 //qDebug("KABCore::recieve ");
391 int count = mAddressBook->importFromFile( fn, true ); 391 int count = mAddressBook->importFromFile( fn, true );
392 if ( count ) 392 if ( count )
393 setModified( true ); 393 setModified( true );
394 mViewManager->refreshView(); 394 mViewManager->refreshView();
395 message(i18n("%1 contact(s) received!").arg( count )); 395 message(i18n("%1 contact(s) received!").arg( count ));
396 topLevelWidget()->showMaximized(); 396 topLevelWidget()->showMaximized();
397 topLevelWidget()->raise(); 397 topLevelWidget()->raise();
398} 398}
399void KABCore::restoreSettings() 399void KABCore::restoreSettings()
400{ 400{
401 mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce; 401 mMultipleViewsAtOnce = KABPrefs::instance()->mMultipleViewsAtOnce;
402 402
403 bool state; 403 bool state;
404 404
405 if (mMultipleViewsAtOnce) 405 if (mMultipleViewsAtOnce)
406 state = KABPrefs::instance()->mDetailsPageVisible; 406 state = KABPrefs::instance()->mDetailsPageVisible;
407 else 407 else
408 state = false; 408 state = false;
409 409
410 mActionDetails->setChecked( state ); 410 mActionDetails->setChecked( state );
411 setDetailsVisible( state ); 411 setDetailsVisible( state );
412 412
413 state = KABPrefs::instance()->mJumpButtonBarVisible; 413 state = KABPrefs::instance()->mJumpButtonBarVisible;
414 414
415 mActionJumpBar->setChecked( state ); 415 mActionJumpBar->setChecked( state );
416 setJumpButtonBarVisible( state ); 416 setJumpButtonBarVisible( state );
417/*US 417/*US
418 QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter; 418 QValueList<int> splitterSize = KABPrefs::instance()->mDetailsSplitter;
419 if ( splitterSize.count() == 0 ) { 419 if ( splitterSize.count() == 0 ) {
420 splitterSize.append( width() / 2 ); 420 splitterSize.append( width() / 2 );
421 splitterSize.append( width() / 2 ); 421 splitterSize.append( width() / 2 );
422 } 422 }
423 mMiniSplitter->setSizes( splitterSize ); 423 mMiniSplitter->setSizes( splitterSize );
424 if ( mExtensionBarSplitter ) { 424 if ( mExtensionBarSplitter ) {
425 splitterSize = KABPrefs::instance()->mExtensionsSplitter; 425 splitterSize = KABPrefs::instance()->mExtensionsSplitter;
426 if ( splitterSize.count() == 0 ) { 426 if ( splitterSize.count() == 0 ) {
427 splitterSize.append( width() / 2 ); 427 splitterSize.append( width() / 2 );
428 splitterSize.append( width() / 2 ); 428 splitterSize.append( width() / 2 );
429 } 429 }
430 mExtensionBarSplitter->setSizes( splitterSize ); 430 mExtensionBarSplitter->setSizes( splitterSize );
431 431
432 } 432 }
433*/ 433*/
434 mViewManager->restoreSettings(); 434 mViewManager->restoreSettings();
435 mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField ); 435 mIncSearchWidget->setCurrentItem( KABPrefs::instance()->mCurrentIncSearchField );
436 mExtensionManager->restoreSettings(); 436 mExtensionManager->restoreSettings();
437#ifdef DESKTOP_VERSION 437#ifdef DESKTOP_VERSION
438 int wid = width(); 438 int wid = width();
439 if ( wid < 10 ) 439 if ( wid < 10 )
440 wid = 400; 440 wid = 400;
441#else 441#else
442 int wid = QApplication::desktop()->width(); 442 int wid = QApplication::desktop()->width();
443 if ( wid < 640 ) 443 if ( wid < 640 )
444 wid = QApplication::desktop()->height(); 444 wid = QApplication::desktop()->height();
445#endif 445#endif
446 QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter; 446 QValueList<int> splitterSize;// = KABPrefs::instance()->mDetailsSplitter;
447 if ( true /*splitterSize.count() == 0*/ ) { 447 if ( true /*splitterSize.count() == 0*/ ) {
448 splitterSize.append( wid / 2 ); 448 splitterSize.append( wid / 2 );
449 splitterSize.append( wid / 2 ); 449 splitterSize.append( wid / 2 );
450 } 450 }
451 mMiniSplitter->setSizes( splitterSize ); 451 mMiniSplitter->setSizes( splitterSize );
452 if ( mExtensionBarSplitter ) { 452 if ( mExtensionBarSplitter ) {
453 //splitterSize = KABPrefs::instance()->mExtensionsSplitter; 453 //splitterSize = KABPrefs::instance()->mExtensionsSplitter;
454 if ( true /*splitterSize.count() == 0*/ ) { 454 if ( true /*splitterSize.count() == 0*/ ) {
455 splitterSize.append( wid / 2 ); 455 splitterSize.append( wid / 2 );
456 splitterSize.append( wid / 2 ); 456 splitterSize.append( wid / 2 );
457 } 457 }
458 mExtensionBarSplitter->setSizes( splitterSize ); 458 mExtensionBarSplitter->setSizes( splitterSize );
459 459
460 } 460 }
461 461
462 462
463} 463}
464 464
465void KABCore::saveSettings() 465void KABCore::saveSettings()
466{ 466{
467 KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked(); 467 KABPrefs::instance()->mJumpButtonBarVisible = mActionJumpBar->isChecked();
468 if ( mExtensionBarSplitter ) 468 if ( mExtensionBarSplitter )
469 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); 469 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
470 KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked(); 470 KABPrefs::instance()->mDetailsPageVisible = mActionDetails->isChecked();
471 KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes(); 471 KABPrefs::instance()->mDetailsSplitter = mMiniSplitter->sizes();
472#ifndef KAB_EMBEDDED 472#ifndef KAB_EMBEDDED
473 473
474 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes(); 474 KABPrefs::instance()->mExtensionsSplitter = mExtensionBarSplitter->sizes();
475 KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes(); 475 KABPrefs::instance()->mDetailsSplitter = mDetailsSplitter->sizes();
476#endif //KAB_EMBEDDED 476#endif //KAB_EMBEDDED
477 mExtensionManager->saveSettings(); 477 mExtensionManager->saveSettings();
478 mViewManager->saveSettings(); 478 mViewManager->saveSettings();
479 479
480 KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem(); 480 KABPrefs::instance()->mCurrentIncSearchField = mIncSearchWidget->currentItem();
481} 481}
482 482
483KABC::AddressBook *KABCore::addressBook() const 483KABC::AddressBook *KABCore::addressBook() const
484{ 484{
485 return mAddressBook; 485 return mAddressBook;
486} 486}
487 487
488KConfig *KABCore::config() 488KConfig *KABCore::config()
489{ 489{
490#ifndef KAB_EMBEDDED 490#ifndef KAB_EMBEDDED
491 return KABPrefs::instance()->config(); 491 return KABPrefs::instance()->config();
492#else //KAB_EMBEDDED 492#else //KAB_EMBEDDED
493 return KABPrefs::instance()->getConfig(); 493 return KABPrefs::instance()->getConfig();
494#endif //KAB_EMBEDDED 494#endif //KAB_EMBEDDED
495} 495}
496 496
497KActionCollection *KABCore::actionCollection() const 497KActionCollection *KABCore::actionCollection() const
498{ 498{
499 return mGUIClient->actionCollection(); 499 return mGUIClient->actionCollection();
500} 500}
501 501
502KABC::Field *KABCore::currentSearchField() const 502KABC::Field *KABCore::currentSearchField() const
503{ 503{
504 if (mIncSearchWidget) 504 if (mIncSearchWidget)
505 return mIncSearchWidget->currentField(); 505 return mIncSearchWidget->currentField();
506 else 506 else
507 return 0; 507 return 0;
508} 508}
509 509
510QStringList KABCore::selectedUIDs() const 510QStringList KABCore::selectedUIDs() const
511{ 511{
512 return mViewManager->selectedUids(); 512 return mViewManager->selectedUids();
513} 513}
514 514
515KABC::Resource *KABCore::requestResource( QWidget *parent ) 515KABC::Resource *KABCore::requestResource( QWidget *parent )
516{ 516{
517 QPtrList<KABC::Resource> kabcResources = addressBook()->resources(); 517 QPtrList<KABC::Resource> kabcResources = addressBook()->resources();
518 518
519 QPtrList<KRES::Resource> kresResources; 519 QPtrList<KRES::Resource> kresResources;
520 QPtrListIterator<KABC::Resource> resIt( kabcResources ); 520 QPtrListIterator<KABC::Resource> resIt( kabcResources );
521 KABC::Resource *resource; 521 KABC::Resource *resource;
522 while ( ( resource = resIt.current() ) != 0 ) { 522 while ( ( resource = resIt.current() ) != 0 ) {
523 ++resIt; 523 ++resIt;
524 if ( !resource->readOnly() ) { 524 if ( !resource->readOnly() ) {
525 KRES::Resource *res = static_cast<KRES::Resource*>( resource ); 525 KRES::Resource *res = static_cast<KRES::Resource*>( resource );
526 if ( res ) 526 if ( res )
527 kresResources.append( res ); 527 kresResources.append( res );
528 } 528 }
529 } 529 }
530 530
531 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent ); 531 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent );
532 return static_cast<KABC::Resource*>( res ); 532 return static_cast<KABC::Resource*>( res );
533} 533}
534 534
535#ifndef KAB_EMBEDDED 535#ifndef KAB_EMBEDDED
536KAboutData *KABCore::createAboutData() 536KAboutData *KABCore::createAboutData()
537#else //KAB_EMBEDDED 537#else //KAB_EMBEDDED
538void KABCore::createAboutData() 538void KABCore::createAboutData()
539#endif //KAB_EMBEDDED 539#endif //KAB_EMBEDDED
540{ 540{
541#ifndef KAB_EMBEDDED 541#ifndef KAB_EMBEDDED
542 KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ), 542 KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ),
543 "3.1", I18N_NOOP( "The KDE Address Book" ), 543 "3.1", I18N_NOOP( "The KDE Address Book" ),
544 KAboutData::License_GPL_V2, 544 KAboutData::License_GPL_V2,
545 I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) ); 545 I18N_NOOP( "(c) 1997-2003, The KDE PIM Team" ) );
546 about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" ); 546 about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer " ), "tokoe@kde.org" );
547 about->addAuthor( "Don Sanders", I18N_NOOP( "Original author " ) ); 547 about->addAuthor( "Don Sanders", I18N_NOOP( "Original author " ) );
548 about->addAuthor( "Cornelius Schumacher", 548 about->addAuthor( "Cornelius Schumacher",
549 I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export " ), 549 I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export " ),
550 "schumacher@kde.org" ); 550 "schumacher@kde.org" );
551 about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign " ), 551 about->addAuthor( "Mike Pilone", I18N_NOOP( "GUI and framework redesign " ),
552 "mpilone@slac.com" ); 552 "mpilone@slac.com" );
553 about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) ); 553 about->addAuthor( "Greg Stern", I18N_NOOP( "DCOP interface" ) );
554 about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) ); 554 about->addAuthor( "Mark Westcott", I18N_NOOP( "Contact pinning" ) );
555 about->addAuthor( "Michel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup\n" ), 555 about->addAuthor( "Michel Boyer de la Giroday", I18N_NOOP( "LDAP Lookup\n" ),
556 "michel@klaralvdalens-datakonsult.se" ); 556 "michel@klaralvdalens-datakonsult.se" );
557 about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup " ), 557 about->addAuthor( "Steffen Hansen", I18N_NOOP( "LDAP Lookup " ),
558 "hansen@kde.org" ); 558 "hansen@kde.org" );
559 559
560 return about; 560 return about;
561#endif //KAB_EMBEDDED 561#endif //KAB_EMBEDDED
562 562
563 QString version; 563 QString version;
564#include <../version> 564#include <../version>
565 QMessageBox::about( this, "About KAddressbook/Pi", 565 QMessageBox::about( this, "About KAddressbook/Pi",
566 "KAddressbook/Platform-independent\n" 566 "KAddressbook/Platform-independent\n"
567 "(KA/Pi) " +version + " - " + 567 "(KA/Pi) " +version + " - " +
568#ifdef DESKTOP_VERSION 568#ifdef DESKTOP_VERSION
569 "Desktop Edition\n" 569 "Desktop Edition\n"
570#else 570#else
571 "PDA-Edition\n" 571 "PDA-Edition\n"
572 "for: Zaurus 5500 / 7x0 / 8x0\n" 572 "for: Zaurus 5500 / 7x0 / 8x0\n"
573#endif 573#endif
574 574
575 "(c) 2004 Ulf Schenk\n" 575 "(c) 2004 Ulf Schenk\n"
576 "(c) 2004 Lutz Rogowski\n" 576 "(c) 2004 Lutz Rogowski\n"
577 "(c) 1997-2003, The KDE PIM Team\n" 577 "(c) 1997-2003, The KDE PIM Team\n"
578 "Tobias Koenig Current maintainer\ntokoe@kde.org\n" 578 "Tobias Koenig Current maintainer\ntokoe@kde.org\n"
579 "Don Sanders Original author\n" 579 "Don Sanders Original author\n"
580 "Cornelius Schumacher Co-maintainer\nschumacher@kde.org\n" 580 "Cornelius Schumacher Co-maintainer\nschumacher@kde.org\n"
581 "Mike Pilone GUI and framework redesign\nmpilone@slac.com\n" 581 "Mike Pilone GUI and framework redesign\nmpilone@slac.com\n"
582 "Greg Stern DCOP interface\n" 582 "Greg Stern DCOP interface\n"
583 "Mark Westcot Contact pinning\n" 583 "Mark Westcot Contact pinning\n"
584 "Michel Boyer de la Giroday LDAP Lookup\n" "michel@klaralvdalens-datakonsult.se\n" 584 "Michel Boyer de la Giroday LDAP Lookup\n" "michel@klaralvdalens-datakonsult.se\n"
585 "Steffen Hansen LDAP Lookup\nhansen@kde.org\n" 585 "Steffen Hansen LDAP Lookup\nhansen@kde.org\n"
586#ifdef _WIN32_ 586#ifdef _WIN32_
587 "(c) 2004 Lutz Rogowski Import from OL\nrogowski@kde.org\n" 587 "(c) 2004 Lutz Rogowski Import from OL\nrogowski@kde.org\n"
588#endif 588#endif
589 ); 589 );
590} 590}
591 591
592void KABCore::setContactSelected( const QString &uid ) 592void KABCore::setContactSelected( const QString &uid )
593{ 593{
594 KABC::Addressee addr = mAddressBook->findByUid( uid ); 594 KABC::Addressee addr = mAddressBook->findByUid( uid );
595 if ( !mDetails->isHidden() ) 595 if ( !mDetails->isHidden() )
596 mDetails->setAddressee( addr ); 596 mDetails->setAddressee( addr );
597 597
598 if ( !addr.isEmpty() ) { 598 if ( !addr.isEmpty() ) {
599 emit contactSelected( addr.formattedName() ); 599 emit contactSelected( addr.formattedName() );
600 KABC::Picture pic = addr.photo(); 600 KABC::Picture pic = addr.photo();
601 if ( pic.isIntern() ) { 601 if ( pic.isIntern() ) {
602//US emit contactSelected( pic.data() ); 602//US emit contactSelected( pic.data() );
603//US instead use: 603//US instead use:
604 QPixmap px; 604 QPixmap px;
605 if (pic.data().isNull() != true) 605 if (pic.data().isNull() != true)
606 { 606 {
607 px.convertFromImage(pic.data()); 607 px.convertFromImage(pic.data());
608 } 608 }
609 609
610 emit contactSelected( px ); 610 emit contactSelected( px );
611 } 611 }
612 } 612 }
613 613
614 614
615 mExtensionManager->setSelectionChanged(); 615 mExtensionManager->setSelectionChanged();
616 616
617 // update the actions 617 // update the actions
618 bool selected = !uid.isEmpty(); 618 bool selected = !uid.isEmpty();
619 619
620 if ( mReadWrite ) { 620 if ( mReadWrite ) {
621 mActionCut->setEnabled( selected ); 621 mActionCut->setEnabled( selected );
622 mActionPaste->setEnabled( selected ); 622 mActionPaste->setEnabled( selected );
623 } 623 }
624 624
625 mActionCopy->setEnabled( selected ); 625 mActionCopy->setEnabled( selected );
626 mActionDelete->setEnabled( selected ); 626 mActionDelete->setEnabled( selected );
627 mActionEditAddressee->setEnabled( selected ); 627 mActionEditAddressee->setEnabled( selected );
628 mActionMail->setEnabled( selected ); 628 mActionMail->setEnabled( selected );
629 mActionMailVCard->setEnabled( selected ); 629 mActionMailVCard->setEnabled( selected );
630 //if (mActionBeam) 630 //if (mActionBeam)
631 //mActionBeam->setEnabled( selected ); 631 //mActionBeam->setEnabled( selected );
632 632
633 if (mActionBeamVCard) 633 if (mActionBeamVCard)
634 mActionBeamVCard->setEnabled( selected ); 634 mActionBeamVCard->setEnabled( selected );
635 635
636 mActionExport2phone->setEnabled( selected ); 636 mActionExport2phone->setEnabled( selected );
637 mActionWhoAmI->setEnabled( selected ); 637 mActionWhoAmI->setEnabled( selected );
638 mActionCategories->setEnabled( selected ); 638 mActionCategories->setEnabled( selected );
639} 639}
640 640
641void KABCore::sendMail() 641void KABCore::sendMail()
642{ 642{
643 sendMail( mViewManager->selectedEmails().join( ", " ) ); 643 sendMail( mViewManager->selectedEmails().join( ", " ) );
644} 644}
645 645
646void KABCore::sendMail( const QString& emaillist ) 646void KABCore::sendMail( const QString& emaillist )
647{ 647{
648 // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... " 648 // the parameter has the form "name1 <abc@aol.com>,name2 <abc@aol.com>;... "
649 if (emaillist.contains(",") > 0) 649 if (emaillist.contains(",") > 0)
650 ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null ); 650 ExternalAppHandler::instance()->mailToMultipleContacts( emaillist, QString::null );
651 else 651 else
652 ExternalAppHandler::instance()->mailToOneContact( emaillist ); 652 ExternalAppHandler::instance()->mailToOneContact( emaillist );
653} 653}
654 654
655 655
656 656
657void KABCore::mailVCard() 657void KABCore::mailVCard()
658{ 658{
659 QStringList uids = mViewManager->selectedUids(); 659 QStringList uids = mViewManager->selectedUids();
660 if ( !uids.isEmpty() ) 660 if ( !uids.isEmpty() )
661 mailVCard( uids ); 661 mailVCard( uids );
662} 662}
663 663
664void KABCore::mailVCard( const QStringList& uids ) 664void KABCore::mailVCard( const QStringList& uids )
665{ 665{
666 QStringList urls; 666 QStringList urls;
667 667
668// QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); 668// QString tmpdir = locateLocal("tmp", KGlobal::getAppName());
669 669
670 QString dirName = "/tmp/" + KApplication::randomString( 8 ); 670 QString dirName = "/tmp/" + KApplication::randomString( 8 );
671 671
672 672
673 673
674 QDir().mkdir( dirName, true ); 674 QDir().mkdir( dirName, true );
675 675
676 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 676 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
677 KABC::Addressee a = mAddressBook->findByUid( *it ); 677 KABC::Addressee a = mAddressBook->findByUid( *it );
678 678
679 if ( a.isEmpty() ) 679 if ( a.isEmpty() )
680 continue; 680 continue;
681 681
682 QString name = a.givenName() + "_" + a.familyName() + ".vcf"; 682 QString name = a.givenName() + "_" + a.familyName() + ".vcf";
683 683
684 QString fileName = dirName + "/" + name; 684 QString fileName = dirName + "/" + name;
685 685
686 QFile outFile(fileName); 686 QFile outFile(fileName);
687 687
688 if ( outFile.open(IO_WriteOnly) ) { // file opened successfully 688 if ( outFile.open(IO_WriteOnly) ) { // file opened successfully
689 KABC::VCardConverter converter; 689 KABC::VCardConverter converter;
690 QString vcard; 690 QString vcard;
691 691
692 converter.addresseeToVCard( a, vcard ); 692 converter.addresseeToVCard( a, vcard );
693 693
694 QTextStream t( &outFile ); // use a text stream 694 QTextStream t( &outFile ); // use a text stream
695 t.setEncoding( QTextStream::UnicodeUTF8 ); 695 t.setEncoding( QTextStream::UnicodeUTF8 );
696 t << vcard; 696 t << vcard;
697 697
698 outFile.close(); 698 outFile.close();
699 699
700 urls.append( fileName ); 700 urls.append( fileName );
701 } 701 }
702 } 702 }
703 703
704 bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") ); 704 bool result = ExternalAppHandler::instance()->mailToMultipleContacts( QString::null, urls.join(", ") );
705 705
706 706
707/*US 707/*US
708 kapp->invokeMailer( QString::null, QString::null, QString::null, 708 kapp->invokeMailer( QString::null, QString::null, QString::null,
709 QString::null, // subject 709 QString::null, // subject
710 QString::null, // body 710 QString::null, // body
711 QString::null, 711 QString::null,
712 urls ); // attachments 712 urls ); // attachments
713*/ 713*/
714 714
715} 715}
716 716
717/** 717/**
718 Beams the "WhoAmI contact. 718 Beams the "WhoAmI contact.
719*/ 719*/
720void KABCore::beamMySelf() 720void KABCore::beamMySelf()
721{ 721{
722 KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI(); 722 KABC::Addressee a = KABC::StdAddressBook::self()->whoAmI();
723 if (!a.isEmpty()) 723 if (!a.isEmpty())
724 { 724 {
725 QStringList uids; 725 QStringList uids;
726 uids << a.uid(); 726 uids << a.uid();
727 727
728 beamVCard(uids); 728 beamVCard(uids);
729 } else { 729 } else {
730 KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) ); 730 KMessageBox::information( this, i18n( "Your personal contact is\nnot set! Please select it\nand set it with menu:\nSettings - Set Who Am I\n" ) );
731 731
732 732
733 } 733 }
734} 734}
735 735
736void KABCore::export2phone() 736void KABCore::export2phone()
737{ 737{
738 738
739 KAex2phonePrefs ex2phone; 739 KAex2phonePrefs ex2phone;
740 ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection ); 740 ex2phone.mPhoneConnection->setText( KPimGlobalPrefs::instance()->mEx2PhoneConnection );
741 ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice ); 741 ex2phone.mPhoneDevice->setText( KPimGlobalPrefs::instance()->mEx2PhoneDevice );
742 ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel ); 742 ex2phone.mPhoneModel->setText( KPimGlobalPrefs::instance()->mEx2PhoneModel );
743 743
744 if ( !ex2phone.exec() ) { 744 if ( !ex2phone.exec() ) {
745 return; 745 return;
746 } 746 }
747 KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text(); 747 KPimGlobalPrefs::instance()->mEx2PhoneConnection = ex2phone.mPhoneConnection->text();
748 KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text(); 748 KPimGlobalPrefs::instance()->mEx2PhoneDevice = ex2phone.mPhoneDevice->text();
749 KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text(); 749 KPimGlobalPrefs::instance()->mEx2PhoneModel = ex2phone.mPhoneModel->text();
750 750
751 751
752 PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice, 752 PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice,
753 KPimGlobalPrefs::instance()->mEx2PhoneConnection, 753 KPimGlobalPrefs::instance()->mEx2PhoneConnection,
754 KPimGlobalPrefs::instance()->mEx2PhoneModel ); 754 KPimGlobalPrefs::instance()->mEx2PhoneModel );
755 755
756 QStringList uids = mViewManager->selectedUids(); 756 QStringList uids = mViewManager->selectedUids();
757 if ( uids.isEmpty() ) 757 if ( uids.isEmpty() )
758 return; 758 return;
759 759
760 QString fileName = getPhoneFile(); 760 QString fileName = getPhoneFile();
761 if ( ! mAddressBook->export2PhoneFormat( uids ,fileName ) ) 761 if ( ! mAddressBook->export2PhoneFormat( uids ,fileName ) )
762 return; 762 return;
763 763
764 message(i18n("Exporting to phone...")); 764 message(i18n("Exporting to phone..."));
765 QTimer::singleShot( 1, this , SLOT ( writeToPhone())); 765 QTimer::singleShot( 1, this , SLOT ( writeToPhone()));
766 766
767} 767}
768QString KABCore::getPhoneFile() 768QString KABCore::getPhoneFile()
769{ 769{
770#ifdef DESKTOP_VERSION 770#ifdef DESKTOP_VERSION
771 return locateLocal("tmp", "phonefile.vcf"); 771 return locateLocal("tmp", "phonefile.vcf");
772#else 772#else
773 return "/tmp/phonefile.vcf"; 773 return "/tmp/phonefile.vcf";
774#endif 774#endif
775 775
776} 776}
777void KABCore::writeToPhone( ) 777void KABCore::writeToPhone( )
778{ 778{
779 if ( PhoneAccess::writeToPhone( getPhoneFile() ) ) 779 if ( PhoneAccess::writeToPhone( getPhoneFile() ) )
780 message(i18n("Export to phone finished!")); 780 message(i18n("Export to phone finished!"));
781 else 781 else
782 qDebug(i18n("Error exporting to phone")); 782 qDebug(i18n("Error exporting to phone"));
783} 783}
784void KABCore::beamVCard() 784void KABCore::beamVCard()
785{ 785{
786 QStringList uids = mViewManager->selectedUids(); 786 QStringList uids = mViewManager->selectedUids();
787 if ( !uids.isEmpty() ) 787 if ( !uids.isEmpty() )
788 beamVCard( uids ); 788 beamVCard( uids );
789} 789}
790 790
791 791
792void KABCore::beamVCard(const QStringList& uids) 792void KABCore::beamVCard(const QStringList& uids)
793{ 793{
794 794
795 // LR: we should use the /tmp dir on the Zaurus, 795 // LR: we should use the /tmp dir on the Zaurus,
796 // because: /tmp = RAM, (HOME)/kdepim = flash memory 796 // because: /tmp = RAM, (HOME)/kdepim = flash memory
797 797
798#ifdef DESKTOP_VERSION 798#ifdef DESKTOP_VERSION
799 QString fileName = locateLocal("tmp", "kapibeamfile.vcf"); 799 QString fileName = locateLocal("tmp", "kapibeamfile.vcf");
800#else 800#else
801 QString fileName = "/tmp/kapibeamfile.vcf"; 801 QString fileName = "/tmp/kapibeamfile.vcf";
802#endif 802#endif
803 803
804 KABC::VCardConverter converter; 804 KABC::VCardConverter converter;
805 QString description; 805 QString description;
806 QString datastream; 806 QString datastream;
807 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 807 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
808 KABC::Addressee a = mAddressBook->findByUid( *it ); 808 KABC::Addressee a = mAddressBook->findByUid( *it );
809 809
810 if ( a.isEmpty() ) 810 if ( a.isEmpty() )
811 continue; 811 continue;
812 812
813 if (description.isEmpty()) 813 if (description.isEmpty())
814 description = a.formattedName(); 814 description = a.formattedName();
815 815
816 QString vcard; 816 QString vcard;
817 converter.addresseeToVCard( a, vcard ); 817 converter.addresseeToVCard( a, vcard );
818 int start = 0; 818 int start = 0;
819 int next; 819 int next;
820 while ( (next = vcard.find("TYPE=", start) )>= 0 ) { 820 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
821 int semi = vcard.find(";", next); 821 int semi = vcard.find(";", next);
822 int dopp = vcard.find(":", next); 822 int dopp = vcard.find(":", next);
823 int sep; 823 int sep;
824 if ( semi < dopp && semi >= 0 ) 824 if ( semi < dopp && semi >= 0 )
825 sep = semi ; 825 sep = semi ;
826 else 826 else
827 sep = dopp; 827 sep = dopp;
828 datastream +=vcard.mid( start, next - start); 828 datastream +=vcard.mid( start, next - start);
829 datastream +=vcard.mid( next+5,sep -next -5 ).upper(); 829 datastream +=vcard.mid( next+5,sep -next -5 ).upper();
830 start = sep; 830 start = sep;
831 } 831 }
832 datastream += vcard.mid( start,vcard.length() ); 832 datastream += vcard.mid( start,vcard.length() );
833 } 833 }
834#ifndef DESKTOP_VERSION 834#ifndef DESKTOP_VERSION
835 QFile outFile(fileName); 835 QFile outFile(fileName);
836 if ( outFile.open(IO_WriteOnly) ) { 836 if ( outFile.open(IO_WriteOnly) ) {
837 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); 837 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
838 QTextStream t( &outFile ); // use a text stream 838 QTextStream t( &outFile ); // use a text stream
839 //t.setEncoding( QTextStream::UnicodeUTF8 ); 839 //t.setEncoding( QTextStream::UnicodeUTF8 );
840 t.setEncoding( QTextStream::Latin1 ); 840 t.setEncoding( QTextStream::Latin1 );
841 t <<datastream.latin1(); 841 t <<datastream.latin1();
842 outFile.close(); 842 outFile.close();
843 Ir *ir = new Ir( this ); 843 Ir *ir = new Ir( this );
844 connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); 844 connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) );
845 ir->send( fileName, description, "text/x-vCard" ); 845 ir->send( fileName, description, "text/x-vCard" );
846 } else { 846 } else {
847 qDebug("Error open temp beam file "); 847 qDebug("Error open temp beam file ");
848 return; 848 return;
849 } 849 }
850#endif 850#endif
851 851
852} 852}
853 853
854void KABCore::beamDone( Ir *ir ) 854void KABCore::beamDone( Ir *ir )
855{ 855{
856#ifndef DESKTOP_VERSION 856#ifndef DESKTOP_VERSION
857 delete ir; 857 delete ir;
858#endif 858#endif
859 topLevelWidget()->raise(); 859 topLevelWidget()->raise();
860 message( i18n("Beaming finished!") ); 860 message( i18n("Beaming finished!") );
861} 861}
862 862
863 863
864void KABCore::browse( const QString& url ) 864void KABCore::browse( const QString& url )
865{ 865{
866#ifndef KAB_EMBEDDED 866#ifndef KAB_EMBEDDED
867 kapp->invokeBrowser( url ); 867 kapp->invokeBrowser( url );
868#else //KAB_EMBEDDED 868#else //KAB_EMBEDDED
869 qDebug("KABCore::browse must be fixed"); 869 qDebug("KABCore::browse must be fixed");
870#endif //KAB_EMBEDDED 870#endif //KAB_EMBEDDED
871} 871}
872 872
873void KABCore::selectAllContacts() 873void KABCore::selectAllContacts()
874{ 874{
875 mViewManager->setSelected( QString::null, true ); 875 mViewManager->setSelected( QString::null, true );
876} 876}
877 877
878void KABCore::deleteContacts() 878void KABCore::deleteContacts()
879{ 879{
880 QStringList uidList = mViewManager->selectedUids(); 880 QStringList uidList = mViewManager->selectedUids();
881 deleteContacts( uidList ); 881 deleteContacts( uidList );
882} 882}
883 883
884void KABCore::deleteContacts( const QStringList &uids ) 884void KABCore::deleteContacts( const QStringList &uids )
885{ 885{
886 if ( uids.count() > 0 ) { 886 if ( uids.count() > 0 ) {
887 PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids ); 887 PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids );
888 UndoStack::instance()->push( command ); 888 UndoStack::instance()->push( command );
889 RedoStack::instance()->clear(); 889 RedoStack::instance()->clear();
890 890
891 // now if we deleted anything, refresh 891 // now if we deleted anything, refresh
892 setContactSelected( QString::null ); 892 setContactSelected( QString::null );
893 setModified( true ); 893 setModified( true );
894 } 894 }
895} 895}
896 896
897void KABCore::copyContacts() 897void KABCore::copyContacts()
898{ 898{
899 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 899 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
900 900
901 QString clipText = AddresseeUtil::addresseesToClipboard( addrList ); 901 QString clipText = AddresseeUtil::addresseesToClipboard( addrList );
902 902
903 kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl; 903 kdDebug(5720) << "KABCore::copyContacts: " << clipText << endl;
904 904
905 QClipboard *cb = QApplication::clipboard(); 905 QClipboard *cb = QApplication::clipboard();
906 cb->setText( clipText ); 906 cb->setText( clipText );
907} 907}
908 908
909void KABCore::cutContacts() 909void KABCore::cutContacts()
910{ 910{
911 QStringList uidList = mViewManager->selectedUids(); 911 QStringList uidList = mViewManager->selectedUids();
912 912
913//US if ( uidList.size() > 0 ) { 913//US if ( uidList.size() > 0 ) {
914 if ( uidList.count() > 0 ) { 914 if ( uidList.count() > 0 ) {
915 PwCutCommand *command = new PwCutCommand( mAddressBook, uidList ); 915 PwCutCommand *command = new PwCutCommand( mAddressBook, uidList );
916 UndoStack::instance()->push( command ); 916 UndoStack::instance()->push( command );
917 RedoStack::instance()->clear(); 917 RedoStack::instance()->clear();
918 918
919 setModified( true ); 919 setModified( true );
920 } 920 }
921} 921}
922 922
923void KABCore::pasteContacts() 923void KABCore::pasteContacts()
924{ 924{
925 QClipboard *cb = QApplication::clipboard(); 925 QClipboard *cb = QApplication::clipboard();
926 926
927 KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() ); 927 KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() );
928 928
929 pasteContacts( list ); 929 pasteContacts( list );
930} 930}
931 931
932void KABCore::pasteContacts( KABC::Addressee::List &list ) 932void KABCore::pasteContacts( KABC::Addressee::List &list )
933{ 933{
934 KABC::Resource *resource = requestResource( this ); 934 KABC::Resource *resource = requestResource( this );
935 KABC::Addressee::List::Iterator it; 935 KABC::Addressee::List::Iterator it;
936 for ( it = list.begin(); it != list.end(); ++it ) 936 for ( it = list.begin(); it != list.end(); ++it )
937 (*it).setResource( resource ); 937 (*it).setResource( resource );
938 938
939 PwPasteCommand *command = new PwPasteCommand( this, list ); 939 PwPasteCommand *command = new PwPasteCommand( this, list );
940 UndoStack::instance()->push( command ); 940 UndoStack::instance()->push( command );
941 RedoStack::instance()->clear(); 941 RedoStack::instance()->clear();
942 942
943 setModified( true ); 943 setModified( true );
944} 944}
945 945
946void KABCore::setWhoAmI() 946void KABCore::setWhoAmI()
947{ 947{
948 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 948 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
949 949
950 if ( addrList.count() > 1 ) { 950 if ( addrList.count() > 1 ) {
951 KMessageBox::sorry( this, i18n( "Please select only one contact." ) ); 951 KMessageBox::sorry( this, i18n( "Please select only one contact." ) );
952 return; 952 return;
953 } 953 }
954 954
955 QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) ); 955 QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) );
956 if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes ) 956 if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes )
957 static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] ); 957 static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] );
958} 958}
959 959
960void KABCore::setCategories() 960void KABCore::setCategories()
961{ 961{
962 KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true ); 962 KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true );
963 if ( !dlg.exec() ) 963 if ( !dlg.exec() )
964 return; 964 return;
965 965
966 bool merge = false; 966 bool merge = false;
967 QString msg = i18n( "Merge with existing categories?" ); 967 QString msg = i18n( "Merge with existing categories?" );
968 if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes ) 968 if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes )
969 merge = true; 969 merge = true;
970 970
971 QStringList categories = dlg.selectedCategories(); 971 QStringList categories = dlg.selectedCategories();
972 972
973 QStringList uids = mViewManager->selectedUids(); 973 QStringList uids = mViewManager->selectedUids();
974 QStringList::Iterator it; 974 QStringList::Iterator it;
975 for ( it = uids.begin(); it != uids.end(); ++it ) { 975 for ( it = uids.begin(); it != uids.end(); ++it ) {
976 KABC::Addressee addr = mAddressBook->findByUid( *it ); 976 KABC::Addressee addr = mAddressBook->findByUid( *it );
977 if ( !addr.isEmpty() ) { 977 if ( !addr.isEmpty() ) {
978 if ( !merge ) 978 if ( !merge )
979 addr.setCategories( categories ); 979 addr.setCategories( categories );
980 else { 980 else {
981 QStringList addrCategories = addr.categories(); 981 QStringList addrCategories = addr.categories();
982 QStringList::Iterator catIt; 982 QStringList::Iterator catIt;
983 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { 983 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) {
984 if ( !addrCategories.contains( *catIt ) ) 984 if ( !addrCategories.contains( *catIt ) )
985 addrCategories.append( *catIt ); 985 addrCategories.append( *catIt );
986 } 986 }
987 addr.setCategories( addrCategories ); 987 addr.setCategories( addrCategories );
988 } 988 }
989 989
990 mAddressBook->insertAddressee( addr ); 990 mAddressBook->insertAddressee( addr );
991 } 991 }
992 } 992 }
993 993
994 if ( uids.count() > 0 ) 994 if ( uids.count() > 0 )
995 setModified( true ); 995 setModified( true );
996} 996}
997 997
998void KABCore::setSearchFields( const KABC::Field::List &fields ) 998void KABCore::setSearchFields( const KABC::Field::List &fields )
999{ 999{
1000 mIncSearchWidget->setFields( fields ); 1000 mIncSearchWidget->setFields( fields );
1001} 1001}
1002 1002
1003void KABCore::incrementalSearch( const QString& text ) 1003void KABCore::incrementalSearch( const QString& text )
1004{ 1004{
1005 mViewManager->doSearch( text, mIncSearchWidget->currentField() ); 1005 mViewManager->doSearch( text, mIncSearchWidget->currentField() );
1006} 1006}
1007 1007
1008void KABCore::setModified() 1008void KABCore::setModified()
1009{ 1009{
1010 setModified( true ); 1010 setModified( true );
1011} 1011}
1012 1012
1013void KABCore::setModifiedWOrefresh() 1013void KABCore::setModifiedWOrefresh()
1014{ 1014{
1015 // qDebug("KABCore::setModifiedWOrefresh() "); 1015 // qDebug("KABCore::setModifiedWOrefresh() ");
1016 mModified = true; 1016 mModified = true;
1017 mActionSave->setEnabled( mModified ); 1017 mActionSave->setEnabled( mModified );
1018#ifdef DESKTOP_VERSION 1018#ifdef DESKTOP_VERSION
1019 mDetails->refreshView(); 1019 mDetails->refreshView();
1020#endif 1020#endif
1021 1021
1022} 1022}
1023void KABCore::setModified( bool modified ) 1023void KABCore::setModified( bool modified )
1024{ 1024{
1025 mModified = modified; 1025 mModified = modified;
1026 mActionSave->setEnabled( mModified ); 1026 mActionSave->setEnabled( mModified );
1027 1027
1028 if ( modified ) 1028 if ( modified )
1029 mJumpButtonBar->recreateButtons(); 1029 mJumpButtonBar->recreateButtons();
1030 1030
1031 mViewManager->refreshView(); 1031 mViewManager->refreshView();
1032 mDetails->refreshView(); 1032 mDetails->refreshView();
1033 1033
1034} 1034}
1035 1035
1036bool KABCore::modified() const 1036bool KABCore::modified() const
1037{ 1037{
1038 return mModified; 1038 return mModified;
1039} 1039}
1040 1040
1041void KABCore::contactModified( const KABC::Addressee &addr ) 1041void KABCore::contactModified( const KABC::Addressee &addr )
1042{ 1042{
1043 1043
1044 Command *command = 0; 1044 Command *command = 0;
1045 QString uid; 1045 QString uid;
1046 1046
1047 // check if it exists already 1047 // check if it exists already
1048 KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() ); 1048 KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() );
1049 if ( origAddr.isEmpty() ) 1049 if ( origAddr.isEmpty() )
1050 command = new PwNewCommand( mAddressBook, addr ); 1050 command = new PwNewCommand( mAddressBook, addr );
1051 else { 1051 else {
1052 command = new PwEditCommand( mAddressBook, origAddr, addr ); 1052 command = new PwEditCommand( mAddressBook, origAddr, addr );
1053 uid = addr.uid(); 1053 uid = addr.uid();
1054 } 1054 }
1055 1055
1056 UndoStack::instance()->push( command ); 1056 UndoStack::instance()->push( command );
1057 RedoStack::instance()->clear(); 1057 RedoStack::instance()->clear();
1058 1058
1059 setModified( true ); 1059 setModified( true );
1060} 1060}
1061 1061
1062void KABCore::newContact() 1062void KABCore::newContact()
1063{ 1063{
1064 1064
1065 1065
1066 QPtrList<KABC::Resource> kabcResources = mAddressBook->resources(); 1066 QPtrList<KABC::Resource> kabcResources = mAddressBook->resources();
1067 1067
1068 QPtrList<KRES::Resource> kresResources; 1068 QPtrList<KRES::Resource> kresResources;
1069 QPtrListIterator<KABC::Resource> it( kabcResources ); 1069 QPtrListIterator<KABC::Resource> it( kabcResources );
1070 KABC::Resource *resource; 1070 KABC::Resource *resource;
1071 while ( ( resource = it.current() ) != 0 ) { 1071 while ( ( resource = it.current() ) != 0 ) {
1072 ++it; 1072 ++it;
1073 if ( !resource->readOnly() ) { 1073 if ( !resource->readOnly() ) {
1074 KRES::Resource *res = static_cast<KRES::Resource*>( resource ); 1074 KRES::Resource *res = static_cast<KRES::Resource*>( resource );
1075 if ( res ) 1075 if ( res )
1076 kresResources.append( res ); 1076 kresResources.append( res );
1077 } 1077 }
1078 } 1078 }
1079 1079
1080 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this ); 1080 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this );
1081 resource = static_cast<KABC::Resource*>( res ); 1081 resource = static_cast<KABC::Resource*>( res );
1082 1082
1083 if ( resource ) { 1083 if ( resource ) {
1084 KABC::Addressee addr; 1084 KABC::Addressee addr;
1085 addr.setResource( resource ); 1085 addr.setResource( resource );
1086 mEditorDialog->setAddressee( addr ); 1086 mEditorDialog->setAddressee( addr );
1087 KApplication::execDialog ( mEditorDialog ); 1087 KApplication::execDialog ( mEditorDialog );
1088 1088
1089 } else 1089 } else
1090 return; 1090 return;
1091 1091
1092 // mEditorDict.insert( dialog->addressee().uid(), dialog ); 1092 // mEditorDict.insert( dialog->addressee().uid(), dialog );
1093 1093
1094 1094
1095} 1095}
1096 1096
1097void KABCore::addEmail( QString aStr ) 1097void KABCore::addEmail( QString aStr )
1098{ 1098{
1099#ifndef KAB_EMBEDDED 1099#ifndef KAB_EMBEDDED
1100 QString fullName, email; 1100 QString fullName, email;
1101 1101
1102 KABC::Addressee::parseEmailAddress( aStr, fullName, email ); 1102 KABC::Addressee::parseEmailAddress( aStr, fullName, email );
1103 1103
1104 // Try to lookup the addressee matching the email address 1104 // Try to lookup the addressee matching the email address
1105 bool found = false; 1105 bool found = false;
1106 QStringList emailList; 1106 QStringList emailList;
1107 KABC::AddressBook::Iterator it; 1107 KABC::AddressBook::Iterator it;
1108 for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) { 1108 for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) {
1109 emailList = (*it).emails(); 1109 emailList = (*it).emails();
1110 if ( emailList.contains( email ) > 0 ) { 1110 if ( emailList.contains( email ) > 0 ) {
1111 found = true; 1111 found = true;
1112 (*it).setNameFromString( fullName ); 1112 (*it).setNameFromString( fullName );
1113 editContact( (*it).uid() ); 1113 editContact( (*it).uid() );
1114 } 1114 }
1115 } 1115 }
1116 1116
1117 if ( !found ) { 1117 if ( !found ) {
1118 KABC::Addressee addr; 1118 KABC::Addressee addr;
1119 addr.setNameFromString( fullName ); 1119 addr.setNameFromString( fullName );
1120 addr.insertEmail( email, true ); 1120 addr.insertEmail( email, true );
1121 1121
1122 mAddressBook->insertAddressee( addr ); 1122 mAddressBook->insertAddressee( addr );
1123 mViewManager->refreshView( addr.uid() ); 1123 mViewManager->refreshView( addr.uid() );
1124 editContact( addr.uid() ); 1124 editContact( addr.uid() );
1125 } 1125 }
1126#else //KAB_EMBEDDED 1126#else //KAB_EMBEDDED
1127 qDebug("KABCore::addEmail finsih method"); 1127 qDebug("KABCore::addEmail finsih method");
1128#endif //KAB_EMBEDDED 1128#endif //KAB_EMBEDDED
1129} 1129}
1130 1130
1131void KABCore::importVCard( const KURL &url, bool showPreview ) 1131void KABCore::importVCard( const KURL &url, bool showPreview )
1132{ 1132{
1133 mXXPortManager->importVCard( url, showPreview ); 1133 mXXPortManager->importVCard( url, showPreview );
1134} 1134}
1135void KABCore::importFromOL() 1135void KABCore::importFromOL()
1136{ 1136{
1137#ifdef _WIN32_ 1137#ifdef _WIN32_
1138 KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this ); 1138 KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this );
1139 idgl->exec(); 1139 idgl->exec();
1140 KABC::Addressee::List list = idgl->getAddressList(); 1140 KABC::Addressee::List list = idgl->getAddressList();
1141 if ( list.count() > 0 ) { 1141 if ( list.count() > 0 ) {
1142 KABC::Addressee::List listNew; 1142 KABC::Addressee::List listNew;
1143 KABC::Addressee::List listExisting; 1143 KABC::Addressee::List listExisting;
1144 KABC::Addressee::List::Iterator it; 1144 KABC::Addressee::List::Iterator it;
1145 KABC::AddressBook::Iterator iter; 1145 KABC::AddressBook::Iterator iter;
1146 for ( it = list.begin(); it != list.end(); ++it ) { 1146 for ( it = list.begin(); it != list.end(); ++it ) {
1147 if ( mAddressBook->findByUid((*it).uid() ).isEmpty()) 1147 if ( mAddressBook->findByUid((*it).uid() ).isEmpty())
1148 listNew.append( (*it) ); 1148 listNew.append( (*it) );
1149 else 1149 else
1150 listExisting.append( (*it) ); 1150 listExisting.append( (*it) );
1151 } 1151 }
1152 if ( listExisting.count() > 0 ) 1152 if ( listExisting.count() > 0 )
1153 KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() )); 1153 KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() ));
1154 if ( listNew.count() > 0 ) { 1154 if ( listNew.count() > 0 ) {
1155 pasteWithNewUid = false; 1155 pasteWithNewUid = false;
1156 pasteContacts( listNew ); 1156 pasteContacts( listNew );
1157 pasteWithNewUid = true; 1157 pasteWithNewUid = true;
1158 } 1158 }
1159 } 1159 }
1160 delete idgl; 1160 delete idgl;
1161#endif 1161#endif
1162} 1162}
1163 1163
1164void KABCore::importVCard( const QString &vCard, bool showPreview ) 1164void KABCore::importVCard( const QString &vCard, bool showPreview )
1165{ 1165{
1166 mXXPortManager->importVCard( vCard, showPreview ); 1166 mXXPortManager->importVCard( vCard, showPreview );
1167} 1167}
1168 1168
1169//US added a second method without defaultparameter 1169//US added a second method without defaultparameter
1170void KABCore::editContact2() { 1170void KABCore::editContact2() {
1171 editContact( QString::null ); 1171 editContact( QString::null );
1172} 1172}
1173 1173
1174void KABCore::editContact( const QString &uid ) 1174void KABCore::editContact( const QString &uid )
1175{ 1175{
1176 1176
1177 if ( mExtensionManager->isQuickEditVisible() ) 1177 if ( mExtensionManager->isQuickEditVisible() )
1178 return; 1178 return;
1179 1179
1180 // First, locate the contact entry 1180 // First, locate the contact entry
1181 QString localUID = uid; 1181 QString localUID = uid;
1182 if ( localUID.isNull() ) { 1182 if ( localUID.isNull() ) {
1183 QStringList uidList = mViewManager->selectedUids(); 1183 QStringList uidList = mViewManager->selectedUids();
1184 if ( uidList.count() > 0 ) 1184 if ( uidList.count() > 0 )
1185 localUID = *( uidList.at( 0 ) ); 1185 localUID = *( uidList.at( 0 ) );
1186 } 1186 }
1187 1187
1188 KABC::Addressee addr = mAddressBook->findByUid( localUID ); 1188 KABC::Addressee addr = mAddressBook->findByUid( localUID );
1189 if ( !addr.isEmpty() ) { 1189 if ( !addr.isEmpty() ) {
1190 mEditorDialog->setAddressee( addr ); 1190 mEditorDialog->setAddressee( addr );
1191 KApplication::execDialog ( mEditorDialog ); 1191 KApplication::execDialog ( mEditorDialog );
1192 } 1192 }
1193} 1193}
1194 1194
1195/** 1195/**
1196 Shows or edits the detail view for the given uid. If the uid is QString::null, 1196 Shows or edits the detail view for the given uid. If the uid is QString::null,
1197 the method will try to find a selected addressee in the view. 1197 the method will try to find a selected addressee in the view.
1198 */ 1198 */
1199void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) 1199void KABCore::executeContact( const QString &uid /*US = QString::null*/ )
1200{ 1200{
1201 if ( mMultipleViewsAtOnce ) 1201 if ( mMultipleViewsAtOnce )
1202 { 1202 {
1203 editContact( uid ); 1203 editContact( uid );
1204 } 1204 }
1205 else 1205 else
1206 { 1206 {
1207 setDetailsVisible( true ); 1207 setDetailsVisible( true );
1208 mActionDetails->setChecked(true); 1208 mActionDetails->setChecked(true);
1209 } 1209 }
1210 1210
1211} 1211}
1212 1212
1213void KABCore::save() 1213void KABCore::save()
1214{ 1214{
1215 if (syncManager->blockSave()) 1215 if (syncManager->blockSave())
1216 return; 1216 return;
1217 if ( !mModified ) 1217 if ( !mModified )
1218 return; 1218 return;
1219 1219
1220 syncManager->setBlockSave(true); 1220 syncManager->setBlockSave(true);
1221 QString text = i18n( "There was an error while attempting to save\n the " 1221 QString text = i18n( "There was an error while attempting to save\n the "
1222 "address book. Please check that some \nother application is " 1222 "address book. Please check that some \nother application is "
1223 "not using it. " ); 1223 "not using it. " );
1224 message(i18n("Saving addressbook ... ")); 1224 message(i18n("Saving addressbook ... "));
1225#ifndef KAB_EMBEDDED 1225#ifndef KAB_EMBEDDED
1226 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); 1226 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook );
1227 if ( !b || !b->save() ) { 1227 if ( !b || !b->save() ) {
1228 KMessageBox::error( this, text, i18n( "Unable to Save" ) ); 1228 KMessageBox::error( this, text, i18n( "Unable to Save" ) );
1229 } 1229 }
1230#else //KAB_EMBEDDED 1230#else //KAB_EMBEDDED
1231 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); 1231 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook );
1232 if ( !b || !b->save() ) { 1232 if ( !b || !b->save() ) {
1233 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); 1233 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok"));
1234 } 1234 }
1235#endif //KAB_EMBEDDED 1235#endif //KAB_EMBEDDED
1236 1236
1237 message(i18n("Addressbook saved!")); 1237 message(i18n("Addressbook saved!"));
1238 setModified( false ); 1238 setModified( false );
1239 syncManager->setBlockSave(false); 1239 syncManager->setBlockSave(false);
1240} 1240}
1241 1241
1242 1242
1243void KABCore::undo() 1243void KABCore::undo()
1244{ 1244{
1245 UndoStack::instance()->undo(); 1245 UndoStack::instance()->undo();
1246 1246
1247 // Refresh the view 1247 // Refresh the view
1248 mViewManager->refreshView(); 1248 mViewManager->refreshView();
1249} 1249}
1250 1250
1251void KABCore::redo() 1251void KABCore::redo()
1252{ 1252{
1253 RedoStack::instance()->redo(); 1253 RedoStack::instance()->redo();
1254 1254
1255 // Refresh the view 1255 // Refresh the view
1256 mViewManager->refreshView(); 1256 mViewManager->refreshView();
1257} 1257}
1258 1258
1259void KABCore::setJumpButtonBarVisible( bool visible ) 1259void KABCore::setJumpButtonBarVisible( bool visible )
1260{ 1260{
1261 if (mMultipleViewsAtOnce) 1261 if (mMultipleViewsAtOnce)
1262 { 1262 {
1263 if ( visible ) 1263 if ( visible )
1264 mJumpButtonBar->show(); 1264 mJumpButtonBar->show();
1265 else 1265 else
1266 mJumpButtonBar->hide(); 1266 mJumpButtonBar->hide();
1267 } 1267 }
1268 else 1268 else
1269 { 1269 {
1270 // show the jumpbar only if "the details are hidden" == "viewmanager are shown" 1270 // show the jumpbar only if "the details are hidden" == "viewmanager are shown"
1271 if (mViewManager->isVisible()) 1271 if (mViewManager->isVisible())
1272 { 1272 {
1273 if ( visible ) 1273 if ( visible )
1274 mJumpButtonBar->show(); 1274 mJumpButtonBar->show();
1275 else 1275 else
1276 mJumpButtonBar->hide(); 1276 mJumpButtonBar->hide();
1277 } 1277 }
1278 else 1278 else
1279 { 1279 {
1280 mJumpButtonBar->hide(); 1280 mJumpButtonBar->hide();
1281 } 1281 }
1282 } 1282 }
1283} 1283}
1284 1284
1285 1285
1286void KABCore::setDetailsToState() 1286void KABCore::setDetailsToState()
1287{ 1287{
1288 setDetailsVisible( mActionDetails->isChecked() ); 1288 setDetailsVisible( mActionDetails->isChecked() );
1289} 1289}
1290void KABCore::setDetailsToggle() 1290void KABCore::setDetailsToggle()
1291{ 1291{
1292 mActionDetails->setChecked( !mActionDetails->isChecked() ); 1292 mActionDetails->setChecked( !mActionDetails->isChecked() );
1293 setDetailsToState(); 1293 setDetailsToState();
1294} 1294}
1295 1295
1296 1296
1297 1297
1298void KABCore::setDetailsVisible( bool visible ) 1298void KABCore::setDetailsVisible( bool visible )
1299{ 1299{
1300 if (visible && mDetails->isHidden()) 1300 if (visible && mDetails->isHidden())
1301 { 1301 {
1302 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 1302 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
1303 if ( addrList.count() > 0 ) 1303 if ( addrList.count() > 0 )
1304 mDetails->setAddressee( addrList[ 0 ] ); 1304 mDetails->setAddressee( addrList[ 0 ] );
1305 } 1305 }
1306 1306
1307 // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between 1307 // mMultipleViewsAtOnce=false: mDetails is always visible. But we switch between
1308 // the listview and the detailview. We do that by changing the splitbar size. 1308 // the listview and the detailview. We do that by changing the splitbar size.
1309 if (mMultipleViewsAtOnce) 1309 if (mMultipleViewsAtOnce)
1310 { 1310 {
1311 if ( visible ) 1311 if ( visible )
1312 mDetails->show(); 1312 mDetails->show();
1313 else 1313 else
1314 mDetails->hide(); 1314 mDetails->hide();
1315 } 1315 }
1316 else 1316 else
1317 { 1317 {
1318 if ( visible ) { 1318 if ( visible ) {
1319 mViewManager->hide(); 1319 mViewManager->hide();
1320 mDetails->show(); 1320 mDetails->show();
1321 mIncSearchWidget->setFocus(); 1321 mIncSearchWidget->setFocus();
1322 } 1322 }
1323 else { 1323 else {
1324 mViewManager->show(); 1324 mViewManager->show();
1325 mDetails->hide(); 1325 mDetails->hide();
1326 mViewManager->setFocusAV(); 1326 mViewManager->setFocusAV();
1327 } 1327 }
1328 setJumpButtonBarVisible( !visible ); 1328 setJumpButtonBarVisible( !visible );
1329 } 1329 }
1330 1330
1331} 1331}
1332 1332
1333void KABCore::extensionChanged( int id ) 1333void KABCore::extensionChanged( int id )
1334{ 1334{
1335 //change the details view only for non desktop systems 1335 //change the details view only for non desktop systems
1336#ifndef DESKTOP_VERSION 1336#ifndef DESKTOP_VERSION
1337 1337
1338 if (id == 0) 1338 if (id == 0)
1339 { 1339 {
1340 //the user disabled the extension. 1340 //the user disabled the extension.
1341 1341
1342 if (mMultipleViewsAtOnce) 1342 if (mMultipleViewsAtOnce)
1343 { // enable detailsview again 1343 { // enable detailsview again
1344 setDetailsVisible( true ); 1344 setDetailsVisible( true );
1345 mActionDetails->setChecked( true ); 1345 mActionDetails->setChecked( true );
1346 } 1346 }
1347 else 1347 else
1348 { //go back to the listview 1348 { //go back to the listview
1349 setDetailsVisible( false ); 1349 setDetailsVisible( false );
1350 mActionDetails->setChecked( false ); 1350 mActionDetails->setChecked( false );
1351 mActionDetails->setEnabled(true); 1351 mActionDetails->setEnabled(true);
1352 } 1352 }
1353 1353
1354 } 1354 }
1355 else 1355 else
1356 { 1356 {
1357 //the user enabled the extension. 1357 //the user enabled the extension.
1358 setDetailsVisible( false ); 1358 setDetailsVisible( false );
1359 mActionDetails->setChecked( false ); 1359 mActionDetails->setChecked( false );
1360 1360
1361 if (!mMultipleViewsAtOnce) 1361 if (!mMultipleViewsAtOnce)
1362 { 1362 {
1363 mActionDetails->setEnabled(false); 1363 mActionDetails->setEnabled(false);
1364 } 1364 }
1365 1365
1366 mExtensionManager->setSelectionChanged(); 1366 mExtensionManager->setSelectionChanged();
1367 1367
1368 } 1368 }
1369 1369
1370#endif// DESKTOP_VERSION 1370#endif// DESKTOP_VERSION
1371 1371
1372} 1372}
1373 1373
1374 1374
1375void KABCore::extensionModified( const KABC::Addressee::List &list ) 1375void KABCore::extensionModified( const KABC::Addressee::List &list )
1376{ 1376{
1377 1377
1378 if ( list.count() != 0 ) { 1378 if ( list.count() != 0 ) {
1379 KABC::Addressee::List::ConstIterator it; 1379 KABC::Addressee::List::ConstIterator it;
1380 for ( it = list.begin(); it != list.end(); ++it ) 1380 for ( it = list.begin(); it != list.end(); ++it )
1381 mAddressBook->insertAddressee( *it ); 1381 mAddressBook->insertAddressee( *it );
1382 if ( list.count() > 1 ) 1382 if ( list.count() > 1 )
1383 setModified(); 1383 setModified();
1384 else 1384 else
1385 setModifiedWOrefresh(); 1385 setModifiedWOrefresh();
1386 } 1386 }
1387 if ( list.count() == 0 ) 1387 if ( list.count() == 0 )
1388 mViewManager->refreshView(); 1388 mViewManager->refreshView();
1389 else 1389 else
1390 mViewManager->refreshView( list[ 0 ].uid() ); 1390 mViewManager->refreshView( list[ 0 ].uid() );
1391 1391
1392 1392
1393 1393
1394} 1394}
1395 1395
1396QString KABCore::getNameByPhone( const QString &phone ) 1396QString KABCore::getNameByPhone( const QString &phone )
1397{ 1397{
1398#ifndef KAB_EMBEDDED 1398#ifndef KAB_EMBEDDED
1399 QRegExp r( "[/*/-/ ]" ); 1399 QRegExp r( "[/*/-/ ]" );
1400 QString localPhone( phone ); 1400 QString localPhone( phone );
1401 1401
1402 bool found = false; 1402 bool found = false;
1403 QString ownerName = ""; 1403 QString ownerName = "";
1404 KABC::AddressBook::Iterator iter; 1404 KABC::AddressBook::Iterator iter;
1405 KABC::PhoneNumber::List::Iterator phoneIter; 1405 KABC::PhoneNumber::List::Iterator phoneIter;
1406 KABC::PhoneNumber::List phoneList; 1406 KABC::PhoneNumber::List phoneList;
1407 for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) { 1407 for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) {
1408 phoneList = (*iter).phoneNumbers(); 1408 phoneList = (*iter).phoneNumbers();
1409 for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() ); 1409 for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() );
1410 ++phoneIter) { 1410 ++phoneIter) {
1411 // Get rid of separator chars so just the numbers are compared. 1411 // Get rid of separator chars so just the numbers are compared.
1412 if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) { 1412 if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) {
1413 ownerName = (*iter).formattedName(); 1413 ownerName = (*iter).formattedName();
1414 found = true; 1414 found = true;
1415 } 1415 }
1416 } 1416 }
1417 } 1417 }
1418 1418
1419 return ownerName; 1419 return ownerName;
1420#else //KAB_EMBEDDED 1420#else //KAB_EMBEDDED
1421 qDebug("KABCore::getNameByPhone finsih method"); 1421 qDebug("KABCore::getNameByPhone finsih method");
1422 return ""; 1422 return "";
1423#endif //KAB_EMBEDDED 1423#endif //KAB_EMBEDDED
1424 1424
1425} 1425}
1426 1426
1427void KABCore::openConfigDialog() 1427void KABCore::openConfigDialog()
1428{ 1428{
1429 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true ); 1429 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true );
1430 KCMKabConfig* kabcfg = new KCMKabConfig( ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" ); 1430 KCMKabConfig* kabcfg = new KCMKabConfig( ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" );
1431 ConfigureDialog->addModule(kabcfg ); 1431 ConfigureDialog->addModule(kabcfg );
1432 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); 1432 KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" );
1433 ConfigureDialog->addModule(kdelibcfg ); 1433 ConfigureDialog->addModule(kdelibcfg );
1434 1434
1435 connect( ConfigureDialog, SIGNAL( applyClicked() ), 1435 connect( ConfigureDialog, SIGNAL( applyClicked() ),
1436 this, SLOT( configurationChanged() ) ); 1436 this, SLOT( configurationChanged() ) );
1437 connect( ConfigureDialog, SIGNAL( okClicked() ), 1437 connect( ConfigureDialog, SIGNAL( okClicked() ),
1438 this, SLOT( configurationChanged() ) ); 1438 this, SLOT( configurationChanged() ) );
1439 saveSettings(); 1439 saveSettings();
1440#ifndef DESKTOP_VERSION 1440#ifndef DESKTOP_VERSION
1441 ConfigureDialog->showMaximized(); 1441 ConfigureDialog->showMaximized();
1442#endif 1442#endif
1443 if ( ConfigureDialog->exec() ) 1443 if ( ConfigureDialog->exec() )
1444 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); 1444 KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") );
1445 delete ConfigureDialog; 1445 delete ConfigureDialog;
1446} 1446}
1447 1447
1448void KABCore::openLDAPDialog() 1448void KABCore::openLDAPDialog()
1449{ 1449{
1450#ifndef KAB_EMBEDDED 1450#ifndef KAB_EMBEDDED
1451 if ( !mLdapSearchDialog ) { 1451 if ( !mLdapSearchDialog ) {
1452 mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this ); 1452 mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this );
1453 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager, 1453 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager,
1454 SLOT( refreshView() ) ); 1454 SLOT( refreshView() ) );
1455 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this, 1455 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this,
1456 SLOT( setModified() ) ); 1456 SLOT( setModified() ) );
1457 } else 1457 } else
1458 mLdapSearchDialog->restoreSettings(); 1458 mLdapSearchDialog->restoreSettings();
1459 1459
1460 if ( mLdapSearchDialog->isOK() ) 1460 if ( mLdapSearchDialog->isOK() )
1461 mLdapSearchDialog->exec(); 1461 mLdapSearchDialog->exec();
1462#else //KAB_EMBEDDED 1462#else //KAB_EMBEDDED
1463 qDebug("KABCore::openLDAPDialog() finsih method"); 1463 qDebug("KABCore::openLDAPDialog() finsih method");
1464#endif //KAB_EMBEDDED 1464#endif //KAB_EMBEDDED
1465} 1465}
1466 1466
1467void KABCore::print() 1467void KABCore::print()
1468{ 1468{
1469#ifndef KAB_EMBEDDED 1469#ifndef KAB_EMBEDDED
1470 KPrinter printer; 1470 KPrinter printer;
1471 if ( !printer.setup( this ) ) 1471 if ( !printer.setup( this ) )
1472 return; 1472 return;
1473 1473
1474 KABPrinting::PrintingWizard wizard( &printer, mAddressBook, 1474 KABPrinting::PrintingWizard wizard( &printer, mAddressBook,
1475 mViewManager->selectedUids(), this ); 1475 mViewManager->selectedUids(), this );
1476 1476
1477 wizard.exec(); 1477 wizard.exec();
1478#else //KAB_EMBEDDED 1478#else //KAB_EMBEDDED
1479 qDebug("KABCore::print() finsih method"); 1479 qDebug("KABCore::print() finsih method");
1480#endif //KAB_EMBEDDED 1480#endif //KAB_EMBEDDED
1481 1481
1482} 1482}
1483 1483
1484 1484
1485void KABCore::addGUIClient( KXMLGUIClient *client ) 1485void KABCore::addGUIClient( KXMLGUIClient *client )
1486{ 1486{
1487 if ( mGUIClient ) 1487 if ( mGUIClient )
1488 mGUIClient->insertChildClient( client ); 1488 mGUIClient->insertChildClient( client );
1489 else 1489 else
1490 KMessageBox::error( this, "no KXMLGUICLient"); 1490 KMessageBox::error( this, "no KXMLGUICLient");
1491} 1491}
1492 1492
1493 1493
1494void KABCore::configurationChanged() 1494void KABCore::configurationChanged()
1495{ 1495{
1496 mExtensionManager->reconfigure(); 1496 mExtensionManager->reconfigure();
1497} 1497}
1498 1498
1499void KABCore::addressBookChanged() 1499void KABCore::addressBookChanged()
1500{ 1500{
1501/*US 1501/*US
1502 QDictIterator<AddresseeEditorDialog> it( mEditorDict ); 1502 QDictIterator<AddresseeEditorDialog> it( mEditorDict );
1503 while ( it.current() ) { 1503 while ( it.current() ) {
1504 if ( it.current()->dirty() ) { 1504 if ( it.current()->dirty() ) {
1505 QString text = i18n( "Data has been changed externally. Unsaved " 1505 QString text = i18n( "Data has been changed externally. Unsaved "
1506 "changes will be lost." ); 1506 "changes will be lost." );
1507 KMessageBox::information( this, text ); 1507 KMessageBox::information( this, text );
1508 } 1508 }
1509 it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) ); 1509 it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) );
1510 ++it; 1510 ++it;
1511 } 1511 }
1512*/ 1512*/
1513 if (mEditorDialog) 1513 if (mEditorDialog)
1514 { 1514 {
1515 if (mEditorDialog->dirty()) 1515 if (mEditorDialog->dirty())
1516 { 1516 {
1517 QString text = i18n( "Data has been changed externally. Unsaved " 1517 QString text = i18n( "Data has been changed externally. Unsaved "
1518 "changes will be lost." ); 1518 "changes will be lost." );
1519 KMessageBox::information( this, text ); 1519 KMessageBox::information( this, text );
1520 } 1520 }
1521 QString currentuid = mEditorDialog->addressee().uid(); 1521 QString currentuid = mEditorDialog->addressee().uid();
1522 mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) ); 1522 mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) );
1523 } 1523 }
1524 mViewManager->refreshView(); 1524 mViewManager->refreshView();
1525// mDetails->refreshView(); 1525// mDetails->refreshView();
1526 1526
1527 1527
1528} 1528}
1529 1529
1530AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent, 1530AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent,
1531 const char *name ) 1531 const char *name )
1532{ 1532{
1533 1533
1534 if ( mEditorDialog == 0 ) { 1534 if ( mEditorDialog == 0 ) {
1535 mEditorDialog = new AddresseeEditorDialog( this, parent, 1535 mEditorDialog = new AddresseeEditorDialog( this, parent,
1536 name ? name : "editorDialog" ); 1536 name ? name : "editorDialog" );
1537 1537
1538 1538
1539 connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ), 1539 connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ),
1540 SLOT( contactModified( const KABC::Addressee& ) ) ); 1540 SLOT( contactModified( const KABC::Addressee& ) ) );
1541 //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ), 1541 //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ),
1542 // SLOT( slotEditorDestroyed( const QString& ) ) ; 1542 // SLOT( slotEditorDestroyed( const QString& ) ) ;
1543 } 1543 }
1544 1544
1545 return mEditorDialog; 1545 return mEditorDialog;
1546} 1546}
1547 1547
1548void KABCore::slotEditorDestroyed( const QString &uid ) 1548void KABCore::slotEditorDestroyed( const QString &uid )
1549{ 1549{
1550 //mEditorDict.remove( uid ); 1550 //mEditorDict.remove( uid );
1551} 1551}
1552 1552
1553void KABCore::initGUI() 1553void KABCore::initGUI()
1554{ 1554{
1555#ifndef KAB_EMBEDDED 1555#ifndef KAB_EMBEDDED
1556 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1556 QHBoxLayout *topLayout = new QHBoxLayout( this );
1557 topLayout->setSpacing( KDialogBase::spacingHint() ); 1557 topLayout->setSpacing( KDialogBase::spacingHint() );
1558 1558
1559 mExtensionBarSplitter = new QSplitter( this ); 1559 mExtensionBarSplitter = new QSplitter( this );
1560 mExtensionBarSplitter->setOrientation( Qt::Vertical ); 1560 mExtensionBarSplitter->setOrientation( Qt::Vertical );
1561 1561
1562 mDetailsSplitter = new QSplitter( mExtensionBarSplitter ); 1562 mDetailsSplitter = new QSplitter( mExtensionBarSplitter );
1563 1563
1564 QVBox *viewSpace = new QVBox( mDetailsSplitter ); 1564 QVBox *viewSpace = new QVBox( mDetailsSplitter );
1565 mIncSearchWidget = new IncSearchWidget( viewSpace ); 1565 mIncSearchWidget = new IncSearchWidget( viewSpace );
1566 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 1566 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1567 SLOT( incrementalSearch( const QString& ) ) ); 1567 SLOT( incrementalSearch( const QString& ) ) );
1568 1568
1569 mViewManager = new ViewManager( this, viewSpace ); 1569 mViewManager = new ViewManager( this, viewSpace );
1570 viewSpace->setStretchFactor( mViewManager, 1 ); 1570 viewSpace->setStretchFactor( mViewManager, 1 );
1571 1571
1572 mDetails = new ViewContainer( mDetailsSplitter ); 1572 mDetails = new ViewContainer( mDetailsSplitter );
1573 1573
1574 mJumpButtonBar = new JumpButtonBar( this, this ); 1574 mJumpButtonBar = new JumpButtonBar( this, this );
1575 1575
1576 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); 1576 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter );
1577 1577
1578 topLayout->addWidget( mExtensionBarSplitter ); 1578 topLayout->addWidget( mExtensionBarSplitter );
1579 topLayout->setStretchFactor( mExtensionBarSplitter, 100 ); 1579 topLayout->setStretchFactor( mExtensionBarSplitter, 100 );
1580 topLayout->addWidget( mJumpButtonBar ); 1580 topLayout->addWidget( mJumpButtonBar );
1581 topLayout->setStretchFactor( mJumpButtonBar, 1 ); 1581 topLayout->setStretchFactor( mJumpButtonBar, 1 );
1582 1582
1583 mXXPortManager = new XXPortManager( this, this ); 1583 mXXPortManager = new XXPortManager( this, this );
1584 1584
1585#else //KAB_EMBEDDED 1585#else //KAB_EMBEDDED
1586 //US initialize viewMenu before settingup viewmanager. 1586 //US initialize viewMenu before settingup viewmanager.
1587 // Viewmanager needs this menu to plugin submenues. 1587 // Viewmanager needs this menu to plugin submenues.
1588 viewMenu = new QPopupMenu( this ); 1588 viewMenu = new QPopupMenu( this );
1589 settingsMenu = new QPopupMenu( this ); 1589 settingsMenu = new QPopupMenu( this );
1590 //filterMenu = new QPopupMenu( this ); 1590 //filterMenu = new QPopupMenu( this );
1591 ImportMenu = new QPopupMenu( this ); 1591 ImportMenu = new QPopupMenu( this );
1592 ExportMenu = new QPopupMenu( this ); 1592 ExportMenu = new QPopupMenu( this );
1593 syncMenu = new QPopupMenu( this ); 1593 syncMenu = new QPopupMenu( this );
1594 changeMenu= new QPopupMenu( this ); 1594 changeMenu= new QPopupMenu( this );
1595 1595
1596//US since we have no splitter for the embedded system, setup 1596//US since we have no splitter for the embedded system, setup
1597// a layout with two frames. One left and one right. 1597// a layout with two frames. One left and one right.
1598 1598
1599 QBoxLayout *topLayout; 1599 QBoxLayout *topLayout;
1600 1600
1601 // = new QHBoxLayout( this ); 1601 // = new QHBoxLayout( this );
1602// QBoxLayout *topLayout = (QBoxLayout*)layout(); 1602// QBoxLayout *topLayout = (QBoxLayout*)layout();
1603 1603
1604// QWidget *mainBox = new QWidget( this ); 1604// QWidget *mainBox = new QWidget( this );
1605// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox); 1605// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox);
1606 1606
1607#ifdef DESKTOP_VERSION 1607#ifdef DESKTOP_VERSION
1608 topLayout = new QHBoxLayout( this ); 1608 topLayout = new QHBoxLayout( this );
1609 1609
1610 1610
1611 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 1611 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
1612 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 1612 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
1613 1613
1614 topLayout->addWidget(mMiniSplitter ); 1614 topLayout->addWidget(mMiniSplitter );
1615 1615
1616 mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter ); 1616 mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter );
1617 mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); 1617 mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
1618 mViewManager = new ViewManager( this, mExtensionBarSplitter ); 1618 mViewManager = new ViewManager( this, mExtensionBarSplitter );
1619 mDetails = new ViewContainer( mMiniSplitter ); 1619 mDetails = new ViewContainer( mMiniSplitter );
1620 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); 1620 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter );
1621#else 1621#else
1622 if ( QApplication::desktop()->width() > 480 ) { 1622 if ( QApplication::desktop()->width() > 480 ) {
1623 topLayout = new QHBoxLayout( this ); 1623 topLayout = new QHBoxLayout( this );
1624 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 1624 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
1625 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 1625 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
1626 } else { 1626 } else {
1627 1627
1628 topLayout = new QHBoxLayout( this ); 1628 topLayout = new QHBoxLayout( this );
1629 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); 1629 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this);
1630 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); 1630 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
1631 } 1631 }
1632 1632
1633 topLayout->addWidget(mMiniSplitter ); 1633 topLayout->addWidget(mMiniSplitter );
1634 mViewManager = new ViewManager( this, mMiniSplitter ); 1634 mViewManager = new ViewManager( this, mMiniSplitter );
1635 mDetails = new ViewContainer( mMiniSplitter ); 1635 mDetails = new ViewContainer( mMiniSplitter );
1636 1636
1637 1637
1638 mExtensionManager = new ExtensionManager( this, mMiniSplitter ); 1638 mExtensionManager = new ExtensionManager( this, mMiniSplitter );
1639#endif 1639#endif
1640 //eh->hide(); 1640 //eh->hide();
1641 // topLayout->addWidget(mExtensionManager ); 1641 // topLayout->addWidget(mExtensionManager );
1642 1642
1643 1643
1644/*US 1644/*US
1645#ifndef KAB_NOSPLITTER 1645#ifndef KAB_NOSPLITTER
1646 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1646 QHBoxLayout *topLayout = new QHBoxLayout( this );
1647//US topLayout->setSpacing( KDialogBase::spacingHint() ); 1647//US topLayout->setSpacing( KDialogBase::spacingHint() );
1648 topLayout->setSpacing( 10 ); 1648 topLayout->setSpacing( 10 );
1649 1649
1650 mDetailsSplitter = new QSplitter( this ); 1650 mDetailsSplitter = new QSplitter( this );
1651 1651
1652 QVBox *viewSpace = new QVBox( mDetailsSplitter ); 1652 QVBox *viewSpace = new QVBox( mDetailsSplitter );
1653 1653
1654 mViewManager = new ViewManager( this, viewSpace ); 1654 mViewManager = new ViewManager( this, viewSpace );
1655 viewSpace->setStretchFactor( mViewManager, 1 ); 1655 viewSpace->setStretchFactor( mViewManager, 1 );
1656 1656
1657 mDetails = new ViewContainer( mDetailsSplitter ); 1657 mDetails = new ViewContainer( mDetailsSplitter );
1658 1658
1659 topLayout->addWidget( mDetailsSplitter ); 1659 topLayout->addWidget( mDetailsSplitter );
1660 topLayout->setStretchFactor( mDetailsSplitter, 100 ); 1660 topLayout->setStretchFactor( mDetailsSplitter, 100 );
1661#else //KAB_NOSPLITTER 1661#else //KAB_NOSPLITTER
1662 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1662 QHBoxLayout *topLayout = new QHBoxLayout( this );
1663//US topLayout->setSpacing( KDialogBase::spacingHint() ); 1663//US topLayout->setSpacing( KDialogBase::spacingHint() );
1664 topLayout->setSpacing( 10 ); 1664 topLayout->setSpacing( 10 );
1665 1665
1666// mDetailsSplitter = new QSplitter( this ); 1666// mDetailsSplitter = new QSplitter( this );
1667 1667
1668 QVBox *viewSpace = new QVBox( this ); 1668 QVBox *viewSpace = new QVBox( this );
1669 1669
1670 mViewManager = new ViewManager( this, viewSpace ); 1670 mViewManager = new ViewManager( this, viewSpace );
1671 viewSpace->setStretchFactor( mViewManager, 1 ); 1671 viewSpace->setStretchFactor( mViewManager, 1 );
1672 1672
1673 mDetails = new ViewContainer( this ); 1673 mDetails = new ViewContainer( this );
1674 1674
1675 topLayout->addWidget( viewSpace ); 1675 topLayout->addWidget( viewSpace );
1676// topLayout->setStretchFactor( mDetailsSplitter, 100 ); 1676// topLayout->setStretchFactor( mDetailsSplitter, 100 );
1677 topLayout->addWidget( mDetails ); 1677 topLayout->addWidget( mDetails );
1678#endif //KAB_NOSPLITTER 1678#endif //KAB_NOSPLITTER
1679*/ 1679*/
1680 1680
1681 syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); 1681 syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu);
1682 syncManager->setBlockSave(false); 1682 syncManager->setBlockSave(false);
1683 1683
1684 connect(syncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) ); 1684 connect(syncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) );
1685 connect(syncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) ); 1685 connect(syncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) );
1686 syncManager->setDefaultFileName( sentSyncFile()); 1686 syncManager->setDefaultFileName( sentSyncFile());
1687 //connect(syncManager , SIGNAL( ), this, SLOT( ) ); 1687 //connect(syncManager , SIGNAL( ), this, SLOT( ) );
1688 1688
1689#endif //KAB_EMBEDDED 1689#endif //KAB_EMBEDDED
1690 initActions(); 1690 initActions();
1691 1691
1692#ifdef KAB_EMBEDDED 1692#ifdef KAB_EMBEDDED
1693 addActionsManually(); 1693 addActionsManually();
1694 //US make sure the export and import menues are initialized before creating the xxPortManager. 1694 //US make sure the export and import menues are initialized before creating the xxPortManager.
1695 mXXPortManager = new XXPortManager( this, this ); 1695 mXXPortManager = new XXPortManager( this, this );
1696 1696
1697 // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() ); 1697 // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() );
1698 //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget); 1698 //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget);
1699 // mActionQuit->plug ( mMainWindow->toolBar()); 1699 // mActionQuit->plug ( mMainWindow->toolBar());
1700 //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() ); 1700 //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() );
1701 //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget); 1701 //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget);
1702 // mIncSearchWidget->hide(); 1702 // mIncSearchWidget->hide();
1703 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 1703 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1704 SLOT( incrementalSearch( const QString& ) ) ); 1704 SLOT( incrementalSearch( const QString& ) ) );
1705 connect( mIncSearchWidget, SIGNAL( scrollUP() ),mViewManager, SLOT( scrollUP() ) ); 1705 connect( mIncSearchWidget, SIGNAL( scrollUP() ),mViewManager, SLOT( scrollUP() ) );
1706 connect( mIncSearchWidget, SIGNAL( scrollDOWN() ),mViewManager, SLOT( scrollDOWN() ) ); 1706 connect( mIncSearchWidget, SIGNAL( scrollDOWN() ),mViewManager, SLOT( scrollDOWN() ) );
1707 1707
1708 mJumpButtonBar = new JumpButtonBar( this, this ); 1708 mJumpButtonBar = new JumpButtonBar( this, this );
1709 1709
1710 topLayout->addWidget( mJumpButtonBar ); 1710 topLayout->addWidget( mJumpButtonBar );
1711//US topLayout->setStretchFactor( mJumpButtonBar, 10 ); 1711//US topLayout->setStretchFactor( mJumpButtonBar, 10 );
1712 1712
1713// mMainWindow->getIconToolBar()->raise(); 1713// mMainWindow->getIconToolBar()->raise();
1714 1714
1715#endif //KAB_EMBEDDED 1715#endif //KAB_EMBEDDED
1716 1716
1717} 1717}
1718void KABCore::initActions() 1718void KABCore::initActions()
1719{ 1719{
1720//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); 1720//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
1721 1721
1722#ifndef KAB_EMBEDDED 1722#ifndef KAB_EMBEDDED
1723 connect( QApplication::clipboard(), SIGNAL( dataChanged() ), 1723 connect( QApplication::clipboard(), SIGNAL( dataChanged() ),
1724 SLOT( clipboardDataChanged() ) ); 1724 SLOT( clipboardDataChanged() ) );
1725#endif //KAB_EMBEDDED 1725#endif //KAB_EMBEDDED
1726 1726
1727 // file menu 1727 // file menu
1728 if ( mIsPart ) { 1728 if ( mIsPart ) {
1729 mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, 1729 mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this,
1730 SLOT( sendMail() ), actionCollection(), 1730 SLOT( sendMail() ), actionCollection(),
1731 "kaddressbook_mail" ); 1731 "kaddressbook_mail" );
1732 mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, 1732 mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this,
1733 SLOT( print() ), actionCollection(), "kaddressbook_print" ); 1733 SLOT( print() ), actionCollection(), "kaddressbook_print" );
1734 1734
1735 } else { 1735 } else {
1736 mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); 1736 mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() );
1737 mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); 1737 mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() );
1738 } 1738 }
1739 1739
1740 1740
1741 mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, 1741 mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this,
1742 SLOT( save() ), actionCollection(), "file_sync" ); 1742 SLOT( save() ), actionCollection(), "file_sync" );
1743 1743
1744 mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, 1744 mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this,
1745 SLOT( newContact() ), actionCollection(), "file_new_contact" ); 1745 SLOT( newContact() ), actionCollection(), "file_new_contact" );
1746 1746
1747 mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, 1747 mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0,
1748 this, SLOT( mailVCard() ), 1748 this, SLOT( mailVCard() ),
1749 actionCollection(), "file_mail_vcard"); 1749 actionCollection(), "file_mail_vcard");
1750 1750
1751 mActionExport2phone = new KAction( i18n( "Selected to phone" ), "ex2phone", 0, this, 1751 mActionExport2phone = new KAction( i18n( "Selected to phone" ), "ex2phone", 0, this,
1752 SLOT( export2phone() ), actionCollection(), 1752 SLOT( export2phone() ), actionCollection(),
1753 "kaddressbook_ex2phone" ); 1753 "kaddressbook_ex2phone" );
1754 1754
1755 mActionBeamVCard = 0; 1755 mActionBeamVCard = 0;
1756 mActionBeam = 0; 1756 mActionBeam = 0;
1757 1757
1758#ifndef DESKTOP_VERSION 1758#ifndef DESKTOP_VERSION
1759 if ( Ir::supported() ) { 1759 if ( Ir::supported() ) {
1760 mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this, 1760 mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this,
1761 SLOT( beamVCard() ), actionCollection(), 1761 SLOT( beamVCard() ), actionCollection(),
1762 "kaddressbook_beam_vcard" ); 1762 "kaddressbook_beam_vcard" );
1763 1763
1764 mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this, 1764 mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this,
1765 SLOT( beamMySelf() ), actionCollection(), 1765 SLOT( beamMySelf() ), actionCollection(),
1766 "kaddressbook_beam_myself" ); 1766 "kaddressbook_beam_myself" );
1767 } 1767 }
1768#endif 1768#endif
1769 1769
1770 mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, 1770 mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0,
1771 this, SLOT( editContact2() ), 1771 this, SLOT( editContact2() ),
1772 actionCollection(), "file_properties" ); 1772 actionCollection(), "file_properties" );
1773 1773
1774#ifdef KAB_EMBEDDED 1774#ifdef KAB_EMBEDDED
1775 // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); 1775 // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() );
1776 mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, 1776 mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0,
1777 mMainWindow, SLOT( exit() ), 1777 mMainWindow, SLOT( exit() ),
1778 actionCollection(), "quit" ); 1778 actionCollection(), "quit" );
1779#endif //KAB_EMBEDDED 1779#endif //KAB_EMBEDDED
1780 1780
1781 // edit menu 1781 // edit menu
1782 if ( mIsPart ) { 1782 if ( mIsPart ) {
1783 mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, 1783 mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this,
1784 SLOT( copyContacts() ), actionCollection(), 1784 SLOT( copyContacts() ), actionCollection(),
1785 "kaddressbook_copy" ); 1785 "kaddressbook_copy" );
1786 mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this, 1786 mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this,
1787 SLOT( cutContacts() ), actionCollection(), 1787 SLOT( cutContacts() ), actionCollection(),
1788 "kaddressbook_cut" ); 1788 "kaddressbook_cut" );
1789 mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this, 1789 mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this,
1790 SLOT( pasteContacts() ), actionCollection(), 1790 SLOT( pasteContacts() ), actionCollection(),
1791 "kaddressbook_paste" ); 1791 "kaddressbook_paste" );
1792 mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this, 1792 mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this,
1793 SLOT( selectAllContacts() ), actionCollection(), 1793 SLOT( selectAllContacts() ), actionCollection(),
1794 "kaddressbook_select_all" ); 1794 "kaddressbook_select_all" );
1795 mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this, 1795 mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this,
1796 SLOT( undo() ), actionCollection(), 1796 SLOT( undo() ), actionCollection(),
1797 "kaddressbook_undo" ); 1797 "kaddressbook_undo" );
1798 mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z, 1798 mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z,
1799 this, SLOT( redo() ), actionCollection(), 1799 this, SLOT( redo() ), actionCollection(),
1800 "kaddressbook_redo" ); 1800 "kaddressbook_redo" );
1801 } else { 1801 } else {
1802 mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() ); 1802 mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() );
1803 mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() ); 1803 mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() );
1804 mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() ); 1804 mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() );
1805 mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() ); 1805 mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() );
1806 mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() ); 1806 mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() );
1807 mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() ); 1807 mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() );
1808 } 1808 }
1809 1809
1810 mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete", 1810 mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete",
1811 Key_Delete, this, SLOT( deleteContacts() ), 1811 Key_Delete, this, SLOT( deleteContacts() ),
1812 actionCollection(), "edit_delete" ); 1812 actionCollection(), "edit_delete" );
1813 1813
1814 mActionUndo->setEnabled( false ); 1814 mActionUndo->setEnabled( false );
1815 mActionRedo->setEnabled( false ); 1815 mActionRedo->setEnabled( false );
1816 1816
1817 // settings menu 1817 // settings menu
1818#ifdef KAB_EMBEDDED 1818#ifdef KAB_EMBEDDED
1819//US special menuentry to configure the addressbook resources. On KDE 1819//US special menuentry to configure the addressbook resources. On KDE
1820// you do that through the control center !!! 1820// you do that through the control center !!!
1821 mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this, 1821 mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this,
1822 SLOT( configureResources() ), actionCollection(), 1822 SLOT( configureResources() ), actionCollection(),
1823 "kaddressbook_configure_resources" ); 1823 "kaddressbook_configure_resources" );
1824#endif //KAB_EMBEDDED 1824#endif //KAB_EMBEDDED
1825 1825
1826 if ( mIsPart ) { 1826 if ( mIsPart ) {
1827 mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this, 1827 mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this,
1828 SLOT( openConfigDialog() ), actionCollection(), 1828 SLOT( openConfigDialog() ), actionCollection(),
1829 "kaddressbook_configure" ); 1829 "kaddressbook_configure" );
1830 1830
1831 //US not implemented yet 1831 //US not implemented yet
1832 //mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0, 1832 //mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0,
1833 // this, SLOT( configureKeyBindings() ), actionCollection(), 1833 // this, SLOT( configureKeyBindings() ), actionCollection(),
1834 // "kaddressbook_configure_shortcuts" ); 1834 // "kaddressbook_configure_shortcuts" );
1835#ifdef KAB_EMBEDDED 1835#ifdef KAB_EMBEDDED
1836 mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() ); 1836 mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() );
1837 mActionConfigureToolbars->setEnabled( false ); 1837 mActionConfigureToolbars->setEnabled( false );
1838#endif //KAB_EMBEDDED 1838#endif //KAB_EMBEDDED
1839 1839
1840 } else { 1840 } else {
1841 mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() ); 1841 mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() );
1842 1842
1843 //US not implemented yet 1843 //US not implemented yet
1844 //mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() ); 1844 //mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() );
1845 } 1845 }
1846 1846
1847 mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0, 1847 mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0,
1848 actionCollection(), "options_show_jump_bar" ); 1848 actionCollection(), "options_show_jump_bar" );
1849 connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) ); 1849 connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) );
1850 1850
1851 mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0, 1851 mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0,
1852 actionCollection(), "options_show_details" ); 1852 actionCollection(), "options_show_details" );
1853 connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) ); 1853 connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) );
1854 1854
1855 1855
1856 mActionBR = new KToggleAction( i18n( "Beam receive enabled" ), "beam", 0, this, 1856 mActionBR = new KToggleAction( i18n( "Beam receive enabled" ), "beam", 0, this,
1857 SLOT( toggleBeamReceive() ), actionCollection(), 1857 SLOT( toggleBeamReceive() ), actionCollection(),
1858 "kaddressbook_beam_rec" ); 1858 "kaddressbook_beam_rec" );
1859 1859
1860 1860
1861 // misc 1861 // misc
1862 // only enable LDAP lookup if we can handle the protocol 1862 // only enable LDAP lookup if we can handle the protocol
1863#ifndef KAB_EMBEDDED 1863#ifndef KAB_EMBEDDED
1864 if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) { 1864 if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) {
1865 new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0, 1865 new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0,
1866 this, SLOT( openLDAPDialog() ), actionCollection(), 1866 this, SLOT( openLDAPDialog() ), actionCollection(),
1867 "ldap_lookup" ); 1867 "ldap_lookup" );
1868 } 1868 }
1869#else //KAB_EMBEDDED 1869#else //KAB_EMBEDDED
1870 //qDebug("KABCore::initActions() LDAP has to be implemented"); 1870 //qDebug("KABCore::initActions() LDAP has to be implemented");
1871#endif //KAB_EMBEDDED 1871#endif //KAB_EMBEDDED
1872 1872
1873 1873
1874 mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, 1874 mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this,
1875 SLOT( setWhoAmI() ), actionCollection(), 1875 SLOT( setWhoAmI() ), actionCollection(),
1876 "set_personal" ); 1876 "set_personal" );
1877 1877
1878 1878
1879 1879
1880 1880
1881 mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, 1881 mActionCategories = new KAction( i18n( "Set Categories" ), 0, this,
1882 SLOT( setCategories() ), actionCollection(), 1882 SLOT( setCategories() ), actionCollection(),
1883 "edit_set_categories" ); 1883 "edit_set_categories" );
1884 1884
1885 mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, 1885 mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this,
1886 SLOT( removeVoice() ), actionCollection(), 1886 SLOT( removeVoice() ), actionCollection(),
1887 "remove_voice" ); 1887 "remove_voice" );
1888 mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this, 1888 mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this,
1889 SLOT( importFromOL() ), actionCollection(), 1889 SLOT( importFromOL() ), actionCollection(),
1890 "import_OL" ); 1890 "import_OL" );
1891#ifdef KAB_EMBEDDED 1891#ifdef KAB_EMBEDDED
1892 mActionLicence = new KAction( i18n( "Licence" ), 0, 1892 mActionLicence = new KAction( i18n( "Licence" ), 0,
1893 this, SLOT( showLicence() ), actionCollection(), 1893 this, SLOT( showLicence() ), actionCollection(),
1894 "licence_about_data" ); 1894 "licence_about_data" );
1895 mActionFaq = new KAction( i18n( "Faq" ), 0, 1895 mActionFaq = new KAction( i18n( "Faq" ), 0,
1896 this, SLOT( faq() ), actionCollection(), 1896 this, SLOT( faq() ), actionCollection(),
1897 "faq_about_data" ); 1897 "faq_about_data" );
1898 mActionWN = new KAction( i18n( "What's New?" ), 0, 1898 mActionWN = new KAction( i18n( "What's New?" ), 0,
1899 this, SLOT( whatsnew() ), actionCollection(), 1899 this, SLOT( whatsnew() ), actionCollection(),
1900 "wn" ); 1900 "wn" );
1901 mActionSyncHowto = new KAction( i18n( "Sync HowTo" ), 0, 1901 mActionSyncHowto = new KAction( i18n( "Sync HowTo" ), 0,
1902 this, SLOT( synchowto() ), actionCollection(), 1902 this, SLOT( synchowto() ), actionCollection(),
1903 "sync" ); 1903 "sync" );
1904 mActionKdeSyncHowto = new KAction( i18n( "Kde Sync HowTo" ), 0, 1904 mActionKdeSyncHowto = new KAction( i18n( "Kde Sync HowTo" ), 0,
1905 this, SLOT( kdesynchowto() ), actionCollection(), 1905 this, SLOT( kdesynchowto() ), actionCollection(),
1906 "kdesync" ); 1906 "kdesync" );
1907 mActionMultiSyncHowto = new KAction( i18n( "Multi Sync HowTo" ), 0, 1907 mActionMultiSyncHowto = new KAction( i18n( "Multi Sync HowTo" ), 0,
1908 this, SLOT( multisynchowto() ), actionCollection(), 1908 this, SLOT( multisynchowto() ), actionCollection(),
1909 "multisync" ); 1909 "multisync" );
1910 1910
1911 mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0, 1911 mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0,
1912 this, SLOT( createAboutData() ), actionCollection(), 1912 this, SLOT( createAboutData() ), actionCollection(),
1913 "kaddressbook_about_data" ); 1913 "kaddressbook_about_data" );
1914#endif //KAB_EMBEDDED 1914#endif //KAB_EMBEDDED
1915 1915
1916 clipboardDataChanged(); 1916 clipboardDataChanged();
1917 connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); 1917 connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
1918 connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); 1918 connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
1919} 1919}
1920 1920
1921//US we need this function, to plug all actions into the correct menues. 1921//US we need this function, to plug all actions into the correct menues.
1922// KDE uses a XML format to plug the actions, but we work her without this overhead. 1922// KDE uses a XML format to plug the actions, but we work her without this overhead.
1923void KABCore::addActionsManually() 1923void KABCore::addActionsManually()
1924{ 1924{
1925//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); 1925//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
1926 1926
1927#ifdef KAB_EMBEDDED 1927#ifdef KAB_EMBEDDED
1928 QPopupMenu *fileMenu = new QPopupMenu( this ); 1928 QPopupMenu *fileMenu = new QPopupMenu( this );
1929 QPopupMenu *editMenu = new QPopupMenu( this ); 1929 QPopupMenu *editMenu = new QPopupMenu( this );
1930 QPopupMenu *helpMenu = new QPopupMenu( this ); 1930 QPopupMenu *helpMenu = new QPopupMenu( this );
1931 1931
1932 KToolBar* tb = mMainWindow->toolBar(); 1932 KToolBar* tb = mMainWindow->toolBar();
1933 1933
1934#ifndef DESKTOP_VERSION 1934#ifndef DESKTOP_VERSION
1935 if ( KABPrefs::instance()->mFullMenuBarVisible ) { 1935 if ( KABPrefs::instance()->mFullMenuBarVisible ) {
1936#endif 1936#endif
1937 QMenuBar* mb = mMainWindow->menuBar(); 1937 QMenuBar* mb = mMainWindow->menuBar();
1938 1938
1939 //US setup menubar. 1939 //US setup menubar.
1940 //Disable the following block if you do not want to have a menubar. 1940 //Disable the following block if you do not want to have a menubar.
1941 mb->insertItem( "&File", fileMenu ); 1941 mb->insertItem( "&File", fileMenu );
1942 mb->insertItem( "&Edit", editMenu ); 1942 mb->insertItem( "&Edit", editMenu );
1943 mb->insertItem( "&View", viewMenu ); 1943 mb->insertItem( "&View", viewMenu );
1944 mb->insertItem( "&Settings", settingsMenu ); 1944 mb->insertItem( "&Settings", settingsMenu );
1945 mb->insertItem( i18n("Synchronize"), syncMenu ); 1945 mb->insertItem( i18n("Synchronize"), syncMenu );
1946 mb->insertItem( "&Change selected", changeMenu ); 1946 mb->insertItem( "&Change selected", changeMenu );
1947 mb->insertItem( "&Help", helpMenu ); 1947 mb->insertItem( "&Help", helpMenu );
1948 mIncSearchWidget = new IncSearchWidget( tb ); 1948 mIncSearchWidget = new IncSearchWidget( tb );
1949 // tb->insertWidget(-1, 0, mIncSearchWidget); 1949 // tb->insertWidget(-1, 0, mIncSearchWidget);
1950#ifndef DESKTOP_VERSION 1950#ifndef DESKTOP_VERSION
1951 } else { 1951 } else {
1952 //US setup toolbar 1952 //US setup toolbar
1953 QPEMenuBar *menuBarTB = new QPEMenuBar( tb ); 1953 QPEMenuBar *menuBarTB = new QPEMenuBar( tb );
1954 QPopupMenu *popupBarTB = new QPopupMenu( this ); 1954 QPopupMenu *popupBarTB = new QPopupMenu( this );
1955 menuBarTB->insertItem( "ME", popupBarTB); 1955 menuBarTB->insertItem( "ME", popupBarTB);
1956 tb->insertWidget(-1, 0, menuBarTB); 1956 tb->insertWidget(-1, 0, menuBarTB);
1957 mIncSearchWidget = new IncSearchWidget( tb ); 1957 mIncSearchWidget = new IncSearchWidget( tb );
1958 1958
1959 tb->enableMoving(false); 1959 tb->enableMoving(false);
1960 popupBarTB->insertItem( "&File", fileMenu ); 1960 popupBarTB->insertItem( "&File", fileMenu );
1961 popupBarTB->insertItem( "&Edit", editMenu ); 1961 popupBarTB->insertItem( "&Edit", editMenu );
1962 popupBarTB->insertItem( "&View", viewMenu ); 1962 popupBarTB->insertItem( "&View", viewMenu );
1963 popupBarTB->insertItem( "&Settings", settingsMenu ); 1963 popupBarTB->insertItem( "&Settings", settingsMenu );
1964 popupBarTB->insertItem( i18n("Synchronize"), syncMenu ); 1964 popupBarTB->insertItem( i18n("Synchronize"), syncMenu );
1965 mViewManager->getFilterAction()->plug ( popupBarTB); 1965 mViewManager->getFilterAction()->plug ( popupBarTB);
1966 popupBarTB->insertItem( "&Change selected", changeMenu ); 1966 popupBarTB->insertItem( "&Change selected", changeMenu );
1967 popupBarTB->insertItem( "&Help", helpMenu ); 1967 popupBarTB->insertItem( "&Help", helpMenu );
1968 if (QApplication::desktop()->width() > 320 ) { 1968 if (QApplication::desktop()->width() > 320 ) {
1969 // mViewManager->getFilterAction()->plug ( tb); 1969 // mViewManager->getFilterAction()->plug ( tb);
1970 } 1970 }
1971 } 1971 }
1972#endif 1972#endif
1973 // mActionQuit->plug ( mMainWindow->toolBar()); 1973 // mActionQuit->plug ( mMainWindow->toolBar());
1974 1974
1975 1975
1976 1976
1977 //US Now connect the actions with the menue entries. 1977 //US Now connect the actions with the menue entries.
1978 mActionPrint->plug( fileMenu ); 1978 mActionPrint->plug( fileMenu );
1979 mActionMail->plug( fileMenu ); 1979 mActionMail->plug( fileMenu );
1980 fileMenu->insertSeparator(); 1980 fileMenu->insertSeparator();
1981 1981
1982 mActionNewContact->plug( fileMenu ); 1982 mActionNewContact->plug( fileMenu );
1983 mActionNewContact->plug( tb ); 1983 mActionNewContact->plug( tb );
1984 1984
1985 mActionEditAddressee->plug( fileMenu ); 1985 mActionEditAddressee->plug( fileMenu );
1986 // if ((KGlobal::getDesktopSize() > KGlobal::Small ) || 1986 // if ((KGlobal::getDesktopSize() > KGlobal::Small ) ||
1987 // (!KABPrefs::instance()->mMultipleViewsAtOnce )) 1987 // (!KABPrefs::instance()->mMultipleViewsAtOnce ))
1988 mActionEditAddressee->plug( tb ); 1988 mActionEditAddressee->plug( tb );
1989 1989
1990 fileMenu->insertSeparator(); 1990 fileMenu->insertSeparator();
1991 mActionSave->plug( fileMenu ); 1991 mActionSave->plug( fileMenu );
1992 fileMenu->insertItem( "&Import", ImportMenu ); 1992 fileMenu->insertItem( "&Import", ImportMenu );
1993 fileMenu->insertItem( "&Export", ExportMenu ); 1993 fileMenu->insertItem( "&Export", ExportMenu );
1994 fileMenu->insertSeparator(); 1994 fileMenu->insertSeparator();
1995 mActionMailVCard->plug( fileMenu ); 1995 mActionMailVCard->plug( fileMenu );
1996#ifndef DESKTOP_VERSION 1996#ifndef DESKTOP_VERSION
1997 if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu ); 1997 if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu );
1998 if ( Ir::supported() ) mActionBeam->plug(fileMenu ); 1998 if ( Ir::supported() ) mActionBeam->plug(fileMenu );
1999#endif 1999#endif
2000 fileMenu->insertSeparator(); 2000 fileMenu->insertSeparator();
2001 mActionQuit->plug( fileMenu ); 2001 mActionQuit->plug( fileMenu );
2002#ifdef _WIN32_ 2002#ifdef _WIN32_
2003 mActionImportOL->plug( ImportMenu ); 2003 mActionImportOL->plug( ImportMenu );
2004#endif 2004#endif
2005 // edit menu 2005 // edit menu
2006 mActionUndo->plug( editMenu ); 2006 mActionUndo->plug( editMenu );
2007 mActionRedo->plug( editMenu ); 2007 mActionRedo->plug( editMenu );
2008 editMenu->insertSeparator(); 2008 editMenu->insertSeparator();
2009 mActionCut->plug( editMenu ); 2009 mActionCut->plug( editMenu );
2010 mActionCopy->plug( editMenu ); 2010 mActionCopy->plug( editMenu );
2011 mActionPaste->plug( editMenu ); 2011 mActionPaste->plug( editMenu );
2012 mActionDelete->plug( editMenu ); 2012 mActionDelete->plug( editMenu );
2013 editMenu->insertSeparator(); 2013 editMenu->insertSeparator();
2014 mActionSelectAll->plug( editMenu ); 2014 mActionSelectAll->plug( editMenu );
2015 2015
2016 mActionRemoveVoice->plug( changeMenu ); 2016 mActionRemoveVoice->plug( changeMenu );
2017 // settings menu 2017 // settings menu
2018//US special menuentry to configure the addressbook resources. On KDE 2018//US special menuentry to configure the addressbook resources. On KDE
2019// you do that through the control center !!! 2019// you do that through the control center !!!
2020 mActionConfigResources->plug( settingsMenu ); 2020 mActionConfigResources->plug( settingsMenu );
2021 settingsMenu->insertSeparator(); 2021 settingsMenu->insertSeparator();
2022 2022
2023 mActionConfigKAddressbook->plug( settingsMenu ); 2023 mActionConfigKAddressbook->plug( settingsMenu );
2024 2024
2025 if ( mIsPart ) { 2025 if ( mIsPart ) {
2026 //US not implemented yet 2026 //US not implemented yet
2027 //mActionConfigShortcuts->plug( settingsMenu ); 2027 //mActionConfigShortcuts->plug( settingsMenu );
2028 //mActionConfigureToolbars->plug( settingsMenu ); 2028 //mActionConfigureToolbars->plug( settingsMenu );
2029 2029
2030 } else { 2030 } else {
2031 //US not implemented yet 2031 //US not implemented yet
2032 //mActionKeyBindings->plug( settingsMenu ); 2032 //mActionKeyBindings->plug( settingsMenu );
2033 } 2033 }
2034 2034
2035 settingsMenu->insertSeparator(); 2035 settingsMenu->insertSeparator();
2036 2036
2037 mActionJumpBar->plug( settingsMenu ); 2037 mActionJumpBar->plug( settingsMenu );
2038 mActionDetails->plug( settingsMenu ); 2038 mActionDetails->plug( settingsMenu );
2039 //if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop ) 2039 //if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop )
2040 mActionDetails->plug( tb ); 2040 mActionDetails->plug( tb );
2041 settingsMenu->insertSeparator(); 2041 settingsMenu->insertSeparator();
2042 mActionBR->plug(settingsMenu ); 2042 mActionBR->plug(settingsMenu );
2043 settingsMenu->insertSeparator(); 2043 settingsMenu->insertSeparator();
2044 2044
2045 mActionWhoAmI->plug( settingsMenu ); 2045 mActionWhoAmI->plug( settingsMenu );
2046 mActionCategories->plug( settingsMenu ); 2046 mActionCategories->plug( settingsMenu );
2047 2047
2048 2048
2049 mActionWN->plug( helpMenu ); 2049 mActionWN->plug( helpMenu );
2050 mActionSyncHowto->plug( helpMenu ); 2050 mActionSyncHowto->plug( helpMenu );
2051 mActionKdeSyncHowto->plug( helpMenu ); 2051 mActionKdeSyncHowto->plug( helpMenu );
2052 mActionMultiSyncHowto->plug( helpMenu ); 2052 mActionMultiSyncHowto->plug( helpMenu );
2053 mActionFaq->plug( helpMenu ); 2053 mActionFaq->plug( helpMenu );
2054 mActionLicence->plug( helpMenu ); 2054 mActionLicence->plug( helpMenu );
2055 mActionAboutKAddressbook->plug( helpMenu ); 2055 mActionAboutKAddressbook->plug( helpMenu );
2056 2056
2057 if (KGlobal::getDesktopSize() > KGlobal::Small ) { 2057 if (KGlobal::getDesktopSize() > KGlobal::Small ) {
2058 2058
2059 mActionSave->plug( tb ); 2059 mActionSave->plug( tb );
2060 mViewManager->getFilterAction()->plug ( tb); 2060 mViewManager->getFilterAction()->plug ( tb);
2061 if (KGlobal::getDesktopSize() == KGlobal::Desktop ) { 2061 if (KGlobal::getDesktopSize() == KGlobal::Desktop ) {
2062 mActionUndo->plug( tb ); 2062 mActionUndo->plug( tb );
2063 mActionDelete->plug( tb ); 2063 mActionDelete->plug( tb );
2064 mActionRedo->plug( tb ); 2064 mActionRedo->plug( tb );
2065 } 2065 }
2066 } else { 2066 } else {
2067 mActionSave->plug( tb ); 2067 mActionSave->plug( tb );
2068 tb->enableMoving(false); 2068 tb->enableMoving(false);
2069 } 2069 }
2070 //mActionQuit->plug ( tb ); 2070 //mActionQuit->plug ( tb );
2071 // tb->insertWidget(-1, 0, mIncSearchWidget, 6); 2071 // tb->insertWidget(-1, 0, mIncSearchWidget, 6);
2072 2072
2073 //US link the searchwidget first to this. 2073 //US link the searchwidget first to this.
2074 // The real linkage to the toolbar happens later. 2074 // The real linkage to the toolbar happens later.
2075//US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); 2075//US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE);
2076//US tb->insertItem( mIncSearchWidget ); 2076//US tb->insertItem( mIncSearchWidget );
2077/*US 2077/*US
2078 mIncSearchWidget = new IncSearchWidget( tb ); 2078 mIncSearchWidget = new IncSearchWidget( tb );
2079 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 2079 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
2080 SLOT( incrementalSearch( const QString& ) ) ); 2080 SLOT( incrementalSearch( const QString& ) ) );
2081 2081
2082 mJumpButtonBar = new JumpButtonBar( this, this ); 2082 mJumpButtonBar = new JumpButtonBar( this, this );
2083 2083
2084//US topLayout->addWidget( mJumpButtonBar ); 2084//US topLayout->addWidget( mJumpButtonBar );
2085 this->layout()->add( mJumpButtonBar ); 2085 this->layout()->add( mJumpButtonBar );
2086*/ 2086*/
2087 2087
2088#endif //KAB_EMBEDDED 2088#endif //KAB_EMBEDDED
2089 2089
2090 mActionExport2phone->plug( ExportMenu ); 2090 mActionExport2phone->plug( ExportMenu );
2091 connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); 2091 connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) );
2092 syncManager->fillSyncMenu(); 2092 syncManager->fillSyncMenu();
2093 2093
2094} 2094}
2095void KABCore::showLicence() 2095void KABCore::showLicence()
2096{ 2096{
2097 KApplication::showLicence(); 2097 KApplication::showLicence();
2098} 2098}
2099void KABCore::removeVoice() 2099void KABCore::removeVoice()
2100{ 2100{
2101 if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No ) 2101 if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No )
2102 return; 2102 return;
2103 KABC::Addressee::List list = mViewManager->selectedAddressees(); 2103 KABC::Addressee::List list = mViewManager->selectedAddressees();
2104 KABC::Addressee::List::Iterator it; 2104 KABC::Addressee::List::Iterator it;
2105 for ( it = list.begin(); it != list.end(); ++it ) { 2105 for ( it = list.begin(); it != list.end(); ++it ) {
2106 2106
2107 if ( (*it).removeVoice() ) 2107 if ( (*it).removeVoice() )
2108 contactModified((*it) ); 2108 contactModified((*it) );
2109 } 2109 }
2110} 2110}
2111 2111
2112 2112
2113 2113
2114void KABCore::clipboardDataChanged() 2114void KABCore::clipboardDataChanged()
2115{ 2115{
2116 2116
2117 if ( mReadWrite ) 2117 if ( mReadWrite )
2118 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); 2118 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() );
2119 2119
2120} 2120}
2121 2121
2122void KABCore::updateActionMenu() 2122void KABCore::updateActionMenu()
2123{ 2123{
2124 UndoStack *undo = UndoStack::instance(); 2124 UndoStack *undo = UndoStack::instance();
2125 RedoStack *redo = RedoStack::instance(); 2125 RedoStack *redo = RedoStack::instance();
2126 2126
2127 if ( undo->isEmpty() ) 2127 if ( undo->isEmpty() )
2128 mActionUndo->setText( i18n( "Undo" ) ); 2128 mActionUndo->setText( i18n( "Undo" ) );
2129 else 2129 else
2130 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); 2130 mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) );
2131 2131
2132 mActionUndo->setEnabled( !undo->isEmpty() ); 2132 mActionUndo->setEnabled( !undo->isEmpty() );
2133 2133
2134 if ( !redo->top() ) 2134 if ( !redo->top() )
2135 mActionRedo->setText( i18n( "Redo" ) ); 2135 mActionRedo->setText( i18n( "Redo" ) );
2136 else 2136 else
2137 mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) ); 2137 mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) );
2138 2138
2139 mActionRedo->setEnabled( !redo->isEmpty() ); 2139 mActionRedo->setEnabled( !redo->isEmpty() );
2140} 2140}
2141 2141
2142void KABCore::configureKeyBindings() 2142void KABCore::configureKeyBindings()
2143{ 2143{
2144#ifndef KAB_EMBEDDED 2144#ifndef KAB_EMBEDDED
2145 KKeyDialog::configure( actionCollection(), true ); 2145 KKeyDialog::configure( actionCollection(), true );
2146#else //KAB_EMBEDDED 2146#else //KAB_EMBEDDED
2147 qDebug("KABCore::configureKeyBindings() not implemented"); 2147 qDebug("KABCore::configureKeyBindings() not implemented");
2148#endif //KAB_EMBEDDED 2148#endif //KAB_EMBEDDED
2149} 2149}
2150 2150
2151#ifdef KAB_EMBEDDED 2151#ifdef KAB_EMBEDDED
2152void KABCore::configureResources() 2152void KABCore::configureResources()
2153{ 2153{
2154 KRES::KCMKResources dlg( this, "" , 0 ); 2154 KRES::KCMKResources dlg( this, "" , 0 );
2155 2155
2156 if ( !dlg.exec() ) 2156 if ( !dlg.exec() )
2157 return; 2157 return;
2158 KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); 2158 KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") );
2159} 2159}
2160#endif //KAB_EMBEDDED 2160#endif //KAB_EMBEDDED
2161 2161
2162 2162
2163/* this method will be called through the QCop interface from Ko/Pi to select addresses 2163/* this method will be called through the QCop interface from Ko/Pi to select addresses
2164 * for the attendees list of an event. 2164 * for the attendees list of an event.
2165 */ 2165 */
2166void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid) 2166void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid)
2167{ 2167{
2168 QStringList nameList; 2168 QStringList nameList;
2169 QStringList emailList; 2169 QStringList emailList;
2170 QStringList uidList; 2170 QStringList uidList;
2171 2171
2172 KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); 2172 KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this);
2173 uint i=0; 2173 uint i=0;
2174 for (i=0; i < list.count(); i++) 2174 for (i=0; i < list.count(); i++)
2175 { 2175 {
2176 nameList.append(list[i].realName()); 2176 nameList.append(list[i].realName());
2177 emailList.append(list[i].preferredEmail()); 2177 emailList.append(list[i].preferredEmail());
2178 uidList.append(list[i].uid()); 2178 uidList.append(list[i].uid());
2179 } 2179 }
2180 2180
2181 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList); 2181 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList);
2182 2182
2183} 2183}
2184 2184
2185/* this method will be called through the QCop interface from Ko/Pi to select birthdays 2185/* this method will be called through the QCop interface from Ko/Pi to select birthdays
2186 * to put them into the calendar. 2186 * to put them into the calendar.
2187 */ 2187 */
2188void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString& uid) 2188void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString& uid)
2189{ 2189{
2190 // qDebug("KABCore::requestForBirthdayList"); 2190 // qDebug("KABCore::requestForBirthdayList");
2191 QStringList birthdayList; 2191 QStringList birthdayList;
2192 QStringList anniversaryList; 2192 QStringList anniversaryList;
2193 QStringList realNameList; 2193 QStringList realNameList;
2194 QStringList preferredEmailList; 2194 QStringList preferredEmailList;
2195 QStringList assembledNameList; 2195 QStringList assembledNameList;
2196 QStringList uidList; 2196 QStringList uidList;
2197 2197
2198 KABC::AddressBook::Iterator it; 2198 KABC::AddressBook::Iterator it;
2199 2199
2200 int count = 0; 2200 int count = 0;
2201 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { 2201 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
2202 ++count; 2202 ++count;
2203 } 2203 }
2204 QProgressBar bar(count,0 ); 2204 QProgressBar bar(count,0 );
2205 int w = 300; 2205 int w = 300;
2206 if ( QApplication::desktop()->width() < 320 ) 2206 if ( QApplication::desktop()->width() < 320 )
2207 w = 220; 2207 w = 220;
2208 int h = bar.sizeHint().height() ; 2208 int h = bar.sizeHint().height() ;
2209 int dw = QApplication::desktop()->width(); 2209 int dw = QApplication::desktop()->width();
2210 int dh = QApplication::desktop()->height(); 2210 int dh = QApplication::desktop()->height();
2211 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2211 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2212 bar.show(); 2212 bar.show();
2213 bar.setCaption (i18n("Collecting birthdays - close to abort!") ); 2213 bar.setCaption (i18n("Collecting birthdays - close to abort!") );
2214 qApp->processEvents(); 2214 qApp->processEvents();
2215 2215
2216 QDate bday; 2216 QDate bday;
2217 QString anni; 2217 QString anni;
2218 QString formattedbday; 2218 QString formattedbday;
2219 2219
2220 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) 2220 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it )
2221 { 2221 {
2222 if ( ! bar.isVisible() ) 2222 if ( ! bar.isVisible() )
2223 return; 2223 return;
2224 bar.setProgress( count++ ); 2224 bar.setProgress( count++ );
2225 qApp->processEvents(); 2225 qApp->processEvents();
2226 bday = (*it).birthday().date(); 2226 bday = (*it).birthday().date();
2227 anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" ); 2227 anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" );
2228 2228
2229 if ( bday.isValid() || !anni.isEmpty()) 2229 if ( bday.isValid() || !anni.isEmpty())
2230 { 2230 {
2231 if (bday.isValid()) 2231 if (bday.isValid())
2232 formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate); 2232 formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate);
2233 else 2233 else
2234 formattedbday = "NOTVALID"; 2234 formattedbday = "NOTVALID";
2235 if (anni.isEmpty()) 2235 if (anni.isEmpty())
2236 anni = "INVALID"; 2236 anni = "INVALID";
2237 2237
2238 birthdayList.append(formattedbday); 2238 birthdayList.append(formattedbday);
2239 anniversaryList.append(anni); //should be ISODate 2239 anniversaryList.append(anni); //should be ISODate
2240 realNameList.append((*it).realName()); 2240 realNameList.append((*it).realName());
2241 preferredEmailList.append((*it).preferredEmail()); 2241 preferredEmailList.append((*it).preferredEmail());
2242 assembledNameList.append((*it).assembledName()); 2242 assembledNameList.append((*it).assembledName());
2243 uidList.append((*it).uid()); 2243 uidList.append((*it).uid());
2244 2244
2245 qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() ); 2245 //qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() );
2246 } 2246 }
2247 } 2247 }
2248 2248
2249 bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList); 2249 bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList);
2250 2250
2251} 2251}
2252 2252
2253/* this method will be called through the QCop interface from other apps to show details of a contact. 2253/* this method will be called through the QCop interface from other apps to show details of a contact.
2254 */ 2254 */
2255void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) 2255void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid)
2256{ 2256{
2257 qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); 2257 //qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1());
2258 2258
2259 QString foundUid = QString::null; 2259 QString foundUid = QString::null;
2260 if ( ! uid.isEmpty() ) { 2260 if ( ! uid.isEmpty() ) {
2261 Addressee adrr = mAddressBook->findByUid( uid ); 2261 Addressee adrr = mAddressBook->findByUid( uid );
2262 if ( !adrr.isEmpty() ) { 2262 if ( !adrr.isEmpty() ) {
2263 foundUid = uid; 2263 foundUid = uid;
2264 } 2264 }
2265 if ( email == "sendbacklist" ) { 2265 if ( email == "sendbacklist" ) {
2266 //qDebug("ssssssssssssssssssssssend "); 2266 //qDebug("ssssssssssssssssssssssend ");
2267 QStringList nameList; 2267 QStringList nameList;
2268 QStringList emailList; 2268 QStringList emailList;
2269 QStringList uidList; 2269 QStringList uidList;
2270 nameList.append(adrr.realName()); 2270 nameList.append(adrr.realName());
2271 emailList = adrr.emails(); 2271 emailList = adrr.emails();
2272 uidList.append( adrr.preferredEmail()); 2272 uidList.append( adrr.preferredEmail());
2273 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); 2273 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList);
2274 return; 2274 return;
2275 } 2275 }
2276 2276
2277 } 2277 }
2278 2278
2279 if ( email == "sendbacklist" ) 2279 if ( email == "sendbacklist" )
2280 return; 2280 return;
2281 if (foundUid.isEmpty()) 2281 if (foundUid.isEmpty())
2282 { 2282 {
2283 //find the uid of the person first 2283 //find the uid of the person first
2284 Addressee::List namelist; 2284 Addressee::List namelist;
2285 Addressee::List emaillist; 2285 Addressee::List emaillist;
2286 2286
2287 if (!name.isEmpty()) 2287 if (!name.isEmpty())
2288 namelist = mAddressBook->findByName( name ); 2288 namelist = mAddressBook->findByName( name );
2289 2289
2290 if (!email.isEmpty()) 2290 if (!email.isEmpty())
2291 emaillist = mAddressBook->findByEmail( email ); 2291 emaillist = mAddressBook->findByEmail( email );
2292 qDebug("count %d %d ", namelist.count(),emaillist.count() ); 2292 //qDebug("count %d %d ", namelist.count(),emaillist.count() );
2293 //check if we have a match in Namelist and Emaillist 2293 //check if we have a match in Namelist and Emaillist
2294 if ((namelist.count() == 0) && (emaillist.count() > 0)) { 2294 if ((namelist.count() == 0) && (emaillist.count() > 0)) {
2295 foundUid = emaillist[0].uid(); 2295 foundUid = emaillist[0].uid();
2296 } 2296 }
2297 else if ((namelist.count() > 0) && (emaillist.count() == 0)) 2297 else if ((namelist.count() > 0) && (emaillist.count() == 0))
2298 foundUid = namelist[0].uid(); 2298 foundUid = namelist[0].uid();
2299 else 2299 else
2300 { 2300 {
2301 for (int i = 0; i < namelist.count(); i++) 2301 for (int i = 0; i < namelist.count(); i++)
2302 { 2302 {
2303 for (int j = 0; j < emaillist.count(); j++) 2303 for (int j = 0; j < emaillist.count(); j++)
2304 { 2304 {
2305 if (namelist[i] == emaillist[j]) 2305 if (namelist[i] == emaillist[j])
2306 { 2306 {
2307 foundUid = namelist[i].uid(); 2307 foundUid = namelist[i].uid();
2308 } 2308 }
2309 } 2309 }
2310 } 2310 }
2311 } 2311 }
2312 } 2312 }
2313 else 2313 else
2314 { 2314 {
2315 foundUid = uid; 2315 foundUid = uid;
2316 } 2316 }
2317 2317
2318 if (!foundUid.isEmpty()) 2318 if (!foundUid.isEmpty())
2319 { 2319 {
2320 2320
2321 // raise Ka/Pi if it is in the background 2321 // raise Ka/Pi if it is in the background
2322#ifndef DESKTOP_VERSION 2322#ifndef DESKTOP_VERSION
2323#ifndef KORG_NODCOP 2323#ifndef KORG_NODCOP
2324 //QCopEnvelope e("QPE/Application/kapi", "raise()"); 2324 //QCopEnvelope e("QPE/Application/kapi", "raise()");
2325#endif 2325#endif
2326#endif 2326#endif
2327 2327
2328 mMainWindow->showMaximized(); 2328 mMainWindow->showMaximized();
2329 mMainWindow-> raise(); 2329 mMainWindow-> raise();
2330 2330
2331 mViewManager->setSelected( "", false); 2331 mViewManager->setSelected( "", false);
2332 mViewManager->refreshView( "" ); 2332 mViewManager->refreshView( "" );
2333 mViewManager->setSelected( foundUid, true ); 2333 mViewManager->setSelected( foundUid, true );
2334 mViewManager->refreshView( foundUid ); 2334 mViewManager->refreshView( foundUid );
2335 2335
2336 if ( !mMultipleViewsAtOnce ) 2336 if ( !mMultipleViewsAtOnce )
2337 { 2337 {
2338 setDetailsVisible( true ); 2338 setDetailsVisible( true );
2339 mActionDetails->setChecked(true); 2339 mActionDetails->setChecked(true);
2340 } 2340 }
2341 } 2341 }
2342} 2342}
2343 2343
2344void KABCore::whatsnew() 2344void KABCore::whatsnew()
2345{ 2345{
2346 KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); 2346 KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" );
2347} 2347}
2348void KABCore::synchowto() 2348void KABCore::synchowto()
2349{ 2349{
2350 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); 2350 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" );
2351} 2351}
2352void KABCore::kdesynchowto() 2352void KABCore::kdesynchowto()
2353{ 2353{
2354 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/Zaurus-KDE_syncHowTo.txt" ); 2354 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/Zaurus-KDE_syncHowTo.txt" );
2355} 2355}
2356void KABCore::multisynchowto() 2356void KABCore::multisynchowto()
2357{ 2357{
2358 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/MultiSyncHowTo.txt" ); 2358 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/MultiSyncHowTo.txt" );
2359} 2359}
2360void KABCore::faq() 2360void KABCore::faq()
2361{ 2361{
2362 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); 2362 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" );
2363} 2363}
2364 2364
2365#include <libkcal/syncdefines.h> 2365#include <libkcal/syncdefines.h>
2366 2366
2367KABC::Addressee KABCore::getLastSyncAddressee() 2367KABC::Addressee KABCore::getLastSyncAddressee()
2368{ 2368{
2369 Addressee lse; 2369 Addressee lse;
2370 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2370 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2371 2371
2372 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 2372 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
2373 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2373 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2374 if (lse.isEmpty()) { 2374 if (lse.isEmpty()) {
2375 qDebug("Creating new last-syncAddressee "); 2375 qDebug("Creating new last-syncAddressee ");
2376 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2376 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice );
2377 QString sum = ""; 2377 QString sum = "";
2378 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 2378 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
2379 sum = "E: "; 2379 sum = "E: ";
2380 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); 2380 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event"));
2381 lse.setRevision( mLastAddressbookSync ); 2381 lse.setRevision( mLastAddressbookSync );
2382 lse.setCategories( i18n("SyncEvent") ); 2382 lse.setCategories( i18n("SyncEvent") );
2383 mAddressBook->insertAddressee( lse ); 2383 mAddressBook->insertAddressee( lse );
2384 } 2384 }
2385 return lse; 2385 return lse;
2386} 2386}
2387int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) 2387int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full )
2388{ 2388{
2389 2389
2390 //void setZaurusId(int id); 2390 //void setZaurusId(int id);
2391 // int zaurusId() const; 2391 // int zaurusId() const;
2392 // void setZaurusUid(int id); 2392 // void setZaurusUid(int id);
2393 // int zaurusUid() const; 2393 // int zaurusUid() const;
2394 // void setZaurusStat(int id); 2394 // void setZaurusStat(int id);
2395 // int zaurusStat() const; 2395 // int zaurusStat() const;
2396 // 0 equal 2396 // 0 equal
2397 // 1 take local 2397 // 1 take local
2398 // 2 take remote 2398 // 2 take remote
2399 // 3 cancel 2399 // 3 cancel
2400 QDateTime lastSync = mLastAddressbookSync; 2400 QDateTime lastSync = mLastAddressbookSync;
2401 QDateTime localMod = local->revision(); 2401 QDateTime localMod = local->revision();
2402 QDateTime remoteMod = remote->revision(); 2402 QDateTime remoteMod = remote->revision();
2403 2403
2404 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2404 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2405 2405
2406 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2406 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2407 bool remCh, locCh; 2407 bool remCh, locCh;
2408 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 2408 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
2409 qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 2409 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
2410 locCh = ( localMod > mLastAddressbookSync ); 2410 locCh = ( localMod > mLastAddressbookSync );
2411 if ( !remCh && ! locCh ) { 2411 if ( !remCh && ! locCh ) {
2412 qDebug("both not changed "); 2412 //qDebug("both not changed ");
2413 lastSync = localMod.addDays(1); 2413 lastSync = localMod.addDays(1);
2414 if ( mode <= SYNC_PREF_ASK ) 2414 if ( mode <= SYNC_PREF_ASK )
2415 return 0; 2415 return 0;
2416 } else { 2416 } else {
2417 if ( locCh ) { 2417 if ( locCh ) {
2418 qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); 2418 //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1());
2419 lastSync = localMod.addDays( -1 ); 2419 lastSync = localMod.addDays( -1 );
2420 if ( !remCh ) 2420 if ( !remCh )
2421 remoteMod =( lastSync.addDays( -1 ) ); 2421 remoteMod =( lastSync.addDays( -1 ) );
2422 } else { 2422 } else {
2423 qDebug(" not loc changed "); 2423 //qDebug(" not loc changed ");
2424 lastSync = localMod.addDays( 1 ); 2424 lastSync = localMod.addDays( 1 );
2425 if ( remCh ) { 2425 if ( remCh ) {
2426 qDebug("rem changed "); 2426 //qDebug("rem changed ");
2427 remoteMod =( lastSync.addDays( 1 ) ); 2427 remoteMod =( lastSync.addDays( 1 ) );
2428 } 2428 }
2429 2429
2430 } 2430 }
2431 } 2431 }
2432 full = true; 2432 full = true;
2433 if ( mode < SYNC_PREF_ASK ) 2433 if ( mode < SYNC_PREF_ASK )
2434 mode = SYNC_PREF_ASK; 2434 mode = SYNC_PREF_ASK;
2435 } else { 2435 } else {
2436 if ( localMod == remoteMod ) 2436 if ( localMod == remoteMod )
2437 return 0; 2437 return 0;
2438 2438
2439 } 2439 }
2440 qDebug("%s %s --- %d %d", localMod.toString().latin1() , remoteMod.toString().latin1(), localMod.time().msec(), remoteMod.time().msec()); 2440 //qDebug("%s %s --- %d %d", localMod.toString().latin1() , remoteMod.toString().latin1(), localMod.time().msec(), remoteMod.time().msec());
2441 qDebug("lastsync %s ", lastSync.toString().latin1() ); 2441 //qDebug("lastsync %s ", lastSync.toString().latin1() );
2442 //full = true; //debug only 2442 //full = true; //debug only
2443 if ( full ) { 2443 if ( full ) {
2444 bool equ = ( (*local) == (*remote) ); 2444 bool equ = ( (*local) == (*remote) );
2445 if ( equ ) { 2445 if ( equ ) {
2446 qDebug("equal "); 2446 //qDebug("equal ");
2447 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2447 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2448 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 2448 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
2449 } 2449 }
2450 if ( mode < SYNC_PREF_FORCE_LOCAL ) 2450 if ( mode < SYNC_PREF_FORCE_LOCAL )
2451 return 0; 2451 return 0;
2452 2452
2453 }//else //debug only 2453 }//else //debug only
2454 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 2454 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
2455 } 2455 }
2456 int result; 2456 int result;
2457 bool localIsNew; 2457 bool localIsNew;
2458 //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() ); 2458 //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() );
2459 2459
2460 if ( full && mode < SYNC_PREF_NEWEST ) 2460 if ( full && mode < SYNC_PREF_NEWEST )
2461 mode = SYNC_PREF_ASK; 2461 mode = SYNC_PREF_ASK;
2462 2462
2463 switch( mode ) { 2463 switch( mode ) {
2464 case SYNC_PREF_LOCAL: 2464 case SYNC_PREF_LOCAL:
2465 if ( lastSync > remoteMod ) 2465 if ( lastSync > remoteMod )
2466 return 1; 2466 return 1;
2467 if ( lastSync > localMod ) 2467 if ( lastSync > localMod )
2468 return 2; 2468 return 2;
2469 return 1; 2469 return 1;
2470 break; 2470 break;
2471 case SYNC_PREF_REMOTE: 2471 case SYNC_PREF_REMOTE:
2472 if ( lastSync > remoteMod ) 2472 if ( lastSync > remoteMod )
2473 return 1; 2473 return 1;
2474 if ( lastSync > localMod ) 2474 if ( lastSync > localMod )
2475 return 2; 2475 return 2;
2476 return 2; 2476 return 2;
2477 break; 2477 break;
2478 case SYNC_PREF_NEWEST: 2478 case SYNC_PREF_NEWEST:
2479 if ( localMod > remoteMod ) 2479 if ( localMod > remoteMod )
2480 return 1; 2480 return 1;
2481 else 2481 else
2482 return 2; 2482 return 2;
2483 break; 2483 break;
2484 case SYNC_PREF_ASK: 2484 case SYNC_PREF_ASK:
2485 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 2485 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
2486 if ( lastSync > remoteMod ) 2486 if ( lastSync > remoteMod )
2487 return 1; 2487 return 1;
2488 if ( lastSync > localMod ) 2488 if ( lastSync > localMod )
2489 return 2; 2489 return 2;
2490 localIsNew = localMod >= remoteMod; 2490 localIsNew = localMod >= remoteMod;
2491 //qDebug("conflict! ************************************** "); 2491 //qDebug("conflict! ************************************** ");
2492 { 2492 {
2493 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); 2493 KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this );
2494 result = acd.executeD(localIsNew); 2494 result = acd.executeD(localIsNew);
2495 return result; 2495 return result;
2496 } 2496 }
2497 break; 2497 break;
2498 case SYNC_PREF_FORCE_LOCAL: 2498 case SYNC_PREF_FORCE_LOCAL:
2499 return 1; 2499 return 1;
2500 break; 2500 break;
2501 case SYNC_PREF_FORCE_REMOTE: 2501 case SYNC_PREF_FORCE_REMOTE:
2502 return 2; 2502 return 2;
2503 break; 2503 break;
2504 2504
2505 default: 2505 default:
2506 // SYNC_PREF_TAKE_BOTH not implemented 2506 // SYNC_PREF_TAKE_BOTH not implemented
2507 break; 2507 break;
2508 } 2508 }
2509 return 0; 2509 return 0;
2510} 2510}
2511 2511
2512 2512
2513bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2513bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2514{ 2514{
2515 bool syncOK = true; 2515 bool syncOK = true;
2516 int addedAddressee = 0; 2516 int addedAddressee = 0;
2517 int addedAddresseeR = 0; 2517 int addedAddresseeR = 0;
2518 int deletedAddresseeR = 0; 2518 int deletedAddresseeR = 0;
2519 int deletedAddresseeL = 0; 2519 int deletedAddresseeL = 0;
2520 int changedLocal = 0; 2520 int changedLocal = 0;
2521 int changedRemote = 0; 2521 int changedRemote = 0;
2522 2522
2523 QString mCurrentSyncName = syncManager->getCurrentSyncName(); 2523 QString mCurrentSyncName = syncManager->getCurrentSyncName();
2524 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2524 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2525 2525
2526 //QPtrList<Addressee> el = local->rawAddressees(); 2526 //QPtrList<Addressee> el = local->rawAddressees();
2527 Addressee addresseeR; 2527 Addressee addresseeR;
2528 QString uid; 2528 QString uid;
2529 int take; 2529 int take;
2530 Addressee addresseeL; 2530 Addressee addresseeL;
2531 Addressee addresseeRSync; 2531 Addressee addresseeRSync;
2532 Addressee addresseeLSync; 2532 Addressee addresseeLSync;
2533 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2533 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2534 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2534 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2535 bool fullDateRange = false; 2535 bool fullDateRange = false;
2536 local->resetTempSyncStat(); 2536 local->resetTempSyncStat();
2537 mLastAddressbookSync = QDateTime::currentDateTime(); 2537 mLastAddressbookSync = QDateTime::currentDateTime();
2538 if ( syncManager->syncWithDesktop() ) { 2538 if ( syncManager->syncWithDesktop() ) {
2539 // remote->removeSyncInfo( QString());//remove all info 2539 // remote->removeSyncInfo( QString());//remove all info
2540 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 2540 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
2541 mLastAddressbookSync = KSyncManager::mRequestedSyncEvent; 2541 mLastAddressbookSync = KSyncManager::mRequestedSyncEvent;
2542 qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() ); 2542 qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() );
2543 } else { 2543 } else {
2544 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 2544 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
2545 } 2545 }
2546 } 2546 }
2547 QDateTime modifiedCalendar = mLastAddressbookSync; 2547 QDateTime modifiedCalendar = mLastAddressbookSync;
2548 addresseeLSync = getLastSyncAddressee(); 2548 addresseeLSync = getLastSyncAddressee();
2549 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); 2549 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1());
2550 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); 2550 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2551 if ( !addresseeR.isEmpty() ) { 2551 if ( !addresseeR.isEmpty() ) {
2552 addresseeRSync = addresseeR; 2552 addresseeRSync = addresseeR;
2553 remote->removeAddressee(addresseeR ); 2553 remote->removeAddressee(addresseeR );
2554 2554
2555 } else { 2555 } else {
2556 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2556 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2557 addresseeRSync = addresseeLSync ; 2557 addresseeRSync = addresseeLSync ;
2558 } else { 2558 } else {
2559 qDebug("FULLDATE 1"); 2559 //qDebug("FULLDATE 1");
2560 fullDateRange = true; 2560 fullDateRange = true;
2561 Addressee newAdd; 2561 Addressee newAdd;
2562 addresseeRSync = newAdd; 2562 addresseeRSync = newAdd;
2563 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); 2563 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
2564 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); 2564 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
2565 addresseeRSync.setRevision( mLastAddressbookSync ); 2565 addresseeRSync.setRevision( mLastAddressbookSync );
2566 addresseeRSync.setCategories( i18n("SyncAddressee") ); 2566 addresseeRSync.setCategories( i18n("SyncAddressee") );
2567 } 2567 }
2568 } 2568 }
2569 if ( addresseeLSync.revision() == mLastAddressbookSync ) { 2569 if ( addresseeLSync.revision() == mLastAddressbookSync ) {
2570 qDebug("FULLDATE 2"); 2570 // qDebug("FULLDATE 2");
2571 fullDateRange = true; 2571 fullDateRange = true;
2572 } 2572 }
2573 if ( ! fullDateRange ) { 2573 if ( ! fullDateRange ) {
2574 if ( addresseeLSync.revision() != addresseeRSync.revision() ) { 2574 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2575 2575
2576 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2576 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2577 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2577 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2578 fullDateRange = true; 2578 fullDateRange = true;
2579 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); 2579 //qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
2580 } 2580 }
2581 } 2581 }
2582 // fullDateRange = true; // debug only! 2582 // fullDateRange = true; // debug only!
2583 if ( fullDateRange ) 2583 if ( fullDateRange )
2584 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2584 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2585 else 2585 else
2586 mLastAddressbookSync = addresseeLSync.revision(); 2586 mLastAddressbookSync = addresseeLSync.revision();
2587 // for resyncing if own file has changed 2587 // for resyncing if own file has changed
2588 // PENDING fixme later when implemented 2588 // PENDING fixme later when implemented
2589#if 0 2589#if 0
2590 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2590 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2591 mLastAddressbookSync = loadedFileVersion; 2591 mLastAddressbookSync = loadedFileVersion;
2592 qDebug("setting mLastAddressbookSync "); 2592 qDebug("setting mLastAddressbookSync ");
2593 } 2593 }
2594#endif 2594#endif
2595 2595
2596 //qDebug("*************************** "); 2596 //qDebug("*************************** ");
2597 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2597 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2598 QStringList er = remote->uidList(); 2598 QStringList er = remote->uidList();
2599 Addressee inR ;//= er.first(); 2599 Addressee inR ;//= er.first();
2600 Addressee inL; 2600 Addressee inL;
2601 2601
2602 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 2602 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
2603 2603
2604 int modulo = (er.count()/10)+1; 2604 int modulo = (er.count()/10)+1;
2605 int incCounter = 0; 2605 int incCounter = 0;
2606 while ( incCounter < er.count()) { 2606 while ( incCounter < er.count()) {
2607 if (syncManager->isProgressBarCanceled()) 2607 if (syncManager->isProgressBarCanceled())
2608 return false; 2608 return false;
2609 if ( incCounter % modulo == 0 ) 2609 if ( incCounter % modulo == 0 )
2610 syncManager->showProgressBar(incCounter); 2610 syncManager->showProgressBar(incCounter);
2611 2611
2612 uid = er[ incCounter ]; 2612 uid = er[ incCounter ];
2613 bool skipIncidence = false; 2613 bool skipIncidence = false;
2614 if ( uid.left(19) == QString("last-syncAddressee-") ) 2614 if ( uid.left(19) == QString("last-syncAddressee-") )
2615 skipIncidence = true; 2615 skipIncidence = true;
2616 QString idS,OidS; 2616 QString idS,OidS;
2617 qApp->processEvents(); 2617 qApp->processEvents();
2618 if ( !skipIncidence ) { 2618 if ( !skipIncidence ) {
2619 inL = local->findByUid( uid ); 2619 inL = local->findByUid( uid );
2620 inR = remote->findByUid( uid ); 2620 inR = remote->findByUid( uid );
2621 //inL.setResource( 0 ); 2621 //inL.setResource( 0 );
2622 //inR.setResource( 0 ); 2622 //inR.setResource( 0 );
2623 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars 2623 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
2624 if ( !inL.resource() || inL.resource()->includeInSync() ) { 2624 if ( !inL.resource() || inL.resource()->includeInSync() ) {
2625 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { 2625 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) {
2626 //qDebug("take %d %s ", take, inL.summary().latin1()); 2626 //qDebug("take %d %s ", take, inL.summary().latin1());
2627 if ( take == 3 ) 2627 if ( take == 3 )
2628 return false; 2628 return false;
2629 if ( take == 1 ) {// take local ********************** 2629 if ( take == 1 ) {// take local **********************
2630 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2630 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2631 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2631 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2632 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2632 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2633 local->insertAddressee( inL, false ); 2633 local->insertAddressee( inL, false );
2634 idS = inR.externalUID(); 2634 idS = inR.externalUID();
2635 OidS = inR.originalExternalUID(); 2635 OidS = inR.originalExternalUID();
2636 } 2636 }
2637 else 2637 else
2638 idS = inR.IDStr(); 2638 idS = inR.IDStr();
2639 remote->removeAddressee( inR ); 2639 remote->removeAddressee( inR );
2640 inR = inL; 2640 inR = inL;
2641 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2641 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2642 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2642 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2643 inR.setOriginalExternalUID( OidS ); 2643 inR.setOriginalExternalUID( OidS );
2644 inR.setExternalUID( idS ); 2644 inR.setExternalUID( idS );
2645 if ( syncManager->syncWithDesktop() ) { 2645 if ( syncManager->syncWithDesktop() ) {
2646 inR.setIDStr("changed" ); 2646 inR.setIDStr("changed" );
2647 } 2647 }
2648 //inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" ); 2648 //inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" );
2649 } else { 2649 } else {
2650 inR.setIDStr( idS ); 2650 inR.setIDStr( idS );
2651 } 2651 }
2652 inR.setResource( 0 ); 2652 inR.setResource( 0 );
2653 remote->insertAddressee( inR , false); 2653 remote->insertAddressee( inR , false);
2654 ++changedRemote; 2654 ++changedRemote;
2655 } else { // take == 2 take remote ********************** 2655 } else { // take == 2 take remote **********************
2656 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2656 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2657 if ( inR.revision().date().year() < 2004 ) 2657 if ( inR.revision().date().year() < 2004 )
2658 inR.setRevision( modifiedCalendar ); 2658 inR.setRevision( modifiedCalendar );
2659 } 2659 }
2660 idS = inL.IDStr(); 2660 idS = inL.IDStr();
2661 local->removeAddressee( inL ); 2661 local->removeAddressee( inL );
2662 inL = inR; 2662 inL = inR;
2663 inL.setIDStr( idS ); 2663 inL.setIDStr( idS );
2664 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2664 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2665 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2665 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2666 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2666 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2667 } 2667 }
2668 inL.setResource( 0 ); 2668 inL.setResource( 0 );
2669 local->insertAddressee( inL , false ); 2669 local->insertAddressee( inL , false );
2670 ++changedLocal; 2670 ++changedLocal;
2671 } 2671 }
2672 } 2672 }
2673 } 2673 }
2674 } else { // no conflict ********** add or delete remote 2674 } else { // no conflict ********** add or delete remote
2675 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2675 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2676 QString des = addresseeLSync.note(); 2676 QString des = addresseeLSync.note();
2677 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 2677 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2678 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 2678 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2679 remote->insertAddressee( inR, false ); 2679 remote->insertAddressee( inR, false );
2680 ++deletedAddresseeR; 2680 ++deletedAddresseeR;
2681 } else { 2681 } else {
2682 inR.setRevision( modifiedCalendar ); 2682 inR.setRevision( modifiedCalendar );
2683 remote->insertAddressee( inR, false ); 2683 remote->insertAddressee( inR, false );
2684 inL = inR; 2684 inL = inR;
2685 inL.setIDStr( ":" ); 2685 inL.setIDStr( ":" );
2686 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2686 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2687 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2687 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2688 inL.setResource( 0 ); 2688 inL.setResource( 0 );
2689 local->insertAddressee( inL , false); 2689 local->insertAddressee( inL , false);
2690 ++addedAddressee; 2690 ++addedAddressee;
2691 } 2691 }
2692 } else { 2692 } else {
2693 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { 2693 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2694 inR.setRevision( modifiedCalendar ); 2694 inR.setRevision( modifiedCalendar );
2695 remote->insertAddressee( inR, false ); 2695 remote->insertAddressee( inR, false );
2696 inR.setResource( 0 ); 2696 inR.setResource( 0 );
2697 local->insertAddressee( inR, false ); 2697 local->insertAddressee( inR, false );
2698 ++addedAddressee; 2698 ++addedAddressee;
2699 } else { 2699 } else {
2700 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2700 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2701 remote->removeAddressee( inR ); 2701 remote->removeAddressee( inR );
2702 ++deletedAddresseeR; 2702 ++deletedAddresseeR;
2703 } 2703 }
2704 } 2704 }
2705 } 2705 }
2706 } 2706 }
2707 ++incCounter; 2707 ++incCounter;
2708 } 2708 }
2709 er.clear(); 2709 er.clear();
2710 QStringList el = local->uidList(); 2710 QStringList el = local->uidList();
2711 modulo = (el.count()/10)+1; 2711 modulo = (el.count()/10)+1;
2712 2712
2713 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 2713 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
2714 incCounter = 0; 2714 incCounter = 0;
2715 while ( incCounter < el.count()) { 2715 while ( incCounter < el.count()) {
2716 qApp->processEvents(); 2716 qApp->processEvents();
2717 if (syncManager->isProgressBarCanceled()) 2717 if (syncManager->isProgressBarCanceled())
2718 return false; 2718 return false;
2719 if ( incCounter % modulo == 0 ) 2719 if ( incCounter % modulo == 0 )
2720 syncManager->showProgressBar(incCounter); 2720 syncManager->showProgressBar(incCounter);
2721 uid = el[ incCounter ]; 2721 uid = el[ incCounter ];
2722 bool skipIncidence = false; 2722 bool skipIncidence = false;
2723 if ( uid.left(19) == QString("last-syncAddressee-") ) 2723 if ( uid.left(19) == QString("last-syncAddressee-") )
2724 skipIncidence = true; 2724 skipIncidence = true;
2725 if ( !skipIncidence ) { 2725 if ( !skipIncidence ) {
2726 inL = local->findByUid( uid ); 2726 inL = local->findByUid( uid );
2727 if ( !inL.resource() || inL.resource()->includeInSync() ) { 2727 if ( !inL.resource() || inL.resource()->includeInSync() ) {
2728 inR = remote->findByUid( uid ); 2728 inR = remote->findByUid( uid );
2729 if ( inR.isEmpty() ) { // no conflict ********** add or delete local 2729 if ( inR.isEmpty() ) { // no conflict ********** add or delete local
2730 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2730 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2731 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 2731 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
2732 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2732 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2733 local->removeAddressee( inL ); 2733 local->removeAddressee( inL );
2734 ++deletedAddresseeL; 2734 ++deletedAddresseeL;
2735 } else { 2735 } else {
2736 if ( ! syncManager->mWriteBackExistingOnly ) { 2736 if ( ! syncManager->mWriteBackExistingOnly ) {
2737 inL.removeID(mCurrentSyncDevice ); 2737 inL.removeID(mCurrentSyncDevice );
2738 ++addedAddresseeR; 2738 ++addedAddresseeR;
2739 inL.setRevision( modifiedCalendar ); 2739 inL.setRevision( modifiedCalendar );
2740 local->insertAddressee( inL, false ); 2740 local->insertAddressee( inL, false );
2741 inR = inL; 2741 inR = inL;
2742 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); 2742 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL );
2743 inR.setResource( 0 ); 2743 inR.setResource( 0 );
2744 remote->insertAddressee( inR, false ); 2744 remote->insertAddressee( inR, false );
2745 } 2745 }
2746 } 2746 }
2747 } else { 2747 } else {
2748 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { 2748 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
2749 //qDebug("data %s ", inL.revision().toString().latin1()); 2749 //qDebug("data %s ", inL.revision().toString().latin1());
2750 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2750 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2751 local->removeAddressee( inL ); 2751 local->removeAddressee( inL );
2752 ++deletedAddresseeL; 2752 ++deletedAddresseeL;
2753 } else { 2753 } else {
2754 if ( ! syncManager->mWriteBackExistingOnly ) { 2754 if ( ! syncManager->mWriteBackExistingOnly ) {
2755 ++addedAddresseeR; 2755 ++addedAddresseeR;
2756 inL.setRevision( modifiedCalendar ); 2756 inL.setRevision( modifiedCalendar );
2757 local->insertAddressee( inL, false ); 2757 local->insertAddressee( inL, false );
2758 inR = inL; 2758 inR = inL;
2759 inR.setIDStr( ":" ); 2759 inR.setIDStr( ":" );
2760 inR.setResource( 0 ); 2760 inR.setResource( 0 );
2761 remote->insertAddressee( inR, false ); 2761 remote->insertAddressee( inR, false );
2762 } 2762 }
2763 } 2763 }
2764 } 2764 }
2765 } 2765 }
2766 } 2766 }
2767 } 2767 }
2768 ++incCounter; 2768 ++incCounter;
2769 } 2769 }
2770 el.clear(); 2770 el.clear();
2771 syncManager->hideProgressBar(); 2771 syncManager->hideProgressBar();
2772 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 2772 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
2773 // get rid of micro seconds 2773 // get rid of micro seconds
2774 QTime t = mLastAddressbookSync.time(); 2774 QTime t = mLastAddressbookSync.time();
2775 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 2775 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
2776 addresseeLSync.setRevision( mLastAddressbookSync ); 2776 addresseeLSync.setRevision( mLastAddressbookSync );
2777 addresseeRSync.setRevision( mLastAddressbookSync ); 2777 addresseeRSync.setRevision( mLastAddressbookSync );
2778 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 2778 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
2779 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 2779 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
2780 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; 2780 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ;
2781 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); 2781 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") );
2782 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; 2782 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ;
2783 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); 2783 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() );
2784 addresseeRSync.setNote( "" ) ; 2784 addresseeRSync.setNote( "" ) ;
2785 addresseeLSync.setNote( "" ); 2785 addresseeLSync.setNote( "" );
2786 2786
2787 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2787 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2788 remote->insertAddressee( addresseeRSync, false ); 2788 remote->insertAddressee( addresseeRSync, false );
2789 local->insertAddressee( addresseeLSync, false ); 2789 local->insertAddressee( addresseeLSync, false );
2790 QString mes; 2790 QString mes;
2791 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 ); 2791 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 );
2792 qDebug( mes ); 2792 qDebug( mes );
2793 mes = i18n("Local addressbook changed!\n") +mes; 2793 mes = i18n("Local addressbook changed!\n") +mes;
2794 if ( syncManager->mShowSyncSummary ) { 2794 if ( syncManager->mShowSyncSummary ) {
2795 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 2795 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
2796 i18n("KA/Pi Synchronization"),i18n("Write back"))) { 2796 i18n("KA/Pi Synchronization"),i18n("Write back"))) {
2797 qDebug("cancelled "); 2797 qDebug("cancelled ");
2798 return false; 2798 return false;
2799 } 2799 }
2800 } 2800 }
2801 return syncOK; 2801 return syncOK;
2802} 2802}
2803 2803
2804 2804
2805//this is a overwritten callbackmethods from the syncinterface 2805//this is a overwritten callbackmethods from the syncinterface
2806bool KABCore::sync(KSyncManager* manager, QString filename, int mode) 2806bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
2807{ 2807{
2808 2808
2809 //pending prepare addresseeview for output 2809 //pending prepare addresseeview for output
2810 //pending detect, if remote file has REV field. if not switch to external sync 2810 //pending detect, if remote file has REV field. if not switch to external sync
2811 mGlobalSyncMode = SYNC_MODE_NORMAL; 2811 mGlobalSyncMode = SYNC_MODE_NORMAL;
2812 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2812 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2813 2813
2814 AddressBook abLocal(filename,"syncContact"); 2814 AddressBook abLocal(filename,"syncContact");
2815 bool syncOK = false; 2815 bool syncOK = false;
2816 if ( abLocal.load() ) { 2816 if ( abLocal.load() ) {
2817 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); 2817 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode );
2818 bool external = false; 2818 bool external = false;
2819 bool isXML = false; 2819 bool isXML = false;
2820 if ( filename.right(4) == ".xml") { 2820 if ( filename.right(4) == ".xml") {
2821 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2821 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2822 isXML = true; 2822 isXML = true;
2823 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); 2823 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true );
2824 } else { 2824 } else {
2825 external = !manager->mIsKapiFile; 2825 external = !manager->mIsKapiFile;
2826 if ( external ) { 2826 if ( external ) {
2827 qDebug("Setting vcf mode to external "); 2827 qDebug("Setting vcf mode to external ");
2828 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2828 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2829 AddressBook::Iterator it; 2829 AddressBook::Iterator it;
2830 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2830 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2831 (*it).setID( mCurrentSyncDevice, (*it).uid() ); 2831 (*it).setID( mCurrentSyncDevice, (*it).uid() );
2832 (*it).computeCsum( mCurrentSyncDevice ); 2832 (*it).computeCsum( mCurrentSyncDevice );
2833 } 2833 }
2834 } 2834 }
2835 } 2835 }
2836 //AddressBook::Iterator it; 2836 //AddressBook::Iterator it;
2837 //QStringList vcards; 2837 //QStringList vcards;
2838 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2838 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2839 // qDebug("Name %s ", (*it).familyName().latin1()); 2839 // qDebug("Name %s ", (*it).familyName().latin1());
2840 //} 2840 //}
2841 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2841 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2842 if ( syncOK ) { 2842 if ( syncOK ) {
2843 if ( syncManager->mWriteBackFile ) 2843 if ( syncManager->mWriteBackFile )
2844 { 2844 {
2845 if ( external ) 2845 if ( external )
2846 abLocal.removeSyncAddressees( !isXML); 2846 abLocal.removeSyncAddressees( !isXML);
2847 qDebug("Saving remote AB "); 2847 qDebug("Saving remote AB ");
2848 if ( ! abLocal.saveAB()) 2848 if ( ! abLocal.saveAB())
2849 qDebug("Error writing back AB to file "); 2849 qDebug("Error writing back AB to file ");
2850 if ( external ) { 2850 if ( external ) {
2851 // afterwrite processing 2851 // afterwrite processing
2852 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ,isXML); 2852 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ,isXML);
2853 } 2853 }
2854 } 2854 }
2855 } 2855 }
2856 setModified(); 2856 setModified();
2857 2857
2858 } 2858 }
2859 abLocal.removeResources();
2859 if ( syncOK ) 2860 if ( syncOK )
2860 mViewManager->refreshView(); 2861 mViewManager->refreshView();
2861 return syncOK; 2862 return syncOK;
2862 2863
2863} 2864}
2864void KABCore::removeSyncInfo( QString syncProfile) 2865void KABCore::removeSyncInfo( QString syncProfile)
2865{ 2866{
2866 qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1()); 2867 qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1());
2867 mAddressBook->removeSyncInfo( syncProfile ); 2868 mAddressBook->removeSyncInfo( syncProfile );
2868 setModified(); 2869 setModified();
2869} 2870}
2870 2871
2871 2872
2872//this is a overwritten callbackmethods from the syncinterface 2873//this is a overwritten callbackmethods from the syncinterface
2873bool KABCore::syncExternal(KSyncManager* manager, QString resource) 2874bool KABCore::syncExternal(KSyncManager* manager, QString resource)
2874{ 2875{
2875 if ( resource == "phone" ) 2876 if ( resource == "phone" )
2876 return syncPhone(); 2877 return syncPhone();
2877 disableBR( true ); 2878 disableBR( true );
2878 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2879 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2879 2880
2880 AddressBook abLocal( resource,"syncContact"); 2881 AddressBook abLocal( resource,"syncContact");
2881 bool syncOK = false; 2882 bool syncOK = false;
2882 if ( abLocal.load() ) { 2883 if ( abLocal.load() ) {
2883 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2884 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1());
2884 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2885 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2885 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); 2886 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false );
2886 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2887 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2887 if ( syncOK ) { 2888 if ( syncOK ) {
2888 if ( syncManager->mWriteBackFile ) { 2889 if ( syncManager->mWriteBackFile ) {
2889 abLocal.removeSyncAddressees( false ); 2890 abLocal.removeSyncAddressees( false );
2890 abLocal.saveAB(); 2891 abLocal.saveAB();
2891 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); 2892 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true );
2892 } 2893 }
2893 } else 2894 } else
2894 message( i18n("Sync cancelled or failed.") ); 2895 message( i18n("Sync cancelled or failed.") );
2895 setModified(); 2896 setModified();
2896 } 2897 }
2898 abLocal.removeResources();
2897 if ( syncOK ) 2899 if ( syncOK )
2898 mViewManager->refreshView(); 2900 mViewManager->refreshView();
2899 disableBR( false ); 2901 disableBR( false );
2900 return syncOK; 2902 return syncOK;
2901 2903
2902} 2904}
2903void KABCore::message( QString m ) 2905void KABCore::message( QString m )
2904{ 2906{
2905 topLevelWidget()->setCaption( m ); 2907 topLevelWidget()->setCaption( m );
2906 mMessageTimer->start( 15000, true ); 2908 mMessageTimer->start( 15000, true );
2907} 2909}
2908bool KABCore::syncPhone() 2910bool KABCore::syncPhone()
2909{ 2911{
2910 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2912 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2911 QString fileName = getPhoneFile(); 2913 QString fileName = getPhoneFile();
2912 if ( !PhoneAccess::readFromPhone( fileName) ) { 2914 if ( !PhoneAccess::readFromPhone( fileName) ) {
2913 message(i18n("Phone access failed!")); 2915 message(i18n("Phone access failed!"));
2914 return false; 2916 return false;
2915 } 2917 }
2916 AddressBook abLocal( fileName,"syncContact"); 2918 AddressBook abLocal( fileName,"syncContact");
2917 bool syncOK = false; 2919 bool syncOK = false;
2918 { 2920 {
2919 abLocal.importFromFile( fileName ); 2921 abLocal.importFromFile( fileName );
2920 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2922 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1());
2921 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2923 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2922 abLocal.preparePhoneSync( mCurrentSyncDevice, true ); 2924 abLocal.preparePhoneSync( mCurrentSyncDevice, true );
2923 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); 2925 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true );
2924 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2926 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2925 if ( syncOK ) { 2927 if ( syncOK ) {
2926 if ( syncManager->mWriteBackFile ) { 2928 if ( syncManager->mWriteBackFile ) {
2927 abLocal.removeSyncAddressees( true ); 2929 abLocal.removeSyncAddressees( true );
2928 abLocal.saveABphone( fileName ); 2930 abLocal.saveABphone( fileName );
2929 abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); 2931 abLocal.findNewExtIds( fileName, mCurrentSyncDevice );
2930 //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); 2932 //abLocal.preparePhoneSync( mCurrentSyncDevice, false );
2931 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); 2933 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true );
2932 } 2934 }
2933 } 2935 }
2934 setModified(); 2936 setModified();
2935 } 2937 }
2938 abLocal.removeResources();
2936 if ( syncOK ) 2939 if ( syncOK )
2937 mViewManager->refreshView(); 2940 mViewManager->refreshView();
2938 return syncOK; 2941 return syncOK;
2939} 2942}
2940void KABCore::getFile( bool success ) 2943void KABCore::getFile( bool success )
2941{ 2944{
2942 if ( ! success ) { 2945 if ( ! success ) {
2943 message( i18n("Error receiving file. Nothing changed!") ); 2946 message( i18n("Error receiving file. Nothing changed!") );
2944 return; 2947 return;
2945 } 2948 }
2946 int count = mAddressBook->importFromFile( sentSyncFile() , false, true ); 2949 int count = mAddressBook->importFromFile( sentSyncFile() , false, true );
2947 if ( count ) 2950 if ( count )
2948 setModified( true ); 2951 setModified( true );
2949 message( i18n("Pi-Sync successful!") ); 2952 message( i18n("Pi-Sync successful!") );
2950 mViewManager->refreshView(); 2953 mViewManager->refreshView();
2951} 2954}
2952void KABCore::syncFileRequest() 2955void KABCore::syncFileRequest()
2953{ 2956{
2954 if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) { 2957 if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) {
2955 syncManager->slotSyncMenu( 999 ); 2958 syncManager->slotSyncMenu( 999 );
2956 } 2959 }
2957 mAddressBook->export2File( sentSyncFile() ); 2960 mAddressBook->export2File( sentSyncFile() );
2958} 2961}
2959QString KABCore::sentSyncFile() 2962QString KABCore::sentSyncFile()
2960{ 2963{
2961#ifdef DESKTOP_VERSION 2964#ifdef DESKTOP_VERSION
2962 return locateLocal( "tmp", "copysyncab.vcf" ); 2965 return locateLocal( "tmp", "copysyncab.vcf" );
2963#else 2966#else
2964 return QString( "/tmp/copysyncab.vcf" ); 2967 return QString( "/tmp/copysyncab.vcf" );
2965#endif 2968#endif
2966} 2969}
2967 2970
2968void KABCore::setCaptionBack() 2971void KABCore::setCaptionBack()
2969{ 2972{
2970 mMessageTimer->stop(); 2973 mMessageTimer->stop();
2971 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); 2974 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") );
2972} 2975}