author | zautrix <zautrix> | 2005-10-28 03:41:01 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-10-28 03:41:01 (UTC) |
commit | d934f3fe2a62f6a696992335124c4434cd77d990 (patch) (side-by-side diff) | |
tree | 88d33c54e3f8d08b09cf81f4cdbaeb7eb6a4bb9b /kabc | |
parent | f83a59cf4f9d0cff4111b6f5c88e88e6dc96e79e (diff) | |
download | kdepimpi-d934f3fe2a62f6a696992335124c4434cd77d990.zip kdepimpi-d934f3fe2a62f6a696992335124c4434cd77d990.tar.gz kdepimpi-d934f3fe2a62f6a696992335124c4434cd77d990.tar.bz2 |
and some bugs fixed
-rw-r--r-- | kabc/addressee.cpp | 4 | ||||
-rw-r--r-- | kabc/plugins/qtopia/qtopiaconverter.cpp | 8 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/sharpdtmconverter.cpp | 10 |
3 files changed, 11 insertions, 11 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 661bdf6..19c78ee 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -810,531 +810,531 @@ QString Addressee::name() const { return mData->name; } QString Addressee::nameLabel() { return i18n("Name"); } void Addressee::setFormattedName( const QString &formattedName ) { if ( formattedName == mData->formattedName ) return; detach(); mData->empty = false; mData->formattedName = formattedName; } QString Addressee::formattedName() const { return mData->formattedName; } QString Addressee::formattedNameLabel() { return i18n("Formatted Name"); } void Addressee::setFamilyName( const QString &familyName ) { if ( familyName == mData->familyName ) return; detach(); mData->empty = false; mData->familyName = familyName; } QString Addressee::familyName() const { return mData->familyName; } QString Addressee::familyNameLabel() { return i18n("Family Name"); } void Addressee::setGivenName( const QString &givenName ) { if ( givenName == mData->givenName ) return; detach(); mData->empty = false; mData->givenName = givenName; } QString Addressee::givenName() const { return mData->givenName; } QString Addressee::givenNameLabel() { return i18n("Given Name"); } void Addressee::setAdditionalName( const QString &additionalName ) { if ( additionalName == mData->additionalName ) return; detach(); mData->empty = false; mData->additionalName = additionalName; } QString Addressee::additionalName() const { return mData->additionalName; } QString Addressee::additionalNameLabel() { return i18n("Additional Names"); } void Addressee::setPrefix( const QString &prefix ) { if ( prefix == mData->prefix ) return; detach(); mData->empty = false; mData->prefix = prefix; } QString Addressee::prefix() const { return mData->prefix; } QString Addressee::prefixLabel() { return i18n("Honorific Prefixes"); } void Addressee::setSuffix( const QString &suffix ) { if ( suffix == mData->suffix ) return; detach(); mData->empty = false; mData->suffix = suffix; } QString Addressee::suffix() const { return mData->suffix; } QString Addressee::suffixLabel() { return i18n("Honorific Suffixes"); } void Addressee::setNickName( const QString &nickName ) { if ( nickName == mData->nickName ) return; detach(); mData->empty = false; mData->nickName = nickName; } QString Addressee::nickName() const { return mData->nickName; } QString Addressee::nickNameLabel() { return i18n("Nick Name"); } void Addressee::setBirthday( const QDateTime &birthday ) { if ( birthday == mData->birthday ) return; detach(); mData->empty = false; mData->birthday = birthday; } QDateTime Addressee::birthday() const { return mData->birthday; } QString Addressee::birthdayLabel() { return i18n("Birthday"); } QString Addressee::homeAddressStreetLabel() { return i18n("Home Address Street"); } QString Addressee::homeAddressLocalityLabel() { return i18n("Home Address Locality"); } QString Addressee::homeAddressRegionLabel() { return i18n("Home Address Region"); } QString Addressee::homeAddressPostalCodeLabel() { return i18n("Home Address Postal Code"); } QString Addressee::homeAddressCountryLabel() { return i18n("Home Address Country"); } QString Addressee::homeAddressLabelLabel() { return i18n("Home Address Label"); } QString Addressee::businessAddressStreetLabel() { return i18n("Business Address Street"); } QString Addressee::businessAddressLocalityLabel() { return i18n("Business Address Locality"); } QString Addressee::businessAddressRegionLabel() { return i18n("Business Address Region"); } QString Addressee::businessAddressPostalCodeLabel() { return i18n("Business Address Postal Code"); } QString Addressee::businessAddressCountryLabel() { return i18n("Business Address Country"); } QString Addressee::businessAddressLabelLabel() { return i18n("Business Address Label"); } QString Addressee::homePhoneLabel() { return i18n("Home Phone"); } QString Addressee::businessPhoneLabel() { return i18n("Work Phone"); } QString Addressee::mobilePhoneLabel() { return i18n("Mobile Phone"); } QString Addressee::mobileWorkPhoneLabel() { return i18n("Mobile2 (work)"); } QString Addressee::mobileHomePhoneLabel() { - return i18n("Mobile"); + return i18n("Mobile (Home)"); } QString Addressee::homeFaxLabel() { return i18n("Fax (Home)"); } QString Addressee::businessFaxLabel() { return i18n("Fax (Work)"); } QString Addressee::carPhoneLabel() { - return i18n("Mobile2 (work)"); + return i18n("Mobile2 (car)"); } QString Addressee::isdnLabel() { return i18n("ISDN"); } QString Addressee::pagerLabel() { return i18n("Pager"); } QString Addressee::sipLabel() { return i18n("SIP"); } QString Addressee::emailLabel() { return i18n("Email Address"); } void Addressee::setMailer( const QString &mailer ) { if ( mailer == mData->mailer ) return; detach(); mData->empty = false; mData->mailer = mailer; } QString Addressee::mailer() const { return mData->mailer; } QString Addressee::mailerLabel() { return i18n("Mail Client"); } void Addressee::setTimeZone( const TimeZone &timeZone ) { if ( timeZone == mData->timeZone ) return; detach(); mData->empty = false; mData->timeZone = timeZone; } TimeZone Addressee::timeZone() const { return mData->timeZone; } QString Addressee::timeZoneLabel() { return i18n("Time Zone"); } void Addressee::setGeo( const Geo &geo ) { if ( geo == mData->geo ) return; detach(); mData->empty = false; mData->geo = geo; } Geo Addressee::geo() const { return mData->geo; } QString Addressee::geoLabel() { return i18n("Geographic Position"); } void Addressee::setTitle( const QString &title ) { if ( title == mData->title ) return; detach(); mData->empty = false; mData->title = title; } QString Addressee::title() const { return mData->title; } QString Addressee::titleLabel() { return i18n("Title"); } void Addressee::setRole( const QString &role ) { if ( role == mData->role ) return; detach(); mData->empty = false; mData->role = role; } QString Addressee::role() const { return mData->role; } QString Addressee::roleLabel() { return i18n("Role"); } void Addressee::setOrganization( const QString &organization ) { if ( organization == mData->organization ) return; detach(); mData->empty = false; mData->organization = organization; } QString Addressee::organization() const { return mData->organization; } QString Addressee::organizationLabel() { return i18n("Organization"); } void Addressee::setNote( const QString ¬e ) { if ( note == mData->note ) return; detach(); mData->empty = false; mData->note = note; } QString Addressee::note() const { return mData->note; } QString Addressee::noteLabel() { return i18n("Note"); } void Addressee::setProductId( const QString &productId ) { if ( productId == mData->productId ) return; detach(); mData->empty = false; mData->productId = productId; } QString Addressee::productId() const { return mData->productId; } QString Addressee::productIdLabel() { return i18n("Product Identifier"); } void Addressee::setRevision( const QDateTime &revision ) { if ( revision == mData->revision ) return; detach(); mData->empty = false; mData->revision = QDateTime( revision.date(), QTime (revision.time().hour(), revision.time().minute(), revision.time().second())); } QDateTime Addressee::revision() const { return mData->revision; } QString Addressee::revisionLabel() { return i18n("Revision Date"); } void Addressee::setSortString( const QString &sortString ) { if ( sortString == mData->sortString ) return; detach(); mData->empty = false; mData->sortString = sortString; } QString Addressee::sortString() const { return mData->sortString; } QString Addressee::sortStringLabel() { return i18n("Sort String"); } void Addressee::setUrl( const KURL &url ) { if ( url == mData->url ) return; detach(); mData->empty = false; mData->url = url; } KURL Addressee::url() const { return mData->url; } QString Addressee::urlLabel() { return i18n("URL"); } void Addressee::setSecrecy( const Secrecy &secrecy ) { if ( secrecy == mData->secrecy ) return; detach(); mData->empty = false; mData->secrecy = secrecy; } Secrecy Addressee::secrecy() const { return mData->secrecy; } QString Addressee::secrecyLabel() { return i18n("Security Class"); } diff --git a/kabc/plugins/qtopia/qtopiaconverter.cpp b/kabc/plugins/qtopia/qtopiaconverter.cpp index 39d366b..9693a68 100644 --- a/kabc/plugins/qtopia/qtopiaconverter.cpp +++ b/kabc/plugins/qtopia/qtopiaconverter.cpp @@ -1,489 +1,489 @@ /* 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 "klocale.h" #include "qtopiaconverter.h" #include <qfile.h> #include <qdir.h> #include <qtextstream.h> //#include <.h> #include <libkdepim/ksyncprofile.h> using namespace KABC; QtopiaConverter::QtopiaConverter() { m_edit = 0; } QtopiaConverter::~QtopiaConverter() { deinit(); } bool QtopiaConverter::init() { QString fn = QDir::homeDirPath() +"/Settings/Categories.xml"; m_edit = new CategoryEdit( fn); return true; } void QtopiaConverter::deinit() { if (m_edit) { delete m_edit; m_edit = 0; } } QString QtopiaConverter::categoriesToNumber( const QStringList &list, const QString &app ) { startover: QStringList dummy; QValueList<OpieCategories>::ConstIterator catIt; QValueList<OpieCategories> categories = m_edit->categories(); bool found = false; for ( QStringList::ConstIterator listIt = list.begin(); listIt != list.end(); ++listIt ) { /* skip empty category name */ if ( (*listIt).isEmpty() ) continue; found = false; for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { /* * We currently do not take app into account * if name matches and the id isn't already in dummy we'll add it */ if ( (*catIt).name() == (*listIt) && !dummy.contains(( *catIt).id() ) ) { // the same name found= true; dummy << (*catIt).id(); } } /* if not found and the category is not empty * * generate a new category and start over again * ugly goto to reiterate */ if ( !found && !(*listIt).isEmpty() ){ m_edit->addCategory( app, (*listIt) ); // generate a new category goto startover; } } return dummy.join(";"); } // FROM TT timeconversion.cpp GPLed QDate QtopiaConverter::fromString( const QString &datestr ) { if (datestr.isEmpty() ) return QDate(); int monthPos = datestr.find('.'); int yearPos = datestr.find('.', monthPos+1 ); if ( monthPos == -1 || yearPos == -1 ) { return QDate(); } int d = datestr.left( monthPos ).toInt(); int m = datestr.mid( monthPos+1, yearPos - monthPos - 1 ).toInt(); int y = datestr.mid( yearPos+1 ).toInt(); QDate date ( y,m,d ); return date; } QDate QtopiaConverter::dateFromString( const QString& s ) { QDate date; if ( s.isEmpty() ) return date; // Be backward compatible to old Opie format: // Try to load old format. If it fails, try new ISO-Format! date = fromString ( s ); if ( date.isValid() ) return date; // Read ISO-Format (YYYYMMDD) int year = s.mid(0, 4).toInt(); int month = s.mid(4,2).toInt(); int day = s.mid(6,2).toInt(); // do some quick sanity checking if ( year < 1900 || year > 3000 ) return date; if ( month < 0 || month > 12 ) return date; if ( day < 0 || day > 31 ) return date; date.setYMD( year, month, day ); if ( !date.isValid() ) return QDate(); return date; } QString QtopiaConverter::dateToString( const QDate &d ) { if ( d.isNull() || !d.isValid() ) return QString::null; // ISO format in year, month, day (YYYYMMDD); e.g. 20021231 QString year = QString::number( d.year() ); QString month = QString::number( d.month() ); month = month.rightJustify( 2, '0' ); QString day = QString::number( d.day() ); day = day.rightJustify( 2, '0' ); QString str = year + month + day; return str; } bool QtopiaConverter::qtopiaToAddressee( const QDomElement& el, Addressee &adr ) { { //LR adr.setUid( el.attribute("Uid" ) ); adr.setFamilyName( el.attribute( "LastName" ) ); adr.setGivenName( el.attribute( "FirstName" ) ); adr.setAdditionalName( el.attribute( "MiddleName" ) ); adr.setSuffix( el.attribute( "Suffix" ) ); adr.setNickName( el.attribute( "Nickname" ) ); QDate date = dateFromString( el.attribute( "Birthday" ) ); if ( date.isValid() ) adr.setBirthday( date ); adr.setRole( el.attribute( "JobTitle" ) ); if ( !el.attribute( "FileAs" ).isEmpty() ) adr.setFormattedName( el.attribute( "FileAs" ) ); adr.setOrganization( el.attribute( "Company" ) ); KABC::PhoneNumber businessPhoneNum( el.attribute( "BusinessPhone" ), - KABC::PhoneNumber::Work ); + KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref ); KABC::PhoneNumber businessFaxNum( el.attribute( "BusinessFax" ), KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax ); KABC::PhoneNumber businessMobile( el.attribute( "BusinessMobile" ), - KABC::PhoneNumber::Work | KABC::PhoneNumber::Cell ); + KABC::PhoneNumber::Car ); KABC::PhoneNumber businessPager( el.attribute( "BusinessPager" ), - KABC::PhoneNumber::Work | KABC::PhoneNumber::Pager ); + KABC::PhoneNumber::Pager ); if ( !businessPhoneNum.number().isEmpty() ) adr.insertPhoneNumber( businessPhoneNum ); if ( !businessFaxNum.number().isEmpty() ) adr.insertPhoneNumber( businessFaxNum ); if ( !businessMobile.number().isEmpty() ) adr.insertPhoneNumber( businessMobile ); if ( !businessPager.number().isEmpty() ) adr.insertPhoneNumber( businessPager ); // Handle multiple mail addresses QString DefaultEmail = el.attribute( "DefaultEmail" ); if ( !DefaultEmail.isEmpty() ) adr.insertEmail( DefaultEmail, true ); // preferred QStringList Emails = QStringList::split(" ",el.attribute("Emails")); int i; for (i = 0;i < Emails.count();++i) { if ( Emails[i] != DefaultEmail ) adr.insertEmail( Emails[i], false ); } KABC::PhoneNumber homePhoneNum( el.attribute( "HomePhone" ), - KABC::PhoneNumber::Home ); + KABC::PhoneNumber::Home | KABC::PhoneNumber::Pref); KABC::PhoneNumber homeFax( el.attribute( "HomeFax" ), KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax ); KABC::PhoneNumber homeMobile( el.attribute( "HomeMobile" ), KABC::PhoneNumber::Cell ); if ( !homePhoneNum.number().isEmpty() ) adr.insertPhoneNumber( homePhoneNum ); if ( !homeFax.number().isEmpty() ) adr.insertPhoneNumber( homeFax ); if ( !homeMobile.number().isEmpty() ) adr.insertPhoneNumber( homeMobile ); KABC::Address business( KABC::Address::Work ); business.setStreet( el.attribute( "BusinessStreet" ) ); business.setLocality( el.attribute( "BusinessCity" ) ); business.setRegion( el.attribute( "BusinessState" ) ); business.setPostalCode( el.attribute( "BusinessZip" ) ); business.setCountry( el.attribute( "BusinessCountry" ) ); if ( !business.isEmpty() ) adr.insertAddress( business ); KABC::Address home( KABC::Address::Home ); home.setStreet( el.attribute( "HomeStreet" ) ); home.setLocality( el.attribute( "HomeCity" ) ); home.setRegion( el.attribute( "HomeState" ) ); home.setPostalCode( el.attribute( "HomeZip" ) ); home.setCountry( el.attribute( "HomeCountry" ) ); if ( !home.isEmpty() ) adr.insertAddress( home ); adr.setNickName( el.attribute( "Nickname" ) ); adr.setNote( el.attribute( "Notes" ) ); { QStringList categories = QStringList::split(";", el.attribute("Categories" ) ); QString cat; QStringList added; for ( uint i = 0; i < categories.count(); i++ ) { cat = m_edit->categoryById( categories[ i ], "Contacts" ); // if name is not empty and we did not add the // cat try to repair broken files if ( !cat.isEmpty() && !added.contains( cat ) ) { adr.insertCategory( cat ); added << cat; } } } if ( !el.attribute( "Department" ).isEmpty() ) adr.insertCustom( "KADDRESSBOOK", "X-Department", el.attribute( "Department" ) ); if ( !el.attribute( "HomeWebPage" ).isEmpty() ) adr.insertCustom( "opie", "HomeWebPage", el.attribute( "HomeWebPage" ) ); if ( !el.attribute( "Spouse" ).isEmpty() ) adr.insertCustom( "KADDRESSBOOK", "X-SpousesName", el.attribute( "Spouse" ) ); if ( !el.attribute( "Gender" ).isEmpty() ) { if ( el.attribute( "Gender" ) == "1" ) adr.insertCustom( "KADDRESSBOOK", "X-Gender", "male" ); else if ( el.attribute( "Gender" ) == "2" ) adr.insertCustom( "KADDRESSBOOK", "X-Gender", "female" ); } QDate ann = dateFromString( el.attribute( "Anniversary" ) ); if ( ann.isValid() ) { QString dt = KGlobal::locale()->formatDate(ann, true, KLocale::ISODate); adr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt ); } if ( !el.attribute( "Children" ).isEmpty() ) adr.insertCustom("KADDRESSBOOK", "X-Children", el.attribute("Children") ); if ( !el.attribute( "Office" ).isEmpty() ) adr.insertCustom("KADDRESSBOOK", "X-Office", el.attribute("Office") ); if ( !el.attribute( "Profession" ).isEmpty() ) adr.insertCustom("KADDRESSBOOK", "X-Profession", el.attribute("Profession") ); if ( !el.attribute( "Assistant" ).isEmpty() ) adr.insertCustom("KADDRESSBOOK", "X-AssistantsName", el.attribute("Assistant") ); if ( !el.attribute( "Manager" ).isEmpty() ) adr.insertCustom("KADDRESSBOOK", "X-ManagersName", el.attribute("Manager") ); } return true; } bool QtopiaConverter::addresseeToQtopia( const Addressee &ab, QTextStream *stream ) { *stream << "<Contact "; *stream << "FirstName=\"" << escape(ab.givenName()) << "\" "; *stream << "MiddleName=\"" << escape(ab.additionalName()) << "\" "; *stream << "LastName=\"" << escape(ab.familyName()) << "\" "; *stream << "Suffix=\"" << escape(ab.suffix()) << "\" "; QString sortStr; sortStr = ab.formattedName(); /* is formattedName is empty we use the assembled name as fallback */ if (sortStr.isEmpty() ) sortStr = ab.assembledName(); *stream << "FileAs=\"" << escape(sortStr) << "\" "; *stream << "JobTitle=\"" << escape(ab.role()) << "\" "; *stream << "Department=\"" << escape(ab.custom( "KADDRESSBOOK", "X-Department" )) << "\" "; *stream << "Company=\"" << escape(ab.organization()) << "\" "; KABC::PhoneNumber businessPhoneNum = ab.phoneNumber(KABC::PhoneNumber::Work ); *stream << "BusinessPhone=\"" << escape( businessPhoneNum.number() ) << "\" "; KABC::PhoneNumber businessFaxNum = ab.phoneNumber(KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax ); *stream << "BusinessFax=\"" << escape( businessFaxNum.number() )<< "\" "; KABC::PhoneNumber businessMobile = ab.phoneNumber(KABC::PhoneNumber::Work | KABC::PhoneNumber::Cell ); *stream << "BusinessMobile=\"" << escape( businessMobile.number() ) << "\" "; *stream << "DefaultEmail=\"" << escape( ab.preferredEmail() ) << "\" "; QStringList list = ab.emails(); if ( list.count() > 0 ) { QStringList::Iterator it = list.begin(); *stream << "Emails=\"" << escape( *it ); while (++it != list.end()) *stream << ' ' << escape( *it ); *stream << "\" "; } KABC::PhoneNumber homePhoneNum = ab.phoneNumber(KABC::PhoneNumber::Home ); *stream << "HomePhone=\"" << escape( homePhoneNum.number() ) << "\" "; KABC::PhoneNumber homeFax = ab.phoneNumber( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax ); *stream << "HomeFax=\"" << escape( homeFax.number() ) << "\" "; KABC::PhoneNumber homeMobile = ab.phoneNumber( KABC::PhoneNumber::Cell ); *stream << "HomeMobile=\"" << escape( homeMobile.number() ) << "\" "; KABC::Address business = ab.address(KABC::Address::Work ); *stream << "BusinessStreet=\"" << escape( business.street() ) << "\" "; *stream << "BusinessCity=\"" << escape( business.locality() ) << "\" "; *stream << "BusinessZip=\"" << escape( business.postalCode() ) << "\" "; *stream << "BusinessCountry=\"" << escape( business.country() ) << "\" "; *stream << "BusinessState=\"" << escape( business.region() ) << "\" "; //stream << "BusinessPager=\"" << << "\" "; *stream << "Office=\"" << escape( ab.custom( "KADDRESSBOOK", "X-Office" ) ) << "\" "; *stream << "Profession=\"" << escape( ab.custom( "KADDRESSBOOK", "X-Profession" ) ) << "\" "; *stream << "Assistant=\"" << escape( ab.custom( "KADDRESSBOOK", "X-AssistantsName") ) << "\" "; *stream << "Manager=\"" << escape( ab.custom( "KADDRESSBOOK", "X-ManagersName" ) ) << "\" "; KABC::Address home = ab.address( KABC::Address::Home ); *stream << "HomeStreet=\"" << escape( home.street() ) << "\" "; *stream << "HomeCity=\"" << escape( home.locality() ) << "\" "; *stream << "HomeState=\"" << escape( home.region() ) << "\" "; *stream << "HomeZip=\"" << escape( home.postalCode() ) << "\" "; *stream << "HomeCountry=\"" << escape( home.country() ) << "\" "; *stream << "HomeWebPage=\"" << escape( ab.custom( "opie", "HomeWebPage" ) ) << "\" "; *stream << "Spouse=\"" << escape( ab.custom( "KADDRESSBOOK", "X-SpousesName") ) << "\" "; QString gen = "0"; if ( ab.custom( "KADDRESSBOOK", "X-Gender") == "male" ) gen = "1"; else if ( ab.custom( "KADDRESSBOOK", "X-Gender") == "female" ) gen = "2"; *stream << "Gender=\"" << escape( gen ) << "\" "; if ( ab.birthday().date().isValid() ) *stream << "Birthday=\"" << escape( dateToString(ab.birthday().date() ) ) << "\" "; { QDate ann = KGlobal::locale()->readDate( ab.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); if (ann.isValid() ) { *stream << "Anniversary=\"" << escape( dateToString( ann ) ) << "\" "; } } *stream << "Nickname=\"" << escape( ab.nickName() ) << "\" "; *stream << "Children=\"" << escape( ab.custom("KADDRESSBOOK", "X-Children" ) ) << "\" "; *stream << "Notes=\"" << escape( ab.note() ) << "\" "; *stream << "Categories=\"" << categoriesToNumber( ab.categories(), "Contacts") << "\" "; QString uid = ab.uid(); *stream << "Uid=\"" << uid << "\" "; //*stream << map.toString( "addressbook", uid ); *stream << " />" << "\n"; return true; } #if 0 KTempFile* AddressBook::fromKDE( KSync::AddressBookSyncee *syncee, ExtraMap& map ) { } QStringList AddressBook::attributes()const { QStringList lst; lst << "FirstName"; lst << "MiddleName"; lst << "LastName"; lst << "Suffix"; lst << "FileAs"; lst << "JobTitle"; lst << "Department"; lst << "Company"; lst << "BusinessPhone"; lst << "BusinessFax"; lst << "BusinessMobile"; lst << "DefaultEmail"; lst << "Emails"; lst << "HomePhone"; lst << "HomeFax"; lst << "HomeMobile"; lst << "BusinessStreet"; lst << "BusinessCity"; lst << "BusinessZip"; lst << "BusinessCountry"; lst << "BusinessState"; lst << "Office"; lst << "Profession"; lst << "Assistant"; lst << "Manager"; lst << "HomeStreet"; lst << "HomeCity"; lst << "HomeState"; lst << "HomeZip"; lst << "HomeCountry"; lst << "HomeWebPage"; lst << "Spouse"; lst << "Gender"; lst << "Anniversary"; lst << "Nickname"; lst << "Children"; lst << "Notes"; lst << "Categories"; lst << "Uid"; lst << "Birthday"; return lst; } #endif CategoryEdit::CategoryEdit(){ } CategoryEdit::CategoryEdit(const QString &fileName){ parse( fileName ); } CategoryEdit::~CategoryEdit(){ } void CategoryEdit::save(const QString& fileName)const{ QFile file( fileName ); QString endl = "\n"; if ( file.open( IO_WriteOnly ) ) { QTextStream stream( &file ); stream.setEncoding( QTextStream::UnicodeUTF8 ); diff --git a/kabc/plugins/sharpdtm/sharpdtmconverter.cpp b/kabc/plugins/sharpdtm/sharpdtmconverter.cpp index 4adcae4..3d429fa 100644 --- a/kabc/plugins/sharpdtm/sharpdtmconverter.cpp +++ b/kabc/plugins/sharpdtm/sharpdtmconverter.cpp @@ -1,444 +1,444 @@ /* 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$ */ #include "kglobal.h" #include <qregexp.h> #include "sharpdtmconverter.h" #include <sl/slcategories.h> #include <libkdepim/ksyncprofile.h> //US #include <qpe/categoryselect.h> using namespace KABC; using namespace SlCategory; SharpDTMConverter::SharpDTMConverter() : catDB(0) { } SharpDTMConverter::~SharpDTMConverter() { deinit(); } bool SharpDTMConverter::init() { catDB = new SlCategory::SlCategories(); if (!catDB) return false; // catDB->load( categoryFileName() ); return true; } void SharpDTMConverter::deinit() { if (catDB) { delete catDB; catDB = 0; } } bool SharpDTMConverter::sharpToAddressee( const CardId &contact, const SlZDataBase* database, Addressee &addr ) { SlZDataBase* db = (SlZDataBase*)database; // for syncing: we need setting of the two fields addr.setExternalUID( QString::number( contact ) ); addr.setOriginalExternalUID( QString::number( contact ) ); addr.setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); // name //qDebug("SharpDTMConverter::sharpToAddressee check if the fileAs transformation works!!"); addr.setFormattedName(db->readField(ZdbAdrs::FileAs)); //addr.setName(db->readField(ZdbAdrs::FullName)); addr.setFamilyName( db->readField(ZdbAdrs::LastName) ); addr.setGivenName( db->readField(ZdbAdrs::FirstName) ); addr.setAdditionalName( db->readField(ZdbAdrs::MiddleName) ); addr.setPrefix( db->readField(ZdbAdrs::Title) ); addr.setSuffix( db->readField(ZdbAdrs::Suffix) ); QString emailstr = db->readField(ZdbAdrs::Emails); emailstr.replace( QRegExp(","), " " ); emailstr.replace( QRegExp(";"), " " ); emailstr.replace( QRegExp(":"), " " ); //qDebug("SharpDTMConverter::sharpToAddressee whats the character to seperate the emailadresses? %s ", emailstr.latin1()); QStringList emails = QStringList::split(" ", emailstr.simplifyWhiteSpace()); bool defE = false; bool found = false; for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { if (found ) defE = false; else found = defE = ((*it).lower() == db->readField(ZdbAdrs::DefaultEmail).lower()); addr.insertEmail( *it, defE ); } if ( ! found ) if (!db->readField(ZdbAdrs::DefaultEmail).isEmpty()) addr.insertEmail(db->readField(ZdbAdrs::DefaultEmail), true); // home if ((!db->readField(ZdbAdrs::HomeStreet).isEmpty()) || (!db->readField(ZdbAdrs::HomeCity).isEmpty()) || (!db->readField(ZdbAdrs::HomeState).isEmpty()) || (!db->readField(ZdbAdrs::HomeZip).isEmpty()) || (!db->readField(ZdbAdrs::HomeCountry).isEmpty())) { Address homeaddress; homeaddress.setType(Address::Home); //US homeaddress.setPostOfficeBox( "" ); //US homeaddress.setExtended( "" ); homeaddress.setStreet( db->readField(ZdbAdrs::HomeStreet).replace( QRegExp("\\r"), "")); homeaddress.setLocality( db->readField(ZdbAdrs::HomeCity) ); homeaddress.setRegion( db->readField(ZdbAdrs::HomeState) ); homeaddress.setPostalCode( db->readField(ZdbAdrs::HomeZip) ); homeaddress.setCountry( db->readField(ZdbAdrs::HomeCountry) ); addr.insertAddress( homeaddress ); } if (!db->readField(ZdbAdrs::HomePhone).isEmpty()) { PhoneNumber homephone; - homephone.setType( PhoneNumber::Home ); + homephone.setType( PhoneNumber::Home | PhoneNumber::Pref ); homephone.setNumber( db->readField(ZdbAdrs::HomePhone) ); addr.insertPhoneNumber( homephone ); } if (!db->readField(ZdbAdrs::HomeFax).isEmpty()) { PhoneNumber homefax; homefax.setType( PhoneNumber::Home | PhoneNumber::Fax ); homefax.setNumber( db->readField(ZdbAdrs::HomeFax) ); addr.insertPhoneNumber( homefax ); } if (!db->readField(ZdbAdrs::HomeMobile).isEmpty()) { PhoneNumber homemobile; - homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell ); + homemobile.setType( PhoneNumber::Cell ); homemobile.setNumber( db->readField(ZdbAdrs::HomeMobile) ); addr.insertPhoneNumber( homemobile ); } addr.setUrl( db->readField(ZdbAdrs::HomeWebPage) ); // business if ((!db->readField(ZdbAdrs::BusinessStreet).isEmpty()) || (!db->readField(ZdbAdrs::BusinessCity).isEmpty()) || (!db->readField(ZdbAdrs::BusinessState).isEmpty()) || (!db->readField(ZdbAdrs::BusinessZip).isEmpty()) || (!db->readField(ZdbAdrs::BusinessCountry).isEmpty())) { Address businessaddress; businessaddress.setType(Address::Work); //US businessaddress.setPostOfficeBox( "" ); //US businessaddress.setExtended( "" ); businessaddress.setStreet( db->readField(ZdbAdrs::BusinessStreet).replace( QRegExp("\\r"), "") ); businessaddress.setLocality( db->readField(ZdbAdrs::BusinessCity) ); businessaddress.setRegion( db->readField(ZdbAdrs::BusinessState) ); businessaddress.setPostalCode( db->readField(ZdbAdrs::BusinessZip) ); businessaddress.setCountry( db->readField(ZdbAdrs::BusinessCountry) ); addr.insertAddress( businessaddress ); } if (!db->readField(ZdbAdrs::BusinessPhone).isEmpty()) { PhoneNumber businessphone; - businessphone.setType( PhoneNumber::Work ); + businessphone.setType( PhoneNumber::Work | PhoneNumber::Pref ); businessphone.setNumber( db->readField(ZdbAdrs::BusinessPhone) ); addr.insertPhoneNumber( businessphone ); } if (!db->readField(ZdbAdrs::BusinessFax).isEmpty()) { PhoneNumber businessfax; businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax ); businessfax.setNumber( db->readField(ZdbAdrs::BusinessFax) ); addr.insertPhoneNumber( businessfax ); } if (!db->readField(ZdbAdrs::BusinessMobile).isEmpty()) { PhoneNumber businessmobile; - businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell ); + businessmobile.setType( PhoneNumber::Car ); businessmobile.setNumber( db->readField(ZdbAdrs::BusinessMobile) ); addr.insertPhoneNumber( businessmobile ); } if (!db->readField(ZdbAdrs::BusinessPager).isEmpty()) { PhoneNumber businesspager; - businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager ); + businesspager.setType( PhoneNumber::Pager ); businesspager.setNumber( db->readField(ZdbAdrs::BusinessPager) ); addr.insertPhoneNumber( businesspager ); } addr.setRole( db->readField(ZdbAdrs::JobTitle) ); addr.setOrganization( db->readField(ZdbAdrs::Company) ); addr.insertCustom( "KADDRESSBOOK", "X-Profession", db->readField(ZdbAdrs::Profession) ); addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", db->readField(ZdbAdrs::Assistant) ); addr.insertCustom( "KADDRESSBOOK", "X-Department", db->readField(ZdbAdrs::Department) ); addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", db->readField(ZdbAdrs::Manager) ); addr.insertCustom( "KADDRESSBOOK", "X-Office", db->readField(ZdbAdrs::Office) ); //personal addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", db->readField(ZdbAdrs::Spouse) ); QString gen = db->readField(ZdbAdrs::Gender); //qDebug("SharpDTMConverter::sharpToAddressee pleas check that gender works!! : Gender: %s", gen.latin1()); //qDebug("SharpDTMConverter::sharpToAddressee: may be int db->readUshortField(\"ZdbAdrs::Gender\") is here better suited"); if (gen == "1") addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male"); else if (gen == "2") addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female"); else addr.insertCustom( "KADDRESSBOOK", "X-Gender", "undef"); QDate ann = KGlobal::locale()->readDate( db->readField(ZdbAdrs::Anniversary) ); if (ann.isValid()) { QString dt = KGlobal::locale()->formatDate(ann, true, KLocale::ISODate); //qDebug("qtopiaToAddressee annyversary found:%s", dt.latin1()); addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); } else addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", " "); addr.insertCustom( "KADDRESSBOOK", "X-Children", db->readField(ZdbAdrs::Children) ); QDate birthd = KGlobal::locale()->readDate( db->readField(ZdbAdrs::Birthday) ); //qDebug("birtd %s ", birthd.toString().latin1()); if (birthd.isValid()) addr.setBirthday( birthd ); addr.setNickName( db->readField(ZdbAdrs::Nickname) ); // others //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available. //QString notes = db->readField(ZdbAdrs::Notes); //notes += "\nBusinessWebPage: " + db->readField(ZdbAdrs::BusinessWebPage) + "\n"; if ( addr.url().isEmpty() ) addr.setUrl( db->readField(ZdbAdrs::BusinessWebPage) ); addr.setNote( db->readField(ZdbAdrs::Notes).replace( QRegExp("\\r"), "")); //US QString groups() const { return find( Qtopia::Groups ); } //US QStringList groupList() const; //qDebug("SharpDTMConverter::sharpToAddressee please check that the categories will be converted" ); QArray<int> catArray = db->readCategories(); QString cat; for ( unsigned int i=0; i < catArray.size(); i++ ) { cat = catDB->label(catArray[i]); if ( cat.isEmpty() ) addr.insertCategory(QString::number(catArray[i])); else addr.insertCategory( cat ); } return true; } bool SharpDTMConverter::addresseeToSharp( const Addressee &addr, SlZDataBase* database , const CardId &contact ) { bool cellHome = false, cellWork = false; // name database->writeField(ZdbAdrs::LastName, addr.familyName()); database->writeField(ZdbAdrs::FirstName, addr.givenName()); database->writeField(ZdbAdrs::MiddleName, addr.additionalName()); database->writeField(ZdbAdrs::Title, addr.prefix()); database->writeField(ZdbAdrs::Suffix, addr.suffix()); //qDebug("SharpDTMConverter::addresseeToSharp check if the fileAs transformation works!!\n%s",addr.formattedName().latin1() ); QString formattedName = addr.formattedName(); if ( formattedName.isEmpty() ) { if ( !addr.familyName().isEmpty() ) { formattedName = addr.familyName(); if ( !addr.givenName().isEmpty() ) { formattedName += ", "; formattedName += addr.givenName(); } } else formattedName = addr.givenName(); } database->writeField(ZdbAdrs::FileAs, formattedName); database->writeField(ZdbAdrs::FullName, formattedName); // email //qDebug("SharpDTMConverter::addresseeToSharp check which seperator we need here for the emails!!"); //qDebug("SharpDTMConverter::addresseeToSharp its probably the same from sharpToAddressee"); QString emails = addr.emails().join(" "); database->writeField(ZdbAdrs::Emails, emails ); database->writeField(ZdbAdrs::DefaultEmail, addr.preferredEmail() ); // home const Address homeaddress = addr.address(Address::Home); database->writeField(ZdbAdrs::HomeStreet, homeaddress.street()); database->writeField(ZdbAdrs::HomeCity, homeaddress.locality()); database->writeField(ZdbAdrs::HomeState, homeaddress.region()); database->writeField(ZdbAdrs::HomeZip, homeaddress.postalCode()); database->writeField(ZdbAdrs::HomeCountry, homeaddress.country()); PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); database->writeField(ZdbAdrs::HomePhone, homephone.number()); PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); database->writeField(ZdbAdrs::HomeFax, homefax.number()); PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); database->writeField(ZdbAdrs::HomeMobile, homemobile.number()); if (!homemobile.number().isEmpty()) { cellHome = true; } database->writeField(ZdbAdrs::HomeWebPage, addr.url().url()); // business const Address businessaddress = addr.address(Address::Work); //qDebug("write business address "); database->writeField(ZdbAdrs::BusinessStreet, businessaddress.street()); database->writeField(ZdbAdrs::BusinessCity, businessaddress.locality()); database->writeField(ZdbAdrs::BusinessState, businessaddress.region()); database->writeField(ZdbAdrs::BusinessZip, businessaddress.postalCode()); database->writeField(ZdbAdrs::BusinessCountry, businessaddress.country()); PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work ); database->writeField(ZdbAdrs::BusinessPhone, businessphone.number()); PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ); database->writeField(ZdbAdrs::BusinessFax, businessfax.number()); PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell ); database->writeField(ZdbAdrs::BusinessMobile, businessmobile.number()); if (!businessmobile.number().isEmpty()) { cellWork = true; } PhoneNumber mobile = addr.phoneNumber( PhoneNumber::Cell ); if (! mobile.number().isEmpty()) { if ( ! cellHome ) database->writeField(ZdbAdrs::HomeMobile, mobile.number()); else if (! cellWork ) database->writeField(ZdbAdrs::BusinessMobile, mobile.number()); } PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); database->writeField(ZdbAdrs::BusinessPager, businesspager.number()); database->writeField(ZdbAdrs::JobTitle, addr.role()); database->writeField(ZdbAdrs::Company, addr.organization()); database->writeField(ZdbAdrs::Profession, addr.custom( "KADDRESSBOOK", "X-Profession" )); database->writeField(ZdbAdrs::Assistant, addr.custom( "KADDRESSBOOK", "X-AssistantsName" )); database->writeField(ZdbAdrs::Department, addr.custom( "KADDRESSBOOK", "X-Department" )); database->writeField(ZdbAdrs::Manager, addr.custom( "KADDRESSBOOK", "X-ManagersName" )); database->writeField(ZdbAdrs::Office, addr.custom( "KADDRESSBOOK", "X-Office" )); //personal database->writeField(ZdbAdrs::Spouse, addr.custom( "KADDRESSBOOK", "X-Spouse" )); QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" ); //qDebug("SharpDTMConverter::addresseeToSharp please check that gender works!! : Gender: %s", gt.latin1()); //qDebug("SharpDTMConverter::addresseeToSharp: may be writeField(\"ZdbAdrs::Gender\", ushort) is here better suited?"); //qDebug("SharpDTMConverter::addresseeToSharp: check also the reverse functionality in sharpToAddressee"); if (gt == "male") database->writeField(ZdbAdrs::Gender, "1"); else if (gt == "female") database->writeField(ZdbAdrs::Gender, "2"); else database->writeField(ZdbAdrs::Gender, ""); QString dateS ; QDate dt = KGlobal::locale()->readDate(addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate if ( dt.isValid() ) { dateS = KGlobal::locale()->formatDate(dt, true ); } database->writeField(ZdbAdrs::Anniversary, dateS ); database->writeField(ZdbAdrs::Children, addr.custom( "KADDRESSBOOK", "X-Children" )); dt = addr.birthday().date(); dateS = ""; if ( dt.isValid() ) { dateS = KGlobal::locale()->formatDate(dt, true ); } database->writeField(ZdbAdrs::Birthday, dateS); database->writeField(ZdbAdrs::Nickname, addr.nickName()); // other database->writeField(ZdbAdrs::Notes, addr.note()); //US QString groups() const { return find( Qtopia::Groups ); } //US QStringList groupList() const; //qDebug("SharpDTMConverter::addresseeToSharp please check if category transformation works"); return true; } bool SharpDTMConverter::setCategories( const Addressee &addr, SlZDataBase* database , const CardId &contact ) { QStringList list = addr.categories(); QArray<int> ids(list.count()); uint index = 0; for(uint i=0; i<ids.size(); i++){ if(catDB->exists(list[i])){ ids[index] = catDB->id(list[i]); //qDebug("set exist cat %d %s ",ids[index] , list[i].latin1()); index++; } else { ids[index] = catDB->addCategory(list[i]); //qDebug("add new cat %d %s ",ids[index] , list[i].latin1()); index++; } } bool res ; if ( !(res = database->updateCategories(contact, ids) )) qDebug("SharpDTMConverter::Error updating categories"); return res; } QDate SharpDTMConverter::convertDate( QString s) { QDate dt = KGlobal::locale()->readDate( s ); return dt; return QDate (); } |