-rw-r--r-- | kaddressbook/kabcore.cpp | 14 | ||||
-rw-r--r-- | korganizer/calendarview.cpp | 14 | ||||
-rw-r--r-- | korganizer/calendarview.h | 2 | ||||
-rw-r--r-- | korganizer/mainwindow.cpp | 1 | ||||
-rw-r--r-- | libkdepim/kpimprefs.h | 18 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.cpp | 100 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.h | 20 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.cpp | 6 |
8 files changed, 79 insertions, 96 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index b014cba..9041e45 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -2560,248 +2560,248 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo inL = inR; inL.setResource( 0 ); local->insertAddressee( inL , false); ++addedAddressee; } } else { if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { inR.setRevision( modifiedCalendar ); remote->insertAddressee( inR, false ); inR.setResource( 0 ); local->insertAddressee( inR, false ); ++addedAddressee; } else { // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); remote->removeAddressee( inR ); ++deletedAddresseeR; } } } } ++incCounter; } er.clear(); QStringList el = local->uidList(); modulo = (el.count()/10)+1; syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); incCounter = 0; while ( incCounter < el.count()) { qApp->processEvents(); if (syncManager->isProgressBarCanceled()) return false; if ( incCounter % modulo == 0 ) syncManager->showProgressBar(incCounter); uid = el[ incCounter ]; bool skipIncidence = false; if ( uid.left(19) == QString("last-syncAddressee-") ) skipIncidence = true; if ( !skipIncidence ) { inL = local->findByUid( uid ); inR = remote->findByUid( uid ); if ( inR.isEmpty() ) { if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); local->removeAddressee( inL ); ++deletedAddresseeL; } else { - if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { + if ( ! syncManager->mWriteBackExistingOnly ) { inL.removeID(mCurrentSyncDevice ); ++addedAddresseeR; inL.setRevision( modifiedCalendar ); local->insertAddressee( inL, false ); inR = inL; inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); inR.setResource( 0 ); remote->insertAddressee( inR, false ); } } } else { if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); local->removeAddressee( inL ); ++deletedAddresseeL; } else { - if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { + if ( ! syncManager->mWriteBackExistingOnly ) { ++addedAddresseeR; inL.setRevision( modifiedCalendar ); local->insertAddressee( inL, false ); inR = inL; inR.setResource( 0 ); remote->insertAddressee( inR, false ); } } } } } ++incCounter; } el.clear(); syncManager->hideProgressBar(); mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); // get rid of micro seconds QTime t = mLastAddressbookSync.time(); mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); addresseeLSync.setRevision( mLastAddressbookSync ); addresseeRSync.setRevision( mLastAddressbookSync ); addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); addresseeRSync.setNote( "" ) ; addresseeLSync.setNote( "" ); if ( mGlobalSyncMode == SYNC_MODE_NORMAL) remote->insertAddressee( addresseeRSync, false ); local->insertAddressee( addresseeLSync, false ); QString mes; mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); - if ( KABPrefs::instance()->mShowSyncSummary ) { + if ( syncManager->mShowSyncSummary ) { KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); } qDebug( mes ); return syncOK; } //this is a overwritten callbackmethods from the syncinterface bool KABCore::sync(KSyncManager* manager, QString filename, int mode) -{ +{ //pending prepare addresseeview for output //pending detect, if remote file has REV field. if not switch to external sync mGlobalSyncMode = SYNC_MODE_NORMAL; QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); AddressBook abLocal(filename,"syncContact"); bool syncOK = false; if ( abLocal.load() ) { qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); bool external = false; bool isXML = false; if ( filename.right(4) == ".xml") { mGlobalSyncMode = SYNC_MODE_EXTERNAL; isXML = true; abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); } else { Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); if ( ! lse.isEmpty() ) { if ( lse.familyName().left(4) == "!E: " ) external = true; } 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 ( KABPrefs::instance()->mWriteBackFile ) + if ( syncManager->mWriteBackFile ) { if ( external ) abLocal.removeSyncAddressees( !isXML); qDebug("Saving remote AB "); abLocal.saveAB(); 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) { 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 ); qDebug("KABCore::syncExternal: why do we acces here KABPrefs and not somehow KSyncProfile? "); - syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, KABPrefs::instance()->mSyncAlgoPrefs ); + syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); if ( syncOK ) { - if ( KABPrefs::instance()->mWriteBackFile ) { + if ( syncManager->mWriteBackFile ) { abLocal.saveAB(); abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); } } setModified(); } if ( syncOK ) mViewManager->refreshView(); return syncOK; } //called by the syncmanager to indicate that the work has to marked as dirty. void KABCore::sync_setModified() { setModified(); } //called by the syncmanager to ask if the dirty flag is set. bool KABCore::sync_isModified() { return mModified; } //called by the syncmanager to indicate that the work has to be saved. void KABCore::sync_save() { save(); } diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 38b55f7..1de2759 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp @@ -832,111 +832,97 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b if ( localIsNew ) getEventViewerDialog()->setColorMode( 2 ); else getEventViewerDialog()->setColorMode( 1 ); getEventViewerDialog()->addIncidence(remote); getEventViewerDialog()->setColorMode( 0 ); //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); getEventViewerDialog()->showMe(); result = getEventViewerDialog()->executeS( localIsNew ); return result; break; case SYNC_PREF_FORCE_LOCAL: return 1; break; case SYNC_PREF_FORCE_REMOTE: return 2; break; default: // SYNC_PREF_TAKE_BOTH not implemented break; } return 0; } Event* CalendarView::getLastSyncEvent() { Event* lse; //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); if (!lse) { lse = new Event(); lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); QString sum = ""; if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) sum = "E: "; lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); lse->setDtStart( mLastCalendarSync ); lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); lse->setCategories( i18n("SyncEvent") ); lse->setReadOnly( true ); mCalendar->addEvent( lse ); } return lse; } -// probaly useless -void CalendarView::setupExternSyncProfiles() -{ - Event* lse; - mExternLastSyncEvent.clear(); - int i; - for ( i = 0; i < KOPrefs::instance()->mExternSyncProfiles.count(); ++i ) { - lse = mCalendar->event( "last-syncEvent-"+ KOPrefs::instance()->mExternSyncProfiles[i] ); - if ( lse ) - mExternLastSyncEvent.append( lse ); - else - qDebug("Last Sync event not found for %s ", KOPrefs::instance()->mExternSyncProfiles[i].latin1()); - } -} // we check, if the to delete event has a id for a profile // if yes, we set this id in the profile to delete void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) { if ( lastSync.count() == 0 ) { //qDebug(" lastSync.count() == 0"); return; } if ( toDelete->type() == "Journal" ) return; Event* eve = lastSync.first(); while ( eve ) { QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name if ( !id.isEmpty() ) { QString des = eve->description(); QString pref = "e"; if ( toDelete->type() == "Todo" ) pref = "t"; des += pref+ id + ","; eve->setReadOnly( false ); eve->setDescription( des ); //qDebug("setdes %s ", des.latin1()); eve->setReadOnly( true ); } eve = lastSync.next(); } } void CalendarView::checkExternalId( Incidence * inc ) { QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; checkExternSyncEvent( lastSync, inc ); } bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) { bool syncOK = true; int addedEvent = 0; int addedEventR = 0; int deletedEventR = 0; int deletedEventL = 0; int changedLocal = 0; int changedRemote = 0; //QPtrList<Event> el = local->rawEvents(); Event* eventR; QString uid; diff --git a/korganizer/calendarview.h b/korganizer/calendarview.h index a713c91..0f7e696 100644 --- a/korganizer/calendarview.h +++ b/korganizer/calendarview.h @@ -68,97 +68,96 @@ namespace KCal { class FileStorage; } using namespace KCal; /** This is the main calendar widget. It provides the different vies on t he calendar data as well as the date navigator. It also handles synchronisation of the different views and controls the different dialogs like preferences, event editor, search dialog etc. @short main calendar view widget @author Cornelius Schumacher */ class CalendarView : public KOrg::CalendarViewBase, public KCal::Calendar::Observer { Q_OBJECT public: /** Constructs a new calendar view widget. @param calendar calendar document @param parent parent window @param name Qt internal widget object name */ CalendarView( CalendarResources *calendar, QWidget *parent = 0, const char *name = 0 ); CalendarView( Calendar *calendar, QWidget *parent = 0, const char *name = 0 ); virtual ~CalendarView(); Calendar *calendar() { return mCalendar; } KOViewManager *viewManager(); KODialogManager *dialogManager(); QDate startDate(); QDate endDate(); QWidgetStack *viewStack(); QWidget *leftFrame(); NavigatorBar *navigatorBar(); DateNavigator *dateNavigator(); KDateNavigator *dateNavigatorWidget(); void addView(KOrg::BaseView *); void showView(KOrg::BaseView *); KOEventViewerDialog* getEventViewerDialog(); Incidence *currentSelection(); - void setupExternSyncProfiles(); signals: /** This todo has been modified */ void todoModified(Todo *, int); /** when change is made to options dialog, the topwidget will catch this * and emit this signal which notifies all widgets which have registered * for notification to update their settings. */ void configChanged(); /** emitted when the topwidget is closing down, so that any attached child windows can also close. */ void closingDown(); /** emitted right before we die */ void closed(QWidget *); /** Emitted when state of modified flag changes */ void modifiedChanged(bool); void signalmodified(); /** Emitted when state of read-only flag changes */ void readOnlyChanged(bool); /** Emitted when the unit of navigation changes */ void changeNavStringPrev(const QString &); void changeNavStringNext(const QString &); /** Emitted when state of events selection has changed and user is organizer*/ void organizerEventsSelected(bool); /** Emitted when state of events selection has changed and user is attendee*/ void groupEventsSelected(bool); /** Emitted when an incidence gets selected. If the selection is cleared the signal is emitted with 0 as argument. */ void incidenceSelected( Incidence * ); /** Emitted, when a todoitem is selected or deselected. */ void todoSelected( bool ); /** Emitted, when clipboard content changes. Parameter indicates if paste is possible or not. */ void pasteEnabled(bool); /** Emitted, when the number of incoming messages has changed. */ void numIncomingChanged(int); /** Emitted, when the number of outgoing messages has changed. */ @@ -499,97 +498,96 @@ class CalendarView : public KOrg::CalendarViewBase, public KCal::Calendar::Obser KOBeamPrefs* beamDialog; void init(); int mDatePickerMode; bool mFlagEditDescription; QDateTime mLastCalendarSync; void createPrinter(); void calendarModified( bool, Calendar * ); CalPrinter *mCalPrinter; QSplitter *mPanner; QSplitter *mLeftSplitter; QWidget *mLeftFrame; QWidgetStack *mRightFrame; KDatePicker* mDatePicker; QVBox* mDateFrame; NavigatorBar *mNavigatorBar; KDateNavigator *mDateNavigator; // widget showing small month view. KOFilterView *mFilterView; ResourceView *mResourceView; // calendar object for this viewing instance Calendar *mCalendar; CalendarResourceManager *mResourceManager; FileStorage *mStorage; DateNavigator *mNavigator; KOViewManager *mViewManager; KODialogManager *mDialogManager; // Calendar filters QPtrList<CalFilter> mFilters; // various housekeeping variables. bool mModified; // flag indicating if calendar is modified bool mReadOnly; // flag indicating if calendar is read-only QDate mSaveSingleDate; Incidence *mSelectedIncidence; Incidence *mMoveIncidence; - QPtrList<Event> mExternLastSyncEvent; KOTodoView *mTodoList; KOEventEditor * mEventEditor; KOTodoEditor * mTodoEditor; KOEventViewerDialog * mEventViewerDialog; void keyPressEvent ( QKeyEvent *e) ; //QMap<Incidence*,KOIncidenceEditor*> mDialogList; }; class CalendarViewVisitor : public Incidence::Visitor { public: CalendarViewVisitor() : mView( 0 ) {} bool act( Incidence *incidence, CalendarView *view ) { mView = view; return incidence->accept( *this ); } protected: CalendarView *mView; }; class ShowIncidenceVisitor : public CalendarViewVisitor { protected: bool visit( Event *event ) { mView->showEvent( event ); return true; } bool visit( Todo *todo ) { mView->showTodo( todo ); return true; } bool visit( Journal * j ) { mView->showJournal( j );return true; } }; class EditIncidenceVisitor : public CalendarViewVisitor { protected: bool visit( Event *event ) { mView->editEvent( event ); return true; } bool visit( Todo *todo ) { mView->editTodo( todo ); return true; } bool visit( Journal *j ) { mView->editJournal( j); return true; } }; class DeleteIncidenceVisitor : public CalendarViewVisitor { protected: bool visit( Event *event ) { mView->deleteEvent( event ); return true; } bool visit( Todo *todo ) { mView->deleteTodo( todo ); return true; } bool visit( Journal * j) {mView->deleteJournal( j ); return true; } }; diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp index ec69b11..9104347 100644 --- a/korganizer/mainwindow.cpp +++ b/korganizer/mainwindow.cpp @@ -945,97 +945,96 @@ void MainWindow::fillSyncMenu() { if ( syncMenu->count() ) syncMenu->clear(); syncMenu->insertItem( i18n("Configure..."), 0 ); syncMenu->insertSeparator(); if ( mServerSocket == 0 ) { syncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); } else { syncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); } syncMenu->insertSeparator(); syncMenu->insertItem( i18n("Multiple sync"), 1 ); syncMenu->insertSeparator(); KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); config.setGroup("General"); QStringList prof = config.readListEntry("SyncProfileNames"); KOPrefs::instance()->mLocalMachineName = config.readEntry("LocalMachineName","undefined"); if ( prof.count() < 3 ) { prof.clear(); prof << i18n("Sharp_DTM"); prof << i18n("Local_file"); prof << i18n("Last_file"); KSyncProfile* temp = new KSyncProfile (); temp->setName( prof[0] ); temp->writeConfig(&config); temp->setName( prof[1] ); temp->writeConfig(&config); temp->setName( prof[2] ); temp->writeConfig(&config); config.setGroup("General"); config.writeEntry("SyncProfileNames",prof); config.writeEntry("ExternSyncProfiles","Sharp_DTM"); config.sync(); delete temp; } KOPrefs::instance()->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); KOPrefs::instance()->mSyncProfileNames = prof; int i; for ( i = 0; i < prof.count(); ++i ) { syncMenu->insertItem( prof[i], 1000+i ); if ( i == 2 ) syncMenu->insertSeparator(); } QDir app_dir; if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { syncMenu->setItemEnabled( false , 1000 ); } - mView->setupExternSyncProfiles(); } int MainWindow::ringSync() { int syncedProfiles = 0; int i; QTime timer; KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); QStringList syncProfileNames = KOPrefs::instance()->mSyncProfileNames; KSyncProfile* temp = new KSyncProfile (); KOPrefs::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 )) { setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); ++syncedProfiles; // KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); KOPrefs::instance()->mWriteBackInFuture = 0; if ( temp->getWriteBackFuture() ) KOPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); KOPrefs::instance()->mShowSyncSummary = false; mView->setSyncDevice(syncProfileNames[i] ); mView->setSyncName( KOPrefs::instance()->mLocalMachineName ); if ( i == 0 ) { syncSharp(); } else { if ( temp->getIsLocalFileSync() ) { if ( syncWithFile( temp->getRemoteFileName( ), true ) ) KOPrefs::instance()->mLastSyncedLocalFile = temp->getRemoteFileName(); } else { if ( temp->getIsPhoneSync() ) { KOPrefs::instance()->mPhoneDevice = temp->getPhoneDevice( ) ; KOPrefs::instance()->mPhoneConnection = temp->getPhoneConnection( ); KOPrefs::instance()->mPhoneModel = temp->getPhoneModel( ); syncPhone(); } else if ( temp->getIsPiSync() ) { mPassWordPiSync = temp->getRemotePw(); KOPrefs::instance()->mActiveSyncPort = temp->getRemotePort(); KOPrefs::instance()->mActiveSyncIP = temp->getRemoteIP(); syncPi(); } else syncRemote( temp, false ); } diff --git a/libkdepim/kpimprefs.h b/libkdepim/kpimprefs.h index 01c57a3..6f92919 100644 --- a/libkdepim/kpimprefs.h +++ b/libkdepim/kpimprefs.h @@ -11,75 +11,59 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #ifndef KPIMPREFS_H #define KPIMPREFS_H #include <qstringlist.h> #include "kprefs.h" class KPimPrefs : public KPrefs { public: KPimPrefs( const QString &name = QString::null ); virtual ~KPimPrefs(); /** Set preferences to default values */ void usrSetDefaults(); /** Read preferences from config file */ void usrReadConfig(); /** Write preferences to config file */ void usrWriteConfig(); public: QStringList mCustomCategories; - // sync stuff - QString mLocalMachineName; - QStringList mExternSyncProfiles; - QStringList mSyncProfileNames; - bool mAskForPreferences; - bool mShowSyncSummary; - bool mShowSyncEvents; - bool mShowTodoInAgenda; - bool mWriteBackExistingOnly; - int mSyncAlgoPrefs; - int mRingSyncAlgoPrefs; - bool mWriteBackFile; - int mWriteBackInFuture; - QString mPhoneDevice; - QString mPhoneConnection; - QString mPhoneModel; - QString mLastSyncedLocalFile; // save! + protected: virtual void setCategoryDefaults(); }; #endif diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 07e6761..c0cc840 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp @@ -7,435 +7,433 @@ 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. */ // $Id$ #include "ksyncmanager.h" #include <stdlib.h> #ifndef _WIN32_ #include <unistd.h> #endif #include "ksyncprofile.h" #include "ksyncprefsdialog.h" #include "kpimprefs.h" #include <qdir.h> #include <qprogressbar.h> #include <qpopupmenu.h> #include <qpushbutton.h> #include <qradiobutton.h> #include <qbuttongroup.h> #include <qtimer.h> #include <qmessagebox.h> #include <qapplication.h> #include <qlineedit.h> #include <qdialog.h> #include <qlayout.h> #include <klocale.h> #include <kglobal.h> #include <kconfig.h> #include <kfiledialog.h> KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) - : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs), mSyncMenu(syncmenu) + : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mSyncMenu(syncmenu) { bar = new QProgressBar ( 1, 0 ); bar->setCaption (""); int w = 300; if ( QApplication::desktop()->width() < 320 ) w = 220; int h = bar->sizeHint().height() ; int dw = QApplication::desktop()->width(); int dh = QApplication::desktop()->height(); bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); } KSyncManager::~KSyncManager() { delete bar; } void KSyncManager::fillSyncMenu() { if ( mSyncMenu->count() ) mSyncMenu->clear(); mSyncMenu->insertItem( i18n("Configure..."), 0 ); mSyncMenu->insertSeparator(); mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); mSyncMenu->insertSeparator(); KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); config.setGroup("General"); QStringList prof = config.readListEntry("SyncProfileNames"); - mPrefs->mLocalMachineName = config.readEntry("LocalMachineName","undefined"); + mLocalMachineName = config.readEntry("LocalMachineName","undefined"); if ( prof.count() < 3 ) { prof.clear(); prof << i18n("Sharp_DTM"); prof << i18n("Local_file"); prof << i18n("Last_file"); KSyncProfile* temp = new KSyncProfile (); temp->setName( prof[0] ); temp->writeConfig(&config); temp->setName( prof[1] ); temp->writeConfig(&config); temp->setName( prof[2] ); temp->writeConfig(&config); config.setGroup("General"); config.writeEntry("SyncProfileNames",prof); config.writeEntry("ExternSyncProfiles","Sharp_DTM"); config.sync(); delete temp; } - mPrefs->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); - mPrefs->mSyncProfileNames = prof; + mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); + mSyncProfileNames = prof; unsigned int i; for ( i = 0; i < prof.count(); ++i ) { mSyncMenu->insertItem( prof[i], 1000+i ); if ( i == 2 ) mSyncMenu->insertSeparator(); } QDir app_dir; //US do not display SharpDTM if app is pwmpi, or no sharpfiles available if ( mTargetApp == PWMPI) { mSyncMenu->removeItem( 1000 ); } else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { mSyncMenu->setItemEnabled( 1000, false ); } - //probaly useless - //mView->setupExternSyncProfiles(); } void KSyncManager::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 (blockSave()) return; setBlockSave(true); mCurrentSyncProfile = action - 1000 ; - mCurrentSyncDevice = mPrefs->mSyncProfileNames[mCurrentSyncProfile] ; - mCurrentSyncName = mPrefs->mLocalMachineName ; + mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; + mCurrentSyncName = mLocalMachineName ; KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); KSyncProfile* temp = new KSyncProfile (); - temp->setName(mPrefs->mSyncProfileNames[mCurrentSyncProfile]); + temp->setName(mSyncProfileNames[mCurrentSyncProfile]); temp->readConfig(&config); - mPrefs->mAskForPreferences = temp->getAskForPreferences(); - mPrefs->mSyncAlgoPrefs = temp->getSyncPrefs(); - mPrefs->mWriteBackFile = temp->getWriteBackFile(); - mPrefs->mWriteBackExistingOnly = temp->getWriteBackExisting(); - mPrefs->mWriteBackInFuture = 0; + mAskForPreferences = temp->getAskForPreferences(); + mSyncAlgoPrefs = temp->getSyncPrefs(); + mWriteBackFile = temp->getWriteBackFile(); + mWriteBackExistingOnly = temp->getWriteBackExisting(); + mWriteBackInFuture = 0; if ( temp->getWriteBackFuture() ) - mPrefs->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); - mPrefs->mShowSyncSummary = temp->getShowSummaryAfterSync(); + mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); + mShowSyncSummary = temp->getShowSummaryAfterSync(); if ( action == 1000 ) { syncSharp(); } else if ( action == 1001 ) { syncLocalFile(); } else if ( action == 1002 ) { quickSyncLocalFile(); } else if ( action >= 1003 ) { if ( temp->getIsLocalFileSync() ) { switch(mTargetApp) { case (KAPI): if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) - mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); + mLastSyncedLocalFile = temp->getRemoteFileNameAB(); break; case (KOPI): if ( syncWithFile( temp->getRemoteFileName( ), false ) ) - mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); + mLastSyncedLocalFile = temp->getRemoteFileName(); break; case (PWMPI): if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) - mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); + mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); break; default: qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); break; } } else { if ( temp->getIsPhoneSync() ) { - mPrefs->mPhoneDevice = temp->getPhoneDevice( ) ; - mPrefs->mPhoneConnection = temp->getPhoneConnection( ); - mPrefs->mPhoneModel = temp->getPhoneModel( ); + mPhoneDevice = temp->getPhoneDevice( ) ; + mPhoneConnection = temp->getPhoneConnection( ); + mPhoneModel = temp->getPhoneModel( ); syncPhone(); } else syncRemote( temp ); } } delete temp; setBlockSave(false); } void KSyncManager::syncLocalFile() { - QString fn =mPrefs->mLastSyncedLocalFile; + QString fn =mLastSyncedLocalFile; QString ext; switch(mTargetApp) { case (KAPI): ext = "(*.vcf)"; break; case (KOPI): ext = "(*.ics/*.vcs)"; break; case (PWMPI): ext = "(*.pwm)"; break; default: qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); break; } fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); if ( fn == "" ) return; if ( syncWithFile( fn, false ) ) { qDebug("syncLocalFile() successful "); } } bool KSyncManager::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( mParent, i18n("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( mParent, i18n("Warning!"), mess, i18n("Sync"), i18n("Cancel"), 0, 0, 1 ); if ( result ) return false; } - if ( mPrefs->mAskForPreferences ) + if ( mAskForPreferences ) edit_sync_options(); if ( result == 0 ) { //qDebug("Now sycing ... "); - if ( ret = mImplementation->sync( this, fn, mPrefs->mSyncAlgoPrefs ) ) + if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) mParent->setCaption( i18n("Synchronization successful") ); else mParent->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); if ( ! quick ) - mPrefs->mLastSyncedLocalFile = fn; + mLastSyncedLocalFile = fn; mImplementation->sync_setModified(); } return ret; } void KSyncManager::quickSyncLocalFile() { - if ( syncWithFile( mPrefs->mLastSyncedLocalFile, false ) ) { + if ( syncWithFile( mLastSyncedLocalFile, false ) ) { qDebug("quick syncLocalFile() successful "); } } void KSyncManager::multiSync( bool askforPrefs ) { if (blockSave()) return; setBlockSave(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( mParent, i18n("Sync"), question, i18n("Yes"), i18n("No"), 0, 0 ) != 0 ) { setBlockSave(false); mParent->setCaption(i18n("Aborted! Nothing synced!")); return; } mCurrentSyncDevice = i18n("Multiple profiles") ; - mPrefs->mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; + mSyncAlgoPrefs = mRingSyncAlgoPrefs; if ( askforPrefs ) { edit_sync_options(); - mPrefs->mRingSyncAlgoPrefs = mPrefs->mSyncAlgoPrefs; + mRingSyncAlgoPrefs = mSyncAlgoPrefs; } mParent->setCaption(i18n("Multiple sync started.") ); qApp->processEvents(); int num = ringSync() ; if ( num > 1 ) ringSync(); setBlockSave(false); if ( num ) mImplementation->sync_save(); if ( num ) mParent->setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); else mParent->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); return; } int KSyncManager::ringSync() { int syncedProfiles = 0; unsigned int i; QTime timer; KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); - QStringList syncProfileNames = mPrefs->mSyncProfileNames; + QStringList syncProfileNames = mSyncProfileNames; KSyncProfile* temp = new KSyncProfile (); - mPrefs->mAskForPreferences = false; + mAskForPreferences = false; for ( i = 0; i < syncProfileNames.count(); ++i ) { mCurrentSyncProfile = i; temp->setName(syncProfileNames[mCurrentSyncProfile]); temp->readConfig(&config); QString includeInRingSync; switch(mTargetApp) { case (KAPI): includeInRingSync = temp->getIncludeInRingSyncAB(); break; case (KOPI): includeInRingSync = temp->getIncludeInRingSync(); break; case (PWMPI): includeInRingSync = temp->getIncludeInRingSyncPWM(); break; default: qDebug("KSyncManager::ringSync: invalid apptype selected"); break; } if ( includeInRingSync && ( i < 1 || i > 2 )) { mParent->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); ++syncedProfiles; - // mPrefs->mAskForPreferences = temp->getAskForPreferences(); - mPrefs->mWriteBackFile = temp->getWriteBackFile(); - mPrefs->mWriteBackExistingOnly = temp->getWriteBackExisting(); - mPrefs->mWriteBackInFuture = 0; + // mAskForPreferences = temp->getAskForPreferences(); + mWriteBackFile = temp->getWriteBackFile(); + mWriteBackExistingOnly = temp->getWriteBackExisting(); + mWriteBackInFuture = 0; if ( temp->getWriteBackFuture() ) - mPrefs->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); - mPrefs->mShowSyncSummary = false; + mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); + mShowSyncSummary = false; mCurrentSyncDevice = syncProfileNames[i] ; - mCurrentSyncName = mPrefs->mLocalMachineName; + mCurrentSyncName = mLocalMachineName; if ( i == 0 ) { syncSharp(); } else { if ( temp->getIsLocalFileSync() ) { switch(mTargetApp) { case (KAPI): if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) - mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); + mLastSyncedLocalFile = temp->getRemoteFileNameAB(); break; case (KOPI): if ( syncWithFile( temp->getRemoteFileName( ), false ) ) - mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); + mLastSyncedLocalFile = temp->getRemoteFileName(); break; case (PWMPI): if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) - mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); + mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); break; default: qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); break; } } else { if ( temp->getIsPhoneSync() ) { - mPrefs->mPhoneDevice = temp->getPhoneDevice( ) ; - mPrefs->mPhoneConnection = temp->getPhoneConnection( ); - mPrefs->mPhoneModel = temp->getPhoneModel( ); + mPhoneDevice = temp->getPhoneDevice( ) ; + mPhoneConnection = temp->getPhoneConnection( ); + mPhoneModel = temp->getPhoneModel( ); syncPhone(); } else syncRemote( temp, false ); } } timer.start(); mParent->setCaption(i18n("Multiple sync in progress ... please wait!") ); while ( timer.elapsed () < 2000 ) { qApp->processEvents(); #ifndef _WIN32_ sleep (1); #endif } } } delete temp; return syncedProfiles; } void KSyncManager::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( mParent, i18n("Sync"), question, i18n("Yes"), i18n("No"), 0, 0 ) != 0 ) return; } QString preCommand; QString localTempFile; QString postCommand; switch(mTargetApp) { case (KAPI): preCommand = prof->getPreSyncCommandAB(); postCommand = prof->getPostSyncCommandAB(); localTempFile = prof->getLocalTempFileAB(); break; case (KOPI): preCommand = prof->getPreSyncCommand(); postCommand = prof->getPostSyncCommand(); @@ -446,220 +444,220 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) postCommand = prof->getPostSyncCommandPWM(); localTempFile = prof->getLocalTempFilePWM(); break; default: qDebug("KSyncManager::syncRemote: invalid apptype selected"); break; } int fi; if ( (fi = preCommand.find("$PWD$")) > 0 ) { QString pwd = getPassword(); preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); } int maxlen = 30; if ( QApplication::desktop()->width() > 320 ) maxlen += 25; mParent->setCaption ( i18n( "Copy remote file to local machine..." ) ); int fileSize = 0; int result = system ( preCommand ); // 0 : okay // 256: no such file or dir // qDebug("KO: Remote copy result(0 = okay): %d ",result ); if ( result != 0 ) { unsigned int len = maxlen; while ( len < preCommand.length() ) { preCommand.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 (preCommand) ; QMessageBox::information( mParent, i18n("Sync - ERROR"), question, i18n("Okay!")) ; mParent->setCaption (""); return; } mParent->setCaption ( i18n( "Copying succeed." ) ); //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); if ( syncWithFile( localTempFile, true ) ) { // Event* e = mView->getLastSyncEvent(); // e->setReadOnly( false ); // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); // e->setReadOnly( true ); - if ( mPrefs->mWriteBackFile ) { + if ( mWriteBackFile ) { int fi; if ( (fi = postCommand.find("$PWD$")) > 0 ) { QString pwd = getPassword(); postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); } mParent->setCaption ( i18n( "Writing back file ..." ) ); result = system ( postCommand ); qDebug("Writing back file result: %d ", result); if ( result != 0 ) { mParent->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); return; } else { mParent->setCaption ( i18n( "Syncronization sucessfully completed" ) ); } } } return; } void KSyncManager::edit_sync_options() { //mDialogManager->showSyncOptions(); - //mPrefs->mSyncAlgoPrefs + //mSyncAlgoPrefs QDialog dia( mParent, "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 ( mPrefs->mSyncAlgoPrefs ) { + switch ( mSyncAlgoPrefs ) { case 0: loc.setChecked( true); break; case 1: rem.setChecked( true ); break; 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() ) { - mPrefs->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; + mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; } } QString KSyncManager::getPassword( ) { QString retfile = ""; QDialog dia ( mParent, "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; } void KSyncManager::confSync() { static KSyncPrefsDialog* sp = 0; if ( ! sp ) { sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); } sp->usrReadConfig(); #ifndef DESKTOP_VERSION sp->showMaximized(); #else sp->show(); #endif sp->exec(); - mPrefs->mSyncProfileNames = sp->getSyncProfileNames(); - mPrefs->mLocalMachineName = sp->getLocalMachineName (); + mSyncProfileNames = sp->getSyncProfileNames(); + mLocalMachineName = sp->getLocalMachineName (); fillSyncMenu(); } void KSyncManager::syncSharp() { if ( ! syncExternalApplication("sharp") ) qDebug("ERROR sync sharp ");; } bool KSyncManager::syncExternalApplication(QString resource) { if ( mImplementation->sync_isModified() ) mImplementation->sync_save(); - if ( mPrefs->mAskForPreferences ) + if ( mAskForPreferences ) edit_sync_options(); qDebug("sync %s", resource.latin1()); bool syncOK = mImplementation->syncExternal(this, resource); return syncOK; } void KSyncManager::syncPhone() { if ( mImplementation->sync_isModified() ) mImplementation->sync_save(); qDebug("pending syncPhone(); "); //mView->syncPhone(); mImplementation->sync_setModified(); } void KSyncManager::showProgressBar(int percentage, QString caption, int total) { if (!bar->isVisible()) { bar->setCaption (caption); bar->setTotalSteps ( total ) ; bar->show(); } bar->setProgress( percentage ); } void KSyncManager::hideProgressBar() { bar->hide(); } bool KSyncManager::isProgressBarCanceled() { return !bar->isVisible(); } diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h index 9761107..6b10016 100644 --- a/libkdepim/ksyncmanager.h +++ b/libkdepim/ksyncmanager.h @@ -14,116 +14,134 @@ 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. $Id$ */ #ifndef _KSYNCMANAGER_H #define _KSYNCMANAGER_H #include <qobject.h> #include <qstring.h> class QPopupMenu; class KSyncProfile; class KPimPrefs; class QWidget; class KSyncManager; class KSyncInterface; class QProgressBar; class KSyncManager : public QObject { Q_OBJECT public: enum TargetApp { KOPI = 0, KAPI = 1, PWMPI = 2 }; KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); ~KSyncManager() ; bool blockSave() { return mBlockSaveFlag; } void setBlockSave(bool sa) { mBlockSaveFlag = sa; } void fillSyncMenu(); QString getCurrentSyncDevice() { return mCurrentSyncDevice; } QString getCurrentSyncName() { return mCurrentSyncName; } void showProgressBar(int percentage, QString caption = QString::null, int total=100); void hideProgressBar(); bool isProgressBarCanceled(); + // sync stuff + QString mLocalMachineName; + QStringList mExternSyncProfiles; + QStringList mSyncProfileNames; + bool mAskForPreferences; + bool mShowSyncSummary; + bool mShowSyncEvents; + bool mShowTodoInAgenda; + bool mWriteBackExistingOnly; + int mSyncAlgoPrefs; + int mRingSyncAlgoPrefs; + bool mWriteBackFile; + int mWriteBackInFuture; + QString mPhoneDevice; + QString mPhoneConnection; + QString mPhoneModel; + QString mLastSyncedLocalFile; // save! + + public slots: void slotSyncMenu( int ); private: // LR ******************************* // sync stuff! QString mCurrentSyncDevice; QString mCurrentSyncName; void quickSyncLocalFile(); bool syncWithFile( QString fn , bool quick ); void syncLocalFile(); void syncPhone(); void syncSharp(); bool syncExternalApplication(QString); void multiSync( bool askforPrefs ); int mCurrentSyncProfile ; void syncRemote( KSyncProfile* prof, bool ask = true); void edit_sync_options(); int ringSync(); QString getPassword( ); private slots: void confSync(); // ********************* private: bool mBlockSaveFlag; QWidget* mParent; KSyncInterface* mImplementation; TargetApp mTargetApp; - KPimPrefs* mPrefs; QPopupMenu* mSyncMenu; QProgressBar* bar; }; class KSyncInterface { public: virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0; virtual bool syncExternal(KSyncManager* manager, QString resource) { // empty implementation, because some syncable applications do not have an external(sharpdtm) syncmode, like pwmanager. return false; } //called by the syncmanager to indicate that the work has to be marked as dirty. virtual void sync_setModified() = 0; //called by the syncmanager to ask if the dirty flag is set. virtual bool sync_isModified() = 0; //called by the syncmanager to indicate that the work has to be saved. virtual void sync_save() = 0; }; #endif diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp index 6c1a9c0..76a45f4 100644 --- a/pwmanager/pwmanager/pwmdoc.cpp +++ b/pwmanager/pwmanager/pwmdoc.cpp @@ -2915,132 +2915,132 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s (*inLocal) = (*inRemote); //US syncLocal->insertAddressee( inLocal , false ); ++changedLocal; } } } else { // no conflict if ( inRemote->meta.update > mLastSync || mode == 5 ) { inRemote->meta.update = modifiedSync; //US syncRemote->insertAddressee( inRemote, false ); //US syncLocal->insertAddressee( inRemote, false ); syncLocal->addEntry("newcategory", inRemote, true, false); ++addedPasswordsLocal; } else { // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); syncRemote->delEntry(catRemote, indexRemote, true); //USsyncRemote->removeAddressee( inRemote ); ++deletedPasswordsRemote; } } ++incCounter; } er.clear(); QStringList el = syncLocal->getIDEntryList(); modulo = (el.count()/10)+1; manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); incCounter = 0; while ( incCounter < el.count()) { qApp->processEvents(); if (manager->isProgressBarCanceled()) return e_syncError; if ( incCounter % modulo == 0 ) manager->showProgressBar(incCounter); uid = el[ incCounter ]; inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); if ( inRemote == 0 ) { if ( inLocal->meta.update < mLastSync && mode != 4 ) { // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); syncLocal->delEntry(catLocal, indexLocal, true); //USsyncLocal->removeAddressee( inLocal ); ++deletedPasswordsLocal; } else { - if ( ! PWMPrefs::instance()->mWriteBackExistingOnly ) { + if ( ! manager->mWriteBackExistingOnly ) { ++addedPasswordsRemote; inLocal->meta.update = modifiedSync; //USsyncLocal->insertAddressee( inLocal, false ); (*inRemote) = (*inLocal); //USsyncRemote->insertAddressee( inRemote, false ); syncRemote->addEntry("newcategory", inRemote, true, false); } } } ++incCounter; } el.clear(); manager->hideProgressBar(); // Now write the info back into the sync data space of the files mLastSync = QDateTime::currentDateTime().addSecs( 1 ); // get rid of micro seconds QTime t = mLastSync.time(); mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); syncItemLocal->lastSyncDate = mLastSync; syncItemRemote->lastSyncDate = mLastSync; // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); syncRemote->addSyncDataEntry( syncItemRemote, false ); syncLocal->addSyncDataEntry( syncItemLocal, false ); QString mes; mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote ); - if ( PWMPrefs::instance()->mShowSyncSummary ) { + if ( manager->mShowSyncSummary ) { KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); } qDebug( mes ); return e_success; } int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) { // 0 equal // 1 take local // 2 take remote // 3 cancel QDateTime localMod = local->meta.update; QDateTime remoteMod = remote->meta.update; //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); if ( localMod == remoteMod ) return 0; qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); //full = true; //debug only if ( full ) { bool equ = true;//US ( (*local) == (*remote) ); if ( equ ) { //qDebug("equal "); if ( mode < SYNC_PREF_FORCE_LOCAL ) return 0; }//else //debug only //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); } int result; bool localIsNew; //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); if ( full && mode < SYNC_PREF_NEWEST ) mode = SYNC_PREF_ASK; switch( mode ) { case SYNC_PREF_LOCAL: if ( lastSync > remoteMod ) return 1; @@ -3094,97 +3094,97 @@ int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime //this are the overwritten callbackmethods from the syncinterface bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) { QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); //1) unlock local file first if necessary (ask for password) if (this->isDeepLocked()) { PwMerror ret = this->deepLock(false); if (ret != e_success) return false; } //2) construct and open a new doc on the stack(automatic cleanup) for remote file. PwMDoc syncTarget(this, "synctarget"); PwMDoc* pSyncTarget = &syncTarget; PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/); if (err == e_alreadyOpen) { PwMDocList::listItem li; if (getOpenDocList()->find(filename.latin1(), &li)) pSyncTarget = li.doc; else { qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); return false; } } else if (err != e_success) { qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); return false; } qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); //3) unlock remote file first if necessary (ask for password) if (pSyncTarget->isDeepLocked()) { PwMerror ret = pSyncTarget->deepLock(false); if (ret != e_success) return false; } err = syncronize(manager, this, pSyncTarget, mode ); if (err == e_success) { - if ( PWMPrefs::instance()->mWriteBackFile ) { + if ( manager->mWriteBackFile ) { qDebug("Saving remote PWManager file"); err = pSyncTarget->saveDoc(conf()->confGlobCompression()); if (err != e_success) { qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1()); return false; } } flagDirty(); return true; } else { return false; } } //called by the syncmanager to indicate that the work has to marked as dirty. void PwMDoc::sync_setModified() { flagDirty(); } //called by the syncmanager to ask if the dirty flag is set. bool PwMDoc::sync_isModified() { return isDirty(); } //called by the syncmanager to indicate that the work has to be saved. void PwMDoc::sync_save() { saveDoc(conf()->confGlobCompression()); } #endif bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) { vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), end = dti.syncDta.end(); while (i != end) { if ((*i).syncName == syncname.latin1()) { if (index) { *index = i - dti.syncDta.begin(); } return true; } |