summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
authorzautrix <zautrix>2005-12-02 09:10:14 (UTC)
committer zautrix <zautrix>2005-12-02 09:10:14 (UTC)
commit64be8d64fc26d1025a24150d065197ba5d608f3d (patch) (unidiff)
tree4f7b0c82641ac591af04f6fdd541b662d4727850 /kabc/addressbook.cpp
parent2bd8aff44e90b6d58e2037771db8b38846addb3e (diff)
downloadkdepimpi-64be8d64fc26d1025a24150d065197ba5d608f3d.zip
kdepimpi-64be8d64fc26d1025a24150d065197ba5d608f3d.tar.gz
kdepimpi-64be8d64fc26d1025a24150d065197ba5d608f3d.tar.bz2
more sync
Diffstat (limited to 'kabc/addressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp24
1 files changed, 15 insertions, 9 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index f3744bc..e04f4b1 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -1,1266 +1,1272 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28/*US 28/*US
29 29
30#include <qfile.h> 30#include <qfile.h>
31#include <qregexp.h> 31#include <qregexp.h>
32#include <qtimer.h> 32#include <qtimer.h>
33 33
34#include <kapplication.h> 34#include <kapplication.h>
35#include <kinstance.h> 35#include <kinstance.h>
36#include <kstandarddirs.h> 36#include <kstandarddirs.h>
37 37
38#include "errorhandler.h" 38#include "errorhandler.h"
39*/ 39*/
40#include <qptrlist.h> 40#include <qptrlist.h>
41#include <qtextstream.h> 41#include <qtextstream.h>
42#include <qfile.h> 42#include <qfile.h>
43#include <qregexp.h> 43#include <qregexp.h>
44 44
45#include <kglobal.h> 45#include <kglobal.h>
46#include <klocale.h> 46#include <klocale.h>
47#include <kmessagebox.h> 47#include <kmessagebox.h>
48#include <kdebug.h> 48#include <kdebug.h>
49#include <libkcal/syncdefines.h> 49#include <libkcal/syncdefines.h>
50#include <libkdepim/phoneaccess.h> 50#include <libkdepim/phoneaccess.h>
51#include "addressbook.h" 51#include "addressbook.h"
52#include "resource.h" 52#include "resource.h"
53#include "vcardconverter.h" 53#include "vcardconverter.h"
54#include "vcardparser/vcardtool.h" 54#include "vcardparser/vcardtool.h"
55 55
56//US #include "addressbook.moc" 56//US #include "addressbook.moc"
57 57
58using namespace KABC; 58using namespace KABC;
59 59
60struct AddressBook::AddressBookData 60struct AddressBook::AddressBookData
61{ 61{
62 Addressee::List mAddressees; 62 Addressee::List mAddressees;
63 Addressee::List mRemovedAddressees; 63 Addressee::List mRemovedAddressees;
64 Field::List mAllFields; 64 Field::List mAllFields;
65 KConfig *mConfig; 65 KConfig *mConfig;
66 KRES::Manager<Resource> *mManager; 66 KRES::Manager<Resource> *mManager;
67//US ErrorHandler *mErrorHandler; 67//US ErrorHandler *mErrorHandler;
68}; 68};
69 69
70struct AddressBook::Iterator::IteratorData 70struct AddressBook::Iterator::IteratorData
71{ 71{
72 Addressee::List::Iterator mIt; 72 Addressee::List::Iterator mIt;
73}; 73};
74 74
75struct AddressBook::ConstIterator::ConstIteratorData 75struct AddressBook::ConstIterator::ConstIteratorData
76{ 76{
77 Addressee::List::ConstIterator mIt; 77 Addressee::List::ConstIterator mIt;
78}; 78};
79 79
80AddressBook::Iterator::Iterator() 80AddressBook::Iterator::Iterator()
81{ 81{
82 d = new IteratorData; 82 d = new IteratorData;
83} 83}
84 84
85AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) 85AddressBook::Iterator::Iterator( const AddressBook::Iterator &i )
86{ 86{
87 d = new IteratorData; 87 d = new IteratorData;
88 d->mIt = i.d->mIt; 88 d->mIt = i.d->mIt;
89} 89}
90 90
91AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) 91AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i )
92{ 92{
93 if( this == &i ) return *this; // guard against self assignment 93 if( this == &i ) return *this; // guard against self assignment
94 delete d; // delete the old data the Iterator was completely constructed before 94 delete d; // delete the old data the Iterator was completely constructed before
95 d = new IteratorData; 95 d = new IteratorData;
96 d->mIt = i.d->mIt; 96 d->mIt = i.d->mIt;
97 return *this; 97 return *this;
98} 98}
99 99
100AddressBook::Iterator::~Iterator() 100AddressBook::Iterator::~Iterator()
101{ 101{
102 delete d; 102 delete d;
103} 103}
104 104
105const Addressee &AddressBook::Iterator::operator*() const 105const Addressee &AddressBook::Iterator::operator*() const
106{ 106{
107 return *(d->mIt); 107 return *(d->mIt);
108} 108}
109 109
110Addressee &AddressBook::Iterator::operator*() 110Addressee &AddressBook::Iterator::operator*()
111{ 111{
112 return *(d->mIt); 112 return *(d->mIt);
113} 113}
114 114
115Addressee *AddressBook::Iterator::operator->() 115Addressee *AddressBook::Iterator::operator->()
116{ 116{
117 return &(*(d->mIt)); 117 return &(*(d->mIt));
118} 118}
119 119
120AddressBook::Iterator &AddressBook::Iterator::operator++() 120AddressBook::Iterator &AddressBook::Iterator::operator++()
121{ 121{
122 (d->mIt)++; 122 (d->mIt)++;
123 return *this; 123 return *this;
124} 124}
125 125
126AddressBook::Iterator &AddressBook::Iterator::operator++(int) 126AddressBook::Iterator &AddressBook::Iterator::operator++(int)
127{ 127{
128 (d->mIt)++; 128 (d->mIt)++;
129 return *this; 129 return *this;
130} 130}
131 131
132AddressBook::Iterator &AddressBook::Iterator::operator--() 132AddressBook::Iterator &AddressBook::Iterator::operator--()
133{ 133{
134 (d->mIt)--; 134 (d->mIt)--;
135 return *this; 135 return *this;
136} 136}
137 137
138AddressBook::Iterator &AddressBook::Iterator::operator--(int) 138AddressBook::Iterator &AddressBook::Iterator::operator--(int)
139{ 139{
140 (d->mIt)--; 140 (d->mIt)--;
141 return *this; 141 return *this;
142} 142}
143 143
144bool AddressBook::Iterator::operator==( const Iterator &it ) 144bool AddressBook::Iterator::operator==( const Iterator &it )
145{ 145{
146 return ( d->mIt == it.d->mIt ); 146 return ( d->mIt == it.d->mIt );
147} 147}
148 148
149bool AddressBook::Iterator::operator!=( const Iterator &it ) 149bool AddressBook::Iterator::operator!=( const Iterator &it )
150{ 150{
151 return ( d->mIt != it.d->mIt ); 151 return ( d->mIt != it.d->mIt );
152} 152}
153 153
154 154
155AddressBook::ConstIterator::ConstIterator() 155AddressBook::ConstIterator::ConstIterator()
156{ 156{
157 d = new ConstIteratorData; 157 d = new ConstIteratorData;
158} 158}
159 159
160AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) 160AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i )
161{ 161{
162 d = new ConstIteratorData; 162 d = new ConstIteratorData;
163 d->mIt = i.d->mIt; 163 d->mIt = i.d->mIt;
164} 164}
165 165
166AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) 166AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i )
167{ 167{
168 if( this == &i ) return *this; // guard for self assignment 168 if( this == &i ) return *this; // guard for self assignment
169 delete d; // delete the old data because the Iterator was really constructed before 169 delete d; // delete the old data because the Iterator was really constructed before
170 d = new ConstIteratorData; 170 d = new ConstIteratorData;
171 d->mIt = i.d->mIt; 171 d->mIt = i.d->mIt;
172 return *this; 172 return *this;
173} 173}
174 174
175AddressBook::ConstIterator::~ConstIterator() 175AddressBook::ConstIterator::~ConstIterator()
176{ 176{
177 delete d; 177 delete d;
178} 178}
179 179
180const Addressee &AddressBook::ConstIterator::operator*() const 180const Addressee &AddressBook::ConstIterator::operator*() const
181{ 181{
182 return *(d->mIt); 182 return *(d->mIt);
183} 183}
184 184
185const Addressee* AddressBook::ConstIterator::operator->() const 185const Addressee* AddressBook::ConstIterator::operator->() const
186{ 186{
187 return &(*(d->mIt)); 187 return &(*(d->mIt));
188} 188}
189 189
190AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() 190AddressBook::ConstIterator &AddressBook::ConstIterator::operator++()
191{ 191{
192 (d->mIt)++; 192 (d->mIt)++;
193 return *this; 193 return *this;
194} 194}
195 195
196AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) 196AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int)
197{ 197{
198 (d->mIt)++; 198 (d->mIt)++;
199 return *this; 199 return *this;
200} 200}
201 201
202AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() 202AddressBook::ConstIterator &AddressBook::ConstIterator::operator--()
203{ 203{
204 (d->mIt)--; 204 (d->mIt)--;
205 return *this; 205 return *this;
206} 206}
207 207
208AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) 208AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int)
209{ 209{
210 (d->mIt)--; 210 (d->mIt)--;
211 return *this; 211 return *this;
212} 212}
213 213
214bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) 214bool AddressBook::ConstIterator::operator==( const ConstIterator &it )
215{ 215{
216 return ( d->mIt == it.d->mIt ); 216 return ( d->mIt == it.d->mIt );
217} 217}
218 218
219bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) 219bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
220{ 220{
221 return ( d->mIt != it.d->mIt ); 221 return ( d->mIt != it.d->mIt );
222} 222}
223 223
224 224
225AddressBook::AddressBook() 225AddressBook::AddressBook()
226{ 226{
227 init(0, "contact"); 227 init(0, "contact");
228} 228}
229 229
230AddressBook::AddressBook( const QString &config ) 230AddressBook::AddressBook( const QString &config )
231{ 231{
232 init(config, "contact"); 232 init(config, "contact");
233} 233}
234 234
235AddressBook::AddressBook( const QString &config, const QString &family ) 235AddressBook::AddressBook( const QString &config, const QString &family )
236{ 236{
237 init(config, family); 237 init(config, family);
238 238
239} 239}
240 240
241// the default family is "contact" 241// the default family is "contact"
242void AddressBook::init(const QString &config, const QString &family ) 242void AddressBook::init(const QString &config, const QString &family )
243{ 243{
244 blockLSEchange = false; 244 blockLSEchange = false;
245 d = new AddressBookData; 245 d = new AddressBookData;
246 QString fami = family; 246 QString fami = family;
247 if (config != 0) { 247 if (config != 0) {
248 if ( family == "syncContact" ) { 248 if ( family == "syncContact" ) {
249 qDebug("creating sync config "); 249 qDebug("creating sync config ");
250 fami = "contact"; 250 fami = "contact";
251 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); 251 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") );
252 con->setGroup( "General" ); 252 con->setGroup( "General" );
253 con->writeEntry( "ResourceKeys", QString("sync") ); 253 con->writeEntry( "ResourceKeys", QString("sync") );
254 con->writeEntry( "Standard", QString("sync") ); 254 con->writeEntry( "Standard", QString("sync") );
255 con->setGroup( "Resource_sync" ); 255 con->setGroup( "Resource_sync" );
256 con->writeEntry( "FileName", config ); 256 con->writeEntry( "FileName", config );
257 con->writeEntry( "FileFormat", QString("vcard") ); 257 con->writeEntry( "FileFormat", QString("vcard") );
258 con->writeEntry( "ResourceIdentifier", QString("sync") ); 258 con->writeEntry( "ResourceIdentifier", QString("sync") );
259 con->writeEntry( "ResourceName", QString("sync_res") ); 259 con->writeEntry( "ResourceName", QString("sync_res") );
260 if ( config.right(4) == ".xml" ) 260 if ( config.right(4) == ".xml" )
261 con->writeEntry( "ResourceType", QString("qtopia") ); 261 con->writeEntry( "ResourceType", QString("qtopia") );
262 else if ( config == "sharp" ) { 262 else if ( config == "sharp" ) {
263 con->writeEntry( "ResourceType", QString("sharp") ); 263 con->writeEntry( "ResourceType", QString("sharp") );
264 } else { 264 } else {
265 con->writeEntry( "ResourceType", QString("file") ); 265 con->writeEntry( "ResourceType", QString("file") );
266 } 266 }
267 //con->sync(); 267 //con->sync();
268 d->mConfig = con; 268 d->mConfig = con;
269 } 269 }
270 else 270 else
271 d->mConfig = new KConfig( locateLocal("config", config) ); 271 d->mConfig = new KConfig( locateLocal("config", config) );
272// qDebug("AddressBook::init 1 config=%s",config.latin1() ); 272// qDebug("AddressBook::init 1 config=%s",config.latin1() );
273 } 273 }
274 else { 274 else {
275 d->mConfig = 0; 275 d->mConfig = 0;
276// qDebug("AddressBook::init 1 config=0"); 276// qDebug("AddressBook::init 1 config=0");
277 } 277 }
278 278
279//US d->mErrorHandler = 0; 279//US d->mErrorHandler = 0;
280 d->mManager = new KRES::Manager<Resource>( fami ); 280 d->mManager = new KRES::Manager<Resource>( fami );
281 d->mManager->readConfig( d->mConfig ); 281 d->mManager->readConfig( d->mConfig );
282 if ( family == "syncContact" ) { 282 if ( family == "syncContact" ) {
283 KRES::Manager<Resource> *manager = d->mManager; 283 KRES::Manager<Resource> *manager = d->mManager;
284 KRES::Manager<Resource>::ActiveIterator it; 284 KRES::Manager<Resource>::ActiveIterator it;
285 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 285 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
286 (*it)->setAddressBook( this ); 286 (*it)->setAddressBook( this );
287 if ( !(*it)->open() ) 287 if ( !(*it)->open() )
288 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 288 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
289 } 289 }
290 Resource *res = standardResource(); 290 Resource *res = standardResource();
291 if ( !res ) { 291 if ( !res ) {
292 qDebug("ERROR: no standard resource"); 292 qDebug("ERROR: no standard resource");
293 res = manager->createResource( "file" ); 293 res = manager->createResource( "file" );
294 if ( res ) 294 if ( res )
295 { 295 {
296 addResource( res ); 296 addResource( res );
297 } 297 }
298 else 298 else
299 qDebug(" No resource available!!!"); 299 qDebug(" No resource available!!!");
300 } 300 }
301 setStandardResource( res ); 301 setStandardResource( res );
302 manager->writeConfig(); 302 manager->writeConfig();
303 } 303 }
304 addCustomField( i18n( "Department" ), KABC::Field::Organization, 304 addCustomField( i18n( "Department" ), KABC::Field::Organization,
305 "X-Department", "KADDRESSBOOK" ); 305 "X-Department", "KADDRESSBOOK" );
306 addCustomField( i18n( "Profession" ), KABC::Field::Organization, 306 addCustomField( i18n( "Profession" ), KABC::Field::Organization,
307 "X-Profession", "KADDRESSBOOK" ); 307 "X-Profession", "KADDRESSBOOK" );
308 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 308 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
309 "X-AssistantsName", "KADDRESSBOOK" ); 309 "X-AssistantsName", "KADDRESSBOOK" );
310 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 310 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
311 "X-ManagersName", "KADDRESSBOOK" ); 311 "X-ManagersName", "KADDRESSBOOK" );
312 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 312 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
313 "X-SpousesName", "KADDRESSBOOK" ); 313 "X-SpousesName", "KADDRESSBOOK" );
314 addCustomField( i18n( "Office" ), KABC::Field::Personal, 314 addCustomField( i18n( "Office" ), KABC::Field::Personal,
315 "X-Office", "KADDRESSBOOK" ); 315 "X-Office", "KADDRESSBOOK" );
316 addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 316 addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
317 "X-IMAddress", "KADDRESSBOOK" ); 317 "X-IMAddress", "KADDRESSBOOK" );
318 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 318 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
319 "X-Anniversary", "KADDRESSBOOK" ); 319 "X-Anniversary", "KADDRESSBOOK" );
320 320
321 //US added this field to become compatible with Opie/qtopia addressbook 321 //US added this field to become compatible with Opie/qtopia addressbook
322 // values can be "female" or "male" or "". An empty field represents undefined. 322 // values can be "female" or "male" or "". An empty field represents undefined.
323 addCustomField( i18n( "Gender" ), KABC::Field::Personal, 323 addCustomField( i18n( "Gender" ), KABC::Field::Personal,
324 "X-Gender", "KADDRESSBOOK" ); 324 "X-Gender", "KADDRESSBOOK" );
325 addCustomField( i18n( "Children" ), KABC::Field::Personal, 325 addCustomField( i18n( "Children" ), KABC::Field::Personal,
326 "X-Children", "KADDRESSBOOK" ); 326 "X-Children", "KADDRESSBOOK" );
327 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 327 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
328 "X-FreeBusyUrl", "KADDRESSBOOK" ); 328 "X-FreeBusyUrl", "KADDRESSBOOK" );
329 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, 329 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal,
330 "X-ExternalID", "KADDRESSBOOK" ); 330 "X-ExternalID", "KADDRESSBOOK" );
331} 331}
332 332
333AddressBook::~AddressBook() 333AddressBook::~AddressBook()
334{ 334{
335 delete d->mConfig; d->mConfig = 0; 335 delete d->mConfig; d->mConfig = 0;
336 delete d->mManager; d->mManager = 0; 336 delete d->mManager; d->mManager = 0;
337//US delete d->mErrorHandler; d->mErrorHandler = 0; 337//US delete d->mErrorHandler; d->mErrorHandler = 0;
338 delete d; d = 0; 338 delete d; d = 0;
339} 339}
340 340
341bool AddressBook::load() 341bool AddressBook::load()
342{ 342{
343 343
344 clear(); 344 clear();
345 KRES::Manager<Resource>::ActiveIterator it; 345 KRES::Manager<Resource>::ActiveIterator it;
346 bool ok = true; 346 bool ok = true;
347 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 347 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
348 if ( !(*it)->load() ) { 348 if ( !(*it)->load() ) {
349 qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 349 qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
350 ok = false; 350 ok = false;
351 } else { 351 } else {
352 qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); 352 qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) );
353 } 353 }
354 // mark all addressees as unchanged 354 // mark all addressees as unchanged
355 Addressee::List::Iterator addrIt; 355 Addressee::List::Iterator addrIt;
356 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { 356 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) {
357 (*addrIt).setChanged( false ); 357 (*addrIt).setChanged( false );
358 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); 358 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" );
359 if ( !id.isEmpty() ) { 359 if ( !id.isEmpty() ) {
360 //qDebug("setId aa %s ", id.latin1()); 360 //qDebug("setId aa %s ", id.latin1());
361 (*addrIt).setIDStr(id ); 361 (*addrIt).setIDStr(id );
362 } 362 }
363 } 363 }
364 blockLSEchange = true; 364 blockLSEchange = true;
365 return ok; 365 return ok;
366} 366}
367 367
368bool AddressBook::save( Ticket *ticket ) 368bool AddressBook::save( Ticket *ticket )
369{ 369{
370 kdDebug(5700) << "AddressBook::save()"<< endl; 370 kdDebug(5700) << "AddressBook::save()"<< endl;
371 371
372 if ( ticket->resource() ) { 372 if ( ticket->resource() ) {
373 deleteRemovedAddressees(); 373 deleteRemovedAddressees();
374 return ticket->resource()->save( ticket ); 374 return ticket->resource()->save( ticket );
375 } 375 }
376 376
377 return false; 377 return false;
378} 378}
379// exports all Addressees, which are syncable 379// exports all Addressees, which are syncable
380void AddressBook::export2File( QString fileName ) 380void AddressBook::export2File( QString fileName, QString resourceName )
381{ 381{
382 382
383 QFile outFile( fileName ); 383 QFile outFile( fileName );
384 if ( !outFile.open( IO_WriteOnly ) ) { 384 if ( !outFile.open( IO_WriteOnly ) ) {
385 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); 385 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" );
386 KMessageBox::error( 0, text.arg( fileName ) ); 386 KMessageBox::error( 0, text.arg( fileName ) );
387 return ; 387 return ;
388 } 388 }
389 QTextStream t( &outFile ); 389 QTextStream t( &outFile );
390 t.setEncoding( QTextStream::UnicodeUTF8 ); 390 t.setEncoding( QTextStream::UnicodeUTF8 );
391 Iterator it; 391 Iterator it;
392 KABC::VCardConverter::Version version; 392 KABC::VCardConverter::Version version;
393 version = KABC::VCardConverter::v3_0; 393 version = KABC::VCardConverter::v3_0;
394 for ( it = begin(); it != end(); ++it ) { 394 for ( it = begin(); it != end(); ++it ) {
395 if ( (*it).resource() && (*it).resource()->includeInSync() ) { 395 if ( (*it).resource() ) {
396 if ( !(*it).IDStr().isEmpty() ) { 396 bool include = (*it).resource()->includeInSync();
397 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); 397 if ( !resourceName.isEmpty() )
398 include = (resourceName == (*it).resource()->name() );
399 if ( include ) {
400 qDebug(QString ("Exporting resource %1 to file %2").arg( (*it).resource()->name() ).arg( fileName ) );
401 if ( !(*it).IDStr().isEmpty() ) {
402 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() );
403 }
404 KABC::VCardConverter converter;
405 QString vcard;
406 //Resource *resource() const;
407 converter.addresseeToVCard( *it, vcard, version );
408 t << vcard << "\r\n";
398 } 409 }
399 KABC::VCardConverter converter;
400 QString vcard;
401 //Resource *resource() const;
402 converter.addresseeToVCard( *it, vcard, version );
403 t << vcard << "\r\n";
404 } 410 }
405 } 411 }
406 t << "\r\n\r\n"; 412 t << "\r\n\r\n";
407 outFile.close(); 413 outFile.close();
408} 414}
409// if QStringList uids is empty, all are exported 415// if QStringList uids is empty, all are exported
410bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) 416bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName )
411{ 417{
412 KABC::VCardConverter converter; 418 KABC::VCardConverter converter;
413 QString datastream; 419 QString datastream;
414 Iterator it; 420 Iterator it;
415 bool all = uids.isEmpty(); 421 bool all = uids.isEmpty();
416 for ( it = begin(); it != end(); ++it ) { 422 for ( it = begin(); it != end(); ++it ) {
417 // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 423 // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
418 if ( ! all ) { 424 if ( ! all ) {
419 if ( ! ( uids.contains((*it).uid() ) )) 425 if ( ! ( uids.contains((*it).uid() ) ))
420 continue; 426 continue;
421 } 427 }
422 KABC::Addressee a = ( *it ); 428 KABC::Addressee a = ( *it );
423 if ( a.isEmpty() ) 429 if ( a.isEmpty() )
424 continue; 430 continue;
425 if ( all && a.resource() && !a.resource()->includeInSync() ) 431 if ( all && a.resource() && !a.resource()->includeInSync() )
426 continue; 432 continue;
427 a.simplifyEmails(); 433 a.simplifyEmails();
428 a.simplifyPhoneNumbers(); 434 a.simplifyPhoneNumbers();
429 a.simplifyPhoneNumberTypes(); 435 a.simplifyPhoneNumberTypes();
430 a.simplifyAddresses(); 436 a.simplifyAddresses();
431 437
432 QString vcard; 438 QString vcard;
433 QString vcardnew; 439 QString vcardnew;
434 converter.addresseeToVCard( a, vcard ); 440 converter.addresseeToVCard( a, vcard );
435 int start = 0; 441 int start = 0;
436 int next; 442 int next;
437 while ( (next = vcard.find("TYPE=", start) )>= 0 ) { 443 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
438 int semi = vcard.find(";", next); 444 int semi = vcard.find(";", next);
439 int dopp = vcard.find(":", next); 445 int dopp = vcard.find(":", next);
440 int sep; 446 int sep;
441 if ( semi < dopp && semi >= 0 ) 447 if ( semi < dopp && semi >= 0 )
442 sep = semi ; 448 sep = semi ;
443 else 449 else
444 sep = dopp; 450 sep = dopp;
445 vcardnew +=vcard.mid( start, next - start); 451 vcardnew +=vcard.mid( start, next - start);
446 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); 452 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper();
447 start = sep; 453 start = sep;
448 } 454 }
449 vcardnew += vcard.mid( start,vcard.length() ); 455 vcardnew += vcard.mid( start,vcard.length() );
450 vcard = ""; 456 vcard = "";
451 start = 0; 457 start = 0;
452 while ( (next = vcardnew.find("ADR", start) )>= 0 ) { 458 while ( (next = vcardnew.find("ADR", start) )>= 0 ) {
453 int sep = vcardnew.find(":", next); 459 int sep = vcardnew.find(":", next);
454 vcard +=vcardnew.mid( start, next - start+3); 460 vcard +=vcardnew.mid( start, next - start+3);
455 start = sep; 461 start = sep;
456 } 462 }
457 vcard += vcardnew.mid( start,vcardnew.length() ); 463 vcard += vcardnew.mid( start,vcardnew.length() );
458 vcard.replace ( QRegExp(";;;") , "" ); 464 vcard.replace ( QRegExp(";;;") , "" );
459 vcard.replace ( QRegExp(";;") , "" ); 465 vcard.replace ( QRegExp(";;") , "" );
460 datastream += vcard; 466 datastream += vcard;
461 467
462 } 468 }
463 469
464 QFile outFile(fileName); 470 QFile outFile(fileName);
465 if ( outFile.open(IO_WriteOnly) ) { 471 if ( outFile.open(IO_WriteOnly) ) {
466 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); 472 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
467 QTextStream t( &outFile ); // use a text stream 473 QTextStream t( &outFile ); // use a text stream
468 t.setEncoding( QTextStream::UnicodeUTF8 ); 474 t.setEncoding( QTextStream::UnicodeUTF8 );
469 t <<datastream; 475 t <<datastream;
470 t << "\r\n\r\n"; 476 t << "\r\n\r\n";
471 outFile.close(); 477 outFile.close();
472 478
473 } else { 479 } else {
474 qDebug("Error open temp file "); 480 qDebug("Error open temp file ");
475 return false; 481 return false;
476 } 482 }
477 return true; 483 return true;
478 484
479} 485}
480int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) 486int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld )
481{ 487{
482 488
483 if ( removeOld ) 489 if ( removeOld )
484 setUntagged( true ); 490 setUntagged( true );
485 KABC::Addressee::List list; 491 KABC::Addressee::List list;
486 QFile file( fileName ); 492 QFile file( fileName );
487 file.open( IO_ReadOnly ); 493 file.open( IO_ReadOnly );
488 QByteArray rawData = file.readAll(); 494 QByteArray rawData = file.readAll();
489 file.close(); 495 file.close();
490 QString data; 496 QString data;
491 if ( replaceLabel ) { 497 if ( replaceLabel ) {
492 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); 498 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 );
493 data.replace ( QRegExp("LABEL") , "ADR" ); 499 data.replace ( QRegExp("LABEL") , "ADR" );
494 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); 500 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" );
495 } else 501 } else
496 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 502 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
497 KABC::VCardTool tool; 503 KABC::VCardTool tool;
498 list = tool.parseVCards( data ); 504 list = tool.parseVCards( data );
499 KABC::Addressee::List::Iterator it; 505 KABC::Addressee::List::Iterator it;
500 for ( it = list.begin(); it != list.end(); ++it ) { 506 for ( it = list.begin(); it != list.end(); ++it ) {
501 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); 507 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
502 if ( !id.isEmpty() ) 508 if ( !id.isEmpty() )
503 (*it).setIDStr(id ); 509 (*it).setIDStr(id );
504 (*it).setResource( 0 ); 510 (*it).setResource( 0 );
505 if ( replaceLabel ) 511 if ( replaceLabel )
506 (*it).removeVoice(); 512 (*it).removeVoice();
507 if ( removeOld ) 513 if ( removeOld )
508 (*it).setTagged( true ); 514 (*it).setTagged( true );
509 insertAddressee( (*it), false, true ); 515 insertAddressee( (*it), false, true );
510 } 516 }
511 if ( removeOld ) 517 if ( removeOld )
512 removeUntagged(); 518 removeUntagged();
513 return list.count(); 519 return list.count();
514} 520}
515void AddressBook::setUntagged(bool setNonSyncTagged) // = false) 521void AddressBook::setUntagged(bool setNonSyncTagged) // = false)
516{ 522{
517 Iterator ait; 523 Iterator ait;
518 for ( ait = begin(); ait != end(); ++ait ) { 524 for ( ait = begin(); ait != end(); ++ait ) {
519 if ( setNonSyncTagged ) { 525 if ( setNonSyncTagged ) {
520 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { 526 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) {
521 (*ait).setTagged( true ); 527 (*ait).setTagged( true );
522 } else 528 } else
523 (*ait).setTagged( false ); 529 (*ait).setTagged( false );
524 } else 530 } else
525 (*ait).setTagged( false ); 531 (*ait).setTagged( false );
526 } 532 }
527} 533}
528void AddressBook::removeUntagged() 534void AddressBook::removeUntagged()
529{ 535{
530 Iterator ait; 536 Iterator ait;
531 bool todelete = false; 537 bool todelete = false;
532 Iterator todel; 538 Iterator todel;
533 for ( ait = begin(); ait != end(); ++ait ) { 539 for ( ait = begin(); ait != end(); ++ait ) {
534 if ( todelete ) 540 if ( todelete )
535 removeAddressee( todel ); 541 removeAddressee( todel );
536 if (!(*ait).tagged()) { 542 if (!(*ait).tagged()) {
537 todelete = true; 543 todelete = true;
538 todel = ait; 544 todel = ait;
539 } else 545 } else
540 todelete = false; 546 todelete = false;
541 } 547 }
542 if ( todelete ) 548 if ( todelete )
543 removeAddressee( todel ); 549 removeAddressee( todel );
544 deleteRemovedAddressees(); 550 deleteRemovedAddressees();
545} 551}
546void AddressBook::smplifyAddressees() 552void AddressBook::smplifyAddressees()
547{ 553{
548 Iterator ait; 554 Iterator ait;
549 for ( ait = begin(); ait != end(); ++ait ) { 555 for ( ait = begin(); ait != end(); ++ait ) {
550 (*ait).simplifyEmails(); 556 (*ait).simplifyEmails();
551 (*ait).simplifyPhoneNumbers(); 557 (*ait).simplifyPhoneNumbers();
552 (*ait).simplifyPhoneNumberTypes(); 558 (*ait).simplifyPhoneNumberTypes();
553 (*ait).simplifyAddresses(); 559 (*ait).simplifyAddresses();
554 } 560 }
555} 561}
556void AddressBook::removeSyncInfo( QString syncProfile) 562void AddressBook::removeSyncInfo( QString syncProfile)
557{ 563{
558 Iterator ait; 564 Iterator ait;
559 for ( ait = begin(); ait != end(); ++ait ) { 565 for ( ait = begin(); ait != end(); ++ait ) {
560 (*ait).removeID( syncProfile ); 566 (*ait).removeID( syncProfile );
561 } 567 }
562 if ( syncProfile.isEmpty() ) { 568 if ( syncProfile.isEmpty() ) {
563 Iterator it = begin(); 569 Iterator it = begin();
564 Iterator it2 ; 570 Iterator it2 ;
565 while ( it != end() ) { 571 while ( it != end() ) {
566 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 572 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
567 it2 = it; 573 it2 = it;
568 //qDebug("removing %s ",(*it).uid().latin1() ); 574 //qDebug("removing %s ",(*it).uid().latin1() );
569 ++it; 575 ++it;
570 removeAddressee( it2 ); 576 removeAddressee( it2 );
571 } else { 577 } else {
572 //qDebug("skipping %s ",(*it).uid().latin1() ); 578 //qDebug("skipping %s ",(*it).uid().latin1() );
573 ++it; 579 ++it;
574 } 580 }
575 } 581 }
576 } else { 582 } else {
577 Addressee lse; 583 Addressee lse;
578 lse = findByUid( "last-syncAddressee-"+ syncProfile ); 584 lse = findByUid( "last-syncAddressee-"+ syncProfile );
579 if ( ! lse.isEmpty() ) 585 if ( ! lse.isEmpty() )
580 removeAddressee( lse ); 586 removeAddressee( lse );
581 } 587 }
582 588
583} 589}
584void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) 590void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync )
585{ 591{
586 Iterator ait; 592 Iterator ait;
587 for ( ait = begin(); ait != end(); ++ait ) { 593 for ( ait = begin(); ait != end(); ++ait ) {
588 QString id = (*ait).IDStr(); 594 QString id = (*ait).IDStr();
589 (*ait).setIDStr( ":"); 595 (*ait).setIDStr( ":");
590 (*ait).setExternalUID( id ); 596 (*ait).setExternalUID( id );
591 (*ait).setOriginalExternalUID( id ); 597 (*ait).setOriginalExternalUID( id );
592 if ( isPreSync ) 598 if ( isPreSync )
593 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 599 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
594 else { 600 else {
595 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 601 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
596 (*ait).setID( currentSyncDevice,id ); 602 (*ait).setID( currentSyncDevice,id );
597 603
598 } 604 }
599 } 605 }
600} 606}
601void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) 607void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice )
602{ 608{
603 609
604 setUntagged(); 610 setUntagged();
605 KABC::Addressee::List list; 611 KABC::Addressee::List list;
606 QFile file( fileName ); 612 QFile file( fileName );
607 file.open( IO_ReadOnly ); 613 file.open( IO_ReadOnly );
608 QByteArray rawData = file.readAll(); 614 QByteArray rawData = file.readAll();
609 file.close(); 615 file.close();
610 QString data; 616 QString data;
611 617
612 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 618 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
613 KABC::VCardTool tool; 619 KABC::VCardTool tool;
614 list = tool.parseVCards( data ); 620 list = tool.parseVCards( data );
615 KABC::Addressee::List::Iterator it; 621 KABC::Addressee::List::Iterator it;
616 for ( it = list.begin(); it != list.end(); ++it ) { 622 for ( it = list.begin(); it != list.end(); ++it ) {
617 Iterator ait; 623 Iterator ait;
618 for ( ait = begin(); ait != end(); ++ait ) { 624 for ( ait = begin(); ait != end(); ++ait ) {
619 if ( !(*ait).tagged() ) { 625 if ( !(*ait).tagged() ) {
620 if ( (*ait).containsAdr(*it)) { 626 if ( (*ait).containsAdr(*it)) {
621 (*ait).setTagged(true); 627 (*ait).setTagged(true);
622 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); 628 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
623 (*it).setIDStr( ":"); 629 (*it).setIDStr( ":");
624 (*it).setID( currentSyncDevice,id ); 630 (*it).setID( currentSyncDevice,id );
625 (*it).setExternalUID( id ); 631 (*it).setExternalUID( id );
626 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 632 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
627 (*it).setUid( ( (*ait).uid() )); 633 (*it).setUid( ( (*ait).uid() ));
628 break; 634 break;
629 } 635 }
630 } 636 }
631 637
632 } 638 }
633 if ( ait == end() ) 639 if ( ait == end() )
634 qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); 640 qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1());
635 } 641 }
636 clear(); 642 clear();
637 for ( it = list.begin(); it != list.end(); ++it ) { 643 for ( it = list.begin(); it != list.end(); ++it ) {
638 insertAddressee( (*it) ); 644 insertAddressee( (*it) );
639 } 645 }
640} 646}
641 647
642bool AddressBook::saveABphone( QString fileName ) 648bool AddressBook::saveABphone( QString fileName )
643{ 649{
644 //smplifyAddressees(); 650 //smplifyAddressees();
645 qDebug("saveABphone:: saving AB... "); 651 qDebug("saveABphone:: saving AB... ");
646 if ( ! export2PhoneFormat( QStringList() ,fileName ) ) 652 if ( ! export2PhoneFormat( QStringList() ,fileName ) )
647 return false; 653 return false;
648 qDebug("saveABphone:: writing to phone... "); 654 qDebug("saveABphone:: writing to phone... ");
649 if ( !PhoneAccess::writeToPhone( fileName) ) { 655 if ( !PhoneAccess::writeToPhone( fileName) ) {
650 return false; 656 return false;
651 } 657 }
652 qDebug("saveABphone:: re-reading from phone... "); 658 qDebug("saveABphone:: re-reading from phone... ");
653 if ( !PhoneAccess::readFromPhone( fileName) ) { 659 if ( !PhoneAccess::readFromPhone( fileName) ) {
654 return false; 660 return false;
655 } 661 }
656 return true; 662 return true;
657} 663}
658bool AddressBook::saveAB() 664bool AddressBook::saveAB()
659{ 665{
660 bool ok = true; 666 bool ok = true;
661 667
662 deleteRemovedAddressees(); 668 deleteRemovedAddressees();
663 Iterator ait; 669 Iterator ait;
664 for ( ait = begin(); ait != end(); ++ait ) { 670 for ( ait = begin(); ait != end(); ++ait ) {
665 if ( !(*ait).IDStr().isEmpty() ) { 671 if ( !(*ait).IDStr().isEmpty() ) {
666 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); 672 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
667 } 673 }
668 } 674 }
669 KRES::Manager<Resource>::ActiveIterator it; 675 KRES::Manager<Resource>::ActiveIterator it;
670 KRES::Manager<Resource> *manager = d->mManager; 676 KRES::Manager<Resource> *manager = d->mManager;
671 qDebug("SaveAB::saving..." ); 677 qDebug("SaveAB::saving..." );
672 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 678 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
673 qDebug("SaveAB::checking resource..." ); 679 qDebug("SaveAB::checking resource..." );
674 if ( (*it)->readOnly() ) 680 if ( (*it)->readOnly() )
675 qDebug("SaveAB::resource is readonly." ); 681 qDebug("SaveAB::resource is readonly." );
676 if ( (*it)->isOpen() ) 682 if ( (*it)->isOpen() )
677 qDebug("SaveAB::resource is open" ); 683 qDebug("SaveAB::resource is open" );
678 684
679 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 685 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
680 Ticket *ticket = requestSaveTicket( *it ); 686 Ticket *ticket = requestSaveTicket( *it );
681 qDebug("SaveAB::StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 687 qDebug("SaveAB::StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
682 if ( !ticket ) { 688 if ( !ticket ) {
683 qDebug( i18n( "SaveAB::Unable to save to resource '%1'. It is locked." ) 689 qDebug( i18n( "SaveAB::Unable to save to resource '%1'. It is locked." )
684 .arg( (*it)->resourceName() ) ); 690 .arg( (*it)->resourceName() ) );
685 return false; 691 return false;
686 } 692 }
687 693
688 //if ( !save( ticket ) ) 694 //if ( !save( ticket ) )
689 if ( ticket->resource() ) { 695 if ( ticket->resource() ) {
690 QString name = ticket->resource()->resourceName(); 696 QString name = ticket->resource()->resourceName();
691 if ( ! ticket->resource()->save( ticket ) ) 697 if ( ! ticket->resource()->save( ticket ) )
692 ok = false; 698 ok = false;
693 else 699 else
694 qDebug("SaveAB::resource saved '%s'", name.latin1() ); 700 qDebug("SaveAB::resource saved '%s'", name.latin1() );
695 701
696 } else 702 } else
697 ok = false; 703 ok = false;
698 704
699 } 705 }
700 } 706 }
701 return ok; 707 return ok;
702} 708}
703 709
704AddressBook::Iterator AddressBook::begin() 710AddressBook::Iterator AddressBook::begin()
705{ 711{
706 Iterator it = Iterator(); 712 Iterator it = Iterator();
707 it.d->mIt = d->mAddressees.begin(); 713 it.d->mIt = d->mAddressees.begin();
708 return it; 714 return it;
709} 715}
710 716
711AddressBook::ConstIterator AddressBook::begin() const 717AddressBook::ConstIterator AddressBook::begin() const
712{ 718{
713 ConstIterator it = ConstIterator(); 719 ConstIterator it = ConstIterator();
714 it.d->mIt = d->mAddressees.begin(); 720 it.d->mIt = d->mAddressees.begin();
715 return it; 721 return it;
716} 722}
717 723
718AddressBook::Iterator AddressBook::end() 724AddressBook::Iterator AddressBook::end()
719{ 725{
720 Iterator it = Iterator(); 726 Iterator it = Iterator();
721 it.d->mIt = d->mAddressees.end(); 727 it.d->mIt = d->mAddressees.end();
722 return it; 728 return it;
723} 729}
724 730
725AddressBook::ConstIterator AddressBook::end() const 731AddressBook::ConstIterator AddressBook::end() const
726{ 732{
727 ConstIterator it = ConstIterator(); 733 ConstIterator it = ConstIterator();
728 it.d->mIt = d->mAddressees.end(); 734 it.d->mIt = d->mAddressees.end();
729 return it; 735 return it;
730} 736}
731 737
732void AddressBook::clear() 738void AddressBook::clear()
733{ 739{
734 d->mAddressees.clear(); 740 d->mAddressees.clear();
735} 741}
736 742
737Ticket *AddressBook::requestSaveTicket( Resource *resource ) 743Ticket *AddressBook::requestSaveTicket( Resource *resource )
738{ 744{
739 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 745 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
740 746
741 if ( !resource ) 747 if ( !resource )
742 { 748 {
743 qDebug("AddressBook::requestSaveTicket no resource" ); 749 qDebug("AddressBook::requestSaveTicket no resource" );
744 resource = standardResource(); 750 resource = standardResource();
745 } 751 }
746 752
747 KRES::Manager<Resource>::ActiveIterator it; 753 KRES::Manager<Resource>::ActiveIterator it;
748 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 754 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
749 if ( (*it) == resource ) { 755 if ( (*it) == resource ) {
750 if ( (*it)->readOnly() || !(*it)->isOpen() ) 756 if ( (*it)->readOnly() || !(*it)->isOpen() )
751 return 0; 757 return 0;
752 else 758 else
753 return (*it)->requestSaveTicket(); 759 return (*it)->requestSaveTicket();
754 } 760 }
755 } 761 }
756 762
757 return 0; 763 return 0;
758} 764}
759//void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); 765//void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
760void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) 766void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource )
761{ 767{
762 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { 768 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
763 //qDebug("block insert "); 769 //qDebug("block insert ");
764 return; 770 return;
765 } 771 }
766 //qDebug("inserting.... %s ",a.uid().latin1() ); 772 //qDebug("inserting.... %s ",a.uid().latin1() );
767 bool found = false; 773 bool found = false;
768 Addressee::List::Iterator it; 774 Addressee::List::Iterator it;
769 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 775 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
770 if ( a.uid() == (*it).uid() ) { 776 if ( a.uid() == (*it).uid() ) {
771 777
772 bool changed = false; 778 bool changed = false;
773 Addressee addr = a; 779 Addressee addr = a;
774 if ( addr != (*it) ) 780 if ( addr != (*it) )
775 changed = true; 781 changed = true;
776 782
777 if ( takeResource ) { 783 if ( takeResource ) {
778 Resource * res = (*it).resource(); 784 Resource * res = (*it).resource();
779 (*it) = a; 785 (*it) = a;
780 (*it).setResource( res ); 786 (*it).setResource( res );
781 } else { 787 } else {
782 (*it) = a; 788 (*it) = a;
783 if ( (*it).resource() == 0 ) 789 if ( (*it).resource() == 0 )
784 (*it).setResource( standardResource() ); 790 (*it).setResource( standardResource() );
785 } 791 }
786 if ( changed ) { 792 if ( changed ) {
787 if ( setRev ) { 793 if ( setRev ) {
788 (*it).setRevision( QDateTime::currentDateTime() ); 794 (*it).setRevision( QDateTime::currentDateTime() );
789 } 795 }
790 (*it).setChanged( true ); 796 (*it).setChanged( true );
791 } 797 }
792 798
793 found = true; 799 found = true;
794 } else { 800 } else {
795 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 801 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
796 QString name = (*it).uid().mid( 19 ); 802 QString name = (*it).uid().mid( 19 );
797 Addressee b = a; 803 Addressee b = a;
798 QString id = b.getID( name ); 804 QString id = b.getID( name );
799 if ( ! id.isEmpty() ) { 805 if ( ! id.isEmpty() ) {
800 QString des = (*it).note(); 806 QString des = (*it).note();
801 int startN; 807 int startN;
802 if( (startN = des.find( id ) ) >= 0 ) { 808 if( (startN = des.find( id ) ) >= 0 ) {
803 int endN = des.find( ",", startN+1 ); 809 int endN = des.find( ",", startN+1 );
804 des = des.left( startN ) + des.mid( endN+1 ); 810 des = des.left( startN ) + des.mid( endN+1 );
805 (*it).setNote( des ); 811 (*it).setNote( des );
806 } 812 }
807 } 813 }
808 } 814 }
809 } 815 }
810 } 816 }
811 if ( found ) 817 if ( found )
812 return; 818 return;
813 819
814 d->mAddressees.append( a ); 820 d->mAddressees.append( a );
815 Addressee& addr = d->mAddressees.last(); 821 Addressee& addr = d->mAddressees.last();
816 if ( addr.resource() == 0 ) 822 if ( addr.resource() == 0 )
817 addr.setResource( standardResource() ); 823 addr.setResource( standardResource() );
818 addr.setChanged( true ); 824 addr.setChanged( true );
819} 825}
820 826
821void AddressBook::removeAddressee( const Addressee &a ) 827void AddressBook::removeAddressee( const Addressee &a )
822{ 828{
823 Iterator it; 829 Iterator it;
824 Iterator it2; 830 Iterator it2;
825 bool found = false; 831 bool found = false;
826 for ( it = begin(); it != end(); ++it ) { 832 for ( it = begin(); it != end(); ++it ) {
827 if ( a.uid() == (*it).uid() ) { 833 if ( a.uid() == (*it).uid() ) {
828 found = true; 834 found = true;
829 it2 = it; 835 it2 = it;
830 } else { 836 } else {
831 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 837 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
832 QString name = (*it).uid().mid( 19 ); 838 QString name = (*it).uid().mid( 19 );
833 Addressee b = a; 839 Addressee b = a;
834 QString id = b.getID( name ); 840 QString id = b.getID( name );
835 if ( ! id.isEmpty() ) { 841 if ( ! id.isEmpty() ) {
836 QString des = (*it).note(); 842 QString des = (*it).note();
837 if( des.find( id ) < 0 ) { 843 if( des.find( id ) < 0 ) {
838 des += id + ","; 844 des += id + ",";
839 (*it).setNote( des ); 845 (*it).setNote( des );
840 } 846 }
841 } 847 }
842 } 848 }
843 849
844 } 850 }
845 } 851 }
846 852
847 if ( found ) 853 if ( found )
848 removeAddressee( it2 ); 854 removeAddressee( it2 );
849 855
850} 856}
851 857
852void AddressBook::removeSyncAddressees( bool removeDeleted ) 858void AddressBook::removeSyncAddressees( bool removeDeleted )
853{ 859{
854 Iterator it = begin(); 860 Iterator it = begin();
855 Iterator it2 ; 861 Iterator it2 ;
856 QDateTime dt ( QDate( 2003,1,1) ); 862 QDateTime dt ( QDate( 2003,1,1) );
857 while ( it != end() ) { 863 while ( it != end() ) {
858 (*it).setRevision( dt ); 864 (*it).setRevision( dt );
859 if (( *it).IDStr() != "changed" ) { 865 if (( *it).IDStr() != "changed" ) {
860 // "changed" is used for tagging changed addressees when syncing with KDE or OL 866 // "changed" is used for tagging changed addressees when syncing with KDE or OL
861 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); 867 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" );
862 (*it).setIDStr(":"); 868 (*it).setIDStr(":");
863 } 869 }
864 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { 870 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) {
865 it2 = it; 871 it2 = it;
866 //qDebug("removing %s ",(*it).uid().latin1() ); 872 //qDebug("removing %s ",(*it).uid().latin1() );
867 ++it; 873 ++it;
868 removeAddressee( it2 ); 874 removeAddressee( it2 );
869 } else { 875 } else {
870 //qDebug("skipping %s ",(*it).uid().latin1() ); 876 //qDebug("skipping %s ",(*it).uid().latin1() );
871 if ( removeDeleted ) { 877 if ( removeDeleted ) {
872 // we have no postprocessing in the resource, we have to do it here 878 // we have no postprocessing in the resource, we have to do it here
873 // we have to compute csum for all, because it could be the first sync 879 // we have to compute csum for all, because it could be the first sync
874 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 880 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
875 } 881 }
876 ++it; 882 ++it;
877 } 883 }
878 } 884 }
879 deleteRemovedAddressees(); 885 deleteRemovedAddressees();
880} 886}
881 887
882void AddressBook::removeAddressee( const Iterator &it ) 888void AddressBook::removeAddressee( const Iterator &it )
883{ 889{
884 d->mRemovedAddressees.append( (*it) ); 890 d->mRemovedAddressees.append( (*it) );
885 d->mAddressees.remove( it.d->mIt ); 891 d->mAddressees.remove( it.d->mIt );
886} 892}
887 893
888AddressBook::Iterator AddressBook::find( const Addressee &a ) 894AddressBook::Iterator AddressBook::find( const Addressee &a )
889{ 895{
890 Iterator it; 896 Iterator it;
891 for ( it = begin(); it != end(); ++it ) { 897 for ( it = begin(); it != end(); ++it ) {
892 if ( a.uid() == (*it).uid() ) { 898 if ( a.uid() == (*it).uid() ) {
893 return it; 899 return it;
894 } 900 }
895 } 901 }
896 return end(); 902 return end();
897} 903}
898 904
899Addressee AddressBook::findByUid( const QString &uid ) 905Addressee AddressBook::findByUid( const QString &uid )
900{ 906{
901 Iterator it; 907 Iterator it;
902 for ( it = begin(); it != end(); ++it ) { 908 for ( it = begin(); it != end(); ++it ) {
903 if ( uid == (*it).uid() ) { 909 if ( uid == (*it).uid() ) {
904 return *it; 910 return *it;
905 } 911 }
906 } 912 }
907 return Addressee(); 913 return Addressee();
908} 914}
909void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) 915void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset )
910{ 916{
911 //qDebug("AddressBook::preExternSync "); 917 //qDebug("AddressBook::preExternSync ");
912 AddressBook::Iterator it; 918 AddressBook::Iterator it;
913 for ( it = begin(); it != end(); ++it ) { 919 for ( it = begin(); it != end(); ++it ) {
914 (*it).setID( csd, (*it).externalUID() ); 920 (*it).setID( csd, (*it).externalUID() );
915 (*it).computeCsum( csd ); 921 (*it).computeCsum( csd );
916 } 922 }
917 mergeAB( aBook ,csd, isSubset ); 923 mergeAB( aBook ,csd, isSubset );
918} 924}
919void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool setID) 925void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool setID)
920{ 926{
921 //qDebug("AddressBook::postExternSync "); 927 //qDebug("AddressBook::postExternSync ");
922 AddressBook::Iterator it; 928 AddressBook::Iterator it;
923 int foundEmpty = 0; 929 int foundEmpty = 0;
924 for ( it = begin(); it != end(); ++it ) { 930 for ( it = begin(); it != end(); ++it ) {
925 //qDebug("check uid %s ", (*it).uid().latin1() ); 931 //qDebug("check uid %s ", (*it).uid().latin1() );
926 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || 932 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ||
927 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM || 933 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ||
928 (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL) { 934 (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL) {
929 Addressee ad = aBook->findByUid( ( (*it).uid() )); 935 Addressee ad = aBook->findByUid( ( (*it).uid() ));
930 if ( ad.isEmpty() ) { 936 if ( ad.isEmpty() ) {
931 ++foundEmpty; 937 ++foundEmpty;
932 //qDebug("postExternSync:addressee is empty: %s ", (*it).uid().latin1()); 938 //qDebug("postExternSync:addressee is empty: %s ", (*it).uid().latin1());
933 //qDebug("-- formatted name %s ",(*it).formattedName().latin1() ); 939 //qDebug("-- formatted name %s ",(*it).formattedName().latin1() );
934 } else { 940 } else {
935 (*it).setIDStr(":"); 941 (*it).setIDStr(":");
936 if ( setID ) { 942 if ( setID ) {
937 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) 943 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID )
938 ad.setID( csd, (*it).externalUID() ); 944 ad.setID( csd, (*it).externalUID() );
939 } else 945 } else
940 ad.setID( csd, (*it).uid() ); 946 ad.setID( csd, (*it).uid() );
941 (*it).computeCsum( csd ); 947 (*it).computeCsum( csd );
942 ad.setCsum( csd, (*it).getCsum( csd ) ); 948 ad.setCsum( csd, (*it).getCsum( csd ) );
943 //qDebug("CSUM %s ",(*it).getCsum( csd ).latin1() ); 949 //qDebug("CSUM %s ",(*it).getCsum( csd ).latin1() );
944 aBook->insertAddressee( ad , false); 950 aBook->insertAddressee( ad , false);
945 } 951 }
946 } 952 }
947 } 953 }
948 if ( foundEmpty ) { 954 if ( foundEmpty ) {
949 qDebug("postExternSync:%d empty addressees found:\n probably filtered out by incoming sync filter.",foundEmpty ); 955 qDebug("postExternSync:%d empty addressees found:\n probably filtered out by incoming sync filter.",foundEmpty );
950 } 956 }
951 957
952} 958}
953 959
954bool AddressBook::containsExternalUid( const QString& uid ) 960bool AddressBook::containsExternalUid( const QString& uid )
955{ 961{
956 Iterator it; 962 Iterator it;
957 for ( it = begin(); it != end(); ++it ) { 963 for ( it = begin(); it != end(); ++it ) {
958 if ( uid == (*it).externalUID( ) ) 964 if ( uid == (*it).externalUID( ) )
959 return true; 965 return true;
960 } 966 }
961 return false; 967 return false;
962} 968}
963const Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) const 969const Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) const
964{ 970{
965 ConstIterator it; 971 ConstIterator it;
966 for ( it = begin(); it != end(); ++it ) { 972 for ( it = begin(); it != end(); ++it ) {
967 if ( uid == (*it).getID( profile ) ) 973 if ( uid == (*it).getID( profile ) )
968 return (*it); 974 return (*it);
969 } 975 }
970 return Addressee(); 976 return Addressee();
971} 977}
972void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) 978void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset )
973{ 979{
974 Iterator it; 980 Iterator it;
975 Addressee ad; 981 Addressee ad;
976 for ( it = begin(); it != end(); ++it ) { 982 for ( it = begin(); it != end(); ++it ) {
977 ad = aBook->findByExternUid( (*it).externalUID(), profile ); 983 ad = aBook->findByExternUid( (*it).externalUID(), profile );
978 if ( !ad.isEmpty() ) { 984 if ( !ad.isEmpty() ) {
979 (*it).mergeContact( ad ,isSubset); 985 (*it).mergeContact( ad ,isSubset);
980 } 986 }
981 } 987 }
982#if 0 988#if 0
983 // test only 989 // test only
984 for ( it = begin(); it != end(); ++it ) { 990 for ( it = begin(); it != end(); ++it ) {
985 991
986 qDebug("uid %s ", (*it).uid().latin1()); 992 qDebug("uid %s ", (*it).uid().latin1());
987 } 993 }
988#endif 994#endif
989} 995}
990 996
991#if 0 997#if 0
992Addressee::List AddressBook::getExternLastSyncAddressees() 998Addressee::List AddressBook::getExternLastSyncAddressees()
993{ 999{
994 Addressee::List results; 1000 Addressee::List results;
995 1001
996 Iterator it; 1002 Iterator it;
997 for ( it = begin(); it != end(); ++it ) { 1003 for ( it = begin(); it != end(); ++it ) {
998 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { 1004 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
999 if ( (*it).familyName().left(4) == "!E: " ) 1005 if ( (*it).familyName().left(4) == "!E: " )
1000 results.append( *it ); 1006 results.append( *it );
1001 } 1007 }
1002 } 1008 }
1003 1009
1004 return results; 1010 return results;
1005} 1011}
1006#endif 1012#endif
1007void AddressBook::resetTempSyncStat() 1013void AddressBook::resetTempSyncStat()
1008{ 1014{
1009 Iterator it; 1015 Iterator it;
1010 for ( it = begin(); it != end(); ++it ) { 1016 for ( it = begin(); it != end(); ++it ) {
1011 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); 1017 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
1012 } 1018 }
1013 1019
1014} 1020}
1015 1021
1016QStringList AddressBook:: uidList() 1022QStringList AddressBook:: uidList()
1017{ 1023{
1018 QStringList results; 1024 QStringList results;
1019 Iterator it; 1025 Iterator it;
1020 for ( it = begin(); it != end(); ++it ) { 1026 for ( it = begin(); it != end(); ++it ) {
1021 results.append( (*it).uid() ); 1027 results.append( (*it).uid() );
1022 } 1028 }
1023 return results; 1029 return results;
1024} 1030}
1025 1031
1026 1032
1027Addressee::List AddressBook::allAddressees() 1033Addressee::List AddressBook::allAddressees()
1028{ 1034{
1029 return d->mAddressees; 1035 return d->mAddressees;
1030 1036
1031} 1037}
1032 1038
1033Addressee::List AddressBook::findByName( const QString &name ) 1039Addressee::List AddressBook::findByName( const QString &name )
1034{ 1040{
1035 Addressee::List results; 1041 Addressee::List results;
1036 1042
1037 Iterator it; 1043 Iterator it;
1038 for ( it = begin(); it != end(); ++it ) { 1044 for ( it = begin(); it != end(); ++it ) {
1039 if ( name == (*it).realName() ) { 1045 if ( name == (*it).realName() ) {
1040 results.append( *it ); 1046 results.append( *it );
1041 } 1047 }
1042 } 1048 }
1043 1049
1044 return results; 1050 return results;
1045} 1051}
1046 1052
1047Addressee::List AddressBook::findByEmail( const QString &email ) 1053Addressee::List AddressBook::findByEmail( const QString &email )
1048{ 1054{
1049 Addressee::List results; 1055 Addressee::List results;
1050 QStringList mailList; 1056 QStringList mailList;
1051 1057
1052 Iterator it; 1058 Iterator it;
1053 for ( it = begin(); it != end(); ++it ) { 1059 for ( it = begin(); it != end(); ++it ) {
1054 mailList = (*it).emails(); 1060 mailList = (*it).emails();
1055 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 1061 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
1056 if ( email == (*ite) ) { 1062 if ( email == (*ite) ) {
1057 results.append( *it ); 1063 results.append( *it );
1058 } 1064 }
1059 } 1065 }
1060 } 1066 }
1061 1067
1062 return results; 1068 return results;
1063} 1069}
1064 1070
1065Addressee::List AddressBook::findByCategory( const QString &category ) 1071Addressee::List AddressBook::findByCategory( const QString &category )
1066{ 1072{
1067 Addressee::List results; 1073 Addressee::List results;
1068 1074
1069 Iterator it; 1075 Iterator it;
1070 for ( it = begin(); it != end(); ++it ) { 1076 for ( it = begin(); it != end(); ++it ) {
1071 if ( (*it).hasCategory( category) ) { 1077 if ( (*it).hasCategory( category) ) {
1072 results.append( *it ); 1078 results.append( *it );
1073 } 1079 }
1074 } 1080 }
1075 1081
1076 return results; 1082 return results;
1077} 1083}
1078 1084
1079void AddressBook::dump() const 1085void AddressBook::dump() const
1080{ 1086{
1081 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; 1087 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
1082 1088
1083 ConstIterator it; 1089 ConstIterator it;
1084 for( it = begin(); it != end(); ++it ) { 1090 for( it = begin(); it != end(); ++it ) {
1085 (*it).dump(); 1091 (*it).dump();
1086 } 1092 }
1087 1093
1088 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; 1094 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
1089} 1095}
1090 1096
1091QString AddressBook::identifier() 1097QString AddressBook::identifier()
1092{ 1098{
1093 QStringList identifier; 1099 QStringList identifier;
1094 1100
1095 1101
1096 KRES::Manager<Resource>::ActiveIterator it; 1102 KRES::Manager<Resource>::ActiveIterator it;
1097 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 1103 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
1098 if ( !(*it)->identifier().isEmpty() ) 1104 if ( !(*it)->identifier().isEmpty() )
1099 identifier.append( (*it)->identifier() ); 1105 identifier.append( (*it)->identifier() );
1100 } 1106 }
1101 1107
1102 return identifier.join( ":" ); 1108 return identifier.join( ":" );
1103} 1109}
1104 1110
1105Field::List AddressBook::fields( int category ) 1111Field::List AddressBook::fields( int category )
1106{ 1112{
1107 if ( d->mAllFields.isEmpty() ) { 1113 if ( d->mAllFields.isEmpty() ) {
1108 d->mAllFields = Field::allFields(); 1114 d->mAllFields = Field::allFields();
1109 } 1115 }
1110 1116
1111 if ( category == Field::All ) return d->mAllFields; 1117 if ( category == Field::All ) return d->mAllFields;
1112 1118
1113 Field::List result; 1119 Field::List result;
1114 Field::List::ConstIterator it; 1120 Field::List::ConstIterator it;
1115 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { 1121 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
1116 if ( (*it)->category() & category ) result.append( *it ); 1122 if ( (*it)->category() & category ) result.append( *it );
1117 } 1123 }
1118 1124
1119 return result; 1125 return result;
1120} 1126}
1121 1127
1122bool AddressBook::addCustomField( const QString &label, int category, 1128bool AddressBook::addCustomField( const QString &label, int category,
1123 const QString &key, const QString &app ) 1129 const QString &key, const QString &app )
1124{ 1130{
1125 if ( d->mAllFields.isEmpty() ) { 1131 if ( d->mAllFields.isEmpty() ) {
1126 d->mAllFields = Field::allFields(); 1132 d->mAllFields = Field::allFields();
1127 } 1133 }
1128//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; 1134//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app;
1129 QString a = app.isNull() ? KGlobal::getAppName() : app; 1135 QString a = app.isNull() ? KGlobal::getAppName() : app;
1130 1136
1131 QString k = key.isNull() ? label : key; 1137 QString k = key.isNull() ? label : key;
1132 1138
1133 Field *field = Field::createCustomField( label, category, k, a ); 1139 Field *field = Field::createCustomField( label, category, k, a );
1134 1140
1135 if ( !field ) return false; 1141 if ( !field ) return false;
1136 1142
1137 d->mAllFields.append( field ); 1143 d->mAllFields.append( field );
1138 1144
1139 return true; 1145 return true;
1140} 1146}
1141 1147
1142QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) 1148QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab )
1143{ 1149{
1144 if (!ab.d) return s; 1150 if (!ab.d) return s;
1145 1151
1146 return s << ab.d->mAddressees; 1152 return s << ab.d->mAddressees;
1147} 1153}
1148 1154
1149QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) 1155QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
1150{ 1156{
1151 if (!ab.d) return s; 1157 if (!ab.d) return s;
1152 1158
1153 s >> ab.d->mAddressees; 1159 s >> ab.d->mAddressees;
1154 1160
1155 return s; 1161 return s;
1156} 1162}
1157 1163
1158bool AddressBook::addResource( Resource *resource ) 1164bool AddressBook::addResource( Resource *resource )
1159{ 1165{
1160 if ( !resource->open() ) { 1166 if ( !resource->open() ) {
1161 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; 1167 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
1162 return false; 1168 return false;
1163 } 1169 }
1164 1170
1165 resource->setAddressBook( this ); 1171 resource->setAddressBook( this );
1166 1172
1167 d->mManager->add( resource ); 1173 d->mManager->add( resource );
1168 return true; 1174 return true;
1169} 1175}
1170void AddressBook::removeResources() 1176void AddressBook::removeResources()
1171{ 1177{
1172 //remove all possible resources. This should cleanup the configfile. 1178 //remove all possible resources. This should cleanup the configfile.
1173 QPtrList<KABC::Resource> mResources = resources(); 1179 QPtrList<KABC::Resource> mResources = resources();
1174 1180
1175 QPtrListIterator<KABC::Resource> it(mResources); 1181 QPtrListIterator<KABC::Resource> it(mResources);
1176 for ( ; it.current(); ++it ) { 1182 for ( ; it.current(); ++it ) {
1177 KABC::Resource *res = it.current(); 1183 KABC::Resource *res = it.current();
1178 removeResource(res); 1184 removeResource(res);
1179 } 1185 }
1180} 1186}
1181 1187
1182bool AddressBook::removeResource( Resource *resource ) 1188bool AddressBook::removeResource( Resource *resource )
1183{ 1189{
1184 resource->close(); 1190 resource->close();
1185 1191
1186 if ( resource == standardResource() ) 1192 if ( resource == standardResource() )
1187 d->mManager->setStandardResource( 0 ); 1193 d->mManager->setStandardResource( 0 );
1188 1194
1189 resource->setAddressBook( 0 ); 1195 resource->setAddressBook( 0 );
1190 1196
1191 d->mManager->remove( resource ); 1197 d->mManager->remove( resource );
1192 return true; 1198 return true;
1193} 1199}
1194 1200
1195QPtrList<Resource> AddressBook::resources() 1201QPtrList<Resource> AddressBook::resources()
1196{ 1202{
1197 QPtrList<Resource> list; 1203 QPtrList<Resource> list;
1198 1204
1199// qDebug("AddressBook::resources() 1"); 1205// qDebug("AddressBook::resources() 1");
1200 1206
1201 KRES::Manager<Resource>::ActiveIterator it; 1207 KRES::Manager<Resource>::ActiveIterator it;
1202 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 1208 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
1203 list.append( *it ); 1209 list.append( *it );
1204 1210
1205 return list; 1211 return list;
1206} 1212}
1207 1213
1208/*US 1214/*US
1209void AddressBook::setErrorHandler( ErrorHandler *handler ) 1215void AddressBook::setErrorHandler( ErrorHandler *handler )
1210{ 1216{
1211 delete d->mErrorHandler; 1217 delete d->mErrorHandler;
1212 d->mErrorHandler = handler; 1218 d->mErrorHandler = handler;
1213} 1219}
1214*/ 1220*/
1215 1221
1216void AddressBook::error( const QString& msg ) 1222void AddressBook::error( const QString& msg )
1217{ 1223{
1218/*US 1224/*US
1219 if ( !d->mErrorHandler ) // create default error handler 1225 if ( !d->mErrorHandler ) // create default error handler
1220 d->mErrorHandler = new ConsoleErrorHandler; 1226 d->mErrorHandler = new ConsoleErrorHandler;
1221 1227
1222 if ( d->mErrorHandler ) 1228 if ( d->mErrorHandler )
1223 d->mErrorHandler->error( msg ); 1229 d->mErrorHandler->error( msg );
1224 else 1230 else
1225 kdError(5700) << "no error handler defined" << endl; 1231 kdError(5700) << "no error handler defined" << endl;
1226*/ 1232*/
1227 kdDebug(5700) << "msg" << endl; 1233 kdDebug(5700) << "msg" << endl;
1228 qDebug(msg); 1234 qDebug(msg);
1229} 1235}
1230 1236
1231void AddressBook::deleteRemovedAddressees() 1237void AddressBook::deleteRemovedAddressees()
1232{ 1238{
1233 Addressee::List::Iterator it; 1239 Addressee::List::Iterator it;
1234 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { 1240 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) {
1235 Resource *resource = (*it).resource(); 1241 Resource *resource = (*it).resource();
1236 if ( resource && !resource->readOnly() && resource->isOpen() ) 1242 if ( resource && !resource->readOnly() && resource->isOpen() )
1237 resource->removeAddressee( *it ); 1243 resource->removeAddressee( *it );
1238 } 1244 }
1239 1245
1240 d->mRemovedAddressees.clear(); 1246 d->mRemovedAddressees.clear();
1241} 1247}
1242 1248
1243void AddressBook::setStandardResource( Resource *resource ) 1249void AddressBook::setStandardResource( Resource *resource )
1244{ 1250{
1245// qDebug("AddressBook::setStandardResource 1"); 1251// qDebug("AddressBook::setStandardResource 1");
1246 d->mManager->setStandardResource( resource ); 1252 d->mManager->setStandardResource( resource );
1247} 1253}
1248 1254
1249Resource *AddressBook::standardResource() 1255Resource *AddressBook::standardResource()
1250{ 1256{
1251 return d->mManager->standardResource(); 1257 return d->mManager->standardResource();
1252} 1258}
1253 1259
1254KRES::Manager<Resource> *AddressBook::resourceManager() 1260KRES::Manager<Resource> *AddressBook::resourceManager()
1255{ 1261{
1256 return d->mManager; 1262 return d->mManager;
1257} 1263}
1258 1264
1259void AddressBook::cleanUp() 1265void AddressBook::cleanUp()
1260{ 1266{
1261 KRES::Manager<Resource>::ActiveIterator it; 1267 KRES::Manager<Resource>::ActiveIterator it;
1262 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 1268 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
1263 if ( !(*it)->readOnly() && (*it)->isOpen() ) 1269 if ( !(*it)->readOnly() && (*it)->isOpen() )
1264 (*it)->cleanUp(); 1270 (*it)->cleanUp();
1265 } 1271 }
1266} 1272}