-rw-r--r-- | kabc/addressbook.cpp | 101 | ||||
-rw-r--r-- | kabc/addressbook.h | 1 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 95 | ||||
-rw-r--r-- | kaddressbook/kabcore.h | 5 |
4 files changed, 186 insertions, 16 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 47d298a..70eda1b 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -189,152 +189,249 @@ AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) { (d->mIt)++; return *this; } AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() { (d->mIt)--; return *this; } AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) { (d->mIt)--; return *this; } bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) { return ( d->mIt == it.d->mIt ); } bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) { return ( d->mIt != it.d->mIt ); } AddressBook::AddressBook() { init(0, "contact"); } AddressBook::AddressBook( const QString &config ) { init(config, "contact"); } AddressBook::AddressBook( const QString &config, const QString &family ) { init(config, family); } // the default family is "contact" void AddressBook::init(const QString &config, const QString &family ) { d = new AddressBookData; + QString fami = family; + qDebug("new ab "); if (config != 0) { + qDebug("config != 0 "); + if ( family == "syncContact" ) { + qDebug("creating sync config "); + fami = "contact"; + KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); + con->setGroup( "General" ); + con->writeEntry( "ResourceKeys", QString("sync") ); + con->writeEntry( "Standard", QString("sync") ); + con->setGroup( "Resource_sync" ); + con->writeEntry( "FileFormat", QString("vcard") ); + con->writeEntry( "FileName", config ); + con->writeEntry( "ResourceIdentifier", QString("sync") ); + con->writeEntry( "ResourceName", QString("sync_res") ); + con->writeEntry( "ResourceType", QString("file") ); + //con->sync(); + d->mConfig = con; + } + else d->mConfig = new KConfig( locateLocal("config", config) ); // qDebug("AddressBook::init 1 config=%s",config.latin1() ); } else { d->mConfig = 0; // qDebug("AddressBook::init 1 config=0"); } //US d->mErrorHandler = 0; - d->mManager = new KRES::Manager<Resource>( family, false ); + d->mManager = new KRES::Manager<Resource>( fami, false ); d->mManager->readConfig( d->mConfig ); + if ( family == "syncContact" ) { + KRES::Manager<Resource> *manager = d->mManager; + KRES::Manager<Resource>::ActiveIterator it; + for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { + (*it)->setAddressBook( this ); + if ( !(*it)->open() ) + error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); + } + Resource *res = standardResource(); + if ( !res ) { + qDebug("ERROR: no standard resource"); + res = manager->createResource( "file" ); + if ( res ) + { + addResource( res ); + } + else + qDebug(" No resource available!!!"); + } + setStandardResource( res ); + manager->writeConfig(); + } + addCustomField( i18n( "Department" ), KABC::Field::Organization, + "X-Department", "KADDRESSBOOK" ); + addCustomField( i18n( "Profession" ), KABC::Field::Organization, + "X-Profession", "KADDRESSBOOK" ); + addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, + "X-AssistantsName", "KADDRESSBOOK" ); + addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, + "X-ManagersName", "KADDRESSBOOK" ); + addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, + "X-SpousesName", "KADDRESSBOOK" ); + addCustomField( i18n( "Office" ), KABC::Field::Personal, + "X-Office", "KADDRESSBOOK" ); + addCustomField( i18n( "IM Address" ), KABC::Field::Personal, + "X-IMAddress", "KADDRESSBOOK" ); + addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, + "X-Anniversary", "KADDRESSBOOK" ); + + //US added this field to become compatible with Opie/qtopia addressbook + // values can be "female" or "male" or "". An empty field represents undefined. + addCustomField( i18n( "Gender" ), KABC::Field::Personal, + "X-Gender", "KADDRESSBOOK" ); + addCustomField( i18n( "Children" ), KABC::Field::Personal, + "X-Children", "KADDRESSBOOK" ); + addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, + "X-FreeBusyUrl", "KADDRESSBOOK" ); + addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, + "X-ExternalID", "KADDRESSBOOK" ); } AddressBook::~AddressBook() { delete d->mConfig; d->mConfig = 0; delete d->mManager; d->mManager = 0; //US delete d->mErrorHandler; d->mErrorHandler = 0; delete d; d = 0; } bool AddressBook::load() { clear(); KRES::Manager<Resource>::ActiveIterator it; bool ok = true; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) if ( !(*it)->load() ) { error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); ok = false; } // mark all addressees as unchanged Addressee::List::Iterator addrIt; for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) (*addrIt).setChanged( false ); return ok; } bool AddressBook::save( Ticket *ticket ) { kdDebug(5700) << "AddressBook::save()"<< endl; if ( ticket->resource() ) { deleteRemovedAddressees(); - return ticket->resource()->save( ticket ); } return false; } +bool AddressBook::saveAB() +{ + bool ok = true; + + deleteRemovedAddressees(); + + 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; } AddressBook::Iterator AddressBook::end() { Iterator it = Iterator(); it.d->mIt = d->mAddressees.end(); return it; } AddressBook::ConstIterator AddressBook::end() const { ConstIterator it = ConstIterator(); it.d->mIt = d->mAddressees.end(); return it; } void AddressBook::clear() { d->mAddressees.clear(); } Ticket *AddressBook::requestSaveTicket( Resource *resource ) { kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; if ( !resource ) { qDebug("AddressBook::requestSaveTicket no resource" ); resource = standardResource(); } KRES::Manager<Resource>::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { if ( (*it) == resource ) { if ( (*it)->readOnly() || !(*it)->isOpen() ) diff --git a/kabc/addressbook.h b/kabc/addressbook.h index f89d7da..e43de31 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h @@ -96,96 +96,97 @@ class AddressBook : public QObject ~ConstIterator(); 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( ); /** 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 & ); /** 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 & ); /** Find the specified entry in address book. Returns end(), if the entry couldn't be found. */ diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 49c3b19..e912941 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -103,153 +103,156 @@ $Id$ #endif // KAB_EMBEDDED #include "kcmconfigs/kcmkabconfig.h" #include "kcmconfigs/kcmkdepimconfig.h" #include "kpimglobalprefs.h" #include "externalapphandler.h" #include <kresources/selectdialog.h> #include <kmessagebox.h> #include <picture.h> #include <resource.h> //US#include <qsplitter.h> #include <qmap.h> #include <qdir.h> #include <qfile.h> #include <qvbox.h> #include <qlayout.h> #include <qclipboard.h> #include <qtextstream.h> #include <libkdepim/categoryselectdialog.h> #include <kabc/vcardconverter.h> #include "addresseeutil.h" #include "undocmds.h" #include "addresseeeditordialog.h" #include "viewmanager.h" #include "details/detailsviewcontainer.h" #include "kabprefs.h" #include "xxportmanager.h" #include "incsearchwidget.h" #include "jumpbuttonbar.h" #include "extensionmanager.h" #include "addresseeconfig.h" #include <kcmultidialog.h> #ifdef _WIN32_ #include "kaimportoldialog.h" #else #include <unistd.h> #endif // sync includes #include <libkdepim/ksyncprofile.h> +#include <libkdepim/ksyncprefsdialog.h> bool pasteWithNewUid = true; #ifdef KAB_EMBEDDED KABCore::KABCore( KAddressBookMain *client, bool readWrite, QWidget *parent, const char *name ) : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ), mExtensionManager( 0 ),mConfigureDialog( 0 ),/*US mLdapSearchDialog( 0 ),*/ mReadWrite( readWrite ), mModified( false ), mMainWindow(client) #else //KAB_EMBEDDED KABCore::KABCore( KXMLGUIClient *client, bool readWrite, QWidget *parent, const char *name ) : QWidget( parent, name ), mGUIClient( client ), mViewManager( 0 ), mExtensionManager( 0 ), mConfigureDialog( 0 ), mLdapSearchDialog( 0 ), mReadWrite( readWrite ), mModified( false ) #endif //KAB_EMBEDDED { mBlockSaveFlag = false; mExtensionBarSplitter = 0; mIsPart = !parent->inherits( "KAddressBookMain" ); mAddressBook = KABC::StdAddressBook::self(); KABC::StdAddressBook::setAutomaticSave( false ); #ifndef KAB_EMBEDDED mAddressBook->setErrorHandler( new KABC::GUIErrorHandler ); #endif //KAB_EMBEDDED connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook * ) ), SLOT( addressBookChanged() ) ); +#if 0 + // LP moved to addressbook init method mAddressBook->addCustomField( i18n( "Department" ), KABC::Field::Organization, "X-Department", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Profession" ), KABC::Field::Organization, "X-Profession", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, "X-AssistantsName", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, "X-ManagersName", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, "X-SpousesName", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Office" ), KABC::Field::Personal, "X-Office", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "IM Address" ), KABC::Field::Personal, "X-IMAddress", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, "X-Anniversary", "KADDRESSBOOK" ); //US added this field to become compatible with Opie/qtopia addressbook // values can be "female" or "male" or "". An empty field represents undefined. mAddressBook->addCustomField( i18n( "Gender" ), KABC::Field::Personal, "X-Gender", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "Children" ), KABC::Field::Personal, "X-Children", "KADDRESSBOOK" ); mAddressBook->addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, "X-FreeBusyUrl", "KADDRESSBOOK" ); - +#endif initGUI(); mIncSearchWidget->setFocus(); connect( mViewManager, SIGNAL( selected( const QString& ) ), SLOT( setContactSelected( const QString& ) ) ); connect( mViewManager, SIGNAL( executed( const QString& ) ), SLOT( executeContact( const QString& ) ) ); connect( mViewManager, SIGNAL( deleteRequest( ) ), SLOT( deleteContacts( ) ) ); connect( mViewManager, SIGNAL( modified() ), SLOT( setModified() ) ); connect( mExtensionManager, SIGNAL( modified( const KABC::Addressee::List& ) ), this, SLOT( extensionModified( const KABC::Addressee::List& ) ) ); connect( mExtensionManager, SIGNAL( changedActiveExtension( int ) ), this, SLOT( extensionChanged( int ) ) ); connect( mXXPortManager, SIGNAL( modified() ), SLOT( setModified() ) ); connect( mJumpButtonBar, SIGNAL( jumpToLetter( const QString& ) ), SLOT( incrementalSearch( const QString& ) ) ); connect( mIncSearchWidget, SIGNAL( fieldChanged() ), mJumpButtonBar, SLOT( recreateButtons() ) ); connect( mDetails, SIGNAL( sendEmail( const QString& ) ), SLOT( sendMail( const QString& ) ) ); connect( ExternalAppHandler::instance(), SIGNAL (requestForNameEmailUidList(const QString&, const QString&)),this, SLOT(requestForNameEmailUidList(const QString&, const QString&))); connect( ExternalAppHandler::instance(), SIGNAL (requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&)),this, SLOT(requestForDetails(const QString&, const QString&, const QString&, const QString&, const QString&))); #ifndef KAB_EMBEDDED connect( mViewManager, SIGNAL( urlDropped( const KURL& ) ), mXXPortManager, SLOT( importVCard( const KURL& ) ) ); connect( mDetails, SIGNAL( browse( const QString& ) ), SLOT( browse( const QString& ) ) ); mAddressBookService = new KAddressBookService( this ); #endif //KAB_EMBEDDED mEditorDialog = 0; createAddresseeEditorDialog( this ); setModified( false ); @@ -2150,98 +2153,98 @@ void KABCore::fillSyncMenu() void KABCore::slotSyncMenu( int action ) { //qDebug("syncaction %d ", action); if ( action == 0 ) { // seems to be a Qt2 event handling bug // syncmenu.clear causes a segfault at first time // when we call it after the main event loop, it is ok // same behaviour when calling OM/Pi via QCOP for the first time QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); //confSync(); return; } if ( action == 1 ) { multiSync( true ); return; } if (mBlockSaveFlag) return; mBlockSaveFlag = true; mCurrentSyncProfile = action - 1000 ; mCurrentSyncDevice = KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ; mCurrentSyncName = KABPrefs::instance()->mLocalMachineName ; KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); KSyncProfile* temp = new KSyncProfile (); temp->setName(KABPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); temp->readConfig(&config); KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); KABPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); KABPrefs::instance()->mWriteBackInFuture = 0; if ( temp->getWriteBackFuture() ) KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); KABPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); if ( action == 1000 ) { syncSharp(); } else if ( action == 1001 ) { syncLocalFile(); } else if ( action == 1002 ) { quickSyncLocalFile(); } else if ( action >= 1003 ) { if ( temp->getIsLocalFileSync() ) { - if ( syncWithFile( temp->getRemoteFileName( ), false ) ) - KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName(); + if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) + KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); } else { if ( temp->getIsPhoneSync() ) { KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); syncPhone(); } else syncRemote( temp ); } } delete temp; mBlockSaveFlag = false; } void KABCore::syncLocalFile() { QString fn =KABPrefs::instance()->mLastSyncedLocalFile; fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); if ( fn == "" ) return; if ( syncWithFile( fn, false ) ) { qDebug("syncLocalFile() successful "); } } bool KABCore::syncWithFile( QString fn , bool quick ) { bool ret = false; QFileInfo info; info.setFile( fn ); QString mess; bool loadbup = true; if ( !info. exists() ) { mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), mess ); return ret; } int result = 0; if ( !quick ) { mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), mess, i18n("Sync"), i18n("Cancel"), 0, 0, 1 ); @@ -2272,191 +2275,191 @@ void KABCore::quickSyncLocalFile() } void KABCore::multiSync( bool askforPrefs ) { if (mBlockSaveFlag) return; mBlockSaveFlag = true; QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); if ( QMessageBox::information( this, i18n("KO/Pi Sync"), question, i18n("Yes"), i18n("No"), 0, 0 ) != 0 ) { mBlockSaveFlag = false; setCaption(i18n("Aborted! Nothing synced!")); return; } mCurrentSyncDevice = i18n("Multiple profiles") ; KABPrefs::instance()->mSyncAlgoPrefs = KABPrefs::instance()->mRingSyncAlgoPrefs; if ( askforPrefs ) { edit_sync_options(); KABPrefs::instance()->mRingSyncAlgoPrefs = KABPrefs::instance()->mSyncAlgoPrefs; } setCaption(i18n("Multiple sync started.") ); qApp->processEvents(); int num = ringSync() ; if ( num > 1 ) ringSync(); mBlockSaveFlag = false; if ( num ) save(); if ( num ) setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); else setCaption(i18n("Nothing synced! No profiles defined for multisync!")); return; } int KABCore::ringSync() { int syncedProfiles = 0; int i; QTime timer; KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); QStringList syncProfileNames = KABPrefs::instance()->mSyncProfileNames; KSyncProfile* temp = new KSyncProfile (); KABPrefs::instance()->mAskForPreferences = false; for ( i = 0; i < syncProfileNames.count(); ++i ) { mCurrentSyncProfile = i; temp->setName(syncProfileNames[mCurrentSyncProfile]); temp->readConfig(&config); - if ( temp->getIncludeInRingSync() && ( i < 1 || i > 2 )) { + if ( temp->getIncludeInRingSyncAB() && ( i < 1 || i > 2 )) { setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); ++syncedProfiles; // KABPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); KABPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); KABPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); KABPrefs::instance()->mWriteBackInFuture = 0; if ( temp->getWriteBackFuture() ) KABPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); KABPrefs::instance()->mShowSyncSummary = false; mCurrentSyncDevice = syncProfileNames[i] ; mCurrentSyncName = KABPrefs::instance()->mLocalMachineName; if ( i == 0 ) { syncSharp(); } else { if ( temp->getIsLocalFileSync() ) { - if ( syncWithFile( temp->getRemoteFileName( ), true ) ) - KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName(); + if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) ) + KABPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); } else { if ( temp->getIsPhoneSync() ) { KABPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; KABPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); KABPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); syncPhone(); } else syncRemote( temp, false ); } } timer.start(); setCaption(i18n("Multiple sync in progress ... please wait!") ); while ( timer.elapsed () < 2000 ) { qApp->processEvents(); #ifndef _WIN32_ sleep (1); #endif } } } delete temp; return syncedProfiles; } void KABCore::syncRemote( KSyncProfile* prof, bool ask) { QString question; if ( ask ) { question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; if ( QMessageBox::information( this, i18n("KO/Pi Sync"), question, i18n("Yes"), i18n("No"), 0, 0 ) != 0 ) return; } - QString command = prof->getPreSyncCommand(); + QString command = prof->getPreSyncCommandAB(); int fi; if ( (fi = command.find("$PWD$")) > 0 ) { QString pwd = getPassword(); command = command.left( fi )+ pwd + command.mid( fi+5 ); } int maxlen = 30; if ( QApplication::desktop()->width() > 320 ) maxlen += 25; setCaption ( i18n( "Copy remote file to local machine..." ) ); int fileSize = 0; int result = system ( command ); // 0 : okay // 256: no such file or dir // qDebug("KO: Remote copy result(0 = okay): %d ",result ); if ( result != 0 ) { int len = maxlen; while ( len < command.length() ) { command.insert( len , "\n" ); len += maxlen +2; } question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (command) ; QMessageBox::information( this, i18n("KO/Pi Sync - ERROR"), question, i18n("Okay!")) ; setCaption ("KO/Pi"); return; } setCaption ( i18n( "Copying succeed." ) ); //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); - if ( syncWithFile( prof->getLocalTempFile(), true ) ) { + if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) { // Event* e = mView->getLastSyncEvent(); // e->setReadOnly( false ); // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); // e->setReadOnly( true ); if ( KABPrefs::instance()->mWriteBackFile ) { - command = prof->getPostSyncCommand(); + command = prof->getPostSyncCommandAB(); int fi; if ( (fi = command.find("$PWD$")) > 0 ) { QString pwd = getPassword(); command = command.left( fi )+ pwd + command.mid( fi+5 ); } setCaption ( i18n( "Writing back file ..." ) ); result = system ( command ); qDebug("KO: Writing back file result: %d ", result); if ( result != 0 ) { setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); return; } else { setCaption ( i18n( "Syncronization sucessfully completed" ) ); } } } return; } #include <qpushbutton.h> #include <qradiobutton.h> #include <qbuttongroup.h> void KABCore::edit_sync_options() { //mDialogManager->showSyncOptions(); //KABPrefs::instance()->mSyncAlgoPrefs QDialog dia( this, "dia", true ); dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); QVBoxLayout lay ( &dia ); lay.setSpacing( 2 ); lay.setMargin( 3 ); lay.addWidget(&gr); QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); //QRadioButton both( i18n("Take both on conflict"), &gr ); QPushButton pb ( "OK", &dia); lay.addWidget( &pb ); connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); switch ( KABPrefs::instance()->mSyncAlgoPrefs ) { case 0: loc.setChecked( true); break; case 1: @@ -2465,79 +2468,145 @@ void KABCore::edit_sync_options() case 2: newest.setChecked( true); break; case 3: ask.setChecked( true); break; case 4: f_loc.setChecked( true); break; case 5: f_rem.setChecked( true); break; case 6: // both.setChecked( true); break; default: break; } if ( dia.exec() ) { KABPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; } } QString KABCore::getPassword( ) { QString retfile = ""; QDialog dia ( this, "input-dialog", true ); QLineEdit lab ( &dia ); lab.setEchoMode( QLineEdit::Password ); QVBoxLayout lay( &dia ); lay.setMargin(7); lay.setSpacing(7); lay.addWidget( &lab); dia.setFixedSize( 230,50 ); dia.setCaption( i18n("Enter password") ); QPushButton pb ( "OK", &dia); lay.addWidget( &pb ); connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); dia.show(); int res = dia.exec(); if ( res ) retfile = lab.text(); dia.hide(); qApp->processEvents(); return retfile; } +bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) +{ +} bool KABCore::syncAB(QString filename, int mode) { + + + mGlobalSyncMode = SYNC_MODE_NORMAL; + AddressBook abLocal(filename,"syncContact"); + bool syncOK = false; + if ( abLocal.load() ) { + qDebug("AB loaded %s mode %d",filename.latin1(), mode ); + 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 ( KABPrefs::instance()->mWriteBackFile ) + { + abLocal.saveAB(); + } + } + setModified(); + + } + if ( syncOK ) + ;//updateView(); + return syncOK; +#if 0 + mGlobalSyncMode = SYNC_MODE_NORMAL; + CalendarLocal* calendar = new CalendarLocal(); + calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); + FileStorage* storage = new FileStorage( calendar ); + bool syncOK = false; + storage->setFileName( filename ); + // qDebug("loading ... "); + 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(); + } + delete storage; + delete calendar; + if ( syncOK ) + updateView(); + return syncOK; +#endif } void KABCore::confSync() -{ - //mView->confSync(); - qDebug("pending KABCore::confSync() "); +{ + static KSyncPrefsDialog* sp = 0; + if ( ! sp ) { + sp = new KSyncPrefsDialog( this, "syncprefs", true ); + } + sp->usrReadConfig(); +#ifndef DESKTOP_VERSION + sp->showMaximized(); +#else + sp->show(); +#endif + sp->exec(); + KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); + KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); fillSyncMenu(); } void KABCore::syncSharp() { if ( mModified ) save(); qDebug("pending syncSharp() "); //mView->syncSharp(); - mModified = true ; + setModified(); } void KABCore::syncPhone() { if ( mModified ) save(); qDebug("pending syncPhone(); "); //mView->syncPhone(); setModified(); } diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h index 10ce8f4..4487a8a 100644 --- a/kaddressbook/kabcore.h +++ b/kaddressbook/kabcore.h @@ -411,68 +411,71 @@ class KABCore : public QWidget 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; bool mBlockSaveFlag; #ifdef KAB_EMBEDDED KAddressBookMain *mMainWindow; // should be the same like mGUIClient #endif //KAB_EMBEDDED // LR ******************************* // sync stuff! QPopupMenu *syncMenu; void fillSyncMenu(); - void confSync(); QString mCurrentSyncDevice; QString mCurrentSyncName; void quickSyncLocalFile(); bool syncWithFile( QString fn , bool quick ); void KABCore::syncLocalFile(); void KABCore::syncPhone(); void KABCore::syncSharp(); void multiSync( bool askforPrefs ); int mCurrentSyncProfile ; void syncRemote( KSyncProfile* prof, bool ask = true); void edit_sync_options(); bool syncAB(QString filename, int mode); int ringSync(); QString getPassword( ); + int mGlobalSyncMode; + bool synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode); + public slots: + void confSync(); // ********************* }; #endif |