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