-rw-r--r-- | kabc/addressbook.cpp | 44 | ||||
-rw-r--r-- | kabc/addressbook.h | 3 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 65 | ||||
-rw-r--r-- | kaddressbook/kabcore.h | 3 | ||||
-rw-r--r-- | libkcal/phoneformat.cpp | 12 | ||||
-rw-r--r-- | libkdepim/phoneaccess.cpp | 24 | ||||
-rw-r--r-- | libkdepim/phoneaccess.h | 2 |
7 files changed, 123 insertions, 30 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 16927e2..d037d2f 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -2,96 +2,97 @@ This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher <schumacher@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 <qfile.h> #include <qregexp.h> #include <qtimer.h> #include <kapplication.h> #include <kinstance.h> #include <kstandarddirs.h> #include "errorhandler.h" */ #include <qptrlist.h> #include <qtextstream.h> #include <qfile.h> #include <qregexp.h> #include <kglobal.h> #include <klocale.h> #include <kmessagebox.h> #include <kdebug.h> #include <libkcal/syncdefines.h> +#include <libkdepim/phoneaccess.h> #include "addressbook.h" #include "resource.h" #include "vcardconverter.h" #include "vcardparser/vcardtool.h" //US #include "addressbook.moc" using namespace KABC; struct AddressBook::AddressBookData { Addressee::List mAddressees; Addressee::List mRemovedAddressees; Field::List mAllFields; KConfig *mConfig; KRES::Manager<Resource> *mManager; //US ErrorHandler *mErrorHandler; }; struct AddressBook::Iterator::IteratorData { Addressee::List::Iterator mIt; }; struct AddressBook::ConstIterator::ConstIteratorData { Addressee::List::ConstIterator mIt; }; AddressBook::Iterator::Iterator() { d = new IteratorData; } AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) { d = new IteratorData; d->mIt = i.d->mIt; } AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) { if( this == &i ) return *this; // guard against self assignment delete d; // delete the old data the Iterator was completely constructed before d = new IteratorData; d->mIt = i.d->mIt; return *this; } @@ -414,96 +415,139 @@ void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool rem QByteArray rawData = file.readAll(); file.close(); QString data; if ( replaceLabel ) { data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); data.replace ( QRegExp("LABEL") , "ADR" ); data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); } else data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); KABC::VCardTool tool; list = tool.parseVCards( data ); KABC::Addressee::List::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { (*it).setResource( 0 ); if ( replaceLabel ) (*it).removeVoice(); if ( removeOld ) (*it).setTagged( true ); insertAddressee( (*it), false, true ); } if ( removeOld ) removeUntagged(); } void AddressBook::setUntagged() { Iterator ait; for ( ait = begin(); ait != end(); ++ait ) { (*ait).setTagged( false ); } } void AddressBook::removeUntagged() { Iterator ait; bool todelete = false; Iterator todel; for ( ait = begin(); ait != end(); ++ait ) { if ( todelete ) removeAddressee( todel ); if (!(*ait).tagged()) { todelete = true; todel = ait; } else todelete = false; } if ( todelete ) removeAddressee( todel ); deleteRemovedAddressees(); } +void AddressBook::smplifyAddressees() +{ + Iterator ait; + for ( ait = begin(); ait != end(); ++ait ) { + (*ait).simplifyEmails(); + (*ait).simplifyPhoneNumbers(); + (*ait).simplifyPhoneNumberTypes(); + (*ait).simplifyAddresses(); + } +} +void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) +{ + Iterator ait; + for ( ait = begin(); ait != end(); ++ait ) { + QString id = (*ait).IDStr(); + (*ait).setIDStr( ":"); + (*ait).setExternalUID( id ); + (*ait).setOriginalExternalUID( id ); + if ( isPreSync ) + (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); + else + (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); + } +} +bool AddressBook::saveABphone( QString fileName ) +{ + smplifyAddressees(); + qDebug("saveABphone:: saving AB... "); + if ( ! saveAB() ) + return false; + qDebug("saveABphone:: writing to phone... "); + if ( !PhoneAccess::writeToPhone( fileName) ) { + return false; + } + qDebug("saveABphone:: re-reading from phone... "); + if ( !PhoneAccess::readFromPhone( fileName) ) { + return false; + } + qDebug("reloading phone book... "); + if ( !load() ) + return false; + return true; +} bool AddressBook::saveAB() { bool ok = true; deleteRemovedAddressees(); Iterator ait; for ( ait = begin(); ait != end(); ++ait ) { if ( !(*ait).IDStr().isEmpty() ) { (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); } } KRES::Manager<Resource>::ActiveIterator it; KRES::Manager<Resource> *manager = d->mManager; for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { if ( !(*it)->readOnly() && (*it)->isOpen() ) { Ticket *ticket = requestSaveTicket( *it ); // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); if ( !ticket ) { error( i18n( "Unable to save to resource '%1'. It is locked." ) .arg( (*it)->resourceName() ) ); return false; } //if ( !save( ticket ) ) if ( ticket->resource() ) { if ( ! ticket->resource()->save( ticket ) ) ok = false; } else ok = false; } } return ok; } AddressBook::Iterator AddressBook::begin() { Iterator it = Iterator(); it.d->mIt = d->mAddressees.begin(); return it; } AddressBook::ConstIterator AddressBook::begin() const { ConstIterator it = ConstIterator(); it.d->mIt = d->mAddressees.begin(); return it; } diff --git a/kabc/addressbook.h b/kabc/addressbook.h index 532e05d..cc755d1 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h @@ -97,96 +97,99 @@ class AddressBook : public QObject ConstIterator &operator=( const ConstIterator & ); const Addressee &operator*() const; const Addressee* operator->() const; ConstIterator &operator++(); ConstIterator &operator++(int); ConstIterator &operator--(); ConstIterator &operator--(int); bool operator==( const ConstIterator &it ); bool operator!=( const ConstIterator &it ); struct ConstIteratorData; ConstIteratorData *d; }; /** Constructs a address book object. @param format File format class. */ AddressBook(); AddressBook( const QString &config ); AddressBook( const QString &config, const QString &family ); virtual ~AddressBook(); /** Requests a ticket for saving the addressbook. Calling this function locks the addressbook for all other processes. If the address book is already locked the function returns 0. You need the returned @ref Ticket object for calling the @ref save() function. @see save() */ Ticket *requestSaveTicket( Resource *resource=0 ); /** Load address book from file. */ bool load(); /** Save address book. The address book is saved to the file, the Ticket object has been requested for by @ref requestSaveTicket(). @param ticket a ticket object returned by @ref requestSaveTicket() */ bool save( Ticket *ticket ); bool saveAB( ); + bool saveABphone( QString fileName ); + void smplifyAddressees(); + void preparePhoneSync( QString currentSyncDevice, bool isPreSync ); void export2File( QString fileName ); void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); void setUntagged(); void removeUntagged(); /** Returns a iterator for first entry of address book. */ Iterator begin(); /** Returns a const iterator for first entry of address book. */ ConstIterator begin() const; /** Returns a iterator for first entry of address book. */ Iterator end(); /** Returns a const iterator for first entry of address book. */ ConstIterator end() const; /** Removes all entries from address book. */ void clear(); /** Insert an Addressee object into address book. If an object with the same unique id already exists in the address book it it replaced by the new one. If not the new object is appended to the address book. */ void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); /** Removes entry from the address book. */ void removeAddressee( const Addressee & ); /** This is like @ref removeAddressee() just above, with the difference that the first element is a iterator, returned by @ref begin(). */ void removeAddressee( const Iterator & ); /** diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 452f1bc..a7967cb 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -2778,122 +2778,147 @@ bool KABCore::sync(KSyncManager* manager, QString filename, int mode) } else { bool found = false; AddressBook::Iterator it; for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { if ( (*it).revision().date().year() > 2003 ) { found = true; break; } } external = ! found; } if ( external ) { qDebug("Setting vcf mode to external "); mGlobalSyncMode = SYNC_MODE_EXTERNAL; AddressBook::Iterator it; for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { (*it).setID( mCurrentSyncDevice, (*it).uid() ); (*it).computeCsum( mCurrentSyncDevice ); } } } //AddressBook::Iterator it; //QStringList vcards; //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { // qDebug("Name %s ", (*it).familyName().latin1()); //} syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); if ( syncOK ) { if ( syncManager->mWriteBackFile ) { if ( external ) abLocal.removeSyncAddressees( !isXML); qDebug("Saving remote AB "); if ( ! abLocal.saveAB()) qDebug("Error writing back AB to file "); if ( isXML ) { // afterwrite processing abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); } } } setModified(); } if ( syncOK ) mViewManager->refreshView(); return syncOK; -#if 0 - if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { - getEventViewerDialog()->setSyncMode( true ); - syncOK = synchronizeCalendar( mCalendar, calendar, mode ); - getEventViewerDialog()->setSyncMode( false ); - if ( syncOK ) { - if ( KOPrefs::instance()->mWriteBackFile ) - { - storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); - storage->save(); - } - } - setModified(); - } - -#endif } //this is a overwritten callbackmethods from the syncinterface bool KABCore::syncExternal(KSyncManager* manager, QString resource) { + if ( resource == "phone" ) + return syncPhone(); QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); AddressBook abLocal( resource,"syncContact"); bool syncOK = false; if ( abLocal.load() ) { qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); mGlobalSyncMode = SYNC_MODE_EXTERNAL; abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); if ( syncOK ) { if ( syncManager->mWriteBackFile ) { abLocal.saveAB(); abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); } } setModified(); } if ( syncOK ) mViewManager->refreshView(); return syncOK; } - -void KABCore::getFile( bool success ) +void KABCore::message( QString m ) { + + topLevelWidget()->setCaption( m ); QTimer::singleShot( 15000, this , SLOT ( setCaptionBack())); +} +bool KABCore::syncPhone() +{ + QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); + QString fileName; +#ifdef _WIN32_ + fileName = locateLocal("tmp", "phonefile.vcf"); +#else + fileName = "/tmp/phonefile.vcf"; +#endif + if ( !PhoneAccess::readFromPhone( fileName) ) { + message(i18n("Phone access failed!")); + return false; + } + AddressBook abLocal( fileName,"syncContact"); + bool syncOK = false; + if ( abLocal.load() ) { + qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); + mGlobalSyncMode = SYNC_MODE_EXTERNAL; + abLocal.preparePhoneSync( mCurrentSyncDevice, true ); + abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); + syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); + if ( syncOK ) { + if ( syncManager->mWriteBackFile ) { + abLocal.saveABphone( fileName ); + abLocal.preparePhoneSync( mCurrentSyncDevice, false ); + abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); + abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); + } + } + setModified(); + } + if ( syncOK ) + mViewManager->refreshView(); + return syncOK; +} +void KABCore::getFile( bool success ) +{ if ( ! success ) { - setCaption( i18n("Error receiving file. Nothing changed!") ); + message( i18n("Error receiving file. Nothing changed!") ); return; } mAddressBook->importFromFile( sentSyncFile() , false, true ); - topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); + message( i18n("Pi-Sync successful!") ); mViewManager->refreshView(); } void KABCore::syncFileRequest() { mAddressBook->export2File( sentSyncFile() ); } QString KABCore::sentSyncFile() { #ifdef _WIN32_ return locateLocal( "tmp", "copysyncab.vcf" ); #else return QString( "/tmp/copysyncab.vcf" ); #endif } void KABCore::setCaptionBack() { topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); } diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h index 43c5f99..04ce33d 100644 --- a/kaddressbook/kabcore.h +++ b/kaddressbook/kabcore.h @@ -419,65 +419,66 @@ class KABCore : public QWidget, public KSyncInterface KAction *mActionPaste; KAction *mActionSelectAll; KAction *mActionUndo; KAction *mActionRedo; KAction *mActionDelete; //US settings menu KAction *mActionConfigResources; KAction *mActionConfigKAddressbook; KAction *mActionConfigShortcuts; KAction *mActionConfigureToolbars; KAction *mActionKeyBindings; KToggleAction *mActionJumpBar; KToggleAction *mActionDetails; KAction *mActionWhoAmI; KAction *mActionCategories; KAction *mActionAboutKAddressbook; KAction *mActionLicence; KAction *mActionFaq; KAction *mActionDeleteView; QPopupMenu *viewMenu; QPopupMenu *filterMenu; QPopupMenu *settingsMenu; QPopupMenu *changeMenu; //US QAction *mActionSave; QPopupMenu *ImportMenu; QPopupMenu *ExportMenu; //LR additional methods KAction *mActionRemoveVoice; KAction * mActionImportOL; #ifndef KAB_EMBEDDED KAddressBookService *mAddressBookService; #endif //KAB_EMBEDDED class KABCorePrivate; KABCorePrivate *d; //US bool mBlockSaveFlag; #ifdef KAB_EMBEDDED KAddressBookMain *mMainWindow; // should be the same like mGUIClient #endif //KAB_EMBEDDED //this are the overwritten callbackmethods from the syncinterface virtual bool sync(KSyncManager* manager, QString filename, int mode); virtual bool syncExternal(KSyncManager* manager, QString resource); - + bool syncPhone(); + void message( QString m ); // LR ******************************* // sync stuff! QString sentSyncFile(); QPopupMenu *syncMenu; KSyncManager* syncManager; int mGlobalSyncMode; bool synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode); KABC::Addressee getLastSyncAddressee(); QDateTime mLastAddressbookSync; int takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ); // ********************* }; #endif diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index c39413e..3555dc6 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp @@ -246,106 +246,102 @@ ulong PhoneFormat::getCsumEvent( Event* event ) list.append( "0" ); list.append( "20991231T000000" ); } } attList << list.join(""); attList << event->categoriesStr(); //qDebug("csum cat %s", event->categoriesStr().latin1()); attList << event->secrecyStr(); return PhoneFormat::getCsum(attList ); } ulong PhoneFormat::getCsum( const QStringList & attList) { int max = attList.count(); ulong cSum = 0; int j,k,i; int add; for ( i = 0; i < max ; ++i ) { QString s = attList[i]; if ( ! s.isEmpty() ){ j = s.length(); for ( k = 0; k < j; ++k ) { int mul = k +1; add = s[k].unicode (); if ( k < 16 ) mul = mul * mul; int ii = i+1; add = add * mul *ii*ii*ii; cSum += add; } } } //QString dump = attList.join(","); //qDebug("csum: %d %s", cSum,dump.latin1()); return cSum; } //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); #include <stdlib.h> #define DEBUGMODE false bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) { QString fileName; #ifdef _WIN32_ - fileName = locateLocal("tmp", "tempfile.vcs"); + fileName = locateLocal("tmp", "phonefile.vcs"); #else - fileName = "/tmp/kdepimtemp.vcs"; + fileName = "/tmp/phonefile.vcs"; #endif -#ifdef DESKTOP_VERSION - QString command ="./kammu --backup " + fileName + " -yes" ; -#else - QString command ="kammu --backup " + fileName + " -yes" ; -#endif - int ret = system ( command.latin1() ); + QString command; + int ret = PhoneAccess::readFromPhone( fileName ); if ( ret != 0 ) { qDebug("Error::command returned %d", ret); return false; } VCalFormat vfload; vfload.setLocalTime ( true ); qDebug("loading file ..."); if ( ! vfload.load( calendar, fileName ) ) return false; QPtrList<Event> er = calendar->rawEvents(); Event* ev = er.first(); qDebug("reading events... "); while ( ev ) { QStringList cat = ev->categories(); if ( cat.contains( "MeetingDEF" )) { ev->setCategories( QStringList() ); } int id = ev->pilotId(); Event *event; event = existingCal->event( mProfileName ,QString::number( id ) ); if ( event ) { event = (Event*)event->clone(); copyEvent( event, ev ); calendar->deleteEvent( ev ); calendar->addEvent( event); } else event = ev; uint cSum; cSum = PhoneFormat::getCsumEvent( event ); event->setCsum( mProfileName, QString::number( cSum )); event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); event->setID( mProfileName,QString::number( id ) ); ev = er.next(); } { qDebug("reading todos... "); QPtrList<Todo> tr = calendar->rawTodos(); Todo* ev = tr.first(); while ( ev ) { QStringList cat = ev->categories(); if ( cat.contains( "MeetingDEF" )) { ev->setCategories( QStringList() ); } int id = ev->pilotId(); Todo *event; diff --git a/libkdepim/phoneaccess.cpp b/libkdepim/phoneaccess.cpp index fe914dd..5fafa1f 100644 --- a/libkdepim/phoneaccess.cpp +++ b/libkdepim/phoneaccess.cpp @@ -98,54 +98,76 @@ void PhoneAccess::writeConfig( QString device, QString connection, QString model write = true; content += "connection = "; content += connection; content += "\n"; } if ( addPort ) { write = true; content += "port = "; content += device; content += "\n"; } if ( addModel ) { write = true; content += "model = "; content += model; content += "\n"; } if ( write ) { if (!file.open( IO_WriteOnly ) ) { qDebug("Error: cannot write file %s ", fileName.latin1() ); return; } qDebug("Writing file %s ", fileName.latin1() ); QTextStream ts( &file ); ts << content ; file.close(); } } bool PhoneAccess::writeToPhone( QString fileName) { #ifdef DESKTOP_VERSION #ifdef _WIN32_ QString command ="kammu --restore " + fileName ; #else QString command ="./kammu --restore " + fileName ; #endif #else QString command ="kammu --restore " + fileName ; #endif int ret; while ( (ret = system ( command.latin1())) != 0 ) { qDebug("Error S::command returned %d.", ret); int retval = KMessageBox::warningContinueCancel(0, - i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone access"),i18n("Retry"),i18n("Cancel")); + i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KDE/Pim phone access"),i18n("Retry"),i18n("Cancel")); + if ( retval != KMessageBox::Continue ) + return false; + } + return true; +} +bool PhoneAccess::readFromPhone( QString fileName) +{ + +#ifdef DESKTOP_VERSION +#ifdef _WIN32_ + QString command ="kammu --backup " + fileName + " -yes" ; +#else + QString command ="./kammu --backup " + fileName + " -yes" ; +#endif +#else + QString command ="kammu --backup " + fileName + " -yes" ; +#endif + int ret; + while ( (ret = system ( command.latin1())) != 0 ) { + qDebug("Error S::command returned %d.", ret); + int retval = KMessageBox::warningContinueCancel(0, + i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KDE/Pim phone access"),i18n("Retry"),i18n("Cancel")); if ( retval != KMessageBox::Continue ) return false; } return true; } diff --git a/libkdepim/phoneaccess.h b/libkdepim/phoneaccess.h index b7c4732..80840e2 100644 --- a/libkdepim/phoneaccess.h +++ b/libkdepim/phoneaccess.h @@ -1,42 +1,44 @@ /* This file is part of libkcal. Copyright (c) 2003 Cornelius Schumacher <schumacher@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. */ #ifndef PHONEACCESS_H #define PHONEACCESS_H #include <qstring.h> +#include <qobject.h> /** This class implements the calendar format used by Phone. */ class PhoneAccess : public QObject { public: static void writeConfig( QString device,QString connection, QString model ); static bool writeToPhone( QString fileName ); + static bool readFromPhone( QString fileName ); }; #endif |