summaryrefslogtreecommitdiffabout
path: root/kabc
Unidiff
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 1a06956..1050f55 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -1,426 +1,427 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28/*US 28/*US
29 29
30#include <qfile.h> 30#include <qfile.h>
31#include <qregexp.h> 31#include <qregexp.h>
32#include <qtimer.h> 32#include <qtimer.h>
33 33
34#include <kapplication.h> 34#include <kapplication.h>
35#include <kinstance.h> 35#include <kinstance.h>
36#include <kstandarddirs.h> 36#include <kstandarddirs.h>
37 37
38#include "errorhandler.h" 38#include "errorhandler.h"
39*/ 39*/
40#include <qptrlist.h> 40#include <qptrlist.h>
41#include <qtextstream.h> 41#include <qtextstream.h>
42#include <qfile.h> 42#include <qfile.h>
43#include <qregexp.h>
43 44
44#include <kglobal.h> 45#include <kglobal.h>
45#include <klocale.h> 46#include <klocale.h>
46#include <kmessagebox.h> 47#include <kmessagebox.h>
47#include <kdebug.h> 48#include <kdebug.h>
48#include <libkcal/syncdefines.h> 49#include <libkcal/syncdefines.h>
49#include "addressbook.h" 50#include "addressbook.h"
50#include "resource.h" 51#include "resource.h"
51#include "vcardconverter.h" 52#include "vcardconverter.h"
52#include "vcardparser/vcardtool.h" 53#include "vcardparser/vcardtool.h"
53 54
54//US #include "addressbook.moc" 55//US #include "addressbook.moc"
55 56
56using namespace KABC; 57using namespace KABC;
57 58
58struct AddressBook::AddressBookData 59struct AddressBook::AddressBookData
59{ 60{
60 Addressee::List mAddressees; 61 Addressee::List mAddressees;
61 Addressee::List mRemovedAddressees; 62 Addressee::List mRemovedAddressees;
62 Field::List mAllFields; 63 Field::List mAllFields;
63 KConfig *mConfig; 64 KConfig *mConfig;
64 KRES::Manager<Resource> *mManager; 65 KRES::Manager<Resource> *mManager;
65//US ErrorHandler *mErrorHandler; 66//US ErrorHandler *mErrorHandler;
66}; 67};
67 68
68struct AddressBook::Iterator::IteratorData 69struct AddressBook::Iterator::IteratorData
69{ 70{
70 Addressee::List::Iterator mIt; 71 Addressee::List::Iterator mIt;
71}; 72};
72 73
73struct AddressBook::ConstIterator::ConstIteratorData 74struct AddressBook::ConstIterator::ConstIteratorData
74{ 75{
75 Addressee::List::ConstIterator mIt; 76 Addressee::List::ConstIterator mIt;
76}; 77};
77 78
78AddressBook::Iterator::Iterator() 79AddressBook::Iterator::Iterator()
79{ 80{
80 d = new IteratorData; 81 d = new IteratorData;
81} 82}
82 83
83AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) 84AddressBook::Iterator::Iterator( const AddressBook::Iterator &i )
84{ 85{
85 d = new IteratorData; 86 d = new IteratorData;
86 d->mIt = i.d->mIt; 87 d->mIt = i.d->mIt;
87} 88}
88 89
89AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) 90AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i )
90{ 91{
91 if( this == &i ) return *this; // guard against self assignment 92 if( this == &i ) return *this; // guard against self assignment
92 delete d; // delete the old data the Iterator was completely constructed before 93 delete d; // delete the old data the Iterator was completely constructed before
93 d = new IteratorData; 94 d = new IteratorData;
94 d->mIt = i.d->mIt; 95 d->mIt = i.d->mIt;
95 return *this; 96 return *this;
96} 97}
97 98
98AddressBook::Iterator::~Iterator() 99AddressBook::Iterator::~Iterator()
99{ 100{
100 delete d; 101 delete d;
101} 102}
102 103
103const Addressee &AddressBook::Iterator::operator*() const 104const Addressee &AddressBook::Iterator::operator*() const
104{ 105{
105 return *(d->mIt); 106 return *(d->mIt);
106} 107}
107 108
108Addressee &AddressBook::Iterator::operator*() 109Addressee &AddressBook::Iterator::operator*()
109{ 110{
110 return *(d->mIt); 111 return *(d->mIt);
111} 112}
112 113
113Addressee *AddressBook::Iterator::operator->() 114Addressee *AddressBook::Iterator::operator->()
114{ 115{
115 return &(*(d->mIt)); 116 return &(*(d->mIt));
116} 117}
117 118
118AddressBook::Iterator &AddressBook::Iterator::operator++() 119AddressBook::Iterator &AddressBook::Iterator::operator++()
119{ 120{
120 (d->mIt)++; 121 (d->mIt)++;
121 return *this; 122 return *this;
122} 123}
123 124
124AddressBook::Iterator &AddressBook::Iterator::operator++(int) 125AddressBook::Iterator &AddressBook::Iterator::operator++(int)
125{ 126{
126 (d->mIt)++; 127 (d->mIt)++;
127 return *this; 128 return *this;
128} 129}
129 130
130AddressBook::Iterator &AddressBook::Iterator::operator--() 131AddressBook::Iterator &AddressBook::Iterator::operator--()
131{ 132{
132 (d->mIt)--; 133 (d->mIt)--;
133 return *this; 134 return *this;
134} 135}
135 136
136AddressBook::Iterator &AddressBook::Iterator::operator--(int) 137AddressBook::Iterator &AddressBook::Iterator::operator--(int)
137{ 138{
138 (d->mIt)--; 139 (d->mIt)--;
139 return *this; 140 return *this;
140} 141}
141 142
142bool AddressBook::Iterator::operator==( const Iterator &it ) 143bool AddressBook::Iterator::operator==( const Iterator &it )
143{ 144{
144 return ( d->mIt == it.d->mIt ); 145 return ( d->mIt == it.d->mIt );
145} 146}
146 147
147bool AddressBook::Iterator::operator!=( const Iterator &it ) 148bool AddressBook::Iterator::operator!=( const Iterator &it )
148{ 149{
149 return ( d->mIt != it.d->mIt ); 150 return ( d->mIt != it.d->mIt );
150} 151}
151 152
152 153
153AddressBook::ConstIterator::ConstIterator() 154AddressBook::ConstIterator::ConstIterator()
154{ 155{
155 d = new ConstIteratorData; 156 d = new ConstIteratorData;
156} 157}
157 158
158AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) 159AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i )
159{ 160{
160 d = new ConstIteratorData; 161 d = new ConstIteratorData;
161 d->mIt = i.d->mIt; 162 d->mIt = i.d->mIt;
162} 163}
163 164
164AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) 165AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i )
165{ 166{
166 if( this == &i ) return *this; // guard for self assignment 167 if( this == &i ) return *this; // guard for self assignment
167 delete d; // delete the old data because the Iterator was really constructed before 168 delete d; // delete the old data because the Iterator was really constructed before
168 d = new ConstIteratorData; 169 d = new ConstIteratorData;
169 d->mIt = i.d->mIt; 170 d->mIt = i.d->mIt;
170 return *this; 171 return *this;
171} 172}
172 173
173AddressBook::ConstIterator::~ConstIterator() 174AddressBook::ConstIterator::~ConstIterator()
174{ 175{
175 delete d; 176 delete d;
176} 177}
177 178
178const Addressee &AddressBook::ConstIterator::operator*() const 179const Addressee &AddressBook::ConstIterator::operator*() const
179{ 180{
180 return *(d->mIt); 181 return *(d->mIt);
181} 182}
182 183
183const Addressee* AddressBook::ConstIterator::operator->() const 184const Addressee* AddressBook::ConstIterator::operator->() const
184{ 185{
185 return &(*(d->mIt)); 186 return &(*(d->mIt));
186} 187}
187 188
188AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() 189AddressBook::ConstIterator &AddressBook::ConstIterator::operator++()
189{ 190{
190 (d->mIt)++; 191 (d->mIt)++;
191 return *this; 192 return *this;
192} 193}
193 194
194AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) 195AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int)
195{ 196{
196 (d->mIt)++; 197 (d->mIt)++;
197 return *this; 198 return *this;
198} 199}
199 200
200AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() 201AddressBook::ConstIterator &AddressBook::ConstIterator::operator--()
201{ 202{
202 (d->mIt)--; 203 (d->mIt)--;
203 return *this; 204 return *this;
204} 205}
205 206
206AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) 207AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int)
207{ 208{
208 (d->mIt)--; 209 (d->mIt)--;
209 return *this; 210 return *this;
210} 211}
211 212
212bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) 213bool AddressBook::ConstIterator::operator==( const ConstIterator &it )
213{ 214{
214 return ( d->mIt == it.d->mIt ); 215 return ( d->mIt == it.d->mIt );
215} 216}
216 217
217bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) 218bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
218{ 219{
219 return ( d->mIt != it.d->mIt ); 220 return ( d->mIt != it.d->mIt );
220} 221}
221 222
222 223
223AddressBook::AddressBook() 224AddressBook::AddressBook()
224{ 225{
225 init(0, "contact"); 226 init(0, "contact");
226} 227}
227 228
228AddressBook::AddressBook( const QString &config ) 229AddressBook::AddressBook( const QString &config )
229{ 230{
230 init(config, "contact"); 231 init(config, "contact");
231} 232}
232 233
233AddressBook::AddressBook( const QString &config, const QString &family ) 234AddressBook::AddressBook( const QString &config, const QString &family )
234{ 235{
235 init(config, family); 236 init(config, family);
236 237
237} 238}
238 239
239// the default family is "contact" 240// the default family is "contact"
240void AddressBook::init(const QString &config, const QString &family ) 241void AddressBook::init(const QString &config, const QString &family )
241{ 242{
242 blockLSEchange = false; 243 blockLSEchange = false;
243 d = new AddressBookData; 244 d = new AddressBookData;
244 QString fami = family; 245 QString fami = family;
245 if (config != 0) { 246 if (config != 0) {
246 if ( family == "syncContact" ) { 247 if ( family == "syncContact" ) {
247 qDebug("creating sync config "); 248 qDebug("creating sync config ");
248 fami = "contact"; 249 fami = "contact";
249 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); 250 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") );
250 con->setGroup( "General" ); 251 con->setGroup( "General" );
251 con->writeEntry( "ResourceKeys", QString("sync") ); 252 con->writeEntry( "ResourceKeys", QString("sync") );
252 con->writeEntry( "Standard", QString("sync") ); 253 con->writeEntry( "Standard", QString("sync") );
253 con->setGroup( "Resource_sync" ); 254 con->setGroup( "Resource_sync" );
254 con->writeEntry( "FileName", config ); 255 con->writeEntry( "FileName", config );
255 con->writeEntry( "FileFormat", QString("vcard") ); 256 con->writeEntry( "FileFormat", QString("vcard") );
256 con->writeEntry( "ResourceIdentifier", QString("sync") ); 257 con->writeEntry( "ResourceIdentifier", QString("sync") );
257 con->writeEntry( "ResourceName", QString("sync_res") ); 258 con->writeEntry( "ResourceName", QString("sync_res") );
258 if ( config.right(4) == ".xml" ) 259 if ( config.right(4) == ".xml" )
259 con->writeEntry( "ResourceType", QString("qtopia") ); 260 con->writeEntry( "ResourceType", QString("qtopia") );
260 else if ( config == "sharp" ) { 261 else if ( config == "sharp" ) {
261 con->writeEntry( "ResourceType", QString("sharp") ); 262 con->writeEntry( "ResourceType", QString("sharp") );
262 } else { 263 } else {
263 con->writeEntry( "ResourceType", QString("file") ); 264 con->writeEntry( "ResourceType", QString("file") );
264 } 265 }
265 //con->sync(); 266 //con->sync();
266 d->mConfig = con; 267 d->mConfig = con;
267 } 268 }
268 else 269 else
269 d->mConfig = new KConfig( locateLocal("config", config) ); 270 d->mConfig = new KConfig( locateLocal("config", config) );
270// qDebug("AddressBook::init 1 config=%s",config.latin1() ); 271// qDebug("AddressBook::init 1 config=%s",config.latin1() );
271 } 272 }
272 else { 273 else {
273 d->mConfig = 0; 274 d->mConfig = 0;
274// qDebug("AddressBook::init 1 config=0"); 275// qDebug("AddressBook::init 1 config=0");
275 } 276 }
276 277
277//US d->mErrorHandler = 0; 278//US d->mErrorHandler = 0;
278 d->mManager = new KRES::Manager<Resource>( fami, false ); 279 d->mManager = new KRES::Manager<Resource>( fami, false );
279 d->mManager->readConfig( d->mConfig ); 280 d->mManager->readConfig( d->mConfig );
280 if ( family == "syncContact" ) { 281 if ( family == "syncContact" ) {
281 KRES::Manager<Resource> *manager = d->mManager; 282 KRES::Manager<Resource> *manager = d->mManager;
282 KRES::Manager<Resource>::ActiveIterator it; 283 KRES::Manager<Resource>::ActiveIterator it;
283 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 284 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
284 (*it)->setAddressBook( this ); 285 (*it)->setAddressBook( this );
285 if ( !(*it)->open() ) 286 if ( !(*it)->open() )
286 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 287 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
287 } 288 }
288 Resource *res = standardResource(); 289 Resource *res = standardResource();
289 if ( !res ) { 290 if ( !res ) {
290 qDebug("ERROR: no standard resource"); 291 qDebug("ERROR: no standard resource");
291 res = manager->createResource( "file" ); 292 res = manager->createResource( "file" );
292 if ( res ) 293 if ( res )
293 { 294 {
294 addResource( res ); 295 addResource( res );
295 } 296 }
296 else 297 else
297 qDebug(" No resource available!!!"); 298 qDebug(" No resource available!!!");
298 } 299 }
299 setStandardResource( res ); 300 setStandardResource( res );
300 manager->writeConfig(); 301 manager->writeConfig();
301 } 302 }
302 addCustomField( i18n( "Department" ), KABC::Field::Organization, 303 addCustomField( i18n( "Department" ), KABC::Field::Organization,
303 "X-Department", "KADDRESSBOOK" ); 304 "X-Department", "KADDRESSBOOK" );
304 addCustomField( i18n( "Profession" ), KABC::Field::Organization, 305 addCustomField( i18n( "Profession" ), KABC::Field::Organization,
305 "X-Profession", "KADDRESSBOOK" ); 306 "X-Profession", "KADDRESSBOOK" );
306 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, 307 addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization,
307 "X-AssistantsName", "KADDRESSBOOK" ); 308 "X-AssistantsName", "KADDRESSBOOK" );
308 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, 309 addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization,
309 "X-ManagersName", "KADDRESSBOOK" ); 310 "X-ManagersName", "KADDRESSBOOK" );
310 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, 311 addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal,
311 "X-SpousesName", "KADDRESSBOOK" ); 312 "X-SpousesName", "KADDRESSBOOK" );
312 addCustomField( i18n( "Office" ), KABC::Field::Personal, 313 addCustomField( i18n( "Office" ), KABC::Field::Personal,
313 "X-Office", "KADDRESSBOOK" ); 314 "X-Office", "KADDRESSBOOK" );
314 addCustomField( i18n( "IM Address" ), KABC::Field::Personal, 315 addCustomField( i18n( "IM Address" ), KABC::Field::Personal,
315 "X-IMAddress", "KADDRESSBOOK" ); 316 "X-IMAddress", "KADDRESSBOOK" );
316 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, 317 addCustomField( i18n( "Anniversary" ), KABC::Field::Personal,
317 "X-Anniversary", "KADDRESSBOOK" ); 318 "X-Anniversary", "KADDRESSBOOK" );
318 319
319 //US added this field to become compatible with Opie/qtopia addressbook 320 //US added this field to become compatible with Opie/qtopia addressbook
320 // values can be "female" or "male" or "". An empty field represents undefined. 321 // values can be "female" or "male" or "". An empty field represents undefined.
321 addCustomField( i18n( "Gender" ), KABC::Field::Personal, 322 addCustomField( i18n( "Gender" ), KABC::Field::Personal,
322 "X-Gender", "KADDRESSBOOK" ); 323 "X-Gender", "KADDRESSBOOK" );
323 addCustomField( i18n( "Children" ), KABC::Field::Personal, 324 addCustomField( i18n( "Children" ), KABC::Field::Personal,
324 "X-Children", "KADDRESSBOOK" ); 325 "X-Children", "KADDRESSBOOK" );
325 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, 326 addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal,
326 "X-FreeBusyUrl", "KADDRESSBOOK" ); 327 "X-FreeBusyUrl", "KADDRESSBOOK" );
327 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, 328 addCustomField( i18n( "ExternalID" ), KABC::Field::Personal,
328 "X-ExternalID", "KADDRESSBOOK" ); 329 "X-ExternalID", "KADDRESSBOOK" );
329} 330}
330 331
331AddressBook::~AddressBook() 332AddressBook::~AddressBook()
332{ 333{
333 delete d->mConfig; d->mConfig = 0; 334 delete d->mConfig; d->mConfig = 0;
334 delete d->mManager; d->mManager = 0; 335 delete d->mManager; d->mManager = 0;
335//US delete d->mErrorHandler; d->mErrorHandler = 0; 336//US delete d->mErrorHandler; d->mErrorHandler = 0;
336 delete d; d = 0; 337 delete d; d = 0;
337} 338}
338 339
339bool AddressBook::load() 340bool AddressBook::load()
340{ 341{
341 342
342 343
343 clear(); 344 clear();
344 345
345 KRES::Manager<Resource>::ActiveIterator it; 346 KRES::Manager<Resource>::ActiveIterator it;
346 bool ok = true; 347 bool ok = true;
347 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) 348 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
348 if ( !(*it)->load() ) { 349 if ( !(*it)->load() ) {
349 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); 350 error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
350 ok = false; 351 ok = false;
351 } 352 }
352 353
353 // mark all addressees as unchanged 354 // mark all addressees as unchanged
354 Addressee::List::Iterator addrIt; 355 Addressee::List::Iterator addrIt;
355 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { 356 for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) {
356 (*addrIt).setChanged( false ); 357 (*addrIt).setChanged( false );
357 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); 358 QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" );
358 if ( !id.isEmpty() ) { 359 if ( !id.isEmpty() ) {
359 //qDebug("setId aa %s ", id.latin1()); 360 //qDebug("setId aa %s ", id.latin1());
360 (*addrIt).setIDStr(id ); 361 (*addrIt).setIDStr(id );
361 } 362 }
362 } 363 }
363 blockLSEchange = true; 364 blockLSEchange = true;
364 return ok; 365 return ok;
365} 366}
366 367
367bool AddressBook::save( Ticket *ticket ) 368bool AddressBook::save( Ticket *ticket )
368{ 369{
369 kdDebug(5700) << "AddressBook::save()"<< endl; 370 kdDebug(5700) << "AddressBook::save()"<< endl;
370 371
371 if ( ticket->resource() ) { 372 if ( ticket->resource() ) {
372 deleteRemovedAddressees(); 373 deleteRemovedAddressees();
373 return ticket->resource()->save( ticket ); 374 return ticket->resource()->save( ticket );
374 } 375 }
375 376
376 return false; 377 return false;
377} 378}
378void AddressBook::export2File( QString fileName ) 379void AddressBook::export2File( QString fileName )
379{ 380{
380 381
381 QFile outFile( fileName ); 382 QFile outFile( fileName );
382 if ( !outFile.open( IO_WriteOnly ) ) { 383 if ( !outFile.open( IO_WriteOnly ) ) {
383 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); 384 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" );
384 KMessageBox::error( 0, text.arg( fileName ) ); 385 KMessageBox::error( 0, text.arg( fileName ) );
385 return ; 386 return ;
386 } 387 }
387 QTextStream t( &outFile ); 388 QTextStream t( &outFile );
388 t.setEncoding( QTextStream::UnicodeUTF8 ); 389 t.setEncoding( QTextStream::UnicodeUTF8 );
389 Iterator it; 390 Iterator it;
390 KABC::VCardConverter::Version version; 391 KABC::VCardConverter::Version version;
391 version = KABC::VCardConverter::v3_0; 392 version = KABC::VCardConverter::v3_0;
392 for ( it = begin(); it != end(); ++it ) { 393 for ( it = begin(); it != end(); ++it ) {
393 if ( !(*it).IDStr().isEmpty() ) { 394 if ( !(*it).IDStr().isEmpty() ) {
394 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); 395 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() );
395 } 396 }
396 KABC::VCardConverter converter; 397 KABC::VCardConverter converter;
397 QString vcard; 398 QString vcard;
398 //Resource *resource() const; 399 //Resource *resource() const;
399 converter.addresseeToVCard( *it, vcard, version ); 400 converter.addresseeToVCard( *it, vcard, version );
400 t << vcard << "\r\n"; 401 t << vcard << "\r\n";
401 } 402 }
402 t << "\r\n\r\n"; 403 t << "\r\n\r\n";
403 outFile.close(); 404 outFile.close();
404} 405}
405void AddressBook::importFromFile( QString fileName, bool replaceLabel ) 406void AddressBook::importFromFile( QString fileName, bool replaceLabel )
406{ 407{
407 408
408 KABC::Addressee::List list; 409 KABC::Addressee::List list;
409 QFile file( fileName ); 410 QFile file( fileName );
410 411
411 file.open( IO_ReadOnly ); 412 file.open( IO_ReadOnly );
412 QByteArray rawData = file.readAll(); 413 QByteArray rawData = file.readAll();
413 file.close(); 414 file.close();
414 QString data; 415 QString data;
415 if ( replaceLabel ) { 416 if ( replaceLabel ) {
416 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); 417 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 );
417 data.replace ( QRegExp("LABEL") , "ADR" ); 418 data.replace ( QRegExp("LABEL") , "ADR" );
418 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); 419 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" );
419 } else 420 } else
420 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 421 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
421 KABC::VCardTool tool; 422 KABC::VCardTool tool;
422 list = tool.parseVCards( data ); 423 list = tool.parseVCards( data );
423 KABC::Addressee::List::Iterator it; 424 KABC::Addressee::List::Iterator it;
424 for ( it = list.begin(); it != list.end(); ++it ) { 425 for ( it = list.begin(); it != list.end(); ++it ) {
425 (*it).setResource( 0 ); 426 (*it).setResource( 0 );
426 if ( replaceLabel ) 427 if ( replaceLabel )