-rw-r--r-- | kabc/converter/opie/opieconverter.cpp | 105 | ||||
-rw-r--r-- | kabc/converter/opie/opieconverter.h | 11 |
2 files changed, 81 insertions, 35 deletions
diff --git a/kabc/converter/opie/opieconverter.cpp b/kabc/converter/opie/opieconverter.cpp index d785fbc..b4e9f1c 100644 --- a/kabc/converter/opie/opieconverter.cpp +++ b/kabc/converter/opie/opieconverter.cpp @@ -31,18 +31,44 @@ $Id$ #include "opieconverter.h" #include <qpe/categories.h> +#include <qpe/categoryselect.h> using namespace KABC; -OpieConverter::OpieConverter() +OpieConverter::OpieConverter() : catDB(0) { } OpieConverter::~OpieConverter() { + deinit(); +} + +bool OpieConverter::init() +{ + catDB = new Categories(); + if (catDB) + { + catDB->load( categoryFileName() ); + return true; + } + else + { + return false; + } + +} + +void OpieConverter::deinit() +{ + if (catDB) + { + delete catDB; + catDB = 0; + } } bool OpieConverter::opieToAddressee( OContact &contact, Addressee &addr ) { @@ -60,22 +86,30 @@ bool OpieConverter::opieToAddressee( OContact &contact, Addressee &addr ) for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { addr.insertEmail( *it, ((*it) == contact.defaultEmail()) ); } - addr.insertEmail(contact.defaultEmail(), true); + if (!contact.defaultEmail().isEmpty()) + addr.insertEmail(contact.defaultEmail(), true); // home - Address homeaddress; - homeaddress.setType(Address::Home); + if ((!contact.homeStreet().isEmpty()) || + (!contact.homeCity().isEmpty()) || + (!contact.homeState().isEmpty()) || + (!contact.homeZip().isEmpty()) || + (!contact.homeCountry().isEmpty())) + { + Address homeaddress; + homeaddress.setType(Address::Home); //US homeaddress.setPostOfficeBox( "" ); //US homeaddress.setExtended( "" ); - homeaddress.setStreet( contact.homeStreet() ); - homeaddress.setLocality( contact.homeCity() ); - homeaddress.setRegion( contact.homeState() ); - homeaddress.setPostalCode( contact.homeZip() ); - homeaddress.setCountry( contact.homeCountry() ); + homeaddress.setStreet( contact.homeStreet() ); + homeaddress.setLocality( contact.homeCity() ); + homeaddress.setRegion( contact.homeState() ); + homeaddress.setPostalCode( contact.homeZip() ); + homeaddress.setCountry( contact.homeCountry() ); - addr.insertAddress( homeaddress ); + addr.insertAddress( homeaddress ); + } if (!contact.homePhone().isEmpty()) { PhoneNumber homephone; @@ -103,20 +137,28 @@ bool OpieConverter::opieToAddressee( OContact &contact, Addressee &addr ) addr.setUrl( contact.homeWebpage() ); // business - Address businessaddress; - businessaddress.setType(Address::Work); + if ((!contact.businessStreet().isEmpty()) || + (!contact.businessCity().isEmpty()) || + (!contact.businessState().isEmpty()) || + (!contact.businessZip().isEmpty()) || + (!contact.businessCountry().isEmpty())) + { + Address businessaddress; + businessaddress.setType(Address::Work); //US businessaddress.setPostOfficeBox( "" ); //US businessaddress.setExtended( "" ); - businessaddress.setStreet( contact.businessStreet() ); - businessaddress.setLocality( contact.businessCity() ); - businessaddress.setRegion( contact.businessState() ); - businessaddress.setPostalCode( contact.businessZip() ); - businessaddress.setCountry( contact.businessCountry() ); + businessaddress.setStreet( contact.businessStreet() ); + businessaddress.setLocality( contact.businessCity() ); + businessaddress.setRegion( contact.businessState() ); + businessaddress.setPostalCode( contact.businessZip() ); + businessaddress.setCountry( contact.businessCountry() ); + + addr.insertAddress( businessaddress ); + } + - addr.insertAddress( businessaddress ); - if (!contact.businessPhone().isEmpty()) { PhoneNumber businessphone; businessphone.setType( PhoneNumber::Work ); @@ -160,14 +202,11 @@ bool OpieConverter::opieToAddressee( OContact &contact, Addressee &addr ) addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() ); addr.insertCustom( "KADDRESSBOOK", "X-Gender", contact.gender() ); if (contact.anniversary().isValid()) { - int orgformat = KGlobal::locale()->getIntDateFormat(); - KGlobal::locale()->setIntDateFormat( 2 ); // = Qt::ISODate - QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true); + QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true, KLocale::ISODate); //US qDebug("OpieConverter::opieToAddressee found:%s", dt.latin1()); - KGlobal::locale()->setIntDateFormat(orgformat ); addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); } addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() ); @@ -189,11 +228,11 @@ bool OpieConverter::opieToAddressee( OContact &contact, Addressee &addr ) //US QStringList groupList() const; QStringList cats = contact.categoryNames("Contacts"); - for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) { - qDebug("Cat: %s", (*it).latin1()); - } +// for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) { +// qDebug("Cat: %s", (*it).latin1()); +// } addr.setCategories( contact.categoryNames("Contacts") ); // qDebug("Groups: %s", contact.groups().latin1()); @@ -322,17 +361,15 @@ bool OpieConverter::addresseeToOpie( const Addressee &addr, OContact &contact ) contact.setCategories( cat ); */ Categories catDB; - catDB.dump(); -//US catDB.load( contact.categoryFileName() ); - catDB.load( "contact" ); - + catDB.load( categoryFileName() ); QStringList cats = addr.categories(); - for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) { - qDebug("categories: %s", (*it).latin1()); -// contact.setCategories(catDB.id(*it)); - } + QArray<int> iar; + if ( !cats.isEmpty() ) { + QArray<int> iar = catDB.ids("contact", cats); + contact.setCategories(iar); + } return true; } diff --git a/kabc/converter/opie/opieconverter.h b/kabc/converter/opie/opieconverter.h index ef7300b..7d2ad85 100644 --- a/kabc/converter/opie/opieconverter.h +++ b/kabc/converter/opie/opieconverter.h @@ -32,8 +32,10 @@ $Id$ #include "addressee.h" #include <opie/ocontact.h> +class Categories; + namespace KABC { class OpieConverter { @@ -46,9 +48,12 @@ public: /** * Destructor. */ - ~OpieConverter(); + virtual ~OpieConverter(); + + virtual bool init(); + virtual void deinit(); /** * Converts a vcard string to an addressee. * @@ -63,9 +68,13 @@ public: * @param addr The addressee. * @param contact The opie contact. */ bool addresseeToOpie( const Addressee &addr, OContact &contact ); + + private: + Categories* catDB; + }; } #endif |