summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
Unidiff
Diffstat (limited to 'kabc/addressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 1a06956..1050f55 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -1,1003 +1,1004 @@
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 44
44#include <kglobal.h> 45#include <kglobal.h>
45#include <klocale.h> 46#include <klocale.h>
46#include <kmessagebox.h> 47#include <kmessagebox.h>
47#include <kdebug.h> 48#include <kdebug.h>
48#include <libkcal/syncdefines.h> 49#include <libkcal/syncdefines.h>
49#include "addressbook.h" 50#include "addressbook.h"
50#include "resource.h" 51#include "resource.h"
51#include "vcardconverter.h" 52#include "vcardconverter.h"
52#include "vcardparser/vcardtool.h" 53#include "vcardparser/vcardtool.h"
53 54
54//US #include "addressbook.moc" 55//US #include "addressbook.moc"
55 56
56using namespace KABC; 57using namespace KABC;
57 58
58struct AddressBook::AddressBookData 59struct AddressBook::AddressBookData
59{ 60{
60 Addressee::List mAddressees; 61 Addressee::List mAddressees;
61 Addressee::List mRemovedAddressees; 62 Addressee::List mRemovedAddressees;
62 Field::List mAllFields; 63 Field::List mAllFields;
63 KConfig *mConfig; 64 KConfig *mConfig;
64 KRES::Manager<Resource> *mManager; 65 KRES::Manager<Resource> *mManager;
65//US ErrorHandler *mErrorHandler; 66//US ErrorHandler *mErrorHandler;
66}; 67};
67 68
68struct AddressBook::Iterator::IteratorData 69struct AddressBook::Iterator::IteratorData
69{ 70{
70 Addressee::List::Iterator mIt; 71 Addressee::List::Iterator mIt;
71}; 72};
72 73
73struct AddressBook::ConstIterator::ConstIteratorData 74struct AddressBook::ConstIterator::ConstIteratorData
74{ 75{
75 Addressee::List::ConstIterator mIt; 76 Addressee::List::ConstIterator mIt;
76}; 77};
77 78
78AddressBook::Iterator::Iterator() 79AddressBook::Iterator::Iterator()
79{ 80{
80 d = new IteratorData; 81 d = new IteratorData;
81} 82}
82 83
83AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) 84AddressBook::Iterator::Iterator( const AddressBook::Iterator &i )
84{ 85{
85 d = new IteratorData; 86 d = new IteratorData;
86 d->mIt = i.d->mIt; 87 d->mIt = i.d->mIt;
87} 88}
88 89
89AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) 90AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i )
90{ 91{
91 if( this == &i ) return *this; // guard against self assignment 92 if( this == &i ) return *this; // guard against self assignment
92 delete d; // delete the old data the Iterator was completely constructed before 93 delete d; // delete the old data the Iterator was completely constructed before
93 d = new IteratorData; 94 d = new IteratorData;
94 d->mIt = i.d->mIt; 95 d->mIt = i.d->mIt;
95 return *this; 96 return *this;
96} 97}
97 98
98AddressBook::Iterator::~Iterator() 99AddressBook::Iterator::~Iterator()
99{ 100{
100 delete d; 101 delete d;
101} 102}
102 103
103const Addressee &AddressBook::Iterator::operator*() const 104const Addressee &AddressBook::Iterator::operator*() const
104{ 105{
105 return *(d->mIt); 106 return *(d->mIt);
106} 107}
107 108
108Addressee &AddressBook::Iterator::operator*() 109Addressee &AddressBook::Iterator::operator*()
109{ 110{
110 return *(d->mIt); 111 return *(d->mIt);
111} 112}
112 113
113Addressee *AddressBook::Iterator::operator->() 114Addressee *AddressBook::Iterator::operator->()
114{ 115{
115 return &(*(d->mIt)); 116 return &(*(d->mIt));
116} 117}
117 118
118AddressBook::Iterator &AddressBook::Iterator::operator++() 119AddressBook::Iterator &AddressBook::Iterator::operator++()
119{ 120{
120 (d->mIt)++; 121 (d->mIt)++;
121 return *this; 122 return *this;
122} 123}
123 124
124AddressBook::Iterator &AddressBook::Iterator::operator++(int) 125AddressBook::Iterator &AddressBook::Iterator::operator++(int)
125{ 126{
126 (d->mIt)++; 127 (d->mIt)++;
127 return *this; 128 return *this;
128} 129}
129 130
130AddressBook::Iterator &AddressBook::Iterator::operator--() 131AddressBook::Iterator &AddressBook::Iterator::operator--()
131{ 132{
132 (d->mIt)--; 133 (d->mIt)--;
133 return *this; 134 return *this;
134} 135}
135 136
136AddressBook::Iterator &AddressBook::Iterator::operator--(int) 137AddressBook::Iterator &AddressBook::Iterator::operator--(int)
137{ 138{
138 (d->mIt)--; 139 (d->mIt)--;
139 return *this; 140 return *this;
140} 141}
141 142
142bool AddressBook::Iterator::operator==( const Iterator &it ) 143bool AddressBook::Iterator::operator==( const Iterator &it )
143{ 144{
144 return ( d->mIt == it.d->mIt ); 145 return ( d->mIt == it.d->mIt );
145} 146}
146 147
147bool AddressBook::Iterator::operator!=( const Iterator &it ) 148bool AddressBook::Iterator::operator!=( const Iterator &it )
148{ 149{
149 return ( d->mIt != it.d->mIt ); 150 return ( d->mIt != it.d->mIt );
150} 151}
151 152
152 153
153AddressBook::ConstIterator::ConstIterator() 154AddressBook::ConstIterator::ConstIterator()
154{ 155{
155 d = new ConstIteratorData; 156 d = new ConstIteratorData;
156} 157}
157 158
158AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) 159AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i )
159{ 160{
160 d = new ConstIteratorData; 161 d = new ConstIteratorData;
161 d->mIt = i.d->mIt; 162 d->mIt = i.d->mIt;
162} 163}
163 164
164AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) 165AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i )
165{ 166{
166 if( this == &i ) return *this; // guard for self assignment 167 if( this == &i ) return *this; // guard for self assignment
167 delete d; // delete the old data because the Iterator was really constructed before 168 delete d; // delete the old data because the Iterator was really constructed before
168 d = new ConstIteratorData; 169 d = new ConstIteratorData;
169 d->mIt = i.d->mIt; 170 d->mIt = i.d->mIt;
170 return *this; 171 return *this;
171} 172}
172 173
173AddressBook::ConstIterator::~ConstIterator() 174AddressBook::ConstIterator::~ConstIterator()
174{ 175{
175 delete d; 176 delete d;
176} 177}
177 178
178const Addressee &AddressBook::ConstIterator::operator*() const 179const Addressee &AddressBook::ConstIterator::operator*() const
179{ 180{
180 return *(d->mIt); 181 return *(d->mIt);
181} 182}
182 183
183const Addressee* AddressBook::ConstIterator::operator->() const 184const Addressee* AddressBook::ConstIterator::operator->() const
184{ 185{
185 return &(*(d->mIt)); 186 return &(*(d->mIt));
186} 187}
187 188
188AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() 189AddressBook::ConstIterator &AddressBook::ConstIterator::operator++()
189{ 190{
190 (d->mIt)++; 191 (d->mIt)++;
191 return *this; 192 return *this;
192} 193}
193 194
194AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) 195AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int)
195{ 196{
196 (d->mIt)++; 197 (d->mIt)++;
197 return *this; 198 return *this;
198} 199}
199 200
200AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() 201AddressBook::ConstIterator &AddressBook::ConstIterator::operator--()
201{ 202{
202 (d->mIt)--; 203 (d->mIt)--;
203 return *this; 204 return *this;
204} 205}
205 206
206AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) 207AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int)
207{ 208{
208 (d->mIt)--; 209 (d->mIt)--;
209 return *this; 210 return *this;
210} 211}
211 212
212bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) 213bool AddressBook::ConstIterator::operator==( const ConstIterator &it )
213{ 214{
214 return ( d->mIt == it.d->mIt ); 215 return ( d->mIt == it.d->mIt );
215} 216}
216 217
217bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) 218bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
218{ 219{
219 return ( d->mIt != it.d->mIt ); 220 return ( d->mIt != it.d->mIt );
220} 221}
221 222
222 223
223AddressBook::AddressBook() 224AddressBook::AddressBook()
224{ 225{
225 init(0, "contact"); 226 init(0, "contact");
226} 227}
227 228
228AddressBook::AddressBook( const QString &config ) 229AddressBook::AddressBook( const QString &config )
229{ 230{
230 init(config, "contact"); 231 init(config, "contact");
231} 232}
232 233
233AddressBook::AddressBook( const QString &config, const QString &family ) 234AddressBook::AddressBook( const QString &config, const QString &family )
234{ 235{
235 init(config, family); 236 init(config, family);
236 237
237} 238}
238 239
239// the default family is "contact" 240// the default family is "contact"
240void AddressBook::init(const QString &config, const QString &family ) 241void AddressBook::init(const QString &config, const QString &family )
241{ 242{
242 blockLSEchange = false; 243 blockLSEchange = false;
243 d = new AddressBookData; 244 d = new AddressBookData;
244 QString fami = family; 245 QString fami = family;
245 if (config != 0) { 246 if (config != 0) {
246 if ( family == "syncContact" ) { 247 if ( family == "syncContact" ) {
247 qDebug("creating sync config "); 248 qDebug("creating sync config ");
248 fami = "contact"; 249 fami = "contact";
249 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); 250 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") );
250 con->setGroup( "General" ); 251 con->setGroup( "General" );
251 con->writeEntry( "ResourceKeys", QString("sync") ); 252 con->writeEntry( "ResourceKeys", QString("sync") );
252 con->writeEntry( "Standard", QString("sync") ); 253 con->writeEntry( "Standard", QString("sync") );
253 con->setGroup( "Resource_sync" ); 254 con->setGroup( "Resource_sync" );
254 con->writeEntry( "FileName", config ); 255 con->writeEntry( "FileName", config );
255 con->writeEntry( "FileFormat", QString("vcard") ); 256 con->writeEntry( "FileFormat", QString("vcard") );
256 con->writeEntry( "ResourceIdentifier", QString("sync") ); 257 con->writeEntry( "ResourceIdentifier", QString("sync") );
257 con->writeEntry( "ResourceName", QString("sync_res") ); 258 con->writeEntry( "ResourceName", QString("sync_res") );
258 if ( config.right(4) == ".xml" ) 259 if ( config.right(4) == ".xml" )
259 con->writeEntry( "ResourceType", QString("qtopia") ); 260 con->writeEntry( "ResourceType", QString("qtopia") );
260 else if ( config == "sharp" ) { 261 else if ( config == "sharp" ) {
261 con->writeEntry( "ResourceType", QString("sharp") ); 262 con->writeEntry( "ResourceType", QString("sharp") );
262 } else { 263 } else {
263 con->writeEntry( "ResourceType", QString("file") ); 264 con->writeEntry( "ResourceType", QString("file") );
264 } 265 }
265 //con->sync(); 266 //con->sync();
266 d->mConfig = con; 267 d->mConfig = con;
267 } 268 }
268 else 269 else
269 d->mConfig = new KConfig( locateLocal("config", config) ); 270 d->mConfig = new KConfig( locateLocal("config", config) );
270// qDebug("AddressBook::init 1 config=%s",config.latin1() ); 271// qDebug("AddressBook::init 1 config=%s",config.latin1() );
271 } 272 }
272 else { 273 else {
273 d->mConfig = 0; 274 d->mConfig = 0;
274// qDebug("AddressBook::init 1 config=0"); 275// qDebug("AddressBook::init 1 config=0");
275 } 276 }
276 277
277//US d->mErrorHandler = 0; 278//US d->mErrorHandler = 0;
278 d->mManager = new KRES::Manager<Resource>( fami, false ); 279 d->mManager = new KRES::Manager<Resource>( fami, false );
279 d->mManager->readConfig( d->mConfig ); 280 d->mManager->readConfig( d->mConfig );
280 if ( family == "syncContact" ) { 281 if ( family == "syncContact" ) {
281 KRES::Manager<Resource> *manager = d->mManager; 282 KRES::Manager<Resource> *manager = d->mManager;
282 KRES::Manager<Resource>::ActiveIterator it; 283 KRES::Manager<Resource>::ActiveIterator it;
283 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 284 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
284 (*it)->setAddressBook( this ); 285 (*it)->setAddressBook( this );
285 if ( !(*it)->open() ) 286 if ( !(*it)->open() )
286 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 287 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
287 } 288 }
288 Resource *res = standardResource(); 289 Resource *res = standardResource();
289 if ( !res ) { 290 if ( !res ) {
290 qDebug("ERROR: no standard resource"); 291 qDebug("ERROR: no standard resource");
291 res = manager->createResource( "file" ); 292 res = manager->createResource( "file" );
292 if ( res ) 293 if ( res )
293 { 294 {
294 addResource( res ); 295 addResource( res );
295 } 296 }
296 else 297 else
297 qDebug(" No resource available!!!"); 298 qDebug(" No resource available!!!");
298 } 299 }
299 setStandardResource( res ); 300 setStandardResource( res );
300 manager->writeConfig(); 301 manager->writeConfig();
301 } 302 }
302 addCustomField( i18n( "Department" ), KABC::Field::Organization, 303 addCustomField( i18n( "Department" ), KABC::Field::Organization,
303 "X-Department", "KADDRESSBOOK" ); 304 "X-Department", "KADDRESSBOOK" );
304 addCustomField( i18n( "Profession" ), KABC::Field::Organization, 305 addCustomField( i18n( "Profession" ), KABC::Field::Organization,
305 "X-Profession", "KADDRESSBOOK" ); 306 "X-Profession", "KADDRESSBOOK" );
306 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 307 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
307 "X-AssistantsName", "KADDRESSBOOK" ); 308 "X-AssistantsName", "KADDRESSBOOK" );
308 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 309 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
309 "X-ManagersName", "KADDRESSBOOK" ); 310 "X-ManagersName", "KADDRESSBOOK" );
310 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 311 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
311 "X-SpousesName", "KADDRESSBOOK" ); 312 "X-SpousesName", "KADDRESSBOOK" );
312 addCustomField( i18n( "Office" ), KABC::Field::Personal, 313 addCustomField( i18n( "Office" ), KABC::Field::Personal,
313 "X-Office", "KADDRESSBOOK" ); 314 "X-Office", "KADDRESSBOOK" );
314 addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 315 addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
315 "X-IMAddress", "KADDRESSBOOK" ); 316 "X-IMAddress", "KADDRESSBOOK" );
316 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 317 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
317 "X-Anniversary", "KADDRESSBOOK" ); 318 "X-Anniversary", "KADDRESSBOOK" );
318 319
319 //US added this field to become compatible with Opie/qtopia addressbook 320 //US added this field to become compatible with Opie/qtopia addressbook
320 // values can be "female" or "male" or "". An empty field represents undefined. 321 // values can be "female" or "male" or "". An empty field represents undefined.
321 addCustomField( i18n( "Gender" ), KABC::Field::Personal, 322 addCustomField( i18n( "Gender" ), KABC::Field::Personal,
322 "X-Gender", "KADDRESSBOOK" ); 323 "X-Gender", "KADDRESSBOOK" );
323 addCustomField( i18n( "Children" ), KABC::Field::Personal, 324 addCustomField( i18n( "Children" ), KABC::Field::Personal,
324 "X-Children", "KADDRESSBOOK" ); 325 "X-Children", "KADDRESSBOOK" );
325 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 326 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
326 "X-FreeBusyUrl", "KADDRESSBOOK" ); 327 "X-FreeBusyUrl", "KADDRESSBOOK" );
327 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, 328 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal,
328 "X-ExternalID", "KADDRESSBOOK" ); 329 "X-ExternalID", "KADDRESSBOOK" );
329} 330}
330 331
331AddressBook::~AddressBook() 332AddressBook::~AddressBook()
332{ 333{
333 delete d->mConfig; d->mConfig = 0; 334 delete d->mConfig; d->mConfig = 0;
334 delete d->mManager; d->mManager = 0; 335 delete d->mManager; d->mManager = 0;
335//US delete d->mErrorHandler; d->mErrorHandler = 0; 336//US delete d->mErrorHandler; d->mErrorHandler = 0;
336 delete d; d = 0; 337 delete d; d = 0;
337} 338}
338 339
339bool AddressBook::load() 340bool AddressBook::load()
340{ 341{
341 342
342 343
343 clear(); 344 clear();
344 345
345 KRES::Manager<Resource>::ActiveIterator it; 346 KRES::Manager<Resource>::ActiveIterator it;
346 bool ok = true; 347 bool ok = true;
347 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 348 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
348 if ( !(*it)->load() ) { 349 if ( !(*it)->load() ) {
349 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 350 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
350 ok = false; 351 ok = false;
351 } 352 }
352 353
353 // mark all addressees as unchanged 354 // mark all addressees as unchanged
354 Addressee::List::Iterator addrIt; 355 Addressee::List::Iterator addrIt;
355 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { 356 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) {
356 (*addrIt).setChanged( false ); 357 (*addrIt).setChanged( false );
357 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); 358 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" );
358 if ( !id.isEmpty() ) { 359 if ( !id.isEmpty() ) {
359 //qDebug("setId aa %s ", id.latin1()); 360 //qDebug("setId aa %s ", id.latin1());
360 (*addrIt).setIDStr(id ); 361 (*addrIt).setIDStr(id );
361 } 362 }
362 } 363 }
363 blockLSEchange = true; 364 blockLSEchange = true;
364 return ok; 365 return ok;
365} 366}
366 367
367bool AddressBook::save( Ticket *ticket ) 368bool AddressBook::save( Ticket *ticket )
368{ 369{
369 kdDebug(5700) << "AddressBook::save()"<< endl; 370 kdDebug(5700) << "AddressBook::save()"<< endl;
370 371
371 if ( ticket->resource() ) { 372 if ( ticket->resource() ) {
372 deleteRemovedAddressees(); 373 deleteRemovedAddressees();
373 return ticket->resource()->save( ticket ); 374 return ticket->resource()->save( ticket );
374 } 375 }
375 376
376 return false; 377 return false;
377} 378}
378void AddressBook::export2File( QString fileName ) 379void AddressBook::export2File( QString fileName )
379{ 380{
380 381
381 QFile outFile( fileName ); 382 QFile outFile( fileName );
382 if ( !outFile.open( IO_WriteOnly ) ) { 383 if ( !outFile.open( IO_WriteOnly ) ) {
383 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); 384 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" );
384 KMessageBox::error( 0, text.arg( fileName ) ); 385 KMessageBox::error( 0, text.arg( fileName ) );
385 return ; 386 return ;
386 } 387 }
387 QTextStream t( &outFile ); 388 QTextStream t( &outFile );
388 t.setEncoding( QTextStream::UnicodeUTF8 ); 389 t.setEncoding( QTextStream::UnicodeUTF8 );
389 Iterator it; 390 Iterator it;
390 KABC::VCardConverter::Version version; 391 KABC::VCardConverter::Version version;
391 version = KABC::VCardConverter::v3_0; 392 version = KABC::VCardConverter::v3_0;
392 for ( it = begin(); it != end(); ++it ) { 393 for ( it = begin(); it != end(); ++it ) {
393 if ( !(*it).IDStr().isEmpty() ) { 394 if ( !(*it).IDStr().isEmpty() ) {
394 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); 395 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() );
395 } 396 }
396 KABC::VCardConverter converter; 397 KABC::VCardConverter converter;
397 QString vcard; 398 QString vcard;
398 //Resource *resource() const; 399 //Resource *resource() const;
399 converter.addresseeToVCard( *it, vcard, version ); 400 converter.addresseeToVCard( *it, vcard, version );
400 t << vcard << "\r\n"; 401 t << vcard << "\r\n";
401 } 402 }
402 t << "\r\n\r\n"; 403 t << "\r\n\r\n";
403 outFile.close(); 404 outFile.close();
404} 405}
405void AddressBook::importFromFile( QString fileName, bool replaceLabel ) 406void AddressBook::importFromFile( QString fileName, bool replaceLabel )
406{ 407{
407 408
408 KABC::Addressee::List list; 409 KABC::Addressee::List list;
409 QFile file( fileName ); 410 QFile file( fileName );
410 411
411 file.open( IO_ReadOnly ); 412 file.open( IO_ReadOnly );
412 QByteArray rawData = file.readAll(); 413 QByteArray rawData = file.readAll();
413 file.close(); 414 file.close();
414 QString data; 415 QString data;
415 if ( replaceLabel ) { 416 if ( replaceLabel ) {
416 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); 417 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 );
417 data.replace ( QRegExp("LABEL") , "ADR" ); 418 data.replace ( QRegExp("LABEL") , "ADR" );
418 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); 419 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" );
419 } else 420 } else
420 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 421 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
421 KABC::VCardTool tool; 422 KABC::VCardTool tool;
422 list = tool.parseVCards( data ); 423 list = tool.parseVCards( data );
423 KABC::Addressee::List::Iterator it; 424 KABC::Addressee::List::Iterator it;
424 for ( it = list.begin(); it != list.end(); ++it ) { 425 for ( it = list.begin(); it != list.end(); ++it ) {
425 (*it).setResource( 0 ); 426 (*it).setResource( 0 );
426 if ( replaceLabel ) 427 if ( replaceLabel )
427 (*it).removeVoice(); 428 (*it).removeVoice();
428 insertAddressee( (*it), false, true ); 429 insertAddressee( (*it), false, true );
429 } 430 }
430 431
431} 432}
432 433
433bool AddressBook::saveAB() 434bool AddressBook::saveAB()
434{ 435{
435 bool ok = true; 436 bool ok = true;
436 437
437 deleteRemovedAddressees(); 438 deleteRemovedAddressees();
438 Iterator ait; 439 Iterator ait;
439 for ( ait = begin(); ait != end(); ++ait ) { 440 for ( ait = begin(); ait != end(); ++ait ) {
440 if ( !(*ait).IDStr().isEmpty() ) { 441 if ( !(*ait).IDStr().isEmpty() ) {
441 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); 442 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
442 } 443 }
443 } 444 }
444 KRES::Manager<Resource>::ActiveIterator it; 445 KRES::Manager<Resource>::ActiveIterator it;
445 KRES::Manager<Resource> *manager = d->mManager; 446 KRES::Manager<Resource> *manager = d->mManager;
446 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 447 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
447 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 448 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
448 Ticket *ticket = requestSaveTicket( *it ); 449 Ticket *ticket = requestSaveTicket( *it );
449// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 450// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
450 if ( !ticket ) { 451 if ( !ticket ) {
451 error( i18n( "Unable to save to resource '%1'. It is locked." ) 452 error( i18n( "Unable to save to resource '%1'. It is locked." )
452 .arg( (*it)->resourceName() ) ); 453 .arg( (*it)->resourceName() ) );
453 return false; 454 return false;
454 } 455 }
455 456
456 //if ( !save( ticket ) ) 457 //if ( !save( ticket ) )
457 if ( ticket->resource() ) { 458 if ( ticket->resource() ) {
458 if ( ! ticket->resource()->save( ticket ) ) 459 if ( ! ticket->resource()->save( ticket ) )
459 ok = false; 460 ok = false;
460 } else 461 } else
461 ok = false; 462 ok = false;
462 463
463 } 464 }
464 } 465 }
465 return ok; 466 return ok;
466} 467}
467 468
468AddressBook::Iterator AddressBook::begin() 469AddressBook::Iterator AddressBook::begin()
469{ 470{
470 Iterator it = Iterator(); 471 Iterator it = Iterator();
471 it.d->mIt = d->mAddressees.begin(); 472 it.d->mIt = d->mAddressees.begin();
472 return it; 473 return it;
473} 474}
474 475
475AddressBook::ConstIterator AddressBook::begin() const 476AddressBook::ConstIterator AddressBook::begin() const
476{ 477{
477 ConstIterator it = ConstIterator(); 478 ConstIterator it = ConstIterator();
478 it.d->mIt = d->mAddressees.begin(); 479 it.d->mIt = d->mAddressees.begin();
479 return it; 480 return it;
480} 481}
481 482
482AddressBook::Iterator AddressBook::end() 483AddressBook::Iterator AddressBook::end()
483{ 484{
484 Iterator it = Iterator(); 485 Iterator it = Iterator();
485 it.d->mIt = d->mAddressees.end(); 486 it.d->mIt = d->mAddressees.end();
486 return it; 487 return it;
487} 488}
488 489
489AddressBook::ConstIterator AddressBook::end() const 490AddressBook::ConstIterator AddressBook::end() const
490{ 491{
491 ConstIterator it = ConstIterator(); 492 ConstIterator it = ConstIterator();
492 it.d->mIt = d->mAddressees.end(); 493 it.d->mIt = d->mAddressees.end();
493 return it; 494 return it;
494} 495}
495 496
496void AddressBook::clear() 497void AddressBook::clear()
497{ 498{
498 d->mAddressees.clear(); 499 d->mAddressees.clear();
499} 500}
500 501
501Ticket *AddressBook::requestSaveTicket( Resource *resource ) 502Ticket *AddressBook::requestSaveTicket( Resource *resource )
502{ 503{
503 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 504 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
504 505
505 if ( !resource ) 506 if ( !resource )
506 { 507 {
507 qDebug("AddressBook::requestSaveTicket no resource" ); 508 qDebug("AddressBook::requestSaveTicket no resource" );
508 resource = standardResource(); 509 resource = standardResource();
509 } 510 }
510 511
511 KRES::Manager<Resource>::ActiveIterator it; 512 KRES::Manager<Resource>::ActiveIterator it;
512 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 513 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
513 if ( (*it) == resource ) { 514 if ( (*it) == resource ) {
514 if ( (*it)->readOnly() || !(*it)->isOpen() ) 515 if ( (*it)->readOnly() || !(*it)->isOpen() )
515 return 0; 516 return 0;
516 else 517 else
517 return (*it)->requestSaveTicket(); 518 return (*it)->requestSaveTicket();
518 } 519 }
519 } 520 }
520 521
521 return 0; 522 return 0;
522} 523}
523 524
524void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) 525void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource )
525{ 526{
526 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { 527 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
527 //qDebug("block insert "); 528 //qDebug("block insert ");
528 return; 529 return;
529 } 530 }
530 //qDebug("inserting.... %s ",a.uid().latin1() ); 531 //qDebug("inserting.... %s ",a.uid().latin1() );
531 bool found = false; 532 bool found = false;
532 Addressee::List::Iterator it; 533 Addressee::List::Iterator it;
533 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 534 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
534 if ( a.uid() == (*it).uid() ) { 535 if ( a.uid() == (*it).uid() ) {
535 536
536 bool changed = false; 537 bool changed = false;
537 Addressee addr = a; 538 Addressee addr = a;
538 if ( addr != (*it) ) 539 if ( addr != (*it) )
539 changed = true; 540 changed = true;
540 541
541 if ( takeResource ) { 542 if ( takeResource ) {
542 Resource * res = (*it).resource(); 543 Resource * res = (*it).resource();
543 (*it) = a; 544 (*it) = a;
544 (*it).setResource( res ); 545 (*it).setResource( res );
545 } else { 546 } else {
546 (*it) = a; 547 (*it) = a;
547 if ( (*it).resource() == 0 ) 548 if ( (*it).resource() == 0 )
548 (*it).setResource( standardResource() ); 549 (*it).setResource( standardResource() );
549 } 550 }
550 if ( changed ) { 551 if ( changed ) {
551 if ( setRev ) { 552 if ( setRev ) {
552 553
553 // get rid of micro seconds 554 // get rid of micro seconds
554 QDateTime dt = QDateTime::currentDateTime(); 555 QDateTime dt = QDateTime::currentDateTime();
555 QTime t = dt.time(); 556 QTime t = dt.time();
556 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 557 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
557 (*it).setRevision( dt ); 558 (*it).setRevision( dt );
558 } 559 }
559 (*it).setChanged( true ); 560 (*it).setChanged( true );
560 } 561 }
561 562
562 found = true; 563 found = true;
563 } else { 564 } else {
564 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 565 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
565 QString name = (*it).uid().mid( 19 ); 566 QString name = (*it).uid().mid( 19 );
566 Addressee b = a; 567 Addressee b = a;
567 QString id = b.getID( name ); 568 QString id = b.getID( name );
568 if ( ! id.isEmpty() ) { 569 if ( ! id.isEmpty() ) {
569 QString des = (*it).note(); 570 QString des = (*it).note();
570 int startN; 571 int startN;
571 if( (startN = des.find( id ) ) >= 0 ) { 572 if( (startN = des.find( id ) ) >= 0 ) {
572 int endN = des.find( ",", startN+1 ); 573 int endN = des.find( ",", startN+1 );
573 des = des.left( startN ) + des.mid( endN+1 ); 574 des = des.left( startN ) + des.mid( endN+1 );
574 (*it).setNote( des ); 575 (*it).setNote( des );
575 } 576 }
576 } 577 }
577 } 578 }
578 } 579 }
579 } 580 }
580 if ( found ) 581 if ( found )
581 return; 582 return;
582 d->mAddressees.append( a ); 583 d->mAddressees.append( a );
583 Addressee& addr = d->mAddressees.last(); 584 Addressee& addr = d->mAddressees.last();
584 if ( addr.resource() == 0 ) 585 if ( addr.resource() == 0 )
585 addr.setResource( standardResource() ); 586 addr.setResource( standardResource() );
586 587
587 addr.setChanged( true ); 588 addr.setChanged( true );
588} 589}
589 590
590void AddressBook::removeAddressee( const Addressee &a ) 591void AddressBook::removeAddressee( const Addressee &a )
591{ 592{
592 Iterator it; 593 Iterator it;
593 Iterator it2; 594 Iterator it2;
594 bool found = false; 595 bool found = false;
595 for ( it = begin(); it != end(); ++it ) { 596 for ( it = begin(); it != end(); ++it ) {
596 if ( a.uid() == (*it).uid() ) { 597 if ( a.uid() == (*it).uid() ) {
597 found = true; 598 found = true;
598 it2 = it; 599 it2 = it;
599 } else { 600 } else {
600 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 601 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
601 QString name = (*it).uid().mid( 19 ); 602 QString name = (*it).uid().mid( 19 );
602 Addressee b = a; 603 Addressee b = a;
603 QString id = b.getID( name ); 604 QString id = b.getID( name );
604 if ( ! id.isEmpty() ) { 605 if ( ! id.isEmpty() ) {
605 QString des = (*it).note(); 606 QString des = (*it).note();
606 if( des.find( id ) < 0 ) { 607 if( des.find( id ) < 0 ) {
607 des += id + ","; 608 des += id + ",";
608 (*it).setNote( des ); 609 (*it).setNote( des );
609 } 610 }
610 } 611 }
611 } 612 }
612 613
613 } 614 }
614 } 615 }
615 616
616 if ( found ) 617 if ( found )
617 removeAddressee( it2 ); 618 removeAddressee( it2 );
618 619
619} 620}
620 621
621void AddressBook::removeSyncAddressees( bool removeDeleted ) 622void AddressBook::removeSyncAddressees( bool removeDeleted )
622{ 623{
623 Iterator it = begin(); 624 Iterator it = begin();
624 Iterator it2 ; 625 Iterator it2 ;
625 QDateTime dt ( QDate( 2004,1,1) ); 626 QDateTime dt ( QDate( 2004,1,1) );
626 while ( it != end() ) { 627 while ( it != end() ) {
627 (*it).setRevision( dt ); 628 (*it).setRevision( dt );
628 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); 629 (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" );
629 (*it).setIDStr(""); 630 (*it).setIDStr("");
630 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { 631 if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) {
631 it2 = it; 632 it2 = it;
632 //qDebug("removing %s ",(*it).uid().latin1() ); 633 //qDebug("removing %s ",(*it).uid().latin1() );
633 ++it; 634 ++it;
634 removeAddressee( it2 ); 635 removeAddressee( it2 );
635 } else { 636 } else {
636 //qDebug("skipping %s ",(*it).uid().latin1() ); 637 //qDebug("skipping %s ",(*it).uid().latin1() );
637 ++it; 638 ++it;
638 } 639 }
639 } 640 }
640 deleteRemovedAddressees(); 641 deleteRemovedAddressees();
641} 642}
642 643
643void AddressBook::removeAddressee( const Iterator &it ) 644void AddressBook::removeAddressee( const Iterator &it )
644{ 645{
645 d->mRemovedAddressees.append( (*it) ); 646 d->mRemovedAddressees.append( (*it) );
646 d->mAddressees.remove( it.d->mIt ); 647 d->mAddressees.remove( it.d->mIt );
647} 648}
648 649
649AddressBook::Iterator AddressBook::find( const Addressee &a ) 650AddressBook::Iterator AddressBook::find( const Addressee &a )
650{ 651{
651 Iterator it; 652 Iterator it;
652 for ( it = begin(); it != end(); ++it ) { 653 for ( it = begin(); it != end(); ++it ) {
653 if ( a.uid() == (*it).uid() ) { 654 if ( a.uid() == (*it).uid() ) {
654 return it; 655 return it;
655 } 656 }
656 } 657 }
657 return end(); 658 return end();
658} 659}
659 660
660Addressee AddressBook::findByUid( const QString &uid ) 661Addressee AddressBook::findByUid( const QString &uid )
661{ 662{
662 Iterator it; 663 Iterator it;
663 for ( it = begin(); it != end(); ++it ) { 664 for ( it = begin(); it != end(); ++it ) {
664 if ( uid == (*it).uid() ) { 665 if ( uid == (*it).uid() ) {
665 return *it; 666 return *it;
666 } 667 }
667 } 668 }
668 return Addressee(); 669 return Addressee();
669} 670}
670void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) 671void AddressBook::preExternSync( AddressBook* aBook, const QString& csd )
671{ 672{
672 //qDebug("AddressBook::preExternSync "); 673 //qDebug("AddressBook::preExternSync ");
673 AddressBook::Iterator it; 674 AddressBook::Iterator it;
674 for ( it = begin(); it != end(); ++it ) { 675 for ( it = begin(); it != end(); ++it ) {
675 (*it).setID( csd, (*it).externalUID() ); 676 (*it).setID( csd, (*it).externalUID() );
676 (*it).computeCsum( csd ); 677 (*it).computeCsum( csd );
677 } 678 }
678 mergeAB( aBook ,csd ); 679 mergeAB( aBook ,csd );
679} 680}
680void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) 681void AddressBook::postExternSync( AddressBook* aBook , const QString& csd)
681{ 682{
682 //qDebug("AddressBook::postExternSync "); 683 //qDebug("AddressBook::postExternSync ");
683 AddressBook::Iterator it; 684 AddressBook::Iterator it;
684 for ( it = begin(); it != end(); ++it ) { 685 for ( it = begin(); it != end(); ++it ) {
685 // qDebug("check uid %s ", (*it).uid().latin1() ); 686 // qDebug("check uid %s ", (*it).uid().latin1() );
686 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || 687 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ||
687 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { 688 (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) {
688 Addressee ad = aBook->findByUid( ( (*it).uid() )); 689 Addressee ad = aBook->findByUid( ( (*it).uid() ));
689 if ( ad.isEmpty() ) { 690 if ( ad.isEmpty() ) {
690 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); 691 qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1());
691 } else { 692 } else {
692 (*it).computeCsum( csd ); 693 (*it).computeCsum( csd );
693 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) 694 if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID )
694 ad.setID( csd, (*it).externalUID() ); 695 ad.setID( csd, (*it).externalUID() );
695 ad.setCsum( csd, (*it).getCsum( csd ) ); 696 ad.setCsum( csd, (*it).getCsum( csd ) );
696 aBook->insertAddressee( ad ); 697 aBook->insertAddressee( ad );
697 } 698 }
698 } 699 }
699 } 700 }
700} 701}
701 702
702bool AddressBook::containsExternalUid( const QString& uid ) 703bool AddressBook::containsExternalUid( const QString& uid )
703{ 704{
704 Iterator it; 705 Iterator it;
705 for ( it = begin(); it != end(); ++it ) { 706 for ( it = begin(); it != end(); ++it ) {
706 if ( uid == (*it).externalUID( ) ) 707 if ( uid == (*it).externalUID( ) )
707 return true; 708 return true;
708 } 709 }
709 return false; 710 return false;
710} 711}
711Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) 712Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile )
712{ 713{
713 Iterator it; 714 Iterator it;
714 for ( it = begin(); it != end(); ++it ) { 715 for ( it = begin(); it != end(); ++it ) {
715 if ( uid == (*it).getID( profile ) ) 716 if ( uid == (*it).getID( profile ) )
716 return (*it); 717 return (*it);
717 } 718 }
718 return Addressee(); 719 return Addressee();
719} 720}
720void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) 721void AddressBook::mergeAB( AddressBook *aBook, const QString& profile )
721{ 722{
722 Iterator it; 723 Iterator it;
723 Addressee ad; 724 Addressee ad;
724 for ( it = begin(); it != end(); ++it ) { 725 for ( it = begin(); it != end(); ++it ) {
725 ad = aBook->findByExternUid( (*it).externalUID(), profile ); 726 ad = aBook->findByExternUid( (*it).externalUID(), profile );
726 if ( !ad.isEmpty() ) { 727 if ( !ad.isEmpty() ) {
727 (*it).mergeContact( ad ); 728 (*it).mergeContact( ad );
728 } 729 }
729 } 730 }
730#if 0 731#if 0
731 // test only 732 // test only
732 for ( it = begin(); it != end(); ++it ) { 733 for ( it = begin(); it != end(); ++it ) {
733 734
734 qDebug("uid %s ", (*it).uid().latin1()); 735 qDebug("uid %s ", (*it).uid().latin1());
735 } 736 }
736#endif 737#endif
737} 738}
738 739
739#if 0 740#if 0
740Addressee::List AddressBook::getExternLastSyncAddressees() 741Addressee::List AddressBook::getExternLastSyncAddressees()
741{ 742{
742 Addressee::List results; 743 Addressee::List results;
743 744
744 Iterator it; 745 Iterator it;
745 for ( it = begin(); it != end(); ++it ) { 746 for ( it = begin(); it != end(); ++it ) {
746 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { 747 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
747 if ( (*it).familyName().left(4) == "!E: " ) 748 if ( (*it).familyName().left(4) == "!E: " )
748 results.append( *it ); 749 results.append( *it );
749 } 750 }
750 } 751 }
751 752
752 return results; 753 return results;
753} 754}
754#endif 755#endif
755void AddressBook::resetTempSyncStat() 756void AddressBook::resetTempSyncStat()
756{ 757{
757 Iterator it; 758 Iterator it;
758 for ( it = begin(); it != end(); ++it ) { 759 for ( it = begin(); it != end(); ++it ) {
759 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); 760 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
760 } 761 }
761 762
762} 763}
763 764
764QStringList AddressBook:: uidList() 765QStringList AddressBook:: uidList()
765{ 766{
766 QStringList results; 767 QStringList results;
767 Iterator it; 768 Iterator it;
768 for ( it = begin(); it != end(); ++it ) { 769 for ( it = begin(); it != end(); ++it ) {
769 results.append( (*it).uid() ); 770 results.append( (*it).uid() );
770 } 771 }
771 return results; 772 return results;
772} 773}
773 774
774 775
775Addressee::List AddressBook::allAddressees() 776Addressee::List AddressBook::allAddressees()
776{ 777{
777 return d->mAddressees; 778 return d->mAddressees;
778 779
779} 780}
780 781
781Addressee::List AddressBook::findByName( const QString &name ) 782Addressee::List AddressBook::findByName( const QString &name )
782{ 783{
783 Addressee::List results; 784 Addressee::List results;
784 785
785 Iterator it; 786 Iterator it;
786 for ( it = begin(); it != end(); ++it ) { 787 for ( it = begin(); it != end(); ++it ) {
787 if ( name == (*it).realName() ) { 788 if ( name == (*it).realName() ) {
788 results.append( *it ); 789 results.append( *it );
789 } 790 }
790 } 791 }
791 792
792 return results; 793 return results;
793} 794}
794 795
795Addressee::List AddressBook::findByEmail( const QString &email ) 796Addressee::List AddressBook::findByEmail( const QString &email )
796{ 797{
797 Addressee::List results; 798 Addressee::List results;
798 QStringList mailList; 799 QStringList mailList;
799 800
800 Iterator it; 801 Iterator it;
801 for ( it = begin(); it != end(); ++it ) { 802 for ( it = begin(); it != end(); ++it ) {
802 mailList = (*it).emails(); 803 mailList = (*it).emails();
803 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 804 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
804 if ( email == (*ite) ) { 805 if ( email == (*ite) ) {
805 results.append( *it ); 806 results.append( *it );
806 } 807 }
807 } 808 }
808 } 809 }
809 810
810 return results; 811 return results;
811} 812}
812 813
813Addressee::List AddressBook::findByCategory( const QString &category ) 814Addressee::List AddressBook::findByCategory( const QString &category )
814{ 815{
815 Addressee::List results; 816 Addressee::List results;
816 817
817 Iterator it; 818 Iterator it;
818 for ( it = begin(); it != end(); ++it ) { 819 for ( it = begin(); it != end(); ++it ) {
819 if ( (*it).hasCategory( category) ) { 820 if ( (*it).hasCategory( category) ) {
820 results.append( *it ); 821 results.append( *it );
821 } 822 }
822 } 823 }
823 824
824 return results; 825 return results;
825} 826}
826 827
827void AddressBook::dump() const 828void AddressBook::dump() const
828{ 829{
829 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; 830 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
830 831
831 ConstIterator it; 832 ConstIterator it;
832 for( it = begin(); it != end(); ++it ) { 833 for( it = begin(); it != end(); ++it ) {
833 (*it).dump(); 834 (*it).dump();
834 } 835 }
835 836
836 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; 837 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
837} 838}
838 839
839QString AddressBook::identifier() 840QString AddressBook::identifier()
840{ 841{
841 QStringList identifier; 842 QStringList identifier;
842 843
843 844
844 KRES::Manager<Resource>::ActiveIterator it; 845 KRES::Manager<Resource>::ActiveIterator it;
845 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 846 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
846 if ( !(*it)->identifier().isEmpty() ) 847 if ( !(*it)->identifier().isEmpty() )
847 identifier.append( (*it)->identifier() ); 848 identifier.append( (*it)->identifier() );
848 } 849 }
849 850
850 return identifier.join( ":" ); 851 return identifier.join( ":" );
851} 852}
852 853
853Field::List AddressBook::fields( int category ) 854Field::List AddressBook::fields( int category )
854{ 855{
855 if ( d->mAllFields.isEmpty() ) { 856 if ( d->mAllFields.isEmpty() ) {
856 d->mAllFields = Field::allFields(); 857 d->mAllFields = Field::allFields();
857 } 858 }
858 859
859 if ( category == Field::All ) return d->mAllFields; 860 if ( category == Field::All ) return d->mAllFields;
860 861
861 Field::List result; 862 Field::List result;
862 Field::List::ConstIterator it; 863 Field::List::ConstIterator it;
863 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { 864 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
864 if ( (*it)->category() & category ) result.append( *it ); 865 if ( (*it)->category() & category ) result.append( *it );
865 } 866 }
866 867
867 return result; 868 return result;
868} 869}
869 870
870bool AddressBook::addCustomField( const QString &label, int category, 871bool AddressBook::addCustomField( const QString &label, int category,
871 const QString &key, const QString &app ) 872 const QString &key, const QString &app )
872{ 873{
873 if ( d->mAllFields.isEmpty() ) { 874 if ( d->mAllFields.isEmpty() ) {
874 d->mAllFields = Field::allFields(); 875 d->mAllFields = Field::allFields();
875 } 876 }
876//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; 877//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app;
877 QString a = app.isNull() ? KGlobal::getAppName() : app; 878 QString a = app.isNull() ? KGlobal::getAppName() : app;
878 879
879 QString k = key.isNull() ? label : key; 880 QString k = key.isNull() ? label : key;
880 881
881 Field *field = Field::createCustomField( label, category, k, a ); 882 Field *field = Field::createCustomField( label, category, k, a );
882 883
883 if ( !field ) return false; 884 if ( !field ) return false;
884 885
885 d->mAllFields.append( field ); 886 d->mAllFields.append( field );
886 887
887 return true; 888 return true;
888} 889}
889 890
890QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) 891QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab )
891{ 892{
892 if (!ab.d) return s; 893 if (!ab.d) return s;
893 894
894 return s << ab.d->mAddressees; 895 return s << ab.d->mAddressees;
895} 896}
896 897
897QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) 898QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
898{ 899{
899 if (!ab.d) return s; 900 if (!ab.d) return s;
900 901
901 s >> ab.d->mAddressees; 902 s >> ab.d->mAddressees;
902 903
903 return s; 904 return s;
904} 905}
905 906
906bool AddressBook::addResource( Resource *resource ) 907bool AddressBook::addResource( Resource *resource )
907{ 908{
908 if ( !resource->open() ) { 909 if ( !resource->open() ) {
909 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; 910 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
910 return false; 911 return false;
911 } 912 }
912 913
913 resource->setAddressBook( this ); 914 resource->setAddressBook( this );
914 915
915 d->mManager->add( resource ); 916 d->mManager->add( resource );
916 return true; 917 return true;
917} 918}
918 919
919bool AddressBook::removeResource( Resource *resource ) 920bool AddressBook::removeResource( Resource *resource )
920{ 921{
921 resource->close(); 922 resource->close();
922 923
923 if ( resource == standardResource() ) 924 if ( resource == standardResource() )
924 d->mManager->setStandardResource( 0 ); 925 d->mManager->setStandardResource( 0 );
925 926
926 resource->setAddressBook( 0 ); 927 resource->setAddressBook( 0 );
927 928
928 d->mManager->remove( resource ); 929 d->mManager->remove( resource );
929 return true; 930 return true;
930} 931}
931 932
932QPtrList<Resource> AddressBook::resources() 933QPtrList<Resource> AddressBook::resources()
933{ 934{
934 QPtrList<Resource> list; 935 QPtrList<Resource> list;
935 936
936// qDebug("AddressBook::resources() 1"); 937// qDebug("AddressBook::resources() 1");
937 938
938 KRES::Manager<Resource>::ActiveIterator it; 939 KRES::Manager<Resource>::ActiveIterator it;
939 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 940 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
940 list.append( *it ); 941 list.append( *it );
941 942
942 return list; 943 return list;
943} 944}
944 945
945/*US 946/*US
946void AddressBook::setErrorHandler( ErrorHandler *handler ) 947void AddressBook::setErrorHandler( ErrorHandler *handler )
947{ 948{
948 delete d->mErrorHandler; 949 delete d->mErrorHandler;
949 d->mErrorHandler = handler; 950 d->mErrorHandler = handler;
950} 951}
951*/ 952*/
952 953
953void AddressBook::error( const QString& msg ) 954void AddressBook::error( const QString& msg )
954{ 955{
955/*US 956/*US
956 if ( !d->mErrorHandler ) // create default error handler 957 if ( !d->mErrorHandler ) // create default error handler
957 d->mErrorHandler = new ConsoleErrorHandler; 958 d->mErrorHandler = new ConsoleErrorHandler;
958 959
959 if ( d->mErrorHandler ) 960 if ( d->mErrorHandler )
960 d->mErrorHandler->error( msg ); 961 d->mErrorHandler->error( msg );
961 else 962 else
962 kdError(5700) << "no error handler defined" << endl; 963 kdError(5700) << "no error handler defined" << endl;
963*/ 964*/
964 kdDebug(5700) << "msg" << endl; 965 kdDebug(5700) << "msg" << endl;
965 qDebug(msg); 966 qDebug(msg);
966} 967}
967 968
968void AddressBook::deleteRemovedAddressees() 969void AddressBook::deleteRemovedAddressees()
969{ 970{
970 Addressee::List::Iterator it; 971 Addressee::List::Iterator it;
971 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { 972 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) {
972 Resource *resource = (*it).resource(); 973 Resource *resource = (*it).resource();
973 if ( resource && !resource->readOnly() && resource->isOpen() ) 974 if ( resource && !resource->readOnly() && resource->isOpen() )
974 resource->removeAddressee( *it ); 975 resource->removeAddressee( *it );
975 } 976 }
976 977
977 d->mRemovedAddressees.clear(); 978 d->mRemovedAddressees.clear();
978} 979}
979 980
980void AddressBook::setStandardResource( Resource *resource ) 981void AddressBook::setStandardResource( Resource *resource )
981{ 982{
982// qDebug("AddressBook::setStandardResource 1"); 983// qDebug("AddressBook::setStandardResource 1");
983 d->mManager->setStandardResource( resource ); 984 d->mManager->setStandardResource( resource );
984} 985}
985 986
986Resource *AddressBook::standardResource() 987Resource *AddressBook::standardResource()
987{ 988{
988 return d->mManager->standardResource(); 989 return d->mManager->standardResource();
989} 990}
990 991
991KRES::Manager<Resource> *AddressBook::resourceManager() 992KRES::Manager<Resource> *AddressBook::resourceManager()
992{ 993{
993 return d->mManager; 994 return d->mManager;
994} 995}
995 996
996void AddressBook::cleanUp() 997void AddressBook::cleanUp()
997{ 998{
998 KRES::Manager<Resource>::ActiveIterator it; 999 KRES::Manager<Resource>::ActiveIterator it;
999 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 1000 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
1000 if ( !(*it)->readOnly() && (*it)->isOpen() ) 1001 if ( !(*it)->readOnly() && (*it)->isOpen() )
1001 (*it)->cleanUp(); 1002 (*it)->cleanUp();
1002 } 1003 }
1003} 1004}