summaryrefslogtreecommitdiffabout
path: root/kabc
Unidiff
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp16
-rw-r--r--kabc/addressbook.h2
-rw-r--r--kabc/addressee.cpp17
-rw-r--r--kabc/addressee.h1
4 files changed, 31 insertions, 5 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index dc3cda1..bf6d053 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -381,64 +381,72 @@ void AddressBook::export2File( QString fileName )
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." )
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 3603ec1..cea1b03 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -122,49 +122,49 @@ class AddressBook : public QObject
122 /** 122 /**
123 Requests a ticket for saving the addressbook. Calling this function locks 123 Requests a ticket for saving the addressbook. Calling this function locks
124 the addressbook for all other processes. If the address book is already 124 the addressbook for all other processes. If the address book is already
125 locked the function returns 0. You need the returned @ref Ticket object 125 locked the function returns 0. You need the returned @ref Ticket object
126 for calling the @ref save() function. 126 for calling the @ref save() function.
127 127
128 @see save() 128 @see save()
129 */ 129 */
130 Ticket *requestSaveTicket( Resource *resource=0 ); 130 Ticket *requestSaveTicket( Resource *resource=0 );
131 131
132 /** 132 /**
133 Load address book from file. 133 Load address book from file.
134 */ 134 */
135 bool load(); 135 bool load();
136 136
137 /** 137 /**
138 Save address book. The address book is saved to the file, the Ticket 138 Save address book. The address book is saved to the file, the Ticket
139 object has been requested for by @ref requestSaveTicket(). 139 object has been requested for by @ref requestSaveTicket().
140 140
141 @param ticket a ticket object returned by @ref requestSaveTicket() 141 @param ticket a ticket object returned by @ref requestSaveTicket()
142 */ 142 */
143 bool save( Ticket *ticket ); 143 bool save( Ticket *ticket );
144 bool saveAB( ); 144 bool saveAB( );
145 void export2File( QString fileName ); 145 void export2File( QString fileName );
146 void importFromFile( QString fileName ); 146 void importFromFile( QString fileName, bool replaceLabel = false );
147 /** 147 /**
148 Returns a iterator for first entry of address book. 148 Returns a iterator for first entry of address book.
149 */ 149 */
150 Iterator begin(); 150 Iterator begin();
151 151
152 /** 152 /**
153 Returns a const iterator for first entry of address book. 153 Returns a const iterator for first entry of address book.
154 */ 154 */
155 ConstIterator begin() const; 155 ConstIterator begin() const;
156 156
157 /** 157 /**
158 Returns a iterator for first entry of address book. 158 Returns a iterator for first entry of address book.
159 */ 159 */
160 Iterator end(); 160 Iterator end();
161 161
162 /** 162 /**
163 Returns a const iterator for first entry of address book. 163 Returns a const iterator for first entry of address book.
164 */ 164 */
165 ConstIterator end() const; 165 ConstIterator end() const;
166 166
167 /** 167 /**
168 Removes all entries from address book. 168 Removes all entries from address book.
169 */ 169 */
170 void clear(); 170 void clear();
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 19a1845..3f3d5c0 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -294,48 +294,65 @@ void Addressee::mergeContact( const Addressee& ad )
294 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; 294 if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer;
295 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; 295 if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone;
296 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; 296 if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo;
297 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; 297 if ( mData->title .isEmpty() ) mData->title = ad.mData->title ;
298 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; 298 if ( mData->role.isEmpty() ) mData->role = ad.mData->role ;
299 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; 299 if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ;
300 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; 300 if ( mData->note.isEmpty() ) mData->note = ad.mData->note ;
301 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; 301 if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId;
302 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; 302 if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString;
303 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; 303 if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy;
304 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; 304 if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ;
305 305
306 // pending: 306 // pending:
307 // merging phonenumbers 307 // merging phonenumbers
308 // merging addresses 308 // merging addresses
309 // merging emails; 309 // merging emails;
310 // merging categories; 310 // merging categories;
311 // merging custom; 311 // merging custom;
312 // merging keys 312 // merging keys
313 qDebug("merge contact %s ", ad.uid().latin1()); 313 qDebug("merge contact %s ", ad.uid().latin1());
314 setUid( ad.uid() ); 314 setUid( ad.uid() );
315 setRevision( ad.revision() ); 315 setRevision( ad.revision() );
316} 316}
317 317
318bool Addressee::removeVoice()
319{
320 PhoneNumber::List phoneN = phoneNumbers();
321 PhoneNumber::List::Iterator phoneIt;
322 bool found = false;
323 for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
324 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found
325 if ((*phoneIt).type() - PhoneNumber::Voice ) {
326 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice );
327 insertPhoneNumber( (*phoneIt) );
328 found = true;
329 }
330 }
331
332 }
333 return found;
334}
318void Addressee::simplifyAddresses() 335void Addressee::simplifyAddresses()
319{ 336{
320 if ( mData->addresses.count() < 3 ) return ; 337 if ( mData->addresses.count() < 3 ) return ;
321 int count = 0; 338 int count = 0;
322 Address::List list; 339 Address::List list;
323 Address::List::Iterator it; 340 Address::List::Iterator it;
324 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { 341 for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
325 if ( count > 1 ) 342 if ( count > 1 )
326 list.append( *it ); 343 list.append( *it );
327 ++count; 344 ++count;
328 } 345 }
329 for( it = list.begin(); it != list.end(); ++it ) { 346 for( it = list.begin(); it != list.end(); ++it ) {
330 removeAddress( (*it) ); 347 removeAddress( (*it) );
331 } 348 }
332} 349}
333 350
334// removes all emails but the first 351// removes all emails but the first
335// needed by phone sync 352// needed by phone sync
336void Addressee::simplifyEmails() 353void Addressee::simplifyEmails()
337{ 354{
338 if ( mData->emails.count() == 0 ) return ; 355 if ( mData->emails.count() == 0 ) return ;
339 QString email = mData->emails.first(); 356 QString email = mData->emails.first();
340 detach(); 357 detach();
341 mData->emails.clear(); 358 mData->emails.clear();
diff --git a/kabc/addressee.h b/kabc/addressee.h
index 44f0629..9336edc 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -100,48 +100,49 @@ class Addressee
100 void setTempSyncStat(int id); 100 void setTempSyncStat(int id);
101 int tempSyncStat() const; 101 int tempSyncStat() const;
102 void setIDStr( const QString & ); 102 void setIDStr( const QString & );
103 QString IDStr() const; 103 QString IDStr() const;
104 void setID( const QString &, const QString & ); 104 void setID( const QString &, const QString & );
105 QString getID( const QString & ); 105 QString getID( const QString & );
106 void setCsum( const QString &, const QString & ); 106 void setCsum( const QString &, const QString & );
107 QString getCsum( const QString & ); 107 QString getCsum( const QString & );
108 void removeID(const QString &); 108 void removeID(const QString &);
109 void computeCsum(const QString &dev); 109 void computeCsum(const QString &dev);
110 ulong getCsum4List( const QStringList & attList); 110 ulong getCsum4List( const QStringList & attList);
111 /** 111 /**
112 Return, if the address book entry is empty. 112 Return, if the address book entry is empty.
113 */ 113 */
114 bool isEmpty() const; 114 bool isEmpty() const;
115 void setExternalUID( const QString &id ); 115 void setExternalUID( const QString &id );
116 QString externalUID() const; 116 QString externalUID() const;
117 void setOriginalExternalUID( const QString &id ); 117 void setOriginalExternalUID( const QString &id );
118 QString originalExternalUID() const; 118 QString originalExternalUID() const;
119 void mergeContact( const Addressee& ad ); 119 void mergeContact( const Addressee& ad );
120 void simplifyEmails(); 120 void simplifyEmails();
121 void simplifyAddresses(); 121 void simplifyAddresses();
122 void simplifyPhoneNumbers(); 122 void simplifyPhoneNumbers();
123 void simplifyPhoneNumberTypes(); 123 void simplifyPhoneNumberTypes();
124 bool removeVoice();
124 125
125 /** 126 /**
126 Set unique identifier. 127 Set unique identifier.
127 */ 128 */
128 void setUid( const QString &uid ); 129 void setUid( const QString &uid );
129 /** 130 /**
130 Return unique identifier. 131 Return unique identifier.
131 */ 132 */
132 QString uid() const; 133 QString uid() const;
133 /** 134 /**
134 Return translated label for uid field. 135 Return translated label for uid field.
135 */ 136 */
136 static QString uidLabel(); 137 static QString uidLabel();
137 138
138 /** 139 /**
139 Set name. 140 Set name.
140 */ 141 */
141 void setName( const QString &name ); 142 void setName( const QString &name );
142 /** 143 /**
143 Return name. 144 Return name.
144 */ 145 */
145 QString name() const; 146 QString name() const;
146 /** 147 /**
147 Return translated label for name field. 148 Return translated label for name field.