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