summaryrefslogtreecommitdiffabout
path: root/kabc
Unidiff
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp8
-rw-r--r--kabc/addressbook.h1
-rw-r--r--kabc/addressee.cpp5
3 files changed, 13 insertions, 1 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 3641c0c..2785131 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -1,1211 +1,1219 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28/*US 28/*US
29 29
30#include <qfile.h> 30#include <qfile.h>
31#include <qregexp.h> 31#include <qregexp.h>
32#include <qtimer.h> 32#include <qtimer.h>
33 33
34#include <kapplication.h> 34#include <kapplication.h>
35#include <kinstance.h> 35#include <kinstance.h>
36#include <kstandarddirs.h> 36#include <kstandarddirs.h>
37 37
38#include "errorhandler.h" 38#include "errorhandler.h"
39*/ 39*/
40#include <qptrlist.h> 40#include <qptrlist.h>
41#include <qtextstream.h> 41#include <qtextstream.h>
42#include <qfile.h> 42#include <qfile.h>
43#include <qregexp.h> 43#include <qregexp.h>
44 44
45#include <kglobal.h> 45#include <kglobal.h>
46#include <klocale.h> 46#include <klocale.h>
47#include <kmessagebox.h> 47#include <kmessagebox.h>
48#include <kdebug.h> 48#include <kdebug.h>
49#include <libkcal/syncdefines.h> 49#include <libkcal/syncdefines.h>
50#include <libkdepim/phoneaccess.h> 50#include <libkdepim/phoneaccess.h>
51#include "addressbook.h" 51#include "addressbook.h"
52#include "resource.h" 52#include "resource.h"
53#include "vcardconverter.h" 53#include "vcardconverter.h"
54#include "vcardparser/vcardtool.h" 54#include "vcardparser/vcardtool.h"
55 55
56//US #include "addressbook.moc" 56//US #include "addressbook.moc"
57 57
58using namespace KABC; 58using namespace KABC;
59 59
60struct AddressBook::AddressBookData 60struct AddressBook::AddressBookData
61{ 61{
62 Addressee::List mAddressees; 62 Addressee::List mAddressees;
63 Addressee::List mRemovedAddressees; 63 Addressee::List mRemovedAddressees;
64 Field::List mAllFields; 64 Field::List mAllFields;
65 KConfig *mConfig; 65 KConfig *mConfig;
66 KRES::Manager<Resource> *mManager; 66 KRES::Manager<Resource> *mManager;
67//US ErrorHandler *mErrorHandler; 67//US ErrorHandler *mErrorHandler;
68}; 68};
69 69
70struct AddressBook::Iterator::IteratorData 70struct AddressBook::Iterator::IteratorData
71{ 71{
72 Addressee::List::Iterator mIt; 72 Addressee::List::Iterator mIt;
73}; 73};
74 74
75struct AddressBook::ConstIterator::ConstIteratorData 75struct AddressBook::ConstIterator::ConstIteratorData
76{ 76{
77 Addressee::List::ConstIterator mIt; 77 Addressee::List::ConstIterator mIt;
78}; 78};
79 79
80AddressBook::Iterator::Iterator() 80AddressBook::Iterator::Iterator()
81{ 81{
82 d = new IteratorData; 82 d = new IteratorData;
83} 83}
84 84
85AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) 85AddressBook::Iterator::Iterator( const AddressBook::Iterator &i )
86{ 86{
87 d = new IteratorData; 87 d = new IteratorData;
88 d->mIt = i.d->mIt; 88 d->mIt = i.d->mIt;
89} 89}
90 90
91AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) 91AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i )
92{ 92{
93 if( this == &i ) return *this; // guard against self assignment 93 if( this == &i ) return *this; // guard against self assignment
94 delete d; // delete the old data the Iterator was completely constructed before 94 delete d; // delete the old data the Iterator was completely constructed before
95 d = new IteratorData; 95 d = new IteratorData;
96 d->mIt = i.d->mIt; 96 d->mIt = i.d->mIt;
97 return *this; 97 return *this;
98} 98}
99 99
100AddressBook::Iterator::~Iterator() 100AddressBook::Iterator::~Iterator()
101{ 101{
102 delete d; 102 delete d;
103} 103}
104 104
105const Addressee &AddressBook::Iterator::operator*() const 105const Addressee &AddressBook::Iterator::operator*() const
106{ 106{
107 return *(d->mIt); 107 return *(d->mIt);
108} 108}
109 109
110Addressee &AddressBook::Iterator::operator*() 110Addressee &AddressBook::Iterator::operator*()
111{ 111{
112 return *(d->mIt); 112 return *(d->mIt);
113} 113}
114 114
115Addressee *AddressBook::Iterator::operator->() 115Addressee *AddressBook::Iterator::operator->()
116{ 116{
117 return &(*(d->mIt)); 117 return &(*(d->mIt));
118} 118}
119 119
120AddressBook::Iterator &AddressBook::Iterator::operator++() 120AddressBook::Iterator &AddressBook::Iterator::operator++()
121{ 121{
122 (d->mIt)++; 122 (d->mIt)++;
123 return *this; 123 return *this;
124} 124}
125 125
126AddressBook::Iterator &AddressBook::Iterator::operator++(int) 126AddressBook::Iterator &AddressBook::Iterator::operator++(int)
127{ 127{
128 (d->mIt)++; 128 (d->mIt)++;
129 return *this; 129 return *this;
130} 130}
131 131
132AddressBook::Iterator &AddressBook::Iterator::operator--() 132AddressBook::Iterator &AddressBook::Iterator::operator--()
133{ 133{
134 (d->mIt)--; 134 (d->mIt)--;
135 return *this; 135 return *this;
136} 136}
137 137
138AddressBook::Iterator &AddressBook::Iterator::operator--(int) 138AddressBook::Iterator &AddressBook::Iterator::operator--(int)
139{ 139{
140 (d->mIt)--; 140 (d->mIt)--;
141 return *this; 141 return *this;
142} 142}
143 143
144bool AddressBook::Iterator::operator==( const Iterator &it ) 144bool AddressBook::Iterator::operator==( const Iterator &it )
145{ 145{
146 return ( d->mIt == it.d->mIt ); 146 return ( d->mIt == it.d->mIt );
147} 147}
148 148
149bool AddressBook::Iterator::operator!=( const Iterator &it ) 149bool AddressBook::Iterator::operator!=( const Iterator &it )
150{ 150{
151 return ( d->mIt != it.d->mIt ); 151 return ( d->mIt != it.d->mIt );
152} 152}
153 153
154 154
155AddressBook::ConstIterator::ConstIterator() 155AddressBook::ConstIterator::ConstIterator()
156{ 156{
157 d = new ConstIteratorData; 157 d = new ConstIteratorData;
158} 158}
159 159
160AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) 160AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i )
161{ 161{
162 d = new ConstIteratorData; 162 d = new ConstIteratorData;
163 d->mIt = i.d->mIt; 163 d->mIt = i.d->mIt;
164} 164}
165 165
166AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) 166AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i )
167{ 167{
168 if( this == &i ) return *this; // guard for self assignment 168 if( this == &i ) return *this; // guard for self assignment
169 delete d; // delete the old data because the Iterator was really constructed before 169 delete d; // delete the old data because the Iterator was really constructed before
170 d = new ConstIteratorData; 170 d = new ConstIteratorData;
171 d->mIt = i.d->mIt; 171 d->mIt = i.d->mIt;
172 return *this; 172 return *this;
173} 173}
174 174
175AddressBook::ConstIterator::~ConstIterator() 175AddressBook::ConstIterator::~ConstIterator()
176{ 176{
177 delete d; 177 delete d;
178} 178}
179 179
180const Addressee &AddressBook::ConstIterator::operator*() const 180const Addressee &AddressBook::ConstIterator::operator*() const
181{ 181{
182 return *(d->mIt); 182 return *(d->mIt);
183} 183}
184 184
185const Addressee* AddressBook::ConstIterator::operator->() const 185const Addressee* AddressBook::ConstIterator::operator->() const
186{ 186{
187 return &(*(d->mIt)); 187 return &(*(d->mIt));
188} 188}
189 189
190AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() 190AddressBook::ConstIterator &AddressBook::ConstIterator::operator++()
191{ 191{
192 (d->mIt)++; 192 (d->mIt)++;
193 return *this; 193 return *this;
194} 194}
195 195
196AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) 196AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int)
197{ 197{
198 (d->mIt)++; 198 (d->mIt)++;
199 return *this; 199 return *this;
200} 200}
201 201
202AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() 202AddressBook::ConstIterator &AddressBook::ConstIterator::operator--()
203{ 203{
204 (d->mIt)--; 204 (d->mIt)--;
205 return *this; 205 return *this;
206} 206}
207 207
208AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) 208AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int)
209{ 209{
210 (d->mIt)--; 210 (d->mIt)--;
211 return *this; 211 return *this;
212} 212}
213 213
214bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) 214bool AddressBook::ConstIterator::operator==( const ConstIterator &it )
215{ 215{
216 return ( d->mIt == it.d->mIt ); 216 return ( d->mIt == it.d->mIt );
217} 217}
218 218
219bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) 219bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
220{ 220{
221 return ( d->mIt != it.d->mIt ); 221 return ( d->mIt != it.d->mIt );
222} 222}
223 223
224 224
225AddressBook::AddressBook() 225AddressBook::AddressBook()
226{ 226{
227 init(0, "contact"); 227 init(0, "contact");
228} 228}
229 229
230AddressBook::AddressBook( const QString &config ) 230AddressBook::AddressBook( const QString &config )
231{ 231{
232 init(config, "contact"); 232 init(config, "contact");
233} 233}
234 234
235AddressBook::AddressBook( const QString &config, const QString &family ) 235AddressBook::AddressBook( const QString &config, const QString &family )
236{ 236{
237 init(config, family); 237 init(config, family);
238 238
239} 239}
240 240
241// the default family is "contact" 241// the default family is "contact"
242void AddressBook::init(const QString &config, const QString &family ) 242void AddressBook::init(const QString &config, const QString &family )
243{ 243{
244 blockLSEchange = false; 244 blockLSEchange = false;
245 d = new AddressBookData; 245 d = new AddressBookData;
246 QString fami = family; 246 QString fami = family;
247 if (config != 0) { 247 if (config != 0) {
248 if ( family == "syncContact" ) { 248 if ( family == "syncContact" ) {
249 qDebug("creating sync config "); 249 qDebug("creating sync config ");
250 fami = "contact"; 250 fami = "contact";
251 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); 251 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") );
252 con->setGroup( "General" ); 252 con->setGroup( "General" );
253 con->writeEntry( "ResourceKeys", QString("sync") ); 253 con->writeEntry( "ResourceKeys", QString("sync") );
254 con->writeEntry( "Standard", QString("sync") ); 254 con->writeEntry( "Standard", QString("sync") );
255 con->setGroup( "Resource_sync" ); 255 con->setGroup( "Resource_sync" );
256 con->writeEntry( "FileName", config ); 256 con->writeEntry( "FileName", config );
257 con->writeEntry( "FileFormat", QString("vcard") ); 257 con->writeEntry( "FileFormat", QString("vcard") );
258 con->writeEntry( "ResourceIdentifier", QString("sync") ); 258 con->writeEntry( "ResourceIdentifier", QString("sync") );
259 con->writeEntry( "ResourceName", QString("sync_res") ); 259 con->writeEntry( "ResourceName", QString("sync_res") );
260 if ( config.right(4) == ".xml" ) 260 if ( config.right(4) == ".xml" )
261 con->writeEntry( "ResourceType", QString("qtopia") ); 261 con->writeEntry( "ResourceType", QString("qtopia") );
262 else if ( config == "sharp" ) { 262 else if ( config == "sharp" ) {
263 con->writeEntry( "ResourceType", QString("sharp") ); 263 con->writeEntry( "ResourceType", QString("sharp") );
264 } else { 264 } else {
265 con->writeEntry( "ResourceType", QString("file") ); 265 con->writeEntry( "ResourceType", QString("file") );
266 } 266 }
267 //con->sync(); 267 //con->sync();
268 d->mConfig = con; 268 d->mConfig = con;
269 } 269 }
270 else 270 else
271 d->mConfig = new KConfig( locateLocal("config", config) ); 271 d->mConfig = new KConfig( locateLocal("config", config) );
272// qDebug("AddressBook::init 1 config=%s",config.latin1() ); 272// qDebug("AddressBook::init 1 config=%s",config.latin1() );
273 } 273 }
274 else { 274 else {
275 d->mConfig = 0; 275 d->mConfig = 0;
276// qDebug("AddressBook::init 1 config=0"); 276// qDebug("AddressBook::init 1 config=0");
277 } 277 }
278 278
279//US d->mErrorHandler = 0; 279//US d->mErrorHandler = 0;
280 d->mManager = new KRES::Manager<Resource>( fami ); 280 d->mManager = new KRES::Manager<Resource>( fami );
281 d->mManager->readConfig( d->mConfig ); 281 d->mManager->readConfig( d->mConfig );
282 if ( family == "syncContact" ) { 282 if ( family == "syncContact" ) {
283 KRES::Manager<Resource> *manager = d->mManager; 283 KRES::Manager<Resource> *manager = d->mManager;
284 KRES::Manager<Resource>::ActiveIterator it; 284 KRES::Manager<Resource>::ActiveIterator it;
285 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 285 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
286 (*it)->setAddressBook( this ); 286 (*it)->setAddressBook( this );
287 if ( !(*it)->open() ) 287 if ( !(*it)->open() )
288 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 288 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
289 } 289 }
290 Resource *res = standardResource(); 290 Resource *res = standardResource();
291 if ( !res ) { 291 if ( !res ) {
292 qDebug("ERROR: no standard resource"); 292 qDebug("ERROR: no standard resource");
293 res = manager->createResource( "file" ); 293 res = manager->createResource( "file" );
294 if ( res ) 294 if ( res )
295 { 295 {
296 addResource( res ); 296 addResource( res );
297 } 297 }
298 else 298 else
299 qDebug(" No resource available!!!"); 299 qDebug(" No resource available!!!");
300 } 300 }
301 setStandardResource( res ); 301 setStandardResource( res );
302 manager->writeConfig(); 302 manager->writeConfig();
303 } 303 }
304 addCustomField( i18n( "Department" ), KABC::Field::Organization, 304 addCustomField( i18n( "Department" ), KABC::Field::Organization,
305 "X-Department", "KADDRESSBOOK" ); 305 "X-Department", "KADDRESSBOOK" );
306 addCustomField( i18n( "Profession" ), KABC::Field::Organization, 306 addCustomField( i18n( "Profession" ), KABC::Field::Organization,
307 "X-Profession", "KADDRESSBOOK" ); 307 "X-Profession", "KADDRESSBOOK" );
308 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 308 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
309 "X-AssistantsName", "KADDRESSBOOK" ); 309 "X-AssistantsName", "KADDRESSBOOK" );
310 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 310 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
311 "X-ManagersName", "KADDRESSBOOK" ); 311 "X-ManagersName", "KADDRESSBOOK" );
312 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 312 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
313 "X-SpousesName", "KADDRESSBOOK" ); 313 "X-SpousesName", "KADDRESSBOOK" );
314 addCustomField( i18n( "Office" ), KABC::Field::Personal, 314 addCustomField( i18n( "Office" ), KABC::Field::Personal,
315 "X-Office", "KADDRESSBOOK" ); 315 "X-Office", "KADDRESSBOOK" );
316 addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 316 addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
317 "X-IMAddress", "KADDRESSBOOK" ); 317 "X-IMAddress", "KADDRESSBOOK" );
318 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 318 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
319 "X-Anniversary", "KADDRESSBOOK" ); 319 "X-Anniversary", "KADDRESSBOOK" );
320 320
321 //US added this field to become compatible with Opie/qtopia addressbook 321 //US added this field to become compatible with Opie/qtopia addressbook
322 // values can be "female" or "male" or "". An empty field represents undefined. 322 // values can be "female" or "male" or "". An empty field represents undefined.
323 addCustomField( i18n( "Gender" ), KABC::Field::Personal, 323 addCustomField( i18n( "Gender" ), KABC::Field::Personal,
324 "X-Gender", "KADDRESSBOOK" ); 324 "X-Gender", "KADDRESSBOOK" );
325 addCustomField( i18n( "Children" ), KABC::Field::Personal, 325 addCustomField( i18n( "Children" ), KABC::Field::Personal,
326 "X-Children", "KADDRESSBOOK" ); 326 "X-Children", "KADDRESSBOOK" );
327 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 327 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
328 "X-FreeBusyUrl", "KADDRESSBOOK" ); 328 "X-FreeBusyUrl", "KADDRESSBOOK" );
329 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, 329 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal,
330 "X-ExternalID", "KADDRESSBOOK" ); 330 "X-ExternalID", "KADDRESSBOOK" );
331} 331}
332 332
333AddressBook::~AddressBook() 333AddressBook::~AddressBook()
334{ 334{
335 delete d->mConfig; d->mConfig = 0; 335 delete d->mConfig; d->mConfig = 0;
336 delete d->mManager; d->mManager = 0; 336 delete d->mManager; d->mManager = 0;
337//US delete d->mErrorHandler; d->mErrorHandler = 0; 337//US delete d->mErrorHandler; d->mErrorHandler = 0;
338 delete d; d = 0; 338 delete d; d = 0;
339} 339}
340 340
341bool AddressBook::load() 341bool AddressBook::load()
342{ 342{
343 343
344 clear(); 344 clear();
345 KRES::Manager<Resource>::ActiveIterator it; 345 KRES::Manager<Resource>::ActiveIterator it;
346 bool ok = true; 346 bool ok = true;
347 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 347 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
348 if ( !(*it)->load() ) { 348 if ( !(*it)->load() ) {
349 qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 349 qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
350 ok = false; 350 ok = false;
351 } else { 351 } else {
352 qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); 352 qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) );
353 } 353 }
354 // mark all addressees as unchanged 354 // mark all addressees as unchanged
355 Addressee::List::Iterator addrIt; 355 Addressee::List::Iterator addrIt;
356 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { 356 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) {
357 (*addrIt).setChanged( false ); 357 (*addrIt).setChanged( false );
358 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); 358 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" );
359 if ( !id.isEmpty() ) { 359 if ( !id.isEmpty() ) {
360 //qDebug("setId aa %s ", id.latin1()); 360 //qDebug("setId aa %s ", id.latin1());
361 (*addrIt).setIDStr(id ); 361 (*addrIt).setIDStr(id );
362 } 362 }
363 } 363 }
364 blockLSEchange = true; 364 blockLSEchange = true;
365 return ok; 365 return ok;
366} 366}
367 367
368bool AddressBook::save( Ticket *ticket ) 368bool AddressBook::save( Ticket *ticket )
369{ 369{
370 kdDebug(5700) << "AddressBook::save()"<< endl; 370 kdDebug(5700) << "AddressBook::save()"<< endl;
371 371
372 if ( ticket->resource() ) { 372 if ( ticket->resource() ) {
373 deleteRemovedAddressees(); 373 deleteRemovedAddressees();
374 return ticket->resource()->save( ticket ); 374 return ticket->resource()->save( ticket );
375 } 375 }
376 376
377 return false; 377 return false;
378} 378}
379// exports all Addressees, which are syncable 379// exports all Addressees, which are syncable
380void AddressBook::export2File( QString fileName ) 380void AddressBook::export2File( QString fileName )
381{ 381{
382 382
383 QFile outFile( fileName ); 383 QFile outFile( fileName );
384 if ( !outFile.open( IO_WriteOnly ) ) { 384 if ( !outFile.open( IO_WriteOnly ) ) {
385 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); 385 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" );
386 KMessageBox::error( 0, text.arg( fileName ) ); 386 KMessageBox::error( 0, text.arg( fileName ) );
387 return ; 387 return ;
388 } 388 }
389 QTextStream t( &outFile ); 389 QTextStream t( &outFile );
390 t.setEncoding( QTextStream::UnicodeUTF8 ); 390 t.setEncoding( QTextStream::UnicodeUTF8 );
391 Iterator it; 391 Iterator it;
392 KABC::VCardConverter::Version version; 392 KABC::VCardConverter::Version version;
393 version = KABC::VCardConverter::v3_0; 393 version = KABC::VCardConverter::v3_0;
394 for ( it = begin(); it != end(); ++it ) { 394 for ( it = begin(); it != end(); ++it ) {
395 if ( (*it).resource() && (*it).resource()->includeInSync() ) { 395 if ( (*it).resource() && (*it).resource()->includeInSync() ) {
396 if ( !(*it).IDStr().isEmpty() ) { 396 if ( !(*it).IDStr().isEmpty() ) {
397 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); 397 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() );
398 } 398 }
399 KABC::VCardConverter converter; 399 KABC::VCardConverter converter;
400 QString vcard; 400 QString vcard;
401 //Resource *resource() const; 401 //Resource *resource() const;
402 converter.addresseeToVCard( *it, vcard, version ); 402 converter.addresseeToVCard( *it, vcard, version );
403 t << vcard << "\r\n"; 403 t << vcard << "\r\n";
404 } 404 }
405 } 405 }
406 t << "\r\n\r\n"; 406 t << "\r\n\r\n";
407 outFile.close(); 407 outFile.close();
408} 408}
409// if QStringList uids is empty, all are exported 409// if QStringList uids is empty, all are exported
410bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) 410bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName )
411{ 411{
412 KABC::VCardConverter converter; 412 KABC::VCardConverter converter;
413 QString datastream; 413 QString datastream;
414 Iterator it; 414 Iterator it;
415 bool all = uids.isEmpty(); 415 bool all = uids.isEmpty();
416 for ( it = begin(); it != end(); ++it ) { 416 for ( it = begin(); it != end(); ++it ) {
417 // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 417 // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
418 if ( ! all ) { 418 if ( ! all ) {
419 if ( ! ( uids.contains((*it).uid() ) )) 419 if ( ! ( uids.contains((*it).uid() ) ))
420 continue; 420 continue;
421 } 421 }
422 KABC::Addressee a = ( *it ); 422 KABC::Addressee a = ( *it );
423 if ( a.isEmpty() ) 423 if ( a.isEmpty() )
424 continue; 424 continue;
425 if ( all && a.resource() && !a.resource()->includeInSync() ) 425 if ( all && a.resource() && !a.resource()->includeInSync() )
426 continue; 426 continue;
427 a.simplifyEmails(); 427 a.simplifyEmails();
428 a.simplifyPhoneNumbers(); 428 a.simplifyPhoneNumbers();
429 a.simplifyPhoneNumberTypes(); 429 a.simplifyPhoneNumberTypes();
430 a.simplifyAddresses(); 430 a.simplifyAddresses();
431 431
432 QString vcard; 432 QString vcard;
433 QString vcardnew; 433 QString vcardnew;
434 converter.addresseeToVCard( a, vcard ); 434 converter.addresseeToVCard( a, vcard );
435 int start = 0; 435 int start = 0;
436 int next; 436 int next;
437 while ( (next = vcard.find("TYPE=", start) )>= 0 ) { 437 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
438 int semi = vcard.find(";", next); 438 int semi = vcard.find(";", next);
439 int dopp = vcard.find(":", next); 439 int dopp = vcard.find(":", next);
440 int sep; 440 int sep;
441 if ( semi < dopp && semi >= 0 ) 441 if ( semi < dopp && semi >= 0 )
442 sep = semi ; 442 sep = semi ;
443 else 443 else
444 sep = dopp; 444 sep = dopp;
445 vcardnew +=vcard.mid( start, next - start); 445 vcardnew +=vcard.mid( start, next - start);
446 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); 446 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper();
447 start = sep; 447 start = sep;
448 } 448 }
449 vcardnew += vcard.mid( start,vcard.length() ); 449 vcardnew += vcard.mid( start,vcard.length() );
450 vcard = ""; 450 vcard = "";
451 start = 0; 451 start = 0;
452 while ( (next = vcardnew.find("ADR", start) )>= 0 ) { 452 while ( (next = vcardnew.find("ADR", start) )>= 0 ) {
453 int sep = vcardnew.find(":", next); 453 int sep = vcardnew.find(":", next);
454 vcard +=vcardnew.mid( start, next - start+3); 454 vcard +=vcardnew.mid( start, next - start+3);
455 start = sep; 455 start = sep;
456 } 456 }
457 vcard += vcardnew.mid( start,vcardnew.length() ); 457 vcard += vcardnew.mid( start,vcardnew.length() );
458 vcard.replace ( QRegExp(";;;") , "" ); 458 vcard.replace ( QRegExp(";;;") , "" );
459 vcard.replace ( QRegExp(";;") , "" ); 459 vcard.replace ( QRegExp(";;") , "" );
460 datastream += vcard; 460 datastream += vcard;
461 461
462 } 462 }
463 463
464 QFile outFile(fileName); 464 QFile outFile(fileName);
465 if ( outFile.open(IO_WriteOnly) ) { 465 if ( outFile.open(IO_WriteOnly) ) {
466 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); 466 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
467 QTextStream t( &outFile ); // use a text stream 467 QTextStream t( &outFile ); // use a text stream
468 t.setEncoding( QTextStream::UnicodeUTF8 ); 468 t.setEncoding( QTextStream::UnicodeUTF8 );
469 t <<datastream; 469 t <<datastream;
470 t << "\r\n\r\n"; 470 t << "\r\n\r\n";
471 outFile.close(); 471 outFile.close();
472 472
473 } else { 473 } else {
474 qDebug("Error open temp file "); 474 qDebug("Error open temp file ");
475 return false; 475 return false;
476 } 476 }
477 return true; 477 return true;
478 478
479} 479}
480int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) 480int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld )
481{ 481{
482 482
483 if ( removeOld ) 483 if ( removeOld )
484 setUntagged( true ); 484 setUntagged( true );
485 KABC::Addressee::List list; 485 KABC::Addressee::List list;
486 QFile file( fileName ); 486 QFile file( fileName );
487 file.open( IO_ReadOnly ); 487 file.open( IO_ReadOnly );
488 QByteArray rawData = file.readAll(); 488 QByteArray rawData = file.readAll();
489 file.close(); 489 file.close();
490 QString data; 490 QString data;
491 if ( replaceLabel ) { 491 if ( replaceLabel ) {
492 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); 492 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 );
493 data.replace ( QRegExp("LABEL") , "ADR" ); 493 data.replace ( QRegExp("LABEL") , "ADR" );
494 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); 494 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" );
495 } else 495 } else
496 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 496 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
497 KABC::VCardTool tool; 497 KABC::VCardTool tool;
498 list = tool.parseVCards( data ); 498 list = tool.parseVCards( data );
499 KABC::Addressee::List::Iterator it; 499 KABC::Addressee::List::Iterator it;
500 for ( it = list.begin(); it != list.end(); ++it ) { 500 for ( it = list.begin(); it != list.end(); ++it ) {
501 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); 501 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
502 if ( !id.isEmpty() ) 502 if ( !id.isEmpty() )
503 (*it).setIDStr(id ); 503 (*it).setIDStr(id );
504 (*it).setResource( 0 ); 504 (*it).setResource( 0 );
505 if ( replaceLabel ) 505 if ( replaceLabel )
506 (*it).removeVoice(); 506 (*it).removeVoice();
507 if ( removeOld ) 507 if ( removeOld )
508 (*it).setTagged( true ); 508 (*it).setTagged( true );
509 insertAddressee( (*it), false, true ); 509 insertAddressee( (*it), false, true );
510 } 510 }
511 if ( removeOld ) 511 if ( removeOld )
512 removeUntagged(); 512 removeUntagged();
513 return list.count(); 513 return list.count();
514} 514}
515void AddressBook::setUntagged(bool setNonSyncTagged) // = false) 515void AddressBook::setUntagged(bool setNonSyncTagged) // = false)
516{ 516{
517 Iterator ait; 517 Iterator ait;
518 for ( ait = begin(); ait != end(); ++ait ) { 518 for ( ait = begin(); ait != end(); ++ait ) {
519 if ( setNonSyncTagged ) { 519 if ( setNonSyncTagged ) {
520 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { 520 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) {
521 (*ait).setTagged( true ); 521 (*ait).setTagged( true );
522 } else 522 } else
523 (*ait).setTagged( false ); 523 (*ait).setTagged( false );
524 } else 524 } else
525 (*ait).setTagged( false ); 525 (*ait).setTagged( false );
526 } 526 }
527} 527}
528void AddressBook::removeUntagged() 528void AddressBook::removeUntagged()
529{ 529{
530 Iterator ait; 530 Iterator ait;
531 bool todelete = false; 531 bool todelete = false;
532 Iterator todel; 532 Iterator todel;
533 for ( ait = begin(); ait != end(); ++ait ) { 533 for ( ait = begin(); ait != end(); ++ait ) {
534 if ( todelete ) 534 if ( todelete )
535 removeAddressee( todel ); 535 removeAddressee( todel );
536 if (!(*ait).tagged()) { 536 if (!(*ait).tagged()) {
537 todelete = true; 537 todelete = true;
538 todel = ait; 538 todel = ait;
539 } else 539 } else
540 todelete = false; 540 todelete = false;
541 } 541 }
542 if ( todelete ) 542 if ( todelete )
543 removeAddressee( todel ); 543 removeAddressee( todel );
544 deleteRemovedAddressees(); 544 deleteRemovedAddressees();
545} 545}
546void AddressBook::smplifyAddressees() 546void AddressBook::smplifyAddressees()
547{ 547{
548 Iterator ait; 548 Iterator ait;
549 for ( ait = begin(); ait != end(); ++ait ) { 549 for ( ait = begin(); ait != end(); ++ait ) {
550 (*ait).simplifyEmails(); 550 (*ait).simplifyEmails();
551 (*ait).simplifyPhoneNumbers(); 551 (*ait).simplifyPhoneNumbers();
552 (*ait).simplifyPhoneNumberTypes(); 552 (*ait).simplifyPhoneNumberTypes();
553 (*ait).simplifyAddresses(); 553 (*ait).simplifyAddresses();
554 } 554 }
555} 555}
556void AddressBook::removeSyncInfo( QString syncProfile)
557{
558 Iterator ait;
559 for ( ait = begin(); ait != end(); ++ait ) {
560 (*ait).removeID( syncProfile );
561 }
562
563}
556void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) 564void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync )
557{ 565{
558 Iterator ait; 566 Iterator ait;
559 for ( ait = begin(); ait != end(); ++ait ) { 567 for ( ait = begin(); ait != end(); ++ait ) {
560 QString id = (*ait).IDStr(); 568 QString id = (*ait).IDStr();
561 (*ait).setIDStr( ":"); 569 (*ait).setIDStr( ":");
562 (*ait).setExternalUID( id ); 570 (*ait).setExternalUID( id );
563 (*ait).setOriginalExternalUID( id ); 571 (*ait).setOriginalExternalUID( id );
564 if ( isPreSync ) 572 if ( isPreSync )
565 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 573 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
566 else { 574 else {
567 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 575 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
568 (*ait).setID( currentSyncDevice,id ); 576 (*ait).setID( currentSyncDevice,id );
569 577
570 } 578 }
571 } 579 }
572} 580}
573void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) 581void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice )
574{ 582{
575 583
576 setUntagged(); 584 setUntagged();
577 KABC::Addressee::List list; 585 KABC::Addressee::List list;
578 QFile file( fileName ); 586 QFile file( fileName );
579 file.open( IO_ReadOnly ); 587 file.open( IO_ReadOnly );
580 QByteArray rawData = file.readAll(); 588 QByteArray rawData = file.readAll();
581 file.close(); 589 file.close();
582 QString data; 590 QString data;
583 591
584 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 592 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
585 KABC::VCardTool tool; 593 KABC::VCardTool tool;
586 list = tool.parseVCards( data ); 594 list = tool.parseVCards( data );
587 KABC::Addressee::List::Iterator it; 595 KABC::Addressee::List::Iterator it;
588 for ( it = list.begin(); it != list.end(); ++it ) { 596 for ( it = list.begin(); it != list.end(); ++it ) {
589 Iterator ait; 597 Iterator ait;
590 for ( ait = begin(); ait != end(); ++ait ) { 598 for ( ait = begin(); ait != end(); ++ait ) {
591 if ( !(*ait).tagged() ) { 599 if ( !(*ait).tagged() ) {
592 if ( (*ait).containsAdr(*it)) { 600 if ( (*ait).containsAdr(*it)) {
593 (*ait).setTagged(true); 601 (*ait).setTagged(true);
594 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); 602 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
595 (*it).setIDStr( ":"); 603 (*it).setIDStr( ":");
596 (*it).setID( currentSyncDevice,id ); 604 (*it).setID( currentSyncDevice,id );
597 (*it).setExternalUID( id ); 605 (*it).setExternalUID( id );
598 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 606 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
599 (*it).setUid( ( (*ait).uid() )); 607 (*it).setUid( ( (*ait).uid() ));
600 break; 608 break;
601 } 609 }
602 } 610 }
603 611
604 } 612 }
605 if ( ait == end() ) 613 if ( ait == end() )
606 qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); 614 qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1());
607 } 615 }
608 clear(); 616 clear();
609 for ( it = list.begin(); it != list.end(); ++it ) { 617 for ( it = list.begin(); it != list.end(); ++it ) {
610 insertAddressee( (*it) ); 618 insertAddressee( (*it) );
611 } 619 }
612} 620}
613 621
614bool AddressBook::saveABphone( QString fileName ) 622bool AddressBook::saveABphone( QString fileName )
615{ 623{
616 //smplifyAddressees(); 624 //smplifyAddressees();
617 qDebug("saveABphone:: saving AB... "); 625 qDebug("saveABphone:: saving AB... ");
618 if ( ! export2PhoneFormat( QStringList() ,fileName ) ) 626 if ( ! export2PhoneFormat( QStringList() ,fileName ) )
619 return false; 627 return false;
620 qDebug("saveABphone:: writing to phone... "); 628 qDebug("saveABphone:: writing to phone... ");
621 if ( !PhoneAccess::writeToPhone( fileName) ) { 629 if ( !PhoneAccess::writeToPhone( fileName) ) {
622 return false; 630 return false;
623 } 631 }
624 qDebug("saveABphone:: re-reading from phone... "); 632 qDebug("saveABphone:: re-reading from phone... ");
625 if ( !PhoneAccess::readFromPhone( fileName) ) { 633 if ( !PhoneAccess::readFromPhone( fileName) ) {
626 return false; 634 return false;
627 } 635 }
628 return true; 636 return true;
629} 637}
630bool AddressBook::saveAB() 638bool AddressBook::saveAB()
631{ 639{
632 bool ok = true; 640 bool ok = true;
633 641
634 deleteRemovedAddressees(); 642 deleteRemovedAddressees();
635 Iterator ait; 643 Iterator ait;
636 for ( ait = begin(); ait != end(); ++ait ) { 644 for ( ait = begin(); ait != end(); ++ait ) {
637 if ( !(*ait).IDStr().isEmpty() ) { 645 if ( !(*ait).IDStr().isEmpty() ) {
638 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); 646 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
639 } 647 }
640 } 648 }
641 KRES::Manager<Resource>::ActiveIterator it; 649 KRES::Manager<Resource>::ActiveIterator it;
642 KRES::Manager<Resource> *manager = d->mManager; 650 KRES::Manager<Resource> *manager = d->mManager;
643 qDebug("SaveAB::saving..." ); 651 qDebug("SaveAB::saving..." );
644 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 652 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
645 qDebug("SaveAB::checking resource..." ); 653 qDebug("SaveAB::checking resource..." );
646 if ( (*it)->readOnly() ) 654 if ( (*it)->readOnly() )
647 qDebug("resource is readonly." ); 655 qDebug("resource is readonly." );
648 if ( (*it)->isOpen() ) 656 if ( (*it)->isOpen() )
649 qDebug("resource is open" ); 657 qDebug("resource is open" );
650 658
651 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 659 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
652 Ticket *ticket = requestSaveTicket( *it ); 660 Ticket *ticket = requestSaveTicket( *it );
653 qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 661 qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
654 if ( !ticket ) { 662 if ( !ticket ) {
655 qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) 663 qDebug( i18n( "Unable to save to resource '%1'. It is locked." )
656 .arg( (*it)->resourceName() ) ); 664 .arg( (*it)->resourceName() ) );
657 return false; 665 return false;
658 } 666 }
659 667
660 //if ( !save( ticket ) ) 668 //if ( !save( ticket ) )
661 if ( ticket->resource() ) { 669 if ( ticket->resource() ) {
662 QString name = ticket->resource()->resourceName(); 670 QString name = ticket->resource()->resourceName();
663 if ( ! ticket->resource()->save( ticket ) ) 671 if ( ! ticket->resource()->save( ticket ) )
664 ok = false; 672 ok = false;
665 else 673 else
666 qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); 674 qDebug("StdAddressBook::resource saved '%s'", name.latin1() );
667 675
668 } else 676 } else
669 ok = false; 677 ok = false;
670 678
671 } 679 }
672 } 680 }
673 return ok; 681 return ok;
674} 682}
675 683
676AddressBook::Iterator AddressBook::begin() 684AddressBook::Iterator AddressBook::begin()
677{ 685{
678 Iterator it = Iterator(); 686 Iterator it = Iterator();
679 it.d->mIt = d->mAddressees.begin(); 687 it.d->mIt = d->mAddressees.begin();
680 return it; 688 return it;
681} 689}
682 690
683AddressBook::ConstIterator AddressBook::begin() const 691AddressBook::ConstIterator AddressBook::begin() const
684{ 692{
685 ConstIterator it = ConstIterator(); 693 ConstIterator it = ConstIterator();
686 it.d->mIt = d->mAddressees.begin(); 694 it.d->mIt = d->mAddressees.begin();
687 return it; 695 return it;
688} 696}
689 697
690AddressBook::Iterator AddressBook::end() 698AddressBook::Iterator AddressBook::end()
691{ 699{
692 Iterator it = Iterator(); 700 Iterator it = Iterator();
693 it.d->mIt = d->mAddressees.end(); 701 it.d->mIt = d->mAddressees.end();
694 return it; 702 return it;
695} 703}
696 704
697AddressBook::ConstIterator AddressBook::end() const 705AddressBook::ConstIterator AddressBook::end() const
698{ 706{
699 ConstIterator it = ConstIterator(); 707 ConstIterator it = ConstIterator();
700 it.d->mIt = d->mAddressees.end(); 708 it.d->mIt = d->mAddressees.end();
701 return it; 709 return it;
702} 710}
703 711
704void AddressBook::clear() 712void AddressBook::clear()
705{ 713{
706 d->mAddressees.clear(); 714 d->mAddressees.clear();
707} 715}
708 716
709Ticket *AddressBook::requestSaveTicket( Resource *resource ) 717Ticket *AddressBook::requestSaveTicket( Resource *resource )
710{ 718{
711 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 719 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
712 720
713 if ( !resource ) 721 if ( !resource )
714 { 722 {
715 qDebug("AddressBook::requestSaveTicket no resource" ); 723 qDebug("AddressBook::requestSaveTicket no resource" );
716 resource = standardResource(); 724 resource = standardResource();
717 } 725 }
718 726
719 KRES::Manager<Resource>::ActiveIterator it; 727 KRES::Manager<Resource>::ActiveIterator it;
720 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 728 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
721 if ( (*it) == resource ) { 729 if ( (*it) == resource ) {
722 if ( (*it)->readOnly() || !(*it)->isOpen() ) 730 if ( (*it)->readOnly() || !(*it)->isOpen() )
723 return 0; 731 return 0;
724 else 732 else
725 return (*it)->requestSaveTicket(); 733 return (*it)->requestSaveTicket();
726 } 734 }
727 } 735 }
728 736
729 return 0; 737 return 0;
730} 738}
731//void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); 739//void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
732void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) 740void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource )
733{ 741{
734 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { 742 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
735 //qDebug("block insert "); 743 //qDebug("block insert ");
736 return; 744 return;
737 } 745 }
738 //qDebug("inserting.... %s ",a.uid().latin1() ); 746 //qDebug("inserting.... %s ",a.uid().latin1() );
739 bool found = false; 747 bool found = false;
740 Addressee::List::Iterator it; 748 Addressee::List::Iterator it;
741 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 749 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
742 if ( a.uid() == (*it).uid() ) { 750 if ( a.uid() == (*it).uid() ) {
743 751
744 bool changed = false; 752 bool changed = false;
745 Addressee addr = a; 753 Addressee addr = a;
746 if ( addr != (*it) ) 754 if ( addr != (*it) )
747 changed = true; 755 changed = true;
748 756
749 if ( takeResource ) { 757 if ( takeResource ) {
750 Resource * res = (*it).resource(); 758 Resource * res = (*it).resource();
751 (*it) = a; 759 (*it) = a;
752 (*it).setResource( res ); 760 (*it).setResource( res );
753 } else { 761 } else {
754 (*it) = a; 762 (*it) = a;
755 if ( (*it).resource() == 0 ) 763 if ( (*it).resource() == 0 )
756 (*it).setResource( standardResource() ); 764 (*it).setResource( standardResource() );
757 } 765 }
758 if ( changed ) { 766 if ( changed ) {
759 if ( setRev ) { 767 if ( setRev ) {
760 768
761 // get rid of micro seconds 769 // get rid of micro seconds
762 QDateTime dt = QDateTime::currentDateTime(); 770 QDateTime dt = QDateTime::currentDateTime();
763 QTime t = dt.time(); 771 QTime t = dt.time();
764 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 772 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
765 (*it).setRevision( dt ); 773 (*it).setRevision( dt );
766 } 774 }
767 (*it).setChanged( true ); 775 (*it).setChanged( true );
768 } 776 }
769 777
770 found = true; 778 found = true;
771 } else { 779 } else {
772 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 780 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
773 QString name = (*it).uid().mid( 19 ); 781 QString name = (*it).uid().mid( 19 );
774 Addressee b = a; 782 Addressee b = a;
775 QString id = b.getID( name ); 783 QString id = b.getID( name );
776 if ( ! id.isEmpty() ) { 784 if ( ! id.isEmpty() ) {
777 QString des = (*it).note(); 785 QString des = (*it).note();
778 int startN; 786 int startN;
779 if( (startN = des.find( id ) ) >= 0 ) { 787 if( (startN = des.find( id ) ) >= 0 ) {
780 int endN = des.find( ",", startN+1 ); 788 int endN = des.find( ",", startN+1 );
781 des = des.left( startN ) + des.mid( endN+1 ); 789 des = des.left( startN ) + des.mid( endN+1 );
782 (*it).setNote( des ); 790 (*it).setNote( des );
783 } 791 }
784 } 792 }
785 } 793 }
786 } 794 }
787 } 795 }
788 if ( found ) 796 if ( found )
789 return; 797 return;
790 d->mAddressees.append( a ); 798 d->mAddressees.append( a );
791 Addressee& addr = d->mAddressees.last(); 799 Addressee& addr = d->mAddressees.last();
792 if ( addr.resource() == 0 ) 800 if ( addr.resource() == 0 )
793 addr.setResource( standardResource() ); 801 addr.setResource( standardResource() );
794 802
795 addr.setChanged( true ); 803 addr.setChanged( true );
796} 804}
797 805
798void AddressBook::removeAddressee( const Addressee &a ) 806void AddressBook::removeAddressee( const Addressee &a )
799{ 807{
800 Iterator it; 808 Iterator it;
801 Iterator it2; 809 Iterator it2;
802 bool found = false; 810 bool found = false;
803 for ( it = begin(); it != end(); ++it ) { 811 for ( it = begin(); it != end(); ++it ) {
804 if ( a.uid() == (*it).uid() ) { 812 if ( a.uid() == (*it).uid() ) {
805 found = true; 813 found = true;
806 it2 = it; 814 it2 = it;
807 } else { 815 } else {
808 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 816 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
809 QString name = (*it).uid().mid( 19 ); 817 QString name = (*it).uid().mid( 19 );
810 Addressee b = a; 818 Addressee b = a;
811 QString id = b.getID( name ); 819 QString id = b.getID( name );
812 if ( ! id.isEmpty() ) { 820 if ( ! id.isEmpty() ) {
813 QString des = (*it).note(); 821 QString des = (*it).note();
814 if( des.find( id ) < 0 ) { 822 if( des.find( id ) < 0 ) {
815 des += id + ","; 823 des += id + ",";
816 (*it).setNote( des ); 824 (*it).setNote( des );
817 } 825 }
818 } 826 }
819 } 827 }
820 828
821 } 829 }
822 } 830 }
823 831
824 if ( found ) 832 if ( found )
825 removeAddressee( it2 ); 833 removeAddressee( it2 );
826 834
827} 835}
828 836
829void AddressBook::removeSyncAddressees( bool removeDeleted ) 837void AddressBook::removeSyncAddressees( bool removeDeleted )
830{ 838{
831 Iterator it = begin(); 839 Iterator it = begin();
832 Iterator it2 ; 840 Iterator it2 ;
833 QDateTime dt ( QDate( 2004,1,1) ); 841 QDateTime dt ( QDate( 2004,1,1) );
834 while ( it != end() ) { 842 while ( it != end() ) {
835 (*it).setRevision( dt ); 843 (*it).setRevision( dt );
836 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); 844 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" );
837 (*it).setIDStr(""); 845 (*it).setIDStr("");
838 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { 846 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) {
839 it2 = it; 847 it2 = it;
840 //qDebug("removing %s ",(*it).uid().latin1() ); 848 //qDebug("removing %s ",(*it).uid().latin1() );
841 ++it; 849 ++it;
842 removeAddressee( it2 ); 850 removeAddressee( it2 );
843 } else { 851 } else {
844 //qDebug("skipping %s ",(*it).uid().latin1() ); 852 //qDebug("skipping %s ",(*it).uid().latin1() );
845 ++it; 853 ++it;
846 } 854 }
847 } 855 }
848 deleteRemovedAddressees(); 856 deleteRemovedAddressees();
849} 857}
850 858
851void AddressBook::removeAddressee( const Iterator &it ) 859void AddressBook::removeAddressee( const Iterator &it )
852{ 860{
853 d->mRemovedAddressees.append( (*it) ); 861 d->mRemovedAddressees.append( (*it) );
854 d->mAddressees.remove( it.d->mIt ); 862 d->mAddressees.remove( it.d->mIt );
855} 863}
856 864
857AddressBook::Iterator AddressBook::find( const Addressee &a ) 865AddressBook::Iterator AddressBook::find( const Addressee &a )
858{ 866{
859 Iterator it; 867 Iterator it;
860 for ( it = begin(); it != end(); ++it ) { 868 for ( it = begin(); it != end(); ++it ) {
861 if ( a.uid() == (*it).uid() ) { 869 if ( a.uid() == (*it).uid() ) {
862 return it; 870 return it;
863 } 871 }
864 } 872 }
865 return end(); 873 return end();
866} 874}
867 875
868Addressee AddressBook::findByUid( const QString &uid ) 876Addressee AddressBook::findByUid( const QString &uid )
869{ 877{
870 Iterator it; 878 Iterator it;
871 for ( it = begin(); it != end(); ++it ) { 879 for ( it = begin(); it != end(); ++it ) {
872 if ( uid == (*it).uid() ) { 880 if ( uid == (*it).uid() ) {
873 return *it; 881 return *it;
874 } 882 }
875 } 883 }
876 return Addressee(); 884 return Addressee();
877} 885}
878void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) 886void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset )
879{ 887{
880 //qDebug("AddressBook::preExternSync "); 888 //qDebug("AddressBook::preExternSync ");
881 AddressBook::Iterator it; 889 AddressBook::Iterator it;
882 for ( it = begin(); it != end(); ++it ) { 890 for ( it = begin(); it != end(); ++it ) {
883 (*it).setID( csd, (*it).externalUID() ); 891 (*it).setID( csd, (*it).externalUID() );
884 (*it).computeCsum( csd ); 892 (*it).computeCsum( csd );
885 } 893 }
886 mergeAB( aBook ,csd, isSubset ); 894 mergeAB( aBook ,csd, isSubset );
887} 895}
888void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) 896void AddressBook::postExternSync( AddressBook* aBook , const QString& csd)
889{ 897{
890 //qDebug("AddressBook::postExternSync "); 898 //qDebug("AddressBook::postExternSync ");
891 AddressBook::Iterator it; 899 AddressBook::Iterator it;
892 for ( it = begin(); it != end(); ++it ) { 900 for ( it = begin(); it != end(); ++it ) {
893 // qDebug("check uid %s ", (*it).uid().latin1() ); 901 // qDebug("check uid %s ", (*it).uid().latin1() );
894 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || 902 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ||
895 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { 903 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) {
896 Addressee ad = aBook->findByUid( ( (*it).uid() )); 904 Addressee ad = aBook->findByUid( ( (*it).uid() ));
897 if ( ad.isEmpty() ) { 905 if ( ad.isEmpty() ) {
898 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); 906 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1());
899 } else { 907 } else {
900 (*it).computeCsum( csd ); 908 (*it).computeCsum( csd );
901 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) 909 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID )
902 ad.setID( csd, (*it).externalUID() ); 910 ad.setID( csd, (*it).externalUID() );
903 ad.setCsum( csd, (*it).getCsum( csd ) ); 911 ad.setCsum( csd, (*it).getCsum( csd ) );
904 aBook->insertAddressee( ad ); 912 aBook->insertAddressee( ad );
905 } 913 }
906 } 914 }
907 } 915 }
908} 916}
909 917
910bool AddressBook::containsExternalUid( const QString& uid ) 918bool AddressBook::containsExternalUid( const QString& uid )
911{ 919{
912 Iterator it; 920 Iterator it;
913 for ( it = begin(); it != end(); ++it ) { 921 for ( it = begin(); it != end(); ++it ) {
914 if ( uid == (*it).externalUID( ) ) 922 if ( uid == (*it).externalUID( ) )
915 return true; 923 return true;
916 } 924 }
917 return false; 925 return false;
918} 926}
919Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) 927Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile )
920{ 928{
921 Iterator it; 929 Iterator it;
922 for ( it = begin(); it != end(); ++it ) { 930 for ( it = begin(); it != end(); ++it ) {
923 if ( uid == (*it).getID( profile ) ) 931 if ( uid == (*it).getID( profile ) )
924 return (*it); 932 return (*it);
925 } 933 }
926 return Addressee(); 934 return Addressee();
927} 935}
928void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) 936void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset )
929{ 937{
930 Iterator it; 938 Iterator it;
931 Addressee ad; 939 Addressee ad;
932 for ( it = begin(); it != end(); ++it ) { 940 for ( it = begin(); it != end(); ++it ) {
933 ad = aBook->findByExternUid( (*it).externalUID(), profile ); 941 ad = aBook->findByExternUid( (*it).externalUID(), profile );
934 if ( !ad.isEmpty() ) { 942 if ( !ad.isEmpty() ) {
935 (*it).mergeContact( ad ,isSubset); 943 (*it).mergeContact( ad ,isSubset);
936 } 944 }
937 } 945 }
938#if 0 946#if 0
939 // test only 947 // test only
940 for ( it = begin(); it != end(); ++it ) { 948 for ( it = begin(); it != end(); ++it ) {
941 949
942 qDebug("uid %s ", (*it).uid().latin1()); 950 qDebug("uid %s ", (*it).uid().latin1());
943 } 951 }
944#endif 952#endif
945} 953}
946 954
947#if 0 955#if 0
948Addressee::List AddressBook::getExternLastSyncAddressees() 956Addressee::List AddressBook::getExternLastSyncAddressees()
949{ 957{
950 Addressee::List results; 958 Addressee::List results;
951 959
952 Iterator it; 960 Iterator it;
953 for ( it = begin(); it != end(); ++it ) { 961 for ( it = begin(); it != end(); ++it ) {
954 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { 962 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
955 if ( (*it).familyName().left(4) == "!E: " ) 963 if ( (*it).familyName().left(4) == "!E: " )
956 results.append( *it ); 964 results.append( *it );
957 } 965 }
958 } 966 }
959 967
960 return results; 968 return results;
961} 969}
962#endif 970#endif
963void AddressBook::resetTempSyncStat() 971void AddressBook::resetTempSyncStat()
964{ 972{
965 Iterator it; 973 Iterator it;
966 for ( it = begin(); it != end(); ++it ) { 974 for ( it = begin(); it != end(); ++it ) {
967 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); 975 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
968 } 976 }
969 977
970} 978}
971 979
972QStringList AddressBook:: uidList() 980QStringList AddressBook:: uidList()
973{ 981{
974 QStringList results; 982 QStringList results;
975 Iterator it; 983 Iterator it;
976 for ( it = begin(); it != end(); ++it ) { 984 for ( it = begin(); it != end(); ++it ) {
977 results.append( (*it).uid() ); 985 results.append( (*it).uid() );
978 } 986 }
979 return results; 987 return results;
980} 988}
981 989
982 990
983Addressee::List AddressBook::allAddressees() 991Addressee::List AddressBook::allAddressees()
984{ 992{
985 return d->mAddressees; 993 return d->mAddressees;
986 994
987} 995}
988 996
989Addressee::List AddressBook::findByName( const QString &name ) 997Addressee::List AddressBook::findByName( const QString &name )
990{ 998{
991 Addressee::List results; 999 Addressee::List results;
992 1000
993 Iterator it; 1001 Iterator it;
994 for ( it = begin(); it != end(); ++it ) { 1002 for ( it = begin(); it != end(); ++it ) {
995 if ( name == (*it).realName() ) { 1003 if ( name == (*it).realName() ) {
996 results.append( *it ); 1004 results.append( *it );
997 } 1005 }
998 } 1006 }
999 1007
1000 return results; 1008 return results;
1001} 1009}
1002 1010
1003Addressee::List AddressBook::findByEmail( const QString &email ) 1011Addressee::List AddressBook::findByEmail( const QString &email )
1004{ 1012{
1005 Addressee::List results; 1013 Addressee::List results;
1006 QStringList mailList; 1014 QStringList mailList;
1007 1015
1008 Iterator it; 1016 Iterator it;
1009 for ( it = begin(); it != end(); ++it ) { 1017 for ( it = begin(); it != end(); ++it ) {
1010 mailList = (*it).emails(); 1018 mailList = (*it).emails();
1011 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 1019 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
1012 if ( email == (*ite) ) { 1020 if ( email == (*ite) ) {
1013 results.append( *it ); 1021 results.append( *it );
1014 } 1022 }
1015 } 1023 }
1016 } 1024 }
1017 1025
1018 return results; 1026 return results;
1019} 1027}
1020 1028
1021Addressee::List AddressBook::findByCategory( const QString &category ) 1029Addressee::List AddressBook::findByCategory( const QString &category )
1022{ 1030{
1023 Addressee::List results; 1031 Addressee::List results;
1024 1032
1025 Iterator it; 1033 Iterator it;
1026 for ( it = begin(); it != end(); ++it ) { 1034 for ( it = begin(); it != end(); ++it ) {
1027 if ( (*it).hasCategory( category) ) { 1035 if ( (*it).hasCategory( category) ) {
1028 results.append( *it ); 1036 results.append( *it );
1029 } 1037 }
1030 } 1038 }
1031 1039
1032 return results; 1040 return results;
1033} 1041}
1034 1042
1035void AddressBook::dump() const 1043void AddressBook::dump() const
1036{ 1044{
1037 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; 1045 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
1038 1046
1039 ConstIterator it; 1047 ConstIterator it;
1040 for( it = begin(); it != end(); ++it ) { 1048 for( it = begin(); it != end(); ++it ) {
1041 (*it).dump(); 1049 (*it).dump();
1042 } 1050 }
1043 1051
1044 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; 1052 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
1045} 1053}
1046 1054
1047QString AddressBook::identifier() 1055QString AddressBook::identifier()
1048{ 1056{
1049 QStringList identifier; 1057 QStringList identifier;
1050 1058
1051 1059
1052 KRES::Manager<Resource>::ActiveIterator it; 1060 KRES::Manager<Resource>::ActiveIterator it;
1053 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 1061 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
1054 if ( !(*it)->identifier().isEmpty() ) 1062 if ( !(*it)->identifier().isEmpty() )
1055 identifier.append( (*it)->identifier() ); 1063 identifier.append( (*it)->identifier() );
1056 } 1064 }
1057 1065
1058 return identifier.join( ":" ); 1066 return identifier.join( ":" );
1059} 1067}
1060 1068
1061Field::List AddressBook::fields( int category ) 1069Field::List AddressBook::fields( int category )
1062{ 1070{
1063 if ( d->mAllFields.isEmpty() ) { 1071 if ( d->mAllFields.isEmpty() ) {
1064 d->mAllFields = Field::allFields(); 1072 d->mAllFields = Field::allFields();
1065 } 1073 }
1066 1074
1067 if ( category == Field::All ) return d->mAllFields; 1075 if ( category == Field::All ) return d->mAllFields;
1068 1076
1069 Field::List result; 1077 Field::List result;
1070 Field::List::ConstIterator it; 1078 Field::List::ConstIterator it;
1071 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { 1079 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
1072 if ( (*it)->category() & category ) result.append( *it ); 1080 if ( (*it)->category() & category ) result.append( *it );
1073 } 1081 }
1074 1082
1075 return result; 1083 return result;
1076} 1084}
1077 1085
1078bool AddressBook::addCustomField( const QString &label, int category, 1086bool AddressBook::addCustomField( const QString &label, int category,
1079 const QString &key, const QString &app ) 1087 const QString &key, const QString &app )
1080{ 1088{
1081 if ( d->mAllFields.isEmpty() ) { 1089 if ( d->mAllFields.isEmpty() ) {
1082 d->mAllFields = Field::allFields(); 1090 d->mAllFields = Field::allFields();
1083 } 1091 }
1084//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; 1092//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app;
1085 QString a = app.isNull() ? KGlobal::getAppName() : app; 1093 QString a = app.isNull() ? KGlobal::getAppName() : app;
1086 1094
1087 QString k = key.isNull() ? label : key; 1095 QString k = key.isNull() ? label : key;
1088 1096
1089 Field *field = Field::createCustomField( label, category, k, a ); 1097 Field *field = Field::createCustomField( label, category, k, a );
1090 1098
1091 if ( !field ) return false; 1099 if ( !field ) return false;
1092 1100
1093 d->mAllFields.append( field ); 1101 d->mAllFields.append( field );
1094 1102
1095 return true; 1103 return true;
1096} 1104}
1097 1105
1098QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) 1106QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab )
1099{ 1107{
1100 if (!ab.d) return s; 1108 if (!ab.d) return s;
1101 1109
1102 return s << ab.d->mAddressees; 1110 return s << ab.d->mAddressees;
1103} 1111}
1104 1112
1105QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) 1113QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
1106{ 1114{
1107 if (!ab.d) return s; 1115 if (!ab.d) return s;
1108 1116
1109 s >> ab.d->mAddressees; 1117 s >> ab.d->mAddressees;
1110 1118
1111 return s; 1119 return s;
1112} 1120}
1113 1121
1114bool AddressBook::addResource( Resource *resource ) 1122bool AddressBook::addResource( Resource *resource )
1115{ 1123{
1116 if ( !resource->open() ) { 1124 if ( !resource->open() ) {
1117 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; 1125 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
1118 return false; 1126 return false;
1119 } 1127 }
1120 1128
1121 resource->setAddressBook( this ); 1129 resource->setAddressBook( this );
1122 1130
1123 d->mManager->add( resource ); 1131 d->mManager->add( resource );
1124 return true; 1132 return true;
1125} 1133}
1126 1134
1127bool AddressBook::removeResource( Resource *resource ) 1135bool AddressBook::removeResource( Resource *resource )
1128{ 1136{
1129 resource->close(); 1137 resource->close();
1130 1138
1131 if ( resource == standardResource() ) 1139 if ( resource == standardResource() )
1132 d->mManager->setStandardResource( 0 ); 1140 d->mManager->setStandardResource( 0 );
1133 1141
1134 resource->setAddressBook( 0 ); 1142 resource->setAddressBook( 0 );
1135 1143
1136 d->mManager->remove( resource ); 1144 d->mManager->remove( resource );
1137 return true; 1145 return true;
1138} 1146}
1139 1147
1140QPtrList<Resource> AddressBook::resources() 1148QPtrList<Resource> AddressBook::resources()
1141{ 1149{
1142 QPtrList<Resource> list; 1150 QPtrList<Resource> list;
1143 1151
1144// qDebug("AddressBook::resources() 1"); 1152// qDebug("AddressBook::resources() 1");
1145 1153
1146 KRES::Manager<Resource>::ActiveIterator it; 1154 KRES::Manager<Resource>::ActiveIterator it;
1147 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 1155 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
1148 list.append( *it ); 1156 list.append( *it );
1149 1157
1150 return list; 1158 return list;
1151} 1159}
1152 1160
1153/*US 1161/*US
1154void AddressBook::setErrorHandler( ErrorHandler *handler ) 1162void AddressBook::setErrorHandler( ErrorHandler *handler )
1155{ 1163{
1156 delete d->mErrorHandler; 1164 delete d->mErrorHandler;
1157 d->mErrorHandler = handler; 1165 d->mErrorHandler = handler;
1158} 1166}
1159*/ 1167*/
1160 1168
1161void AddressBook::error( const QString& msg ) 1169void AddressBook::error( const QString& msg )
1162{ 1170{
1163/*US 1171/*US
1164 if ( !d->mErrorHandler ) // create default error handler 1172 if ( !d->mErrorHandler ) // create default error handler
1165 d->mErrorHandler = new ConsoleErrorHandler; 1173 d->mErrorHandler = new ConsoleErrorHandler;
1166 1174
1167 if ( d->mErrorHandler ) 1175 if ( d->mErrorHandler )
1168 d->mErrorHandler->error( msg ); 1176 d->mErrorHandler->error( msg );
1169 else 1177 else
1170 kdError(5700) << "no error handler defined" << endl; 1178 kdError(5700) << "no error handler defined" << endl;
1171*/ 1179*/
1172 kdDebug(5700) << "msg" << endl; 1180 kdDebug(5700) << "msg" << endl;
1173 qDebug(msg); 1181 qDebug(msg);
1174} 1182}
1175 1183
1176void AddressBook::deleteRemovedAddressees() 1184void AddressBook::deleteRemovedAddressees()
1177{ 1185{
1178 Addressee::List::Iterator it; 1186 Addressee::List::Iterator it;
1179 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { 1187 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) {
1180 Resource *resource = (*it).resource(); 1188 Resource *resource = (*it).resource();
1181 if ( resource && !resource->readOnly() && resource->isOpen() ) 1189 if ( resource && !resource->readOnly() && resource->isOpen() )
1182 resource->removeAddressee( *it ); 1190 resource->removeAddressee( *it );
1183 } 1191 }
1184 1192
1185 d->mRemovedAddressees.clear(); 1193 d->mRemovedAddressees.clear();
1186} 1194}
1187 1195
1188void AddressBook::setStandardResource( Resource *resource ) 1196void AddressBook::setStandardResource( Resource *resource )
1189{ 1197{
1190// qDebug("AddressBook::setStandardResource 1"); 1198// qDebug("AddressBook::setStandardResource 1");
1191 d->mManager->setStandardResource( resource ); 1199 d->mManager->setStandardResource( resource );
1192} 1200}
1193 1201
1194Resource *AddressBook::standardResource() 1202Resource *AddressBook::standardResource()
1195{ 1203{
1196 return d->mManager->standardResource(); 1204 return d->mManager->standardResource();
1197} 1205}
1198 1206
1199KRES::Manager<Resource> *AddressBook::resourceManager() 1207KRES::Manager<Resource> *AddressBook::resourceManager()
1200{ 1208{
1201 return d->mManager; 1209 return d->mManager;
1202} 1210}
1203 1211
1204void AddressBook::cleanUp() 1212void AddressBook::cleanUp()
1205{ 1213{
1206 KRES::Manager<Resource>::ActiveIterator it; 1214 KRES::Manager<Resource>::ActiveIterator it;
1207 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 1215 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
1208 if ( !(*it)->readOnly() && (*it)->isOpen() ) 1216 if ( !(*it)->readOnly() && (*it)->isOpen() )
1209 (*it)->cleanUp(); 1217 (*it)->cleanUp();
1210 } 1218 }
1211} 1219}
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 5edca06..f124dc9 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -1,348 +1,349 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#ifndef KABC_ADDRESSBOOK_H 28#ifndef KABC_ADDRESSBOOK_H
29#define KABC_ADDRESSBOOK_H 29#define KABC_ADDRESSBOOK_H
30 30
31#include <qobject.h> 31#include <qobject.h>
32 32
33#include <kresources/manager.h> 33#include <kresources/manager.h>
34#include <qptrlist.h> 34#include <qptrlist.h>
35 35
36#include "addressee.h" 36#include "addressee.h"
37#include "field.h" 37#include "field.h"
38 38
39namespace KABC { 39namespace KABC {
40 40
41class ErrorHandler; 41class ErrorHandler;
42class Resource; 42class Resource;
43class Ticket; 43class Ticket;
44 44
45/** 45/**
46 @short Address Book 46 @short Address Book
47 47
48 This class provides access to a collection of address book entries. 48 This class provides access to a collection of address book entries.
49*/ 49*/
50class AddressBook : public QObject 50class AddressBook : public QObject
51{ 51{
52 Q_OBJECT 52 Q_OBJECT
53 53
54 friend QDataStream &operator<<( QDataStream &, const AddressBook & ); 54 friend QDataStream &operator<<( QDataStream &, const AddressBook & );
55 friend QDataStream &operator>>( QDataStream &, AddressBook & ); 55 friend QDataStream &operator>>( QDataStream &, AddressBook & );
56 friend class StdAddressBook; 56 friend class StdAddressBook;
57 57
58 public: 58 public:
59 /** 59 /**
60 @short Address Book Iterator 60 @short Address Book Iterator
61 61
62 This class provides an iterator for address book entries. 62 This class provides an iterator for address book entries.
63 */ 63 */
64 class Iterator 64 class Iterator
65 { 65 {
66 public: 66 public:
67 Iterator(); 67 Iterator();
68 Iterator( const Iterator & ); 68 Iterator( const Iterator & );
69 ~Iterator(); 69 ~Iterator();
70 70
71 Iterator &operator=( const Iterator & ); 71 Iterator &operator=( const Iterator & );
72 const Addressee &operator*() const; 72 const Addressee &operator*() const;
73 Addressee &operator*(); 73 Addressee &operator*();
74 Addressee* operator->(); 74 Addressee* operator->();
75 Iterator &operator++(); 75 Iterator &operator++();
76 Iterator &operator++(int); 76 Iterator &operator++(int);
77 Iterator &operator--(); 77 Iterator &operator--();
78 Iterator &operator--(int); 78 Iterator &operator--(int);
79 bool operator==( const Iterator &it ); 79 bool operator==( const Iterator &it );
80 bool operator!=( const Iterator &it ); 80 bool operator!=( const Iterator &it );
81 81
82 struct IteratorData; 82 struct IteratorData;
83 IteratorData *d; 83 IteratorData *d;
84 }; 84 };
85 85
86 /** 86 /**
87 @short Address Book Const Iterator 87 @short Address Book Const Iterator
88 88
89 This class provides a const iterator for address book entries. 89 This class provides a const iterator for address book entries.
90 */ 90 */
91 class ConstIterator 91 class ConstIterator
92 { 92 {
93 public: 93 public:
94 ConstIterator(); 94 ConstIterator();
95 ConstIterator( const ConstIterator & ); 95 ConstIterator( const ConstIterator & );
96 ~ConstIterator(); 96 ~ConstIterator();
97 97
98 ConstIterator &operator=( const ConstIterator & ); 98 ConstIterator &operator=( const ConstIterator & );
99 const Addressee &operator*() const; 99 const Addressee &operator*() const;
100 const Addressee* operator->() const; 100 const Addressee* operator->() const;
101 ConstIterator &operator++(); 101 ConstIterator &operator++();
102 ConstIterator &operator++(int); 102 ConstIterator &operator++(int);
103 ConstIterator &operator--(); 103 ConstIterator &operator--();
104 ConstIterator &operator--(int); 104 ConstIterator &operator--(int);
105 bool operator==( const ConstIterator &it ); 105 bool operator==( const ConstIterator &it );
106 bool operator!=( const ConstIterator &it ); 106 bool operator!=( const ConstIterator &it );
107 107
108 struct ConstIteratorData; 108 struct ConstIteratorData;
109 ConstIteratorData *d; 109 ConstIteratorData *d;
110 }; 110 };
111 111
112 /** 112 /**
113 Constructs a address book object. 113 Constructs a address book object.
114 114
115 @param format File format class. 115 @param format File format class.
116 */ 116 */
117 AddressBook(); 117 AddressBook();
118 AddressBook( const QString &config ); 118 AddressBook( const QString &config );
119 AddressBook( const QString &config, const QString &family ); 119 AddressBook( const QString &config, const QString &family );
120 virtual ~AddressBook(); 120 virtual ~AddressBook();
121 121
122 /** 122 /**
123 Requests a ticket for saving the addressbook. Calling this function locks 123 Requests a ticket for saving the addressbook. Calling this function locks
124 the addressbook for all other processes. If the address book is already 124 the addressbook for all other processes. If the address book is already
125 locked the function returns 0. You need the returned @ref Ticket object 125 locked the function returns 0. You need the returned @ref Ticket object
126 for calling the @ref save() function. 126 for calling the @ref save() function.
127 127
128 @see save() 128 @see save()
129 */ 129 */
130 Ticket *requestSaveTicket( Resource *resource=0 ); 130 Ticket *requestSaveTicket( Resource *resource=0 );
131 131
132 /** 132 /**
133 Load address book from file. 133 Load address book from file.
134 */ 134 */
135 bool load(); 135 bool load();
136 136
137 /** 137 /**
138 Save address book. The address book is saved to the file, the Ticket 138 Save address book. The address book is saved to the file, the Ticket
139 object has been requested for by @ref requestSaveTicket(). 139 object has been requested for by @ref requestSaveTicket().
140 140
141 @param ticket a ticket object returned by @ref requestSaveTicket() 141 @param ticket a ticket object returned by @ref requestSaveTicket()
142 */ 142 */
143 bool save( Ticket *ticket ); 143 bool save( Ticket *ticket );
144 bool saveAB( ); 144 bool saveAB( );
145 bool saveABphone( QString fileName ); 145 bool saveABphone( QString fileName );
146 void smplifyAddressees(); 146 void smplifyAddressees();
147 void removeSyncInfo( QString syncProfile);
147 void preparePhoneSync( QString currentSyncDevice, bool isPreSync ); 148 void preparePhoneSync( QString currentSyncDevice, bool isPreSync );
148 void export2File( QString fileName ); 149 void export2File( QString fileName );
149 bool export2PhoneFormat( QStringList uids ,QString fileName ); 150 bool export2PhoneFormat( QStringList uids ,QString fileName );
150 int importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); 151 int importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false );
151 void setUntagged( bool setNonSyncTagged = false ); 152 void setUntagged( bool setNonSyncTagged = false );
152 void removeUntagged(); 153 void removeUntagged();
153 void findNewExtIds( QString fileName, QString currentSyncDevice ); 154 void findNewExtIds( QString fileName, QString currentSyncDevice );
154 /** 155 /**
155 Returns a iterator for first entry of address book. 156 Returns a iterator for first entry of address book.
156 */ 157 */
157 Iterator begin(); 158 Iterator begin();
158 159
159 /** 160 /**
160 Returns a const iterator for first entry of address book. 161 Returns a const iterator for first entry of address book.
161 */ 162 */
162 ConstIterator begin() const; 163 ConstIterator begin() const;
163 164
164 /** 165 /**
165 Returns a iterator for first entry of address book. 166 Returns a iterator for first entry of address book.
166 */ 167 */
167 Iterator end(); 168 Iterator end();
168 169
169 /** 170 /**
170 Returns a const iterator for first entry of address book. 171 Returns a const iterator for first entry of address book.
171 */ 172 */
172 ConstIterator end() const; 173 ConstIterator end() const;
173 174
174 /** 175 /**
175 Removes all entries from address book. 176 Removes all entries from address book.
176 */ 177 */
177 void clear(); 178 void clear();
178 179
179 /** 180 /**
180 Insert an Addressee object into address book. If an object with the same 181 Insert an Addressee object into address book. If an object with the same
181 unique id already exists in the address book it it replaced by the new 182 unique id already exists in the address book it it replaced by the new
182 one. If not the new object is appended to the address book. 183 one. If not the new object is appended to the address book.
183 */ 184 */
184 void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); 185 void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
185 186
186 /** 187 /**
187 Removes entry from the address book. 188 Removes entry from the address book.
188 */ 189 */
189 void removeAddressee( const Addressee & ); 190 void removeAddressee( const Addressee & );
190 191
191 /** 192 /**
192 This is like @ref removeAddressee() just above, with the difference that 193 This is like @ref removeAddressee() just above, with the difference that
193 the first element is a iterator, returned by @ref begin(). 194 the first element is a iterator, returned by @ref begin().
194 */ 195 */
195 void removeAddressee( const Iterator & ); 196 void removeAddressee( const Iterator & );
196 197
197 /** 198 /**
198 Find the specified entry in address book. Returns end(), if the entry 199 Find the specified entry in address book. Returns end(), if the entry
199 couldn't be found. 200 couldn't be found.
200 */ 201 */
201 Iterator find( const Addressee & ); 202 Iterator find( const Addressee & );
202 203
203 /** 204 /**
204 Find the entry specified by an unique id. Returns an empty Addressee 205 Find the entry specified by an unique id. Returns an empty Addressee
205 object, if the address book does not contain an entry with this id. 206 object, if the address book does not contain an entry with this id.
206 */ 207 */
207 Addressee findByUid( const QString & ); 208 Addressee findByUid( const QString & );
208 209
209 210
210 /** 211 /**
211 Returns a list of all addressees in the address book. This list can 212 Returns a list of all addressees in the address book. This list can
212 be sorted with @ref KABC::AddresseeList for example. 213 be sorted with @ref KABC::AddresseeList for example.
213 */ 214 */
214 Addressee::List allAddressees(); 215 Addressee::List allAddressees();
215 216
216 /** 217 /**
217 Find all entries with the specified name in the address book. Returns 218 Find all entries with the specified name in the address book. Returns
218 an empty list, if no entries could be found. 219 an empty list, if no entries could be found.
219 */ 220 */
220 Addressee::List findByName( const QString & ); 221 Addressee::List findByName( const QString & );
221 222
222 /** 223 /**
223 Find all entries with the specified email address in the address book. 224 Find all entries with the specified email address in the address book.
224 Returns an empty list, if no entries could be found. 225 Returns an empty list, if no entries could be found.
225 */ 226 */
226 Addressee::List findByEmail( const QString & ); 227 Addressee::List findByEmail( const QString & );
227 228
228 /** 229 /**
229 Find all entries wich have the specified category in the address book. 230 Find all entries wich have the specified category in the address book.
230 Returns an empty list, if no entries could be found. 231 Returns an empty list, if no entries could be found.
231 */ 232 */
232 Addressee::List findByCategory( const QString & ); 233 Addressee::List findByCategory( const QString & );
233 234
234 /** 235 /**
235 Return a string identifying this addressbook. 236 Return a string identifying this addressbook.
236 */ 237 */
237 virtual QString identifier(); 238 virtual QString identifier();
238 239
239 /** 240 /**
240 Used for debug output. 241 Used for debug output.
241 */ 242 */
242 void dump() const; 243 void dump() const;
243 244
244 void emitAddressBookLocked() { emit addressBookLocked( this ); } 245 void emitAddressBookLocked() { emit addressBookLocked( this ); }
245 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } 246 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); }
246 void emitAddressBookChanged() { emit addressBookChanged( this ); } 247 void emitAddressBookChanged() { emit addressBookChanged( this ); }
247 248
248 /** 249 /**
249 Return list of all Fields known to the address book which are associated 250 Return list of all Fields known to the address book which are associated
250 with the given field category. 251 with the given field category.
251 */ 252 */
252 Field::List fields( int category = Field::All ); 253 Field::List fields( int category = Field::All );
253 254
254 /** 255 /**
255 Add custom field to address book. 256 Add custom field to address book.
256 257
257 @param label User visible label of the field. 258 @param label User visible label of the field.
258 @param category Ored list of field categories. 259 @param category Ored list of field categories.
259 @param key Identifier used as key for reading and writing the field. 260 @param key Identifier used as key for reading and writing the field.
260 @param app String used as application key for reading and writing 261 @param app String used as application key for reading and writing
261 the field. 262 the field.
262 */ 263 */
263 bool addCustomField( const QString &label, int category = Field::All, 264 bool addCustomField( const QString &label, int category = Field::All,
264 const QString &key = QString::null, 265 const QString &key = QString::null,
265 const QString &app = QString::null ); 266 const QString &app = QString::null );
266 267
267 268
268 /** 269 /**
269 Add address book resource. 270 Add address book resource.
270 */ 271 */
271 bool addResource( Resource * ); 272 bool addResource( Resource * );
272 273
273 /** 274 /**
274 Remove address book resource. 275 Remove address book resource.
275 */ 276 */
276 bool removeResource( Resource * ); 277 bool removeResource( Resource * );
277 278
278 /** 279 /**
279 Return pointer list of all resources. 280 Return pointer list of all resources.
280 */ 281 */
281 QPtrList<Resource> resources(); 282 QPtrList<Resource> resources();
282 283
283 /** 284 /**
284 Set the @p ErrorHandler, that is used by @ref error() to 285 Set the @p ErrorHandler, that is used by @ref error() to
285 provide gui-independend error messages. 286 provide gui-independend error messages.
286 */ 287 */
287 void setErrorHandler( ErrorHandler * ); 288 void setErrorHandler( ErrorHandler * );
288 289
289 /** 290 /**
290 Shows gui independend error messages. 291 Shows gui independend error messages.
291 */ 292 */
292 void error( const QString& ); 293 void error( const QString& );
293 294
294 /** 295 /**
295 Query all resources to clean up their lock files 296 Query all resources to clean up their lock files
296 */ 297 */
297 void cleanUp(); 298 void cleanUp();
298 299
299 // sync stuff 300 // sync stuff
300 //Addressee::List getExternLastSyncAddressees(); 301 //Addressee::List getExternLastSyncAddressees();
301 void resetTempSyncStat(); 302 void resetTempSyncStat();
302 QStringList uidList(); 303 QStringList uidList();
303 void removeSyncAddressees( bool removeDeleted = false ); 304 void removeSyncAddressees( bool removeDeleted = false );
304 void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset ); 305 void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset );
305 Addressee findByExternUid( const QString& uid , const QString& profile ); 306 Addressee findByExternUid( const QString& uid , const QString& profile );
306 bool containsExternalUid( const QString& uid ); 307 bool containsExternalUid( const QString& uid );
307 308
308 void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset ); 309 void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset );
309 void postExternSync( AddressBook* aBook, const QString& csd ); 310 void postExternSync( AddressBook* aBook, const QString& csd );
310 signals: 311 signals:
311 /** 312 /**
312 Emitted, when the address book has changed on disk. 313 Emitted, when the address book has changed on disk.
313 */ 314 */
314 void addressBookChanged( AddressBook * ); 315 void addressBookChanged( AddressBook * );
315 316
316 /** 317 /**
317 Emitted, when the address book has been locked for writing. 318 Emitted, when the address book has been locked for writing.
318 */ 319 */
319 void addressBookLocked( AddressBook * ); 320 void addressBookLocked( AddressBook * );
320 321
321 /** 322 /**
322 Emitted, when the address book has been unlocked. 323 Emitted, when the address book has been unlocked.
323 */ 324 */
324 void addressBookUnlocked( AddressBook * ); 325 void addressBookUnlocked( AddressBook * );
325 326
326 protected: 327 protected:
327 void deleteRemovedAddressees(); 328 void deleteRemovedAddressees();
328 void setStandardResource( Resource * ); 329 void setStandardResource( Resource * );
329 Resource *standardResource(); 330 Resource *standardResource();
330 KRES::Manager<Resource> *resourceManager(); 331 KRES::Manager<Resource> *resourceManager();
331 332
332 void init(const QString &config, const QString &family); 333 void init(const QString &config, const QString &family);
333 334
334 private: 335 private:
335//US QPtrList<Resource> mDummy; // Remove in KDE 4 336//US QPtrList<Resource> mDummy; // Remove in KDE 4
336 337
337 338
338 struct AddressBookData; 339 struct AddressBookData;
339 AddressBookData *d; 340 AddressBookData *d;
340 bool blockLSEchange; 341 bool blockLSEchange;
341}; 342};
342 343
343QDataStream &operator<<( QDataStream &, const AddressBook & ); 344QDataStream &operator<<( QDataStream &, const AddressBook & );
344QDataStream &operator>>( QDataStream &, AddressBook & ); 345QDataStream &operator>>( QDataStream &, AddressBook & );
345 346
346} 347}
347 348
348#endif 349#endif
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 40877ef..a660a9d 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -1,2092 +1,2095 @@
1/*** Warning! This file has been generated by the script makeaddressee ***/ 1/*** Warning! This file has been generated by the script makeaddressee ***/
2/* 2/*
3 This file is part of libkabc. 3 This file is part of libkabc.
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22/* 22/*
23Enhanced Version of the file for platform independent KDE tools. 23Enhanced Version of the file for platform independent KDE tools.
24Copyright (c) 2004 Ulf Schenk 24Copyright (c) 2004 Ulf Schenk
25 25
26$Id$ 26$Id$
27*/ 27*/
28 28
29#include <kconfig.h> 29#include <kconfig.h>
30 30
31#include <ksharedptr.h> 31#include <ksharedptr.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <kapplication.h> 33#include <kapplication.h>
34#include <klocale.h> 34#include <klocale.h>
35#include <kidmanager.h> 35#include <kidmanager.h>
36//US 36//US
37#include <kstandarddirs.h> 37#include <kstandarddirs.h>
38#include <libkcal/syncdefines.h> 38#include <libkcal/syncdefines.h>
39 39
40//US #include "resource.h" 40//US #include "resource.h"
41#include "addressee.h" 41#include "addressee.h"
42 42
43using namespace KABC; 43using namespace KABC;
44 44
45static bool matchBinaryPattern( int value, int pattern ); 45static bool matchBinaryPattern( int value, int pattern );
46static bool matchBinaryPatternA( int value, int pattern ); 46static bool matchBinaryPatternA( int value, int pattern );
47static bool matchBinaryPatternP( int value, int pattern ); 47static bool matchBinaryPatternP( int value, int pattern );
48 48
49struct Addressee::AddresseeData : public KShared 49struct Addressee::AddresseeData : public KShared
50{ 50{
51 QString uid; 51 QString uid;
52 QString name; 52 QString name;
53 QString formattedName; 53 QString formattedName;
54 QString familyName; 54 QString familyName;
55 QString givenName; 55 QString givenName;
56 QString additionalName; 56 QString additionalName;
57 QString prefix; 57 QString prefix;
58 QString suffix; 58 QString suffix;
59 QString nickName; 59 QString nickName;
60 QDateTime birthday; 60 QDateTime birthday;
61 QString mailer; 61 QString mailer;
62 TimeZone timeZone; 62 TimeZone timeZone;
63 Geo geo; 63 Geo geo;
64 QString title; 64 QString title;
65 QString role; 65 QString role;
66 QString organization; 66 QString organization;
67 QString note; 67 QString note;
68 QString productId; 68 QString productId;
69 QDateTime revision; 69 QDateTime revision;
70 QString sortString; 70 QString sortString;
71 QString externalUID; 71 QString externalUID;
72 QString originalExternalUID; 72 QString originalExternalUID;
73 KURL url; 73 KURL url;
74 Secrecy secrecy; 74 Secrecy secrecy;
75 Picture logo; 75 Picture logo;
76 Picture photo; 76 Picture photo;
77 Sound sound; 77 Sound sound;
78 Agent agent; 78 Agent agent;
79 QString mExternalId; 79 QString mExternalId;
80 PhoneNumber::List phoneNumbers; 80 PhoneNumber::List phoneNumbers;
81 Address::List addresses; 81 Address::List addresses;
82 Key::List keys; 82 Key::List keys;
83 QStringList emails; 83 QStringList emails;
84 QStringList categories; 84 QStringList categories;
85 QStringList custom; 85 QStringList custom;
86 int mTempSyncStat; 86 int mTempSyncStat;
87 Resource *resource; 87 Resource *resource;
88 88
89 bool empty :1; 89 bool empty :1;
90 bool changed :1; 90 bool changed :1;
91 bool tagged :1; 91 bool tagged :1;
92}; 92};
93 93
94Addressee::Addressee() 94Addressee::Addressee()
95{ 95{
96 mData = new AddresseeData; 96 mData = new AddresseeData;
97 mData->empty = true; 97 mData->empty = true;
98 mData->changed = false; 98 mData->changed = false;
99 mData->resource = 0; 99 mData->resource = 0;
100 mData->mExternalId = ":"; 100 mData->mExternalId = ":";
101 mData->revision = QDateTime ( QDate( 2003,1,1)); 101 mData->revision = QDateTime ( QDate( 2003,1,1));
102 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 102 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
103} 103}
104 104
105Addressee::~Addressee() 105Addressee::~Addressee()
106{ 106{
107} 107}
108 108
109Addressee::Addressee( const Addressee &a ) 109Addressee::Addressee( const Addressee &a )
110{ 110{
111 mData = a.mData; 111 mData = a.mData;
112} 112}
113 113
114Addressee &Addressee::operator=( const Addressee &a ) 114Addressee &Addressee::operator=( const Addressee &a )
115{ 115{
116 mData = a.mData; 116 mData = a.mData;
117 return (*this); 117 return (*this);
118} 118}
119 119
120Addressee Addressee::copy() 120Addressee Addressee::copy()
121{ 121{
122 Addressee a; 122 Addressee a;
123 *(a.mData) = *mData; 123 *(a.mData) = *mData;
124 return a; 124 return a;
125} 125}
126 126
127void Addressee::detach() 127void Addressee::detach()
128{ 128{
129 if ( mData.count() == 1 ) return; 129 if ( mData.count() == 1 ) return;
130 *this = copy(); 130 *this = copy();
131} 131}
132 132
133bool Addressee::operator==( const Addressee &a ) const 133bool Addressee::operator==( const Addressee &a ) const
134{ 134{
135 if ( uid() != a.uid() ) return false; 135 if ( uid() != a.uid() ) return false;
136 if ( mData->name != a.mData->name ) return false; 136 if ( mData->name != a.mData->name ) return false;
137 if ( mData->formattedName != a.mData->formattedName ) return false; 137 if ( mData->formattedName != a.mData->formattedName ) return false;
138 if ( mData->familyName != a.mData->familyName ) return false; 138 if ( mData->familyName != a.mData->familyName ) return false;
139 if ( mData->givenName != a.mData->givenName ) return false; 139 if ( mData->givenName != a.mData->givenName ) return false;
140 if ( mData->additionalName != a.mData->additionalName ) return false; 140 if ( mData->additionalName != a.mData->additionalName ) return false;
141 if ( mData->prefix != a.mData->prefix ) return false; 141 if ( mData->prefix != a.mData->prefix ) return false;
142 if ( mData->suffix != a.mData->suffix ) return false; 142 if ( mData->suffix != a.mData->suffix ) return false;
143 if ( mData->nickName != a.mData->nickName ) return false; 143 if ( mData->nickName != a.mData->nickName ) return false;
144 if ( mData->birthday != a.mData->birthday ) return false; 144 if ( mData->birthday != a.mData->birthday ) return false;
145 if ( mData->mailer != a.mData->mailer ) return false; 145 if ( mData->mailer != a.mData->mailer ) return false;
146 if ( mData->timeZone != a.mData->timeZone ) return false; 146 if ( mData->timeZone != a.mData->timeZone ) return false;
147 if ( mData->geo != a.mData->geo ) return false; 147 if ( mData->geo != a.mData->geo ) return false;
148 if ( mData->title != a.mData->title ) return false; 148 if ( mData->title != a.mData->title ) return false;
149 if ( mData->role != a.mData->role ) return false; 149 if ( mData->role != a.mData->role ) return false;
150 if ( mData->organization != a.mData->organization ) return false; 150 if ( mData->organization != a.mData->organization ) return false;
151 if ( mData->note != a.mData->note ) return false; 151 if ( mData->note != a.mData->note ) return false;
152 if ( mData->productId != a.mData->productId ) return false; 152 if ( mData->productId != a.mData->productId ) return false;
153 //if ( mData->revision != a.mData->revision ) return false; 153 //if ( mData->revision != a.mData->revision ) return false;
154 if ( mData->sortString != a.mData->sortString ) return false; 154 if ( mData->sortString != a.mData->sortString ) return false;
155 if ( mData->secrecy != a.mData->secrecy ) return false; 155 if ( mData->secrecy != a.mData->secrecy ) return false;
156 if ( mData->logo != a.mData->logo ) return false; 156 if ( mData->logo != a.mData->logo ) return false;
157 if ( mData->photo != a.mData->photo ) return false; 157 if ( mData->photo != a.mData->photo ) return false;
158 if ( mData->sound != a.mData->sound ) return false; 158 if ( mData->sound != a.mData->sound ) return false;
159 if ( mData->agent != a.mData->agent ) return false; 159 if ( mData->agent != a.mData->agent ) return false;
160 if ( ( mData->url.isValid() || a.mData->url.isValid() ) && 160 if ( ( mData->url.isValid() || a.mData->url.isValid() ) &&
161 ( mData->url != a.mData->url ) ) return false; 161 ( mData->url != a.mData->url ) ) return false;
162 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; 162 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false;
163 if ( mData->addresses != a.mData->addresses ) return false; 163 if ( mData->addresses != a.mData->addresses ) return false;
164 if ( mData->keys != a.mData->keys ) return false; 164 if ( mData->keys != a.mData->keys ) return false;
165 if ( mData->emails != a.mData->emails ) return false; 165 if ( mData->emails != a.mData->emails ) return false;
166 if ( mData->categories != a.mData->categories ) return false; 166 if ( mData->categories != a.mData->categories ) return false;
167 if ( mData->custom != a.mData->custom ) return false; 167 if ( mData->custom != a.mData->custom ) return false;
168 168
169 return true; 169 return true;
170} 170}
171 171
172bool Addressee::operator!=( const Addressee &a ) const 172bool Addressee::operator!=( const Addressee &a ) const
173{ 173{
174 return !( a == *this ); 174 return !( a == *this );
175} 175}
176 176
177bool Addressee::isEmpty() const 177bool Addressee::isEmpty() const
178{ 178{
179 return mData->empty; 179 return mData->empty;
180} 180}
181ulong Addressee::getCsum4List( const QStringList & attList) 181ulong Addressee::getCsum4List( const QStringList & attList)
182{ 182{
183 int max = attList.count(); 183 int max = attList.count();
184 ulong cSum = 0; 184 ulong cSum = 0;
185 int j,k,i; 185 int j,k,i;
186 int add; 186 int add;
187 for ( i = 0; i < max ; ++i ) { 187 for ( i = 0; i < max ; ++i ) {
188 QString s = attList[i]; 188 QString s = attList[i];
189 if ( ! s.isEmpty() ){ 189 if ( ! s.isEmpty() ){
190 j = s.length(); 190 j = s.length();
191 for ( k = 0; k < j; ++k ) { 191 for ( k = 0; k < j; ++k ) {
192 int mul = k +1; 192 int mul = k +1;
193 add = s[k].unicode (); 193 add = s[k].unicode ();
194 if ( k < 16 ) 194 if ( k < 16 )
195 mul = mul * mul; 195 mul = mul * mul;
196 int ii = i+1; 196 int ii = i+1;
197 add = add * mul *ii*ii*ii; 197 add = add * mul *ii*ii*ii;
198 cSum += add; 198 cSum += add;
199 } 199 }
200 } 200 }
201 201
202 } 202 }
203 //QString dump = attList.join(","); 203 //QString dump = attList.join(",");
204 //qDebug("csum: %d %s", cSum,dump.latin1()); 204 //qDebug("csum: %d %s", cSum,dump.latin1());
205 205
206 return cSum; 206 return cSum;
207 207
208} 208}
209void Addressee::computeCsum(const QString &dev) 209void Addressee::computeCsum(const QString &dev)
210{ 210{
211 QStringList l; 211 QStringList l;
212 if ( !mData->name.isEmpty() ) l.append(mData->name); 212 if ( !mData->name.isEmpty() ) l.append(mData->name);
213 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); 213 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName );
214 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); 214 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName );
215 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); 215 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName );
216 if ( !mData->additionalName ) l.append( mData->additionalName ); 216 if ( !mData->additionalName ) l.append( mData->additionalName );
217 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); 217 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix );
218 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); 218 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix );
219 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); 219 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName );
220 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); 220 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() );
221 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); 221 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer );
222 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); 222 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() );
223 if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); 223 if ( mData->geo.isValid() ) l.append( mData->geo.asString() );
224 if ( !mData->title .isEmpty() ) l.append( mData->title ); 224 if ( !mData->title .isEmpty() ) l.append( mData->title );
225 if ( !mData->role.isEmpty() ) l.append( mData->role ); 225 if ( !mData->role.isEmpty() ) l.append( mData->role );
226 if ( !mData->organization.isEmpty() ) l.append( mData->organization ); 226 if ( !mData->organization.isEmpty() ) l.append( mData->organization );
227 if ( !mData->note.isEmpty() ) l.append( mData->note ); 227 if ( !mData->note.isEmpty() ) l.append( mData->note );
228 if ( !mData->productId.isEmpty() ) l.append(mData->productId ); 228 if ( !mData->productId.isEmpty() ) l.append(mData->productId );
229 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); 229 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString );
230 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); 230 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString());
231 // if ( !mData->logo.isEmpty() ) l.append( ); 231 // if ( !mData->logo.isEmpty() ) l.append( );
232 //if ( !mData->photo.isEmpty() ) l.append( ); 232 //if ( !mData->photo.isEmpty() ) l.append( );
233 //if ( !mData->sound.isEmpty() ) l.append( ); 233 //if ( !mData->sound.isEmpty() ) l.append( );
234 //if ( !mData->agent.isEmpty() ) l.append( ); 234 //if ( !mData->agent.isEmpty() ) l.append( );
235 if ( mData->url.isValid() ) 235 if ( mData->url.isValid() )
236 if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() ); 236 if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() );
237 KABC::PhoneNumber::List phoneNumbers; 237 KABC::PhoneNumber::List phoneNumbers;
238 KABC::PhoneNumber::List::Iterator phoneIter; 238 KABC::PhoneNumber::List::Iterator phoneIter;
239 239
240 QStringList t; 240 QStringList t;
241 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 241 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
242 ++phoneIter ) 242 ++phoneIter )
243 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); 243 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) );
244 t.sort(); 244 t.sort();
245 uint iii; 245 uint iii;
246 for ( iii = 0; iii < t.count(); ++iii) 246 for ( iii = 0; iii < t.count(); ++iii)
247 l.append( t[iii] ); 247 l.append( t[iii] );
248 t = mData->emails; 248 t = mData->emails;
249 t.sort(); 249 t.sort();
250 for ( iii = 0; iii < t.count(); ++iii) 250 for ( iii = 0; iii < t.count(); ++iii)
251 l.append( t[iii] ); 251 l.append( t[iii] );
252 t = mData->categories; 252 t = mData->categories;
253 t.sort(); 253 t.sort();
254 for ( iii = 0; iii < t.count(); ++iii) 254 for ( iii = 0; iii < t.count(); ++iii)
255 l.append( t[iii] ); 255 l.append( t[iii] );
256 t = mData->custom; 256 t = mData->custom;
257 t.sort(); 257 t.sort();
258 for ( iii = 0; iii < t.count(); ++iii) 258 for ( iii = 0; iii < t.count(); ++iii)
259 l.append( t[iii] ); 259 l.append( t[iii] );
260 KABC::Address::List::Iterator addressIter; 260 KABC::Address::List::Iterator addressIter;
261 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 261 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
262 ++addressIter ) { 262 ++addressIter ) {
263 t = (*addressIter).asList(); 263 t = (*addressIter).asList();
264 t.sort(); 264 t.sort();
265 for ( iii = 0; iii < t.count(); ++iii) 265 for ( iii = 0; iii < t.count(); ++iii)
266 l.append( t[iii] ); 266 l.append( t[iii] );
267 } 267 }
268 uint cs = getCsum4List(l); 268 uint cs = getCsum4List(l);
269 // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); 269 // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() );
270 setCsum( dev, QString::number (cs )); 270 setCsum( dev, QString::number (cs ));
271} 271}
272 272
273void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) 273void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false)
274{ 274{
275 275
276 detach(); 276 detach();
277 if ( mData->name.isEmpty() ) mData->name = ad.mData->name; 277 if ( mData->name.isEmpty() ) mData->name = ad.mData->name;
278 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; 278 if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName;
279 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; 279 if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName;
280 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; 280 if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ;
281 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; 281 if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName;
282 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; 282 if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix;
283 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; 283 if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix;
284 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; 284 if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName;
285 if ( !mData->birthday.isValid() ) 285 if ( !mData->birthday.isValid() )
286 if ( ad.mData->birthday.isValid()) 286 if ( ad.mData->birthday.isValid())
287 mData->birthday = ad.mData->birthday; 287 mData->birthday = ad.mData->birthday;
288 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; 288 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer;
289 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; 289 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone;
290 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; 290 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo;
291 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; 291 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ;
292 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; 292 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ;
293 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; 293 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ;
294 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; 294 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ;
295 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; 295 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId;
296 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; 296 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString;
297 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; 297 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy;
298 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; 298 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ;
299 QStringList t; 299 QStringList t;
300 QStringList tAD; 300 QStringList tAD;
301 uint iii; 301 uint iii;
302 302
303 // ********** phone numbers 303 // ********** phone numbers
304 PhoneNumber::List phoneAD = ad.phoneNumbers(); 304 PhoneNumber::List phoneAD = ad.phoneNumbers();
305 PhoneNumber::List::Iterator phoneItAD; 305 PhoneNumber::List::Iterator phoneItAD;
306 for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { 306 for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) {
307 bool found = false; 307 bool found = false;
308 PhoneNumber::List::Iterator it; 308 PhoneNumber::List::Iterator it;
309 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 309 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
310 if ( ( *phoneItAD ).contains( (*it) ) ) { 310 if ( ( *phoneItAD ).contains( (*it) ) ) {
311 found = true; 311 found = true;
312 (*it).setType( ( *phoneItAD ).type() ); 312 (*it).setType( ( *phoneItAD ).type() );
313 (*it).setNumber( ( *phoneItAD ).number() ); 313 (*it).setNumber( ( *phoneItAD ).number() );
314 break; 314 break;
315 } 315 }
316 } 316 }
317 if ( isSubSet && ! found ) 317 if ( isSubSet && ! found )
318 mData->phoneNumbers.append( *phoneItAD ); 318 mData->phoneNumbers.append( *phoneItAD );
319 } 319 }
320 if ( isSubSet ) { 320 if ( isSubSet ) {
321 // ************* emails; 321 // ************* emails;
322 t = mData->emails; 322 t = mData->emails;
323 tAD = ad.mData->emails; 323 tAD = ad.mData->emails;
324 for ( iii = 0; iii < tAD.count(); ++iii) 324 for ( iii = 0; iii < tAD.count(); ++iii)
325 if ( !t.contains(tAD[iii] ) ) 325 if ( !t.contains(tAD[iii] ) )
326 mData->emails.append( tAD[iii] ); 326 mData->emails.append( tAD[iii] );
327 } 327 }
328 328
329 // ************* categories; 329 // ************* categories;
330 t = mData->categories; 330 t = mData->categories;
331 tAD = ad.mData->categories; 331 tAD = ad.mData->categories;
332 for ( iii = 0; iii < tAD.count(); ++iii) 332 for ( iii = 0; iii < tAD.count(); ++iii)
333 if ( !t.contains(tAD[iii] ) ) 333 if ( !t.contains(tAD[iii] ) )
334 mData->categories.append( tAD[iii] ); 334 mData->categories.append( tAD[iii] );
335 QStringList::ConstIterator it; 335 QStringList::ConstIterator it;
336 for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { 336 for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) {
337 QString qualifiedName = (*it).left( (*it).find( ":" )); 337 QString qualifiedName = (*it).left( (*it).find( ":" ));
338 bool found = false; 338 bool found = false;
339 QStringList::ConstIterator itL; 339 QStringList::ConstIterator itL;
340 for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { 340 for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) {
341 if ( (*itL).startsWith( qualifiedName ) ) { 341 if ( (*itL).startsWith( qualifiedName ) ) {
342 found = true; 342 found = true;
343 break; 343 break;
344 } 344 }
345 } 345 }
346 if ( ! found ) { 346 if ( ! found ) {
347 mData->custom.append( *it ); 347 mData->custom.append( *it );
348 } 348 }
349 } 349 }
350 if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo; 350 if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo;
351 if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo; 351 if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo;
352 if ( !mData->sound.isIntern() ) { 352 if ( !mData->sound.isIntern() ) {
353 if ( mData->sound.url().isEmpty() ) { 353 if ( mData->sound.url().isEmpty() ) {
354 mData->sound = ad.mData->sound; 354 mData->sound = ad.mData->sound;
355 } 355 }
356 } 356 }
357 if ( !mData->agent.isIntern() ) { 357 if ( !mData->agent.isIntern() ) {
358 if ( mData->agent.url().isEmpty() ) { 358 if ( mData->agent.url().isEmpty() ) {
359 mData->agent = ad.mData->agent; 359 mData->agent = ad.mData->agent;
360 } 360 }
361 } 361 }
362 { 362 {
363 Key::List::Iterator itA; 363 Key::List::Iterator itA;
364 for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { 364 for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) {
365 bool found = false; 365 bool found = false;
366 Key::List::Iterator it; 366 Key::List::Iterator it;
367 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 367 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
368 if ( (*it) == (*itA)) { 368 if ( (*it) == (*itA)) {
369 found = true; 369 found = true;
370 break; 370 break;
371 371
372 } 372 }
373 } 373 }
374 if ( ! found ) { 374 if ( ! found ) {
375 mData->keys.append( *itA ); 375 mData->keys.append( *itA );
376 } 376 }
377 } 377 }
378 } 378 }
379 KABC::Address::List::Iterator addressIterA; 379 KABC::Address::List::Iterator addressIterA;
380 for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { 380 for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) {
381 bool found = false; 381 bool found = false;
382 KABC::Address::List::Iterator addressIter; 382 KABC::Address::List::Iterator addressIter;
383 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 383 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
384 ++addressIter ) { 384 ++addressIter ) {
385 if ( (*addressIter) == (*addressIterA)) { 385 if ( (*addressIter) == (*addressIterA)) {
386 found = true; 386 found = true;
387 (*addressIter).setType( (*addressIterA).type() ); 387 (*addressIter).setType( (*addressIterA).type() );
388 break; 388 break;
389 } 389 }
390 390
391 } 391 }
392 if ( isSubSet && ! found ) { 392 if ( isSubSet && ! found ) {
393 mData->addresses.append( *addressIterA ); 393 mData->addresses.append( *addressIterA );
394 } 394 }
395 } 395 }
396 //qDebug("merge contact %s ", ad.uid().latin1()); 396 //qDebug("merge contact %s ", ad.uid().latin1());
397 setUid( ad.uid() ); 397 setUid( ad.uid() );
398 setRevision( ad.revision() ); 398 setRevision( ad.revision() );
399} 399}
400 400
401bool Addressee::removeVoice() 401bool Addressee::removeVoice()
402{ 402{
403 PhoneNumber::List phoneN = phoneNumbers(); 403 PhoneNumber::List phoneN = phoneNumbers();
404 PhoneNumber::List::Iterator phoneIt; 404 PhoneNumber::List::Iterator phoneIt;
405 bool found = false; 405 bool found = false;
406 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { 406 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
407 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found 407 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found
408 if ((*phoneIt).type() - PhoneNumber::Voice ) { 408 if ((*phoneIt).type() - PhoneNumber::Voice ) {
409 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); 409 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice );
410 insertPhoneNumber( (*phoneIt) ); 410 insertPhoneNumber( (*phoneIt) );
411 found = true; 411 found = true;
412 } 412 }
413 } 413 }
414 414
415 } 415 }
416 return found; 416 return found;
417} 417}
418 418
419bool Addressee::containsAdr(const Addressee& ad ) 419bool Addressee::containsAdr(const Addressee& ad )
420{ 420{
421 if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; 421 if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false;
422 if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; 422 if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false;
423 if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; 423 if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ;
424 if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; 424 if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ;
425 if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ; 425 if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ;
426 if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ; 426 if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ;
427 if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; 427 if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ;
428 428
429 // compare phone numbers 429 // compare phone numbers
430 PhoneNumber::List phoneN = ad.phoneNumbers(); 430 PhoneNumber::List phoneN = ad.phoneNumbers();
431 PhoneNumber::List::Iterator phoneIt; 431 PhoneNumber::List::Iterator phoneIt;
432 bool found = false; 432 bool found = false;
433 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { 433 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
434 bool found = false; 434 bool found = false;
435 PhoneNumber::List phoneL = ad.phoneNumbers(); 435 PhoneNumber::List phoneL = ad.phoneNumbers();
436 PhoneNumber::List::Iterator phoneItL; 436 PhoneNumber::List::Iterator phoneItL;
437 for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { 437 for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) {
438 if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { 438 if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) {
439 found = true; 439 found = true;
440 break; 440 break;
441 } 441 }
442 } 442 }
443 if ( ! found ) 443 if ( ! found )
444 return false; 444 return false;
445 } 445 }
446 return true; 446 return true;
447 447
448} 448}
449void Addressee::simplifyAddresses() 449void Addressee::simplifyAddresses()
450{ 450{
451 451
452 452
453 Address::List list; 453 Address::List list;
454 Address::List::Iterator it; 454 Address::List::Iterator it;
455 Address::List::Iterator it2; 455 Address::List::Iterator it2;
456 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 456 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
457 it2 = it; 457 it2 = it;
458 ++it2; 458 ++it2;
459 for( ; it2 != mData->addresses.end(); ++it2 ) { 459 for( ; it2 != mData->addresses.end(); ++it2 ) {
460 if ( (*it) == (*it2) ) { 460 if ( (*it) == (*it2) ) {
461 list.append( *it ); 461 list.append( *it );
462 break; 462 break;
463 } 463 }
464 } 464 }
465 } 465 }
466 for( it = list.begin(); it != list.end(); ++it ) { 466 for( it = list.begin(); it != list.end(); ++it ) {
467 removeAddress( (*it) ); 467 removeAddress( (*it) );
468 } 468 }
469 469
470 list.clear(); 470 list.clear();
471 int max = 2; 471 int max = 2;
472 if ( mData->url.isValid() ) 472 if ( mData->url.isValid() )
473 max = 1; 473 max = 1;
474 if ( mData->addresses.count() <= max ) return ; 474 if ( mData->addresses.count() <= max ) return ;
475 int count = 0; 475 int count = 0;
476 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 476 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
477 if ( count >= max ) 477 if ( count >= max )
478 list.append( *it ); 478 list.append( *it );
479 ++count; 479 ++count;
480 } 480 }
481 for( it = list.begin(); it != list.end(); ++it ) { 481 for( it = list.begin(); it != list.end(); ++it ) {
482 removeAddress( (*it) ); 482 removeAddress( (*it) );
483 } 483 }
484} 484}
485 485
486// removes all emails but the first 486// removes all emails but the first
487// needed by phone sync 487// needed by phone sync
488void Addressee::simplifyEmails() 488void Addressee::simplifyEmails()
489{ 489{
490 if ( mData->emails.count() == 0 ) return ; 490 if ( mData->emails.count() == 0 ) return ;
491 QString email = mData->emails.first(); 491 QString email = mData->emails.first();
492 detach(); 492 detach();
493 mData->emails.clear(); 493 mData->emails.clear();
494 mData->emails.append( email ); 494 mData->emails.append( email );
495} 495}
496 496
497void Addressee::simplifyPhoneNumbers() 497void Addressee::simplifyPhoneNumbers()
498{ 498{
499 int max = 4; 499 int max = 4;
500 int inList = mData->phoneNumbers.count(); 500 int inList = mData->phoneNumbers.count();
501 KABC::PhoneNumber::List removeNumbers; 501 KABC::PhoneNumber::List removeNumbers;
502 KABC::PhoneNumber::List::Iterator phoneIter; 502 KABC::PhoneNumber::List::Iterator phoneIter;
503 if ( inList > max ) { 503 if ( inList > max ) {
504 // delete non-preferred numbers 504 // delete non-preferred numbers
505 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 505 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
506 ++phoneIter ) { 506 ++phoneIter ) {
507 if ( inList > max ) { 507 if ( inList > max ) {
508 if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) { 508 if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) {
509 removeNumbers.append( ( *phoneIter ) ); 509 removeNumbers.append( ( *phoneIter ) );
510 --inList; 510 --inList;
511 } 511 }
512 } else 512 } else
513 break; 513 break;
514 } 514 }
515 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 515 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
516 ++phoneIter ) { 516 ++phoneIter ) {
517 removePhoneNumber(( *phoneIter )); 517 removePhoneNumber(( *phoneIter ));
518 } 518 }
519 // delete preferred numbers 519 // delete preferred numbers
520 if ( inList > max ) { 520 if ( inList > max ) {
521 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 521 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
522 ++phoneIter ) { 522 ++phoneIter ) {
523 if ( inList > max ) { 523 if ( inList > max ) {
524 removeNumbers.append( ( *phoneIter ) ); 524 removeNumbers.append( ( *phoneIter ) );
525 --inList; 525 --inList;
526 } else 526 } else
527 break; 527 break;
528 } 528 }
529 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 529 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
530 ++phoneIter ) { 530 ++phoneIter ) {
531 removePhoneNumber(( *phoneIter )); 531 removePhoneNumber(( *phoneIter ));
532 } 532 }
533 } 533 }
534 } 534 }
535 // remove non-numeric characters 535 // remove non-numeric characters
536 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 536 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
537 ++phoneIter ) { 537 ++phoneIter ) {
538 if ( ! ( *phoneIter ).simplifyNumber() ) 538 if ( ! ( *phoneIter ).simplifyNumber() )
539 removeNumbers.append( ( *phoneIter ) ); 539 removeNumbers.append( ( *phoneIter ) );
540 } 540 }
541 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); 541 for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end();
542 ++phoneIter ) { 542 ++phoneIter ) {
543 removePhoneNumber(( *phoneIter )); 543 removePhoneNumber(( *phoneIter ));
544 } 544 }
545} 545}
546void Addressee::simplifyPhoneNumberTypes() 546void Addressee::simplifyPhoneNumberTypes()
547{ 547{
548 KABC::PhoneNumber::List::Iterator phoneIter; 548 KABC::PhoneNumber::List::Iterator phoneIter;
549 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 549 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
550 ++phoneIter ) 550 ++phoneIter )
551 ( *phoneIter ).simplifyType(); 551 ( *phoneIter ).simplifyType();
552} 552}
553void Addressee::removeID(const QString &prof) 553void Addressee::removeID(const QString &prof)
554{ 554{
555 detach(); 555 detach();
556 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); 556 if ( prof.isEmpty() )
557 mData->mExternalId = ":";
558 else
559 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
557 560
558} 561}
559void Addressee::setID( const QString & prof , const QString & id ) 562void Addressee::setID( const QString & prof , const QString & id )
560{ 563{
561 detach(); 564 detach();
562 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); 565 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
563 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 566 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
564} 567}
565void Addressee::setTempSyncStat( int id ) 568void Addressee::setTempSyncStat( int id )
566{ 569{
567 if ( mData->mTempSyncStat == id ) return; 570 if ( mData->mTempSyncStat == id ) return;
568 detach(); 571 detach();
569 mData->mTempSyncStat = id; 572 mData->mTempSyncStat = id;
570} 573}
571int Addressee::tempSyncStat() const 574int Addressee::tempSyncStat() const
572{ 575{
573 return mData->mTempSyncStat; 576 return mData->mTempSyncStat;
574} 577}
575 578
576QString Addressee::getID( const QString & prof) 579QString Addressee::getID( const QString & prof)
577{ 580{
578 return KIdManager::getId ( mData->mExternalId, prof ); 581 return KIdManager::getId ( mData->mExternalId, prof );
579} 582}
580 583
581void Addressee::setCsum( const QString & prof , const QString & id ) 584void Addressee::setCsum( const QString & prof , const QString & id )
582{ 585{
583 detach(); 586 detach();
584 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 587 //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
585 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); 588 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id );
586 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); 589 //qDebug("setcsum2 %s ",mData->mExternalId.latin1() );
587} 590}
588 591
589QString Addressee::getCsum( const QString & prof) 592QString Addressee::getCsum( const QString & prof)
590{ 593{
591 return KIdManager::getCsum ( mData->mExternalId, prof ); 594 return KIdManager::getCsum ( mData->mExternalId, prof );
592} 595}
593 596
594void Addressee::setIDStr( const QString & s ) 597void Addressee::setIDStr( const QString & s )
595{ 598{
596 detach(); 599 detach();
597 mData->mExternalId = s; 600 mData->mExternalId = s;
598} 601}
599 602
600QString Addressee::IDStr() const 603QString Addressee::IDStr() const
601{ 604{
602 return mData->mExternalId; 605 return mData->mExternalId;
603} 606}
604 607
605void Addressee::setExternalUID( const QString &id ) 608void Addressee::setExternalUID( const QString &id )
606{ 609{
607 if ( id == mData->externalUID ) return; 610 if ( id == mData->externalUID ) return;
608 detach(); 611 detach();
609 mData->empty = false; 612 mData->empty = false;
610 mData->externalUID = id; 613 mData->externalUID = id;
611} 614}
612 615
613QString Addressee::externalUID() const 616QString Addressee::externalUID() const
614{ 617{
615 return mData->externalUID; 618 return mData->externalUID;
616} 619}
617void Addressee::setOriginalExternalUID( const QString &id ) 620void Addressee::setOriginalExternalUID( const QString &id )
618{ 621{
619 if ( id == mData->originalExternalUID ) return; 622 if ( id == mData->originalExternalUID ) return;
620 detach(); 623 detach();
621 mData->empty = false; 624 mData->empty = false;
622 //qDebug("*******Set orig uid %s ", id.latin1()); 625 //qDebug("*******Set orig uid %s ", id.latin1());
623 mData->originalExternalUID = id; 626 mData->originalExternalUID = id;
624} 627}
625 628
626QString Addressee::originalExternalUID() const 629QString Addressee::originalExternalUID() const
627{ 630{
628 return mData->originalExternalUID; 631 return mData->originalExternalUID;
629} 632}
630 633
631void Addressee::setUid( const QString &id ) 634void Addressee::setUid( const QString &id )
632{ 635{
633 if ( id == mData->uid ) return; 636 if ( id == mData->uid ) return;
634 detach(); 637 detach();
635 //qDebug("****setuid %s ", id.latin1()); 638 //qDebug("****setuid %s ", id.latin1());
636 mData->empty = false; 639 mData->empty = false;
637 mData->uid = id; 640 mData->uid = id;
638} 641}
639 642
640QString Addressee::uid() const 643QString Addressee::uid() const
641{ 644{
642 if ( mData->uid.isEmpty() ) 645 if ( mData->uid.isEmpty() )
643 mData->uid = KApplication::randomString( 10 ); 646 mData->uid = KApplication::randomString( 10 );
644 647
645 return mData->uid; 648 return mData->uid;
646} 649}
647 650
648QString Addressee::uidLabel() 651QString Addressee::uidLabel()
649{ 652{
650 return i18n("Unique Identifier"); 653 return i18n("Unique Identifier");
651} 654}
652 655
653void Addressee::setName( const QString &name ) 656void Addressee::setName( const QString &name )
654{ 657{
655 if ( name == mData->name ) return; 658 if ( name == mData->name ) return;
656 detach(); 659 detach();
657 mData->empty = false; 660 mData->empty = false;
658 mData->name = name; 661 mData->name = name;
659} 662}
660 663
661QString Addressee::name() const 664QString Addressee::name() const
662{ 665{
663 return mData->name; 666 return mData->name;
664} 667}
665 668
666QString Addressee::nameLabel() 669QString Addressee::nameLabel()
667{ 670{
668 return i18n("Name"); 671 return i18n("Name");
669} 672}
670 673
671 674
672void Addressee::setFormattedName( const QString &formattedName ) 675void Addressee::setFormattedName( const QString &formattedName )
673{ 676{
674 if ( formattedName == mData->formattedName ) return; 677 if ( formattedName == mData->formattedName ) return;
675 detach(); 678 detach();
676 mData->empty = false; 679 mData->empty = false;
677 mData->formattedName = formattedName; 680 mData->formattedName = formattedName;
678} 681}
679 682
680QString Addressee::formattedName() const 683QString Addressee::formattedName() const
681{ 684{
682 return mData->formattedName; 685 return mData->formattedName;
683} 686}
684 687
685QString Addressee::formattedNameLabel() 688QString Addressee::formattedNameLabel()
686{ 689{
687 return i18n("Formatted Name"); 690 return i18n("Formatted Name");
688} 691}
689 692
690 693
691void Addressee::setFamilyName( const QString &familyName ) 694void Addressee::setFamilyName( const QString &familyName )
692{ 695{
693 if ( familyName == mData->familyName ) return; 696 if ( familyName == mData->familyName ) return;
694 detach(); 697 detach();
695 mData->empty = false; 698 mData->empty = false;
696 mData->familyName = familyName; 699 mData->familyName = familyName;
697} 700}
698 701
699QString Addressee::familyName() const 702QString Addressee::familyName() const
700{ 703{
701 return mData->familyName; 704 return mData->familyName;
702} 705}
703 706
704QString Addressee::familyNameLabel() 707QString Addressee::familyNameLabel()
705{ 708{
706 return i18n("Family Name"); 709 return i18n("Family Name");
707} 710}
708 711
709 712
710void Addressee::setGivenName( const QString &givenName ) 713void Addressee::setGivenName( const QString &givenName )
711{ 714{
712 if ( givenName == mData->givenName ) return; 715 if ( givenName == mData->givenName ) return;
713 detach(); 716 detach();
714 mData->empty = false; 717 mData->empty = false;
715 mData->givenName = givenName; 718 mData->givenName = givenName;
716} 719}
717 720
718QString Addressee::givenName() const 721QString Addressee::givenName() const
719{ 722{
720 return mData->givenName; 723 return mData->givenName;
721} 724}
722 725
723QString Addressee::givenNameLabel() 726QString Addressee::givenNameLabel()
724{ 727{
725 return i18n("Given Name"); 728 return i18n("Given Name");
726} 729}
727 730
728 731
729void Addressee::setAdditionalName( const QString &additionalName ) 732void Addressee::setAdditionalName( const QString &additionalName )
730{ 733{
731 if ( additionalName == mData->additionalName ) return; 734 if ( additionalName == mData->additionalName ) return;
732 detach(); 735 detach();
733 mData->empty = false; 736 mData->empty = false;
734 mData->additionalName = additionalName; 737 mData->additionalName = additionalName;
735} 738}
736 739
737QString Addressee::additionalName() const 740QString Addressee::additionalName() const
738{ 741{
739 return mData->additionalName; 742 return mData->additionalName;
740} 743}
741 744
742QString Addressee::additionalNameLabel() 745QString Addressee::additionalNameLabel()
743{ 746{
744 return i18n("Additional Names"); 747 return i18n("Additional Names");
745} 748}
746 749
747 750
748void Addressee::setPrefix( const QString &prefix ) 751void Addressee::setPrefix( const QString &prefix )
749{ 752{
750 if ( prefix == mData->prefix ) return; 753 if ( prefix == mData->prefix ) return;
751 detach(); 754 detach();
752 mData->empty = false; 755 mData->empty = false;
753 mData->prefix = prefix; 756 mData->prefix = prefix;
754} 757}
755 758
756QString Addressee::prefix() const 759QString Addressee::prefix() const
757{ 760{
758 return mData->prefix; 761 return mData->prefix;
759} 762}
760 763
761QString Addressee::prefixLabel() 764QString Addressee::prefixLabel()
762{ 765{
763 return i18n("Honorific Prefixes"); 766 return i18n("Honorific Prefixes");
764} 767}
765 768
766 769
767void Addressee::setSuffix( const QString &suffix ) 770void Addressee::setSuffix( const QString &suffix )
768{ 771{
769 if ( suffix == mData->suffix ) return; 772 if ( suffix == mData->suffix ) return;
770 detach(); 773 detach();
771 mData->empty = false; 774 mData->empty = false;
772 mData->suffix = suffix; 775 mData->suffix = suffix;
773} 776}
774 777
775QString Addressee::suffix() const 778QString Addressee::suffix() const
776{ 779{
777 return mData->suffix; 780 return mData->suffix;
778} 781}
779 782
780QString Addressee::suffixLabel() 783QString Addressee::suffixLabel()
781{ 784{
782 return i18n("Honorific Suffixes"); 785 return i18n("Honorific Suffixes");
783} 786}
784 787
785 788
786void Addressee::setNickName( const QString &nickName ) 789void Addressee::setNickName( const QString &nickName )
787{ 790{
788 if ( nickName == mData->nickName ) return; 791 if ( nickName == mData->nickName ) return;
789 detach(); 792 detach();
790 mData->empty = false; 793 mData->empty = false;
791 mData->nickName = nickName; 794 mData->nickName = nickName;
792} 795}
793 796
794QString Addressee::nickName() const 797QString Addressee::nickName() const
795{ 798{
796 return mData->nickName; 799 return mData->nickName;
797} 800}
798 801
799QString Addressee::nickNameLabel() 802QString Addressee::nickNameLabel()
800{ 803{
801 return i18n("Nick Name"); 804 return i18n("Nick Name");
802} 805}
803 806
804 807
805void Addressee::setBirthday( const QDateTime &birthday ) 808void Addressee::setBirthday( const QDateTime &birthday )
806{ 809{
807 if ( birthday == mData->birthday ) return; 810 if ( birthday == mData->birthday ) return;
808 detach(); 811 detach();
809 mData->empty = false; 812 mData->empty = false;
810 mData->birthday = birthday; 813 mData->birthday = birthday;
811} 814}
812 815
813QDateTime Addressee::birthday() const 816QDateTime Addressee::birthday() const
814{ 817{
815 return mData->birthday; 818 return mData->birthday;
816} 819}
817 820
818QString Addressee::birthdayLabel() 821QString Addressee::birthdayLabel()
819{ 822{
820 return i18n("Birthday"); 823 return i18n("Birthday");
821} 824}
822 825
823 826
824QString Addressee::homeAddressStreetLabel() 827QString Addressee::homeAddressStreetLabel()
825{ 828{
826 return i18n("Home Address Street"); 829 return i18n("Home Address Street");
827} 830}
828 831
829 832
830QString Addressee::homeAddressLocalityLabel() 833QString Addressee::homeAddressLocalityLabel()
831{ 834{
832 return i18n("Home Address Locality"); 835 return i18n("Home Address Locality");
833} 836}
834 837
835 838
836QString Addressee::homeAddressRegionLabel() 839QString Addressee::homeAddressRegionLabel()
837{ 840{
838 return i18n("Home Address Region"); 841 return i18n("Home Address Region");
839} 842}
840 843
841 844
842QString Addressee::homeAddressPostalCodeLabel() 845QString Addressee::homeAddressPostalCodeLabel()
843{ 846{
844 return i18n("Home Address Postal Code"); 847 return i18n("Home Address Postal Code");
845} 848}
846 849
847 850
848QString Addressee::homeAddressCountryLabel() 851QString Addressee::homeAddressCountryLabel()
849{ 852{
850 return i18n("Home Address Country"); 853 return i18n("Home Address Country");
851} 854}
852 855
853 856
854QString Addressee::homeAddressLabelLabel() 857QString Addressee::homeAddressLabelLabel()
855{ 858{
856 return i18n("Home Address Label"); 859 return i18n("Home Address Label");
857} 860}
858 861
859 862
860QString Addressee::businessAddressStreetLabel() 863QString Addressee::businessAddressStreetLabel()
861{ 864{
862 return i18n("Business Address Street"); 865 return i18n("Business Address Street");
863} 866}
864 867
865 868
866QString Addressee::businessAddressLocalityLabel() 869QString Addressee::businessAddressLocalityLabel()
867{ 870{
868 return i18n("Business Address Locality"); 871 return i18n("Business Address Locality");
869} 872}
870 873
871 874
872QString Addressee::businessAddressRegionLabel() 875QString Addressee::businessAddressRegionLabel()
873{ 876{
874 return i18n("Business Address Region"); 877 return i18n("Business Address Region");
875} 878}
876 879
877 880
878QString Addressee::businessAddressPostalCodeLabel() 881QString Addressee::businessAddressPostalCodeLabel()
879{ 882{
880 return i18n("Business Address Postal Code"); 883 return i18n("Business Address Postal Code");
881} 884}
882 885
883 886
884QString Addressee::businessAddressCountryLabel() 887QString Addressee::businessAddressCountryLabel()
885{ 888{
886 return i18n("Business Address Country"); 889 return i18n("Business Address Country");
887} 890}
888 891
889 892
890QString Addressee::businessAddressLabelLabel() 893QString Addressee::businessAddressLabelLabel()
891{ 894{
892 return i18n("Business Address Label"); 895 return i18n("Business Address Label");
893} 896}
894 897
895 898
896QString Addressee::homePhoneLabel() 899QString Addressee::homePhoneLabel()
897{ 900{
898 return i18n("Home Phone"); 901 return i18n("Home Phone");
899} 902}
900 903
901 904
902QString Addressee::businessPhoneLabel() 905QString Addressee::businessPhoneLabel()
903{ 906{
904 return i18n("Business Phone"); 907 return i18n("Business Phone");
905} 908}
906 909
907 910
908QString Addressee::mobilePhoneLabel() 911QString Addressee::mobilePhoneLabel()
909{ 912{
910 return i18n("Mobile Phone"); 913 return i18n("Mobile Phone");
911} 914}
912 915
913 916
914QString Addressee::homeFaxLabel() 917QString Addressee::homeFaxLabel()
915{ 918{
916 return i18n("Home Fax"); 919 return i18n("Home Fax");
917} 920}
918 921
919 922
920QString Addressee::businessFaxLabel() 923QString Addressee::businessFaxLabel()
921{ 924{
922 return i18n("Business Fax"); 925 return i18n("Business Fax");
923} 926}
924 927
925 928
926QString Addressee::carPhoneLabel() 929QString Addressee::carPhoneLabel()
927{ 930{
928 return i18n("Car Phone"); 931 return i18n("Car Phone");
929} 932}
930 933
931 934
932QString Addressee::isdnLabel() 935QString Addressee::isdnLabel()
933{ 936{
934 return i18n("ISDN"); 937 return i18n("ISDN");
935} 938}
936 939
937 940
938QString Addressee::pagerLabel() 941QString Addressee::pagerLabel()
939{ 942{
940 return i18n("Pager"); 943 return i18n("Pager");
941} 944}
942 945
943QString Addressee::sipLabel() 946QString Addressee::sipLabel()
944{ 947{
945 return i18n("SIP"); 948 return i18n("SIP");
946} 949}
947 950
948QString Addressee::emailLabel() 951QString Addressee::emailLabel()
949{ 952{
950 return i18n("Email Address"); 953 return i18n("Email Address");
951} 954}
952 955
953 956
954void Addressee::setMailer( const QString &mailer ) 957void Addressee::setMailer( const QString &mailer )
955{ 958{
956 if ( mailer == mData->mailer ) return; 959 if ( mailer == mData->mailer ) return;
957 detach(); 960 detach();
958 mData->empty = false; 961 mData->empty = false;
959 mData->mailer = mailer; 962 mData->mailer = mailer;
960} 963}
961 964
962QString Addressee::mailer() const 965QString Addressee::mailer() const
963{ 966{
964 return mData->mailer; 967 return mData->mailer;
965} 968}
966 969
967QString Addressee::mailerLabel() 970QString Addressee::mailerLabel()
968{ 971{
969 return i18n("Mail Client"); 972 return i18n("Mail Client");
970} 973}
971 974
972 975
973void Addressee::setTimeZone( const TimeZone &timeZone ) 976void Addressee::setTimeZone( const TimeZone &timeZone )
974{ 977{
975 if ( timeZone == mData->timeZone ) return; 978 if ( timeZone == mData->timeZone ) return;
976 detach(); 979 detach();
977 mData->empty = false; 980 mData->empty = false;
978 mData->timeZone = timeZone; 981 mData->timeZone = timeZone;
979} 982}
980 983
981TimeZone Addressee::timeZone() const 984TimeZone Addressee::timeZone() const
982{ 985{
983 return mData->timeZone; 986 return mData->timeZone;
984} 987}
985 988
986QString Addressee::timeZoneLabel() 989QString Addressee::timeZoneLabel()
987{ 990{
988 return i18n("Time Zone"); 991 return i18n("Time Zone");
989} 992}
990 993
991 994
992void Addressee::setGeo( const Geo &geo ) 995void Addressee::setGeo( const Geo &geo )
993{ 996{
994 if ( geo == mData->geo ) return; 997 if ( geo == mData->geo ) return;
995 detach(); 998 detach();
996 mData->empty = false; 999 mData->empty = false;
997 mData->geo = geo; 1000 mData->geo = geo;
998} 1001}
999 1002
1000Geo Addressee::geo() const 1003Geo Addressee::geo() const
1001{ 1004{
1002 return mData->geo; 1005 return mData->geo;
1003} 1006}
1004 1007
1005QString Addressee::geoLabel() 1008QString Addressee::geoLabel()
1006{ 1009{
1007 return i18n("Geographic Position"); 1010 return i18n("Geographic Position");
1008} 1011}
1009 1012
1010 1013
1011void Addressee::setTitle( const QString &title ) 1014void Addressee::setTitle( const QString &title )
1012{ 1015{
1013 if ( title == mData->title ) return; 1016 if ( title == mData->title ) return;
1014 detach(); 1017 detach();
1015 mData->empty = false; 1018 mData->empty = false;
1016 mData->title = title; 1019 mData->title = title;
1017} 1020}
1018 1021
1019QString Addressee::title() const 1022QString Addressee::title() const
1020{ 1023{
1021 return mData->title; 1024 return mData->title;
1022} 1025}
1023 1026
1024QString Addressee::titleLabel() 1027QString Addressee::titleLabel()
1025{ 1028{
1026 return i18n("Title"); 1029 return i18n("Title");
1027} 1030}
1028 1031
1029 1032
1030void Addressee::setRole( const QString &role ) 1033void Addressee::setRole( const QString &role )
1031{ 1034{
1032 if ( role == mData->role ) return; 1035 if ( role == mData->role ) return;
1033 detach(); 1036 detach();
1034 mData->empty = false; 1037 mData->empty = false;
1035 mData->role = role; 1038 mData->role = role;
1036} 1039}
1037 1040
1038QString Addressee::role() const 1041QString Addressee::role() const
1039{ 1042{
1040 return mData->role; 1043 return mData->role;
1041} 1044}
1042 1045
1043QString Addressee::roleLabel() 1046QString Addressee::roleLabel()
1044{ 1047{
1045 return i18n("Role"); 1048 return i18n("Role");
1046} 1049}
1047 1050
1048 1051
1049void Addressee::setOrganization( const QString &organization ) 1052void Addressee::setOrganization( const QString &organization )
1050{ 1053{
1051 if ( organization == mData->organization ) return; 1054 if ( organization == mData->organization ) return;
1052 detach(); 1055 detach();
1053 mData->empty = false; 1056 mData->empty = false;
1054 mData->organization = organization; 1057 mData->organization = organization;
1055} 1058}
1056 1059
1057QString Addressee::organization() const 1060QString Addressee::organization() const
1058{ 1061{
1059 return mData->organization; 1062 return mData->organization;
1060} 1063}
1061 1064
1062QString Addressee::organizationLabel() 1065QString Addressee::organizationLabel()
1063{ 1066{
1064 return i18n("Organization"); 1067 return i18n("Organization");
1065} 1068}
1066 1069
1067 1070
1068void Addressee::setNote( const QString &note ) 1071void Addressee::setNote( const QString &note )
1069{ 1072{
1070 if ( note == mData->note ) return; 1073 if ( note == mData->note ) return;
1071 detach(); 1074 detach();
1072 mData->empty = false; 1075 mData->empty = false;
1073 mData->note = note; 1076 mData->note = note;
1074} 1077}
1075 1078
1076QString Addressee::note() const 1079QString Addressee::note() const
1077{ 1080{
1078 return mData->note; 1081 return mData->note;
1079} 1082}
1080 1083
1081QString Addressee::noteLabel() 1084QString Addressee::noteLabel()
1082{ 1085{
1083 return i18n("Note"); 1086 return i18n("Note");
1084} 1087}
1085 1088
1086 1089
1087void Addressee::setProductId( const QString &productId ) 1090void Addressee::setProductId( const QString &productId )
1088{ 1091{
1089 if ( productId == mData->productId ) return; 1092 if ( productId == mData->productId ) return;
1090 detach(); 1093 detach();
1091 mData->empty = false; 1094 mData->empty = false;
1092 mData->productId = productId; 1095 mData->productId = productId;
1093} 1096}
1094 1097
1095QString Addressee::productId() const 1098QString Addressee::productId() const
1096{ 1099{
1097 return mData->productId; 1100 return mData->productId;
1098} 1101}
1099 1102
1100QString Addressee::productIdLabel() 1103QString Addressee::productIdLabel()
1101{ 1104{
1102 return i18n("Product Identifier"); 1105 return i18n("Product Identifier");
1103} 1106}
1104 1107
1105 1108
1106void Addressee::setRevision( const QDateTime &revision ) 1109void Addressee::setRevision( const QDateTime &revision )
1107{ 1110{
1108 if ( revision == mData->revision ) return; 1111 if ( revision == mData->revision ) return;
1109 detach(); 1112 detach();
1110 mData->empty = false; 1113 mData->empty = false;
1111 mData->revision = revision; 1114 mData->revision = revision;
1112} 1115}
1113 1116
1114QDateTime Addressee::revision() const 1117QDateTime Addressee::revision() const
1115{ 1118{
1116 return mData->revision; 1119 return mData->revision;
1117} 1120}
1118 1121
1119QString Addressee::revisionLabel() 1122QString Addressee::revisionLabel()
1120{ 1123{
1121 return i18n("Revision Date"); 1124 return i18n("Revision Date");
1122} 1125}
1123 1126
1124 1127
1125void Addressee::setSortString( const QString &sortString ) 1128void Addressee::setSortString( const QString &sortString )
1126{ 1129{
1127 if ( sortString == mData->sortString ) return; 1130 if ( sortString == mData->sortString ) return;
1128 detach(); 1131 detach();
1129 mData->empty = false; 1132 mData->empty = false;
1130 mData->sortString = sortString; 1133 mData->sortString = sortString;
1131} 1134}
1132 1135
1133QString Addressee::sortString() const 1136QString Addressee::sortString() const
1134{ 1137{
1135 return mData->sortString; 1138 return mData->sortString;
1136} 1139}
1137 1140
1138QString Addressee::sortStringLabel() 1141QString Addressee::sortStringLabel()
1139{ 1142{
1140 return i18n("Sort String"); 1143 return i18n("Sort String");
1141} 1144}
1142 1145
1143 1146
1144void Addressee::setUrl( const KURL &url ) 1147void Addressee::setUrl( const KURL &url )
1145{ 1148{
1146 if ( url == mData->url ) return; 1149 if ( url == mData->url ) return;
1147 detach(); 1150 detach();
1148 mData->empty = false; 1151 mData->empty = false;
1149 mData->url = url; 1152 mData->url = url;
1150} 1153}
1151 1154
1152KURL Addressee::url() const 1155KURL Addressee::url() const
1153{ 1156{
1154 return mData->url; 1157 return mData->url;
1155} 1158}
1156 1159
1157QString Addressee::urlLabel() 1160QString Addressee::urlLabel()
1158{ 1161{
1159 return i18n("URL"); 1162 return i18n("URL");
1160} 1163}
1161 1164
1162 1165
1163void Addressee::setSecrecy( const Secrecy &secrecy ) 1166void Addressee::setSecrecy( const Secrecy &secrecy )
1164{ 1167{
1165 if ( secrecy == mData->secrecy ) return; 1168 if ( secrecy == mData->secrecy ) return;
1166 detach(); 1169 detach();
1167 mData->empty = false; 1170 mData->empty = false;
1168 mData->secrecy = secrecy; 1171 mData->secrecy = secrecy;
1169} 1172}
1170 1173
1171Secrecy Addressee::secrecy() const 1174Secrecy Addressee::secrecy() const
1172{ 1175{
1173 return mData->secrecy; 1176 return mData->secrecy;
1174} 1177}
1175 1178
1176QString Addressee::secrecyLabel() 1179QString Addressee::secrecyLabel()
1177{ 1180{
1178 return i18n("Security Class"); 1181 return i18n("Security Class");
1179} 1182}
1180 1183
1181 1184
1182void Addressee::setLogo( const Picture &logo ) 1185void Addressee::setLogo( const Picture &logo )
1183{ 1186{
1184 if ( logo == mData->logo ) return; 1187 if ( logo == mData->logo ) return;
1185 detach(); 1188 detach();
1186 mData->empty = false; 1189 mData->empty = false;
1187 mData->logo = logo; 1190 mData->logo = logo;
1188} 1191}
1189 1192
1190Picture Addressee::logo() const 1193Picture Addressee::logo() const
1191{ 1194{
1192 return mData->logo; 1195 return mData->logo;
1193} 1196}
1194 1197
1195QString Addressee::logoLabel() 1198QString Addressee::logoLabel()
1196{ 1199{
1197 return i18n("Logo"); 1200 return i18n("Logo");
1198} 1201}
1199 1202
1200 1203
1201void Addressee::setPhoto( const Picture &photo ) 1204void Addressee::setPhoto( const Picture &photo )
1202{ 1205{
1203 if ( photo == mData->photo ) return; 1206 if ( photo == mData->photo ) return;
1204 detach(); 1207 detach();
1205 mData->empty = false; 1208 mData->empty = false;
1206 mData->photo = photo; 1209 mData->photo = photo;
1207} 1210}
1208 1211
1209Picture Addressee::photo() const 1212Picture Addressee::photo() const
1210{ 1213{
1211 return mData->photo; 1214 return mData->photo;
1212} 1215}
1213 1216
1214QString Addressee::photoLabel() 1217QString Addressee::photoLabel()
1215{ 1218{
1216 return i18n("Photo"); 1219 return i18n("Photo");
1217} 1220}
1218 1221
1219 1222
1220void Addressee::setSound( const Sound &sound ) 1223void Addressee::setSound( const Sound &sound )
1221{ 1224{
1222 if ( sound == mData->sound ) return; 1225 if ( sound == mData->sound ) return;
1223 detach(); 1226 detach();
1224 mData->empty = false; 1227 mData->empty = false;
1225 mData->sound = sound; 1228 mData->sound = sound;
1226} 1229}
1227 1230
1228Sound Addressee::sound() const 1231Sound Addressee::sound() const
1229{ 1232{
1230 return mData->sound; 1233 return mData->sound;
1231} 1234}
1232 1235
1233QString Addressee::soundLabel() 1236QString Addressee::soundLabel()
1234{ 1237{
1235 return i18n("Sound"); 1238 return i18n("Sound");
1236} 1239}
1237 1240
1238 1241
1239void Addressee::setAgent( const Agent &agent ) 1242void Addressee::setAgent( const Agent &agent )
1240{ 1243{
1241 if ( agent == mData->agent ) return; 1244 if ( agent == mData->agent ) return;
1242 detach(); 1245 detach();
1243 mData->empty = false; 1246 mData->empty = false;
1244 mData->agent = agent; 1247 mData->agent = agent;
1245} 1248}
1246 1249
1247Agent Addressee::agent() const 1250Agent Addressee::agent() const
1248{ 1251{
1249 return mData->agent; 1252 return mData->agent;
1250} 1253}
1251 1254
1252QString Addressee::agentLabel() 1255QString Addressee::agentLabel()
1253{ 1256{
1254 return i18n("Agent"); 1257 return i18n("Agent");
1255} 1258}
1256 1259
1257 1260
1258 1261
1259void Addressee::setNameFromString( const QString &str ) 1262void Addressee::setNameFromString( const QString &str )
1260{ 1263{
1261 setFormattedName( str ); 1264 setFormattedName( str );
1262 setName( str ); 1265 setName( str );
1263 1266
1264 static bool first = true; 1267 static bool first = true;
1265 static QStringList titles; 1268 static QStringList titles;
1266 static QStringList suffixes; 1269 static QStringList suffixes;
1267 static QStringList prefixes; 1270 static QStringList prefixes;
1268 1271
1269 if ( first ) { 1272 if ( first ) {
1270 first = false; 1273 first = false;
1271 titles += i18n( "Dr." ); 1274 titles += i18n( "Dr." );
1272 titles += i18n( "Miss" ); 1275 titles += i18n( "Miss" );
1273 titles += i18n( "Mr." ); 1276 titles += i18n( "Mr." );
1274 titles += i18n( "Mrs." ); 1277 titles += i18n( "Mrs." );
1275 titles += i18n( "Ms." ); 1278 titles += i18n( "Ms." );
1276 titles += i18n( "Prof." ); 1279 titles += i18n( "Prof." );
1277 1280
1278 suffixes += i18n( "I" ); 1281 suffixes += i18n( "I" );
1279 suffixes += i18n( "II" ); 1282 suffixes += i18n( "II" );
1280 suffixes += i18n( "III" ); 1283 suffixes += i18n( "III" );
1281 suffixes += i18n( "Jr." ); 1284 suffixes += i18n( "Jr." );
1282 suffixes += i18n( "Sr." ); 1285 suffixes += i18n( "Sr." );
1283 1286
1284 prefixes += "van"; 1287 prefixes += "van";
1285 prefixes += "von"; 1288 prefixes += "von";
1286 prefixes += "de"; 1289 prefixes += "de";
1287 1290
1288 KConfig config( locateLocal( "config", "kabcrc") ); 1291 KConfig config( locateLocal( "config", "kabcrc") );
1289 config.setGroup( "General" ); 1292 config.setGroup( "General" );
1290 titles += config.readListEntry( "Prefixes" ); 1293 titles += config.readListEntry( "Prefixes" );
1291 titles.remove( "" ); 1294 titles.remove( "" );
1292 prefixes += config.readListEntry( "Inclusions" ); 1295 prefixes += config.readListEntry( "Inclusions" );
1293 prefixes.remove( "" ); 1296 prefixes.remove( "" );
1294 suffixes += config.readListEntry( "Suffixes" ); 1297 suffixes += config.readListEntry( "Suffixes" );
1295 suffixes.remove( "" ); 1298 suffixes.remove( "" );
1296 } 1299 }
1297 1300
1298 // clear all name parts 1301 // clear all name parts
1299 setPrefix( "" ); 1302 setPrefix( "" );
1300 setGivenName( "" ); 1303 setGivenName( "" );
1301 setAdditionalName( "" ); 1304 setAdditionalName( "" );
1302 setFamilyName( "" ); 1305 setFamilyName( "" );
1303 setSuffix( "" ); 1306 setSuffix( "" );
1304 1307
1305 if ( str.isEmpty() ) 1308 if ( str.isEmpty() )
1306 return; 1309 return;
1307 1310
1308 int i = str.find(','); 1311 int i = str.find(',');
1309 if( i < 0 ) { 1312 if( i < 0 ) {
1310 QStringList parts = QStringList::split( " ", str ); 1313 QStringList parts = QStringList::split( " ", str );
1311 int leftOffset = 0; 1314 int leftOffset = 0;
1312 int rightOffset = parts.count() - 1; 1315 int rightOffset = parts.count() - 1;
1313 1316
1314 QString suffix; 1317 QString suffix;
1315 while ( rightOffset >= 0 ) { 1318 while ( rightOffset >= 0 ) {
1316 if ( suffixes.contains( parts[ rightOffset ] ) ) { 1319 if ( suffixes.contains( parts[ rightOffset ] ) ) {
1317 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); 1320 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " "));
1318 rightOffset--; 1321 rightOffset--;
1319 } else 1322 } else
1320 break; 1323 break;
1321 } 1324 }
1322 setSuffix( suffix ); 1325 setSuffix( suffix );
1323 1326
1324 if ( rightOffset < 0 ) 1327 if ( rightOffset < 0 )
1325 return; 1328 return;
1326 1329
1327 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { 1330 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) {
1328 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); 1331 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] );
1329 rightOffset--; 1332 rightOffset--;
1330 } else 1333 } else
1331 setFamilyName( parts[ rightOffset ] ); 1334 setFamilyName( parts[ rightOffset ] );
1332 1335
1333 QString prefix; 1336 QString prefix;
1334 while ( leftOffset < rightOffset ) { 1337 while ( leftOffset < rightOffset ) {
1335 if ( titles.contains( parts[ leftOffset ] ) ) { 1338 if ( titles.contains( parts[ leftOffset ] ) ) {
1336 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1339 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1337 leftOffset++; 1340 leftOffset++;
1338 } else 1341 } else
1339 break; 1342 break;
1340 } 1343 }
1341 setPrefix( prefix ); 1344 setPrefix( prefix );
1342 1345
1343 if ( leftOffset < rightOffset ) { 1346 if ( leftOffset < rightOffset ) {
1344 setGivenName( parts[ leftOffset ] ); 1347 setGivenName( parts[ leftOffset ] );
1345 leftOffset++; 1348 leftOffset++;
1346 } 1349 }
1347 1350
1348 QString additionalName; 1351 QString additionalName;
1349 while ( leftOffset < rightOffset ) { 1352 while ( leftOffset < rightOffset ) {
1350 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1353 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1351 leftOffset++; 1354 leftOffset++;
1352 } 1355 }
1353 setAdditionalName( additionalName ); 1356 setAdditionalName( additionalName );
1354 } else { 1357 } else {
1355 QString part1 = str.left( i ); 1358 QString part1 = str.left( i );
1356 QString part2 = str.mid( i + 1 ); 1359 QString part2 = str.mid( i + 1 );
1357 1360
1358 QStringList parts = QStringList::split( " ", part1 ); 1361 QStringList parts = QStringList::split( " ", part1 );
1359 int leftOffset = 0; 1362 int leftOffset = 0;
1360 int rightOffset = parts.count() - 1; 1363 int rightOffset = parts.count() - 1;
1361 1364
1362 QString suffix; 1365 QString suffix;
1363 while ( rightOffset >= 0 ) { 1366 while ( rightOffset >= 0 ) {
1364 if ( suffixes.contains( parts[ rightOffset ] ) ) { 1367 if ( suffixes.contains( parts[ rightOffset ] ) ) {
1365 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); 1368 suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " "));
1366 rightOffset--; 1369 rightOffset--;
1367 } else 1370 } else
1368 break; 1371 break;
1369 } 1372 }
1370 setSuffix( suffix ); 1373 setSuffix( suffix );
1371 1374
1372 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { 1375 if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) {
1373 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); 1376 setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] );
1374 rightOffset--; 1377 rightOffset--;
1375 } else 1378 } else
1376 setFamilyName( parts[ rightOffset ] ); 1379 setFamilyName( parts[ rightOffset ] );
1377 1380
1378 QString prefix; 1381 QString prefix;
1379 while ( leftOffset < rightOffset ) { 1382 while ( leftOffset < rightOffset ) {
1380 if ( titles.contains( parts[ leftOffset ] ) ) { 1383 if ( titles.contains( parts[ leftOffset ] ) ) {
1381 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1384 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1382 leftOffset++; 1385 leftOffset++;
1383 } else 1386 } else
1384 break; 1387 break;
1385 } 1388 }
1386 1389
1387 parts = QStringList::split( " ", part2 ); 1390 parts = QStringList::split( " ", part2 );
1388 1391
1389 leftOffset = 0; 1392 leftOffset = 0;
1390 rightOffset = parts.count(); 1393 rightOffset = parts.count();
1391 1394
1392 while ( leftOffset < rightOffset ) { 1395 while ( leftOffset < rightOffset ) {
1393 if ( titles.contains( parts[ leftOffset ] ) ) { 1396 if ( titles.contains( parts[ leftOffset ] ) ) {
1394 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1397 prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1395 leftOffset++; 1398 leftOffset++;
1396 } else 1399 } else
1397 break; 1400 break;
1398 } 1401 }
1399 setPrefix( prefix ); 1402 setPrefix( prefix );
1400 1403
1401 if ( leftOffset < rightOffset ) { 1404 if ( leftOffset < rightOffset ) {
1402 setGivenName( parts[ leftOffset ] ); 1405 setGivenName( parts[ leftOffset ] );
1403 leftOffset++; 1406 leftOffset++;
1404 } 1407 }
1405 1408
1406 QString additionalName; 1409 QString additionalName;
1407 while ( leftOffset < rightOffset ) { 1410 while ( leftOffset < rightOffset ) {
1408 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); 1411 additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] );
1409 leftOffset++; 1412 leftOffset++;
1410 } 1413 }
1411 setAdditionalName( additionalName ); 1414 setAdditionalName( additionalName );
1412 } 1415 }
1413} 1416}
1414 1417
1415QString Addressee::realName() const 1418QString Addressee::realName() const
1416{ 1419{
1417 if ( !formattedName().isEmpty() ) 1420 if ( !formattedName().isEmpty() )
1418 return formattedName(); 1421 return formattedName();
1419 1422
1420 QString n = assembledName(); 1423 QString n = assembledName();
1421 1424
1422 if ( n.isEmpty() ) 1425 if ( n.isEmpty() )
1423 n = name(); 1426 n = name();
1424 1427
1425 return n; 1428 return n;
1426} 1429}
1427 1430
1428QString Addressee::assembledName() const 1431QString Addressee::assembledName() const
1429{ 1432{
1430 QString name = prefix() + " " + givenName() + " " + additionalName() + " " + 1433 QString name = prefix() + " " + givenName() + " " + additionalName() + " " +
1431 familyName() + " " + suffix(); 1434 familyName() + " " + suffix();
1432 1435
1433 return name.simplifyWhiteSpace(); 1436 return name.simplifyWhiteSpace();
1434} 1437}
1435 1438
1436QString Addressee::fullEmail( const QString &email ) const 1439QString Addressee::fullEmail( const QString &email ) const
1437{ 1440{
1438 QString e; 1441 QString e;
1439 if ( email.isNull() ) { 1442 if ( email.isNull() ) {
1440 e = preferredEmail(); 1443 e = preferredEmail();
1441 } else { 1444 } else {
1442 e = email; 1445 e = email;
1443 } 1446 }
1444 if ( e.isEmpty() ) return QString::null; 1447 if ( e.isEmpty() ) return QString::null;
1445 1448
1446 QString text; 1449 QString text;
1447 if ( realName().isEmpty() ) 1450 if ( realName().isEmpty() )
1448 text = e; 1451 text = e;
1449 else 1452 else
1450 text = assembledName() + " <" + e + ">"; 1453 text = assembledName() + " <" + e + ">";
1451 1454
1452 return text; 1455 return text;
1453} 1456}
1454 1457
1455void Addressee::insertEmail( const QString &email, bool preferred ) 1458void Addressee::insertEmail( const QString &email, bool preferred )
1456{ 1459{
1457 detach(); 1460 detach();
1458 1461
1459 QStringList::Iterator it = mData->emails.find( email ); 1462 QStringList::Iterator it = mData->emails.find( email );
1460 1463
1461 if ( it != mData->emails.end() ) { 1464 if ( it != mData->emails.end() ) {
1462 if ( !preferred || it == mData->emails.begin() ) return; 1465 if ( !preferred || it == mData->emails.begin() ) return;
1463 mData->emails.remove( it ); 1466 mData->emails.remove( it );
1464 mData->emails.prepend( email ); 1467 mData->emails.prepend( email );
1465 } else { 1468 } else {
1466 if ( preferred ) { 1469 if ( preferred ) {
1467 mData->emails.prepend( email ); 1470 mData->emails.prepend( email );
1468 } else { 1471 } else {
1469 mData->emails.append( email ); 1472 mData->emails.append( email );
1470 } 1473 }
1471 } 1474 }
1472} 1475}
1473 1476
1474void Addressee::removeEmail( const QString &email ) 1477void Addressee::removeEmail( const QString &email )
1475{ 1478{
1476 detach(); 1479 detach();
1477 1480
1478 QStringList::Iterator it = mData->emails.find( email ); 1481 QStringList::Iterator it = mData->emails.find( email );
1479 if ( it == mData->emails.end() ) return; 1482 if ( it == mData->emails.end() ) return;
1480 1483
1481 mData->emails.remove( it ); 1484 mData->emails.remove( it );
1482} 1485}
1483 1486
1484QString Addressee::preferredEmail() const 1487QString Addressee::preferredEmail() const
1485{ 1488{
1486 if ( mData->emails.count() == 0 ) return QString::null; 1489 if ( mData->emails.count() == 0 ) return QString::null;
1487 else return mData->emails.first(); 1490 else return mData->emails.first();
1488} 1491}
1489 1492
1490QStringList Addressee::emails() const 1493QStringList Addressee::emails() const
1491{ 1494{
1492 return mData->emails; 1495 return mData->emails;
1493} 1496}
1494void Addressee::setEmails( const QStringList& emails ) { 1497void Addressee::setEmails( const QStringList& emails ) {
1495 detach(); 1498 detach();
1496 mData->emails = emails; 1499 mData->emails = emails;
1497} 1500}
1498void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber ) 1501void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber )
1499{ 1502{
1500 detach(); 1503 detach();
1501 mData->empty = false; 1504 mData->empty = false;
1502 1505
1503 PhoneNumber::List::Iterator it; 1506 PhoneNumber::List::Iterator it;
1504 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1507 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1505 if ( (*it).id() == phoneNumber.id() ) { 1508 if ( (*it).id() == phoneNumber.id() ) {
1506 *it = phoneNumber; 1509 *it = phoneNumber;
1507 return; 1510 return;
1508 } 1511 }
1509 } 1512 }
1510 mData->phoneNumbers.append( phoneNumber ); 1513 mData->phoneNumbers.append( phoneNumber );
1511} 1514}
1512 1515
1513void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber ) 1516void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber )
1514{ 1517{
1515 detach(); 1518 detach();
1516 1519
1517 PhoneNumber::List::Iterator it; 1520 PhoneNumber::List::Iterator it;
1518 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1521 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1519 if ( (*it).id() == phoneNumber.id() ) { 1522 if ( (*it).id() == phoneNumber.id() ) {
1520 mData->phoneNumbers.remove( it ); 1523 mData->phoneNumbers.remove( it );
1521 return; 1524 return;
1522 } 1525 }
1523 } 1526 }
1524} 1527}
1525 1528
1526PhoneNumber Addressee::phoneNumber( int type ) const 1529PhoneNumber Addressee::phoneNumber( int type ) const
1527{ 1530{
1528 PhoneNumber phoneNumber( "", type ); 1531 PhoneNumber phoneNumber( "", type );
1529 PhoneNumber::List::ConstIterator it; 1532 PhoneNumber::List::ConstIterator it;
1530 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1533 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1531 if ( matchBinaryPatternP( (*it).type(), type ) ) { 1534 if ( matchBinaryPatternP( (*it).type(), type ) ) {
1532 if ( (*it).type() & PhoneNumber::Pref ) 1535 if ( (*it).type() & PhoneNumber::Pref )
1533 return (*it); 1536 return (*it);
1534 else if ( phoneNumber.number().isEmpty() ) 1537 else if ( phoneNumber.number().isEmpty() )
1535 phoneNumber = (*it); 1538 phoneNumber = (*it);
1536 } 1539 }
1537 } 1540 }
1538 1541
1539 return phoneNumber; 1542 return phoneNumber;
1540} 1543}
1541 1544
1542PhoneNumber::List Addressee::phoneNumbers() const 1545PhoneNumber::List Addressee::phoneNumbers() const
1543{ 1546{
1544 return mData->phoneNumbers; 1547 return mData->phoneNumbers;
1545} 1548}
1546 1549
1547PhoneNumber::List Addressee::phoneNumbers( int type ) const 1550PhoneNumber::List Addressee::phoneNumbers( int type ) const
1548{ 1551{
1549 PhoneNumber::List list; 1552 PhoneNumber::List list;
1550 1553
1551 PhoneNumber::List::ConstIterator it; 1554 PhoneNumber::List::ConstIterator it;
1552 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1555 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1553 if ( matchBinaryPattern( (*it).type(), type ) ) { 1556 if ( matchBinaryPattern( (*it).type(), type ) ) {
1554 list.append( *it ); 1557 list.append( *it );
1555 } 1558 }
1556 } 1559 }
1557 return list; 1560 return list;
1558} 1561}
1559 1562
1560PhoneNumber Addressee::findPhoneNumber( const QString &id ) const 1563PhoneNumber Addressee::findPhoneNumber( const QString &id ) const
1561{ 1564{
1562 PhoneNumber::List::ConstIterator it; 1565 PhoneNumber::List::ConstIterator it;
1563 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { 1566 for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
1564 if ( (*it).id() == id ) { 1567 if ( (*it).id() == id ) {
1565 return *it; 1568 return *it;
1566 } 1569 }
1567 } 1570 }
1568 return PhoneNumber(); 1571 return PhoneNumber();
1569} 1572}
1570 1573
1571void Addressee::insertKey( const Key &key ) 1574void Addressee::insertKey( const Key &key )
1572{ 1575{
1573 detach(); 1576 detach();
1574 mData->empty = false; 1577 mData->empty = false;
1575 1578
1576 Key::List::Iterator it; 1579 Key::List::Iterator it;
1577 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1580 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1578 if ( (*it).id() == key.id() ) { 1581 if ( (*it).id() == key.id() ) {
1579 *it = key; 1582 *it = key;
1580 return; 1583 return;
1581 } 1584 }
1582 } 1585 }
1583 mData->keys.append( key ); 1586 mData->keys.append( key );
1584} 1587}
1585 1588
1586void Addressee::removeKey( const Key &key ) 1589void Addressee::removeKey( const Key &key )
1587{ 1590{
1588 detach(); 1591 detach();
1589 1592
1590 Key::List::Iterator it; 1593 Key::List::Iterator it;
1591 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1594 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1592 if ( (*it).id() == key.id() ) { 1595 if ( (*it).id() == key.id() ) {
1593 mData->keys.remove( key ); 1596 mData->keys.remove( key );
1594 return; 1597 return;
1595 } 1598 }
1596 } 1599 }
1597} 1600}
1598 1601
1599Key Addressee::key( int type, QString customTypeString ) const 1602Key Addressee::key( int type, QString customTypeString ) const
1600{ 1603{
1601 Key::List::ConstIterator it; 1604 Key::List::ConstIterator it;
1602 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1605 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1603 if ( (*it).type() == type ) { 1606 if ( (*it).type() == type ) {
1604 if ( type == Key::Custom ) { 1607 if ( type == Key::Custom ) {
1605 if ( customTypeString.isEmpty() ) { 1608 if ( customTypeString.isEmpty() ) {
1606 return *it; 1609 return *it;
1607 } else { 1610 } else {
1608 if ( (*it).customTypeString() == customTypeString ) 1611 if ( (*it).customTypeString() == customTypeString )
1609 return (*it); 1612 return (*it);
1610 } 1613 }
1611 } else { 1614 } else {
1612 return *it; 1615 return *it;
1613 } 1616 }
1614 } 1617 }
1615 } 1618 }
1616 return Key( QString(), type ); 1619 return Key( QString(), type );
1617} 1620}
1618void Addressee::setKeys( const Key::List& list ) { 1621void Addressee::setKeys( const Key::List& list ) {
1619 detach(); 1622 detach();
1620 mData->keys = list; 1623 mData->keys = list;
1621} 1624}
1622 1625
1623Key::List Addressee::keys() const 1626Key::List Addressee::keys() const
1624{ 1627{
1625 return mData->keys; 1628 return mData->keys;
1626} 1629}
1627 1630
1628Key::List Addressee::keys( int type, QString customTypeString ) const 1631Key::List Addressee::keys( int type, QString customTypeString ) const
1629{ 1632{
1630 Key::List list; 1633 Key::List list;
1631 1634
1632 Key::List::ConstIterator it; 1635 Key::List::ConstIterator it;
1633 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1636 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1634 if ( (*it).type() == type ) { 1637 if ( (*it).type() == type ) {
1635 if ( type == Key::Custom ) { 1638 if ( type == Key::Custom ) {
1636 if ( customTypeString.isEmpty() ) { 1639 if ( customTypeString.isEmpty() ) {
1637 list.append(*it); 1640 list.append(*it);
1638 } else { 1641 } else {
1639 if ( (*it).customTypeString() == customTypeString ) 1642 if ( (*it).customTypeString() == customTypeString )
1640 list.append(*it); 1643 list.append(*it);
1641 } 1644 }
1642 } else { 1645 } else {
1643 list.append(*it); 1646 list.append(*it);
1644 } 1647 }
1645 } 1648 }
1646 } 1649 }
1647 return list; 1650 return list;
1648} 1651}
1649 1652
1650Key Addressee::findKey( const QString &id ) const 1653Key Addressee::findKey( const QString &id ) const
1651{ 1654{
1652 Key::List::ConstIterator it; 1655 Key::List::ConstIterator it;
1653 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { 1656 for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
1654 if ( (*it).id() == id ) { 1657 if ( (*it).id() == id ) {
1655 return *it; 1658 return *it;
1656 } 1659 }
1657 } 1660 }
1658 return Key(); 1661 return Key();
1659} 1662}
1660 1663
1661QString Addressee::asString() const 1664QString Addressee::asString() const
1662{ 1665{
1663 return "Smith, agent Smith..."; 1666 return "Smith, agent Smith...";
1664} 1667}
1665 1668
1666void Addressee::dump() const 1669void Addressee::dump() const
1667{ 1670{
1668 return; 1671 return;
1669 kdDebug(5700) << "Addressee {" << endl; 1672 kdDebug(5700) << "Addressee {" << endl;
1670 1673
1671 kdDebug(5700) << " Uid: '" << uid() << "'" << endl; 1674 kdDebug(5700) << " Uid: '" << uid() << "'" << endl;
1672 1675
1673 kdDebug(5700) << " Name: '" << name() << "'" << endl; 1676 kdDebug(5700) << " Name: '" << name() << "'" << endl;
1674 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl; 1677 kdDebug(5700) << " FormattedName: '" << formattedName() << "'" << endl;
1675 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl; 1678 kdDebug(5700) << " FamilyName: '" << familyName() << "'" << endl;
1676 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl; 1679 kdDebug(5700) << " GivenName: '" << givenName() << "'" << endl;
1677 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl; 1680 kdDebug(5700) << " AdditionalName: '" << additionalName() << "'" << endl;
1678 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl; 1681 kdDebug(5700) << " Prefix: '" << prefix() << "'" << endl;
1679 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl; 1682 kdDebug(5700) << " Suffix: '" << suffix() << "'" << endl;
1680 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl; 1683 kdDebug(5700) << " NickName: '" << nickName() << "'" << endl;
1681 kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl; 1684 kdDebug(5700) << " Birthday: '" << birthday().toString() << "'" << endl;
1682 kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl; 1685 kdDebug(5700) << " Mailer: '" << mailer() << "'" << endl;
1683 kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl; 1686 kdDebug(5700) << " TimeZone: '" << timeZone().asString() << "'" << endl;
1684 kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl; 1687 kdDebug(5700) << " Geo: '" << geo().asString() << "'" << endl;
1685 kdDebug(5700) << " Title: '" << title() << "'" << endl; 1688 kdDebug(5700) << " Title: '" << title() << "'" << endl;
1686 kdDebug(5700) << " Role: '" << role() << "'" << endl; 1689 kdDebug(5700) << " Role: '" << role() << "'" << endl;
1687 kdDebug(5700) << " Organization: '" << organization() << "'" << endl; 1690 kdDebug(5700) << " Organization: '" << organization() << "'" << endl;
1688 kdDebug(5700) << " Note: '" << note() << "'" << endl; 1691 kdDebug(5700) << " Note: '" << note() << "'" << endl;
1689 kdDebug(5700) << " ProductId: '" << productId() << "'" << endl; 1692 kdDebug(5700) << " ProductId: '" << productId() << "'" << endl;
1690 kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl; 1693 kdDebug(5700) << " Revision: '" << revision().toString() << "'" << endl;
1691 kdDebug(5700) << " SortString: '" << sortString() << "'" << endl; 1694 kdDebug(5700) << " SortString: '" << sortString() << "'" << endl;
1692 kdDebug(5700) << " Url: '" << url().url() << "'" << endl; 1695 kdDebug(5700) << " Url: '" << url().url() << "'" << endl;
1693 kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl; 1696 kdDebug(5700) << " Secrecy: '" << secrecy().asString() << "'" << endl;
1694 kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl; 1697 kdDebug(5700) << " Logo: '" << logo().asString() << "'" << endl;
1695 kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl; 1698 kdDebug(5700) << " Photo: '" << photo().asString() << "'" << endl;
1696 kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl; 1699 kdDebug(5700) << " Sound: '" << sound().asString() << "'" << endl;
1697 kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl; 1700 kdDebug(5700) << " Agent: '" << agent().asString() << "'" << endl;
1698 1701
1699 kdDebug(5700) << " Emails {" << endl; 1702 kdDebug(5700) << " Emails {" << endl;
1700 QStringList e = emails(); 1703 QStringList e = emails();
1701 QStringList::ConstIterator it; 1704 QStringList::ConstIterator it;
1702 for( it = e.begin(); it != e.end(); ++it ) { 1705 for( it = e.begin(); it != e.end(); ++it ) {
1703 kdDebug(5700) << " " << (*it) << endl; 1706 kdDebug(5700) << " " << (*it) << endl;
1704 } 1707 }
1705 kdDebug(5700) << " }" << endl; 1708 kdDebug(5700) << " }" << endl;
1706 1709
1707 kdDebug(5700) << " PhoneNumbers {" << endl; 1710 kdDebug(5700) << " PhoneNumbers {" << endl;
1708 PhoneNumber::List p = phoneNumbers(); 1711 PhoneNumber::List p = phoneNumbers();
1709 PhoneNumber::List::ConstIterator it2; 1712 PhoneNumber::List::ConstIterator it2;
1710 for( it2 = p.begin(); it2 != p.end(); ++it2 ) { 1713 for( it2 = p.begin(); it2 != p.end(); ++it2 ) {
1711 kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl; 1714 kdDebug(5700) << " Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl;
1712 } 1715 }
1713 kdDebug(5700) << " }" << endl; 1716 kdDebug(5700) << " }" << endl;
1714 1717
1715 Address::List a = addresses(); 1718 Address::List a = addresses();
1716 Address::List::ConstIterator it3; 1719 Address::List::ConstIterator it3;
1717 for( it3 = a.begin(); it3 != a.end(); ++it3 ) { 1720 for( it3 = a.begin(); it3 != a.end(); ++it3 ) {
1718 (*it3).dump(); 1721 (*it3).dump();
1719 } 1722 }
1720 1723
1721 kdDebug(5700) << " Keys {" << endl; 1724 kdDebug(5700) << " Keys {" << endl;
1722 Key::List k = keys(); 1725 Key::List k = keys();
1723 Key::List::ConstIterator it4; 1726 Key::List::ConstIterator it4;
1724 for( it4 = k.begin(); it4 != k.end(); ++it4 ) { 1727 for( it4 = k.begin(); it4 != k.end(); ++it4 ) {
1725 kdDebug(5700) << " Type: " << int((*it4).type()) << 1728 kdDebug(5700) << " Type: " << int((*it4).type()) <<
1726 " Key: " << (*it4).textData() << 1729 " Key: " << (*it4).textData() <<
1727 " CustomString: " << (*it4).customTypeString() << endl; 1730 " CustomString: " << (*it4).customTypeString() << endl;
1728 } 1731 }
1729 kdDebug(5700) << " }" << endl; 1732 kdDebug(5700) << " }" << endl;
1730 1733
1731 kdDebug(5700) << "}" << endl; 1734 kdDebug(5700) << "}" << endl;
1732} 1735}
1733 1736
1734 1737
1735void Addressee::insertAddress( const Address &address ) 1738void Addressee::insertAddress( const Address &address )
1736{ 1739{
1737 detach(); 1740 detach();
1738 mData->empty = false; 1741 mData->empty = false;
1739 1742
1740 Address::List::Iterator it; 1743 Address::List::Iterator it;
1741 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1744 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1742 if ( (*it).id() == address.id() ) { 1745 if ( (*it).id() == address.id() ) {
1743 *it = address; 1746 *it = address;
1744 return; 1747 return;
1745 } 1748 }
1746 } 1749 }
1747 mData->addresses.append( address ); 1750 mData->addresses.append( address );
1748} 1751}
1749 1752
1750void Addressee::removeAddress( const Address &address ) 1753void Addressee::removeAddress( const Address &address )
1751{ 1754{
1752 detach(); 1755 detach();
1753 1756
1754 Address::List::Iterator it; 1757 Address::List::Iterator it;
1755 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1758 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1756 if ( (*it).id() == address.id() ) { 1759 if ( (*it).id() == address.id() ) {
1757 mData->addresses.remove( it ); 1760 mData->addresses.remove( it );
1758 return; 1761 return;
1759 } 1762 }
1760 } 1763 }
1761} 1764}
1762 1765
1763Address Addressee::address( int type ) const 1766Address Addressee::address( int type ) const
1764{ 1767{
1765 Address address( type ); 1768 Address address( type );
1766 Address::List::ConstIterator it; 1769 Address::List::ConstIterator it;
1767 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1770 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1768 if ( matchBinaryPatternA( (*it).type(), type ) ) { 1771 if ( matchBinaryPatternA( (*it).type(), type ) ) {
1769 if ( (*it).type() & Address::Pref ) 1772 if ( (*it).type() & Address::Pref )
1770 return (*it); 1773 return (*it);
1771 else if ( address.isEmpty() ) 1774 else if ( address.isEmpty() )
1772 address = (*it); 1775 address = (*it);
1773 } 1776 }
1774 } 1777 }
1775 1778
1776 return address; 1779 return address;
1777} 1780}
1778 1781
1779Address::List Addressee::addresses() const 1782Address::List Addressee::addresses() const
1780{ 1783{
1781 return mData->addresses; 1784 return mData->addresses;
1782} 1785}
1783 1786
1784Address::List Addressee::addresses( int type ) const 1787Address::List Addressee::addresses( int type ) const
1785{ 1788{
1786 Address::List list; 1789 Address::List list;
1787 1790
1788 Address::List::ConstIterator it; 1791 Address::List::ConstIterator it;
1789 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1792 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1790 if ( matchBinaryPattern( (*it).type(), type ) ) { 1793 if ( matchBinaryPattern( (*it).type(), type ) ) {
1791 list.append( *it ); 1794 list.append( *it );
1792 } 1795 }
1793 } 1796 }
1794 1797
1795 return list; 1798 return list;
1796} 1799}
1797 1800
1798Address Addressee::findAddress( const QString &id ) const 1801Address Addressee::findAddress( const QString &id ) const
1799{ 1802{
1800 Address::List::ConstIterator it; 1803 Address::List::ConstIterator it;
1801 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 1804 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
1802 if ( (*it).id() == id ) { 1805 if ( (*it).id() == id ) {
1803 return *it; 1806 return *it;
1804 } 1807 }
1805 } 1808 }
1806 return Address(); 1809 return Address();
1807} 1810}
1808 1811
1809void Addressee::insertCategory( const QString &c ) 1812void Addressee::insertCategory( const QString &c )
1810{ 1813{
1811 detach(); 1814 detach();
1812 mData->empty = false; 1815 mData->empty = false;
1813 1816
1814 if ( mData->categories.contains( c ) ) return; 1817 if ( mData->categories.contains( c ) ) return;
1815 1818
1816 mData->categories.append( c ); 1819 mData->categories.append( c );
1817} 1820}
1818 1821
1819void Addressee::removeCategory( const QString &c ) 1822void Addressee::removeCategory( const QString &c )
1820{ 1823{
1821 detach(); 1824 detach();
1822 1825
1823 QStringList::Iterator it = mData->categories.find( c ); 1826 QStringList::Iterator it = mData->categories.find( c );
1824 if ( it == mData->categories.end() ) return; 1827 if ( it == mData->categories.end() ) return;
1825 1828
1826 mData->categories.remove( it ); 1829 mData->categories.remove( it );
1827} 1830}
1828 1831
1829bool Addressee::hasCategory( const QString &c ) const 1832bool Addressee::hasCategory( const QString &c ) const
1830{ 1833{
1831 return ( mData->categories.contains( c ) ); 1834 return ( mData->categories.contains( c ) );
1832} 1835}
1833 1836
1834void Addressee::setCategories( const QStringList &c ) 1837void Addressee::setCategories( const QStringList &c )
1835{ 1838{
1836 detach(); 1839 detach();
1837 mData->empty = false; 1840 mData->empty = false;
1838 1841
1839 mData->categories = c; 1842 mData->categories = c;
1840} 1843}
1841 1844
1842QStringList Addressee::categories() const 1845QStringList Addressee::categories() const
1843{ 1846{
1844 return mData->categories; 1847 return mData->categories;
1845} 1848}
1846 1849
1847void Addressee::insertCustom( const QString &app, const QString &name, 1850void Addressee::insertCustom( const QString &app, const QString &name,
1848 const QString &value ) 1851 const QString &value )
1849{ 1852{
1850 if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return; 1853 if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return;
1851 1854
1852 detach(); 1855 detach();
1853 mData->empty = false; 1856 mData->empty = false;
1854 1857
1855 QString qualifiedName = app + "-" + name + ":"; 1858 QString qualifiedName = app + "-" + name + ":";
1856 1859
1857 QStringList::Iterator it; 1860 QStringList::Iterator it;
1858 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1861 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1859 if ( (*it).startsWith( qualifiedName ) ) { 1862 if ( (*it).startsWith( qualifiedName ) ) {
1860 (*it) = qualifiedName + value; 1863 (*it) = qualifiedName + value;
1861 return; 1864 return;
1862 } 1865 }
1863 } 1866 }
1864 mData->custom.append( qualifiedName + value ); 1867 mData->custom.append( qualifiedName + value );
1865} 1868}
1866 1869
1867void Addressee::removeCustom( const QString &app, const QString &name) 1870void Addressee::removeCustom( const QString &app, const QString &name)
1868{ 1871{
1869 detach(); 1872 detach();
1870 1873
1871 QString qualifiedName = app + "-" + name + ":"; 1874 QString qualifiedName = app + "-" + name + ":";
1872 1875
1873 QStringList::Iterator it; 1876 QStringList::Iterator it;
1874 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1877 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1875 if ( (*it).startsWith( qualifiedName ) ) { 1878 if ( (*it).startsWith( qualifiedName ) ) {
1876 mData->custom.remove( it ); 1879 mData->custom.remove( it );
1877 return; 1880 return;
1878 } 1881 }
1879 } 1882 }
1880} 1883}
1881 1884
1882QString Addressee::custom( const QString &app, const QString &name ) const 1885QString Addressee::custom( const QString &app, const QString &name ) const
1883{ 1886{
1884 QString qualifiedName = app + "-" + name + ":"; 1887 QString qualifiedName = app + "-" + name + ":";
1885 QString value; 1888 QString value;
1886 1889
1887 QStringList::ConstIterator it; 1890 QStringList::ConstIterator it;
1888 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { 1891 for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
1889 if ( (*it).startsWith( qualifiedName ) ) { 1892 if ( (*it).startsWith( qualifiedName ) ) {
1890 value = (*it).mid( (*it).find( ":" ) + 1 ); 1893 value = (*it).mid( (*it).find( ":" ) + 1 );
1891 break; 1894 break;
1892 } 1895 }
1893 } 1896 }
1894 1897
1895 return value; 1898 return value;
1896} 1899}
1897 1900
1898void Addressee::setCustoms( const QStringList &l ) 1901void Addressee::setCustoms( const QStringList &l )
1899{ 1902{
1900 detach(); 1903 detach();
1901 mData->empty = false; 1904 mData->empty = false;
1902 1905
1903 mData->custom = l; 1906 mData->custom = l;
1904} 1907}
1905 1908
1906QStringList Addressee::customs() const 1909QStringList Addressee::customs() const
1907{ 1910{
1908 return mData->custom; 1911 return mData->custom;
1909} 1912}
1910 1913
1911void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName, 1914void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName,
1912 QString &email) 1915 QString &email)
1913{ 1916{
1914 int startPos, endPos, len; 1917 int startPos, endPos, len;
1915 QString partA, partB, result; 1918 QString partA, partB, result;
1916 char endCh = '>'; 1919 char endCh = '>';
1917 1920
1918 startPos = rawEmail.find('<'); 1921 startPos = rawEmail.find('<');
1919 if (startPos < 0) 1922 if (startPos < 0)
1920 { 1923 {
1921 startPos = rawEmail.find('('); 1924 startPos = rawEmail.find('(');
1922 endCh = ')'; 1925 endCh = ')';
1923 } 1926 }
1924 if (startPos < 0) 1927 if (startPos < 0)
1925 { 1928 {
1926 // We couldn't find any separators, so we assume the whole string 1929 // We couldn't find any separators, so we assume the whole string
1927 // is the email address 1930 // is the email address
1928 email = rawEmail; 1931 email = rawEmail;
1929 fullName = ""; 1932 fullName = "";
1930 } 1933 }
1931 else 1934 else
1932 { 1935 {
1933 // We have a start position, try to find an end 1936 // We have a start position, try to find an end
1934 endPos = rawEmail.find(endCh, startPos+1); 1937 endPos = rawEmail.find(endCh, startPos+1);
1935 1938
1936 if (endPos < 0) 1939 if (endPos < 0)
1937 { 1940 {
1938 // We couldn't find the end of the email address. We can only 1941 // We couldn't find the end of the email address. We can only
1939 // assume the entire string is the email address. 1942 // assume the entire string is the email address.
1940 email = rawEmail; 1943 email = rawEmail;
1941 fullName = ""; 1944 fullName = "";
1942 } 1945 }
1943 else 1946 else
1944 { 1947 {
1945 // We have a start and end to the email address 1948 // We have a start and end to the email address
1946 1949
1947 // Grab the name part 1950 // Grab the name part
1948 fullName = rawEmail.left(startPos).stripWhiteSpace(); 1951 fullName = rawEmail.left(startPos).stripWhiteSpace();
1949 1952
1950 // grab the email part 1953 // grab the email part
1951 email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace(); 1954 email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace();
1952 1955
1953 // Check that we do not have any extra characters on the end of the 1956 // Check that we do not have any extra characters on the end of the
1954 // strings 1957 // strings
1955 len = fullName.length(); 1958 len = fullName.length();
1956 if (fullName[0]=='"' && fullName[len-1]=='"') 1959 if (fullName[0]=='"' && fullName[len-1]=='"')
1957 fullName = fullName.mid(1, len-2); 1960 fullName = fullName.mid(1, len-2);
1958 else if (fullName[0]=='<' && fullName[len-1]=='>') 1961 else if (fullName[0]=='<' && fullName[len-1]=='>')
1959 fullName = fullName.mid(1, len-2); 1962 fullName = fullName.mid(1, len-2);
1960 else if (fullName[0]=='(' && fullName[len-1]==')') 1963 else if (fullName[0]=='(' && fullName[len-1]==')')
1961 fullName = fullName.mid(1, len-2); 1964 fullName = fullName.mid(1, len-2);
1962 } 1965 }
1963 } 1966 }
1964} 1967}
1965 1968
1966void Addressee::setResource( Resource *resource ) 1969void Addressee::setResource( Resource *resource )
1967{ 1970{
1968 detach(); 1971 detach();
1969 mData->resource = resource; 1972 mData->resource = resource;
1970} 1973}
1971 1974
1972Resource *Addressee::resource() const 1975Resource *Addressee::resource() const
1973{ 1976{
1974 return mData->resource; 1977 return mData->resource;
1975} 1978}
1976 1979
1977//US 1980//US
1978QString Addressee::resourceLabel() 1981QString Addressee::resourceLabel()
1979{ 1982{
1980 return i18n("Resource"); 1983 return i18n("Resource");
1981} 1984}
1982 1985
1983void Addressee::setChanged( bool value ) 1986void Addressee::setChanged( bool value )
1984{ 1987{
1985 detach(); 1988 detach();
1986 mData->changed = value; 1989 mData->changed = value;
1987} 1990}
1988 1991
1989bool Addressee::changed() const 1992bool Addressee::changed() const
1990{ 1993{
1991 return mData->changed; 1994 return mData->changed;
1992} 1995}
1993 1996
1994void Addressee::setTagged( bool value ) 1997void Addressee::setTagged( bool value )
1995{ 1998{
1996 detach(); 1999 detach();
1997 mData->tagged = value; 2000 mData->tagged = value;
1998} 2001}
1999 2002
2000bool Addressee::tagged() const 2003bool Addressee::tagged() const
2001{ 2004{
2002 return mData->tagged; 2005 return mData->tagged;
2003} 2006}
2004 2007
2005QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a ) 2008QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a )
2006{ 2009{
2007 if (!a.mData) return s; 2010 if (!a.mData) return s;
2008 2011
2009 s << a.uid(); 2012 s << a.uid();
2010 2013
2011 s << a.mData->name; 2014 s << a.mData->name;
2012 s << a.mData->formattedName; 2015 s << a.mData->formattedName;
2013 s << a.mData->familyName; 2016 s << a.mData->familyName;
2014 s << a.mData->givenName; 2017 s << a.mData->givenName;
2015 s << a.mData->additionalName; 2018 s << a.mData->additionalName;
2016 s << a.mData->prefix; 2019 s << a.mData->prefix;
2017 s << a.mData->suffix; 2020 s << a.mData->suffix;
2018 s << a.mData->nickName; 2021 s << a.mData->nickName;
2019 s << a.mData->birthday; 2022 s << a.mData->birthday;
2020 s << a.mData->mailer; 2023 s << a.mData->mailer;
2021 s << a.mData->timeZone; 2024 s << a.mData->timeZone;
2022 s << a.mData->geo; 2025 s << a.mData->geo;
2023 s << a.mData->title; 2026 s << a.mData->title;
2024 s << a.mData->role; 2027 s << a.mData->role;
2025 s << a.mData->organization; 2028 s << a.mData->organization;
2026 s << a.mData->note; 2029 s << a.mData->note;
2027 s << a.mData->productId; 2030 s << a.mData->productId;
2028 s << a.mData->revision; 2031 s << a.mData->revision;
2029 s << a.mData->sortString; 2032 s << a.mData->sortString;
2030 s << a.mData->url; 2033 s << a.mData->url;
2031 s << a.mData->secrecy; 2034 s << a.mData->secrecy;
2032 s << a.mData->logo; 2035 s << a.mData->logo;
2033 s << a.mData->photo; 2036 s << a.mData->photo;
2034 s << a.mData->sound; 2037 s << a.mData->sound;
2035 s << a.mData->agent; 2038 s << a.mData->agent;
2036 s << a.mData->phoneNumbers; 2039 s << a.mData->phoneNumbers;
2037 s << a.mData->addresses; 2040 s << a.mData->addresses;
2038 s << a.mData->emails; 2041 s << a.mData->emails;
2039 s << a.mData->categories; 2042 s << a.mData->categories;
2040 s << a.mData->custom; 2043 s << a.mData->custom;
2041 s << a.mData->keys; 2044 s << a.mData->keys;
2042 return s; 2045 return s;
2043} 2046}
2044 2047
2045QDataStream &KABC::operator>>( QDataStream &s, Addressee &a ) 2048QDataStream &KABC::operator>>( QDataStream &s, Addressee &a )
2046{ 2049{
2047 if (!a.mData) return s; 2050 if (!a.mData) return s;
2048 2051
2049 s >> a.mData->uid; 2052 s >> a.mData->uid;
2050 2053
2051 s >> a.mData->name; 2054 s >> a.mData->name;
2052 s >> a.mData->formattedName; 2055 s >> a.mData->formattedName;
2053 s >> a.mData->familyName; 2056 s >> a.mData->familyName;
2054 s >> a.mData->givenName; 2057 s >> a.mData->givenName;
2055 s >> a.mData->additionalName; 2058 s >> a.mData->additionalName;
2056 s >> a.mData->prefix; 2059 s >> a.mData->prefix;
2057 s >> a.mData->suffix; 2060 s >> a.mData->suffix;
2058 s >> a.mData->nickName; 2061 s >> a.mData->nickName;
2059 s >> a.mData->birthday; 2062 s >> a.mData->birthday;
2060 s >> a.mData->mailer; 2063 s >> a.mData->mailer;
2061 s >> a.mData->timeZone; 2064 s >> a.mData->timeZone;
2062 s >> a.mData->geo; 2065 s >> a.mData->geo;
2063 s >> a.mData->title; 2066 s >> a.mData->title;
2064 s >> a.mData->role; 2067 s >> a.mData->role;
2065 s >> a.mData->organization; 2068 s >> a.mData->organization;
2066 s >> a.mData->note; 2069 s >> a.mData->note;
2067 s >> a.mData->productId; 2070 s >> a.mData->productId;
2068 s >> a.mData->revision; 2071 s >> a.mData->revision;
2069 s >> a.mData->sortString; 2072 s >> a.mData->sortString;
2070 s >> a.mData->url; 2073 s >> a.mData->url;
2071 s >> a.mData->secrecy; 2074 s >> a.mData->secrecy;
2072 s >> a.mData->logo; 2075 s >> a.mData->logo;
2073 s >> a.mData->photo; 2076 s >> a.mData->photo;
2074 s >> a.mData->sound; 2077 s >> a.mData->sound;
2075 s >> a.mData->agent; 2078 s >> a.mData->agent;
2076 s >> a.mData->phoneNumbers; 2079 s >> a.mData->phoneNumbers;
2077 s >> a.mData->addresses; 2080 s >> a.mData->addresses;
2078 s >> a.mData->emails; 2081 s >> a.mData->emails;
2079 s >> a.mData->categories; 2082 s >> a.mData->categories;
2080 s >> a.mData->custom; 2083 s >> a.mData->custom;
2081 s >> a.mData->keys; 2084 s >> a.mData->keys;
2082 2085
2083 a.mData->empty = false; 2086 a.mData->empty = false;
2084 2087
2085 return s; 2088 return s;
2086} 2089}
2087bool matchBinaryPattern( int value, int pattern ) 2090bool matchBinaryPattern( int value, int pattern )
2088{ 2091{
2089 /** 2092 /**
2090 We want to match all telephonnumbers/addresses which have the bits in the 2093 We want to match all telephonnumbers/addresses which have the bits in the
2091 pattern set. More are allowed. 2094 pattern set. More are allowed.
2092 if pattern == 0 we have a special handling, then we want only those with 2095 if pattern == 0 we have a special handling, then we want only those with