summaryrefslogtreecommitdiffabout
path: root/kabc
authorzautrix <zautrix>2004-09-19 09:00:55 (UTC)
committer zautrix <zautrix>2004-09-19 09:00:55 (UTC)
commit787181d34f0d195ad72c9cf6aedbc317b6dd713e (patch) (unidiff)
treeac49d2b1d7887f96f3834458071b89e77b59218b /kabc
parentf370d0f89bcaeeb68bd60152a9812a9cd55e5d8a (diff)
downloadkdepimpi-787181d34f0d195ad72c9cf6aedbc317b6dd713e.zip
kdepimpi-787181d34f0d195ad72c9cf6aedbc317b6dd713e.tar.gz
kdepimpi-787181d34f0d195ad72c9cf6aedbc317b6dd713e.tar.bz2
more AB sync
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp31
-rw-r--r--kabc/addressee.cpp19
-rw-r--r--kabc/addressee.h1
-rw-r--r--kabc/stdaddressbook.cpp7
4 files changed, 43 insertions, 15 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index ec9f893..46a9cf4 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -1,849 +1,866 @@
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 41
42#include <kglobal.h> 42#include <kglobal.h>
43#include <klocale.h> 43#include <klocale.h>
44#include <kdebug.h> 44#include <kdebug.h>
45#include <libkcal/syncdefines.h> 45#include <libkcal/syncdefines.h>
46#include "addressbook.h" 46#include "addressbook.h"
47#include "resource.h" 47#include "resource.h"
48 48
49//US #include "addressbook.moc" 49//US #include "addressbook.moc"
50 50
51using namespace KABC; 51using namespace KABC;
52 52
53struct AddressBook::AddressBookData 53struct AddressBook::AddressBookData
54{ 54{
55 Addressee::List mAddressees; 55 Addressee::List mAddressees;
56 Addressee::List mRemovedAddressees; 56 Addressee::List mRemovedAddressees;
57 Field::List mAllFields; 57 Field::List mAllFields;
58 KConfig *mConfig; 58 KConfig *mConfig;
59 KRES::Manager<Resource> *mManager; 59 KRES::Manager<Resource> *mManager;
60//US ErrorHandler *mErrorHandler; 60//US ErrorHandler *mErrorHandler;
61}; 61};
62 62
63struct AddressBook::Iterator::IteratorData 63struct AddressBook::Iterator::IteratorData
64{ 64{
65 Addressee::List::Iterator mIt; 65 Addressee::List::Iterator mIt;
66}; 66};
67 67
68struct AddressBook::ConstIterator::ConstIteratorData 68struct AddressBook::ConstIterator::ConstIteratorData
69{ 69{
70 Addressee::List::ConstIterator mIt; 70 Addressee::List::ConstIterator mIt;
71}; 71};
72 72
73AddressBook::Iterator::Iterator() 73AddressBook::Iterator::Iterator()
74{ 74{
75 d = new IteratorData; 75 d = new IteratorData;
76} 76}
77 77
78AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) 78AddressBook::Iterator::Iterator( const AddressBook::Iterator &i )
79{ 79{
80 d = new IteratorData; 80 d = new IteratorData;
81 d->mIt = i.d->mIt; 81 d->mIt = i.d->mIt;
82} 82}
83 83
84AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) 84AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i )
85{ 85{
86 if( this == &i ) return *this; // guard against self assignment 86 if( this == &i ) return *this; // guard against self assignment
87 delete d; // delete the old data the Iterator was completely constructed before 87 delete d; // delete the old data the Iterator was completely constructed before
88 d = new IteratorData; 88 d = new IteratorData;
89 d->mIt = i.d->mIt; 89 d->mIt = i.d->mIt;
90 return *this; 90 return *this;
91} 91}
92 92
93AddressBook::Iterator::~Iterator() 93AddressBook::Iterator::~Iterator()
94{ 94{
95 delete d; 95 delete d;
96} 96}
97 97
98const Addressee &AddressBook::Iterator::operator*() const 98const Addressee &AddressBook::Iterator::operator*() const
99{ 99{
100 return *(d->mIt); 100 return *(d->mIt);
101} 101}
102 102
103Addressee &AddressBook::Iterator::operator*() 103Addressee &AddressBook::Iterator::operator*()
104{ 104{
105 return *(d->mIt); 105 return *(d->mIt);
106} 106}
107 107
108Addressee *AddressBook::Iterator::operator->() 108Addressee *AddressBook::Iterator::operator->()
109{ 109{
110 return &(*(d->mIt)); 110 return &(*(d->mIt));
111} 111}
112 112
113AddressBook::Iterator &AddressBook::Iterator::operator++() 113AddressBook::Iterator &AddressBook::Iterator::operator++()
114{ 114{
115 (d->mIt)++; 115 (d->mIt)++;
116 return *this; 116 return *this;
117} 117}
118 118
119AddressBook::Iterator &AddressBook::Iterator::operator++(int) 119AddressBook::Iterator &AddressBook::Iterator::operator++(int)
120{ 120{
121 (d->mIt)++; 121 (d->mIt)++;
122 return *this; 122 return *this;
123} 123}
124 124
125AddressBook::Iterator &AddressBook::Iterator::operator--() 125AddressBook::Iterator &AddressBook::Iterator::operator--()
126{ 126{
127 (d->mIt)--; 127 (d->mIt)--;
128 return *this; 128 return *this;
129} 129}
130 130
131AddressBook::Iterator &AddressBook::Iterator::operator--(int) 131AddressBook::Iterator &AddressBook::Iterator::operator--(int)
132{ 132{
133 (d->mIt)--; 133 (d->mIt)--;
134 return *this; 134 return *this;
135} 135}
136 136
137bool AddressBook::Iterator::operator==( const Iterator &it ) 137bool AddressBook::Iterator::operator==( const Iterator &it )
138{ 138{
139 return ( d->mIt == it.d->mIt ); 139 return ( d->mIt == it.d->mIt );
140} 140}
141 141
142bool AddressBook::Iterator::operator!=( const Iterator &it ) 142bool AddressBook::Iterator::operator!=( const Iterator &it )
143{ 143{
144 return ( d->mIt != it.d->mIt ); 144 return ( d->mIt != it.d->mIt );
145} 145}
146 146
147 147
148AddressBook::ConstIterator::ConstIterator() 148AddressBook::ConstIterator::ConstIterator()
149{ 149{
150 d = new ConstIteratorData; 150 d = new ConstIteratorData;
151} 151}
152 152
153AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) 153AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i )
154{ 154{
155 d = new ConstIteratorData; 155 d = new ConstIteratorData;
156 d->mIt = i.d->mIt; 156 d->mIt = i.d->mIt;
157} 157}
158 158
159AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) 159AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i )
160{ 160{
161 if( this == &i ) return *this; // guard for self assignment 161 if( this == &i ) return *this; // guard for self assignment
162 delete d; // delete the old data because the Iterator was really constructed before 162 delete d; // delete the old data because the Iterator was really constructed before
163 d = new ConstIteratorData; 163 d = new ConstIteratorData;
164 d->mIt = i.d->mIt; 164 d->mIt = i.d->mIt;
165 return *this; 165 return *this;
166} 166}
167 167
168AddressBook::ConstIterator::~ConstIterator() 168AddressBook::ConstIterator::~ConstIterator()
169{ 169{
170 delete d; 170 delete d;
171} 171}
172 172
173const Addressee &AddressBook::ConstIterator::operator*() const 173const Addressee &AddressBook::ConstIterator::operator*() const
174{ 174{
175 return *(d->mIt); 175 return *(d->mIt);
176} 176}
177 177
178const Addressee* AddressBook::ConstIterator::operator->() const 178const Addressee* AddressBook::ConstIterator::operator->() const
179{ 179{
180 return &(*(d->mIt)); 180 return &(*(d->mIt));
181} 181}
182 182
183AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() 183AddressBook::ConstIterator &AddressBook::ConstIterator::operator++()
184{ 184{
185 (d->mIt)++; 185 (d->mIt)++;
186 return *this; 186 return *this;
187} 187}
188 188
189AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) 189AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int)
190{ 190{
191 (d->mIt)++; 191 (d->mIt)++;
192 return *this; 192 return *this;
193} 193}
194 194
195AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() 195AddressBook::ConstIterator &AddressBook::ConstIterator::operator--()
196{ 196{
197 (d->mIt)--; 197 (d->mIt)--;
198 return *this; 198 return *this;
199} 199}
200 200
201AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) 201AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int)
202{ 202{
203 (d->mIt)--; 203 (d->mIt)--;
204 return *this; 204 return *this;
205} 205}
206 206
207bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) 207bool AddressBook::ConstIterator::operator==( const ConstIterator &it )
208{ 208{
209 return ( d->mIt == it.d->mIt ); 209 return ( d->mIt == it.d->mIt );
210} 210}
211 211
212bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) 212bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
213{ 213{
214 return ( d->mIt != it.d->mIt ); 214 return ( d->mIt != it.d->mIt );
215} 215}
216 216
217 217
218AddressBook::AddressBook() 218AddressBook::AddressBook()
219{ 219{
220 init(0, "contact"); 220 init(0, "contact");
221} 221}
222 222
223AddressBook::AddressBook( const QString &config ) 223AddressBook::AddressBook( const QString &config )
224{ 224{
225 init(config, "contact"); 225 init(config, "contact");
226} 226}
227 227
228AddressBook::AddressBook( const QString &config, const QString &family ) 228AddressBook::AddressBook( const QString &config, const QString &family )
229{ 229{
230 init(config, family); 230 init(config, family);
231 231
232} 232}
233 233
234// the default family is "contact" 234// the default family is "contact"
235void AddressBook::init(const QString &config, const QString &family ) 235void AddressBook::init(const QString &config, const QString &family )
236{ 236{
237 blockLSEchange = false; 237 blockLSEchange = false;
238 d = new AddressBookData; 238 d = new AddressBookData;
239 QString fami = family; 239 QString fami = family;
240 qDebug("new ab "); 240 qDebug("new ab ");
241 if (config != 0) { 241 if (config != 0) {
242 qDebug("config != 0 "); 242 qDebug("config != 0 ");
243 if ( family == "syncContact" ) { 243 if ( family == "syncContact" ) {
244 qDebug("creating sync config "); 244 qDebug("creating sync config ");
245 fami = "contact"; 245 fami = "contact";
246 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); 246 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") );
247 con->setGroup( "General" ); 247 con->setGroup( "General" );
248 con->writeEntry( "ResourceKeys", QString("sync") ); 248 con->writeEntry( "ResourceKeys", QString("sync") );
249 con->writeEntry( "Standard", QString("sync") ); 249 con->writeEntry( "Standard", QString("sync") );
250 con->setGroup( "Resource_sync" ); 250 con->setGroup( "Resource_sync" );
251 con->writeEntry( "FileFormat", QString("vcard") ); 251 con->writeEntry( "FileFormat", QString("vcard") );
252 con->writeEntry( "FileName", config ); 252 con->writeEntry( "FileName", config );
253 con->writeEntry( "ResourceIdentifier", QString("sync") ); 253 con->writeEntry( "ResourceIdentifier", QString("sync") );
254 con->writeEntry( "ResourceName", QString("sync_res") ); 254 con->writeEntry( "ResourceName", QString("sync_res") );
255 con->writeEntry( "ResourceType", QString("file") ); 255 con->writeEntry( "ResourceType", QString("file") );
256 //con->sync(); 256 //con->sync();
257 d->mConfig = con; 257 d->mConfig = con;
258 } 258 }
259 else 259 else
260 d->mConfig = new KConfig( locateLocal("config", config) ); 260 d->mConfig = new KConfig( locateLocal("config", config) );
261// qDebug("AddressBook::init 1 config=%s",config.latin1() ); 261// qDebug("AddressBook::init 1 config=%s",config.latin1() );
262 } 262 }
263 else { 263 else {
264 d->mConfig = 0; 264 d->mConfig = 0;
265// qDebug("AddressBook::init 1 config=0"); 265// qDebug("AddressBook::init 1 config=0");
266 } 266 }
267 267
268//US d->mErrorHandler = 0; 268//US d->mErrorHandler = 0;
269 d->mManager = new KRES::Manager<Resource>( fami, false ); 269 d->mManager = new KRES::Manager<Resource>( fami, false );
270 d->mManager->readConfig( d->mConfig ); 270 d->mManager->readConfig( d->mConfig );
271 if ( family == "syncContact" ) { 271 if ( family == "syncContact" ) {
272 KRES::Manager<Resource> *manager = d->mManager; 272 KRES::Manager<Resource> *manager = d->mManager;
273 KRES::Manager<Resource>::ActiveIterator it; 273 KRES::Manager<Resource>::ActiveIterator it;
274 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 274 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
275 (*it)->setAddressBook( this ); 275 (*it)->setAddressBook( this );
276 if ( !(*it)->open() ) 276 if ( !(*it)->open() )
277 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 277 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
278 } 278 }
279 Resource *res = standardResource(); 279 Resource *res = standardResource();
280 if ( !res ) { 280 if ( !res ) {
281 qDebug("ERROR: no standard resource"); 281 qDebug("ERROR: no standard resource");
282 res = manager->createResource( "file" ); 282 res = manager->createResource( "file" );
283 if ( res ) 283 if ( res )
284 { 284 {
285 addResource( res ); 285 addResource( res );
286 } 286 }
287 else 287 else
288 qDebug(" No resource available!!!"); 288 qDebug(" No resource available!!!");
289 } 289 }
290 setStandardResource( res ); 290 setStandardResource( res );
291 manager->writeConfig(); 291 manager->writeConfig();
292 } 292 }
293 addCustomField( i18n( "Department" ), KABC::Field::Organization, 293 addCustomField( i18n( "Department" ), KABC::Field::Organization,
294 "X-Department", "KADDRESSBOOK" ); 294 "X-Department", "KADDRESSBOOK" );
295 addCustomField( i18n( "Profession" ), KABC::Field::Organization, 295 addCustomField( i18n( "Profession" ), KABC::Field::Organization,
296 "X-Profession", "KADDRESSBOOK" ); 296 "X-Profession", "KADDRESSBOOK" );
297 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 297 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
298 "X-AssistantsName", "KADDRESSBOOK" ); 298 "X-AssistantsName", "KADDRESSBOOK" );
299 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 299 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
300 "X-ManagersName", "KADDRESSBOOK" ); 300 "X-ManagersName", "KADDRESSBOOK" );
301 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 301 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
302 "X-SpousesName", "KADDRESSBOOK" ); 302 "X-SpousesName", "KADDRESSBOOK" );
303 addCustomField( i18n( "Office" ), KABC::Field::Personal, 303 addCustomField( i18n( "Office" ), KABC::Field::Personal,
304 "X-Office", "KADDRESSBOOK" ); 304 "X-Office", "KADDRESSBOOK" );
305 addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 305 addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
306 "X-IMAddress", "KADDRESSBOOK" ); 306 "X-IMAddress", "KADDRESSBOOK" );
307 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 307 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
308 "X-Anniversary", "KADDRESSBOOK" ); 308 "X-Anniversary", "KADDRESSBOOK" );
309 309
310 //US added this field to become compatible with Opie/qtopia addressbook 310 //US added this field to become compatible with Opie/qtopia addressbook
311 // values can be "female" or "male" or "". An empty field represents undefined. 311 // values can be "female" or "male" or "". An empty field represents undefined.
312 addCustomField( i18n( "Gender" ), KABC::Field::Personal, 312 addCustomField( i18n( "Gender" ), KABC::Field::Personal,
313 "X-Gender", "KADDRESSBOOK" ); 313 "X-Gender", "KADDRESSBOOK" );
314 addCustomField( i18n( "Children" ), KABC::Field::Personal, 314 addCustomField( i18n( "Children" ), KABC::Field::Personal,
315 "X-Children", "KADDRESSBOOK" ); 315 "X-Children", "KADDRESSBOOK" );
316 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 316 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
317 "X-FreeBusyUrl", "KADDRESSBOOK" ); 317 "X-FreeBusyUrl", "KADDRESSBOOK" );
318 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, 318 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal,
319 "X-ExternalID", "KADDRESSBOOK" ); 319 "X-ExternalID", "KADDRESSBOOK" );
320} 320}
321 321
322AddressBook::~AddressBook() 322AddressBook::~AddressBook()
323{ 323{
324 delete d->mConfig; d->mConfig = 0; 324 delete d->mConfig; d->mConfig = 0;
325 delete d->mManager; d->mManager = 0; 325 delete d->mManager; d->mManager = 0;
326//US delete d->mErrorHandler; d->mErrorHandler = 0; 326//US delete d->mErrorHandler; d->mErrorHandler = 0;
327 delete d; d = 0; 327 delete d; d = 0;
328} 328}
329 329
330bool AddressBook::load() 330bool AddressBook::load()
331{ 331{
332 332
333 333
334 clear(); 334 clear();
335 335
336 KRES::Manager<Resource>::ActiveIterator it; 336 KRES::Manager<Resource>::ActiveIterator it;
337 bool ok = true; 337 bool ok = true;
338 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 338 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
339 if ( !(*it)->load() ) { 339 if ( !(*it)->load() ) {
340 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 340 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
341 ok = false; 341 ok = false;
342 } 342 }
343 343
344 // mark all addressees as unchanged 344 // mark all addressees as unchanged
345 Addressee::List::Iterator addrIt; 345 Addressee::List::Iterator addrIt;
346 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) 346 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) {
347 (*addrIt).setChanged( false ); 347 (*addrIt).setChanged( false );
348 348 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" );
349 if ( !id.isEmpty() ) {
350 //qDebug("setId aa %s ", id.latin1());
351 (*addrIt).setIDStr(id );
352 }
353 }
349 blockLSEchange = true; 354 blockLSEchange = true;
350 return ok; 355 return ok;
351} 356}
352 357
353bool AddressBook::save( Ticket *ticket ) 358bool AddressBook::save( Ticket *ticket )
354{ 359{
355 kdDebug(5700) << "AddressBook::save()"<< endl; 360 kdDebug(5700) << "AddressBook::save()"<< endl;
356 361
357 if ( ticket->resource() ) { 362 if ( ticket->resource() ) {
358 deleteRemovedAddressees(); 363 deleteRemovedAddressees();
359 return ticket->resource()->save( ticket ); 364 return ticket->resource()->save( ticket );
360 } 365 }
361 366
362 return false; 367 return false;
363} 368}
364bool AddressBook::saveAB() 369bool AddressBook::saveAB()
365{ 370{
366 bool ok = true; 371 bool ok = true;
367 372
368 deleteRemovedAddressees(); 373 deleteRemovedAddressees();
369 374 Iterator ait;
375 for ( ait = begin(); ait != end(); ++ait ) {
376 if ( !(*ait).IDStr().isEmpty() ) {
377 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
378 }
379 }
370 KRES::Manager<Resource>::ActiveIterator it; 380 KRES::Manager<Resource>::ActiveIterator it;
371 KRES::Manager<Resource> *manager = d->mManager; 381 KRES::Manager<Resource> *manager = d->mManager;
372 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 382 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
373 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 383 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
374 Ticket *ticket = requestSaveTicket( *it ); 384 Ticket *ticket = requestSaveTicket( *it );
375// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 385// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
376 if ( !ticket ) { 386 if ( !ticket ) {
377 error( i18n( "Unable to save to resource '%1'. It is locked." ) 387 error( i18n( "Unable to save to resource '%1'. It is locked." )
378 .arg( (*it)->resourceName() ) ); 388 .arg( (*it)->resourceName() ) );
379 return false; 389 return false;
380 } 390 }
381 391
382 //if ( !save( ticket ) ) 392 //if ( !save( ticket ) )
383 if ( ticket->resource() ) { 393 if ( ticket->resource() ) {
384 if ( ! ticket->resource()->save( ticket ) ) 394 if ( ! ticket->resource()->save( ticket ) )
385 ok = false; 395 ok = false;
386 } else 396 } else
387 ok = false; 397 ok = false;
388 398
389 } 399 }
390 } 400 }
391 return ok; 401 return ok;
392} 402}
393 403
394AddressBook::Iterator AddressBook::begin() 404AddressBook::Iterator AddressBook::begin()
395{ 405{
396 Iterator it = Iterator(); 406 Iterator it = Iterator();
397 it.d->mIt = d->mAddressees.begin(); 407 it.d->mIt = d->mAddressees.begin();
398 return it; 408 return it;
399} 409}
400 410
401AddressBook::ConstIterator AddressBook::begin() const 411AddressBook::ConstIterator AddressBook::begin() const
402{ 412{
403 ConstIterator it = ConstIterator(); 413 ConstIterator it = ConstIterator();
404 it.d->mIt = d->mAddressees.begin(); 414 it.d->mIt = d->mAddressees.begin();
405 return it; 415 return it;
406} 416}
407 417
408AddressBook::Iterator AddressBook::end() 418AddressBook::Iterator AddressBook::end()
409{ 419{
410 Iterator it = Iterator(); 420 Iterator it = Iterator();
411 it.d->mIt = d->mAddressees.end(); 421 it.d->mIt = d->mAddressees.end();
412 return it; 422 return it;
413} 423}
414 424
415AddressBook::ConstIterator AddressBook::end() const 425AddressBook::ConstIterator AddressBook::end() const
416{ 426{
417 ConstIterator it = ConstIterator(); 427 ConstIterator it = ConstIterator();
418 it.d->mIt = d->mAddressees.end(); 428 it.d->mIt = d->mAddressees.end();
419 return it; 429 return it;
420} 430}
421 431
422void AddressBook::clear() 432void AddressBook::clear()
423{ 433{
424 d->mAddressees.clear(); 434 d->mAddressees.clear();
425} 435}
426 436
427Ticket *AddressBook::requestSaveTicket( Resource *resource ) 437Ticket *AddressBook::requestSaveTicket( Resource *resource )
428{ 438{
429 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 439 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
430 440
431 if ( !resource ) 441 if ( !resource )
432 { 442 {
433 qDebug("AddressBook::requestSaveTicket no resource" ); 443 qDebug("AddressBook::requestSaveTicket no resource" );
434 resource = standardResource(); 444 resource = standardResource();
435 } 445 }
436 446
437 KRES::Manager<Resource>::ActiveIterator it; 447 KRES::Manager<Resource>::ActiveIterator it;
438 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 448 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
439 if ( (*it) == resource ) { 449 if ( (*it) == resource ) {
440 if ( (*it)->readOnly() || !(*it)->isOpen() ) 450 if ( (*it)->readOnly() || !(*it)->isOpen() )
441 return 0; 451 return 0;
442 else 452 else
443 return (*it)->requestSaveTicket(); 453 return (*it)->requestSaveTicket();
444 } 454 }
445 } 455 }
446 456
447 return 0; 457 return 0;
448} 458}
449 459
450void AddressBook::insertAddressee( const Addressee &a, bool setRev ) 460void AddressBook::insertAddressee( const Addressee &a, bool setRev )
451{ 461{
452 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { 462 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
463 //qDebug("block insert ");
453 return; 464 return;
454 } 465 }
466 //qDebug("inserting.... %s ",a.uid().latin1() );
455 bool found = false; 467 bool found = false;
456 Addressee::List::Iterator it; 468 Addressee::List::Iterator it;
457 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 469 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
458 if ( a.uid() == (*it).uid() ) { 470 if ( a.uid() == (*it).uid() ) {
459 471
460 bool changed = false; 472 bool changed = false;
461 Addressee addr = a; 473 Addressee addr = a;
462 if ( addr != (*it) ) 474 if ( addr != (*it) )
463 changed = true; 475 changed = true;
464 476
465 (*it) = a; 477 (*it) = a;
466 if ( (*it).resource() == 0 ) 478 if ( (*it).resource() == 0 )
467 (*it).setResource( standardResource() ); 479 (*it).setResource( standardResource() );
468 480
469 if ( changed ) { 481 if ( changed ) {
470 if ( setRev ) { 482 if ( setRev ) {
471 483
472 // get rid of micro seconds 484 // get rid of micro seconds
473 QDateTime dt = QDateTime::currentDateTime(); 485 QDateTime dt = QDateTime::currentDateTime();
474 QTime t = dt.time(); 486 QTime t = dt.time();
475 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 487 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
476 (*it).setRevision( dt ); 488 (*it).setRevision( dt );
477 } 489 }
478 (*it).setChanged( true ); 490 (*it).setChanged( true );
479 } 491 }
480 492
481 found = true; 493 found = true;
482 } else { 494 } else {
483 if ( (*it).uid() == QString("last-syncAddressee-") ) { 495 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
484 QString name = (*it).uid().mid( 19 ); 496 QString name = (*it).uid().mid( 19 );
485 Addressee b = a; 497 Addressee b = a;
486 QString id = b.getID( name ); 498 QString id = b.getID( name );
487 if ( ! id.isEmpty() ) { 499 if ( ! id.isEmpty() ) {
488 QString des = (*it).note(); 500 QString des = (*it).note();
489 int startN; 501 int startN;
490 if( (startN = des.find( id ) ) >= 0 ) { 502 if( (startN = des.find( id ) ) >= 0 ) {
491 int endN = des.find( ",", startN+1 ); 503 int endN = des.find( ",", startN+1 );
492 des = des.left( startN ) + des.mid( endN+1 ); 504 des = des.left( startN ) + des.mid( endN+1 );
493 (*it).setNote( des ); 505 (*it).setNote( des );
494 } 506 }
495 } 507 }
496 } 508 }
497 } 509 }
498 } 510 }
499 if ( found ) 511 if ( found )
500 return; 512 return;
501 d->mAddressees.append( a ); 513 d->mAddressees.append( a );
502 Addressee& addr = d->mAddressees.last(); 514 Addressee& addr = d->mAddressees.last();
503 if ( addr.resource() == 0 ) 515 if ( addr.resource() == 0 )
504 addr.setResource( standardResource() ); 516 addr.setResource( standardResource() );
505 517
506 addr.setChanged( true ); 518 addr.setChanged( true );
507} 519}
508 520
509void AddressBook::removeAddressee( const Addressee &a ) 521void AddressBook::removeAddressee( const Addressee &a )
510{ 522{
511 Iterator it; 523 Iterator it;
512 Iterator it2; 524 Iterator it2;
513 bool found = false; 525 bool found = false;
514 for ( it = begin(); it != end(); ++it ) { 526 for ( it = begin(); it != end(); ++it ) {
515 if ( a.uid() == (*it).uid() ) { 527 if ( a.uid() == (*it).uid() ) {
516 found = true; 528 found = true;
517 it2 = it; 529 it2 = it;
518 } else { 530 } else {
519 if ( (*it).uid() == QString("last-syncAddressee-") ) { 531 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
520 QString name = (*it).uid().mid( 19 ); 532 QString name = (*it).uid().mid( 19 );
521 Addressee b = a; 533 Addressee b = a;
522 QString id = b.getID( name ); 534 QString id = b.getID( name );
523 if ( ! id.isEmpty() ) { 535 if ( ! id.isEmpty() ) {
524 QString des = (*it).note(); 536 QString des = (*it).note();
525 if( des.find( id ) < 0 ) { 537 if( des.find( id ) < 0 ) {
526 des += id + ","; 538 des += id + ",";
527 (*it).setNote( des ); 539 (*it).setNote( des );
528 } 540 }
529 } 541 }
530 } 542 }
531 543
532 } 544 }
533 } 545 }
534 546
535 if ( found ) 547 if ( found )
536 removeAddressee( it2 ); 548 removeAddressee( it2 );
537 549
538} 550}
539 551
540void AddressBook::removeDeletedAddressees() 552void AddressBook::removeDeletedAddressees()
541{ 553{
542 deleteRemovedAddressees(); 554 deleteRemovedAddressees();
543 Iterator it = begin(); 555 Iterator it = begin();
544 Iterator it2 ; 556 Iterator it2 ;
545 QDateTime dt ( QDate( 2004,1,1) ); 557 QDateTime dt ( QDate( 2004,1,1) );
546 while ( it != end() ) { 558 while ( it != end() ) {
547 (*it).setRevision( dt ); 559 (*it).setRevision( dt );
548 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 560 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" );
561 (*it).setIDStr("");
562 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE || (*it).uid().left( 19 ) == QString("last-syncAddressee-")) {
549 it2 = it; 563 it2 = it;
564 //qDebug("removing %s ",(*it).uid().latin1() );
550 ++it; 565 ++it;
551 removeAddressee( it2 ); 566 removeAddressee( it2 );
552 } else 567 } else {
568 //qDebug("skipping %s ",(*it).uid().latin1() );
553 ++it; 569 ++it;
570 }
554 } 571 }
555 deleteRemovedAddressees(); 572 deleteRemovedAddressees();
556} 573}
557 574
558void AddressBook::removeAddressee( const Iterator &it ) 575void AddressBook::removeAddressee( const Iterator &it )
559{ 576{
560 d->mRemovedAddressees.append( (*it) ); 577 d->mRemovedAddressees.append( (*it) );
561 d->mAddressees.remove( it.d->mIt ); 578 d->mAddressees.remove( it.d->mIt );
562} 579}
563 580
564AddressBook::Iterator AddressBook::find( const Addressee &a ) 581AddressBook::Iterator AddressBook::find( const Addressee &a )
565{ 582{
566 Iterator it; 583 Iterator it;
567 for ( it = begin(); it != end(); ++it ) { 584 for ( it = begin(); it != end(); ++it ) {
568 if ( a.uid() == (*it).uid() ) { 585 if ( a.uid() == (*it).uid() ) {
569 return it; 586 return it;
570 } 587 }
571 } 588 }
572 return end(); 589 return end();
573} 590}
574 591
575Addressee AddressBook::findByUid( const QString &uid ) 592Addressee AddressBook::findByUid( const QString &uid )
576{ 593{
577 Iterator it; 594 Iterator it;
578 for ( it = begin(); it != end(); ++it ) { 595 for ( it = begin(); it != end(); ++it ) {
579 if ( uid == (*it).uid() ) { 596 if ( uid == (*it).uid() ) {
580 return *it; 597 return *it;
581 } 598 }
582 } 599 }
583 return Addressee(); 600 return Addressee();
584} 601}
585#if 0 602#if 0
586Addressee::List AddressBook::getExternLastSyncAddressees() 603Addressee::List AddressBook::getExternLastSyncAddressees()
587{ 604{
588 Addressee::List results; 605 Addressee::List results;
589 606
590 Iterator it; 607 Iterator it;
591 for ( it = begin(); it != end(); ++it ) { 608 for ( it = begin(); it != end(); ++it ) {
592 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { 609 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
593 if ( (*it).familyName().left(4) == "!E: " ) 610 if ( (*it).familyName().left(4) == "!E: " )
594 results.append( *it ); 611 results.append( *it );
595 } 612 }
596 } 613 }
597 614
598 return results; 615 return results;
599} 616}
600#endif 617#endif
601void AddressBook::resetTempSyncStat() 618void AddressBook::resetTempSyncStat()
602{ 619{
603 Iterator it; 620 Iterator it;
604 for ( it = begin(); it != end(); ++it ) { 621 for ( it = begin(); it != end(); ++it ) {
605 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); 622 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
606 } 623 }
607 624
608} 625}
609 626
610QStringList AddressBook:: uidList() 627QStringList AddressBook:: uidList()
611{ 628{
612 QStringList results; 629 QStringList results;
613 Iterator it; 630 Iterator it;
614 for ( it = begin(); it != end(); ++it ) { 631 for ( it = begin(); it != end(); ++it ) {
615 results.append( (*it).uid() ); 632 results.append( (*it).uid() );
616 } 633 }
617 return results; 634 return results;
618} 635}
619 636
620 637
621Addressee::List AddressBook::allAddressees() 638Addressee::List AddressBook::allAddressees()
622{ 639{
623 return d->mAddressees; 640 return d->mAddressees;
624 641
625} 642}
626 643
627Addressee::List AddressBook::findByName( const QString &name ) 644Addressee::List AddressBook::findByName( const QString &name )
628{ 645{
629 Addressee::List results; 646 Addressee::List results;
630 647
631 Iterator it; 648 Iterator it;
632 for ( it = begin(); it != end(); ++it ) { 649 for ( it = begin(); it != end(); ++it ) {
633 if ( name == (*it).realName() ) { 650 if ( name == (*it).realName() ) {
634 results.append( *it ); 651 results.append( *it );
635 } 652 }
636 } 653 }
637 654
638 return results; 655 return results;
639} 656}
640 657
641Addressee::List AddressBook::findByEmail( const QString &email ) 658Addressee::List AddressBook::findByEmail( const QString &email )
642{ 659{
643 Addressee::List results; 660 Addressee::List results;
644 QStringList mailList; 661 QStringList mailList;
645 662
646 Iterator it; 663 Iterator it;
647 for ( it = begin(); it != end(); ++it ) { 664 for ( it = begin(); it != end(); ++it ) {
648 mailList = (*it).emails(); 665 mailList = (*it).emails();
649 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 666 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
650 if ( email == (*ite) ) { 667 if ( email == (*ite) ) {
651 results.append( *it ); 668 results.append( *it );
652 } 669 }
653 } 670 }
654 } 671 }
655 672
656 return results; 673 return results;
657} 674}
658 675
659Addressee::List AddressBook::findByCategory( const QString &category ) 676Addressee::List AddressBook::findByCategory( const QString &category )
660{ 677{
661 Addressee::List results; 678 Addressee::List results;
662 679
663 Iterator it; 680 Iterator it;
664 for ( it = begin(); it != end(); ++it ) { 681 for ( it = begin(); it != end(); ++it ) {
665 if ( (*it).hasCategory( category) ) { 682 if ( (*it).hasCategory( category) ) {
666 results.append( *it ); 683 results.append( *it );
667 } 684 }
668 } 685 }
669 686
670 return results; 687 return results;
671} 688}
672 689
673void AddressBook::dump() const 690void AddressBook::dump() const
674{ 691{
675 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; 692 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
676 693
677 ConstIterator it; 694 ConstIterator it;
678 for( it = begin(); it != end(); ++it ) { 695 for( it = begin(); it != end(); ++it ) {
679 (*it).dump(); 696 (*it).dump();
680 } 697 }
681 698
682 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; 699 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
683} 700}
684 701
685QString AddressBook::identifier() 702QString AddressBook::identifier()
686{ 703{
687 QStringList identifier; 704 QStringList identifier;
688 705
689 706
690 KRES::Manager<Resource>::ActiveIterator it; 707 KRES::Manager<Resource>::ActiveIterator it;
691 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 708 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
692 if ( !(*it)->identifier().isEmpty() ) 709 if ( !(*it)->identifier().isEmpty() )
693 identifier.append( (*it)->identifier() ); 710 identifier.append( (*it)->identifier() );
694 } 711 }
695 712
696 return identifier.join( ":" ); 713 return identifier.join( ":" );
697} 714}
698 715
699Field::List AddressBook::fields( int category ) 716Field::List AddressBook::fields( int category )
700{ 717{
701 if ( d->mAllFields.isEmpty() ) { 718 if ( d->mAllFields.isEmpty() ) {
702 d->mAllFields = Field::allFields(); 719 d->mAllFields = Field::allFields();
703 } 720 }
704 721
705 if ( category == Field::All ) return d->mAllFields; 722 if ( category == Field::All ) return d->mAllFields;
706 723
707 Field::List result; 724 Field::List result;
708 Field::List::ConstIterator it; 725 Field::List::ConstIterator it;
709 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { 726 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
710 if ( (*it)->category() & category ) result.append( *it ); 727 if ( (*it)->category() & category ) result.append( *it );
711 } 728 }
712 729
713 return result; 730 return result;
714} 731}
715 732
716bool AddressBook::addCustomField( const QString &label, int category, 733bool AddressBook::addCustomField( const QString &label, int category,
717 const QString &key, const QString &app ) 734 const QString &key, const QString &app )
718{ 735{
719 if ( d->mAllFields.isEmpty() ) { 736 if ( d->mAllFields.isEmpty() ) {
720 d->mAllFields = Field::allFields(); 737 d->mAllFields = Field::allFields();
721 } 738 }
722//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; 739//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app;
723 QString a = app.isNull() ? KGlobal::getAppName() : app; 740 QString a = app.isNull() ? KGlobal::getAppName() : app;
724 741
725 QString k = key.isNull() ? label : key; 742 QString k = key.isNull() ? label : key;
726 743
727 Field *field = Field::createCustomField( label, category, k, a ); 744 Field *field = Field::createCustomField( label, category, k, a );
728 745
729 if ( !field ) return false; 746 if ( !field ) return false;
730 747
731 d->mAllFields.append( field ); 748 d->mAllFields.append( field );
732 749
733 return true; 750 return true;
734} 751}
735 752
736QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) 753QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab )
737{ 754{
738 if (!ab.d) return s; 755 if (!ab.d) return s;
739 756
740 return s << ab.d->mAddressees; 757 return s << ab.d->mAddressees;
741} 758}
742 759
743QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) 760QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
744{ 761{
745 if (!ab.d) return s; 762 if (!ab.d) return s;
746 763
747 s >> ab.d->mAddressees; 764 s >> ab.d->mAddressees;
748 765
749 return s; 766 return s;
750} 767}
751 768
752bool AddressBook::addResource( Resource *resource ) 769bool AddressBook::addResource( Resource *resource )
753{ 770{
754 if ( !resource->open() ) { 771 if ( !resource->open() ) {
755 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; 772 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
756 return false; 773 return false;
757 } 774 }
758 775
759 resource->setAddressBook( this ); 776 resource->setAddressBook( this );
760 777
761 d->mManager->add( resource ); 778 d->mManager->add( resource );
762 return true; 779 return true;
763} 780}
764 781
765bool AddressBook::removeResource( Resource *resource ) 782bool AddressBook::removeResource( Resource *resource )
766{ 783{
767 resource->close(); 784 resource->close();
768 785
769 if ( resource == standardResource() ) 786 if ( resource == standardResource() )
770 d->mManager->setStandardResource( 0 ); 787 d->mManager->setStandardResource( 0 );
771 788
772 resource->setAddressBook( 0 ); 789 resource->setAddressBook( 0 );
773 790
774 d->mManager->remove( resource ); 791 d->mManager->remove( resource );
775 return true; 792 return true;
776} 793}
777 794
778QPtrList<Resource> AddressBook::resources() 795QPtrList<Resource> AddressBook::resources()
779{ 796{
780 QPtrList<Resource> list; 797 QPtrList<Resource> list;
781 798
782// qDebug("AddressBook::resources() 1"); 799// qDebug("AddressBook::resources() 1");
783 800
784 KRES::Manager<Resource>::ActiveIterator it; 801 KRES::Manager<Resource>::ActiveIterator it;
785 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 802 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
786 list.append( *it ); 803 list.append( *it );
787 804
788 return list; 805 return list;
789} 806}
790 807
791/*US 808/*US
792void AddressBook::setErrorHandler( ErrorHandler *handler ) 809void AddressBook::setErrorHandler( ErrorHandler *handler )
793{ 810{
794 delete d->mErrorHandler; 811 delete d->mErrorHandler;
795 d->mErrorHandler = handler; 812 d->mErrorHandler = handler;
796} 813}
797*/ 814*/
798 815
799void AddressBook::error( const QString& msg ) 816void AddressBook::error( const QString& msg )
800{ 817{
801/*US 818/*US
802 if ( !d->mErrorHandler ) // create default error handler 819 if ( !d->mErrorHandler ) // create default error handler
803 d->mErrorHandler = new ConsoleErrorHandler; 820 d->mErrorHandler = new ConsoleErrorHandler;
804 821
805 if ( d->mErrorHandler ) 822 if ( d->mErrorHandler )
806 d->mErrorHandler->error( msg ); 823 d->mErrorHandler->error( msg );
807 else 824 else
808 kdError(5700) << "no error handler defined" << endl; 825 kdError(5700) << "no error handler defined" << endl;
809*/ 826*/
810 kdDebug(5700) << "msg" << endl; 827 kdDebug(5700) << "msg" << endl;
811 qDebug(msg); 828 qDebug(msg);
812} 829}
813 830
814void AddressBook::deleteRemovedAddressees() 831void AddressBook::deleteRemovedAddressees()
815{ 832{
816 Addressee::List::Iterator it; 833 Addressee::List::Iterator it;
817 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { 834 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) {
818 Resource *resource = (*it).resource(); 835 Resource *resource = (*it).resource();
819 if ( resource && !resource->readOnly() && resource->isOpen() ) 836 if ( resource && !resource->readOnly() && resource->isOpen() )
820 resource->removeAddressee( *it ); 837 resource->removeAddressee( *it );
821 } 838 }
822 839
823 d->mRemovedAddressees.clear(); 840 d->mRemovedAddressees.clear();
824} 841}
825 842
826void AddressBook::setStandardResource( Resource *resource ) 843void AddressBook::setStandardResource( Resource *resource )
827{ 844{
828// qDebug("AddressBook::setStandardResource 1"); 845// qDebug("AddressBook::setStandardResource 1");
829 d->mManager->setStandardResource( resource ); 846 d->mManager->setStandardResource( resource );
830} 847}
831 848
832Resource *AddressBook::standardResource() 849Resource *AddressBook::standardResource()
833{ 850{
834 return d->mManager->standardResource(); 851 return d->mManager->standardResource();
835} 852}
836 853
837KRES::Manager<Resource> *AddressBook::resourceManager() 854KRES::Manager<Resource> *AddressBook::resourceManager()
838{ 855{
839 return d->mManager; 856 return d->mManager;
840} 857}
841 858
842void AddressBook::cleanUp() 859void AddressBook::cleanUp()
843{ 860{
844 KRES::Manager<Resource>::ActiveIterator it; 861 KRES::Manager<Resource>::ActiveIterator it;
845 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 862 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
846 if ( !(*it)->readOnly() && (*it)->isOpen() ) 863 if ( !(*it)->readOnly() && (*it)->isOpen() )
847 (*it)->cleanUp(); 864 (*it)->cleanUp();
848 } 865 }
849} 866}
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 0f5d605..d6b70c4 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -1,685 +1,692 @@
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 );
46 46
47struct Addressee::AddresseeData : public KShared 47struct Addressee::AddresseeData : public KShared
48{ 48{
49 QString uid; 49 QString uid;
50 QString name; 50 QString name;
51 QString formattedName; 51 QString formattedName;
52 QString familyName; 52 QString familyName;
53 QString givenName; 53 QString givenName;
54 QString additionalName; 54 QString additionalName;
55 QString prefix; 55 QString prefix;
56 QString suffix; 56 QString suffix;
57 QString nickName; 57 QString nickName;
58 QDateTime birthday; 58 QDateTime birthday;
59 QString mailer; 59 QString mailer;
60 TimeZone timeZone; 60 TimeZone timeZone;
61 Geo geo; 61 Geo geo;
62 QString title; 62 QString title;
63 QString role; 63 QString role;
64 QString organization; 64 QString organization;
65 QString note; 65 QString note;
66 QString productId; 66 QString productId;
67 QDateTime revision; 67 QDateTime revision;
68 QString sortString; 68 QString sortString;
69 KURL url; 69 KURL url;
70 Secrecy secrecy; 70 Secrecy secrecy;
71 Picture logo; 71 Picture logo;
72 Picture photo; 72 Picture photo;
73 Sound sound; 73 Sound sound;
74 Agent agent; 74 Agent agent;
75 QString mExternalId; 75 QString mExternalId;
76 PhoneNumber::List phoneNumbers; 76 PhoneNumber::List phoneNumbers;
77 Address::List addresses; 77 Address::List addresses;
78 Key::List keys; 78 Key::List keys;
79 QStringList emails; 79 QStringList emails;
80 QStringList categories; 80 QStringList categories;
81 QStringList custom; 81 QStringList custom;
82 82 int mTempSyncStat;
83 Resource *resource; 83 Resource *resource;
84 84
85 bool empty :1; 85 bool empty :1;
86 bool changed :1; 86 bool changed :1;
87}; 87};
88 88
89Addressee::Addressee() 89Addressee::Addressee()
90{ 90{
91 mData = new AddresseeData; 91 mData = new AddresseeData;
92 mData->empty = true; 92 mData->empty = true;
93 mData->changed = false; 93 mData->changed = false;
94 mData->resource = 0; 94 mData->resource = 0;
95 mData->mExternalId = ":"; 95 mData->mExternalId = ":";
96 mData->revision = QDateTime ( QDate( 2004,1,1)); 96 mData->revision = QDateTime ( QDate( 2004,1,1));
97 mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 97 mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
98} 98}
99 99
100Addressee::~Addressee() 100Addressee::~Addressee()
101{ 101{
102} 102}
103 103
104Addressee::Addressee( const Addressee &a ) 104Addressee::Addressee( const Addressee &a )
105{ 105{
106 mData = a.mData; 106 mData = a.mData;
107 mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
108} 107}
109 108
110Addressee &Addressee::operator=( const Addressee &a ) 109Addressee &Addressee::operator=( const Addressee &a )
111{ 110{
112 mData = a.mData; 111 mData = a.mData;
113 return (*this); 112 return (*this);
114} 113}
115 114
116Addressee Addressee::copy() 115Addressee Addressee::copy()
117{ 116{
118 Addressee a; 117 Addressee a;
119 *(a.mData) = *mData; 118 *(a.mData) = *mData;
120 return a; 119 return a;
121} 120}
122 121
123void Addressee::detach() 122void Addressee::detach()
124{ 123{
125 if ( mData.count() == 1 ) return; 124 if ( mData.count() == 1 ) return;
126 *this = copy(); 125 *this = copy();
127} 126}
128 127
129bool Addressee::operator==( const Addressee &a ) const 128bool Addressee::operator==( const Addressee &a ) const
130{ 129{
131 if ( uid() != a.uid() ) return false; 130 if ( uid() != a.uid() ) return false;
132 if ( mData->name != a.mData->name ) return false; 131 if ( mData->name != a.mData->name ) return false;
133 if ( mData->formattedName != a.mData->formattedName ) return false; 132 if ( mData->formattedName != a.mData->formattedName ) return false;
134 if ( mData->familyName != a.mData->familyName ) return false; 133 if ( mData->familyName != a.mData->familyName ) return false;
135 if ( mData->givenName != a.mData->givenName ) return false; 134 if ( mData->givenName != a.mData->givenName ) return false;
136 if ( mData->additionalName != a.mData->additionalName ) return false; 135 if ( mData->additionalName != a.mData->additionalName ) return false;
137 if ( mData->prefix != a.mData->prefix ) return false; 136 if ( mData->prefix != a.mData->prefix ) return false;
138 if ( mData->suffix != a.mData->suffix ) return false; 137 if ( mData->suffix != a.mData->suffix ) return false;
139 if ( mData->nickName != a.mData->nickName ) return false; 138 if ( mData->nickName != a.mData->nickName ) return false;
140 if ( mData->birthday != a.mData->birthday ) return false; 139 if ( mData->birthday != a.mData->birthday ) return false;
141 if ( mData->mailer != a.mData->mailer ) return false; 140 if ( mData->mailer != a.mData->mailer ) return false;
142 if ( mData->timeZone != a.mData->timeZone ) return false; 141 if ( mData->timeZone != a.mData->timeZone ) return false;
143 if ( mData->geo != a.mData->geo ) return false; 142 if ( mData->geo != a.mData->geo ) return false;
144 if ( mData->title != a.mData->title ) return false; 143 if ( mData->title != a.mData->title ) return false;
145 if ( mData->role != a.mData->role ) return false; 144 if ( mData->role != a.mData->role ) return false;
146 if ( mData->organization != a.mData->organization ) return false; 145 if ( mData->organization != a.mData->organization ) return false;
147 if ( mData->note != a.mData->note ) return false; 146 if ( mData->note != a.mData->note ) return false;
148 if ( mData->productId != a.mData->productId ) return false; 147 if ( mData->productId != a.mData->productId ) return false;
149 if ( mData->revision != a.mData->revision ) return false; 148 if ( mData->revision != a.mData->revision ) return false;
150 if ( mData->sortString != a.mData->sortString ) return false; 149 if ( mData->sortString != a.mData->sortString ) return false;
151 if ( mData->secrecy != a.mData->secrecy ) return false; 150 if ( mData->secrecy != a.mData->secrecy ) return false;
152 if ( mData->logo != a.mData->logo ) return false; 151 if ( mData->logo != a.mData->logo ) return false;
153 if ( mData->photo != a.mData->photo ) return false; 152 if ( mData->photo != a.mData->photo ) return false;
154 if ( mData->sound != a.mData->sound ) return false; 153 if ( mData->sound != a.mData->sound ) return false;
155 if ( mData->agent != a.mData->agent ) return false; 154 if ( mData->agent != a.mData->agent ) return false;
156 if ( ( mData->url.isValid() || a.mData->url.isValid() ) && 155 if ( ( mData->url.isValid() || a.mData->url.isValid() ) &&
157 ( mData->url != a.mData->url ) ) return false; 156 ( mData->url != a.mData->url ) ) return false;
158 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; 157 if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false;
159 if ( mData->addresses != a.mData->addresses ) return false; 158 if ( mData->addresses != a.mData->addresses ) return false;
160 if ( mData->keys != a.mData->keys ) return false; 159 if ( mData->keys != a.mData->keys ) return false;
161 if ( mData->emails != a.mData->emails ) return false; 160 if ( mData->emails != a.mData->emails ) return false;
162 if ( mData->categories != a.mData->categories ) return false; 161 if ( mData->categories != a.mData->categories ) return false;
163 if ( mData->custom != a.mData->custom ) return false; 162 if ( mData->custom != a.mData->custom ) return false;
164 163
165 return true; 164 return true;
166} 165}
167 166
168bool Addressee::operator!=( const Addressee &a ) const 167bool Addressee::operator!=( const Addressee &a ) const
169{ 168{
170 return !( a == *this ); 169 return !( a == *this );
171} 170}
172 171
173bool Addressee::isEmpty() const 172bool Addressee::isEmpty() const
174{ 173{
175 return mData->empty; 174 return mData->empty;
176} 175}
177ulong Addressee::getCsum4List( const QStringList & attList) 176ulong Addressee::getCsum4List( const QStringList & attList)
178{ 177{
179 int max = attList.count(); 178 int max = attList.count();
180 ulong cSum = 0; 179 ulong cSum = 0;
181 int j,k,i; 180 int j,k,i;
182 int add; 181 int add;
183 for ( i = 0; i < max ; ++i ) { 182 for ( i = 0; i < max ; ++i ) {
184 QString s = attList[i]; 183 QString s = attList[i];
185 if ( ! s.isEmpty() ){ 184 if ( ! s.isEmpty() ){
186 j = s.length(); 185 j = s.length();
187 for ( k = 0; k < j; ++k ) { 186 for ( k = 0; k < j; ++k ) {
188 int mul = k +1; 187 int mul = k +1;
189 add = s[k].unicode (); 188 add = s[k].unicode ();
190 if ( k < 16 ) 189 if ( k < 16 )
191 mul = mul * mul; 190 mul = mul * mul;
192 int ii = i+1; 191 int ii = i+1;
193 add = add * mul *ii*ii*ii; 192 add = add * mul *ii*ii*ii;
194 cSum += add; 193 cSum += add;
195 } 194 }
196 } 195 }
197 196
198 } 197 }
199 //QString dump = attList.join(","); 198 //QString dump = attList.join(",");
200 //qDebug("csum: %d %s", cSum,dump.latin1()); 199 //qDebug("csum: %d %s", cSum,dump.latin1());
201 200
202 return cSum; 201 return cSum;
203 202
204} 203}
205void Addressee::computeCsum(const QString &dev) 204void Addressee::computeCsum(const QString &dev)
206{ 205{
207 QStringList l; 206 QStringList l;
208 if ( !mData->name.isEmpty() ) l.append(mData->name); 207 if ( !mData->name.isEmpty() ) l.append(mData->name);
209 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); 208 if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName );
210 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); 209 if ( !mData->familyName.isEmpty() ) l.append( mData->familyName );
211 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); 210 if ( !mData->givenName.isEmpty() ) l.append(mData->givenName );
212 if ( !mData->additionalName ) l.append( mData->additionalName ); 211 if ( !mData->additionalName ) l.append( mData->additionalName );
213 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); 212 if ( !mData->prefix.isEmpty() ) l.append( mData->prefix );
214 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); 213 if ( !mData->suffix.isEmpty() ) l.append( mData->suffix );
215 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); 214 if ( !mData->nickName.isEmpty() ) l.append( mData->nickName );
216 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); 215 if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() );
217 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); 216 if ( !mData->mailer.isEmpty() ) l.append( mData->mailer );
218 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); 217 if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() );
219 if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); 218 if ( mData->geo.isValid() ) l.append( mData->geo.asString() );
220 if ( !mData->title .isEmpty() ) l.append( mData->title ); 219 if ( !mData->title .isEmpty() ) l.append( mData->title );
221 if ( !mData->role.isEmpty() ) l.append( mData->role ); 220 if ( !mData->role.isEmpty() ) l.append( mData->role );
222 if ( !mData->organization.isEmpty() ) l.append( mData->organization ); 221 if ( !mData->organization.isEmpty() ) l.append( mData->organization );
223 if ( !mData->note.isEmpty() ) l.append( mData->note ); 222 if ( !mData->note.isEmpty() ) l.append( mData->note );
224 if ( !mData->productId.isEmpty() ) l.append(mData->productId ); 223 if ( !mData->productId.isEmpty() ) l.append(mData->productId );
225 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); 224 if ( !mData->sortString.isEmpty() ) l.append( mData->sortString );
226 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); 225 if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString());
227 // if ( !mData->logo.isEmpty() ) l.append( ); 226 // if ( !mData->logo.isEmpty() ) l.append( );
228 //if ( !mData->photo.isEmpty() ) l.append( ); 227 //if ( !mData->photo.isEmpty() ) l.append( );
229 //if ( !mData->sound.isEmpty() ) l.append( ); 228 //if ( !mData->sound.isEmpty() ) l.append( );
230 //if ( !mData->agent.isEmpty() ) l.append( ); 229 //if ( !mData->agent.isEmpty() ) l.append( );
231 //if ( mData->url.isValid() ) l.append( ); 230 //if ( mData->url.isValid() ) l.append( );
232#if 0 231#if 0
233 if ( !mData->phoneNumbers.isEmpty() ) l.append( ); 232 if ( !mData->phoneNumbers.isEmpty() ) l.append( );
234 if ( !mData->addresses.isEmpty() ) l.append( ); 233 if ( !mData->addresses.isEmpty() ) l.append( );
235 //if ( !mData->keys.isEmpty() ) l.append( ); 234 //if ( !mData->keys.isEmpty() ) l.append( );
236 if ( !mData->emails.isEmpty() ) l.append( ); 235 if ( !mData->emails.isEmpty() ) l.append( );
237 if ( !mData->categories .isEmpty() ) l.append( ); 236 if ( !mData->categories .isEmpty() ) l.append( );
238 if ( !mData->custom.isEmpty() ) l.append( ); 237 if ( !mData->custom.isEmpty() ) l.append( );
239#endif 238#endif
240 KABC::PhoneNumber::List phoneNumbers; 239 KABC::PhoneNumber::List phoneNumbers;
241 KABC::PhoneNumber::List::Iterator phoneIter; 240 KABC::PhoneNumber::List::Iterator phoneIter;
242 241
243 QStringList t; 242 QStringList t;
244 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); 243 for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
245 ++phoneIter ) 244 ++phoneIter )
246 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); 245 t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) );
247 t.sort(); 246 t.sort();
248 uint iii; 247 uint iii;
249 for ( iii = 0; iii < t.count(); ++iii) 248 for ( iii = 0; iii < t.count(); ++iii)
250 l.append( t[iii] ); 249 l.append( t[iii] );
251 t = mData->emails; 250 t = mData->emails;
252 t.sort(); 251 t.sort();
253 for ( iii = 0; iii < t.count(); ++iii) 252 for ( iii = 0; iii < t.count(); ++iii)
254 l.append( t[iii] ); 253 l.append( t[iii] );
255 t = mData->categories; 254 t = mData->categories;
256 t.sort(); 255 t.sort();
257 for ( iii = 0; iii < t.count(); ++iii) 256 for ( iii = 0; iii < t.count(); ++iii)
258 l.append( t[iii] ); 257 l.append( t[iii] );
259 t = mData->custom; 258 t = mData->custom;
260 t.sort(); 259 t.sort();
261 for ( iii = 0; iii < t.count(); ++iii) 260 for ( iii = 0; iii < t.count(); ++iii)
262 l.append( t[iii] ); 261 l.append( t[iii] );
263 KABC::Address::List::Iterator addressIter; 262 KABC::Address::List::Iterator addressIter;
264 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); 263 for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
265 ++addressIter ) { 264 ++addressIter ) {
266 t = (*addressIter).asList(); 265 t = (*addressIter).asList();
267 t.sort(); 266 t.sort();
268 for ( iii = 0; iii < t.count(); ++iii) 267 for ( iii = 0; iii < t.count(); ++iii)
269 l.append( t[iii] ); 268 l.append( t[iii] );
270 } 269 }
271 setCsum( dev, QString::number (getCsum4List(l)) ); 270 uint cs = getCsum4List(l);
271 qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() );
272 setCsum( dev, QString::number (cs ));
272} 273}
273void Addressee::removeID(const QString &prof) 274void Addressee::removeID(const QString &prof)
274{ 275{
275 detach(); 276 detach();
276 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); 277 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
277 278
278} 279}
279void Addressee::setID( const QString & prof , const QString & id ) 280void Addressee::setID( const QString & prof , const QString & id )
280{ 281{
281 detach(); 282 detach();
283 qDebug("setID1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
282 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); 284 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
285 qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
283} 286}
284void Addressee::setTempSyncStat( int id ) 287void Addressee::setTempSyncStat( int id )
285{ 288{
286 mTempSyncStat = id; 289 if ( mData->mTempSyncStat == id ) return;
290 detach();
291 mData->mTempSyncStat = id;
287} 292}
288int Addressee::tempSyncStat() const 293int Addressee::tempSyncStat() const
289{ 294{
290 return mTempSyncStat; 295 return mData->mTempSyncStat;
291} 296}
292 297
293QString Addressee::getID( const QString & prof) 298QString Addressee::getID( const QString & prof)
294{ 299{
295 return KIdManager::getId ( mData->mExternalId, prof ); 300 return KIdManager::getId ( mData->mExternalId, prof );
296} 301}
297 302
298void Addressee::setCsum( const QString & prof , const QString & id ) 303void Addressee::setCsum( const QString & prof , const QString & id )
299{ 304{
300 detach(); 305 detach();
306 qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
301 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); 307 mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id );
308 qDebug("setcsum2 %s ",mData->mExternalId.latin1() );
302} 309}
303 310
304QString Addressee::getCsum( const QString & prof) 311QString Addressee::getCsum( const QString & prof)
305{ 312{
306 return KIdManager::getCsum ( mData->mExternalId, prof ); 313 return KIdManager::getCsum ( mData->mExternalId, prof );
307} 314}
308 315
309void Addressee::setIDStr( const QString & s ) 316void Addressee::setIDStr( const QString & s )
310{ 317{
311 detach(); 318 detach();
312 mData->mExternalId = s; 319 mData->mExternalId = s;
313} 320}
314 321
315QString Addressee::IDStr() const 322QString Addressee::IDStr() const
316{ 323{
317 return mData->mExternalId; 324 return mData->mExternalId;
318} 325}
319 326
320 327
321void Addressee::setUid( const QString &id ) 328void Addressee::setUid( const QString &id )
322{ 329{
323 if ( id == mData->uid ) return; 330 if ( id == mData->uid ) return;
324 detach(); 331 detach();
325 mData->empty = false; 332 mData->empty = false;
326 mData->uid = id; 333 mData->uid = id;
327} 334}
328 335
329QString Addressee::uid() const 336QString Addressee::uid() const
330{ 337{
331 if ( mData->uid.isEmpty() ) 338 if ( mData->uid.isEmpty() )
332 mData->uid = KApplication::randomString( 10 ); 339 mData->uid = KApplication::randomString( 10 );
333 340
334 return mData->uid; 341 return mData->uid;
335} 342}
336 343
337QString Addressee::uidLabel() 344QString Addressee::uidLabel()
338{ 345{
339 return i18n("Unique Identifier"); 346 return i18n("Unique Identifier");
340} 347}
341 348
342void Addressee::setName( const QString &name ) 349void Addressee::setName( const QString &name )
343{ 350{
344 if ( name == mData->name ) return; 351 if ( name == mData->name ) return;
345 detach(); 352 detach();
346 mData->empty = false; 353 mData->empty = false;
347 mData->name = name; 354 mData->name = name;
348} 355}
349 356
350QString Addressee::name() const 357QString Addressee::name() const
351{ 358{
352 return mData->name; 359 return mData->name;
353} 360}
354 361
355QString Addressee::nameLabel() 362QString Addressee::nameLabel()
356{ 363{
357 return i18n("Name"); 364 return i18n("Name");
358} 365}
359 366
360 367
361void Addressee::setFormattedName( const QString &formattedName ) 368void Addressee::setFormattedName( const QString &formattedName )
362{ 369{
363 if ( formattedName == mData->formattedName ) return; 370 if ( formattedName == mData->formattedName ) return;
364 detach(); 371 detach();
365 mData->empty = false; 372 mData->empty = false;
366 mData->formattedName = formattedName; 373 mData->formattedName = formattedName;
367} 374}
368 375
369QString Addressee::formattedName() const 376QString Addressee::formattedName() const
370{ 377{
371 return mData->formattedName; 378 return mData->formattedName;
372} 379}
373 380
374QString Addressee::formattedNameLabel() 381QString Addressee::formattedNameLabel()
375{ 382{
376 return i18n("Formatted Name"); 383 return i18n("Formatted Name");
377} 384}
378 385
379 386
380void Addressee::setFamilyName( const QString &familyName ) 387void Addressee::setFamilyName( const QString &familyName )
381{ 388{
382 if ( familyName == mData->familyName ) return; 389 if ( familyName == mData->familyName ) return;
383 detach(); 390 detach();
384 mData->empty = false; 391 mData->empty = false;
385 mData->familyName = familyName; 392 mData->familyName = familyName;
386} 393}
387 394
388QString Addressee::familyName() const 395QString Addressee::familyName() const
389{ 396{
390 return mData->familyName; 397 return mData->familyName;
391} 398}
392 399
393QString Addressee::familyNameLabel() 400QString Addressee::familyNameLabel()
394{ 401{
395 return i18n("Family Name"); 402 return i18n("Family Name");
396} 403}
397 404
398 405
399void Addressee::setGivenName( const QString &givenName ) 406void Addressee::setGivenName( const QString &givenName )
400{ 407{
401 if ( givenName == mData->givenName ) return; 408 if ( givenName == mData->givenName ) return;
402 detach(); 409 detach();
403 mData->empty = false; 410 mData->empty = false;
404 mData->givenName = givenName; 411 mData->givenName = givenName;
405} 412}
406 413
407QString Addressee::givenName() const 414QString Addressee::givenName() const
408{ 415{
409 return mData->givenName; 416 return mData->givenName;
410} 417}
411 418
412QString Addressee::givenNameLabel() 419QString Addressee::givenNameLabel()
413{ 420{
414 return i18n("Given Name"); 421 return i18n("Given Name");
415} 422}
416 423
417 424
418void Addressee::setAdditionalName( const QString &additionalName ) 425void Addressee::setAdditionalName( const QString &additionalName )
419{ 426{
420 if ( additionalName == mData->additionalName ) return; 427 if ( additionalName == mData->additionalName ) return;
421 detach(); 428 detach();
422 mData->empty = false; 429 mData->empty = false;
423 mData->additionalName = additionalName; 430 mData->additionalName = additionalName;
424} 431}
425 432
426QString Addressee::additionalName() const 433QString Addressee::additionalName() const
427{ 434{
428 return mData->additionalName; 435 return mData->additionalName;
429} 436}
430 437
431QString Addressee::additionalNameLabel() 438QString Addressee::additionalNameLabel()
432{ 439{
433 return i18n("Additional Names"); 440 return i18n("Additional Names");
434} 441}
435 442
436 443
437void Addressee::setPrefix( const QString &prefix ) 444void Addressee::setPrefix( const QString &prefix )
438{ 445{
439 if ( prefix == mData->prefix ) return; 446 if ( prefix == mData->prefix ) return;
440 detach(); 447 detach();
441 mData->empty = false; 448 mData->empty = false;
442 mData->prefix = prefix; 449 mData->prefix = prefix;
443} 450}
444 451
445QString Addressee::prefix() const 452QString Addressee::prefix() const
446{ 453{
447 return mData->prefix; 454 return mData->prefix;
448} 455}
449 456
450QString Addressee::prefixLabel() 457QString Addressee::prefixLabel()
451{ 458{
452 return i18n("Honorific Prefixes"); 459 return i18n("Honorific Prefixes");
453} 460}
454 461
455 462
456void Addressee::setSuffix( const QString &suffix ) 463void Addressee::setSuffix( const QString &suffix )
457{ 464{
458 if ( suffix == mData->suffix ) return; 465 if ( suffix == mData->suffix ) return;
459 detach(); 466 detach();
460 mData->empty = false; 467 mData->empty = false;
461 mData->suffix = suffix; 468 mData->suffix = suffix;
462} 469}
463 470
464QString Addressee::suffix() const 471QString Addressee::suffix() const
465{ 472{
466 return mData->suffix; 473 return mData->suffix;
467} 474}
468 475
469QString Addressee::suffixLabel() 476QString Addressee::suffixLabel()
470{ 477{
471 return i18n("Honorific Suffixes"); 478 return i18n("Honorific Suffixes");
472} 479}
473 480
474 481
475void Addressee::setNickName( const QString &nickName ) 482void Addressee::setNickName( const QString &nickName )
476{ 483{
477 if ( nickName == mData->nickName ) return; 484 if ( nickName == mData->nickName ) return;
478 detach(); 485 detach();
479 mData->empty = false; 486 mData->empty = false;
480 mData->nickName = nickName; 487 mData->nickName = nickName;
481} 488}
482 489
483QString Addressee::nickName() const 490QString Addressee::nickName() const
484{ 491{
485 return mData->nickName; 492 return mData->nickName;
486} 493}
487 494
488QString Addressee::nickNameLabel() 495QString Addressee::nickNameLabel()
489{ 496{
490 return i18n("Nick Name"); 497 return i18n("Nick Name");
491} 498}
492 499
493 500
494void Addressee::setBirthday( const QDateTime &birthday ) 501void Addressee::setBirthday( const QDateTime &birthday )
495{ 502{
496 if ( birthday == mData->birthday ) return; 503 if ( birthday == mData->birthday ) return;
497 detach(); 504 detach();
498 mData->empty = false; 505 mData->empty = false;
499 mData->birthday = birthday; 506 mData->birthday = birthday;
500} 507}
501 508
502QDateTime Addressee::birthday() const 509QDateTime Addressee::birthday() const
503{ 510{
504 return mData->birthday; 511 return mData->birthday;
505} 512}
506 513
507QString Addressee::birthdayLabel() 514QString Addressee::birthdayLabel()
508{ 515{
509 return i18n("Birthday"); 516 return i18n("Birthday");
510} 517}
511 518
512 519
513QString Addressee::homeAddressStreetLabel() 520QString Addressee::homeAddressStreetLabel()
514{ 521{
515 return i18n("Home Address Street"); 522 return i18n("Home Address Street");
516} 523}
517 524
518 525
519QString Addressee::homeAddressLocalityLabel() 526QString Addressee::homeAddressLocalityLabel()
520{ 527{
521 return i18n("Home Address Locality"); 528 return i18n("Home Address Locality");
522} 529}
523 530
524 531
525QString Addressee::homeAddressRegionLabel() 532QString Addressee::homeAddressRegionLabel()
526{ 533{
527 return i18n("Home Address Region"); 534 return i18n("Home Address Region");
528} 535}
529 536
530 537
531QString Addressee::homeAddressPostalCodeLabel() 538QString Addressee::homeAddressPostalCodeLabel()
532{ 539{
533 return i18n("Home Address Postal Code"); 540 return i18n("Home Address Postal Code");
534} 541}
535 542
536 543
537QString Addressee::homeAddressCountryLabel() 544QString Addressee::homeAddressCountryLabel()
538{ 545{
539 return i18n("Home Address Country"); 546 return i18n("Home Address Country");
540} 547}
541 548
542 549
543QString Addressee::homeAddressLabelLabel() 550QString Addressee::homeAddressLabelLabel()
544{ 551{
545 return i18n("Home Address Label"); 552 return i18n("Home Address Label");
546} 553}
547 554
548 555
549QString Addressee::businessAddressStreetLabel() 556QString Addressee::businessAddressStreetLabel()
550{ 557{
551 return i18n("Business Address Street"); 558 return i18n("Business Address Street");
552} 559}
553 560
554 561
555QString Addressee::businessAddressLocalityLabel() 562QString Addressee::businessAddressLocalityLabel()
556{ 563{
557 return i18n("Business Address Locality"); 564 return i18n("Business Address Locality");
558} 565}
559 566
560 567
561QString Addressee::businessAddressRegionLabel() 568QString Addressee::businessAddressRegionLabel()
562{ 569{
563 return i18n("Business Address Region"); 570 return i18n("Business Address Region");
564} 571}
565 572
566 573
567QString Addressee::businessAddressPostalCodeLabel() 574QString Addressee::businessAddressPostalCodeLabel()
568{ 575{
569 return i18n("Business Address Postal Code"); 576 return i18n("Business Address Postal Code");
570} 577}
571 578
572 579
573QString Addressee::businessAddressCountryLabel() 580QString Addressee::businessAddressCountryLabel()
574{ 581{
575 return i18n("Business Address Country"); 582 return i18n("Business Address Country");
576} 583}
577 584
578 585
579QString Addressee::businessAddressLabelLabel() 586QString Addressee::businessAddressLabelLabel()
580{ 587{
581 return i18n("Business Address Label"); 588 return i18n("Business Address Label");
582} 589}
583 590
584 591
585QString Addressee::homePhoneLabel() 592QString Addressee::homePhoneLabel()
586{ 593{
587 return i18n("Home Phone"); 594 return i18n("Home Phone");
588} 595}
589 596
590 597
591QString Addressee::businessPhoneLabel() 598QString Addressee::businessPhoneLabel()
592{ 599{
593 return i18n("Business Phone"); 600 return i18n("Business Phone");
594} 601}
595 602
596 603
597QString Addressee::mobilePhoneLabel() 604QString Addressee::mobilePhoneLabel()
598{ 605{
599 return i18n("Mobile Phone"); 606 return i18n("Mobile Phone");
600} 607}
601 608
602 609
603QString Addressee::homeFaxLabel() 610QString Addressee::homeFaxLabel()
604{ 611{
605 return i18n("Home Fax"); 612 return i18n("Home Fax");
606} 613}
607 614
608 615
609QString Addressee::businessFaxLabel() 616QString Addressee::businessFaxLabel()
610{ 617{
611 return i18n("Business Fax"); 618 return i18n("Business Fax");
612} 619}
613 620
614 621
615QString Addressee::carPhoneLabel() 622QString Addressee::carPhoneLabel()
616{ 623{
617 return i18n("Car Phone"); 624 return i18n("Car Phone");
618} 625}
619 626
620 627
621QString Addressee::isdnLabel() 628QString Addressee::isdnLabel()
622{ 629{
623 return i18n("ISDN"); 630 return i18n("ISDN");
624} 631}
625 632
626 633
627QString Addressee::pagerLabel() 634QString Addressee::pagerLabel()
628{ 635{
629 return i18n("Pager"); 636 return i18n("Pager");
630} 637}
631 638
632QString Addressee::sipLabel() 639QString Addressee::sipLabel()
633{ 640{
634 return i18n("SIP"); 641 return i18n("SIP");
635} 642}
636 643
637QString Addressee::emailLabel() 644QString Addressee::emailLabel()
638{ 645{
639 return i18n("Email Address"); 646 return i18n("Email Address");
640} 647}
641 648
642 649
643void Addressee::setMailer( const QString &mailer ) 650void Addressee::setMailer( const QString &mailer )
644{ 651{
645 if ( mailer == mData->mailer ) return; 652 if ( mailer == mData->mailer ) return;
646 detach(); 653 detach();
647 mData->empty = false; 654 mData->empty = false;
648 mData->mailer = mailer; 655 mData->mailer = mailer;
649} 656}
650 657
651QString Addressee::mailer() const 658QString Addressee::mailer() const
652{ 659{
653 return mData->mailer; 660 return mData->mailer;
654} 661}
655 662
656QString Addressee::mailerLabel() 663QString Addressee::mailerLabel()
657{ 664{
658 return i18n("Mail Client"); 665 return i18n("Mail Client");
659} 666}
660 667
661 668
662void Addressee::setTimeZone( const TimeZone &timeZone ) 669void Addressee::setTimeZone( const TimeZone &timeZone )
663{ 670{
664 if ( timeZone == mData->timeZone ) return; 671 if ( timeZone == mData->timeZone ) return;
665 detach(); 672 detach();
666 mData->empty = false; 673 mData->empty = false;
667 mData->timeZone = timeZone; 674 mData->timeZone = timeZone;
668} 675}
669 676
670TimeZone Addressee::timeZone() const 677TimeZone Addressee::timeZone() const
671{ 678{
672 return mData->timeZone; 679 return mData->timeZone;
673} 680}
674 681
675QString Addressee::timeZoneLabel() 682QString Addressee::timeZoneLabel()
676{ 683{
677 return i18n("Time Zone"); 684 return i18n("Time Zone");
678} 685}
679 686
680 687
681void Addressee::setGeo( const Geo &geo ) 688void Addressee::setGeo( const Geo &geo )
682{ 689{
683 if ( geo == mData->geo ) return; 690 if ( geo == mData->geo ) return;
684 detach(); 691 detach();
685 mData->empty = false; 692 mData->empty = false;
diff --git a/kabc/addressee.h b/kabc/addressee.h
index 0805458..bfb0840 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -445,396 +445,395 @@ class Addressee
445 static QString noteLabel(); 445 static QString noteLabel();
446 446
447 /** 447 /**
448 Set product identifier. 448 Set product identifier.
449 */ 449 */
450 void setProductId( const QString &productId ); 450 void setProductId( const QString &productId );
451 /** 451 /**
452 Return product identifier. 452 Return product identifier.
453 */ 453 */
454 QString productId() const; 454 QString productId() const;
455 /** 455 /**
456 Return translated label for productId field. 456 Return translated label for productId field.
457 */ 457 */
458 static QString productIdLabel(); 458 static QString productIdLabel();
459 459
460 /** 460 /**
461 Set revision date. 461 Set revision date.
462 */ 462 */
463 void setRevision( const QDateTime &revision ); 463 void setRevision( const QDateTime &revision );
464 /** 464 /**
465 Return revision date. 465 Return revision date.
466 */ 466 */
467 QDateTime revision() const; 467 QDateTime revision() const;
468 /** 468 /**
469 Return translated label for revision field. 469 Return translated label for revision field.
470 */ 470 */
471 static QString revisionLabel(); 471 static QString revisionLabel();
472 472
473 /** 473 /**
474 Set sort string. 474 Set sort string.
475 */ 475 */
476 void setSortString( const QString &sortString ); 476 void setSortString( const QString &sortString );
477 /** 477 /**
478 Return sort string. 478 Return sort string.
479 */ 479 */
480 QString sortString() const; 480 QString sortString() const;
481 /** 481 /**
482 Return translated label for sortString field. 482 Return translated label for sortString field.
483 */ 483 */
484 static QString sortStringLabel(); 484 static QString sortStringLabel();
485 485
486 /** 486 /**
487 Set URL. 487 Set URL.
488 */ 488 */
489 void setUrl( const KURL &url ); 489 void setUrl( const KURL &url );
490 /** 490 /**
491 Return URL. 491 Return URL.
492 */ 492 */
493 KURL url() const; 493 KURL url() const;
494 /** 494 /**
495 Return translated label for url field. 495 Return translated label for url field.
496 */ 496 */
497 static QString urlLabel(); 497 static QString urlLabel();
498 498
499 /** 499 /**
500 Set security class. 500 Set security class.
501 */ 501 */
502 void setSecrecy( const Secrecy &secrecy ); 502 void setSecrecy( const Secrecy &secrecy );
503 /** 503 /**
504 Return security class. 504 Return security class.
505 */ 505 */
506 Secrecy secrecy() const; 506 Secrecy secrecy() const;
507 /** 507 /**
508 Return translated label for secrecy field. 508 Return translated label for secrecy field.
509 */ 509 */
510 static QString secrecyLabel(); 510 static QString secrecyLabel();
511 511
512 /** 512 /**
513 Set logo. 513 Set logo.
514 */ 514 */
515 void setLogo( const Picture &logo ); 515 void setLogo( const Picture &logo );
516 /** 516 /**
517 Return logo. 517 Return logo.
518 */ 518 */
519 Picture logo() const; 519 Picture logo() const;
520 /** 520 /**
521 Return translated label for logo field. 521 Return translated label for logo field.
522 */ 522 */
523 static QString logoLabel(); 523 static QString logoLabel();
524 524
525 /** 525 /**
526 Set photo. 526 Set photo.
527 */ 527 */
528 void setPhoto( const Picture &photo ); 528 void setPhoto( const Picture &photo );
529 /** 529 /**
530 Return photo. 530 Return photo.
531 */ 531 */
532 Picture photo() const; 532 Picture photo() const;
533 /** 533 /**
534 Return translated label for photo field. 534 Return translated label for photo field.
535 */ 535 */
536 static QString photoLabel(); 536 static QString photoLabel();
537 537
538 /** 538 /**
539 Set sound. 539 Set sound.
540 */ 540 */
541 void setSound( const Sound &sound ); 541 void setSound( const Sound &sound );
542 /** 542 /**
543 Return sound. 543 Return sound.
544 */ 544 */
545 Sound sound() const; 545 Sound sound() const;
546 /** 546 /**
547 Return translated label for sound field. 547 Return translated label for sound field.
548 */ 548 */
549 static QString soundLabel(); 549 static QString soundLabel();
550 550
551 /** 551 /**
552 Set agent. 552 Set agent.
553 */ 553 */
554 void setAgent( const Agent &agent ); 554 void setAgent( const Agent &agent );
555 /** 555 /**
556 Return agent. 556 Return agent.
557 */ 557 */
558 Agent agent() const; 558 Agent agent() const;
559 /** 559 /**
560 Return translated label for agent field. 560 Return translated label for agent field.
561 */ 561 */
562 static QString agentLabel(); 562 static QString agentLabel();
563 563
564 /** 564 /**
565 Set name fields by parsing the given string and trying to associate the 565 Set name fields by parsing the given string and trying to associate the
566 parts of the string with according fields. This function should probably 566 parts of the string with according fields. This function should probably
567 be a bit more clever. 567 be a bit more clever.
568 */ 568 */
569 void setNameFromString( const QString & ); 569 void setNameFromString( const QString & );
570 570
571 /** 571 /**
572 Return the name of the addressee. This is calculated from all the name 572 Return the name of the addressee. This is calculated from all the name
573 fields. 573 fields.
574 */ 574 */
575 QString realName() const; 575 QString realName() const;
576 576
577 /** 577 /**
578 Return the name that consists of all name parts. 578 Return the name that consists of all name parts.
579 */ 579 */
580 QString assembledName() const; 580 QString assembledName() const;
581 581
582 /** 582 /**
583 Return email address including real name. 583 Return email address including real name.
584 584
585 @param email Email address to be used to construct the full email string. 585 @param email Email address to be used to construct the full email string.
586 If this is QString::null the preferred email address is used. 586 If this is QString::null the preferred email address is used.
587 */ 587 */
588 QString fullEmail( const QString &email=QString::null ) const; 588 QString fullEmail( const QString &email=QString::null ) const;
589 589
590 /** 590 /**
591 Insert an email address. If the email address already exists in this 591 Insert an email address. If the email address already exists in this
592 addressee it is not duplicated. 592 addressee it is not duplicated.
593 593
594 @param email Email address 594 @param email Email address
595 @param preferred Set to true, if this is the preferred email address of 595 @param preferred Set to true, if this is the preferred email address of
596 the addressee. 596 the addressee.
597 */ 597 */
598 void insertEmail( const QString &email, bool preferred=false ); 598 void insertEmail( const QString &email, bool preferred=false );
599 599
600 /** 600 /**
601 Remove email address. If the email address doesn't exist, nothing happens. 601 Remove email address. If the email address doesn't exist, nothing happens.
602 */ 602 */
603 void removeEmail( const QString &email ); 603 void removeEmail( const QString &email );
604 604
605 /** 605 /**
606 Return preferred email address. This is the first email address or the 606 Return preferred email address. This is the first email address or the
607 last one added with @ref insertEmail() with a set preferred parameter. 607 last one added with @ref insertEmail() with a set preferred parameter.
608 */ 608 */
609 QString preferredEmail() const; 609 QString preferredEmail() const;
610 610
611 /** 611 /**
612 Return list of all email addresses. 612 Return list of all email addresses.
613 */ 613 */
614 QStringList emails() const; 614 QStringList emails() const;
615 615
616 /** 616 /**
617 Set the emails to @param. 617 Set the emails to @param.
618 The first email address gets the preferred one! 618 The first email address gets the preferred one!
619 @param list The list of email addresses. 619 @param list The list of email addresses.
620 */ 620 */
621 void setEmails( const QStringList& list); 621 void setEmails( const QStringList& list);
622 622
623 /** 623 /**
624 Insert a phone number. If a phone number with the same id already exists 624 Insert a phone number. If a phone number with the same id already exists
625 in this addressee it is not duplicated. 625 in this addressee it is not duplicated.
626 */ 626 */
627 void insertPhoneNumber( const PhoneNumber &phoneNumber ); 627 void insertPhoneNumber( const PhoneNumber &phoneNumber );
628 628
629 /** 629 /**
630 Remove phone number. If no phone number with the given id exists for this 630 Remove phone number. If no phone number with the given id exists for this
631 addresse nothing happens. 631 addresse nothing happens.
632 */ 632 */
633 void removePhoneNumber( const PhoneNumber &phoneNumber ); 633 void removePhoneNumber( const PhoneNumber &phoneNumber );
634 634
635 /** 635 /**
636 Return phone number, which matches the given type. 636 Return phone number, which matches the given type.
637 */ 637 */
638 PhoneNumber phoneNumber( int type ) const; 638 PhoneNumber phoneNumber( int type ) const;
639 639
640 /** 640 /**
641 Return list of all phone numbers. 641 Return list of all phone numbers.
642 */ 642 */
643 PhoneNumber::List phoneNumbers() const; 643 PhoneNumber::List phoneNumbers() const;
644 644
645 /** 645 /**
646 Return list of phone numbers with a special type. 646 Return list of phone numbers with a special type.
647 */ 647 */
648 PhoneNumber::List phoneNumbers( int type ) const; 648 PhoneNumber::List phoneNumbers( int type ) const;
649 649
650 /** 650 /**
651 Return phone number with the given id. 651 Return phone number with the given id.
652 */ 652 */
653 PhoneNumber findPhoneNumber( const QString &id ) const; 653 PhoneNumber findPhoneNumber( const QString &id ) const;
654 654
655 /** 655 /**
656 Insert a key. If a key with the same id already exists 656 Insert a key. If a key with the same id already exists
657 in this addressee it is not duplicated. 657 in this addressee it is not duplicated.
658 */ 658 */
659 void insertKey( const Key &key ); 659 void insertKey( const Key &key );
660 660
661 /** 661 /**
662 Remove a key. If no key with the given id exists for this 662 Remove a key. If no key with the given id exists for this
663 addresse nothing happens. 663 addresse nothing happens.
664 */ 664 */
665 void removeKey( const Key &key ); 665 void removeKey( const Key &key );
666 666
667 /** 667 /**
668 Return key, which matches the given type. 668 Return key, which matches the given type.
669 If @p type == Key::Custom you can specify a string 669 If @p type == Key::Custom you can specify a string
670 that should match. If you leave the string empty, the first 670 that should match. If you leave the string empty, the first
671 key with a custom value is returned. 671 key with a custom value is returned.
672 */ 672 */
673 Key key( int type, QString customTypeString = QString::null ) const; 673 Key key( int type, QString customTypeString = QString::null ) const;
674 674
675 /** 675 /**
676 Return list of all keys. 676 Return list of all keys.
677 */ 677 */
678 Key::List keys() const; 678 Key::List keys() const;
679 679
680 /** 680 /**
681 Set the list of keys 681 Set the list of keys
682 @param keys The keys to be set. 682 @param keys The keys to be set.
683 */ 683 */
684 void setKeys( const Key::List& keys); 684 void setKeys( const Key::List& keys);
685 685
686 /** 686 /**
687 Return list of keys with a special type. 687 Return list of keys with a special type.
688 If @p type == Key::Custom you can specify a string 688 If @p type == Key::Custom you can specify a string
689 that should match. If you leave the string empty, all custom 689 that should match. If you leave the string empty, all custom
690 keys will be returned. 690 keys will be returned.
691 */ 691 */
692 Key::List keys( int type, QString customTypeString = QString::null ) const; 692 Key::List keys( int type, QString customTypeString = QString::null ) const;
693 693
694 /** 694 /**
695 Return key with the given id. 695 Return key with the given id.
696 */ 696 */
697 Key findKey( const QString &id ) const; 697 Key findKey( const QString &id ) const;
698 698
699 /** 699 /**
700 Insert an address. If an address with the same id already exists 700 Insert an address. If an address with the same id already exists
701 in this addressee it is not duplicated. 701 in this addressee it is not duplicated.
702 */ 702 */
703 void insertAddress( const Address &address ); 703 void insertAddress( const Address &address );
704 704
705 /** 705 /**
706 Remove address. If no address with the given id exists for this 706 Remove address. If no address with the given id exists for this
707 addresse nothing happens. 707 addresse nothing happens.
708 */ 708 */
709 void removeAddress( const Address &address ); 709 void removeAddress( const Address &address );
710 710
711 /** 711 /**
712 Return address, which matches the given type. 712 Return address, which matches the given type.
713 */ 713 */
714 Address address( int type ) const; 714 Address address( int type ) const;
715 715
716 /** 716 /**
717 Return list of all addresses. 717 Return list of all addresses.
718 */ 718 */
719 Address::List addresses() const; 719 Address::List addresses() const;
720 720
721 /** 721 /**
722 Return list of addresses with a special type. 722 Return list of addresses with a special type.
723 */ 723 */
724 Address::List addresses( int type ) const; 724 Address::List addresses( int type ) const;
725 725
726 /** 726 /**
727 Return address with the given id. 727 Return address with the given id.
728 */ 728 */
729 Address findAddress( const QString &id ) const; 729 Address findAddress( const QString &id ) const;
730 730
731 /** 731 /**
732 Insert category. If the category already exists it is not duplicated. 732 Insert category. If the category already exists it is not duplicated.
733 */ 733 */
734 void insertCategory( const QString & ); 734 void insertCategory( const QString & );
735 735
736 /** 736 /**
737 Remove category. 737 Remove category.
738 */ 738 */
739 void removeCategory( const QString & ); 739 void removeCategory( const QString & );
740 740
741 /** 741 /**
742 Return, if addressee has the given category. 742 Return, if addressee has the given category.
743 */ 743 */
744 bool hasCategory( const QString & ) const; 744 bool hasCategory( const QString & ) const;
745 745
746 /** 746 /**
747 Set categories to given value. 747 Set categories to given value.
748 */ 748 */
749 void setCategories( const QStringList & ); 749 void setCategories( const QStringList & );
750 750
751 /** 751 /**
752 Return list of all set categories. 752 Return list of all set categories.
753 */ 753 */
754 QStringList categories() const; 754 QStringList categories() const;
755 755
756 /** 756 /**
757 Insert custom entry. The entry is identified by the name of the inserting 757 Insert custom entry. The entry is identified by the name of the inserting
758 application and a unique name. If an entry with the given app and name 758 application and a unique name. If an entry with the given app and name
759 already exists its value is replaced with the new given value. 759 already exists its value is replaced with the new given value.
760 */ 760 */
761 void insertCustom( const QString &app, const QString &name, 761 void insertCustom( const QString &app, const QString &name,
762 const QString &value ); 762 const QString &value );
763 763
764 /** 764 /**
765 Remove custom entry. 765 Remove custom entry.
766 */ 766 */
767 void removeCustom( const QString &app, const QString &name ); 767 void removeCustom( const QString &app, const QString &name );
768 768
769 /** 769 /**
770 Return value of custom entry, identified by app and entry name. 770 Return value of custom entry, identified by app and entry name.
771 */ 771 */
772 QString custom( const QString &app, const QString &name ) const; 772 QString custom( const QString &app, const QString &name ) const;
773 773
774 /** 774 /**
775 Set all custom entries. 775 Set all custom entries.
776 */ 776 */
777 void setCustoms( const QStringList & ); 777 void setCustoms( const QStringList & );
778 778
779 /** 779 /**
780 Return list of all custom entries. 780 Return list of all custom entries.
781 */ 781 */
782 QStringList customs() const; 782 QStringList customs() const;
783 783
784 /** 784 /**
785 Parse full email address. The result is given back in fullName and email. 785 Parse full email address. The result is given back in fullName and email.
786 */ 786 */
787 static void parseEmailAddress( const QString &rawEmail, QString &fullName, 787 static void parseEmailAddress( const QString &rawEmail, QString &fullName,
788 QString &email ); 788 QString &email );
789 789
790 /** 790 /**
791 Debug output. 791 Debug output.
792 */ 792 */
793 void dump() const; 793 void dump() const;
794 794
795 /** 795 /**
796 Returns string representation of the addressee. 796 Returns string representation of the addressee.
797 */ 797 */
798 QString asString() const; 798 QString asString() const;
799 799
800 /** 800 /**
801 Set resource where the addressee is from. 801 Set resource where the addressee is from.
802 */ 802 */
803 void setResource( Resource *resource ); 803 void setResource( Resource *resource );
804 804
805 /** 805 /**
806 Return pointer to resource. 806 Return pointer to resource.
807 */ 807 */
808 Resource *resource() const; 808 Resource *resource() const;
809 809
810 /** 810 /**
811 Return resourcelabel. 811 Return resourcelabel.
812 */ 812 */
813 //US 813 //US
814 static QString resourceLabel(); 814 static QString resourceLabel();
815 815
816 /** 816 /**
817 Mark addressee as changed. 817 Mark addressee as changed.
818 */ 818 */
819 void setChanged( bool value ); 819 void setChanged( bool value );
820 820
821 /** 821 /**
822 Return whether the addressee is changed. 822 Return whether the addressee is changed.
823 */ 823 */
824 bool changed() const; 824 bool changed() const;
825 825
826 private: 826 private:
827 Addressee copy(); 827 Addressee copy();
828 void detach(); 828 void detach();
829 int mTempSyncStat;
830 829
831 struct AddresseeData; 830 struct AddresseeData;
832 mutable KSharedPtr<AddresseeData> mData; 831 mutable KSharedPtr<AddresseeData> mData;
833}; 832};
834 833
835QDataStream &operator<<( QDataStream &, const Addressee & ); 834QDataStream &operator<<( QDataStream &, const Addressee & );
836QDataStream &operator>>( QDataStream &, Addressee & ); 835QDataStream &operator>>( QDataStream &, Addressee & );
837 836
838} 837}
839 838
840#endif 839#endif
diff --git a/kabc/stdaddressbook.cpp b/kabc/stdaddressbook.cpp
index ec47a4e..181a09e 100644
--- a/kabc/stdaddressbook.cpp
+++ b/kabc/stdaddressbook.cpp
@@ -1,224 +1,229 @@
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 <qdir.h> 28#include <qdir.h>
29#include "resource.h" 29#include "resource.h"
30#include <kresources/manager.h> 30#include <kresources/manager.h>
31#include <kdebug.h> 31#include <kdebug.h>
32#include <klocale.h> 32#include <klocale.h>
33#include <kstaticdeleter.h> 33#include <kstaticdeleter.h>
34#include <kstandarddirs.h> 34#include <kstandarddirs.h>
35 35
36#include "stdaddressbook.h" 36#include "stdaddressbook.h"
37 37
38using namespace KABC; 38using namespace KABC;
39 39
40StdAddressBook *StdAddressBook::mSelf = 0; 40StdAddressBook *StdAddressBook::mSelf = 0;
41bool StdAddressBook::mAutomaticSave = true; 41bool StdAddressBook::mAutomaticSave = true;
42 42
43static KStaticDeleter<StdAddressBook> addressBookDeleter; 43static KStaticDeleter<StdAddressBook> addressBookDeleter;
44 44
45QString StdAddressBook::fileName() 45QString StdAddressBook::fileName()
46{ 46{
47 return locateLocal( "data", "kabc/std.vcf" ); 47 return locateLocal( "data", "kabc/std.vcf" );
48} 48}
49 49
50QString StdAddressBook::directoryName() 50QString StdAddressBook::directoryName()
51{ 51{
52 return locateLocal( "data", "kabc/stdvcf" ); 52 return locateLocal( "data", "kabc/stdvcf" );
53} 53}
54 54
55void StdAddressBook::handleCrash() 55void StdAddressBook::handleCrash()
56{ 56{
57 StdAddressBook::self()->cleanUp(); 57 StdAddressBook::self()->cleanUp();
58} 58}
59 59
60StdAddressBook *StdAddressBook::self() 60StdAddressBook *StdAddressBook::self()
61{ 61{
62 62
63 if ( !mSelf ) 63 if ( !mSelf )
64 { 64 {
65 QString appdir = StdAddressBook::setTempAppDir(); 65 QString appdir = StdAddressBook::setTempAppDir();
66// US im am not sure why I have to use the other format here?? 66// US im am not sure why I have to use the other format here??
67#ifdef KAB_EMBEDDED 67#ifdef KAB_EMBEDDED
68 mSelf = addressBookDeleter.setObject( new StdAddressBook ); 68 mSelf = addressBookDeleter.setObject( new StdAddressBook );
69#else //KAB_EMBEDDED 69#else //KAB_EMBEDDED
70 addressBookDeleter.setObject( mSelf, new StdAddressBook ); 70 addressBookDeleter.setObject( mSelf, new StdAddressBook );
71#endif //KAB_EMBEDDED 71#endif //KAB_EMBEDDED
72 KStandardDirs::setAppDir( appdir ); 72 KStandardDirs::setAppDir( appdir );
73 } 73 }
74 74
75 return mSelf; 75 return mSelf;
76} 76}
77 77
78QString StdAddressBook::setTempAppDir() 78QString StdAddressBook::setTempAppDir()
79{ 79{
80 QString appDIR = KStandardDirs::appDir(); 80 QString appDIR = KStandardDirs::appDir();
81#ifdef DESKTOP_VERSION 81#ifdef DESKTOP_VERSION
82 QString appdir = QDir::homeDirPath(); 82 QString appdir = QDir::homeDirPath();
83 if ( appdir.right(1) == "\\" || appdir.right(1) == "/" ) 83 if ( appdir.right(1) == "\\" || appdir.right(1) == "/" )
84 appdir += "kaddressbook/"; 84 appdir += "kaddressbook/";
85 else 85 else
86 appdir += "/kaddressbook/"; 86 appdir += "/kaddressbook/";
87 KStandardDirs::setAppDir( QDir::convertSeparators( appdir )); 87 KStandardDirs::setAppDir( QDir::convertSeparators( appdir ));
88#else 88#else
89 QString appdir = QDir::homeDirPath() + "/kdepim/apps/kaddressbook"; 89 QString appdir = QDir::homeDirPath() + "/kdepim/apps/kaddressbook";
90 90
91 KStandardDirs::setAppDir( appdir ); 91 KStandardDirs::setAppDir( appdir );
92#endif 92#endif
93 93
94 return appDIR; 94 return appDIR;
95} 95}
96StdAddressBook *StdAddressBook::self( bool onlyFastResources ) 96StdAddressBook *StdAddressBook::self( bool onlyFastResources )
97{ 97{
98 98
99 if ( !mSelf ) 99 if ( !mSelf )
100 { 100 {
101 QString appdir =StdAddressBook::setTempAppDir(); 101 QString appdir =StdAddressBook::setTempAppDir();
102#ifdef KAB_EMBEDDED 102#ifdef KAB_EMBEDDED
103 mSelf = addressBookDeleter.setObject( new StdAddressBook( onlyFastResources ) ); 103 mSelf = addressBookDeleter.setObject( new StdAddressBook( onlyFastResources ) );
104#else //KAB_EMBEDDED 104#else //KAB_EMBEDDED
105 addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) ); 105 addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) );
106#endif //KAB_EMBEDDED 106#endif //KAB_EMBEDDED
107 KStandardDirs::setAppDir( appdir ); 107 KStandardDirs::setAppDir( appdir );
108 } 108 }
109 return mSelf; 109 return mSelf;
110} 110}
111 111
112StdAddressBook::StdAddressBook() 112StdAddressBook::StdAddressBook()
113 : AddressBook( "kabcrc" ) 113 : AddressBook( "kabcrc" )
114{ 114{
115 115
116 init( false ); 116 init( false );
117} 117}
118 118
119StdAddressBook::StdAddressBook( bool onlyFastResources ) 119StdAddressBook::StdAddressBook( bool onlyFastResources )
120 : AddressBook( "kabcrc" ) 120 : AddressBook( "kabcrc" )
121{ 121{
122 122
123 init( onlyFastResources ); 123 init( onlyFastResources );
124} 124}
125 125
126StdAddressBook::~StdAddressBook() 126StdAddressBook::~StdAddressBook()
127{ 127{
128 if ( mAutomaticSave ) 128 if ( mAutomaticSave )
129 save(); 129 save();
130} 130}
131 131
132void StdAddressBook::init( bool ) 132void StdAddressBook::init( bool )
133{ 133{
134 KRES::Manager<Resource> *manager = resourceManager(); 134 KRES::Manager<Resource> *manager = resourceManager();
135 KRES::Manager<Resource>::ActiveIterator it; 135 KRES::Manager<Resource>::ActiveIterator it;
136 136
137 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 137 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
138 (*it)->setAddressBook( this ); 138 (*it)->setAddressBook( this );
139 if ( !(*it)->open() ) 139 if ( !(*it)->open() )
140 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 140 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
141 } 141 }
142 142
143 Resource *res = standardResource(); 143 Resource *res = standardResource();
144 if ( !res ) { 144 if ( !res ) {
145 res = manager->createResource( "file" ); 145 res = manager->createResource( "file" );
146 if ( res ) 146 if ( res )
147 { 147 {
148 addResource( res ); 148 addResource( res );
149 } 149 }
150 else 150 else
151 qDebug(" No resource available!!!"); 151 qDebug(" No resource available!!!");
152 } 152 }
153 153
154 setStandardResource( res ); 154 setStandardResource( res );
155 manager->writeConfig(); 155 manager->writeConfig();
156 156
157 load(); 157 load();
158} 158}
159 159
160bool StdAddressBook::save() 160bool StdAddressBook::save()
161{ 161{
162 kdDebug(5700) << "StdAddressBook::save()" << endl; 162 kdDebug(5700) << "StdAddressBook::save()" << endl;
163 163
164 bool ok = true; 164 bool ok = true;
165 AddressBook *ab = self(); 165 AddressBook *ab = self();
166 166
167 ab->deleteRemovedAddressees(); 167 ab->deleteRemovedAddressees();
168 168 Iterator ait;
169 for ( ait = ab->begin(); ait != ab->end(); ++ait ) {
170 if ( !(*ait).IDStr().isEmpty() ) {
171 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
172 }
173 }
169 KRES::Manager<Resource>::ActiveIterator it; 174 KRES::Manager<Resource>::ActiveIterator it;
170 KRES::Manager<Resource> *manager = ab->resourceManager(); 175 KRES::Manager<Resource> *manager = ab->resourceManager();
171 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 176 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
172 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 177 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
173 Ticket *ticket = ab->requestSaveTicket( *it ); 178 Ticket *ticket = ab->requestSaveTicket( *it );
174// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 179// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
175 if ( !ticket ) { 180 if ( !ticket ) {
176 ab->error( i18n( "Unable to save to resource '%1'. It is locked." ) 181 ab->error( i18n( "Unable to save to resource '%1'. It is locked." )
177 .arg( (*it)->resourceName() ) ); 182 .arg( (*it)->resourceName() ) );
178 return false; 183 return false;
179 } 184 }
180 185
181 if ( !ab->save( ticket ) ) 186 if ( !ab->save( ticket ) )
182 ok = false; 187 ok = false;
183 } 188 }
184 } 189 }
185 190
186 return ok; 191 return ok;
187} 192}
188 193
189void StdAddressBook::close() 194void StdAddressBook::close()
190{ 195{
191//US destructObject is not defined on my system???. Is setObject(0) the same ??? 196//US destructObject is not defined on my system???. Is setObject(0) the same ???
192//US addressBookDeleter.destructObject(); 197//US addressBookDeleter.destructObject();
193 addressBookDeleter.setObject(0); 198 addressBookDeleter.setObject(0);
194 199
195} 200}
196 201
197void StdAddressBook::setAutomaticSave( bool enable ) 202void StdAddressBook::setAutomaticSave( bool enable )
198{ 203{
199 mAutomaticSave = enable; 204 mAutomaticSave = enable;
200} 205}
201 206
202bool StdAddressBook::automaticSave() 207bool StdAddressBook::automaticSave()
203{ 208{
204 return mAutomaticSave; 209 return mAutomaticSave;
205} 210}
206 211
207// should get const for 4.X 212// should get const for 4.X
208Addressee StdAddressBook::whoAmI() 213Addressee StdAddressBook::whoAmI()
209{ 214{
210//US KConfig config( "kabcrc" ); 215//US KConfig config( "kabcrc" );
211 KConfig config( locateLocal("config", "kabcrc") ); 216 KConfig config( locateLocal("config", "kabcrc") );
212 config.setGroup( "General" ); 217 config.setGroup( "General" );
213 218
214 return findByUid( config.readEntry( "WhoAmI" ) ); 219 return findByUid( config.readEntry( "WhoAmI" ) );
215} 220}
216 221
217void StdAddressBook::setWhoAmI( const Addressee &addr ) 222void StdAddressBook::setWhoAmI( const Addressee &addr )
218{ 223{
219//US KConfig config( "kabcrc" ); 224//US KConfig config( "kabcrc" );
220 KConfig config( locateLocal("config", "kabcrc") ); 225 KConfig config( locateLocal("config", "kabcrc") );
221 config.setGroup( "General" ); 226 config.setGroup( "General" );
222 227
223 config.writeEntry( "WhoAmI", addr.uid() ); 228 config.writeEntry( "WhoAmI", addr.uid() );
224} 229}