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