summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/converter/opie/opieconverter.cpp149
-rw-r--r--kabc/converter/opie/opieconverter.h3
2 files changed, 139 insertions, 13 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
@@ -10,76 +10,80 @@
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;
@@ -137,60 +141,185 @@ bool OpieConverter::opieToAddressee( OContact &contact, Addressee &addr )
}
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
@@ -44,31 +44,28 @@ public:
*/
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