author | ulf69 <ulf69> | 2004-07-01 01:40:51 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-07-01 01:40:51 (UTC) |
commit | 574570db1963fd729bb40a778ae3fc6a71ffc221 (patch) (side-by-side diff) | |
tree | 470b49c7c1de2c415edcfb7f4962a23d848b5280 /kabc/converter | |
parent | 94a34390c1c3f6554e171760aa250186e6c8cfc9 (diff) | |
download | kdepimpi-574570db1963fd729bb40a778ae3fc6a71ffc221.zip kdepimpi-574570db1963fd729bb40a778ae3fc6a71ffc221.tar.gz kdepimpi-574570db1963fd729bb40a778ae3fc6a71ffc221.tar.bz2 |
converter also supports now export
-rw-r--r-- | kabc/converter/opie/opieconverter.cpp | 145 | ||||
-rw-r--r-- | kabc/converter/opie/opieconverter.h | 3 |
2 files changed, 137 insertions, 11 deletions
diff --git a/kabc/converter/opie/opieconverter.cpp b/kabc/converter/opie/opieconverter.cpp index fbb5817..cfbe5c0 100644 --- a/kabc/converter/opie/opieconverter.cpp +++ b/kabc/converter/opie/opieconverter.cpp @@ -1,196 +1,325 @@ /* This file is part of libkabc. Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ //US #include "kglobal.h" #include "opieconverter.h" +#include <qpe/categories.h> + + using namespace KABC; OpieConverter::OpieConverter() { } OpieConverter::~OpieConverter() { } bool OpieConverter::opieToAddressee( OContact &contact, Addressee &addr ) { // name -//US QString fileAs() const { return find( Qtopia::FileAs ); } - + addr.setFormattedName(contact.fileAs()); addr.setFamilyName( contact.lastName() ); addr.setGivenName( contact.firstName() ); addr.setAdditionalName( contact.middleName() ); addr.setPrefix( contact.title() ); addr.setSuffix( contact.suffix() ); // email QStringList emails = contact.emailList(); for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { addr.insertEmail( *it, ((*it) == contact.defaultEmail()) ); } + addr.insertEmail(contact.defaultEmail(), true); + // home 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() ); addr.insertAddress( homeaddress ); if (!contact.homePhone().isEmpty()) { PhoneNumber homephone; homephone.setType( PhoneNumber::Home ); homephone.setNumber( contact.homePhone() ); addr.insertPhoneNumber( homephone ); } if (!contact.homeFax().isEmpty()) { PhoneNumber homefax; homefax.setType( PhoneNumber::Home | PhoneNumber::Fax ); homefax.setNumber( contact.homeFax() ); addr.insertPhoneNumber( homefax ); } if (!contact.homeMobile().isEmpty()) { PhoneNumber homemobile; homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell ); homemobile.setNumber( contact.homeMobile() ); addr.insertPhoneNumber( homemobile ); } addr.setUrl( contact.homeWebpage() ); // business 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() ); addr.insertAddress( businessaddress ); if (!contact.businessPhone().isEmpty()) { PhoneNumber businessphone; businessphone.setType( PhoneNumber::Work ); businessphone.setNumber( contact.businessPhone() ); addr.insertPhoneNumber( businessphone ); } if (!contact.businessFax().isEmpty()) { PhoneNumber businessfax; businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax ); businessfax.setNumber( contact.businessFax() ); addr.insertPhoneNumber( businessfax ); } if (!contact.businessMobile().isEmpty()) { PhoneNumber businessmobile; businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell ); businessmobile.setNumber( contact.businessMobile() ); addr.insertPhoneNumber( businessmobile ); } if (!contact.businessPager().isEmpty()) { PhoneNumber businesspager; businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager ); businesspager.setNumber( contact.businessPager() ); addr.insertPhoneNumber( businesspager ); } addr.setRole( contact.jobTitle() ); //? addr.setOrganization( contact.company() ); addr.insertCustom( "KADDRESSBOOK", "X-Profession", contact.profession() ); addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", contact.assistant() ); addr.insertCustom( "KADDRESSBOOK", "X-Department", contact.department() ); addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", contact.manager() ); addr.insertCustom( "KADDRESSBOOK", "X-Office", contact.office() ); //??? //US QString businessWebpage() const { return find( Qtopia::BusinessWebPage ); } //personal addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() ); addr.insertCustom( "KADDRESSBOOK", "X-Gender", contact.gender() ); - addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dateToAddresseeString(contact.anniversary()) ); + + int orgformat = KGlobal::locale()->getIntDateFormat(); + KGlobal::locale()->setIntDateFormat( 2 ); // = Qt::ISODate + QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true); + KGlobal::locale()->setIntDateFormat(orgformat ); + addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); + addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() ); addr.setBirthday( contact.birthday() ); addr.setNickName( contact.nickname() ); // other addr.setNote( contact.notes() ); //US QString groups() const { return find( Qtopia::Groups ); } //US QStringList groupList() const; /*US QStringList cats = contact.categoryNames("Contacts"); 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()); // addr.setCategories( contact.groupList() ); return true; } bool OpieConverter::addresseeToOpie( const Addressee &addr, OContact &contact ) { - return false; + // name + contact.setLastName(addr.familyName()); + contact.setFirstName(addr.givenName()); + contact.setMiddleName(addr.additionalName()); + contact.setTitle(addr.prefix()); + contact.setSuffix(addr.suffix()); + contact.setFileAs(); + + + // email + QStringList emails = addr.emails(); + for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { + contact.insertEmail(*it); } + contact.setDefaultEmail( addr.preferredEmail() ); -QString OpieConverter::dateToAddresseeString( const QDate &date ) -{ - return KGlobal::locale()->formatDate(date, true); -//US return date.toString("yyyyMMdd"); + + // home + const Address homeaddress = addr.address(Address::Home); + if (!homeaddress.isEmpty()) { + contact.setHomeStreet(homeaddress.street()); + contact.setHomeCity(homeaddress.locality()); + contact.setHomeState(homeaddress.region()); + contact.setHomeZip(homeaddress.postalCode()); + contact.setHomeCountry(homeaddress.country()); } + PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); + if (!homephone.number().isEmpty()) + contact.setHomePhone(homephone.number()); + + PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); + if (!homefax.number().isEmpty()) + contact.setHomeFax(homefax.number()); + + PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); + if (!homemobile.number().isEmpty()) + contact.setHomeMobile(homemobile.number()); + + contact.setHomeWebpage(addr.url().url()); + + + // business + const Address businessaddress = addr.address(Address::Work); + if (!businessaddress.isEmpty()) { + contact.setBusinessStreet(businessaddress.street()); + contact.setBusinessCity(businessaddress.locality()); + contact.setBusinessState(businessaddress.region()); + contact.setBusinessZip(businessaddress.postalCode()); + contact.setBusinessCountry(businessaddress.country()); + } + + PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work ); + if (!businessphone.number().isEmpty()) + contact.setBusinessPhone(businessphone.number()); + + PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ); + if (!businessfax.number().isEmpty()) + contact.setBusinessFax(businessfax.number()); + + PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell ); + if (!businessmobile.number().isEmpty()) + contact.setBusinessMobile(businessmobile.number()); + + PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); + if (!businesspager.number().isEmpty()) + contact.setBusinessPager(businesspager.number()); + + contact.setJobTitle(addr.role()); + contact.setCompany(addr.organization()); + + contact.setProfession(addr.custom( "KADDRESSBOOK", "X-Profession" )); + contact.setAssistant(addr.custom( "KADDRESSBOOK", "X-AssistantsName" )); + contact.setDepartment(addr.custom( "KADDRESSBOOK", "X-Department" )); + contact.setManager(addr.custom( "KADDRESSBOOK", "X-ManagersName" )); + contact.setOffice(addr.custom( "KADDRESSBOOK", "X-Office" )); + + //personal + contact.setSpouse(addr.custom( "KADDRESSBOOK", "X-Spouse" )); + contact.setGender(addr.custom( "KADDRESSBOOK", "X-Gender" )); + + QDate dt = KGlobal::locale()->readDate( + addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate + contact.setAnniversary( dt ); + + contact.setChildren(addr.custom( "KADDRESSBOOK", "X-Children" )); + + contact.setBirthday(addr.birthday().date()); + contact.setNickname(addr.nickName()); + + // other + contact.setNotes(addr.note()); + +//US QString groups() const { return find( Qtopia::Groups ); } +//US QStringList groupList() const; + +/*US + QStringList cats = contact.categoryNames("Contacts"); + for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) { + qDebug("Cat: %s", (*it).latin1()); + } +*/ + +// addr.setCategories( contact.categoryNames("Contacts") ); +// contact.categoryNames("Contacts"); +// contact.setCategoryNames(addr.categories()); + +/*US + QStringList cats = addr.categories(); + QArray<int> cat(cats.count()); + int counter = 0; + for ( QStringList::ConstIterator it = cats.begin(); it != cats.end(); ++it ) + cat[counter] = (*it).toInt(); + + contact.setCategories( cat ); +*/ +/*US + Categories catDB; + catDB.load( contact.categoryFileName() ); + + QStringList cats = addr.categories(); + for ( QStringList::Iterator it = cats.begin(); it != cats.end(); ++it ) { + contact.setCategories(catDB.id(*it)); + } +*/ + + return true; +} diff --git a/kabc/converter/opie/opieconverter.h b/kabc/converter/opie/opieconverter.h index 55a869a..ef7300b 100644 --- a/kabc/converter/opie/opieconverter.h +++ b/kabc/converter/opie/opieconverter.h @@ -1,74 +1,71 @@ /* This file is part of libkabc. Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #ifndef KABC_OPIECONVERTER_H #define KABC_OPIECONVERTER_H #include <qstring.h> #include "addressee.h" #include <opie/ocontact.h> namespace KABC { class OpieConverter { public: /** * Constructor. */ OpieConverter(); /** * Destructor. */ ~OpieConverter(); /** * Converts a vcard string to an addressee. * * @param contact The opie contact. * @param addr The addressee. */ bool opieToAddressee( OContact &contact, Addressee &addr ); /** * Converts an addressee to a vcard string. * * @param addr The addressee. * @param contact The opie contact. */ bool addresseeToOpie( const Addressee &addr, OContact &contact ); - private: - QString dateToAddresseeString( const QDate &date ); - }; } #endif |