summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
Unidiff
Diffstat (limited to 'kabc/addressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp30
1 files changed, 15 insertions, 15 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index fe59fcb..c700897 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -1,137 +1,137 @@
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 <q3ptrlist.h>
41#include <qtextstream.h> 41#include <q3textstream.h>
42#include <qfile.h> 42#include <qfile.h>
43#include <qregexp.h> 43#include <qregexp.h>
44 44
45#include <kglobal.h> 45#include <kglobal.h>
46#include <klocale.h> 46#include <klocale.h>
47#include <kmessagebox.h> 47#include <kmessagebox.h>
48#include <kdebug.h> 48#include <kdebug.h>
49#include <libkcal/syncdefines.h> 49#include <libkcal/syncdefines.h>
50#include <libkdepim/phoneaccess.h> 50#include <libkdepim/phoneaccess.h>
51#include "addressbook.h" 51#include "addressbook.h"
52#include "resource.h" 52#include "resource.h"
53#include "vcardconverter.h" 53#include "vcardconverter.h"
54#include "vcardparser/vcardtool.h" 54#include "vcardparser/vcardtool.h"
55 55
56//US #include "addressbook.moc" 56//US #include "addressbook.moc"
57 57
58using namespace KABC; 58using namespace KABC;
59 59
60struct AddressBook::AddressBookData 60struct AddressBook::AddressBookData
61{ 61{
62 Addressee::List mAddressees; 62 Addressee::List mAddressees;
63 Addressee::List mRemovedAddressees; 63 Addressee::List mRemovedAddressees;
64 Field::List mAllFields; 64 Field::List mAllFields;
65 KConfig *mConfig; 65 KConfig *mConfig;
66 KRES::Manager<Resource> *mManager; 66 KRES::Manager<Resource> *mManager;
67//US ErrorHandler *mErrorHandler; 67//US ErrorHandler *mErrorHandler;
68}; 68};
69 69
70struct AddressBook::Iterator::IteratorData 70struct AddressBook::Iterator::IteratorData
71{ 71{
72 Addressee::List::Iterator mIt; 72 Addressee::List::Iterator mIt;
73}; 73};
74 74
75struct AddressBook::ConstIterator::ConstIteratorData 75struct AddressBook::ConstIterator::ConstIteratorData
76{ 76{
77 Addressee::List::ConstIterator mIt; 77 Addressee::List::ConstIterator mIt;
78}; 78};
79 79
80AddressBook::Iterator::Iterator() 80AddressBook::Iterator::Iterator()
81{ 81{
82 d = new IteratorData; 82 d = new IteratorData;
83} 83}
84 84
85AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) 85AddressBook::Iterator::Iterator( const AddressBook::Iterator &i )
86{ 86{
87 d = new IteratorData; 87 d = new IteratorData;
88 d->mIt = i.d->mIt; 88 d->mIt = i.d->mIt;
89} 89}
90 90
91AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) 91AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i )
92{ 92{
93 if( this == &i ) return *this; // guard against self assignment 93 if( this == &i ) return *this; // guard against self assignment
94 delete d; // delete the old data the Iterator was completely constructed before 94 delete d; // delete the old data the Iterator was completely constructed before
95 d = new IteratorData; 95 d = new IteratorData;
96 d->mIt = i.d->mIt; 96 d->mIt = i.d->mIt;
97 return *this; 97 return *this;
98} 98}
99 99
100AddressBook::Iterator::~Iterator() 100AddressBook::Iterator::~Iterator()
101{ 101{
102 delete d; 102 delete d;
103} 103}
104 104
105const Addressee &AddressBook::Iterator::operator*() const 105const Addressee &AddressBook::Iterator::operator*() const
106{ 106{
107 return *(d->mIt); 107 return *(d->mIt);
108} 108}
109 109
110Addressee &AddressBook::Iterator::operator*() 110Addressee &AddressBook::Iterator::operator*()
111{ 111{
112 return *(d->mIt); 112 return *(d->mIt);
113} 113}
114 114
115Addressee *AddressBook::Iterator::operator->() 115Addressee *AddressBook::Iterator::operator->()
116{ 116{
117 return &(*(d->mIt)); 117 return &(*(d->mIt));
118} 118}
119 119
120AddressBook::Iterator &AddressBook::Iterator::operator++() 120AddressBook::Iterator &AddressBook::Iterator::operator++()
121{ 121{
122 (d->mIt)++; 122 (d->mIt)++;
123 return *this; 123 return *this;
124} 124}
125 125
126AddressBook::Iterator &AddressBook::Iterator::operator++(int) 126AddressBook::Iterator &AddressBook::Iterator::operator++(int)
127{ 127{
128 (d->mIt)++; 128 (d->mIt)++;
129 return *this; 129 return *this;
130} 130}
131 131
132AddressBook::Iterator &AddressBook::Iterator::operator--() 132AddressBook::Iterator &AddressBook::Iterator::operator--()
133{ 133{
134 (d->mIt)--; 134 (d->mIt)--;
135 return *this; 135 return *this;
136} 136}
137 137
@@ -151,583 +151,583 @@ bool AddressBook::Iterator::operator!=( const Iterator &it )
151 return ( d->mIt != it.d->mIt ); 151 return ( d->mIt != it.d->mIt );
152} 152}
153 153
154 154
155AddressBook::ConstIterator::ConstIterator() 155AddressBook::ConstIterator::ConstIterator()
156{ 156{
157 d = new ConstIteratorData; 157 d = new ConstIteratorData;
158} 158}
159 159
160AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) 160AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i )
161{ 161{
162 d = new ConstIteratorData; 162 d = new ConstIteratorData;
163 d->mIt = i.d->mIt; 163 d->mIt = i.d->mIt;
164} 164}
165 165
166AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) 166AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i )
167{ 167{
168 if( this == &i ) return *this; // guard for self assignment 168 if( this == &i ) return *this; // guard for self assignment
169 delete d; // delete the old data because the Iterator was really constructed before 169 delete d; // delete the old data because the Iterator was really constructed before
170 d = new ConstIteratorData; 170 d = new ConstIteratorData;
171 d->mIt = i.d->mIt; 171 d->mIt = i.d->mIt;
172 return *this; 172 return *this;
173} 173}
174 174
175AddressBook::ConstIterator::~ConstIterator() 175AddressBook::ConstIterator::~ConstIterator()
176{ 176{
177 delete d; 177 delete d;
178} 178}
179 179
180const Addressee &AddressBook::ConstIterator::operator*() const 180const Addressee &AddressBook::ConstIterator::operator*() const
181{ 181{
182 return *(d->mIt); 182 return *(d->mIt);
183} 183}
184 184
185const Addressee* AddressBook::ConstIterator::operator->() const 185const Addressee* AddressBook::ConstIterator::operator->() const
186{ 186{
187 return &(*(d->mIt)); 187 return &(*(d->mIt));
188} 188}
189 189
190AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() 190AddressBook::ConstIterator &AddressBook::ConstIterator::operator++()
191{ 191{
192 (d->mIt)++; 192 (d->mIt)++;
193 return *this; 193 return *this;
194} 194}
195 195
196AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) 196AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int)
197{ 197{
198 (d->mIt)++; 198 (d->mIt)++;
199 return *this; 199 return *this;
200} 200}
201 201
202AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() 202AddressBook::ConstIterator &AddressBook::ConstIterator::operator--()
203{ 203{
204 (d->mIt)--; 204 (d->mIt)--;
205 return *this; 205 return *this;
206} 206}
207 207
208AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) 208AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int)
209{ 209{
210 (d->mIt)--; 210 (d->mIt)--;
211 return *this; 211 return *this;
212} 212}
213 213
214bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) 214bool AddressBook::ConstIterator::operator==( const ConstIterator &it )
215{ 215{
216 return ( d->mIt == it.d->mIt ); 216 return ( d->mIt == it.d->mIt );
217} 217}
218 218
219bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) 219bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
220{ 220{
221 return ( d->mIt != it.d->mIt ); 221 return ( d->mIt != it.d->mIt );
222} 222}
223 223
224 224
225AddressBook::AddressBook() 225AddressBook::AddressBook()
226{ 226{
227 init(0, "contact"); 227 init(0, "contact");
228} 228}
229 229
230AddressBook::AddressBook( const QString &config ) 230AddressBook::AddressBook( const QString &config )
231{ 231{
232 init(config, "contact"); 232 init(config, "contact");
233} 233}
234 234
235AddressBook::AddressBook( const QString &config, const QString &family ) 235AddressBook::AddressBook( const QString &config, const QString &family )
236{ 236{
237 init(config, family); 237 init(config, family);
238 238
239} 239}
240 240
241// the default family is "contact" 241// the default family is "contact"
242void AddressBook::init(const QString &config, const QString &family ) 242void AddressBook::init(const QString &config, const QString &family )
243{ 243{
244 blockLSEchange = false; 244 blockLSEchange = false;
245 d = new AddressBookData; 245 d = new AddressBookData;
246 QString fami = family; 246 QString fami = family;
247 if (config != 0) { 247 if (!config.isEmpty()) {
248 if ( family == "syncContact" ) { 248 if ( family == "syncContact" ) {
249 qDebug("creating sync config "); 249 qDebug("creating sync config ");
250 fami = "contact"; 250 fami = "contact";
251 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); 251 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") );
252 con->setGroup( "General" ); 252 con->setGroup( "General" );
253 con->writeEntry( "ResourceKeys", QString("sync") ); 253 con->writeEntry( "ResourceKeys", QString("sync") );
254 con->writeEntry( "Standard", QString("sync") ); 254 con->writeEntry( "Standard", QString("sync") );
255 con->setGroup( "Resource_sync" ); 255 con->setGroup( "Resource_sync" );
256 con->writeEntry( "FileName", config ); 256 con->writeEntry( "FileName", config );
257 con->writeEntry( "FileFormat", QString("vcard") ); 257 con->writeEntry( "FileFormat", QString("vcard") );
258 con->writeEntry( "ResourceIdentifier", QString("sync") ); 258 con->writeEntry( "ResourceIdentifier", QString("sync") );
259 con->writeEntry( "ResourceName", QString("sync_res") ); 259 con->writeEntry( "ResourceName", QString("sync_res") );
260 if ( config.right(4) == ".xml" ) 260 if ( config.right(4) == ".xml" )
261 con->writeEntry( "ResourceType", QString("qtopia") ); 261 con->writeEntry( "ResourceType", QString("qtopia") );
262 else if ( config == "sharp" ) { 262 else if ( config == "sharp" ) {
263 con->writeEntry( "ResourceType", QString("sharp") ); 263 con->writeEntry( "ResourceType", QString("sharp") );
264 } else { 264 } else {
265 con->writeEntry( "ResourceType", QString("file") ); 265 con->writeEntry( "ResourceType", QString("file") );
266 } 266 }
267 //con->sync(); 267 //con->sync();
268 d->mConfig = con; 268 d->mConfig = con;
269 } 269 }
270 else 270 else
271 d->mConfig = new KConfig( locateLocal("config", config) ); 271 d->mConfig = new KConfig( locateLocal("config", config) );
272// qDebug("AddressBook::init 1 config=%s",config.latin1() ); 272// qDebug("AddressBook::init 1 config=%s",config.latin1() );
273 } 273 }
274 else { 274 else {
275 d->mConfig = 0; 275 d->mConfig = 0;
276// qDebug("AddressBook::init 1 config=0"); 276// qDebug("AddressBook::init 1 config=0");
277 } 277 }
278 278
279//US d->mErrorHandler = 0; 279//US d->mErrorHandler = 0;
280 d->mManager = new KRES::Manager<Resource>( fami ); 280 d->mManager = new KRES::Manager<Resource>( fami );
281 d->mManager->readConfig( d->mConfig ); 281 d->mManager->readConfig( d->mConfig );
282 if ( family == "syncContact" ) { 282 if ( family == "syncContact" ) {
283 KRES::Manager<Resource> *manager = d->mManager; 283 KRES::Manager<Resource> *manager = d->mManager;
284 KRES::Manager<Resource>::ActiveIterator it; 284 KRES::Manager<Resource>::ActiveIterator it;
285 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 285 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
286 (*it)->setAddressBook( this ); 286 (*it)->setAddressBook( this );
287 if ( !(*it)->open() ) 287 if ( !(*it)->open() )
288 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 288 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
289 } 289 }
290 Resource *res = standardResource(); 290 Resource *res = standardResource();
291 if ( !res ) { 291 if ( !res ) {
292 qDebug("ERROR: no standard resource"); 292 qDebug("ERROR: no standard resource");
293 res = manager->createResource( "file" ); 293 res = manager->createResource( "file" );
294 if ( res ) 294 if ( res )
295 { 295 {
296 addResource( res ); 296 addResource( res );
297 } 297 }
298 else 298 else
299 qDebug(" No resource available!!!"); 299 qDebug(" No resource available!!!");
300 } 300 }
301 setStandardResource( res ); 301 setStandardResource( res );
302 manager->writeConfig(); 302 manager->writeConfig();
303 } 303 }
304 addCustomField( i18n( "Department" ), KABC::Field::Organization, 304 addCustomField( i18n( "Department" ), KABC::Field::Organization,
305 "X-Department", "KADDRESSBOOK" ); 305 "X-Department", "KADDRESSBOOK" );
306 addCustomField( i18n( "Profession" ), KABC::Field::Organization, 306 addCustomField( i18n( "Profession" ), KABC::Field::Organization,
307 "X-Profession", "KADDRESSBOOK" ); 307 "X-Profession", "KADDRESSBOOK" );
308 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 308 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
309 "X-AssistantsName", "KADDRESSBOOK" ); 309 "X-AssistantsName", "KADDRESSBOOK" );
310 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 310 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
311 "X-ManagersName", "KADDRESSBOOK" ); 311 "X-ManagersName", "KADDRESSBOOK" );
312 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 312 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
313 "X-SpousesName", "KADDRESSBOOK" ); 313 "X-SpousesName", "KADDRESSBOOK" );
314 addCustomField( i18n( "Office" ), KABC::Field::Personal, 314 addCustomField( i18n( "Office" ), KABC::Field::Personal,
315 "X-Office", "KADDRESSBOOK" ); 315 "X-Office", "KADDRESSBOOK" );
316 addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 316 addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
317 "X-IMAddress", "KADDRESSBOOK" ); 317 "X-IMAddress", "KADDRESSBOOK" );
318 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 318 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
319 "X-Anniversary", "KADDRESSBOOK" ); 319 "X-Anniversary", "KADDRESSBOOK" );
320 320
321 //US added this field to become compatible with Opie/qtopia addressbook 321 //US added this field to become compatible with Opie/qtopia addressbook
322 // values can be "female" or "male" or "". An empty field represents undefined. 322 // values can be "female" or "male" or "". An empty field represents undefined.
323 addCustomField( i18n( "Gender" ), KABC::Field::Personal, 323 addCustomField( i18n( "Gender" ), KABC::Field::Personal,
324 "X-Gender", "KADDRESSBOOK" ); 324 "X-Gender", "KADDRESSBOOK" );
325 addCustomField( i18n( "Children" ), KABC::Field::Personal, 325 addCustomField( i18n( "Children" ), KABC::Field::Personal,
326 "X-Children", "KADDRESSBOOK" ); 326 "X-Children", "KADDRESSBOOK" );
327 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 327 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
328 "X-FreeBusyUrl", "KADDRESSBOOK" ); 328 "X-FreeBusyUrl", "KADDRESSBOOK" );
329 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, 329 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal,
330 "X-ExternalID", "KADDRESSBOOK" ); 330 "X-ExternalID", "KADDRESSBOOK" );
331} 331}
332 332
333AddressBook::~AddressBook() 333AddressBook::~AddressBook()
334{ 334{
335 delete d->mConfig; d->mConfig = 0; 335 delete d->mConfig; d->mConfig = 0;
336 delete d->mManager; d->mManager = 0; 336 delete d->mManager; d->mManager = 0;
337//US delete d->mErrorHandler; d->mErrorHandler = 0; 337//US delete d->mErrorHandler; d->mErrorHandler = 0;
338 delete d; d = 0; 338 delete d; d = 0;
339} 339}
340 340
341bool AddressBook::load() 341bool AddressBook::load()
342{ 342{
343 343
344 clear(); 344 clear();
345 KRES::Manager<Resource>::ActiveIterator it; 345 KRES::Manager<Resource>::ActiveIterator it;
346 bool ok = true; 346 bool ok = true;
347 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 347 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
348 if ( !(*it)->load() ) { 348 if ( !(*it)->load() ) {
349 qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 349 qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
350 ok = false; 350 ok = false;
351 } else { 351 } else {
352 qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); 352 qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) );
353 } 353 }
354 // mark all addressees as unchanged 354 // mark all addressees as unchanged
355 Addressee::List::Iterator addrIt; 355 Addressee::List::Iterator addrIt;
356 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { 356 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) {
357 (*addrIt).setChanged( false ); 357 (*addrIt).setChanged( false );
358 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); 358 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" );
359 if ( !id.isEmpty() ) { 359 if ( !id.isEmpty() ) {
360 //qDebug("setId aa %s ", id.latin1()); 360 //qDebug("setId aa %s ", id.latin1());
361 (*addrIt).setIDStr(id ); 361 (*addrIt).setIDStr(id );
362 } 362 }
363 } 363 }
364 blockLSEchange = true; 364 blockLSEchange = true;
365 return ok; 365 return ok;
366} 366}
367 367
368bool AddressBook::save( Ticket *ticket ) 368bool AddressBook::save( Ticket *ticket )
369{ 369{
370 kdDebug(5700) << "AddressBook::save()"<< endl; 370 kdDebug(5700) << "AddressBook::save()"<< endl;
371 371
372 if ( ticket->resource() ) { 372 if ( ticket->resource() ) {
373 deleteRemovedAddressees(); 373 deleteRemovedAddressees();
374 return ticket->resource()->save( ticket ); 374 return ticket->resource()->save( ticket );
375 } 375 }
376 376
377 return false; 377 return false;
378} 378}
379// exports all Addressees, which are syncable 379// exports all Addressees, which are syncable
380void AddressBook::export2File( QString fileName, QString resourceName ) 380void AddressBook::export2File( QString fileName, QString resourceName )
381{ 381{
382 382
383 QFile outFile( fileName ); 383 QFile outFile( fileName );
384 if ( !outFile.open( IO_WriteOnly ) ) { 384 if ( !outFile.open( QIODevice::WriteOnly ) ) {
385 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); 385 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" );
386 KMessageBox::error( 0, text.arg( fileName ) ); 386 KMessageBox::error( 0, text.arg( fileName ) );
387 return ; 387 return ;
388 } 388 }
389 QTextStream t( &outFile ); 389 Q3TextStream t( &outFile );
390 t.setEncoding( QTextStream::UnicodeUTF8 ); 390 t.setEncoding( Q3TextStream::UnicodeUTF8 );
391 Iterator it; 391 Iterator it;
392 KABC::VCardConverter::Version version; 392 KABC::VCardConverter::Version version;
393 version = KABC::VCardConverter::v3_0; 393 version = KABC::VCardConverter::v3_0;
394 for ( it = begin(); it != end(); ++it ) { 394 for ( it = begin(); it != end(); ++it ) {
395 if ( (*it).resource() ) { 395 if ( (*it).resource() ) {
396 bool include = (*it).resource()->includeInSync(); 396 bool include = (*it).resource()->includeInSync();
397 if ( !resourceName.isEmpty() ) 397 if ( !resourceName.isEmpty() )
398 include = (resourceName == (*it).resource()->resourceName() ); 398 include = (resourceName == (*it).resource()->resourceName() );
399 if ( include ) { 399 if ( include ) {
400 //qDebug(QString ("Exporting resource %1 to file %2").arg( (*it).resource()->resourceName() ).arg( fileName ) ); 400 //qDebug(QString ("Exporting resource %1 to file %2").arg( (*it).resource()->resourceName() ).arg( fileName ) );
401 if ( !(*it).IDStr().isEmpty() ) { 401 if ( !(*it).IDStr().isEmpty() ) {
402 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); 402 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() );
403 } 403 }
404 KABC::VCardConverter converter; 404 KABC::VCardConverter converter;
405 QString vcard; 405 QString vcard;
406 //Resource *resource() const; 406 //Resource *resource() const;
407 converter.addresseeToVCard( *it, vcard, version ); 407 converter.addresseeToVCard( *it, vcard, version );
408 t << vcard << "\r\n"; 408 t << vcard << "\r\n";
409 } 409 }
410 } 410 }
411 } 411 }
412 t << "\r\n\r\n"; 412 t << "\r\n\r\n";
413 outFile.close(); 413 outFile.close();
414} 414}
415// if QStringList uids is empty, all are exported 415// if QStringList uids is empty, all are exported
416bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) 416bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName )
417{ 417{
418 KABC::VCardConverter converter; 418 KABC::VCardConverter converter;
419 QString datastream; 419 QString datastream;
420 Iterator it; 420 Iterator it;
421 bool all = uids.isEmpty(); 421 bool all = uids.isEmpty();
422 for ( it = begin(); it != end(); ++it ) { 422 for ( it = begin(); it != end(); ++it ) {
423 // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 423 // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
424 if ( ! all ) { 424 if ( ! all ) {
425 if ( ! ( uids.contains((*it).uid() ) )) 425 if ( ! ( uids.contains((*it).uid() ) ))
426 continue; 426 continue;
427 } 427 }
428 KABC::Addressee a = ( *it ); 428 KABC::Addressee a = ( *it );
429 if ( a.isEmpty() ) 429 if ( a.isEmpty() )
430 continue; 430 continue;
431 if ( all && a.resource() && !a.resource()->includeInSync() ) 431 if ( all && a.resource() && !a.resource()->includeInSync() )
432 continue; 432 continue;
433 a.simplifyEmails(); 433 a.simplifyEmails();
434 a.simplifyPhoneNumbers(); 434 a.simplifyPhoneNumbers();
435 a.simplifyPhoneNumberTypes(); 435 a.simplifyPhoneNumberTypes();
436 a.simplifyAddresses(); 436 a.simplifyAddresses();
437 437
438 QString vcard; 438 QString vcard;
439 QString vcardnew; 439 QString vcardnew;
440 converter.addresseeToVCard( a, vcard ); 440 converter.addresseeToVCard( a, vcard );
441 int start = 0; 441 int start = 0;
442 int next; 442 int next;
443 while ( (next = vcard.find("TYPE=", start) )>= 0 ) { 443 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
444 int semi = vcard.find(";", next); 444 int semi = vcard.find(";", next);
445 int dopp = vcard.find(":", next); 445 int dopp = vcard.find(":", next);
446 int sep; 446 int sep;
447 if ( semi < dopp && semi >= 0 ) 447 if ( semi < dopp && semi >= 0 )
448 sep = semi ; 448 sep = semi ;
449 else 449 else
450 sep = dopp; 450 sep = dopp;
451 vcardnew +=vcard.mid( start, next - start); 451 vcardnew +=vcard.mid( start, next - start);
452 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); 452 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper();
453 start = sep; 453 start = sep;
454 } 454 }
455 vcardnew += vcard.mid( start,vcard.length() ); 455 vcardnew += vcard.mid( start,vcard.length() );
456 vcard = ""; 456 vcard = "";
457 start = 0; 457 start = 0;
458 while ( (next = vcardnew.find("ADR", start) )>= 0 ) { 458 while ( (next = vcardnew.find("ADR", start) )>= 0 ) {
459 int sep = vcardnew.find(":", next); 459 int sep = vcardnew.find(":", next);
460 vcard +=vcardnew.mid( start, next - start+3); 460 vcard +=vcardnew.mid( start, next - start+3);
461 start = sep; 461 start = sep;
462 } 462 }
463 vcard += vcardnew.mid( start,vcardnew.length() ); 463 vcard += vcardnew.mid( start,vcardnew.length() );
464 vcard.replace ( QRegExp(";;;") , "" ); 464 vcard.replace ( QRegExp(";;;") , "" );
465 vcard.replace ( QRegExp(";;") , "" ); 465 vcard.replace ( QRegExp(";;") , "" );
466 datastream += vcard; 466 datastream += vcard;
467 467
468 } 468 }
469 469
470 QFile outFile(fileName); 470 QFile outFile(fileName);
471 if ( outFile.open(IO_WriteOnly) ) { 471 if ( outFile.open(QIODevice::WriteOnly) ) {
472 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); 472 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
473 QTextStream t( &outFile ); // use a text stream 473 Q3TextStream t( &outFile ); // use a text stream
474 t.setEncoding( QTextStream::UnicodeUTF8 ); 474 t.setEncoding( Q3TextStream::UnicodeUTF8 );
475 t <<datastream; 475 t <<datastream;
476 t << "\r\n\r\n"; 476 t << "\r\n\r\n";
477 outFile.close(); 477 outFile.close();
478 478
479 } else { 479 } else {
480 qDebug("Error open temp file "); 480 qDebug("Error open temp file ");
481 return false; 481 return false;
482 } 482 }
483 return true; 483 return true;
484 484
485} 485}
486int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld, QString resource ) 486int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld, QString resource )
487{ 487{
488 488
489 if ( removeOld ) 489 if ( removeOld )
490 setUntagged( true, resource ); 490 setUntagged( true, resource );
491 KABC::Addressee::List list; 491 KABC::Addressee::List list;
492 QFile file( fileName ); 492 QFile file( fileName );
493 file.open( IO_ReadOnly ); 493 file.open( QIODevice::ReadOnly );
494 QByteArray rawData = file.readAll(); 494 QByteArray rawData = file.readAll();
495 file.close(); 495 file.close();
496 QString data; 496 QString data;
497 if ( replaceLabel ) { 497 if ( replaceLabel ) {
498 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); 498 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 );
499 data.replace ( QRegExp("LABEL") , "ADR" ); 499 data.replace ( QRegExp("LABEL") , "ADR" );
500 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); 500 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" );
501 } else 501 } else
502 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 502 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
503 KABC::VCardTool tool; 503 KABC::VCardTool tool;
504 list = tool.parseVCards( data ); 504 list = tool.parseVCards( data );
505 KABC::Addressee::List::Iterator it; 505 KABC::Addressee::List::Iterator it;
506 506
507 Resource * setRes = 0; 507 Resource * setRes = 0;
508 if ( !resource.isEmpty() ) { 508 if ( !resource.isEmpty() ) {
509 KRES::Manager<Resource>::ActiveIterator it; 509 KRES::Manager<Resource>::ActiveIterator it;
510 KRES::Manager<Resource> *manager = d->mManager; 510 KRES::Manager<Resource> *manager = d->mManager;
511 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 511 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
512 //qDebug("SaveAB::checking resource..." ); 512 //qDebug("SaveAB::checking resource..." );
513 if ( (*it)->resourceName() == resource ) { 513 if ( (*it)->resourceName() == resource ) {
514 setRes = (*it); 514 setRes = (*it);
515 qDebug("KA: AB: Inserting imported contacs to resource %s", resource.latin1()); 515 qDebug("KA: AB: Inserting imported contacs to resource %s", resource.latin1());
516 break; 516 break;
517 } 517 }
518 } 518 }
519 } 519 }
520 for ( it = list.begin(); it != list.end(); ++it ) { 520 for ( it = list.begin(); it != list.end(); ++it ) {
521 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); 521 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
522 if ( !id.isEmpty() ) 522 if ( !id.isEmpty() )
523 (*it).setIDStr(id ); 523 (*it).setIDStr(id );
524 (*it).setResource( setRes ); 524 (*it).setResource( setRes );
525 if ( replaceLabel ) 525 if ( replaceLabel )
526 (*it).removeVoice(); 526 (*it).removeVoice();
527 if ( removeOld ) 527 if ( removeOld )
528 (*it).setTagged( true ); 528 (*it).setTagged( true );
529 insertAddressee( (*it), false, true ); 529 insertAddressee( (*it), false, true );
530 } 530 }
531 if ( removeOld ) 531 if ( removeOld )
532 removeUntagged(); 532 removeUntagged();
533 return list.count(); 533 return list.count();
534} 534}
535void AddressBook::setUntagged(bool setNonSyncTagged, QString resource) // = false , "") 535void AddressBook::setUntagged(bool setNonSyncTagged, QString resource) // = false , "")
536{ 536{
537 Iterator ait; 537 Iterator ait;
538 if ( !resource.isEmpty() ) { 538 if ( !resource.isEmpty() ) {
539 for ( ait = begin(); ait != end(); ++ait ) { 539 for ( ait = begin(); ait != end(); ++ait ) {
540 if ( (*ait).resource() && (*ait).resource()->resourceName() == resource ) { 540 if ( (*ait).resource() && (*ait).resource()->resourceName() == resource ) {
541 (*ait).setTagged( false ); 541 (*ait).setTagged( false );
542 } 542 }
543 else 543 else
544 (*ait).setTagged( true ); 544 (*ait).setTagged( true );
545 } 545 }
546 } else { 546 } else {
547 for ( ait = begin(); ait != end(); ++ait ) { 547 for ( ait = begin(); ait != end(); ++ait ) {
548 if ( setNonSyncTagged ) { 548 if ( setNonSyncTagged ) {
549 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { 549 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) {
550 (*ait).setTagged( true ); 550 (*ait).setTagged( true );
551 } else 551 } else
552 (*ait).setTagged( false ); 552 (*ait).setTagged( false );
553 } else 553 } else
554 (*ait).setTagged( false ); 554 (*ait).setTagged( false );
555 } 555 }
556 } 556 }
557} 557}
558void AddressBook::removeUntagged() 558void AddressBook::removeUntagged()
559{ 559{
560 Iterator ait; 560 Iterator ait;
561 bool todelete = false; 561 bool todelete = false;
562 Iterator todel; 562 Iterator todel;
563 for ( ait = begin(); ait != end(); ++ait ) { 563 for ( ait = begin(); ait != end(); ++ait ) {
564 if ( todelete ) 564 if ( todelete )
565 removeAddressee( todel ); 565 removeAddressee( todel );
566 if (!(*ait).tagged()) { 566 if (!(*ait).tagged()) {
567 todelete = true; 567 todelete = true;
568 todel = ait; 568 todel = ait;
569 } else 569 } else
570 todelete = false; 570 todelete = false;
571 } 571 }
572 if ( todelete ) 572 if ( todelete )
573 removeAddressee( todel ); 573 removeAddressee( todel );
574 deleteRemovedAddressees(); 574 deleteRemovedAddressees();
575} 575}
576void AddressBook::smplifyAddressees() 576void AddressBook::smplifyAddressees()
577{ 577{
578 Iterator ait; 578 Iterator ait;
579 for ( ait = begin(); ait != end(); ++ait ) { 579 for ( ait = begin(); ait != end(); ++ait ) {
580 (*ait).simplifyEmails(); 580 (*ait).simplifyEmails();
581 (*ait).simplifyPhoneNumbers(); 581 (*ait).simplifyPhoneNumbers();
582 (*ait).simplifyPhoneNumberTypes(); 582 (*ait).simplifyPhoneNumberTypes();
583 (*ait).simplifyAddresses(); 583 (*ait).simplifyAddresses();
584 } 584 }
585} 585}
586void AddressBook::removeSyncInfo( QString syncProfile) 586void AddressBook::removeSyncInfo( QString syncProfile)
587{ 587{
588 Iterator ait; 588 Iterator ait;
589 for ( ait = begin(); ait != end(); ++ait ) { 589 for ( ait = begin(); ait != end(); ++ait ) {
590 (*ait).removeID( syncProfile ); 590 (*ait).removeID( syncProfile );
591 } 591 }
592 if ( syncProfile.isEmpty() ) { 592 if ( syncProfile.isEmpty() ) {
593 Iterator it = begin(); 593 Iterator it = begin();
594 Iterator it2 ; 594 Iterator it2 ;
595 while ( it != end() ) { 595 while ( it != end() ) {
596 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { 596 if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
597 it2 = it; 597 it2 = it;
598 //qDebug("removing %s ",(*it).uid().latin1() ); 598 //qDebug("removing %s ",(*it).uid().latin1() );
599 ++it; 599 ++it;
600 removeAddressee( it2 ); 600 removeAddressee( it2 );
601 } else { 601 } else {
602 //qDebug("skipping %s ",(*it).uid().latin1() ); 602 //qDebug("skipping %s ",(*it).uid().latin1() );
603 ++it; 603 ++it;
604 } 604 }
605 } 605 }
606 } else { 606 } else {
607 Addressee lse; 607 Addressee lse;
608 lse = findByUid( "last-syncAddressee-"+ syncProfile ); 608 lse = findByUid( "last-syncAddressee-"+ syncProfile );
609 if ( ! lse.isEmpty() ) 609 if ( ! lse.isEmpty() )
610 removeAddressee( lse ); 610 removeAddressee( lse );
611 } 611 }
612 612
613} 613}
614void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) 614void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync )
615{ 615{
616 Iterator ait; 616 Iterator ait;
617 for ( ait = begin(); ait != end(); ++ait ) { 617 for ( ait = begin(); ait != end(); ++ait ) {
618 QString id = (*ait).IDStr(); 618 QString id = (*ait).IDStr();
619 (*ait).setIDStr( ":"); 619 (*ait).setIDStr( ":");
620 (*ait).setExternalUID( id ); 620 (*ait).setExternalUID( id );
621 (*ait).setOriginalExternalUID( id ); 621 (*ait).setOriginalExternalUID( id );
622 if ( isPreSync ) 622 if ( isPreSync )
623 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 623 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
624 else { 624 else {
625 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 625 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
626 (*ait).setID( currentSyncDevice,id ); 626 (*ait).setID( currentSyncDevice,id );
627 627
628 } 628 }
629 } 629 }
630} 630}
631void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) 631void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice )
632{ 632{
633 633
634 setUntagged(); 634 setUntagged();
635 KABC::Addressee::List list; 635 KABC::Addressee::List list;
636 QFile file( fileName ); 636 QFile file( fileName );
637 file.open( IO_ReadOnly ); 637 file.open( QIODevice::ReadOnly );
638 QByteArray rawData = file.readAll(); 638 QByteArray rawData = file.readAll();
639 file.close(); 639 file.close();
640 QString data; 640 QString data;
641 641
642 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 642 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
643 KABC::VCardTool tool; 643 KABC::VCardTool tool;
644 list = tool.parseVCards( data ); 644 list = tool.parseVCards( data );
645 KABC::Addressee::List::Iterator it; 645 KABC::Addressee::List::Iterator it;
646 for ( it = list.begin(); it != list.end(); ++it ) { 646 for ( it = list.begin(); it != list.end(); ++it ) {
647 Iterator ait; 647 Iterator ait;
648 for ( ait = begin(); ait != end(); ++ait ) { 648 for ( ait = begin(); ait != end(); ++ait ) {
649 if ( !(*ait).tagged() ) { 649 if ( !(*ait).tagged() ) {
650 if ( (*ait).containsAdr(*it)) { 650 if ( (*ait).containsAdr(*it)) {
651 (*ait).setTagged(true); 651 (*ait).setTagged(true);
652 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); 652 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
653 (*it).setIDStr( ":"); 653 (*it).setIDStr( ":");
654 (*it).setID( currentSyncDevice,id ); 654 (*it).setID( currentSyncDevice,id );
655 (*it).setExternalUID( id ); 655 (*it).setExternalUID( id );
656 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 656 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
657 (*it).setUid( ( (*ait).uid() )); 657 (*it).setUid( ( (*ait).uid() ));
658 break; 658 break;
659 } 659 }
660 } 660 }
661 661
662 } 662 }
663 if ( ait == end() ) 663 if ( ait == end() )
664 qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); 664 qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1());
665 } 665 }
666 clear(); 666 clear();
667 for ( it = list.begin(); it != list.end(); ++it ) { 667 for ( it = list.begin(); it != list.end(); ++it ) {
668 insertAddressee( (*it) ); 668 insertAddressee( (*it) );
669 } 669 }
670} 670}
671 671
672bool AddressBook::saveABphone( QString fileName ) 672bool AddressBook::saveABphone( QString fileName )
673{ 673{
674 //smplifyAddressees(); 674 //smplifyAddressees();
675 qDebug("saveABphone:: saving AB... "); 675 qDebug("saveABphone:: saving AB... ");
676 if ( ! export2PhoneFormat( QStringList() ,fileName ) ) 676 if ( ! export2PhoneFormat( QStringList() ,fileName ) )
677 return false; 677 return false;
678 qDebug("saveABphone:: writing to phone... "); 678 qDebug("saveABphone:: writing to phone... ");
679 if ( !PhoneAccess::writeToPhone( fileName) ) { 679 if ( !PhoneAccess::writeToPhone( fileName) ) {
680 return false; 680 return false;
681 } 681 }
682 qDebug("saveABphone:: re-reading from phone... "); 682 qDebug("saveABphone:: re-reading from phone... ");
683 if ( !PhoneAccess::readFromPhone( fileName) ) { 683 if ( !PhoneAccess::readFromPhone( fileName) ) {
684 return false; 684 return false;
685 } 685 }
686 return true; 686 return true;
687} 687}
688bool AddressBook::saveAB() 688bool AddressBook::saveAB()
689{ 689{
690 bool ok = true; 690 bool ok = true;
691 691
692 deleteRemovedAddressees(); 692 deleteRemovedAddressees();
693 Iterator ait; 693 Iterator ait;
694 for ( ait = begin(); ait != end(); ++ait ) { 694 for ( ait = begin(); ait != end(); ++ait ) {
695 if ( !(*ait).IDStr().isEmpty() ) { 695 if ( !(*ait).IDStr().isEmpty() ) {
696 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); 696 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
697 } 697 }
698 } 698 }
699 KRES::Manager<Resource>::ActiveIterator it; 699 KRES::Manager<Resource>::ActiveIterator it;
700 KRES::Manager<Resource> *manager = d->mManager; 700 KRES::Manager<Resource> *manager = d->mManager;
701 qDebug("SaveAB::saving..." ); 701 qDebug("SaveAB::saving..." );
702 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 702 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
703 qDebug("SaveAB::checking resource..." ); 703 qDebug("SaveAB::checking resource..." );
704 if ( (*it)->readOnly() ) 704 if ( (*it)->readOnly() )
705 qDebug("SaveAB::resource is readonly." ); 705 qDebug("SaveAB::resource is readonly." );
706 if ( (*it)->isOpen() ) 706 if ( (*it)->isOpen() )
707 qDebug("SaveAB::resource is open" ); 707 qDebug("SaveAB::resource is open" );
708 708
709 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 709 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
710 Ticket *ticket = requestSaveTicket( *it ); 710 Ticket *ticket = requestSaveTicket( *it );
711 qDebug("SaveAB::StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 711 qDebug("SaveAB::StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
712 if ( !ticket ) { 712 if ( !ticket ) {
713 qDebug( i18n( "SaveAB::Unable to save to resource '%1'. It is locked." ) 713 qDebug( i18n( "SaveAB::Unable to save to resource '%1'. It is locked." )
714 .arg( (*it)->resourceName() ) ); 714 .arg( (*it)->resourceName() ) );
715 return false; 715 return false;
716 } 716 }
717 717
718 //if ( !save( ticket ) ) 718 //if ( !save( ticket ) )
719 if ( ticket->resource() ) { 719 if ( ticket->resource() ) {
720 QString name = ticket->resource()->resourceName(); 720 QString name = ticket->resource()->resourceName();
721 if ( ! ticket->resource()->save( ticket ) ) 721 if ( ! ticket->resource()->save( ticket ) )
722 ok = false; 722 ok = false;
723 else 723 else
724 qDebug("SaveAB::resource saved '%s'", name.latin1() ); 724 qDebug("SaveAB::resource saved '%s'", name.latin1() );
725 725
726 } else 726 } else
727 ok = false; 727 ok = false;
728 728
729 } 729 }
730 } 730 }
731 return ok; 731 return ok;
732} 732}
733 733
@@ -1125,190 +1125,190 @@ Addressee::List AddressBook::findByCategory( const QString &category )
1125} 1125}
1126 1126
1127void AddressBook::dump() const 1127void AddressBook::dump() const
1128{ 1128{
1129 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; 1129 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
1130 1130
1131 ConstIterator it; 1131 ConstIterator it;
1132 for( it = begin(); it != end(); ++it ) { 1132 for( it = begin(); it != end(); ++it ) {
1133 (*it).dump(); 1133 (*it).dump();
1134 } 1134 }
1135 1135
1136 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; 1136 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
1137} 1137}
1138 1138
1139QString AddressBook::identifier() 1139QString AddressBook::identifier()
1140{ 1140{
1141 QStringList identifier; 1141 QStringList identifier;
1142 1142
1143 1143
1144 KRES::Manager<Resource>::ActiveIterator it; 1144 KRES::Manager<Resource>::ActiveIterator it;
1145 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 1145 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
1146 if ( !(*it)->identifier().isEmpty() ) 1146 if ( !(*it)->identifier().isEmpty() )
1147 identifier.append( (*it)->identifier() ); 1147 identifier.append( (*it)->identifier() );
1148 } 1148 }
1149 1149
1150 return identifier.join( ":" ); 1150 return identifier.join( ":" );
1151} 1151}
1152 1152
1153Field::List AddressBook::fields( int category ) 1153Field::List AddressBook::fields( int category )
1154{ 1154{
1155 if ( d->mAllFields.isEmpty() ) { 1155 if ( d->mAllFields.isEmpty() ) {
1156 d->mAllFields = Field::allFields(); 1156 d->mAllFields = Field::allFields();
1157 } 1157 }
1158 1158
1159 if ( category == Field::All ) return d->mAllFields; 1159 if ( category == Field::All ) return d->mAllFields;
1160 1160
1161 Field::List result; 1161 Field::List result;
1162 Field::List::ConstIterator it; 1162 Field::List::ConstIterator it;
1163 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { 1163 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
1164 if ( (*it)->category() & category ) result.append( *it ); 1164 if ( (*it)->category() & category ) result.append( *it );
1165 } 1165 }
1166 1166
1167 return result; 1167 return result;
1168} 1168}
1169 1169
1170bool AddressBook::addCustomField( const QString &label, int category, 1170bool AddressBook::addCustomField( const QString &label, int category,
1171 const QString &key, const QString &app ) 1171 const QString &key, const QString &app )
1172{ 1172{
1173 if ( d->mAllFields.isEmpty() ) { 1173 if ( d->mAllFields.isEmpty() ) {
1174 d->mAllFields = Field::allFields(); 1174 d->mAllFields = Field::allFields();
1175 } 1175 }
1176//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; 1176//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app;
1177 QString a = app.isNull() ? KGlobal::getAppName() : app; 1177 QString a = app.isNull() ? KGlobal::getAppName() : app;
1178 1178
1179 QString k = key.isNull() ? label : key; 1179 QString k = key.isNull() ? label : key;
1180 1180
1181 Field *field = Field::createCustomField( label, category, k, a ); 1181 Field *field = Field::createCustomField( label, category, k, a );
1182 1182
1183 if ( !field ) return false; 1183 if ( !field ) return false;
1184 1184
1185 d->mAllFields.append( field ); 1185 d->mAllFields.append( field );
1186 1186
1187 return true; 1187 return true;
1188} 1188}
1189 1189
1190QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) 1190QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab )
1191{ 1191{
1192 if (!ab.d) return s; 1192 if (!ab.d) return s;
1193 1193
1194 return s << ab.d->mAddressees; 1194 return s << ab.d->mAddressees;
1195} 1195}
1196 1196
1197QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) 1197QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
1198{ 1198{
1199 if (!ab.d) return s; 1199 if (!ab.d) return s;
1200 1200
1201 s >> ab.d->mAddressees; 1201 s >> ab.d->mAddressees;
1202 1202
1203 return s; 1203 return s;
1204} 1204}
1205 1205
1206bool AddressBook::addResource( Resource *resource ) 1206bool AddressBook::addResource( Resource *resource )
1207{ 1207{
1208 if ( !resource->open() ) { 1208 if ( !resource->open() ) {
1209 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; 1209 kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
1210 return false; 1210 return false;
1211 } 1211 }
1212 1212
1213 resource->setAddressBook( this ); 1213 resource->setAddressBook( this );
1214 1214
1215 d->mManager->add( resource ); 1215 d->mManager->add( resource );
1216 return true; 1216 return true;
1217} 1217}
1218void AddressBook::removeResources() 1218void AddressBook::removeResources()
1219{ 1219{
1220 //remove all possible resources. This should cleanup the configfile. 1220 //remove all possible resources. This should cleanup the configfile.
1221 QPtrList<KABC::Resource> mResources = resources(); 1221 Q3PtrList<KABC::Resource> mResources = resources();
1222 1222
1223 QPtrListIterator<KABC::Resource> it(mResources); 1223 Q3PtrListIterator<KABC::Resource> it(mResources);
1224 for ( ; it.current(); ++it ) { 1224 for ( ; it.current(); ++it ) {
1225 KABC::Resource *res = it.current(); 1225 KABC::Resource *res = it.current();
1226 removeResource(res); 1226 removeResource(res);
1227 } 1227 }
1228} 1228}
1229 1229
1230bool AddressBook::removeResource( Resource *resource ) 1230bool AddressBook::removeResource( Resource *resource )
1231{ 1231{
1232 resource->close(); 1232 resource->close();
1233 1233
1234 if ( resource == standardResource() ) 1234 if ( resource == standardResource() )
1235 d->mManager->setStandardResource( 0 ); 1235 d->mManager->setStandardResource( 0 );
1236 1236
1237 resource->setAddressBook( 0 ); 1237 resource->setAddressBook( 0 );
1238 1238
1239 d->mManager->remove( resource ); 1239 d->mManager->remove( resource );
1240 return true; 1240 return true;
1241} 1241}
1242 1242
1243QPtrList<Resource> AddressBook::resources() 1243Q3PtrList<Resource> AddressBook::resources()
1244{ 1244{
1245 QPtrList<Resource> list; 1245 Q3PtrList<Resource> list;
1246 1246
1247// qDebug("AddressBook::resources() 1"); 1247// qDebug("AddressBook::resources() 1");
1248 1248
1249 KRES::Manager<Resource>::ActiveIterator it; 1249 KRES::Manager<Resource>::ActiveIterator it;
1250 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 1250 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
1251 list.append( *it ); 1251 list.append( *it );
1252 1252
1253 return list; 1253 return list;
1254} 1254}
1255 1255
1256/*US 1256/*US
1257void AddressBook::setErrorHandler( ErrorHandler *handler ) 1257void AddressBook::setErrorHandler( ErrorHandler *handler )
1258{ 1258{
1259 delete d->mErrorHandler; 1259 delete d->mErrorHandler;
1260 d->mErrorHandler = handler; 1260 d->mErrorHandler = handler;
1261} 1261}
1262*/ 1262*/
1263 1263
1264void AddressBook::error( const QString& msg ) 1264void AddressBook::error( const QString& msg )
1265{ 1265{
1266/*US 1266/*US
1267 if ( !d->mErrorHandler ) // create default error handler 1267 if ( !d->mErrorHandler ) // create default error handler
1268 d->mErrorHandler = new ConsoleErrorHandler; 1268 d->mErrorHandler = new ConsoleErrorHandler;
1269 1269
1270 if ( d->mErrorHandler ) 1270 if ( d->mErrorHandler )
1271 d->mErrorHandler->error( msg ); 1271 d->mErrorHandler->error( msg );
1272 else 1272 else
1273 kdError(5700) << "no error handler defined" << endl; 1273 kdError(5700) << "no error handler defined" << endl;
1274*/ 1274*/
1275 kdDebug(5700) << "msg" << endl; 1275 kdDebug(5700) << "msg" << endl;
1276 qDebug(msg); 1276 qDebug(msg);
1277} 1277}
1278 1278
1279void AddressBook::deleteRemovedAddressees() 1279void AddressBook::deleteRemovedAddressees()
1280{ 1280{
1281 Addressee::List::Iterator it; 1281 Addressee::List::Iterator it;
1282 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { 1282 for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) {
1283 Resource *resource = (*it).resource(); 1283 Resource *resource = (*it).resource();
1284 if ( resource && !resource->readOnly() && resource->isOpen() ) 1284 if ( resource && !resource->readOnly() && resource->isOpen() )
1285 resource->removeAddressee( *it ); 1285 resource->removeAddressee( *it );
1286 } 1286 }
1287 1287
1288 d->mRemovedAddressees.clear(); 1288 d->mRemovedAddressees.clear();
1289} 1289}
1290 1290
1291void AddressBook::setStandardResource( Resource *resource ) 1291void AddressBook::setStandardResource( Resource *resource )
1292{ 1292{
1293// qDebug("AddressBook::setStandardResource 1"); 1293// qDebug("AddressBook::setStandardResource 1");
1294 d->mManager->setStandardResource( resource ); 1294 d->mManager->setStandardResource( resource );
1295} 1295}
1296 1296
1297Resource *AddressBook::standardResource() 1297Resource *AddressBook::standardResource()
1298{ 1298{
1299 return d->mManager->standardResource(); 1299 return d->mManager->standardResource();
1300} 1300}
1301 1301
1302KRES::Manager<Resource> *AddressBook::resourceManager() 1302KRES::Manager<Resource> *AddressBook::resourceManager()
1303{ 1303{
1304 return d->mManager; 1304 return d->mManager;
1305} 1305}
1306 1306
1307void AddressBook::cleanUp() 1307void AddressBook::cleanUp()
1308{ 1308{
1309 KRES::Manager<Resource>::ActiveIterator it; 1309 KRES::Manager<Resource>::ActiveIterator it;
1310 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 1310 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
1311 if ( !(*it)->readOnly() && (*it)->isOpen() ) 1311 if ( !(*it)->readOnly() && (*it)->isOpen() )
1312 (*it)->cleanUp(); 1312 (*it)->cleanUp();
1313 } 1313 }
1314} 1314}