summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressee.cpp32
-rw-r--r--kabc/addressee.h4
-rw-r--r--kabc/phonenumber.cpp23
-rw-r--r--kabc/phonenumber.h2
-rw-r--r--kaddressbook/kabcore.cpp23
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
@@ -294,48 +294,80 @@ 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
318// removes all emails but the first
319// needed by phone sync
320void 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
329void 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}
343void 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}
318void Addressee::removeID(const QString &prof) 350void Addressee::removeID(const QString &prof)
319{ 351{
320 detach(); 352 detach();
321 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); 353 mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
322 354
323} 355}
324void Addressee::setID( const QString & prof , const QString & id ) 356void Addressee::setID( const QString & prof , const QString & id )
325{ 357{
326 detach(); 358 detach();
327 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); 359 mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
328 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); 360 //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
329} 361}
330void Addressee::setTempSyncStat( int id ) 362void Addressee::setTempSyncStat( int id )
331{ 363{
332 if ( mData->mTempSyncStat == id ) return; 364 if ( mData->mTempSyncStat == id ) return;
333 detach(); 365 detach();
334 mData->mTempSyncStat = id; 366 mData->mTempSyncStat = id;
335} 367}
336int Addressee::tempSyncStat() const 368int Addressee::tempSyncStat() const
337{ 369{
338 return mData->mTempSyncStat; 370 return mData->mTempSyncStat;
339} 371}
340 372
341QString Addressee::getID( const QString & prof) 373QString Addressee::getID( const QString & prof)
diff --git a/kabc/addressee.h b/kabc/addressee.h
index 8baa888..4cafa86 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -96,48 +96,52 @@ class Addressee
96 96
97 bool operator==( const Addressee & ) const; 97 bool operator==( const Addressee & ) const;
98 bool operator!=( const Addressee & ) const; 98 bool operator!=( const Addressee & ) const;
99 // sync stuff 99 // sync stuff
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();
121 void simplifyPhoneNumbers();
122 void simplifyPhoneNumberTypes();
123
120 /** 124 /**
121 Set unique identifier. 125 Set unique identifier.
122 */ 126 */
123 void setUid( const QString &uid ); 127 void setUid( const QString &uid );
124 /** 128 /**
125 Return unique identifier. 129 Return unique identifier.
126 */ 130 */
127 QString uid() const; 131 QString uid() const;
128 /** 132 /**
129 Return translated label for uid field. 133 Return translated label for uid field.
130 */ 134 */
131 static QString uidLabel(); 135 static QString uidLabel();
132 136
133 /** 137 /**
134 Set name. 138 Set name.
135 */ 139 */
136 void setName( const QString &name ); 140 void setName( const QString &name );
137 /** 141 /**
138 Return name. 142 Return name.
139 */ 143 */
140 QString name() const; 144 QString name() const;
141 /** 145 /**
142 Return translated label for name field. 146 Return translated label for name field.
143 */ 147 */
diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp
index 7aeb2ee..e5abc0e 100644
--- a/kabc/phonenumber.cpp
+++ b/kabc/phonenumber.cpp
@@ -45,48 +45,71 @@ PhoneNumber::PhoneNumber( const QString &number, int type ) :
45} 45}
46 46
47PhoneNumber::~PhoneNumber() 47PhoneNumber::~PhoneNumber()
48{ 48{
49} 49}
50 50
51void PhoneNumber::init() 51void PhoneNumber::init()
52{ 52{
53 mId = KApplication::randomString( 8 ); 53 mId = KApplication::randomString( 8 );
54} 54}
55 55
56bool PhoneNumber::operator==( const PhoneNumber &p ) const 56bool PhoneNumber::operator==( const PhoneNumber &p ) const
57{ 57{
58 if ( mNumber != p.mNumber ) return false; 58 if ( mNumber != p.mNumber ) return false;
59 if ( mType != p.mType ) return false; 59 if ( mType != p.mType ) return false;
60 60
61 return true; 61 return true;
62} 62}
63 63
64bool PhoneNumber::operator!=( const PhoneNumber &p ) const 64bool PhoneNumber::operator!=( const PhoneNumber &p ) const
65{ 65{
66 return !( p == *this ); 66 return !( p == *this );
67} 67}
68 68
69bool 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
84void 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}
69void PhoneNumber::setId( const QString &id ) 92void PhoneNumber::setId( const QString &id )
70{ 93{
71 mId = id; 94 mId = id;
72} 95}
73 96
74QString PhoneNumber::id() const 97QString PhoneNumber::id() const
75{ 98{
76 return mId; 99 return mId;
77} 100}
78 101
79void PhoneNumber::setNumber( const QString &number ) 102void PhoneNumber::setNumber( const QString &number )
80{ 103{
81 mNumber = number; 104 mNumber = number;
82} 105}
83 106
84QString PhoneNumber::number() const 107QString PhoneNumber::number() const
85{ 108{
86 return mNumber; 109 return mNumber;
87} 110}
88 111
89void PhoneNumber::setType( int type ) 112void PhoneNumber::setType( int type )
90{ 113{
91 mType = type; 114 mType = type;
92} 115}
diff --git a/kabc/phonenumber.h b/kabc/phonenumber.h
index 1df344f..410a52f 100644
--- a/kabc/phonenumber.h
+++ b/kabc/phonenumber.h
@@ -127,40 +127,42 @@ class PhoneNumber
127 Returns a translated string of all types the address has. 127 Returns a translated string of all types the address has.
128 */ 128 */
129 QString typeLabel() const; 129 QString typeLabel() const;
130 130
131 /** 131 /**
132 Returns the translated label for phone number depending on its type. 132 Returns the translated label for phone number depending on its type.
133 */ 133 */
134 QString label() const; 134 QString label() const;
135 135
136 /** 136 /**
137 Returns a list of all available types 137 Returns a list of all available types
138 */ 138 */
139 static TypeList typeList(); 139 static TypeList typeList();
140 140
141 /** 141 /**
142 Returns the translated label for phone number type. 142 Returns the translated label for phone number type.
143 */ 143 */
144 static QString typeLabel( int type ); 144 static QString typeLabel( int type );
145 145
146 /** 146 /**
147 Returns the translated label for phone number type. 147 Returns the translated label for phone number type.
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();
154 156
155 QString mId; 157 QString mId;
156 158
157 int mType; 159 int mType;
158 QString mNumber; 160 QString mNumber;
159}; 161};
160 162
161QDataStream &operator<<( QDataStream &, const PhoneNumber & ); 163QDataStream &operator<<( QDataStream &, const PhoneNumber & );
162QDataStream &operator>>( QDataStream &, PhoneNumber & ); 164QDataStream &operator>>( QDataStream &, PhoneNumber & );
163 165
164} 166}
165 167
166#endif 168#endif
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index c5406bf..939296f 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -678,69 +678,84 @@ void KABCore::export2phone()
678 678
679 679
680 PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice, 680 PhoneAccess::writeConfig( KPimGlobalPrefs::instance()->mEx2PhoneDevice,
681 KPimGlobalPrefs::instance()->mEx2PhoneConnection, 681 KPimGlobalPrefs::instance()->mEx2PhoneConnection,
682 KPimGlobalPrefs::instance()->mEx2PhoneModel ); 682 KPimGlobalPrefs::instance()->mEx2PhoneModel );
683 683
684 QStringList uids = mViewManager->selectedUids(); 684 QStringList uids = mViewManager->selectedUids();
685 if ( uids.isEmpty() ) 685 if ( uids.isEmpty() )
686 return; 686 return;
687 687
688#ifdef _WIN32_ 688#ifdef _WIN32_
689 QString fileName = locateLocal("tmp", "tempfile.vcf"); 689 QString fileName = locateLocal("tmp", "tempfile.vcf");
690#else 690#else
691 QString fileName = "/tmp/kdepimtemp.vcf"; 691 QString fileName = "/tmp/kdepimtemp.vcf";
692#endif 692#endif
693 693
694 KABC::VCardConverter converter; 694 KABC::VCardConverter converter;
695 QString description; 695 QString description;
696 QString datastream; 696 QString datastream;
697 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 697 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
698 KABC::Addressee a = mAddressBook->findByUid( *it ); 698 KABC::Addressee a = mAddressBook->findByUid( *it );
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;
710 while ( (next = vcard.find("TYPE=", start) )>= 0 ) { 713 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
711 int semi = vcard.find(";", next); 714 int semi = vcard.find(";", next);
712 int dopp = vcard.find(":", next); 715 int dopp = vcard.find(":", next);
713 int sep; 716 int sep;
714 if ( semi < dopp && semi >= 0 ) 717 if ( semi < dopp && semi >= 0 )
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) ) {
726 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); 741 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
727 QTextStream t( &outFile ); // use a text stream 742 QTextStream t( &outFile ); // use a text stream
728 t.setEncoding( QTextStream::UnicodeUTF8 ); 743 t.setEncoding( QTextStream::UnicodeUTF8 );
729 t <<datastream; 744 t <<datastream;
730 outFile.close(); 745 outFile.close();
731 if ( PhoneAccess::writeToPhone( fileName ) ) 746 if ( PhoneAccess::writeToPhone( fileName ) )
732 qDebug("Export okay "); 747 qDebug("Export okay ");
733 else 748 else
734 qDebug("Error export contacts "); 749 qDebug("Error export contacts ");
735 750
736 } else { 751 } else {
737 qDebug("Error open temp file "); 752 qDebug("Error open temp file ");
738 return; 753 return;
739 } 754 }
740 755
741 756
742#if 0 757#if 0
743 758
744 setCaption( i18n("Writing to phone...")); 759 setCaption( i18n("Writing to phone..."));
745 if ( PhoneFormat::writeToPhone( cal ) ) 760 if ( PhoneFormat::writeToPhone( cal ) )
746 setCaption( i18n("Export to phone successful!")); 761 setCaption( i18n("Export to phone successful!"));