summaryrefslogtreecommitdiffabout
path: root/kabc
Side-by-side diff
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
@@ -393,40 +393,48 @@ void AddressBook::export2File( QString fileName )
if ( !(*it).IDStr().isEmpty() ) {
(*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() );
}
KABC::VCardConverter converter;
QString vcard;
//Resource *resource() const;
converter.addresseeToVCard( *it, vcard, version );
t << vcard << "\r\n";
}
t << "\r\n\r\n";
outFile.close();
}
-void AddressBook::importFromFile( QString fileName )
+void AddressBook::importFromFile( QString fileName, bool replaceLabel )
{
- KABC::Addressee::List list;
+ KABC::Addressee::List list;
QFile file( fileName );
file.open( IO_ReadOnly );
QByteArray rawData = file.readAll();
file.close();
-
- QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
+ qDebug("AddressBook::importFromFile ");
+ QString data;
+ if ( replaceLabel ) {
+ data = QString::fromLatin1( rawData.data(), rawData.size() + 1 );
+ data.replace ( QRegExp("LABEL") , "ADR" );
+ data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" );
+ } else
+ data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
KABC::VCardTool tool;
list = tool.parseVCards( data );
KABC::Addressee::List::Iterator it;
for ( it = list.begin(); it != list.end(); ++it ) {
(*it).setResource( 0 );
+ if ( replaceLabel )
+ (*it).removeVoice();
insertAddressee( (*it), false, true );
}
}
bool AddressBook::saveAB()
{
bool ok = true;
deleteRemovedAddressees();
Iterator ait;
for ( ait = begin(); ait != end(); ++ait ) {
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 3603ec1..cea1b03 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -134,25 +134,25 @@ class AddressBook : public QObject
*/
bool load();
/**
Save address book. The address book is saved to the file, the Ticket
object has been requested for by @ref requestSaveTicket().
@param ticket a ticket object returned by @ref requestSaveTicket()
*/
bool save( Ticket *ticket );
bool saveAB( );
void export2File( QString fileName );
- void importFromFile( QString fileName );
+ void importFromFile( QString fileName, bool replaceLabel = false );
/**
Returns a iterator for first entry of address book.
*/
Iterator begin();
/**
Returns a const iterator for first entry of address book.
*/
ConstIterator begin() const;
/**
Returns a iterator for first entry of address book.
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 19a1845..3f3d5c0 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -306,24 +306,41 @@ void Addressee::mergeContact( const Addressee& ad )
// pending:
// merging phonenumbers
// merging addresses
// merging emails;
// merging categories;
// merging custom;
// merging keys
qDebug("merge contact %s ", ad.uid().latin1());
setUid( ad.uid() );
setRevision( ad.revision() );
}
+bool Addressee::removeVoice()
+{
+ PhoneNumber::List phoneN = phoneNumbers();
+ PhoneNumber::List::Iterator phoneIt;
+ bool found = false;
+ for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) {
+ if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found
+ if ((*phoneIt).type() - PhoneNumber::Voice ) {
+ (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice );
+ insertPhoneNumber( (*phoneIt) );
+ found = true;
+ }
+ }
+
+ }
+ return found;
+}
void Addressee::simplifyAddresses()
{
if ( mData->addresses.count() < 3 ) return ;
int count = 0;
Address::List list;
Address::List::Iterator it;
for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
if ( count > 1 )
list.append( *it );
++count;
}
for( it = list.begin(); it != list.end(); ++it ) {
diff --git a/kabc/addressee.h b/kabc/addressee.h
index 44f0629..9336edc 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -112,24 +112,25 @@ class Addressee
Return, if the address book entry is empty.
*/
bool isEmpty() const;
void setExternalUID( const QString &id );
QString externalUID() const;
void setOriginalExternalUID( const QString &id );
QString originalExternalUID() const;
void mergeContact( const Addressee& ad );
void simplifyEmails();
void simplifyAddresses();
void simplifyPhoneNumbers();
void simplifyPhoneNumberTypes();
+ bool removeVoice();
/**
Set unique identifier.
*/
void setUid( const QString &uid );
/**
Return unique identifier.
*/
QString uid() const;
/**
Return translated label for uid field.
*/