[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: Patch for kab2kabc
From: Eike Welk <eike.welk () post ! rwth-aachen ! de>
Date: 2003-01-28 23:09:08
[Download RAW message or body]
On Tuesday 28 January 2003 03:31, Cornelius Schumacher wrote:
> The problem occurs, when the phonenumber QStringlist has an odd number
> of entries, right?
>
> Wouldn't it be more correct to check inside the loop after incrementing
> the iterator if the end of the list has been reached?
You are exactly right! This time I dont't get all these screwed up phone
numbers.
Here's the new patch.
Greetings,
Eike.
["kab2kabc_diff.txt" (text/plain)]
Index: kab2kabc.cpp
===================================================================
RCS file: /home/kde/kdelibs/kabc/kab2kabc.cpp,v
retrieving revision 1.14
diff -u -3 -p -u -r1.14 kab2kabc.cpp
--- kab2kabc.cpp 14 May 2002 09:06:09 -0000 1.14
+++ kab2kabc.cpp 28 Jan 2003 23:01:31 -0000
@@ -295,6 +295,7 @@ void importKab( KABC::AddressBook *ab, b
kdDebug(5700) << "Converting old-style kab addressbook to "
"new-style kabc addressbook." << endl;
+ //create old style kab addressbook object
KabAPI kab(0);
if (kab.init() != ::AddressBook::NoError) {
kdDebug(5700) << "Error initing kab" << endl;
@@ -308,7 +309,10 @@ void importKab( KABC::AddressBook *ab, b
kdDebug(5700) << "kab Addressbook has " << num << " entries." << endl;
+
for (int i = 0; i < num; ++i) {
+ kdDebug(5700) << "Starting to process entry: " << i << endl;
+
if (::AddressBook::NoError != kab.addressbook()->getKey(i,key)) {
kdDebug(5700) << "Error getting key for index " << i << " from kab." << endl;
continue;
@@ -319,9 +323,11 @@ void importKab( KABC::AddressBook *ab, b
continue;
}
+ //create new style address entry object
Addressee a;
// Convert custom entries
+ // especialyy look for "X-KABC-UID" we insert this custom item to identify item that are already in kabc
int count = 0;
bool idFound = false;
QStringList::ConstIterator customIt;
@@ -335,9 +341,15 @@ void importKab( KABC::AddressBook *ab, b
a.insertCustom( "kab2kabc", QString::number( count++ ), *customIt );
}
}
+ //only convert entries once; unless the user specifies otherwise by setting override to true
if( idFound ) {
- if ( !override ) continue;
+ //kab (old style) entry has unique ID
+ if ( !override ) {
+ kdDebug(5700) << "Entry has already been converted to kabc format; I continue with next entry." << endl;
+ continue;
+ }
} else {
+ //found no kabc ID -> insert kabc unique id into kab custom field
entry.custom << "X-KABC-UID:" + a.uid();
::AddressBook::ErrorCode error = kab.addressbook()->change( key, entry );
if (error != ::AddressBook::NoError) {
@@ -360,10 +372,15 @@ void importKab( KABC::AddressBook *ab, b
a.insertEmail( *emailIt );
}
+ //convert the phone numbers - the list contains a type ID followed by the real phone number
QStringList::ConstIterator phoneIt;
- for( phoneIt = entry.telephone.begin(); phoneIt != entry.telephone.end(); ++phoneIt ) {
- int kabType = (*phoneIt++).toInt();
- QString number = *phoneIt;
+ for( phoneIt = entry.telephone.begin(); phoneIt != entry.telephone.end(); ++phoneIt)
+ {
+ int kabType = (*phoneIt++).toInt(); //Get type ID number
+ if( phoneIt == entry.telephone.end()) //stop if list of phone numbers and type IDs
+ break; //contains an uneven number of entries.
+
+ QString number = *phoneIt; //Get the phone number
int type = 0;
if ( kabType == ::AddressBook::Fixed ) type = PhoneNumber::Voice;
else if ( kabType == ::AddressBook::Mobile ) type = PhoneNumber::Cell | PhoneNumber::Voice;
@@ -424,9 +441,12 @@ void importKab( KABC::AddressBook *ab, b
a.setCategories( entry.categories );
- kdDebug(5700) << "Addressee: " << a.familyName() << endl;
-
+ kdDebug(5700) << "Addressee family name: " << a.familyName() << endl;
+// kdDebug(5700) << "Addressee given name: " << a.givenName() << endl;
+
ab->insertAddressee( a );
+
+ kdDebug(5700) << "Finished processing entry: " << i << endl;
}
kab.save( true );
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic