author | zautrix <zautrix> | 2004-10-08 20:03:23 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-08 20:03:23 (UTC) |
commit | 10a0e05cc4962d9412a7a5faf3d69a3caf6d1c34 (patch) (unidiff) | |
tree | 3105b985a9dbedd31dff52e14fe667eeff4f9ff4 | |
parent | 13bd085e06b76228321f5a004759fcdf19cca711 (diff) | |
download | kdepimpi-10a0e05cc4962d9412a7a5faf3d69a3caf6d1c34.zip kdepimpi-10a0e05cc4962d9412a7a5faf3d69a3caf6d1c34.tar.gz kdepimpi-10a0e05cc4962d9412a7a5faf3d69a3caf6d1c34.tar.bz2 |
added contact phone support
-rw-r--r-- | kabc/addressee.cpp | 32 | ||||
-rw-r--r-- | kabc/addressee.h | 4 | ||||
-rw-r--r-- | kabc/phonenumber.cpp | 23 | ||||
-rw-r--r-- | kabc/phonenumber.h | 2 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 23 |
5 files changed, 80 insertions, 4 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 25c77f6..e571980 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp | |||
@@ -315,6 +315,38 @@ void Addressee::mergeContact( const Addressee& ad ) | |||
315 | setRevision( ad.revision() ); | 315 | setRevision( ad.revision() ); |
316 | } | 316 | } |
317 | 317 | ||
318 | // removes all emails but the first | ||
319 | // needed by phone sync | ||
320 | void Addressee::simplifyEmails() | ||
321 | { | ||
322 | if ( mData->emails.count() == 0 ) return ; | ||
323 | QString email = mData->emails.first(); | ||
324 | detach(); | ||
325 | mData->emails.clear(); | ||
326 | mData->emails.append( email ); | ||
327 | } | ||
328 | |||
329 | void Addressee::simplifyPhoneNumbers() | ||
330 | { | ||
331 | KABC::PhoneNumber::List removeNumbers; | ||
332 | KABC::PhoneNumber::List::Iterator phoneIter; | ||
333 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | ||
334 | ++phoneIter ) { | ||
335 | if ( ! ( *phoneIter ).simplifyNumber() ) | ||
336 | removeNumbers.append( ( *phoneIter ) ); | ||
337 | } | ||
338 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | ||
339 | ++phoneIter ) { | ||
340 | removePhoneNumber(( *phoneIter )); | ||
341 | } | ||
342 | } | ||
343 | void Addressee::simplifyPhoneNumberTypes() | ||
344 | { | ||
345 | KABC::PhoneNumber::List::Iterator phoneIter; | ||
346 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | ||
347 | ++phoneIter ) | ||
348 | ( *phoneIter ).simplifyType(); | ||
349 | } | ||
318 | void Addressee::removeID(const QString &prof) | 350 | void Addressee::removeID(const QString &prof) |
319 | { | 351 | { |
320 | detach(); | 352 | detach(); |
diff --git a/kabc/addressee.h b/kabc/addressee.h index 8baa888..4cafa86 100644 --- a/kabc/addressee.h +++ b/kabc/addressee.h | |||
@@ -117,6 +117,10 @@ class Addressee | |||
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(); | ||
121 | void simplifyPhoneNumbers(); | ||
122 | void simplifyPhoneNumberTypes(); | ||
123 | |||
120 | /** | 124 | /** |
121 | Set unique identifier. | 125 | Set unique identifier. |
122 | */ | 126 | */ |
diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp index 7aeb2ee..e5abc0e 100644 --- a/kabc/phonenumber.cpp +++ b/kabc/phonenumber.cpp | |||
@@ -66,6 +66,29 @@ bool PhoneNumber::operator!=( const PhoneNumber &p ) const | |||
66 | return !( p == *this ); | 66 | return !( p == *this ); |
67 | } | 67 | } |
68 | 68 | ||
69 | bool PhoneNumber::simplifyNumber() | ||
70 | { | ||
71 | QString Number; | ||
72 | int i; | ||
73 | Number = mNumber.stripWhiteSpace (); | ||
74 | mNumber = ""; | ||
75 | if ( Number.at(0) == '+' ) | ||
76 | mNumber += "+"; | ||
77 | for ( i = 0; i < Number.length(); ++i) { | ||
78 | if ( Number.at(i).isDigit() ) | ||
79 | mNumber += Number.at(i); | ||
80 | } | ||
81 | return ( mNumber.length() > 0 ); | ||
82 | } | ||
83 | // make cellphone compatible | ||
84 | void PhoneNumber::simplifyType() | ||
85 | { | ||
86 | if ( mType & Fax ) mType = Fax; | ||
87 | else if ( mType & Cell ) mType = Cell; | ||
88 | else if ( mType & Work ) mType = Work ; | ||
89 | else if ( mType & Home ) mType = Home; | ||
90 | else mType = Pref; | ||
91 | } | ||
69 | void PhoneNumber::setId( const QString &id ) | 92 | void PhoneNumber::setId( const QString &id ) |
70 | { | 93 | { |
71 | mId = id; | 94 | mId = id; |
diff --git a/kabc/phonenumber.h b/kabc/phonenumber.h index 1df344f..410a52f 100644 --- a/kabc/phonenumber.h +++ b/kabc/phonenumber.h | |||
@@ -148,6 +148,8 @@ class PhoneNumber | |||
148 | @obsolete | 148 | @obsolete |
149 | */ | 149 | */ |
150 | static QString label( int type ); | 150 | static QString label( int type ); |
151 | bool simplifyNumber(); | ||
152 | void simplifyType(); | ||
151 | 153 | ||
152 | private: | 154 | private: |
153 | void init(); | 155 | void init(); |
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index c5406bf..939296f 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -699,11 +699,14 @@ void KABCore::export2phone() | |||
699 | 699 | ||
700 | if ( a.isEmpty() ) | 700 | if ( a.isEmpty() ) |
701 | continue; | 701 | continue; |
702 | a.simplifyEmails(); | ||
703 | a.simplifyPhoneNumbers(); | ||
704 | a.simplifyPhoneNumberTypes(); | ||
702 | 705 | ||
703 | if (description.isEmpty()) | 706 | if (description.isEmpty()) |
704 | description = a.formattedName(); | 707 | description = a.formattedName(); |
705 | |||
706 | QString vcard; | 708 | QString vcard; |
709 | QString vcardnew; | ||
707 | converter.addresseeToVCard( a, vcard ); | 710 | converter.addresseeToVCard( a, vcard ); |
708 | int start = 0; | 711 | int start = 0; |
709 | int next; | 712 | int next; |
@@ -715,11 +718,23 @@ void KABCore::export2phone() | |||
715 | sep = semi ; | 718 | sep = semi ; |
716 | else | 719 | else |
717 | sep = dopp; | 720 | sep = dopp; |
718 | datastream +=vcard.mid( start, next - start); | 721 | vcardnew +=vcard.mid( start, next - start); |
719 | datastream +=vcard.mid( next+5,sep -next -5 ).upper(); | 722 | vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); |
720 | start = sep; | 723 | start = sep; |
721 | } | 724 | } |
722 | datastream += vcard.mid( start,vcard.length() ); | 725 | vcardnew += vcard.mid( start,vcard.length() ); |
726 | vcard = ""; | ||
727 | start = 0; | ||
728 | while ( (next = vcardnew.find("ADR", start) )>= 0 ) { | ||
729 | int sep = vcardnew.find(":", next); | ||
730 | vcard +=vcardnew.mid( start, next - start+3); | ||
731 | start = sep; | ||
732 | } | ||
733 | vcard += vcardnew.mid( start,vcardnew.length() ); | ||
734 | vcard.replace ( QRegExp(";;;") , "" ); | ||
735 | vcard.replace ( QRegExp(";;") , "" ); | ||
736 | datastream += vcard; | ||
737 | |||
723 | } | 738 | } |
724 | QFile outFile(fileName); | 739 | QFile outFile(fileName); |
725 | if ( outFile.open(IO_WriteOnly) ) { | 740 | if ( outFile.open(IO_WriteOnly) ) { |