summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-09 16:58:08 (UTC)
committer zautrix <zautrix>2004-10-09 16:58:08 (UTC)
commit59ed933d6c43ecb0ddd3dec53cc289ee8aa68482 (patch) (unidiff)
tree8b1cbcf9c420e7dffd1e1293bcfa69e8e821f3fa
parentb80a099d9432bdc3d4eea778b1813b82b2680ecf (diff)
downloadkdepimpi-59ed933d6c43ecb0ddd3dec53cc289ee8aa68482.zip
kdepimpi-59ed933d6c43ecb0ddd3dec53cc289ee8aa68482.tar.gz
kdepimpi-59ed933d6c43ecb0ddd3dec53cc289ee8aa68482.tar.bz2
fixed sync bug
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp72
-rw-r--r--kabc/addressbook.h4
-rw-r--r--kabc/addressee.cpp12
-rw-r--r--kabc/addressee.h5
-rw-r--r--kaddressbook/kabcore.cpp2
5 files changed, 66 insertions, 29 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 1050f55..ff05f7e 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -22,796 +22,816 @@
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 "addressbook.h" 50#include "addressbook.h"
51#include "resource.h" 51#include "resource.h"
52#include "vcardconverter.h" 52#include "vcardconverter.h"
53#include "vcardparser/vcardtool.h" 53#include "vcardparser/vcardtool.h"
54 54
55//US #include "addressbook.moc" 55//US #include "addressbook.moc"
56 56
57using namespace KABC; 57using namespace KABC;
58 58
59struct AddressBook::AddressBookData 59struct AddressBook::AddressBookData
60{ 60{
61 Addressee::List mAddressees; 61 Addressee::List mAddressees;
62 Addressee::List mRemovedAddressees; 62 Addressee::List mRemovedAddressees;
63 Field::List mAllFields; 63 Field::List mAllFields;
64 KConfig *mConfig; 64 KConfig *mConfig;
65 KRES::Manager<Resource> *mManager; 65 KRES::Manager<Resource> *mManager;
66//US ErrorHandler *mErrorHandler; 66//US ErrorHandler *mErrorHandler;
67}; 67};
68 68
69struct AddressBook::Iterator::IteratorData 69struct AddressBook::Iterator::IteratorData
70{ 70{
71 Addressee::List::Iterator mIt; 71 Addressee::List::Iterator mIt;
72}; 72};
73 73
74struct AddressBook::ConstIterator::ConstIteratorData 74struct AddressBook::ConstIterator::ConstIteratorData
75{ 75{
76 Addressee::List::ConstIterator mIt; 76 Addressee::List::ConstIterator mIt;
77}; 77};
78 78
79AddressBook::Iterator::Iterator() 79AddressBook::Iterator::Iterator()
80{ 80{
81 d = new IteratorData; 81 d = new IteratorData;
82} 82}
83 83
84AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) 84AddressBook::Iterator::Iterator( const AddressBook::Iterator &i )
85{ 85{
86 d = new IteratorData; 86 d = new IteratorData;
87 d->mIt = i.d->mIt; 87 d->mIt = i.d->mIt;
88} 88}
89 89
90AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) 90AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i )
91{ 91{
92 if( this == &i ) return *this; // guard against self assignment 92 if( this == &i ) return *this; // guard against self assignment
93 delete d; // delete the old data the Iterator was completely constructed before 93 delete d; // delete the old data the Iterator was completely constructed before
94 d = new IteratorData; 94 d = new IteratorData;
95 d->mIt = i.d->mIt; 95 d->mIt = i.d->mIt;
96 return *this; 96 return *this;
97} 97}
98 98
99AddressBook::Iterator::~Iterator() 99AddressBook::Iterator::~Iterator()
100{ 100{
101 delete d; 101 delete d;
102} 102}
103 103
104const Addressee &AddressBook::Iterator::operator*() const 104const Addressee &AddressBook::Iterator::operator*() const
105{ 105{
106 return *(d->mIt); 106 return *(d->mIt);
107} 107}
108 108
109Addressee &AddressBook::Iterator::operator*() 109Addressee &AddressBook::Iterator::operator*()
110{ 110{
111 return *(d->mIt); 111 return *(d->mIt);
112} 112}
113 113
114Addressee *AddressBook::Iterator::operator->() 114Addressee *AddressBook::Iterator::operator->()
115{ 115{
116 return &(*(d->mIt)); 116 return &(*(d->mIt));
117} 117}
118 118
119AddressBook::Iterator &AddressBook::Iterator::operator++() 119AddressBook::Iterator &AddressBook::Iterator::operator++()
120{ 120{
121 (d->mIt)++; 121 (d->mIt)++;
122 return *this; 122 return *this;
123} 123}
124 124
125AddressBook::Iterator &AddressBook::Iterator::operator++(int) 125AddressBook::Iterator &AddressBook::Iterator::operator++(int)
126{ 126{
127 (d->mIt)++; 127 (d->mIt)++;
128 return *this; 128 return *this;
129} 129}
130 130
131AddressBook::Iterator &AddressBook::Iterator::operator--() 131AddressBook::Iterator &AddressBook::Iterator::operator--()
132{ 132{
133 (d->mIt)--; 133 (d->mIt)--;
134 return *this; 134 return *this;
135} 135}
136 136
137AddressBook::Iterator &AddressBook::Iterator::operator--(int) 137AddressBook::Iterator &AddressBook::Iterator::operator--(int)
138{ 138{
139 (d->mIt)--; 139 (d->mIt)--;
140 return *this; 140 return *this;
141} 141}
142 142
143bool AddressBook::Iterator::operator==( const Iterator &it ) 143bool AddressBook::Iterator::operator==( const Iterator &it )
144{ 144{
145 return ( d->mIt == it.d->mIt ); 145 return ( d->mIt == it.d->mIt );
146} 146}
147 147
148bool AddressBook::Iterator::operator!=( const Iterator &it ) 148bool AddressBook::Iterator::operator!=( const Iterator &it )
149{ 149{
150 return ( d->mIt != it.d->mIt ); 150 return ( d->mIt != it.d->mIt );
151} 151}
152 152
153 153
154AddressBook::ConstIterator::ConstIterator() 154AddressBook::ConstIterator::ConstIterator()
155{ 155{
156 d = new ConstIteratorData; 156 d = new ConstIteratorData;
157} 157}
158 158
159AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) 159AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i )
160{ 160{
161 d = new ConstIteratorData; 161 d = new ConstIteratorData;
162 d->mIt = i.d->mIt; 162 d->mIt = i.d->mIt;
163} 163}
164 164
165AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) 165AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i )
166{ 166{
167 if( this == &i ) return *this; // guard for self assignment 167 if( this == &i ) return *this; // guard for self assignment
168 delete d; // delete the old data because the Iterator was really constructed before 168 delete d; // delete the old data because the Iterator was really constructed before
169 d = new ConstIteratorData; 169 d = new ConstIteratorData;
170 d->mIt = i.d->mIt; 170 d->mIt = i.d->mIt;
171 return *this; 171 return *this;
172} 172}
173 173
174AddressBook::ConstIterator::~ConstIterator() 174AddressBook::ConstIterator::~ConstIterator()
175{ 175{
176 delete d; 176 delete d;
177} 177}
178 178
179const Addressee &AddressBook::ConstIterator::operator*() const 179const Addressee &AddressBook::ConstIterator::operator*() const
180{ 180{
181 return *(d->mIt); 181 return *(d->mIt);
182} 182}
183 183
184const Addressee* AddressBook::ConstIterator::operator->() const 184const Addressee* AddressBook::ConstIterator::operator->() const
185{ 185{
186 return &(*(d->mIt)); 186 return &(*(d->mIt));
187} 187}
188 188
189AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() 189AddressBook::ConstIterator &AddressBook::ConstIterator::operator++()
190{ 190{
191 (d->mIt)++; 191 (d->mIt)++;
192 return *this; 192 return *this;
193} 193}
194 194
195AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) 195AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int)
196{ 196{
197 (d->mIt)++; 197 (d->mIt)++;
198 return *this; 198 return *this;
199} 199}
200 200
201AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() 201AddressBook::ConstIterator &AddressBook::ConstIterator::operator--()
202{ 202{
203 (d->mIt)--; 203 (d->mIt)--;
204 return *this; 204 return *this;
205} 205}
206 206
207AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) 207AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int)
208{ 208{
209 (d->mIt)--; 209 (d->mIt)--;
210 return *this; 210 return *this;
211} 211}
212 212
213bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) 213bool AddressBook::ConstIterator::operator==( const ConstIterator &it )
214{ 214{
215 return ( d->mIt == it.d->mIt ); 215 return ( d->mIt == it.d->mIt );
216} 216}
217 217
218bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) 218bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
219{ 219{
220 return ( d->mIt != it.d->mIt ); 220 return ( d->mIt != it.d->mIt );
221} 221}
222 222
223 223
224AddressBook::AddressBook() 224AddressBook::AddressBook()
225{ 225{
226 init(0, "contact"); 226 init(0, "contact");
227} 227}
228 228
229AddressBook::AddressBook( const QString &config ) 229AddressBook::AddressBook( const QString &config )
230{ 230{
231 init(config, "contact"); 231 init(config, "contact");
232} 232}
233 233
234AddressBook::AddressBook( const QString &config, const QString &family ) 234AddressBook::AddressBook( const QString &config, const QString &family )
235{ 235{
236 init(config, family); 236 init(config, family);
237 237
238} 238}
239 239
240// the default family is "contact" 240// the default family is "contact"
241void AddressBook::init(const QString &config, const QString &family ) 241void AddressBook::init(const QString &config, const QString &family )
242{ 242{
243 blockLSEchange = false; 243 blockLSEchange = false;
244 d = new AddressBookData; 244 d = new AddressBookData;
245 QString fami = family; 245 QString fami = family;
246 if (config != 0) { 246 if (config != 0) {
247 if ( family == "syncContact" ) { 247 if ( family == "syncContact" ) {
248 qDebug("creating sync config "); 248 qDebug("creating sync config ");
249 fami = "contact"; 249 fami = "contact";
250 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); 250 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") );
251 con->setGroup( "General" ); 251 con->setGroup( "General" );
252 con->writeEntry( "ResourceKeys", QString("sync") ); 252 con->writeEntry( "ResourceKeys", QString("sync") );
253 con->writeEntry( "Standard", QString("sync") ); 253 con->writeEntry( "Standard", QString("sync") );
254 con->setGroup( "Resource_sync" ); 254 con->setGroup( "Resource_sync" );
255 con->writeEntry( "FileName", config ); 255 con->writeEntry( "FileName", config );
256 con->writeEntry( "FileFormat", QString("vcard") ); 256 con->writeEntry( "FileFormat", QString("vcard") );
257 con->writeEntry( "ResourceIdentifier", QString("sync") ); 257 con->writeEntry( "ResourceIdentifier", QString("sync") );
258 con->writeEntry( "ResourceName", QString("sync_res") ); 258 con->writeEntry( "ResourceName", QString("sync_res") );
259 if ( config.right(4) == ".xml" ) 259 if ( config.right(4) == ".xml" )
260 con->writeEntry( "ResourceType", QString("qtopia") ); 260 con->writeEntry( "ResourceType", QString("qtopia") );
261 else if ( config == "sharp" ) { 261 else if ( config == "sharp" ) {
262 con->writeEntry( "ResourceType", QString("sharp") ); 262 con->writeEntry( "ResourceType", QString("sharp") );
263 } else { 263 } else {
264 con->writeEntry( "ResourceType", QString("file") ); 264 con->writeEntry( "ResourceType", QString("file") );
265 } 265 }
266 //con->sync(); 266 //con->sync();
267 d->mConfig = con; 267 d->mConfig = con;
268 } 268 }
269 else 269 else
270 d->mConfig = new KConfig( locateLocal("config", config) ); 270 d->mConfig = new KConfig( locateLocal("config", config) );
271// qDebug("AddressBook::init 1 config=%s",config.latin1() ); 271// qDebug("AddressBook::init 1 config=%s",config.latin1() );
272 } 272 }
273 else { 273 else {
274 d->mConfig = 0; 274 d->mConfig = 0;
275// qDebug("AddressBook::init 1 config=0"); 275// qDebug("AddressBook::init 1 config=0");
276 } 276 }
277 277
278//US d->mErrorHandler = 0; 278//US d->mErrorHandler = 0;
279 d->mManager = new KRES::Manager<Resource>( fami, false ); 279 d->mManager = new KRES::Manager<Resource>( fami, false );
280 d->mManager->readConfig( d->mConfig ); 280 d->mManager->readConfig( d->mConfig );
281 if ( family == "syncContact" ) { 281 if ( family == "syncContact" ) {
282 KRES::Manager<Resource> *manager = d->mManager; 282 KRES::Manager<Resource> *manager = d->mManager;
283 KRES::Manager<Resource>::ActiveIterator it; 283 KRES::Manager<Resource>::ActiveIterator it;
284 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 284 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
285 (*it)->setAddressBook( this ); 285 (*it)->setAddressBook( this );
286 if ( !(*it)->open() ) 286 if ( !(*it)->open() )
287 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 287 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
288 } 288 }
289 Resource *res = standardResource(); 289 Resource *res = standardResource();
290 if ( !res ) { 290 if ( !res ) {
291 qDebug("ERROR: no standard resource"); 291 qDebug("ERROR: no standard resource");
292 res = manager->createResource( "file" ); 292 res = manager->createResource( "file" );
293 if ( res ) 293 if ( res )
294 { 294 {
295 addResource( res ); 295 addResource( res );
296 } 296 }
297 else 297 else
298 qDebug(" No resource available!!!"); 298 qDebug(" No resource available!!!");
299 } 299 }
300 setStandardResource( res ); 300 setStandardResource( res );
301 manager->writeConfig(); 301 manager->writeConfig();
302 } 302 }
303 addCustomField( i18n( "Department" ), KABC::Field::Organization, 303 addCustomField( i18n( "Department" ), KABC::Field::Organization,
304 "X-Department", "KADDRESSBOOK" ); 304 "X-Department", "KADDRESSBOOK" );
305 addCustomField( i18n( "Profession" ), KABC::Field::Organization, 305 addCustomField( i18n( "Profession" ), KABC::Field::Organization,
306 "X-Profession", "KADDRESSBOOK" ); 306 "X-Profession", "KADDRESSBOOK" );
307 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 307 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
308 "X-AssistantsName", "KADDRESSBOOK" ); 308 "X-AssistantsName", "KADDRESSBOOK" );
309 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 309 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
310 "X-ManagersName", "KADDRESSBOOK" ); 310 "X-ManagersName", "KADDRESSBOOK" );
311 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 311 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
312 "X-SpousesName", "KADDRESSBOOK" ); 312 "X-SpousesName", "KADDRESSBOOK" );
313 addCustomField( i18n( "Office" ), KABC::Field::Personal, 313 addCustomField( i18n( "Office" ), KABC::Field::Personal,
314 "X-Office", "KADDRESSBOOK" ); 314 "X-Office", "KADDRESSBOOK" );
315 addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 315 addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
316 "X-IMAddress", "KADDRESSBOOK" ); 316 "X-IMAddress", "KADDRESSBOOK" );
317 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 317 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
318 "X-Anniversary", "KADDRESSBOOK" ); 318 "X-Anniversary", "KADDRESSBOOK" );
319 319
320 //US added this field to become compatible with Opie/qtopia addressbook 320 //US added this field to become compatible with Opie/qtopia addressbook
321 // values can be "female" or "male" or "". An empty field represents undefined. 321 // values can be "female" or "male" or "". An empty field represents undefined.
322 addCustomField( i18n( "Gender" ), KABC::Field::Personal, 322 addCustomField( i18n( "Gender" ), KABC::Field::Personal,
323 "X-Gender", "KADDRESSBOOK" ); 323 "X-Gender", "KADDRESSBOOK" );
324 addCustomField( i18n( "Children" ), KABC::Field::Personal, 324 addCustomField( i18n( "Children" ), KABC::Field::Personal,
325 "X-Children", "KADDRESSBOOK" ); 325 "X-Children", "KADDRESSBOOK" );
326 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 326 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
327 "X-FreeBusyUrl", "KADDRESSBOOK" ); 327 "X-FreeBusyUrl", "KADDRESSBOOK" );
328 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, 328 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal,
329 "X-ExternalID", "KADDRESSBOOK" ); 329 "X-ExternalID", "KADDRESSBOOK" );
330} 330}
331 331
332AddressBook::~AddressBook() 332AddressBook::~AddressBook()
333{ 333{
334 delete d->mConfig; d->mConfig = 0; 334 delete d->mConfig; d->mConfig = 0;
335 delete d->mManager; d->mManager = 0; 335 delete d->mManager; d->mManager = 0;
336//US delete d->mErrorHandler; d->mErrorHandler = 0; 336//US delete d->mErrorHandler; d->mErrorHandler = 0;
337 delete d; d = 0; 337 delete d; d = 0;
338} 338}
339 339
340bool AddressBook::load() 340bool AddressBook::load()
341{ 341{
342 342
343 343
344 clear(); 344 clear();
345 345
346 KRES::Manager<Resource>::ActiveIterator it; 346 KRES::Manager<Resource>::ActiveIterator it;
347 bool ok = true; 347 bool ok = true;
348 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 348 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
349 if ( !(*it)->load() ) { 349 if ( !(*it)->load() ) {
350 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 350 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
351 ok = false; 351 ok = false;
352 } 352 }
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}
379void AddressBook::export2File( QString fileName ) 379void AddressBook::export2File( QString fileName )
380{ 380{
381 381
382 QFile outFile( fileName ); 382 QFile outFile( fileName );
383 if ( !outFile.open( IO_WriteOnly ) ) { 383 if ( !outFile.open( IO_WriteOnly ) ) {
384 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); 384 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" );
385 KMessageBox::error( 0, text.arg( fileName ) ); 385 KMessageBox::error( 0, text.arg( fileName ) );
386 return ; 386 return ;
387 } 387 }
388 QTextStream t( &outFile ); 388 QTextStream t( &outFile );
389 t.setEncoding( QTextStream::UnicodeUTF8 ); 389 t.setEncoding( QTextStream::UnicodeUTF8 );
390 Iterator it; 390 Iterator it;
391 KABC::VCardConverter::Version version; 391 KABC::VCardConverter::Version version;
392 version = KABC::VCardConverter::v3_0; 392 version = KABC::VCardConverter::v3_0;
393 for ( it = begin(); it != end(); ++it ) { 393 for ( it = begin(); it != end(); ++it ) {
394 if ( !(*it).IDStr().isEmpty() ) { 394 if ( !(*it).IDStr().isEmpty() ) {
395 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); 395 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() );
396 } 396 }
397 KABC::VCardConverter converter; 397 KABC::VCardConverter converter;
398 QString vcard; 398 QString vcard;
399 //Resource *resource() const; 399 //Resource *resource() const;
400 converter.addresseeToVCard( *it, vcard, version ); 400 converter.addresseeToVCard( *it, vcard, version );
401 t << vcard << "\r\n"; 401 t << vcard << "\r\n";
402 } 402 }
403 t << "\r\n\r\n"; 403 t << "\r\n\r\n";
404 outFile.close(); 404 outFile.close();
405} 405}
406void AddressBook::importFromFile( QString fileName, bool replaceLabel ) 406void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld )
407{ 407{
408 408
409 KABC::Addressee::List list; 409 if ( removeOld )
410 QFile file( fileName ); 410 setUntagged();
411 411 KABC::Addressee::List list;
412 file.open( IO_ReadOnly ); 412 QFile file( fileName );
413 QByteArray rawData = file.readAll(); 413 file.open( IO_ReadOnly );
414 file.close(); 414 QByteArray rawData = file.readAll();
415 QString data; 415 file.close();
416 if ( replaceLabel ) { 416 QString data;
417 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); 417 if ( replaceLabel ) {
418 data.replace ( QRegExp("LABEL") , "ADR" ); 418 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 );
419 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); 419 data.replace ( QRegExp("LABEL") , "ADR" );
420 } else 420 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" );
421 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 421 } else
422 KABC::VCardTool tool; 422 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
423 list = tool.parseVCards( data ); 423 KABC::VCardTool tool;
424 KABC::Addressee::List::Iterator it; 424 list = tool.parseVCards( data );
425 for ( it = list.begin(); it != list.end(); ++it ) { 425 KABC::Addressee::List::Iterator it;
426 (*it).setResource( 0 ); 426 for ( it = list.begin(); it != list.end(); ++it ) {
427 if ( replaceLabel ) 427 (*it).setResource( 0 );
428 (*it).removeVoice(); 428 if ( replaceLabel )
429 insertAddressee( (*it), false, true ); 429 (*it).removeVoice();
430 if ( removeOld )
431 (*it).setTagged( true );
432 insertAddressee( (*it), false, true );
433 }
434 if ( removeOld )
435 removeUntagged();
436}
437void AddressBook::setUntagged()
438{
439 Iterator ait;
440 for ( ait = begin(); ait != end(); ++ait ) {
441 (*ait).setTagged( false );
442 }
443}
444void AddressBook::removeUntagged()
445{
446 Iterator ait;
447 for ( ait = begin(); ait != end(); ++ait ) {
448 if (!(*ait).tagged())
449 removeAddressee( ait );
430 } 450 }
431 451
452 deleteRemovedAddressees();
432} 453}
433
434bool AddressBook::saveAB() 454bool AddressBook::saveAB()
435{ 455{
436 bool ok = true; 456 bool ok = true;
437 457
438 deleteRemovedAddressees(); 458 deleteRemovedAddressees();
439 Iterator ait; 459 Iterator ait;
440 for ( ait = begin(); ait != end(); ++ait ) { 460 for ( ait = begin(); ait != end(); ++ait ) {
441 if ( !(*ait).IDStr().isEmpty() ) { 461 if ( !(*ait).IDStr().isEmpty() ) {
442 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); 462 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
443 } 463 }
444 } 464 }
445 KRES::Manager<Resource>::ActiveIterator it; 465 KRES::Manager<Resource>::ActiveIterator it;
446 KRES::Manager<Resource> *manager = d->mManager; 466 KRES::Manager<Resource> *manager = d->mManager;
447 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 467 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
448 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 468 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
449 Ticket *ticket = requestSaveTicket( *it ); 469 Ticket *ticket = requestSaveTicket( *it );
450// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 470// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
451 if ( !ticket ) { 471 if ( !ticket ) {
452 error( i18n( "Unable to save to resource '%1'. It is locked." ) 472 error( i18n( "Unable to save to resource '%1'. It is locked." )
453 .arg( (*it)->resourceName() ) ); 473 .arg( (*it)->resourceName() ) );
454 return false; 474 return false;
455 } 475 }
456 476
457 //if ( !save( ticket ) ) 477 //if ( !save( ticket ) )
458 if ( ticket->resource() ) { 478 if ( ticket->resource() ) {
459 if ( ! ticket->resource()->save( ticket ) ) 479 if ( ! ticket->resource()->save( ticket ) )
460 ok = false; 480 ok = false;
461 } else 481 } else
462 ok = false; 482 ok = false;
463 483
464 } 484 }
465 } 485 }
466 return ok; 486 return ok;
467} 487}
468 488
469AddressBook::Iterator AddressBook::begin() 489AddressBook::Iterator AddressBook::begin()
470{ 490{
471 Iterator it = Iterator(); 491 Iterator it = Iterator();
472 it.d->mIt = d->mAddressees.begin(); 492 it.d->mIt = d->mAddressees.begin();
473 return it; 493 return it;
474} 494}
475 495
476AddressBook::ConstIterator AddressBook::begin() const 496AddressBook::ConstIterator AddressBook::begin() const
477{ 497{
478 ConstIterator it = ConstIterator(); 498 ConstIterator it = ConstIterator();
479 it.d->mIt = d->mAddressees.begin(); 499 it.d->mIt = d->mAddressees.begin();
480 return it; 500 return it;
481} 501}
482 502
483AddressBook::Iterator AddressBook::end() 503AddressBook::Iterator AddressBook::end()
484{ 504{
485 Iterator it = Iterator(); 505 Iterator it = Iterator();
486 it.d->mIt = d->mAddressees.end(); 506 it.d->mIt = d->mAddressees.end();
487 return it; 507 return it;
488} 508}
489 509
490AddressBook::ConstIterator AddressBook::end() const 510AddressBook::ConstIterator AddressBook::end() const
491{ 511{
492 ConstIterator it = ConstIterator(); 512 ConstIterator it = ConstIterator();
493 it.d->mIt = d->mAddressees.end(); 513 it.d->mIt = d->mAddressees.end();
494 return it; 514 return it;
495} 515}
496 516
497void AddressBook::clear() 517void AddressBook::clear()
498{ 518{
499 d->mAddressees.clear(); 519 d->mAddressees.clear();
500} 520}
501 521
502Ticket *AddressBook::requestSaveTicket( Resource *resource ) 522Ticket *AddressBook::requestSaveTicket( Resource *resource )
503{ 523{
504 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 524 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
505 525
506 if ( !resource ) 526 if ( !resource )
507 { 527 {
508 qDebug("AddressBook::requestSaveTicket no resource" ); 528 qDebug("AddressBook::requestSaveTicket no resource" );
509 resource = standardResource(); 529 resource = standardResource();
510 } 530 }
511 531
512 KRES::Manager<Resource>::ActiveIterator it; 532 KRES::Manager<Resource>::ActiveIterator it;
513 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 533 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
514 if ( (*it) == resource ) { 534 if ( (*it) == resource ) {
515 if ( (*it)->readOnly() || !(*it)->isOpen() ) 535 if ( (*it)->readOnly() || !(*it)->isOpen() )
516 return 0; 536 return 0;
517 else 537 else
518 return (*it)->requestSaveTicket(); 538 return (*it)->requestSaveTicket();
519 } 539 }
520 } 540 }
521 541
522 return 0; 542 return 0;
523} 543}
524 544
525void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) 545void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource )
526{ 546{
527 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { 547 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
528 //qDebug("block insert "); 548 //qDebug("block insert ");
529 return; 549 return;
530 } 550 }
531 //qDebug("inserting.... %s ",a.uid().latin1() ); 551 //qDebug("inserting.... %s ",a.uid().latin1() );
532 bool found = false; 552 bool found = false;
533 Addressee::List::Iterator it; 553 Addressee::List::Iterator it;
534 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 554 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
535 if ( a.uid() == (*it).uid() ) { 555 if ( a.uid() == (*it).uid() ) {
536 556
537 bool changed = false; 557 bool changed = false;
538 Addressee addr = a; 558 Addressee addr = a;
539 if ( addr != (*it) ) 559 if ( addr != (*it) )
540 changed = true; 560 changed = true;
541 561
542 if ( takeResource ) { 562 if ( takeResource ) {
543 Resource * res = (*it).resource(); 563 Resource * res = (*it).resource();
544 (*it) = a; 564 (*it) = a;
545 (*it).setResource( res ); 565 (*it).setResource( res );
546 } else { 566 } else {
547 (*it) = a; 567 (*it) = a;
548 if ( (*it).resource() == 0 ) 568 if ( (*it).resource() == 0 )
549 (*it).setResource( standardResource() ); 569 (*it).setResource( standardResource() );
550 } 570 }
551 if ( changed ) { 571 if ( changed ) {
552 if ( setRev ) { 572 if ( setRev ) {
553 573
554 // get rid of micro seconds 574 // get rid of micro seconds
555 QDateTime dt = QDateTime::currentDateTime(); 575 QDateTime dt = QDateTime::currentDateTime();
556 QTime t = dt.time(); 576 QTime t = dt.time();
557 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 577 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
558 (*it).setRevision( dt ); 578 (*it).setRevision( dt );
559 } 579 }
560 (*it).setChanged( true ); 580 (*it).setChanged( true );
561 } 581 }
562 582
563 found = true; 583 found = true;
564 } else { 584 } else {
565 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 585 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
566 QString name = (*it).uid().mid( 19 ); 586 QString name = (*it).uid().mid( 19 );
567 Addressee b = a; 587 Addressee b = a;
568 QString id = b.getID( name ); 588 QString id = b.getID( name );
569 if ( ! id.isEmpty() ) { 589 if ( ! id.isEmpty() ) {
570 QString des = (*it).note(); 590 QString des = (*it).note();
571 int startN; 591 int startN;
572 if( (startN = des.find( id ) ) >= 0 ) { 592 if( (startN = des.find( id ) ) >= 0 ) {
573 int endN = des.find( ",", startN+1 ); 593 int endN = des.find( ",", startN+1 );
574 des = des.left( startN ) + des.mid( endN+1 ); 594 des = des.left( startN ) + des.mid( endN+1 );
575 (*it).setNote( des ); 595 (*it).setNote( des );
576 } 596 }
577 } 597 }
578 } 598 }
579 } 599 }
580 } 600 }
581 if ( found ) 601 if ( found )
582 return; 602 return;
583 d->mAddressees.append( a ); 603 d->mAddressees.append( a );
584 Addressee& addr = d->mAddressees.last(); 604 Addressee& addr = d->mAddressees.last();
585 if ( addr.resource() == 0 ) 605 if ( addr.resource() == 0 )
586 addr.setResource( standardResource() ); 606 addr.setResource( standardResource() );
587 607
588 addr.setChanged( true ); 608 addr.setChanged( true );
589} 609}
590 610
591void AddressBook::removeAddressee( const Addressee &a ) 611void AddressBook::removeAddressee( const Addressee &a )
592{ 612{
593 Iterator it; 613 Iterator it;
594 Iterator it2; 614 Iterator it2;
595 bool found = false; 615 bool found = false;
596 for ( it = begin(); it != end(); ++it ) { 616 for ( it = begin(); it != end(); ++it ) {
597 if ( a.uid() == (*it).uid() ) { 617 if ( a.uid() == (*it).uid() ) {
598 found = true; 618 found = true;
599 it2 = it; 619 it2 = it;
600 } else { 620 } else {
601 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 621 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
602 QString name = (*it).uid().mid( 19 ); 622 QString name = (*it).uid().mid( 19 );
603 Addressee b = a; 623 Addressee b = a;
604 QString id = b.getID( name ); 624 QString id = b.getID( name );
605 if ( ! id.isEmpty() ) { 625 if ( ! id.isEmpty() ) {
606 QString des = (*it).note(); 626 QString des = (*it).note();
607 if( des.find( id ) < 0 ) { 627 if( des.find( id ) < 0 ) {
608 des += id + ","; 628 des += id + ",";
609 (*it).setNote( des ); 629 (*it).setNote( des );
610 } 630 }
611 } 631 }
612 } 632 }
613 633
614 } 634 }
615 } 635 }
616 636
617 if ( found ) 637 if ( found )
618 removeAddressee( it2 ); 638 removeAddressee( it2 );
619 639
620} 640}
621 641
622void AddressBook::removeSyncAddressees( bool removeDeleted ) 642void AddressBook::removeSyncAddressees( bool removeDeleted )
623{ 643{
624 Iterator it = begin(); 644 Iterator it = begin();
625 Iterator it2 ; 645 Iterator it2 ;
626 QDateTime dt ( QDate( 2004,1,1) ); 646 QDateTime dt ( QDate( 2004,1,1) );
627 while ( it != end() ) { 647 while ( it != end() ) {
628 (*it).setRevision( dt ); 648 (*it).setRevision( dt );
629 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); 649 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" );
630 (*it).setIDStr(""); 650 (*it).setIDStr("");
631 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { 651 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) {
632 it2 = it; 652 it2 = it;
633 //qDebug("removing %s ",(*it).uid().latin1() ); 653 //qDebug("removing %s ",(*it).uid().latin1() );
634 ++it; 654 ++it;
635 removeAddressee( it2 ); 655 removeAddressee( it2 );
636 } else { 656 } else {
637 //qDebug("skipping %s ",(*it).uid().latin1() ); 657 //qDebug("skipping %s ",(*it).uid().latin1() );
638 ++it; 658 ++it;
639 } 659 }
640 } 660 }
641 deleteRemovedAddressees(); 661 deleteRemovedAddressees();
642} 662}
643 663
644void AddressBook::removeAddressee( const Iterator &it ) 664void AddressBook::removeAddressee( const Iterator &it )
645{ 665{
646 d->mRemovedAddressees.append( (*it) ); 666 d->mRemovedAddressees.append( (*it) );
647 d->mAddressees.remove( it.d->mIt ); 667 d->mAddressees.remove( it.d->mIt );
648} 668}
649 669
650AddressBook::Iterator AddressBook::find( const Addressee &a ) 670AddressBook::Iterator AddressBook::find( const Addressee &a )
651{ 671{
652 Iterator it; 672 Iterator it;
653 for ( it = begin(); it != end(); ++it ) { 673 for ( it = begin(); it != end(); ++it ) {
654 if ( a.uid() == (*it).uid() ) { 674 if ( a.uid() == (*it).uid() ) {
655 return it; 675 return it;
656 } 676 }
657 } 677 }
658 return end(); 678 return end();
659} 679}
660 680
661Addressee AddressBook::findByUid( const QString &uid ) 681Addressee AddressBook::findByUid( const QString &uid )
662{ 682{
663 Iterator it; 683 Iterator it;
664 for ( it = begin(); it != end(); ++it ) { 684 for ( it = begin(); it != end(); ++it ) {
665 if ( uid == (*it).uid() ) { 685 if ( uid == (*it).uid() ) {
666 return *it; 686 return *it;
667 } 687 }
668 } 688 }
669 return Addressee(); 689 return Addressee();
670} 690}
671void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) 691void AddressBook::preExternSync( AddressBook* aBook, const QString& csd )
672{ 692{
673 //qDebug("AddressBook::preExternSync "); 693 //qDebug("AddressBook::preExternSync ");
674 AddressBook::Iterator it; 694 AddressBook::Iterator it;
675 for ( it = begin(); it != end(); ++it ) { 695 for ( it = begin(); it != end(); ++it ) {
676 (*it).setID( csd, (*it).externalUID() ); 696 (*it).setID( csd, (*it).externalUID() );
677 (*it).computeCsum( csd ); 697 (*it).computeCsum( csd );
678 } 698 }
679 mergeAB( aBook ,csd ); 699 mergeAB( aBook ,csd );
680} 700}
681void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) 701void AddressBook::postExternSync( AddressBook* aBook , const QString& csd)
682{ 702{
683 //qDebug("AddressBook::postExternSync "); 703 //qDebug("AddressBook::postExternSync ");
684 AddressBook::Iterator it; 704 AddressBook::Iterator it;
685 for ( it = begin(); it != end(); ++it ) { 705 for ( it = begin(); it != end(); ++it ) {
686 // qDebug("check uid %s ", (*it).uid().latin1() ); 706 // qDebug("check uid %s ", (*it).uid().latin1() );
687 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || 707 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ||
688 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { 708 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) {
689 Addressee ad = aBook->findByUid( ( (*it).uid() )); 709 Addressee ad = aBook->findByUid( ( (*it).uid() ));
690 if ( ad.isEmpty() ) { 710 if ( ad.isEmpty() ) {
691 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); 711 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1());
692 } else { 712 } else {
693 (*it).computeCsum( csd ); 713 (*it).computeCsum( csd );
694 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) 714 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID )
695 ad.setID( csd, (*it).externalUID() ); 715 ad.setID( csd, (*it).externalUID() );
696 ad.setCsum( csd, (*it).getCsum( csd ) ); 716 ad.setCsum( csd, (*it).getCsum( csd ) );
697 aBook->insertAddressee( ad ); 717 aBook->insertAddressee( ad );
698 } 718 }
699 } 719 }
700 } 720 }
701} 721}
702 722
703bool AddressBook::containsExternalUid( const QString& uid ) 723bool AddressBook::containsExternalUid( const QString& uid )
704{ 724{
705 Iterator it; 725 Iterator it;
706 for ( it = begin(); it != end(); ++it ) { 726 for ( it = begin(); it != end(); ++it ) {
707 if ( uid == (*it).externalUID( ) ) 727 if ( uid == (*it).externalUID( ) )
708 return true; 728 return true;
709 } 729 }
710 return false; 730 return false;
711} 731}
712Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) 732Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile )
713{ 733{
714 Iterator it; 734 Iterator it;
715 for ( it = begin(); it != end(); ++it ) { 735 for ( it = begin(); it != end(); ++it ) {
716 if ( uid == (*it).getID( profile ) ) 736 if ( uid == (*it).getID( profile ) )
717 return (*it); 737 return (*it);
718 } 738 }
719 return Addressee(); 739 return Addressee();
720} 740}
721void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) 741void AddressBook::mergeAB( AddressBook *aBook, const QString& profile )
722{ 742{
723 Iterator it; 743 Iterator it;
724 Addressee ad; 744 Addressee ad;
725 for ( it = begin(); it != end(); ++it ) { 745 for ( it = begin(); it != end(); ++it ) {
726 ad = aBook->findByExternUid( (*it).externalUID(), profile ); 746 ad = aBook->findByExternUid( (*it).externalUID(), profile );
727 if ( !ad.isEmpty() ) { 747 if ( !ad.isEmpty() ) {
728 (*it).mergeContact( ad ); 748 (*it).mergeContact( ad );
729 } 749 }
730 } 750 }
731#if 0 751#if 0
732 // test only 752 // test only
733 for ( it = begin(); it != end(); ++it ) { 753 for ( it = begin(); it != end(); ++it ) {
734 754
735 qDebug("uid %s ", (*it).uid().latin1()); 755 qDebug("uid %s ", (*it).uid().latin1());
736 } 756 }
737#endif 757#endif
738} 758}
739 759
740#if 0 760#if 0
741Addressee::List AddressBook::getExternLastSyncAddressees() 761Addressee::List AddressBook::getExternLastSyncAddressees()
742{ 762{
743 Addressee::List results; 763 Addressee::List results;
744 764
745 Iterator it; 765 Iterator it;
746 for ( it = begin(); it != end(); ++it ) { 766 for ( it = begin(); it != end(); ++it ) {
747 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { 767 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
748 if ( (*it).familyName().left(4) == "!E: " ) 768 if ( (*it).familyName().left(4) == "!E: " )
749 results.append( *it ); 769 results.append( *it );
750 } 770 }
751 } 771 }
752 772
753 return results; 773 return results;
754} 774}
755#endif 775#endif
756void AddressBook::resetTempSyncStat() 776void AddressBook::resetTempSyncStat()
757{ 777{
758 Iterator it; 778 Iterator it;
759 for ( it = begin(); it != end(); ++it ) { 779 for ( it = begin(); it != end(); ++it ) {
760 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); 780 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
761 } 781 }
762 782
763} 783}
764 784
765QStringList AddressBook:: uidList() 785QStringList AddressBook:: uidList()
766{ 786{
767 QStringList results; 787 QStringList results;
768 Iterator it; 788 Iterator it;
769 for ( it = begin(); it != end(); ++it ) { 789 for ( it = begin(); it != end(); ++it ) {
770 results.append( (*it).uid() ); 790 results.append( (*it).uid() );
771 } 791 }
772 return results; 792 return results;
773} 793}
774 794
775 795
776Addressee::List AddressBook::allAddressees() 796Addressee::List AddressBook::allAddressees()
777{ 797{
778 return d->mAddressees; 798 return d->mAddressees;
779 799
780} 800}
781 801
782Addressee::List AddressBook::findByName( const QString &name ) 802Addressee::List AddressBook::findByName( const QString &name )
783{ 803{
784 Addressee::List results; 804 Addressee::List results;
785 805
786 Iterator it; 806 Iterator it;
787 for ( it = begin(); it != end(); ++it ) { 807 for ( it = begin(); it != end(); ++it ) {
788 if ( name == (*it).realName() ) { 808 if ( name == (*it).realName() ) {
789 results.append( *it ); 809 results.append( *it );
790 } 810 }
791 } 811 }
792 812
793 return results; 813 return results;
794} 814}
795 815
796Addressee::List AddressBook::findByEmail( const QString &email ) 816Addressee::List AddressBook::findByEmail( const QString &email )
797{ 817{
798 Addressee::List results; 818 Addressee::List results;
799 QStringList mailList; 819 QStringList mailList;
800 820
801 Iterator it; 821 Iterator it;
802 for ( it = begin(); it != end(); ++it ) { 822 for ( it = begin(); it != end(); ++it ) {
803 mailList = (*it).emails(); 823 mailList = (*it).emails();
804 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 824 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
805 if ( email == (*ite) ) { 825 if ( email == (*ite) ) {
806 results.append( *it ); 826 results.append( *it );
807 } 827 }
808 } 828 }
809 } 829 }
810 830
811 return results; 831 return results;
812} 832}
813 833
814Addressee::List AddressBook::findByCategory( const QString &category ) 834Addressee::List AddressBook::findByCategory( const QString &category )
815{ 835{
816 Addressee::List results; 836 Addressee::List results;
817 837
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index cea1b03..532e05d 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -1,341 +1,343 @@
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 void export2File( QString fileName ); 145 void export2File( QString fileName );
146 void importFromFile( QString fileName, bool replaceLabel = false ); 146 void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false );
147 void setUntagged();
148 void removeUntagged();
147 /** 149 /**
148 Returns a iterator for first entry of address book. 150 Returns a iterator for first entry of address book.
149 */ 151 */
150 Iterator begin(); 152 Iterator begin();
151 153
152 /** 154 /**
153 Returns a const iterator for first entry of address book. 155 Returns a const iterator for first entry of address book.
154 */ 156 */
155 ConstIterator begin() const; 157 ConstIterator begin() const;
156 158
157 /** 159 /**
158 Returns a iterator for first entry of address book. 160 Returns a iterator for first entry of address book.
159 */ 161 */
160 Iterator end(); 162 Iterator end();
161 163
162 /** 164 /**
163 Returns a const iterator for first entry of address book. 165 Returns a const iterator for first entry of address book.
164 */ 166 */
165 ConstIterator end() const; 167 ConstIterator end() const;
166 168
167 /** 169 /**
168 Removes all entries from address book. 170 Removes all entries from address book.
169 */ 171 */
170 void clear(); 172 void clear();
171 173
172 /** 174 /**
173 Insert an Addressee object into address book. If an object with the same 175 Insert an Addressee object into address book. If an object with the same
174 unique id already exists in the address book it it replaced by the new 176 unique id already exists in the address book it it replaced by the new
175 one. If not the new object is appended to the address book. 177 one. If not the new object is appended to the address book.
176 */ 178 */
177 void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); 179 void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
178 180
179 /** 181 /**
180 Removes entry from the address book. 182 Removes entry from the address book.
181 */ 183 */
182 void removeAddressee( const Addressee & ); 184 void removeAddressee( const Addressee & );
183 185
184 /** 186 /**
185 This is like @ref removeAddressee() just above, with the difference that 187 This is like @ref removeAddressee() just above, with the difference that
186 the first element is a iterator, returned by @ref begin(). 188 the first element is a iterator, returned by @ref begin().
187 */ 189 */
188 void removeAddressee( const Iterator & ); 190 void removeAddressee( const Iterator & );
189 191
190 /** 192 /**
191 Find the specified entry in address book. Returns end(), if the entry 193 Find the specified entry in address book. Returns end(), if the entry
192 couldn't be found. 194 couldn't be found.
193 */ 195 */
194 Iterator find( const Addressee & ); 196 Iterator find( const Addressee & );
195 197
196 /** 198 /**
197 Find the entry specified by an unique id. Returns an empty Addressee 199 Find the entry specified by an unique id. Returns an empty Addressee
198 object, if the address book does not contain an entry with this id. 200 object, if the address book does not contain an entry with this id.
199 */ 201 */
200 Addressee findByUid( const QString & ); 202 Addressee findByUid( const QString & );
201 203
202 204
203 /** 205 /**
204 Returns a list of all addressees in the address book. This list can 206 Returns a list of all addressees in the address book. This list can
205 be sorted with @ref KABC::AddresseeList for example. 207 be sorted with @ref KABC::AddresseeList for example.
206 */ 208 */
207 Addressee::List allAddressees(); 209 Addressee::List allAddressees();
208 210
209 /** 211 /**
210 Find all entries with the specified name in the address book. Returns 212 Find all entries with the specified name in the address book. Returns
211 an empty list, if no entries could be found. 213 an empty list, if no entries could be found.
212 */ 214 */
213 Addressee::List findByName( const QString & ); 215 Addressee::List findByName( const QString & );
214 216
215 /** 217 /**
216 Find all entries with the specified email address in the address book. 218 Find all entries with the specified email address in the address book.
217 Returns an empty list, if no entries could be found. 219 Returns an empty list, if no entries could be found.
218 */ 220 */
219 Addressee::List findByEmail( const QString & ); 221 Addressee::List findByEmail( const QString & );
220 222
221 /** 223 /**
222 Find all entries wich have the specified category in the address book. 224 Find all entries wich have the specified category in the address book.
223 Returns an empty list, if no entries could be found. 225 Returns an empty list, if no entries could be found.
224 */ 226 */
225 Addressee::List findByCategory( const QString & ); 227 Addressee::List findByCategory( const QString & );
226 228
227 /** 229 /**
228 Return a string identifying this addressbook. 230 Return a string identifying this addressbook.
229 */ 231 */
230 virtual QString identifier(); 232 virtual QString identifier();
231 233
232 /** 234 /**
233 Used for debug output. 235 Used for debug output.
234 */ 236 */
235 void dump() const; 237 void dump() const;
236 238
237 void emitAddressBookLocked() { emit addressBookLocked( this ); } 239 void emitAddressBookLocked() { emit addressBookLocked( this ); }
238 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } 240 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); }
239 void emitAddressBookChanged() { emit addressBookChanged( this ); } 241 void emitAddressBookChanged() { emit addressBookChanged( this ); }
240 242
241 /** 243 /**
242 Return list of all Fields known to the address book which are associated 244 Return list of all Fields known to the address book which are associated
243 with the given field category. 245 with the given field category.
244 */ 246 */
245 Field::List fields( int category = Field::All ); 247 Field::List fields( int category = Field::All );
246 248
247 /** 249 /**
248 Add custom field to address book. 250 Add custom field to address book.
249 251
250 @param label User visible label of the field. 252 @param label User visible label of the field.
251 @param category Ored list of field categories. 253 @param category Ored list of field categories.
252 @param key Identifier used as key for reading and writing the field. 254 @param key Identifier used as key for reading and writing the field.
253 @param app String used as application key for reading and writing 255 @param app String used as application key for reading and writing
254 the field. 256 the field.
255 */ 257 */
256 bool addCustomField( const QString &label, int category = Field::All, 258 bool addCustomField( const QString &label, int category = Field::All,
257 const QString &key = QString::null, 259 const QString &key = QString::null,
258 const QString &app = QString::null ); 260 const QString &app = QString::null );
259 261
260 262
261 /** 263 /**
262 Add address book resource. 264 Add address book resource.
263 */ 265 */
264 bool addResource( Resource * ); 266 bool addResource( Resource * );
265 267
266 /** 268 /**
267 Remove address book resource. 269 Remove address book resource.
268 */ 270 */
269 bool removeResource( Resource * ); 271 bool removeResource( Resource * );
270 272
271 /** 273 /**
272 Return pointer list of all resources. 274 Return pointer list of all resources.
273 */ 275 */
274 QPtrList<Resource> resources(); 276 QPtrList<Resource> resources();
275 277
276 /** 278 /**
277 Set the @p ErrorHandler, that is used by @ref error() to 279 Set the @p ErrorHandler, that is used by @ref error() to
278 provide gui-independend error messages. 280 provide gui-independend error messages.
279 */ 281 */
280 void setErrorHandler( ErrorHandler * ); 282 void setErrorHandler( ErrorHandler * );
281 283
282 /** 284 /**
283 Shows gui independend error messages. 285 Shows gui independend error messages.
284 */ 286 */
285 void error( const QString& ); 287 void error( const QString& );
286 288
287 /** 289 /**
288 Query all resources to clean up their lock files 290 Query all resources to clean up their lock files
289 */ 291 */
290 void cleanUp(); 292 void cleanUp();
291 293
292 // sync stuff 294 // sync stuff
293 //Addressee::List getExternLastSyncAddressees(); 295 //Addressee::List getExternLastSyncAddressees();
294 void resetTempSyncStat(); 296 void resetTempSyncStat();
295 QStringList uidList(); 297 QStringList uidList();
296 void removeSyncAddressees( bool removeDeleted = false ); 298 void removeSyncAddressees( bool removeDeleted = false );
297 void mergeAB( AddressBook *aBook, const QString& profile ); 299 void mergeAB( AddressBook *aBook, const QString& profile );
298 Addressee findByExternUid( const QString& uid , const QString& profile ); 300 Addressee findByExternUid( const QString& uid , const QString& profile );
299 bool containsExternalUid( const QString& uid ); 301 bool containsExternalUid( const QString& uid );
300 302
301 void preExternSync( AddressBook* aBook, const QString& csd ); 303 void preExternSync( AddressBook* aBook, const QString& csd );
302 void postExternSync( AddressBook* aBook, const QString& csd ); 304 void postExternSync( AddressBook* aBook, const QString& csd );
303 signals: 305 signals:
304 /** 306 /**
305 Emitted, when the address book has changed on disk. 307 Emitted, when the address book has changed on disk.
306 */ 308 */
307 void addressBookChanged( AddressBook * ); 309 void addressBookChanged( AddressBook * );
308 310
309 /** 311 /**
310 Emitted, when the address book has been locked for writing. 312 Emitted, when the address book has been locked for writing.
311 */ 313 */
312 void addressBookLocked( AddressBook * ); 314 void addressBookLocked( AddressBook * );
313 315
314 /** 316 /**
315 Emitted, when the address book has been unlocked. 317 Emitted, when the address book has been unlocked.
316 */ 318 */
317 void addressBookUnlocked( AddressBook * ); 319 void addressBookUnlocked( AddressBook * );
318 320
319 protected: 321 protected:
320 void deleteRemovedAddressees(); 322 void deleteRemovedAddressees();
321 void setStandardResource( Resource * ); 323 void setStandardResource( Resource * );
322 Resource *standardResource(); 324 Resource *standardResource();
323 KRES::Manager<Resource> *resourceManager(); 325 KRES::Manager<Resource> *resourceManager();
324 326
325 void init(const QString &config, const QString &family); 327 void init(const QString &config, const QString &family);
326 328
327 private: 329 private:
328//US QPtrList<Resource> mDummy; // Remove in KDE 4 330//US QPtrList<Resource> mDummy; // Remove in KDE 4
329 331
330 332
331 struct AddressBookData; 333 struct AddressBookData;
332 AddressBookData *d; 334 AddressBookData *d;
333 bool blockLSEchange; 335 bool blockLSEchange;
334}; 336};
335 337
336QDataStream &operator<<( QDataStream &, const AddressBook & ); 338QDataStream &operator<<( QDataStream &, const AddressBook & );
337QDataStream &operator>>( QDataStream &, AddressBook & ); 339QDataStream &operator>>( QDataStream &, AddressBook & );
338 340
339} 341}
340 342
341#endif 343#endif
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 3f3d5c0..607ae26 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -1,474 +1,475 @@
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}; 92};
92 93
93Addressee::Addressee() 94Addressee::Addressee()
94{ 95{
95 mData = new AddresseeData; 96 mData = new AddresseeData;
96 mData->empty = true; 97 mData->empty = true;
97 mData->changed = false; 98 mData->changed = false;
98 mData->resource = 0; 99 mData->resource = 0;
99 mData->mExternalId = ":"; 100 mData->mExternalId = ":";
100 mData->revision = QDateTime ( QDate( 2003,1,1)); 101 mData->revision = QDateTime ( QDate( 2003,1,1));
101 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 102 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
102} 103}
103 104
104Addressee::~Addressee() 105Addressee::~Addressee()
105{ 106{
106} 107}
107 108
108Addressee::Addressee( const Addressee &a ) 109Addressee::Addressee( const Addressee &a )
109{ 110{
110 mData = a.mData; 111 mData = a.mData;
111} 112}
112 113
113Addressee &Addressee::operator=( const Addressee &a ) 114Addressee &Addressee::operator=( const Addressee &a )
114{ 115{
115 mData = a.mData; 116 mData = a.mData;
116 return (*this); 117 return (*this);
117} 118}
118 119
119Addressee Addressee::copy() 120Addressee Addressee::copy()
120{ 121{
121 Addressee a; 122 Addressee a;
122 *(a.mData) = *mData; 123 *(a.mData) = *mData;
123 return a; 124 return a;
124} 125}
125 126
126void Addressee::detach() 127void Addressee::detach()
127{ 128{
128 if ( mData.count() == 1 ) return; 129 if ( mData.count() == 1 ) return;
129 *this = copy(); 130 *this = copy();
130} 131}
131 132
132bool Addressee::operator==( const Addressee &a ) const 133bool Addressee::operator==( const Addressee &a ) const
133{ 134{
134 if ( uid() != a.uid() ) return false; 135 if ( uid() != a.uid() ) return false;
135 if ( mData->name != a.mData->name ) return false; 136 if ( mData->name != a.mData->name ) return false;
136 if ( mData->formattedName != a.mData->formattedName ) return false; 137 if ( mData->formattedName != a.mData->formattedName ) return false;
137 if ( mData->familyName != a.mData->familyName ) return false; 138 if ( mData->familyName != a.mData->familyName ) return false;
138 if ( mData->givenName != a.mData->givenName ) return false; 139 if ( mData->givenName != a.mData->givenName ) return false;
139 if ( mData->additionalName != a.mData->additionalName ) return false; 140 if ( mData->additionalName != a.mData->additionalName ) return false;
140 if ( mData->prefix != a.mData->prefix ) return false; 141 if ( mData->prefix != a.mData->prefix ) return false;
141 if ( mData->suffix != a.mData->suffix ) return false; 142 if ( mData->suffix != a.mData->suffix ) return false;
142 if ( mData->nickName != a.mData->nickName ) return false; 143 if ( mData->nickName != a.mData->nickName ) return false;
143 if ( mData->birthday != a.mData->birthday ) return false; 144 if ( mData->birthday != a.mData->birthday ) return false;
144 if ( mData->mailer != a.mData->mailer ) return false; 145 if ( mData->mailer != a.mData->mailer ) return false;
145 if ( mData->timeZone != a.mData->timeZone ) return false; 146 if ( mData->timeZone != a.mData->timeZone ) return false;
146 if ( mData->geo != a.mData->geo ) return false; 147 if ( mData->geo != a.mData->geo ) return false;
147 if ( mData->title != a.mData->title ) return false; 148 if ( mData->title != a.mData->title ) return false;
148 if ( mData->role != a.mData->role ) return false; 149 if ( mData->role != a.mData->role ) return false;
149 if ( mData->organization != a.mData->organization ) return false; 150 if ( mData->organization != a.mData->organization ) return false;
150 if ( mData->note != a.mData->note ) return false; 151 if ( mData->note != a.mData->note ) return false;
151 if ( mData->productId != a.mData->productId ) return false; 152 if ( mData->productId != a.mData->productId ) return false;
152 //if ( mData->revision != a.mData->revision ) return false; 153 //if ( mData->revision != a.mData->revision ) return false;
153 if ( mData->sortString != a.mData->sortString ) return false; 154 if ( mData->sortString != a.mData->sortString ) return false;
154 if ( mData->secrecy != a.mData->secrecy ) return false; 155 if ( mData->secrecy != a.mData->secrecy ) return false;
155 if ( mData->logo != a.mData->logo ) return false; 156 if ( mData->logo != a.mData->logo ) return false;
156 if ( mData->photo != a.mData->photo ) return false; 157 if ( mData->photo != a.mData->photo ) return false;
157 if ( mData->sound != a.mData->sound ) return false; 158 if ( mData->sound != a.mData->sound ) return false;
158 if ( mData->agent != a.mData->agent ) return false; 159 if ( mData->agent != a.mData->agent ) return false;
159 if ( ( mData->url.isValid() || a.mData->url.isValid() ) && 160 if ( ( mData->url.isValid() || a.mData->url.isValid() ) &&
160 ( mData->url != a.mData->url ) ) return false; 161 ( mData->url != a.mData->url ) ) return false;
161 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; 162 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false;
162 if ( mData->addresses != a.mData->addresses ) return false; 163 if ( mData->addresses != a.mData->addresses ) return false;
163 if ( mData->keys != a.mData->keys ) return false; 164 if ( mData->keys != a.mData->keys ) return false;
164 if ( mData->emails != a.mData->emails ) return false; 165 if ( mData->emails != a.mData->emails ) return false;
165 if ( mData->categories != a.mData->categories ) return false; 166 if ( mData->categories != a.mData->categories ) return false;
166 if ( mData->custom != a.mData->custom ) return false; 167 if ( mData->custom != a.mData->custom ) return false;
167 168
168 return true; 169 return true;
169} 170}
170 171
171bool Addressee::operator!=( const Addressee &a ) const 172bool Addressee::operator!=( const Addressee &a ) const
172{ 173{
173 return !( a == *this ); 174 return !( a == *this );
174} 175}
175 176
176bool Addressee::isEmpty() const 177bool Addressee::isEmpty() const
177{ 178{
178 return mData->empty; 179 return mData->empty;
179} 180}
180ulong Addressee::getCsum4List( const QStringList & attList) 181ulong Addressee::getCsum4List( const QStringList & attList)
181{ 182{
182 int max = attList.count(); 183 int max = attList.count();
183 ulong cSum = 0; 184 ulong cSum = 0;
184 int j,k,i; 185 int j,k,i;
185 int add; 186 int add;
186 for ( i = 0; i < max ; ++i ) { 187 for ( i = 0; i < max ; ++i ) {
187 QString s = attList[i]; 188 QString s = attList[i];
188 if ( ! s.isEmpty() ){ 189 if ( ! s.isEmpty() ){
189 j = s.length(); 190 j = s.length();
190 for ( k = 0; k < j; ++k ) { 191 for ( k = 0; k < j; ++k ) {
191 int mul = k +1; 192 int mul = k +1;
192 add = s[k].unicode (); 193 add = s[k].unicode ();
193 if ( k < 16 ) 194 if ( k < 16 )
194 mul = mul * mul; 195 mul = mul * mul;
195 int ii = i+1; 196 int ii = i+1;
196 add = add * mul *ii*ii*ii; 197 add = add * mul *ii*ii*ii;
197 cSum += add; 198 cSum += add;
198 } 199 }
199 } 200 }
200 201
201 } 202 }
202 //QString dump = attList.join(","); 203 //QString dump = attList.join(",");
203 //qDebug("csum: %d %s", cSum,dump.latin1()); 204 //qDebug("csum: %d %s", cSum,dump.latin1());
204 205
205 return cSum; 206 return cSum;
206 207
207} 208}
208void Addressee::computeCsum(const QString &dev) 209void Addressee::computeCsum(const QString &dev)
209{ 210{
210 QStringList l; 211 QStringList l;
211 if ( !mData->name.isEmpty() ) l.append(mData->name); 212 if ( !mData->name.isEmpty() ) l.append(mData->name);
212 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); 213 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName );
213 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); 214 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName );
214 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); 215 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName );
215 if ( !mData->additionalName ) l.append( mData->additionalName ); 216 if ( !mData->additionalName ) l.append( mData->additionalName );
216 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); 217 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix );
217 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); 218 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix );
218 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); 219 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName );
219 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); 220 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() );
220 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); 221 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer );
221 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); 222 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() );
222 if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); 223 if ( mData->geo.isValid() ) l.append( mData->geo.asString() );
223 if ( !mData->title .isEmpty() ) l.append( mData->title ); 224 if ( !mData->title .isEmpty() ) l.append( mData->title );
224 if ( !mData->role.isEmpty() ) l.append( mData->role ); 225 if ( !mData->role.isEmpty() ) l.append( mData->role );
225 if ( !mData->organization.isEmpty() ) l.append( mData->organization ); 226 if ( !mData->organization.isEmpty() ) l.append( mData->organization );
226 if ( !mData->note.isEmpty() ) l.append( mData->note ); 227 if ( !mData->note.isEmpty() ) l.append( mData->note );
227 if ( !mData->productId.isEmpty() ) l.append(mData->productId ); 228 if ( !mData->productId.isEmpty() ) l.append(mData->productId );
228 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); 229 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString );
229 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); 230 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString());
230 // if ( !mData->logo.isEmpty() ) l.append( ); 231 // if ( !mData->logo.isEmpty() ) l.append( );
231 //if ( !mData->photo.isEmpty() ) l.append( ); 232 //if ( !mData->photo.isEmpty() ) l.append( );
232 //if ( !mData->sound.isEmpty() ) l.append( ); 233 //if ( !mData->sound.isEmpty() ) l.append( );
233 //if ( !mData->agent.isEmpty() ) l.append( ); 234 //if ( !mData->agent.isEmpty() ) l.append( );
234 //if ( mData->url.isValid() ) l.append( ); 235 //if ( mData->url.isValid() ) l.append( );
235#if 0 236#if 0
236 if ( !mData->phoneNumbers.isEmpty() ) l.append( ); 237 if ( !mData->phoneNumbers.isEmpty() ) l.append( );
237 if ( !mData->addresses.isEmpty() ) l.append( ); 238 if ( !mData->addresses.isEmpty() ) l.append( );
238 //if ( !mData->keys.isEmpty() ) l.append( ); 239 //if ( !mData->keys.isEmpty() ) l.append( );
239 if ( !mData->emails.isEmpty() ) l.append( ); 240 if ( !mData->emails.isEmpty() ) l.append( );
240 if ( !mData->categories .isEmpty() ) l.append( ); 241 if ( !mData->categories .isEmpty() ) l.append( );
241 if ( !mData->custom.isEmpty() ) l.append( ); 242 if ( !mData->custom.isEmpty() ) l.append( );
242#endif 243#endif
243 KABC::PhoneNumber::List phoneNumbers; 244 KABC::PhoneNumber::List phoneNumbers;
244 KABC::PhoneNumber::List::Iterator phoneIter; 245 KABC::PhoneNumber::List::Iterator phoneIter;
245 246
246 QStringList t; 247 QStringList t;
247 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 248 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
248 ++phoneIter ) 249 ++phoneIter )
249 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); 250 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) );
250 t.sort(); 251 t.sort();
251 uint iii; 252 uint iii;
252 for ( iii = 0; iii < t.count(); ++iii) 253 for ( iii = 0; iii < t.count(); ++iii)
253 l.append( t[iii] ); 254 l.append( t[iii] );
254 t = mData->emails; 255 t = mData->emails;
255 t.sort(); 256 t.sort();
256 for ( iii = 0; iii < t.count(); ++iii) 257 for ( iii = 0; iii < t.count(); ++iii)
257 l.append( t[iii] ); 258 l.append( t[iii] );
258 t = mData->categories; 259 t = mData->categories;
259 t.sort(); 260 t.sort();
260 for ( iii = 0; iii < t.count(); ++iii) 261 for ( iii = 0; iii < t.count(); ++iii)
261 l.append( t[iii] ); 262 l.append( t[iii] );
262 t = mData->custom; 263 t = mData->custom;
263 t.sort(); 264 t.sort();
264 for ( iii = 0; iii < t.count(); ++iii) 265 for ( iii = 0; iii < t.count(); ++iii)
265 l.append( t[iii] ); 266 l.append( t[iii] );
266 KABC::Address::List::Iterator addressIter; 267 KABC::Address::List::Iterator addressIter;
267 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 268 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
268 ++addressIter ) { 269 ++addressIter ) {
269 t = (*addressIter).asList(); 270 t = (*addressIter).asList();
270 t.sort(); 271 t.sort();
271 for ( iii = 0; iii < t.count(); ++iii) 272 for ( iii = 0; iii < t.count(); ++iii)
272 l.append( t[iii] ); 273 l.append( t[iii] );
273 } 274 }
274 uint cs = getCsum4List(l); 275 uint cs = getCsum4List(l);
275 // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); 276 // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() );
276 setCsum( dev, QString::number (cs )); 277 setCsum( dev, QString::number (cs ));
277} 278}
278 279
279void Addressee::mergeContact( const Addressee& ad ) 280void Addressee::mergeContact( const Addressee& ad )
280{ 281{
281 282
282 detach(); 283 detach();
283 if ( mData->name.isEmpty() ) mData->name = ad.mData->name; 284 if ( mData->name.isEmpty() ) mData->name = ad.mData->name;
284 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; 285 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName;
285 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; 286 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName;
286 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; 287 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ;
287 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; 288 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName;
288 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; 289 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix;
289 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; 290 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix;
290 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; 291 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName;
291 if ( !mData->birthday.isValid() ) 292 if ( !mData->birthday.isValid() )
292 if ( ad.mData->birthday.isValid()) 293 if ( ad.mData->birthday.isValid())
293 mData->birthday = ad.mData->birthday; 294 mData->birthday = ad.mData->birthday;
294 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; 295 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer;
295 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; 296 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone;
296 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; 297 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo;
297 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; 298 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ;
298 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; 299 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ;
299 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; 300 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ;
300 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; 301 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ;
301 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; 302 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId;
302 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; 303 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString;
303 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; 304 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy;
304 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; 305 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ;
305 306
306 // pending: 307 // pending:
307 // merging phonenumbers 308 // merging phonenumbers
308 // merging addresses 309 // merging addresses
309 // merging emails; 310 // merging emails;
310 // merging categories; 311 // merging categories;
311 // merging custom; 312 // merging custom;
312 // merging keys 313 // merging keys
313 qDebug("merge contact %s ", ad.uid().latin1()); 314 qDebug("merge contact %s ", ad.uid().latin1());
314 setUid( ad.uid() ); 315 setUid( ad.uid() );
315 setRevision( ad.revision() ); 316 setRevision( ad.revision() );
316} 317}
317 318
318bool Addressee::removeVoice() 319bool Addressee::removeVoice()
319{ 320{
320 PhoneNumber::List phoneN = phoneNumbers(); 321 PhoneNumber::List phoneN = phoneNumbers();
321 PhoneNumber::List::Iterator phoneIt; 322 PhoneNumber::List::Iterator phoneIt;
322 bool found = false; 323 bool found = false;
323 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { 324 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
324 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found 325 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found
325 if ((*phoneIt).type() - PhoneNumber::Voice ) { 326 if ((*phoneIt).type() - PhoneNumber::Voice ) {
326 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); 327 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice );
327 insertPhoneNumber( (*phoneIt) ); 328 insertPhoneNumber( (*phoneIt) );
328 found = true; 329 found = true;
329 } 330 }
330 } 331 }
331 332
332 } 333 }
333 return found; 334 return found;
334} 335}
335void Addressee::simplifyAddresses() 336void Addressee::simplifyAddresses()
336{ 337{
337 if ( mData->addresses.count() < 3 ) return ; 338 if ( mData->addresses.count() < 3 ) return ;
338 int count = 0; 339 int count = 0;
339 Address::List list; 340 Address::List list;
340 Address::List::Iterator it; 341 Address::List::Iterator it;
341 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 342 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
342 if ( count > 1 ) 343 if ( count > 1 )
343 list.append( *it ); 344 list.append( *it );
344 ++count; 345 ++count;
345 } 346 }
346 for( it = list.begin(); it != list.end(); ++it ) { 347 for( it = list.begin(); it != list.end(); ++it ) {
347 removeAddress( (*it) ); 348 removeAddress( (*it) );
348 } 349 }
349} 350}
350 351
351// removes all emails but the first 352// removes all emails but the first
352// needed by phone sync 353// needed by phone sync
353void Addressee::simplifyEmails() 354void Addressee::simplifyEmails()
354{ 355{
355 if ( mData->emails.count() == 0 ) return ; 356 if ( mData->emails.count() == 0 ) return ;
356 QString email = mData->emails.first(); 357 QString email = mData->emails.first();
357 detach(); 358 detach();
358 mData->emails.clear(); 359 mData->emails.clear();
359 mData->emails.append( email ); 360 mData->emails.append( email );
360} 361}
361 362
362void Addressee::simplifyPhoneNumbers() 363void Addressee::simplifyPhoneNumbers()
363{ 364{
364 KABC::PhoneNumber::List removeNumbers; 365 KABC::PhoneNumber::List removeNumbers;
365 KABC::PhoneNumber::List::Iterator phoneIter; 366 KABC::PhoneNumber::List::Iterator phoneIter;
366 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 367 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
367 ++phoneIter ) { 368 ++phoneIter ) {
368 if ( ! ( *phoneIter ).simplifyNumber() ) 369 if ( ! ( *phoneIter ).simplifyNumber() )
369 removeNumbers.append( ( *phoneIter ) ); 370 removeNumbers.append( ( *phoneIter ) );
370 } 371 }
371 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 372 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
372 ++phoneIter ) { 373 ++phoneIter ) {
373 removePhoneNumber(( *phoneIter )); 374 removePhoneNumber(( *phoneIter ));
374 } 375 }
375} 376}
376void Addressee::simplifyPhoneNumberTypes() 377void Addressee::simplifyPhoneNumberTypes()
377{ 378{
378 KABC::PhoneNumber::List::Iterator phoneIter; 379 KABC::PhoneNumber::List::Iterator phoneIter;
379 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 380 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
380 ++phoneIter ) 381 ++phoneIter )
381 ( *phoneIter ).simplifyType(); 382 ( *phoneIter ).simplifyType();
382} 383}
383void Addressee::removeID(const QString &prof) 384void Addressee::removeID(const QString &prof)
384{ 385{
385 detach(); 386 detach();
386 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); 387 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
387 388
388} 389}
389void Addressee::setID( const QString & prof , const QString & id ) 390void Addressee::setID( const QString & prof , const QString & id )
390{ 391{
391 detach(); 392 detach();
392 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); 393 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
393 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 394 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
394} 395}
395void Addressee::setTempSyncStat( int id ) 396void Addressee::setTempSyncStat( int id )
396{ 397{
397 if ( mData->mTempSyncStat == id ) return; 398 if ( mData->mTempSyncStat == id ) return;
398 detach(); 399 detach();
399 mData->mTempSyncStat = id; 400 mData->mTempSyncStat = id;
400} 401}
401int Addressee::tempSyncStat() const 402int Addressee::tempSyncStat() const
402{ 403{
403 return mData->mTempSyncStat; 404 return mData->mTempSyncStat;
404} 405}
405 406
406QString Addressee::getID( const QString & prof) 407QString Addressee::getID( const QString & prof)
407{ 408{
408 return KIdManager::getId ( mData->mExternalId, prof ); 409 return KIdManager::getId ( mData->mExternalId, prof );
409} 410}
410 411
411void Addressee::setCsum( const QString & prof , const QString & id ) 412void Addressee::setCsum( const QString & prof , const QString & id )
412{ 413{
413 detach(); 414 detach();
414 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 415 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
415 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); 416 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id );
416 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); 417 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() );
417} 418}
418 419
419QString Addressee::getCsum( const QString & prof) 420QString Addressee::getCsum( const QString & prof)
420{ 421{
421 return KIdManager::getCsum ( mData->mExternalId, prof ); 422 return KIdManager::getCsum ( mData->mExternalId, prof );
422} 423}
423 424
424void Addressee::setIDStr( const QString & s ) 425void Addressee::setIDStr( const QString & s )
425{ 426{
426 detach(); 427 detach();
427 mData->mExternalId = s; 428 mData->mExternalId = s;
428} 429}
429 430
430QString Addressee::IDStr() const 431QString Addressee::IDStr() const
431{ 432{
432 return mData->mExternalId; 433 return mData->mExternalId;
433} 434}
434 435
435void Addressee::setExternalUID( const QString &id ) 436void Addressee::setExternalUID( const QString &id )
436{ 437{
437 if ( id == mData->externalUID ) return; 438 if ( id == mData->externalUID ) return;
438 detach(); 439 detach();
439 mData->empty = false; 440 mData->empty = false;
440 mData->externalUID = id; 441 mData->externalUID = id;
441} 442}
442 443
443QString Addressee::externalUID() const 444QString Addressee::externalUID() const
444{ 445{
445 return mData->externalUID; 446 return mData->externalUID;
446} 447}
447void Addressee::setOriginalExternalUID( const QString &id ) 448void Addressee::setOriginalExternalUID( const QString &id )
448{ 449{
449 if ( id == mData->originalExternalUID ) return; 450 if ( id == mData->originalExternalUID ) return;
450 detach(); 451 detach();
451 mData->empty = false; 452 mData->empty = false;
452 //qDebug("*******Set orig uid %s ", id.latin1()); 453 //qDebug("*******Set orig uid %s ", id.latin1());
453 mData->originalExternalUID = id; 454 mData->originalExternalUID = id;
454} 455}
455 456
456QString Addressee::originalExternalUID() const 457QString Addressee::originalExternalUID() const
457{ 458{
458 return mData->originalExternalUID; 459 return mData->originalExternalUID;
459} 460}
460 461
461void Addressee::setUid( const QString &id ) 462void Addressee::setUid( const QString &id )
462{ 463{
463 if ( id == mData->uid ) return; 464 if ( id == mData->uid ) return;
464 detach(); 465 detach();
465 //qDebug("****setuid %s ", id.latin1()); 466 //qDebug("****setuid %s ", id.latin1());
466 mData->empty = false; 467 mData->empty = false;
467 mData->uid = id; 468 mData->uid = id;
468} 469}
469 470
470QString Addressee::uid() const 471QString Addressee::uid() const
471{ 472{
472 if ( mData->uid.isEmpty() ) 473 if ( mData->uid.isEmpty() )
473 mData->uid = KApplication::randomString( 10 ); 474 mData->uid = KApplication::randomString( 10 );
474 475
@@ -1440,496 +1441,507 @@ Key Addressee::key( int type, QString customTypeString ) const
1440 } 1441 }
1441 } else { 1442 } else {
1442 return *it; 1443 return *it;
1443 } 1444 }
1444 } 1445 }
1445 } 1446 }
1446 return Key( QString(), type ); 1447 return Key( QString(), type );
1447} 1448}
1448void Addressee::setKeys( const Key::List& list ) { 1449void Addressee::setKeys( const Key::List& list ) {
1449 detach(); 1450 detach();
1450 mData->keys = list; 1451 mData->keys = list;
1451} 1452}
1452 1453
1453Key::List Addressee::keys() const 1454Key::List Addressee::keys() const
1454{ 1455{
1455 return mData->keys; 1456 return mData->keys;
1456} 1457}
1457 1458
1458Key::List Addressee::keys( int type, QString customTypeString ) const 1459Key::List Addressee::keys( int type, QString customTypeString ) const
1459{ 1460{
1460 Key::List list; 1461 Key::List list;
1461 1462
1462 Key::List::ConstIterator it; 1463 Key::List::ConstIterator it;
1463 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1464 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1464 if ( (*it).type() == type ) { 1465 if ( (*it).type() == type ) {
1465 if ( type == Key::Custom ) { 1466 if ( type == Key::Custom ) {
1466 if ( customTypeString.isEmpty() ) { 1467 if ( customTypeString.isEmpty() ) {
1467 list.append(*it); 1468 list.append(*it);
1468 } else { 1469 } else {
1469 if ( (*it).customTypeString() == customTypeString ) 1470 if ( (*it).customTypeString() == customTypeString )
1470 list.append(*it); 1471 list.append(*it);
1471 } 1472 }
1472 } else { 1473 } else {
1473 list.append(*it); 1474 list.append(*it);
1474 } 1475 }
1475 } 1476 }
1476 } 1477 }
1477 return list; 1478 return list;
1478} 1479}
1479 1480
1480Key Addressee::findKey( const QString &id ) const 1481Key Addressee::findKey( const QString &id ) const
1481{ 1482{
1482 Key::List::ConstIterator it; 1483 Key::List::ConstIterator it;
1483 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1484 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1484 if ( (*it).id() == id ) { 1485 if ( (*it).id() == id ) {
1485 return *it; 1486 return *it;
1486 } 1487 }
1487 } 1488 }
1488 return Key(); 1489 return Key();
1489} 1490}
1490 1491
1491QString Addressee::asString() const 1492QString Addressee::asString() const
1492{ 1493{
1493 return "Smith, agent Smith..."; 1494 return "Smith, agent Smith...";
1494} 1495}
1495 1496
1496void Addressee::dump() const 1497void Addressee::dump() const
1497{ 1498{
1498 return; 1499 return;
1499 kdDebug(5700) << "Addressee {" << endl; 1500 kdDebug(5700) << "Addressee {" << endl;
1500 1501
1501 kdDebug(5700) << " Uid: '" << uid() << "'" << endl; 1502 kdDebug(5700) << " Uid: '" << uid() << "'" << endl;
1502 1503
1503 kdDebug(5700) << " Name: '" << name() << "'" << endl; 1504 kdDebug(5700) << " Name: '" << name() << "'" << endl;
1504 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl; 1505 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl;
1505 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl; 1506 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl;
1506 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl; 1507 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl;
1507 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl; 1508 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl;
1508 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl; 1509 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl;
1509 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl; 1510 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl;
1510 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl; 1511 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl;
1511 kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl; 1512 kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl;
1512 kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl; 1513 kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl;
1513 kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl; 1514 kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl;
1514 kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl; 1515 kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl;
1515 kdDebug(5700) << " Title: '" << title() << "'" << endl; 1516 kdDebug(5700) << " Title: '" << title() << "'" << endl;
1516 kdDebug(5700) << " Role: '" << role() << "'" << endl; 1517 kdDebug(5700) << " Role: '" << role() << "'" << endl;
1517 kdDebug(5700) << " Organization: '" << organization() << "'" << endl; 1518 kdDebug(5700) << " Organization: '" << organization() << "'" << endl;
1518 kdDebug(5700) << " Note: '" << note() << "'" << endl; 1519 kdDebug(5700) << " Note: '" << note() << "'" << endl;
1519 kdDebug(5700) << " ProductId: '" << productId() << "'" << endl; 1520 kdDebug(5700) << " ProductId: '" << productId() << "'" << endl;
1520 kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl; 1521 kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl;
1521 kdDebug(5700) << " SortString: '" << sortString() << "'" << endl; 1522 kdDebug(5700) << " SortString: '" << sortString() << "'" << endl;
1522 kdDebug(5700) << " Url: '" << url().url() << "'" << endl; 1523 kdDebug(5700) << " Url: '" << url().url() << "'" << endl;
1523 kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl; 1524 kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl;
1524 kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl; 1525 kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl;
1525 kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl; 1526 kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl;
1526 kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl; 1527 kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl;
1527 kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl; 1528 kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl;
1528 1529
1529 kdDebug(5700) << " Emails {" << endl; 1530 kdDebug(5700) << " Emails {" << endl;
1530 QStringList e = emails(); 1531 QStringList e = emails();
1531 QStringList::ConstIterator it; 1532 QStringList::ConstIterator it;
1532 for( it = e.begin(); it != e.end(); ++it ) { 1533 for( it = e.begin(); it != e.end(); ++it ) {
1533 kdDebug(5700) << " " << (*it) << endl; 1534 kdDebug(5700) << " " << (*it) << endl;
1534 } 1535 }
1535 kdDebug(5700) << " }" << endl; 1536 kdDebug(5700) << " }" << endl;
1536 1537
1537 kdDebug(5700) << " PhoneNumbers {" << endl; 1538 kdDebug(5700) << " PhoneNumbers {" << endl;
1538 PhoneNumber::List p = phoneNumbers(); 1539 PhoneNumber::List p = phoneNumbers();
1539 PhoneNumber::List::ConstIterator it2; 1540 PhoneNumber::List::ConstIterator it2;
1540 for( it2 = p.begin(); it2 != p.end(); ++it2 ) { 1541 for( it2 = p.begin(); it2 != p.end(); ++it2 ) {
1541 kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl; 1542 kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl;
1542 } 1543 }
1543 kdDebug(5700) << " }" << endl; 1544 kdDebug(5700) << " }" << endl;
1544 1545
1545 Address::List a = addresses(); 1546 Address::List a = addresses();
1546 Address::List::ConstIterator it3; 1547 Address::List::ConstIterator it3;
1547 for( it3 = a.begin(); it3 != a.end(); ++it3 ) { 1548 for( it3 = a.begin(); it3 != a.end(); ++it3 ) {
1548 (*it3).dump(); 1549 (*it3).dump();
1549 } 1550 }
1550 1551
1551 kdDebug(5700) << " Keys {" << endl; 1552 kdDebug(5700) << " Keys {" << endl;
1552 Key::List k = keys(); 1553 Key::List k = keys();
1553 Key::List::ConstIterator it4; 1554 Key::List::ConstIterator it4;
1554 for( it4 = k.begin(); it4 != k.end(); ++it4 ) { 1555 for( it4 = k.begin(); it4 != k.end(); ++it4 ) {
1555 kdDebug(5700) << " Type: " << int((*it4).type()) << 1556 kdDebug(5700) << " Type: " << int((*it4).type()) <<
1556 " Key: " << (*it4).textData() << 1557 " Key: " << (*it4).textData() <<
1557 " CustomString: " << (*it4).customTypeString() << endl; 1558 " CustomString: " << (*it4).customTypeString() << endl;
1558 } 1559 }
1559 kdDebug(5700) << " }" << endl; 1560 kdDebug(5700) << " }" << endl;
1560 1561
1561 kdDebug(5700) << "}" << endl; 1562 kdDebug(5700) << "}" << endl;
1562} 1563}
1563 1564
1564 1565
1565void Addressee::insertAddress( const Address &address ) 1566void Addressee::insertAddress( const Address &address )
1566{ 1567{
1567 detach(); 1568 detach();
1568 mData->empty = false; 1569 mData->empty = false;
1569 1570
1570 Address::List::Iterator it; 1571 Address::List::Iterator it;
1571 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1572 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1572 if ( (*it).id() == address.id() ) { 1573 if ( (*it).id() == address.id() ) {
1573 *it = address; 1574 *it = address;
1574 return; 1575 return;
1575 } 1576 }
1576 } 1577 }
1577 mData->addresses.append( address ); 1578 mData->addresses.append( address );
1578} 1579}
1579 1580
1580void Addressee::removeAddress( const Address &address ) 1581void Addressee::removeAddress( const Address &address )
1581{ 1582{
1582 detach(); 1583 detach();
1583 1584
1584 Address::List::Iterator it; 1585 Address::List::Iterator it;
1585 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1586 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1586 if ( (*it).id() == address.id() ) { 1587 if ( (*it).id() == address.id() ) {
1587 mData->addresses.remove( it ); 1588 mData->addresses.remove( it );
1588 return; 1589 return;
1589 } 1590 }
1590 } 1591 }
1591} 1592}
1592 1593
1593Address Addressee::address( int type ) const 1594Address Addressee::address( int type ) const
1594{ 1595{
1595 Address address( type ); 1596 Address address( type );
1596 Address::List::ConstIterator it; 1597 Address::List::ConstIterator it;
1597 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1598 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1598 if ( matchBinaryPatternA( (*it).type(), type ) ) { 1599 if ( matchBinaryPatternA( (*it).type(), type ) ) {
1599 if ( (*it).type() & Address::Pref ) 1600 if ( (*it).type() & Address::Pref )
1600 return (*it); 1601 return (*it);
1601 else if ( address.isEmpty() ) 1602 else if ( address.isEmpty() )
1602 address = (*it); 1603 address = (*it);
1603 } 1604 }
1604 } 1605 }
1605 1606
1606 return address; 1607 return address;
1607} 1608}
1608 1609
1609Address::List Addressee::addresses() const 1610Address::List Addressee::addresses() const
1610{ 1611{
1611 return mData->addresses; 1612 return mData->addresses;
1612} 1613}
1613 1614
1614Address::List Addressee::addresses( int type ) const 1615Address::List Addressee::addresses( int type ) const
1615{ 1616{
1616 Address::List list; 1617 Address::List list;
1617 1618
1618 Address::List::ConstIterator it; 1619 Address::List::ConstIterator it;
1619 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1620 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1620 if ( matchBinaryPattern( (*it).type(), type ) ) { 1621 if ( matchBinaryPattern( (*it).type(), type ) ) {
1621 list.append( *it ); 1622 list.append( *it );
1622 } 1623 }
1623 } 1624 }
1624 1625
1625 return list; 1626 return list;
1626} 1627}
1627 1628
1628Address Addressee::findAddress( const QString &id ) const 1629Address Addressee::findAddress( const QString &id ) const
1629{ 1630{
1630 Address::List::ConstIterator it; 1631 Address::List::ConstIterator it;
1631 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1632 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1632 if ( (*it).id() == id ) { 1633 if ( (*it).id() == id ) {
1633 return *it; 1634 return *it;
1634 } 1635 }
1635 } 1636 }
1636 return Address(); 1637 return Address();
1637} 1638}
1638 1639
1639void Addressee::insertCategory( const QString &c ) 1640void Addressee::insertCategory( const QString &c )
1640{ 1641{
1641 detach(); 1642 detach();
1642 mData->empty = false; 1643 mData->empty = false;
1643 1644
1644 if ( mData->categories.contains( c ) ) return; 1645 if ( mData->categories.contains( c ) ) return;
1645 1646
1646 mData->categories.append( c ); 1647 mData->categories.append( c );
1647} 1648}
1648 1649
1649void Addressee::removeCategory( const QString &c ) 1650void Addressee::removeCategory( const QString &c )
1650{ 1651{
1651 detach(); 1652 detach();
1652 1653
1653 QStringList::Iterator it = mData->categories.find( c ); 1654 QStringList::Iterator it = mData->categories.find( c );
1654 if ( it == mData->categories.end() ) return; 1655 if ( it == mData->categories.end() ) return;
1655 1656
1656 mData->categories.remove( it ); 1657 mData->categories.remove( it );
1657} 1658}
1658 1659
1659bool Addressee::hasCategory( const QString &c ) const 1660bool Addressee::hasCategory( const QString &c ) const
1660{ 1661{
1661 return ( mData->categories.contains( c ) ); 1662 return ( mData->categories.contains( c ) );
1662} 1663}
1663 1664
1664void Addressee::setCategories( const QStringList &c ) 1665void Addressee::setCategories( const QStringList &c )
1665{ 1666{
1666 detach(); 1667 detach();
1667 mData->empty = false; 1668 mData->empty = false;
1668 1669
1669 mData->categories = c; 1670 mData->categories = c;
1670} 1671}
1671 1672
1672QStringList Addressee::categories() const 1673QStringList Addressee::categories() const
1673{ 1674{
1674 return mData->categories; 1675 return mData->categories;
1675} 1676}
1676 1677
1677void Addressee::insertCustom( const QString &app, const QString &name, 1678void Addressee::insertCustom( const QString &app, const QString &name,
1678 const QString &value ) 1679 const QString &value )
1679{ 1680{
1680 if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return; 1681 if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return;
1681 1682
1682 detach(); 1683 detach();
1683 mData->empty = false; 1684 mData->empty = false;
1684 1685
1685 QString qualifiedName = app + "-" + name + ":"; 1686 QString qualifiedName = app + "-" + name + ":";
1686 1687
1687 QStringList::Iterator it; 1688 QStringList::Iterator it;
1688 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1689 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1689 if ( (*it).startsWith( qualifiedName ) ) { 1690 if ( (*it).startsWith( qualifiedName ) ) {
1690 (*it) = qualifiedName + value; 1691 (*it) = qualifiedName + value;
1691 return; 1692 return;
1692 } 1693 }
1693 } 1694 }
1694 mData->custom.append( qualifiedName + value ); 1695 mData->custom.append( qualifiedName + value );
1695} 1696}
1696 1697
1697void Addressee::removeCustom( const QString &app, const QString &name) 1698void Addressee::removeCustom( const QString &app, const QString &name)
1698{ 1699{
1699 detach(); 1700 detach();
1700 1701
1701 QString qualifiedName = app + "-" + name + ":"; 1702 QString qualifiedName = app + "-" + name + ":";
1702 1703
1703 QStringList::Iterator it; 1704 QStringList::Iterator it;
1704 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1705 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1705 if ( (*it).startsWith( qualifiedName ) ) { 1706 if ( (*it).startsWith( qualifiedName ) ) {
1706 mData->custom.remove( it ); 1707 mData->custom.remove( it );
1707 return; 1708 return;
1708 } 1709 }
1709 } 1710 }
1710} 1711}
1711 1712
1712QString Addressee::custom( const QString &app, const QString &name ) const 1713QString Addressee::custom( const QString &app, const QString &name ) const
1713{ 1714{
1714 QString qualifiedName = app + "-" + name + ":"; 1715 QString qualifiedName = app + "-" + name + ":";
1715 QString value; 1716 QString value;
1716 1717
1717 QStringList::ConstIterator it; 1718 QStringList::ConstIterator it;
1718 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1719 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1719 if ( (*it).startsWith( qualifiedName ) ) { 1720 if ( (*it).startsWith( qualifiedName ) ) {
1720 value = (*it).mid( (*it).find( ":" ) + 1 ); 1721 value = (*it).mid( (*it).find( ":" ) + 1 );
1721 break; 1722 break;
1722 } 1723 }
1723 } 1724 }
1724 1725
1725 return value; 1726 return value;
1726} 1727}
1727 1728
1728void Addressee::setCustoms( const QStringList &l ) 1729void Addressee::setCustoms( const QStringList &l )
1729{ 1730{
1730 detach(); 1731 detach();
1731 mData->empty = false; 1732 mData->empty = false;
1732 1733
1733 mData->custom = l; 1734 mData->custom = l;
1734} 1735}
1735 1736
1736QStringList Addressee::customs() const 1737QStringList Addressee::customs() const
1737{ 1738{
1738 return mData->custom; 1739 return mData->custom;
1739} 1740}
1740 1741
1741void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName, 1742void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName,
1742 QString &email) 1743 QString &email)
1743{ 1744{
1744 int startPos, endPos, len; 1745 int startPos, endPos, len;
1745 QString partA, partB, result; 1746 QString partA, partB, result;
1746 char endCh = '>'; 1747 char endCh = '>';
1747 1748
1748 startPos = rawEmail.find('<'); 1749 startPos = rawEmail.find('<');
1749 if (startPos < 0) 1750 if (startPos < 0)
1750 { 1751 {
1751 startPos = rawEmail.find('('); 1752 startPos = rawEmail.find('(');
1752 endCh = ')'; 1753 endCh = ')';
1753 } 1754 }
1754 if (startPos < 0) 1755 if (startPos < 0)
1755 { 1756 {
1756 // We couldn't find any separators, so we assume the whole string 1757 // We couldn't find any separators, so we assume the whole string
1757 // is the email address 1758 // is the email address
1758 email = rawEmail; 1759 email = rawEmail;
1759 fullName = ""; 1760 fullName = "";
1760 } 1761 }
1761 else 1762 else
1762 { 1763 {
1763 // We have a start position, try to find an end 1764 // We have a start position, try to find an end
1764 endPos = rawEmail.find(endCh, startPos+1); 1765 endPos = rawEmail.find(endCh, startPos+1);
1765 1766
1766 if (endPos < 0) 1767 if (endPos < 0)
1767 { 1768 {
1768 // We couldn't find the end of the email address. We can only 1769 // We couldn't find the end of the email address. We can only
1769 // assume the entire string is the email address. 1770 // assume the entire string is the email address.
1770 email = rawEmail; 1771 email = rawEmail;
1771 fullName = ""; 1772 fullName = "";
1772 } 1773 }
1773 else 1774 else
1774 { 1775 {
1775 // We have a start and end to the email address 1776 // We have a start and end to the email address
1776 1777
1777 // Grab the name part 1778 // Grab the name part
1778 fullName = rawEmail.left(startPos).stripWhiteSpace(); 1779 fullName = rawEmail.left(startPos).stripWhiteSpace();
1779 1780
1780 // grab the email part 1781 // grab the email part
1781 email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace(); 1782 email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace();
1782 1783
1783 // Check that we do not have any extra characters on the end of the 1784 // Check that we do not have any extra characters on the end of the
1784 // strings 1785 // strings
1785 len = fullName.length(); 1786 len = fullName.length();
1786 if (fullName[0]=='"' && fullName[len-1]=='"') 1787 if (fullName[0]=='"' && fullName[len-1]=='"')
1787 fullName = fullName.mid(1, len-2); 1788 fullName = fullName.mid(1, len-2);
1788 else if (fullName[0]=='<' && fullName[len-1]=='>') 1789 else if (fullName[0]=='<' && fullName[len-1]=='>')
1789 fullName = fullName.mid(1, len-2); 1790 fullName = fullName.mid(1, len-2);
1790 else if (fullName[0]=='(' && fullName[len-1]==')') 1791 else if (fullName[0]=='(' && fullName[len-1]==')')
1791 fullName = fullName.mid(1, len-2); 1792 fullName = fullName.mid(1, len-2);
1792 } 1793 }
1793 } 1794 }
1794} 1795}
1795 1796
1796void Addressee::setResource( Resource *resource ) 1797void Addressee::setResource( Resource *resource )
1797{ 1798{
1798 detach(); 1799 detach();
1799 mData->resource = resource; 1800 mData->resource = resource;
1800} 1801}
1801 1802
1802Resource *Addressee::resource() const 1803Resource *Addressee::resource() const
1803{ 1804{
1804 return mData->resource; 1805 return mData->resource;
1805} 1806}
1806 1807
1807//US 1808//US
1808QString Addressee::resourceLabel() 1809QString Addressee::resourceLabel()
1809{ 1810{
1810 return i18n("Resource"); 1811 return i18n("Resource");
1811} 1812}
1812 1813
1813void Addressee::setChanged( bool value ) 1814void Addressee::setChanged( bool value )
1814{ 1815{
1815 detach(); 1816 detach();
1816 mData->changed = value; 1817 mData->changed = value;
1817} 1818}
1818 1819
1819bool Addressee::changed() const 1820bool Addressee::changed() const
1820{ 1821{
1821 return mData->changed; 1822 return mData->changed;
1822} 1823}
1823 1824
1825void Addressee::setTagged( bool value )
1826{
1827 detach();
1828 mData->tagged = value;
1829}
1830
1831bool Addressee::tagged() const
1832{
1833 return mData->tagged;
1834}
1835
1824QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) 1836QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a )
1825{ 1837{
1826 if (!a.mData) return s; 1838 if (!a.mData) return s;
1827 1839
1828 s << a.uid(); 1840 s << a.uid();
1829 1841
1830 s << a.mData->name; 1842 s << a.mData->name;
1831 s << a.mData->formattedName; 1843 s << a.mData->formattedName;
1832 s << a.mData->familyName; 1844 s << a.mData->familyName;
1833 s << a.mData->givenName; 1845 s << a.mData->givenName;
1834 s << a.mData->additionalName; 1846 s << a.mData->additionalName;
1835 s << a.mData->prefix; 1847 s << a.mData->prefix;
1836 s << a.mData->suffix; 1848 s << a.mData->suffix;
1837 s << a.mData->nickName; 1849 s << a.mData->nickName;
1838 s << a.mData->birthday; 1850 s << a.mData->birthday;
1839 s << a.mData->mailer; 1851 s << a.mData->mailer;
1840 s << a.mData->timeZone; 1852 s << a.mData->timeZone;
1841 s << a.mData->geo; 1853 s << a.mData->geo;
1842 s << a.mData->title; 1854 s << a.mData->title;
1843 s << a.mData->role; 1855 s << a.mData->role;
1844 s << a.mData->organization; 1856 s << a.mData->organization;
1845 s << a.mData->note; 1857 s << a.mData->note;
1846 s << a.mData->productId; 1858 s << a.mData->productId;
1847 s << a.mData->revision; 1859 s << a.mData->revision;
1848 s << a.mData->sortString; 1860 s << a.mData->sortString;
1849 s << a.mData->url; 1861 s << a.mData->url;
1850 s << a.mData->secrecy; 1862 s << a.mData->secrecy;
1851 s << a.mData->logo; 1863 s << a.mData->logo;
1852 s << a.mData->photo; 1864 s << a.mData->photo;
1853 s << a.mData->sound; 1865 s << a.mData->sound;
1854 s << a.mData->agent; 1866 s << a.mData->agent;
1855 s << a.mData->phoneNumbers; 1867 s << a.mData->phoneNumbers;
1856 s << a.mData->addresses; 1868 s << a.mData->addresses;
1857 s << a.mData->emails; 1869 s << a.mData->emails;
1858 s << a.mData->categories; 1870 s << a.mData->categories;
1859 s << a.mData->custom; 1871 s << a.mData->custom;
1860 s << a.mData->keys; 1872 s << a.mData->keys;
1861 return s; 1873 return s;
1862} 1874}
1863 1875
1864QDataStream &KABC::operator>>( QDataStream &s, Addressee &a ) 1876QDataStream &KABC::operator>>( QDataStream &s, Addressee &a )
1865{ 1877{
1866 if (!a.mData) return s; 1878 if (!a.mData) return s;
1867 1879
1868 s >> a.mData->uid; 1880 s >> a.mData->uid;
1869 1881
1870 s >> a.mData->name; 1882 s >> a.mData->name;
1871 s >> a.mData->formattedName; 1883 s >> a.mData->formattedName;
1872 s >> a.mData->familyName; 1884 s >> a.mData->familyName;
1873 s >> a.mData->givenName; 1885 s >> a.mData->givenName;
1874 s >> a.mData->additionalName; 1886 s >> a.mData->additionalName;
1875 s >> a.mData->prefix; 1887 s >> a.mData->prefix;
1876 s >> a.mData->suffix; 1888 s >> a.mData->suffix;
1877 s >> a.mData->nickName; 1889 s >> a.mData->nickName;
1878 s >> a.mData->birthday; 1890 s >> a.mData->birthday;
1879 s >> a.mData->mailer; 1891 s >> a.mData->mailer;
1880 s >> a.mData->timeZone; 1892 s >> a.mData->timeZone;
1881 s >> a.mData->geo; 1893 s >> a.mData->geo;
1882 s >> a.mData->title; 1894 s >> a.mData->title;
1883 s >> a.mData->role; 1895 s >> a.mData->role;
1884 s >> a.mData->organization; 1896 s >> a.mData->organization;
1885 s >> a.mData->note; 1897 s >> a.mData->note;
1886 s >> a.mData->productId; 1898 s >> a.mData->productId;
1887 s >> a.mData->revision; 1899 s >> a.mData->revision;
1888 s >> a.mData->sortString; 1900 s >> a.mData->sortString;
1889 s >> a.mData->url; 1901 s >> a.mData->url;
1890 s >> a.mData->secrecy; 1902 s >> a.mData->secrecy;
1891 s >> a.mData->logo; 1903 s >> a.mData->logo;
1892 s >> a.mData->photo; 1904 s >> a.mData->photo;
1893 s >> a.mData->sound; 1905 s >> a.mData->sound;
1894 s >> a.mData->agent; 1906 s >> a.mData->agent;
1895 s >> a.mData->phoneNumbers; 1907 s >> a.mData->phoneNumbers;
1896 s >> a.mData->addresses; 1908 s >> a.mData->addresses;
1897 s >> a.mData->emails; 1909 s >> a.mData->emails;
1898 s >> a.mData->categories; 1910 s >> a.mData->categories;
1899 s >> a.mData->custom; 1911 s >> a.mData->custom;
1900 s >> a.mData->keys; 1912 s >> a.mData->keys;
1901 1913
1902 a.mData->empty = false; 1914 a.mData->empty = false;
1903 1915
1904 return s; 1916 return s;
1905} 1917}
1906bool matchBinaryPattern( int value, int pattern ) 1918bool matchBinaryPattern( int value, int pattern )
1907{ 1919{
1908 /** 1920 /**
1909 We want to match all telephonnumbers/addresses which have the bits in the 1921 We want to match all telephonnumbers/addresses which have the bits in the
1910 pattern set. More are allowed. 1922 pattern set. More are allowed.
1911 if pattern == 0 we have a special handling, then we want only those with 1923 if pattern == 0 we have a special handling, then we want only those with
1912 exactly no bit set. 1924 exactly no bit set.
1913 */ 1925 */
1914 if ( pattern == 0 ) 1926 if ( pattern == 0 )
1915 return ( value == 0 ); 1927 return ( value == 0 );
1916 else 1928 else
1917 return ( pattern == ( pattern & value ) ); 1929 return ( pattern == ( pattern & value ) );
1918} 1930}
1919 1931
1920bool matchBinaryPatternP( int value, int pattern ) 1932bool matchBinaryPatternP( int value, int pattern )
1921{ 1933{
1922 1934
1923 if ( pattern == 0 ) 1935 if ( pattern == 0 )
1924 return ( value == 0 ); 1936 return ( value == 0 );
1925 else 1937 else
1926 return ( (pattern |PhoneNumber::Pref ) == ( value |PhoneNumber::Pref ) ); 1938 return ( (pattern |PhoneNumber::Pref ) == ( value |PhoneNumber::Pref ) );
1927} 1939}
1928bool matchBinaryPatternA( int value, int pattern ) 1940bool matchBinaryPatternA( int value, int pattern )
1929{ 1941{
1930 1942
1931 if ( pattern == 0 ) 1943 if ( pattern == 0 )
1932 return ( value == 0 ); 1944 return ( value == 0 );
1933 else 1945 else
1934 return ( (pattern | Address::Pref) == ( value | Address::Pref ) ); 1946 return ( (pattern | Address::Pref) == ( value | Address::Pref ) );
1935} 1947}
diff --git a/kabc/addressee.h b/kabc/addressee.h
index 9336edc..0aa2c51 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -450,400 +450,403 @@ class Addressee
450 */ 450 */
451 QString note() const; 451 QString note() const;
452 /** 452 /**
453 Return translated label for note field. 453 Return translated label for note field.
454 */ 454 */
455 static QString noteLabel(); 455 static QString noteLabel();
456 456
457 /** 457 /**
458 Set product identifier. 458 Set product identifier.
459 */ 459 */
460 void setProductId( const QString &productId ); 460 void setProductId( const QString &productId );
461 /** 461 /**
462 Return product identifier. 462 Return product identifier.
463 */ 463 */
464 QString productId() const; 464 QString productId() const;
465 /** 465 /**
466 Return translated label for productId field. 466 Return translated label for productId field.
467 */ 467 */
468 static QString productIdLabel(); 468 static QString productIdLabel();
469 469
470 /** 470 /**
471 Set revision date. 471 Set revision date.
472 */ 472 */
473 void setRevision( const QDateTime &revision ); 473 void setRevision( const QDateTime &revision );
474 /** 474 /**
475 Return revision date. 475 Return revision date.
476 */ 476 */
477 QDateTime revision() const; 477 QDateTime revision() const;
478 /** 478 /**
479 Return translated label for revision field. 479 Return translated label for revision field.
480 */ 480 */
481 static QString revisionLabel(); 481 static QString revisionLabel();
482 482
483 /** 483 /**
484 Set sort string. 484 Set sort string.
485 */ 485 */
486 void setSortString( const QString &sortString ); 486 void setSortString( const QString &sortString );
487 /** 487 /**
488 Return sort string. 488 Return sort string.
489 */ 489 */
490 QString sortString() const; 490 QString sortString() const;
491 /** 491 /**
492 Return translated label for sortString field. 492 Return translated label for sortString field.
493 */ 493 */
494 static QString sortStringLabel(); 494 static QString sortStringLabel();
495 495
496 /** 496 /**
497 Set URL. 497 Set URL.
498 */ 498 */
499 void setUrl( const KURL &url ); 499 void setUrl( const KURL &url );
500 /** 500 /**
501 Return URL. 501 Return URL.
502 */ 502 */
503 KURL url() const; 503 KURL url() const;
504 /** 504 /**
505 Return translated label for url field. 505 Return translated label for url field.
506 */ 506 */
507 static QString urlLabel(); 507 static QString urlLabel();
508 508
509 /** 509 /**
510 Set security class. 510 Set security class.
511 */ 511 */
512 void setSecrecy( const Secrecy &secrecy ); 512 void setSecrecy( const Secrecy &secrecy );
513 /** 513 /**
514 Return security class. 514 Return security class.
515 */ 515 */
516 Secrecy secrecy() const; 516 Secrecy secrecy() const;
517 /** 517 /**
518 Return translated label for secrecy field. 518 Return translated label for secrecy field.
519 */ 519 */
520 static QString secrecyLabel(); 520 static QString secrecyLabel();
521 521
522 /** 522 /**
523 Set logo. 523 Set logo.
524 */ 524 */
525 void setLogo( const Picture &logo ); 525 void setLogo( const Picture &logo );
526 /** 526 /**
527 Return logo. 527 Return logo.
528 */ 528 */
529 Picture logo() const; 529 Picture logo() const;
530 /** 530 /**
531 Return translated label for logo field. 531 Return translated label for logo field.
532 */ 532 */
533 static QString logoLabel(); 533 static QString logoLabel();
534 534
535 /** 535 /**
536 Set photo. 536 Set photo.
537 */ 537 */
538 void setPhoto( const Picture &photo ); 538 void setPhoto( const Picture &photo );
539 /** 539 /**
540 Return photo. 540 Return photo.
541 */ 541 */
542 Picture photo() const; 542 Picture photo() const;
543 /** 543 /**
544 Return translated label for photo field. 544 Return translated label for photo field.
545 */ 545 */
546 static QString photoLabel(); 546 static QString photoLabel();
547 547
548 /** 548 /**
549 Set sound. 549 Set sound.
550 */ 550 */
551 void setSound( const Sound &sound ); 551 void setSound( const Sound &sound );
552 /** 552 /**
553 Return sound. 553 Return sound.
554 */ 554 */
555 Sound sound() const; 555 Sound sound() const;
556 /** 556 /**
557 Return translated label for sound field. 557 Return translated label for sound field.
558 */ 558 */
559 static QString soundLabel(); 559 static QString soundLabel();
560 560
561 /** 561 /**
562 Set agent. 562 Set agent.
563 */ 563 */
564 void setAgent( const Agent &agent ); 564 void setAgent( const Agent &agent );
565 /** 565 /**
566 Return agent. 566 Return agent.
567 */ 567 */
568 Agent agent() const; 568 Agent agent() const;
569 /** 569 /**
570 Return translated label for agent field. 570 Return translated label for agent field.
571 */ 571 */
572 static QString agentLabel(); 572 static QString agentLabel();
573 573
574 /** 574 /**
575 Set name fields by parsing the given string and trying to associate the 575 Set name fields by parsing the given string and trying to associate the
576 parts of the string with according fields. This function should probably 576 parts of the string with according fields. This function should probably
577 be a bit more clever. 577 be a bit more clever.
578 */ 578 */
579 void setNameFromString( const QString & ); 579 void setNameFromString( const QString & );
580 580
581 /** 581 /**
582 Return the name of the addressee. This is calculated from all the name 582 Return the name of the addressee. This is calculated from all the name
583 fields. 583 fields.
584 */ 584 */
585 QString realName() const; 585 QString realName() const;
586 586
587 /** 587 /**
588 Return the name that consists of all name parts. 588 Return the name that consists of all name parts.
589 */ 589 */
590 QString assembledName() const; 590 QString assembledName() const;
591 591
592 /** 592 /**
593 Return email address including real name. 593 Return email address including real name.
594 594
595 @param email Email address to be used to construct the full email string. 595 @param email Email address to be used to construct the full email string.
596 If this is QString::null the preferred email address is used. 596 If this is QString::null the preferred email address is used.
597 */ 597 */
598 QString fullEmail( const QString &email=QString::null ) const; 598 QString fullEmail( const QString &email=QString::null ) const;
599 599
600 /** 600 /**
601 Insert an email address. If the email address already exists in this 601 Insert an email address. If the email address already exists in this
602 addressee it is not duplicated. 602 addressee it is not duplicated.
603 603
604 @param email Email address 604 @param email Email address
605 @param preferred Set to true, if this is the preferred email address of 605 @param preferred Set to true, if this is the preferred email address of
606 the addressee. 606 the addressee.
607 */ 607 */
608 void insertEmail( const QString &email, bool preferred=false ); 608 void insertEmail( const QString &email, bool preferred=false );
609 609
610 /** 610 /**
611 Remove email address. If the email address doesn't exist, nothing happens. 611 Remove email address. If the email address doesn't exist, nothing happens.
612 */ 612 */
613 void removeEmail( const QString &email ); 613 void removeEmail( const QString &email );
614 614
615 /** 615 /**
616 Return preferred email address. This is the first email address or the 616 Return preferred email address. This is the first email address or the
617 last one added with @ref insertEmail() with a set preferred parameter. 617 last one added with @ref insertEmail() with a set preferred parameter.
618 */ 618 */
619 QString preferredEmail() const; 619 QString preferredEmail() const;
620 620
621 /** 621 /**
622 Return list of all email addresses. 622 Return list of all email addresses.
623 */ 623 */
624 QStringList emails() const; 624 QStringList emails() const;
625 625
626 /** 626 /**
627 Set the emails to @param. 627 Set the emails to @param.
628 The first email address gets the preferred one! 628 The first email address gets the preferred one!
629 @param list The list of email addresses. 629 @param list The list of email addresses.
630 */ 630 */
631 void setEmails( const QStringList& list); 631 void setEmails( const QStringList& list);
632 632
633 /** 633 /**
634 Insert a phone number. If a phone number with the same id already exists 634 Insert a phone number. If a phone number with the same id already exists
635 in this addressee it is not duplicated. 635 in this addressee it is not duplicated.
636 */ 636 */
637 void insertPhoneNumber( const PhoneNumber &phoneNumber ); 637 void insertPhoneNumber( const PhoneNumber &phoneNumber );
638 638
639 /** 639 /**
640 Remove phone number. If no phone number with the given id exists for this 640 Remove phone number. If no phone number with the given id exists for this
641 addresse nothing happens. 641 addresse nothing happens.
642 */ 642 */
643 void removePhoneNumber( const PhoneNumber &phoneNumber ); 643 void removePhoneNumber( const PhoneNumber &phoneNumber );
644 644
645 /** 645 /**
646 Return phone number, which matches the given type. 646 Return phone number, which matches the given type.
647 */ 647 */
648 PhoneNumber phoneNumber( int type ) const; 648 PhoneNumber phoneNumber( int type ) const;
649 649
650 /** 650 /**
651 Return list of all phone numbers. 651 Return list of all phone numbers.
652 */ 652 */
653 PhoneNumber::List phoneNumbers() const; 653 PhoneNumber::List phoneNumbers() const;
654 654
655 /** 655 /**
656 Return list of phone numbers with a special type. 656 Return list of phone numbers with a special type.
657 */ 657 */
658 PhoneNumber::List phoneNumbers( int type ) const; 658 PhoneNumber::List phoneNumbers( int type ) const;
659 659
660 /** 660 /**
661 Return phone number with the given id. 661 Return phone number with the given id.
662 */ 662 */
663 PhoneNumber findPhoneNumber( const QString &id ) const; 663 PhoneNumber findPhoneNumber( const QString &id ) const;
664 664
665 /** 665 /**
666 Insert a key. If a key with the same id already exists 666 Insert a key. If a key with the same id already exists
667 in this addressee it is not duplicated. 667 in this addressee it is not duplicated.
668 */ 668 */
669 void insertKey( const Key &key ); 669 void insertKey( const Key &key );
670 670
671 /** 671 /**
672 Remove a key. If no key with the given id exists for this 672 Remove a key. If no key with the given id exists for this
673 addresse nothing happens. 673 addresse nothing happens.
674 */ 674 */
675 void removeKey( const Key &key ); 675 void removeKey( const Key &key );
676 676
677 /** 677 /**
678 Return key, which matches the given type. 678 Return key, which matches the given type.
679 If @p type == Key::Custom you can specify a string 679 If @p type == Key::Custom you can specify a string
680 that should match. If you leave the string empty, the first 680 that should match. If you leave the string empty, the first
681 key with a custom value is returned. 681 key with a custom value is returned.
682 */ 682 */
683 Key key( int type, QString customTypeString = QString::null ) const; 683 Key key( int type, QString customTypeString = QString::null ) const;
684 684
685 /** 685 /**
686 Return list of all keys. 686 Return list of all keys.
687 */ 687 */
688 Key::List keys() const; 688 Key::List keys() const;
689 689
690 /** 690 /**
691 Set the list of keys 691 Set the list of keys
692 @param keys The keys to be set. 692 @param keys The keys to be set.
693 */ 693 */
694 void setKeys( const Key::List& keys); 694 void setKeys( const Key::List& keys);
695 695
696 /** 696 /**
697 Return list of keys with a special type. 697 Return list of keys with a special type.
698 If @p type == Key::Custom you can specify a string 698 If @p type == Key::Custom you can specify a string
699 that should match. If you leave the string empty, all custom 699 that should match. If you leave the string empty, all custom
700 keys will be returned. 700 keys will be returned.
701 */ 701 */
702 Key::List keys( int type, QString customTypeString = QString::null ) const; 702 Key::List keys( int type, QString customTypeString = QString::null ) const;
703 703
704 /** 704 /**
705 Return key with the given id. 705 Return key with the given id.
706 */ 706 */
707 Key findKey( const QString &id ) const; 707 Key findKey( const QString &id ) const;
708 708
709 /** 709 /**
710 Insert an address. If an address with the same id already exists 710 Insert an address. If an address with the same id already exists
711 in this addressee it is not duplicated. 711 in this addressee it is not duplicated.
712 */ 712 */
713 void insertAddress( const Address &address ); 713 void insertAddress( const Address &address );
714 714
715 /** 715 /**
716 Remove address. If no address with the given id exists for this 716 Remove address. If no address with the given id exists for this
717 addresse nothing happens. 717 addresse nothing happens.
718 */ 718 */
719 void removeAddress( const Address &address ); 719 void removeAddress( const Address &address );
720 720
721 /** 721 /**
722 Return address, which matches the given type. 722 Return address, which matches the given type.
723 */ 723 */
724 Address address( int type ) const; 724 Address address( int type ) const;
725 725
726 /** 726 /**
727 Return list of all addresses. 727 Return list of all addresses.
728 */ 728 */
729 Address::List addresses() const; 729 Address::List addresses() const;
730 730
731 /** 731 /**
732 Return list of addresses with a special type. 732 Return list of addresses with a special type.
733 */ 733 */
734 Address::List addresses( int type ) const; 734 Address::List addresses( int type ) const;
735 735
736 /** 736 /**
737 Return address with the given id. 737 Return address with the given id.
738 */ 738 */
739 Address findAddress( const QString &id ) const; 739 Address findAddress( const QString &id ) const;
740 740
741 /** 741 /**
742 Insert category. If the category already exists it is not duplicated. 742 Insert category. If the category already exists it is not duplicated.
743 */ 743 */
744 void insertCategory( const QString & ); 744 void insertCategory( const QString & );
745 745
746 /** 746 /**
747 Remove category. 747 Remove category.
748 */ 748 */
749 void removeCategory( const QString & ); 749 void removeCategory( const QString & );
750 750
751 /** 751 /**
752 Return, if addressee has the given category. 752 Return, if addressee has the given category.
753 */ 753 */
754 bool hasCategory( const QString & ) const; 754 bool hasCategory( const QString & ) const;
755 755
756 /** 756 /**
757 Set categories to given value. 757 Set categories to given value.
758 */ 758 */
759 void setCategories( const QStringList & ); 759 void setCategories( const QStringList & );
760 760
761 /** 761 /**
762 Return list of all set categories. 762 Return list of all set categories.
763 */ 763 */
764 QStringList categories() const; 764 QStringList categories() const;
765 765
766 /** 766 /**
767 Insert custom entry. The entry is identified by the name of the inserting 767 Insert custom entry. The entry is identified by the name of the inserting
768 application and a unique name. If an entry with the given app and name 768 application and a unique name. If an entry with the given app and name
769 already exists its value is replaced with the new given value. 769 already exists its value is replaced with the new given value.
770 */ 770 */
771 void insertCustom( const QString &app, const QString &name, 771 void insertCustom( const QString &app, const QString &name,
772 const QString &value ); 772 const QString &value );
773 773
774 /** 774 /**
775 Remove custom entry. 775 Remove custom entry.
776 */ 776 */
777 void removeCustom( const QString &app, const QString &name ); 777 void removeCustom( const QString &app, const QString &name );
778 778
779 /** 779 /**
780 Return value of custom entry, identified by app and entry name. 780 Return value of custom entry, identified by app and entry name.
781 */ 781 */
782 QString custom( const QString &app, const QString &name ) const; 782 QString custom( const QString &app, const QString &name ) const;
783 783
784 /** 784 /**
785 Set all custom entries. 785 Set all custom entries.
786 */ 786 */
787 void setCustoms( const QStringList & ); 787 void setCustoms( const QStringList & );
788 788
789 /** 789 /**
790 Return list of all custom entries. 790 Return list of all custom entries.
791 */ 791 */
792 QStringList customs() const; 792 QStringList customs() const;
793 793
794 /** 794 /**
795 Parse full email address. The result is given back in fullName and email. 795 Parse full email address. The result is given back in fullName and email.
796 */ 796 */
797 static void parseEmailAddress( const QString &rawEmail, QString &fullName, 797 static void parseEmailAddress( const QString &rawEmail, QString &fullName,
798 QString &email ); 798 QString &email );
799 799
800 /** 800 /**
801 Debug output. 801 Debug output.
802 */ 802 */
803 void dump() const; 803 void dump() const;
804 804
805 /** 805 /**
806 Returns string representation of the addressee. 806 Returns string representation of the addressee.
807 */ 807 */
808 QString asString() const; 808 QString asString() const;
809 809
810 /** 810 /**
811 Set resource where the addressee is from. 811 Set resource where the addressee is from.
812 */ 812 */
813 void setResource( Resource *resource ); 813 void setResource( Resource *resource );
814 814
815 /** 815 /**
816 Return pointer to resource. 816 Return pointer to resource.
817 */ 817 */
818 Resource *resource() const; 818 Resource *resource() const;
819 819
820 /** 820 /**
821 Return resourcelabel. 821 Return resourcelabel.
822 */ 822 */
823 //US 823 //US
824 static QString resourceLabel(); 824 static QString resourceLabel();
825 825
826 /** 826 /**
827 Mark addressee as changed. 827 Mark addressee as changed.
828 */ 828 */
829 void setChanged( bool value ); 829 void setChanged( bool value );
830 830
831 /** 831 /**
832 Return whether the addressee is changed. 832 Return whether the addressee is changed.
833 */ 833 */
834 bool changed() const; 834 bool changed() const;
835
836 void setTagged( bool value );
837 bool tagged() const;
835 838
836 private: 839 private:
837 Addressee copy(); 840 Addressee copy();
838 void detach(); 841 void detach();
839 842
840 struct AddresseeData; 843 struct AddresseeData;
841 mutable KSharedPtr<AddresseeData> mData; 844 mutable KSharedPtr<AddresseeData> mData;
842}; 845};
843 846
844QDataStream &operator<<( QDataStream &, const Addressee & ); 847QDataStream &operator<<( QDataStream &, const Addressee & );
845QDataStream &operator>>( QDataStream &, Addressee & ); 848QDataStream &operator>>( QDataStream &, Addressee & );
846 849
847} 850}
848 851
849#endif 852#endif
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 7ec3fca..452f1bc 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2495,405 +2495,405 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
2495 int deletedAddresseeL = 0; 2495 int deletedAddresseeL = 0;
2496 int changedLocal = 0; 2496 int changedLocal = 0;
2497 int changedRemote = 0; 2497 int changedRemote = 0;
2498 2498
2499 QString mCurrentSyncName = syncManager->getCurrentSyncName(); 2499 QString mCurrentSyncName = syncManager->getCurrentSyncName();
2500 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2500 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2501 2501
2502 //QPtrList<Addressee> el = local->rawAddressees(); 2502 //QPtrList<Addressee> el = local->rawAddressees();
2503 Addressee addresseeR; 2503 Addressee addresseeR;
2504 QString uid; 2504 QString uid;
2505 int take; 2505 int take;
2506 Addressee addresseeL; 2506 Addressee addresseeL;
2507 Addressee addresseeRSync; 2507 Addressee addresseeRSync;
2508 Addressee addresseeLSync; 2508 Addressee addresseeLSync;
2509 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2509 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2510 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2510 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2511 bool fullDateRange = false; 2511 bool fullDateRange = false;
2512 local->resetTempSyncStat(); 2512 local->resetTempSyncStat();
2513 mLastAddressbookSync = QDateTime::currentDateTime(); 2513 mLastAddressbookSync = QDateTime::currentDateTime();
2514 QDateTime modifiedCalendar = mLastAddressbookSync;; 2514 QDateTime modifiedCalendar = mLastAddressbookSync;;
2515 addresseeLSync = getLastSyncAddressee(); 2515 addresseeLSync = getLastSyncAddressee();
2516 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); 2516 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1());
2517 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); 2517 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2518 if ( !addresseeR.isEmpty() ) { 2518 if ( !addresseeR.isEmpty() ) {
2519 addresseeRSync = addresseeR; 2519 addresseeRSync = addresseeR;
2520 remote->removeAddressee(addresseeR ); 2520 remote->removeAddressee(addresseeR );
2521 2521
2522 } else { 2522 } else {
2523 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2523 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2524 addresseeRSync = addresseeLSync ; 2524 addresseeRSync = addresseeLSync ;
2525 } else { 2525 } else {
2526 qDebug("FULLDATE 1"); 2526 qDebug("FULLDATE 1");
2527 fullDateRange = true; 2527 fullDateRange = true;
2528 Addressee newAdd; 2528 Addressee newAdd;
2529 addresseeRSync = newAdd; 2529 addresseeRSync = newAdd;
2530 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); 2530 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
2531 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); 2531 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
2532 addresseeRSync.setRevision( mLastAddressbookSync ); 2532 addresseeRSync.setRevision( mLastAddressbookSync );
2533 addresseeRSync.setCategories( i18n("SyncAddressee") ); 2533 addresseeRSync.setCategories( i18n("SyncAddressee") );
2534 } 2534 }
2535 } 2535 }
2536 if ( addresseeLSync.revision() == mLastAddressbookSync ) { 2536 if ( addresseeLSync.revision() == mLastAddressbookSync ) {
2537 qDebug("FULLDATE 2"); 2537 qDebug("FULLDATE 2");
2538 fullDateRange = true; 2538 fullDateRange = true;
2539 } 2539 }
2540 if ( ! fullDateRange ) { 2540 if ( ! fullDateRange ) {
2541 if ( addresseeLSync.revision() != addresseeRSync.revision() ) { 2541 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2542 2542
2543 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2543 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2544 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2544 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2545 fullDateRange = true; 2545 fullDateRange = true;
2546 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); 2546 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
2547 } 2547 }
2548 } 2548 }
2549 // fullDateRange = true; // debug only! 2549 // fullDateRange = true; // debug only!
2550 if ( fullDateRange ) 2550 if ( fullDateRange )
2551 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2551 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2552 else 2552 else
2553 mLastAddressbookSync = addresseeLSync.revision(); 2553 mLastAddressbookSync = addresseeLSync.revision();
2554 // for resyncing if own file has changed 2554 // for resyncing if own file has changed
2555 // PENDING fixme later when implemented 2555 // PENDING fixme later when implemented
2556#if 0 2556#if 0
2557 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2557 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2558 mLastAddressbookSync = loadedFileVersion; 2558 mLastAddressbookSync = loadedFileVersion;
2559 qDebug("setting mLastAddressbookSync "); 2559 qDebug("setting mLastAddressbookSync ");
2560 } 2560 }
2561#endif 2561#endif
2562 2562
2563 //qDebug("*************************** "); 2563 //qDebug("*************************** ");
2564 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2564 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2565 QStringList er = remote->uidList(); 2565 QStringList er = remote->uidList();
2566 Addressee inR ;//= er.first(); 2566 Addressee inR ;//= er.first();
2567 Addressee inL; 2567 Addressee inL;
2568 2568
2569 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 2569 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
2570 2570
2571 int modulo = (er.count()/10)+1; 2571 int modulo = (er.count()/10)+1;
2572 int incCounter = 0; 2572 int incCounter = 0;
2573 while ( incCounter < er.count()) { 2573 while ( incCounter < er.count()) {
2574 if (syncManager->isProgressBarCanceled()) 2574 if (syncManager->isProgressBarCanceled())
2575 return false; 2575 return false;
2576 if ( incCounter % modulo == 0 ) 2576 if ( incCounter % modulo == 0 )
2577 syncManager->showProgressBar(incCounter); 2577 syncManager->showProgressBar(incCounter);
2578 2578
2579 uid = er[ incCounter ]; 2579 uid = er[ incCounter ];
2580 bool skipIncidence = false; 2580 bool skipIncidence = false;
2581 if ( uid.left(19) == QString("last-syncAddressee-") ) 2581 if ( uid.left(19) == QString("last-syncAddressee-") )
2582 skipIncidence = true; 2582 skipIncidence = true;
2583 QString idS,OidS; 2583 QString idS,OidS;
2584 qApp->processEvents(); 2584 qApp->processEvents();
2585 if ( !skipIncidence ) { 2585 if ( !skipIncidence ) {
2586 inL = local->findByUid( uid ); 2586 inL = local->findByUid( uid );
2587 inR = remote->findByUid( uid ); 2587 inR = remote->findByUid( uid );
2588 //inL.setResource( 0 ); 2588 //inL.setResource( 0 );
2589 //inR.setResource( 0 ); 2589 //inR.setResource( 0 );
2590 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars 2590 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
2591 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { 2591 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) {
2592 //qDebug("take %d %s ", take, inL.summary().latin1()); 2592 //qDebug("take %d %s ", take, inL.summary().latin1());
2593 if ( take == 3 ) 2593 if ( take == 3 )
2594 return false; 2594 return false;
2595 if ( take == 1 ) {// take local 2595 if ( take == 1 ) {// take local
2596 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2596 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2597 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2597 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2598 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2598 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2599 local->insertAddressee( inL, false ); 2599 local->insertAddressee( inL, false );
2600 idS = inR.externalUID(); 2600 idS = inR.externalUID();
2601 OidS = inR.originalExternalUID(); 2601 OidS = inR.originalExternalUID();
2602 } 2602 }
2603 else 2603 else
2604 idS = inR.IDStr(); 2604 idS = inR.IDStr();
2605 remote->removeAddressee( inR ); 2605 remote->removeAddressee( inR );
2606 inR = inL; 2606 inR = inL;
2607 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2607 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2608 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2608 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2609 inR.setOriginalExternalUID( OidS ); 2609 inR.setOriginalExternalUID( OidS );
2610 inR.setExternalUID( idS ); 2610 inR.setExternalUID( idS );
2611 } else { 2611 } else {
2612 inR.setIDStr( idS ); 2612 inR.setIDStr( idS );
2613 } 2613 }
2614 inR.setResource( 0 ); 2614 inR.setResource( 0 );
2615 remote->insertAddressee( inR , false); 2615 remote->insertAddressee( inR , false);
2616 ++changedRemote; 2616 ++changedRemote;
2617 } else { // take == 2 take remote 2617 } else { // take == 2 take remote
2618 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2618 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2619 if ( inR.revision().date().year() < 2004 ) 2619 if ( inR.revision().date().year() < 2004 )
2620 inR.setRevision( modifiedCalendar ); 2620 inR.setRevision( modifiedCalendar );
2621 } 2621 }
2622 idS = inL.IDStr(); 2622 idS = inL.IDStr();
2623 local->removeAddressee( inL ); 2623 local->removeAddressee( inL );
2624 inL = inR; 2624 inL = inR;
2625 inL.setIDStr( idS ); 2625 inL.setIDStr( idS );
2626 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2626 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2627 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2627 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2628 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2628 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2629 } 2629 }
2630 inL.setResource( 0 ); 2630 inL.setResource( 0 );
2631 local->insertAddressee( inL , false ); 2631 local->insertAddressee( inL , false );
2632 ++changedLocal; 2632 ++changedLocal;
2633 } 2633 }
2634 } 2634 }
2635 } else { // no conflict 2635 } else { // no conflict
2636 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2636 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2637 QString des = addresseeLSync.note(); 2637 QString des = addresseeLSync.note();
2638 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 2638 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2639 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 2639 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2640 remote->insertAddressee( inR, false ); 2640 remote->insertAddressee( inR, false );
2641 ++deletedAddresseeR; 2641 ++deletedAddresseeR;
2642 } else { 2642 } else {
2643 inR.setRevision( modifiedCalendar ); 2643 inR.setRevision( modifiedCalendar );
2644 remote->insertAddressee( inR, false ); 2644 remote->insertAddressee( inR, false );
2645 inL = inR; 2645 inL = inR;
2646 inL.setResource( 0 ); 2646 inL.setResource( 0 );
2647 local->insertAddressee( inL , false); 2647 local->insertAddressee( inL , false);
2648 ++addedAddressee; 2648 ++addedAddressee;
2649 } 2649 }
2650 } else { 2650 } else {
2651 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { 2651 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2652 inR.setRevision( modifiedCalendar ); 2652 inR.setRevision( modifiedCalendar );
2653 remote->insertAddressee( inR, false ); 2653 remote->insertAddressee( inR, false );
2654 inR.setResource( 0 ); 2654 inR.setResource( 0 );
2655 local->insertAddressee( inR, false ); 2655 local->insertAddressee( inR, false );
2656 ++addedAddressee; 2656 ++addedAddressee;
2657 } else { 2657 } else {
2658 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2658 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2659 remote->removeAddressee( inR ); 2659 remote->removeAddressee( inR );
2660 ++deletedAddresseeR; 2660 ++deletedAddresseeR;
2661 } 2661 }
2662 } 2662 }
2663 } 2663 }
2664 } 2664 }
2665 ++incCounter; 2665 ++incCounter;
2666 } 2666 }
2667 er.clear(); 2667 er.clear();
2668 QStringList el = local->uidList(); 2668 QStringList el = local->uidList();
2669 modulo = (el.count()/10)+1; 2669 modulo = (el.count()/10)+1;
2670 2670
2671 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 2671 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
2672 incCounter = 0; 2672 incCounter = 0;
2673 while ( incCounter < el.count()) { 2673 while ( incCounter < el.count()) {
2674 qApp->processEvents(); 2674 qApp->processEvents();
2675 if (syncManager->isProgressBarCanceled()) 2675 if (syncManager->isProgressBarCanceled())
2676 return false; 2676 return false;
2677 if ( incCounter % modulo == 0 ) 2677 if ( incCounter % modulo == 0 )
2678 syncManager->showProgressBar(incCounter); 2678 syncManager->showProgressBar(incCounter);
2679 uid = el[ incCounter ]; 2679 uid = el[ incCounter ];
2680 bool skipIncidence = false; 2680 bool skipIncidence = false;
2681 if ( uid.left(19) == QString("last-syncAddressee-") ) 2681 if ( uid.left(19) == QString("last-syncAddressee-") )
2682 skipIncidence = true; 2682 skipIncidence = true;
2683 if ( !skipIncidence ) { 2683 if ( !skipIncidence ) {
2684 inL = local->findByUid( uid ); 2684 inL = local->findByUid( uid );
2685 inR = remote->findByUid( uid ); 2685 inR = remote->findByUid( uid );
2686 if ( inR.isEmpty() ) { 2686 if ( inR.isEmpty() ) {
2687 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2687 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2688 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 2688 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
2689 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2689 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2690 local->removeAddressee( inL ); 2690 local->removeAddressee( inL );
2691 ++deletedAddresseeL; 2691 ++deletedAddresseeL;
2692 } else { 2692 } else {
2693 if ( ! syncManager->mWriteBackExistingOnly ) { 2693 if ( ! syncManager->mWriteBackExistingOnly ) {
2694 inL.removeID(mCurrentSyncDevice ); 2694 inL.removeID(mCurrentSyncDevice );
2695 ++addedAddresseeR; 2695 ++addedAddresseeR;
2696 inL.setRevision( modifiedCalendar ); 2696 inL.setRevision( modifiedCalendar );
2697 local->insertAddressee( inL, false ); 2697 local->insertAddressee( inL, false );
2698 inR = inL; 2698 inR = inL;
2699 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); 2699 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL );
2700 inR.setResource( 0 ); 2700 inR.setResource( 0 );
2701 remote->insertAddressee( inR, false ); 2701 remote->insertAddressee( inR, false );
2702 } 2702 }
2703 } 2703 }
2704 } else { 2704 } else {
2705 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { 2705 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
2706 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2706 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2707 local->removeAddressee( inL ); 2707 local->removeAddressee( inL );
2708 ++deletedAddresseeL; 2708 ++deletedAddresseeL;
2709 } else { 2709 } else {
2710 if ( ! syncManager->mWriteBackExistingOnly ) { 2710 if ( ! syncManager->mWriteBackExistingOnly ) {
2711 ++addedAddresseeR; 2711 ++addedAddresseeR;
2712 inL.setRevision( modifiedCalendar ); 2712 inL.setRevision( modifiedCalendar );
2713 local->insertAddressee( inL, false ); 2713 local->insertAddressee( inL, false );
2714 inR = inL; 2714 inR = inL;
2715 inR.setResource( 0 ); 2715 inR.setResource( 0 );
2716 remote->insertAddressee( inR, false ); 2716 remote->insertAddressee( inR, false );
2717 } 2717 }
2718 } 2718 }
2719 } 2719 }
2720 } 2720 }
2721 } 2721 }
2722 ++incCounter; 2722 ++incCounter;
2723 } 2723 }
2724 el.clear(); 2724 el.clear();
2725 syncManager->hideProgressBar(); 2725 syncManager->hideProgressBar();
2726 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 2726 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
2727 // get rid of micro seconds 2727 // get rid of micro seconds
2728 QTime t = mLastAddressbookSync.time(); 2728 QTime t = mLastAddressbookSync.time();
2729 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 2729 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
2730 addresseeLSync.setRevision( mLastAddressbookSync ); 2730 addresseeLSync.setRevision( mLastAddressbookSync );
2731 addresseeRSync.setRevision( mLastAddressbookSync ); 2731 addresseeRSync.setRevision( mLastAddressbookSync );
2732 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 2732 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
2733 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 2733 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
2734 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; 2734 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ;
2735 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); 2735 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") );
2736 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; 2736 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ;
2737 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); 2737 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() );
2738 addresseeRSync.setNote( "" ) ; 2738 addresseeRSync.setNote( "" ) ;
2739 addresseeLSync.setNote( "" ); 2739 addresseeLSync.setNote( "" );
2740 2740
2741 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2741 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2742 remote->insertAddressee( addresseeRSync, false ); 2742 remote->insertAddressee( addresseeRSync, false );
2743 local->insertAddressee( addresseeLSync, false ); 2743 local->insertAddressee( addresseeLSync, false );
2744 QString mes; 2744 QString mes;
2745 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); 2745 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR );
2746 if ( syncManager->mShowSyncSummary ) { 2746 if ( syncManager->mShowSyncSummary ) {
2747 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); 2747 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") );
2748 } 2748 }
2749 qDebug( mes ); 2749 qDebug( mes );
2750 return syncOK; 2750 return syncOK;
2751} 2751}
2752 2752
2753 2753
2754//this is a overwritten callbackmethods from the syncinterface 2754//this is a overwritten callbackmethods from the syncinterface
2755bool KABCore::sync(KSyncManager* manager, QString filename, int mode) 2755bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
2756{ 2756{
2757 2757
2758 //pending prepare addresseeview for output 2758 //pending prepare addresseeview for output
2759 //pending detect, if remote file has REV field. if not switch to external sync 2759 //pending detect, if remote file has REV field. if not switch to external sync
2760 mGlobalSyncMode = SYNC_MODE_NORMAL; 2760 mGlobalSyncMode = SYNC_MODE_NORMAL;
2761 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2761 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2762 2762
2763 AddressBook abLocal(filename,"syncContact"); 2763 AddressBook abLocal(filename,"syncContact");
2764 bool syncOK = false; 2764 bool syncOK = false;
2765 if ( abLocal.load() ) { 2765 if ( abLocal.load() ) {
2766 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); 2766 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode );
2767 bool external = false; 2767 bool external = false;
2768 bool isXML = false; 2768 bool isXML = false;
2769 if ( filename.right(4) == ".xml") { 2769 if ( filename.right(4) == ".xml") {
2770 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2770 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2771 isXML = true; 2771 isXML = true;
2772 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); 2772 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
2773 } else { 2773 } else {
2774 Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2774 Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2775 if ( ! lse.isEmpty() ) { 2775 if ( ! lse.isEmpty() ) {
2776 if ( lse.familyName().left(4) == "!E: " ) 2776 if ( lse.familyName().left(4) == "!E: " )
2777 external = true; 2777 external = true;
2778 } else { 2778 } else {
2779 bool found = false; 2779 bool found = false;
2780 AddressBook::Iterator it; 2780 AddressBook::Iterator it;
2781 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2781 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2782 if ( (*it).revision().date().year() > 2003 ) { 2782 if ( (*it).revision().date().year() > 2003 ) {
2783 found = true; 2783 found = true;
2784 break; 2784 break;
2785 } 2785 }
2786 } 2786 }
2787 external = ! found; 2787 external = ! found;
2788 } 2788 }
2789 2789
2790 if ( external ) { 2790 if ( external ) {
2791 qDebug("Setting vcf mode to external "); 2791 qDebug("Setting vcf mode to external ");
2792 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2792 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2793 AddressBook::Iterator it; 2793 AddressBook::Iterator it;
2794 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2794 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2795 (*it).setID( mCurrentSyncDevice, (*it).uid() ); 2795 (*it).setID( mCurrentSyncDevice, (*it).uid() );
2796 (*it).computeCsum( mCurrentSyncDevice ); 2796 (*it).computeCsum( mCurrentSyncDevice );
2797 } 2797 }
2798 } 2798 }
2799 } 2799 }
2800 //AddressBook::Iterator it; 2800 //AddressBook::Iterator it;
2801 //QStringList vcards; 2801 //QStringList vcards;
2802 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2802 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2803 // qDebug("Name %s ", (*it).familyName().latin1()); 2803 // qDebug("Name %s ", (*it).familyName().latin1());
2804 //} 2804 //}
2805 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2805 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2806 if ( syncOK ) { 2806 if ( syncOK ) {
2807 if ( syncManager->mWriteBackFile ) 2807 if ( syncManager->mWriteBackFile )
2808 { 2808 {
2809 if ( external ) 2809 if ( external )
2810 abLocal.removeSyncAddressees( !isXML); 2810 abLocal.removeSyncAddressees( !isXML);
2811 qDebug("Saving remote AB "); 2811 qDebug("Saving remote AB ");
2812 if ( ! abLocal.saveAB()) 2812 if ( ! abLocal.saveAB())
2813 qDebug("Error writing back AB to file "); 2813 qDebug("Error writing back AB to file ");
2814 if ( isXML ) { 2814 if ( isXML ) {
2815 // afterwrite processing 2815 // afterwrite processing
2816 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2816 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2817 } 2817 }
2818 } 2818 }
2819 } 2819 }
2820 setModified(); 2820 setModified();
2821 2821
2822 } 2822 }
2823 if ( syncOK ) 2823 if ( syncOK )
2824 mViewManager->refreshView(); 2824 mViewManager->refreshView();
2825 return syncOK; 2825 return syncOK;
2826#if 0 2826#if 0
2827 2827
2828 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { 2828 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
2829 getEventViewerDialog()->setSyncMode( true ); 2829 getEventViewerDialog()->setSyncMode( true );
2830 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 2830 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
2831 getEventViewerDialog()->setSyncMode( false ); 2831 getEventViewerDialog()->setSyncMode( false );
2832 if ( syncOK ) { 2832 if ( syncOK ) {
2833 if ( KOPrefs::instance()->mWriteBackFile ) 2833 if ( KOPrefs::instance()->mWriteBackFile )
2834 { 2834 {
2835 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 2835 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
2836 storage->save(); 2836 storage->save();
2837 } 2837 }
2838 } 2838 }
2839 setModified(); 2839 setModified();
2840 } 2840 }
2841 2841
2842#endif 2842#endif
2843} 2843}
2844 2844
2845 2845
2846//this is a overwritten callbackmethods from the syncinterface 2846//this is a overwritten callbackmethods from the syncinterface
2847bool KABCore::syncExternal(KSyncManager* manager, QString resource) 2847bool KABCore::syncExternal(KSyncManager* manager, QString resource)
2848{ 2848{
2849 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2849 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2850 2850
2851 AddressBook abLocal( resource,"syncContact"); 2851 AddressBook abLocal( resource,"syncContact");
2852 bool syncOK = false; 2852 bool syncOK = false;
2853 if ( abLocal.load() ) { 2853 if ( abLocal.load() ) {
2854 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2854 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1());
2855 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2855 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2856 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); 2856 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
2857 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2857 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2858 if ( syncOK ) { 2858 if ( syncOK ) {
2859 if ( syncManager->mWriteBackFile ) { 2859 if ( syncManager->mWriteBackFile ) {
2860 abLocal.saveAB(); 2860 abLocal.saveAB();
2861 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2861 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2862 } 2862 }
2863 } 2863 }
2864 setModified(); 2864 setModified();
2865 } 2865 }
2866 if ( syncOK ) 2866 if ( syncOK )
2867 mViewManager->refreshView(); 2867 mViewManager->refreshView();
2868 return syncOK; 2868 return syncOK;
2869 2869
2870} 2870}
2871 2871
2872void KABCore::getFile( bool success ) 2872void KABCore::getFile( bool success )
2873{ 2873{
2874 QTimer::singleShot( 15000, this , SLOT ( setCaptionBack())); 2874 QTimer::singleShot( 15000, this , SLOT ( setCaptionBack()));
2875 if ( ! success ) { 2875 if ( ! success ) {
2876 setCaption( i18n("Error receiving file. Nothing changed!") ); 2876 setCaption( i18n("Error receiving file. Nothing changed!") );
2877 return; 2877 return;
2878 } 2878 }
2879 mAddressBook->importFromFile( sentSyncFile() ); 2879 mAddressBook->importFromFile( sentSyncFile() , false, true );
2880 topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); 2880 topLevelWidget()->setCaption( i18n("Pi-Sync successful!") );
2881 mViewManager->refreshView(); 2881 mViewManager->refreshView();
2882} 2882}
2883void KABCore::syncFileRequest() 2883void KABCore::syncFileRequest()
2884{ 2884{
2885 mAddressBook->export2File( sentSyncFile() ); 2885 mAddressBook->export2File( sentSyncFile() );
2886} 2886}
2887QString KABCore::sentSyncFile() 2887QString KABCore::sentSyncFile()
2888{ 2888{
2889#ifdef _WIN32_ 2889#ifdef _WIN32_
2890 return locateLocal( "tmp", "copysyncab.vcf" ); 2890 return locateLocal( "tmp", "copysyncab.vcf" );
2891#else 2891#else
2892 return QString( "/tmp/copysyncab.vcf" ); 2892 return QString( "/tmp/copysyncab.vcf" );
2893#endif 2893#endif
2894} 2894}
2895 2895
2896void KABCore::setCaptionBack() 2896void KABCore::setCaptionBack()
2897{ 2897{
2898 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); 2898 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") );
2899} 2899}