author | zautrix <zautrix> | 2004-09-18 08:51:10 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-18 08:51:10 (UTC) |
commit | 4ec7c78ebd2c5a79ff224e9b07d9a3164f7fe602 (patch) (side-by-side diff) | |
tree | 0beaebd8819f1fc4a36fb8fc115ff97ac43c3db3 | |
parent | 983b010853dfadfec3638e2afd90e522985f67fb (diff) | |
download | kdepimpi-4ec7c78ebd2c5a79ff224e9b07d9a3164f7fe602.zip kdepimpi-4ec7c78ebd2c5a79ff224e9b07d9a3164f7fe602.tar.gz kdepimpi-4ec7c78ebd2c5a79ff224e9b07d9a3164f7fe602.tar.bz2 |
more AB sync
-rw-r--r-- | kaddressbook/kabcore.cpp | 293 |
1 files changed, 277 insertions, 16 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index e912941..1196360 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -2134,479 +2134,740 @@ void KABCore::fillSyncMenu() config.sync(); delete temp; } KABPrefs::instance()->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); KABPrefs::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 ); } //probaly useless //mView->setupExternSyncProfiles(); } 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->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 ); if ( result ) return false; } if ( KABPrefs::instance()->mAskForPreferences ) edit_sync_options(); if ( result == 0 ) { //qDebug("Now sycing ... "); if ( ret = syncAB( fn, KABPrefs::instance()->mSyncAlgoPrefs ) ) setCaption( i18n("Synchronization successful") ); else setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); if ( ! quick ) KABPrefs::instance()->mLastSyncedLocalFile = fn; setModified(); } return ret; } void KABCore::quickSyncLocalFile() { if ( syncWithFile( KABPrefs::instance()->mLastSyncedLocalFile, false ) ) { qDebug("quick syncLocalFile() successful "); } } 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->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->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->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->getLocalTempFileAB(), true ) ) { // Event* e = mView->getLastSyncEvent(); // e->setReadOnly( false ); // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); // e->setReadOnly( true ); if ( KABPrefs::instance()->mWriteBackFile ) { 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: 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() ) { 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) { - +#if 0 + bool syncOK = true; + int addedAddressee = 0; + int addedAddresseeR = 0; + int deletedAddresseeR = 0; + int deletedAddresseeL = 0; + int changedLocal = 0; + int changedRemote = 0; + //QPtrList<Addressee> el = local->rawAddressees(); + Addressee* addresseeR; + QString uid; + int take; + Addressee* addresseeL; + Addressee* addresseeRSync; + Addressee* addresseeLSync; + QPtrList<Addressee> addresseeRSyncSharp = remote->getExternLastSyncAddressees(); + QPtrList<Addressee> addresseeLSyncSharp = local->getExternLastSyncAddressees(); + bool fullDateRange = false; + local->resetTempSyncStat(); + mLastCalendarSync = QDateTime::currentDateTime(); + QDateTime modifiedCalendar = mLastCalendarSync;; + addresseeLSync = getLastSyncAddressee(); + addresseeR = remote->addressee("last-syncAddressee-"+mCurrentSyncName ); + if ( addresseeR ) { + addresseeRSync = (Addressee*) addresseeR->clone(); + remote->deleteAddressee(addresseeR ); + + } else { + if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { + addresseeRSync = (Addressee*)addresseeLSync->clone(); + } else { + fullDateRange = true; + addresseeRSync = new Addressee(); + addresseeRSync->setSummary(mCurrentSyncName + i18n(" - sync addressee")); + addresseeRSync->setUid("last-syncAddressee-"+mCurrentSyncName ); + addresseeRSync->setDtStart( mLastCalendarSync ); + addresseeRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); + addresseeRSync->setCategories( i18n("SyncAddressee") ); + } + } + if ( addresseeLSync->dtStart() == mLastCalendarSync ) + fullDateRange = true; + + if ( ! fullDateRange ) { + if ( addresseeLSync->dtStart() != addresseeRSync->dtStart() ) { + + // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); + //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); + fullDateRange = true; + } + } + if ( fullDateRange ) + mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); + else + mLastCalendarSync = addresseeLSync->dtStart(); + // for resyncing if own file has changed + if ( mCurrentSyncDevice == "deleteaftersync" ) { + mLastCalendarSync = loadedFileVersion; + qDebug("setting mLastCalendarSync "); + } + //qDebug("*************************** "); + qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); + QPtrList<Incidence> er = remote->rawIncidences(); + Incidence* inR = er.first(); + Incidence* inL; + QProgressBar bar( er.count(),0 ); + bar.setCaption (i18n("Syncing - close to abort!") ); + + 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 ); + bar.show(); + int modulo = (er.count()/10)+1; + int incCounter = 0; + while ( inR ) { + if ( ! bar.isVisible() ) + return false; + if ( incCounter % modulo == 0 ) + bar.setProgress( incCounter ); + ++incCounter; + uid = inR->uid(); + bool skipIncidence = false; + if ( uid.left(15) == QString("last-syncAddressee-") ) + skipIncidence = true; + QString idS; + qApp->processAddressees(); + if ( !skipIncidence ) { + inL = local->incidence( uid ); + if ( inL ) { // maybe conflict - same uid in both calendars + int maxrev = inL->revision(); + if ( maxrev < inR->revision() ) + maxrev = inR->revision(); + if ( (take = takeAddressee( inL, inR, mode, fullDateRange )) > 0 ) { + //qDebug("take %d %s ", take, inL->summary().latin1()); + if ( take == 3 ) + return false; + if ( take == 1 ) {// take local + if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) + inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); + else + idS = inR->IDStr(); + remote->deleteIncidence( inR ); + if ( inL->revision() < maxrev ) + inL->setRevision( maxrev ); + inR = inL->clone(); + inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); + if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) + inR->setIDStr( idS ); + remote->addIncidence( inR ); + ++changedRemote; + } else { + if ( inR->revision() < maxrev ) + inR->setRevision( maxrev ); + idS = inL->IDStr(); + local->deleteIncidence( inL ); + inL = inR->clone(); + inL->setIDStr( idS ); + local->addIncidence( inL ); + ++changedLocal; + } + } + } else { // no conflict + if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { + QString des = addresseeLSync->description(); + QString pref = "e"; + if ( inR->type() == "Todo" ) + pref = "t"; + if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it + inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); + //remote->deleteIncidence( inR ); + ++deletedAddresseeR; + } else { + inR->setLastModified( modifiedCalendar ); + inL = inR->clone(); + local->addIncidence( inL ); + ++addedAddressee; + } + } else { + if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { + inR->setLastModified( modifiedCalendar ); + local->addIncidence( inR->clone() ); + ++addedAddressee; + } else { + checkExternSyncAddressee(addresseeRSyncSharp, inR); + remote->deleteIncidence( inR ); + ++deletedAddresseeR; + } + } + } + } + inR = er.next(); + } + QPtrList<Incidence> el = local->rawIncidences(); + inL = el.first(); + modulo = (el.count()/10)+1; + bar.setCaption (i18n("Add / remove addressees") ); + bar.setTotalSteps ( el.count() ) ; + bar.show(); + incCounter = 0; + + while ( inL ) { + + qApp->processAddressees(); + if ( ! bar.isVisible() ) + return false; + if ( incCounter % modulo == 0 ) + bar.setProgress( incCounter ); + ++incCounter; + uid = inL->uid(); + bool skipIncidence = false; + if ( uid.left(15) == QString("last-syncAddressee-") ) + skipIncidence = true; + if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) + skipIncidence = true; + if ( !skipIncidence ) { + inR = remote->incidence( uid ); + if ( ! inR ) { + if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { + if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { + checkExternSyncAddressee(addresseeLSyncSharp, inL); + local->deleteIncidence( inL ); + ++deletedAddresseeL; + } else { + if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { + inL->removeID(mCurrentSyncDevice ); + ++addedAddresseeR; + //qDebug("remote added Incidence %s ", inL->summary().latin1()); + inL->setLastModified( modifiedCalendar ); + inR = inL->clone(); + inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); + remote->addIncidence( inR ); + } + } + } else { + if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { + checkExternSyncAddressee(addresseeLSyncSharp, inL); + local->deleteIncidence( inL ); + ++deletedAddresseeL; + } else { + if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { + ++addedAddresseeR; + inL->setLastModified( modifiedCalendar ); + remote->addIncidence( inL->clone() ); + } + } + } + } + } + inL = el.next(); + } + int delFut = 0; + if ( KOPrefs::instance()->mWriteBackInFuture ) { + er = remote->rawIncidences(); + inR = er.first(); + QDateTime dt; + QDateTime cur = QDateTime::currentDateTime(); + QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 ); + while ( inR ) { + if ( inR->type() == "Todo" ) { + Todo * t = (Todo*)inR; + if ( t->hasDueDate() ) + dt = t->dtDue(); + else + dt = cur.addSecs( 62 ); + } + else if (inR->type() == "Addressee" ) { + bool ok; + dt = inR->getNextOccurence( cur, &ok ); + if ( !ok ) + dt = cur.addSecs( -62 ); + } + else + dt = inR->dtStart(); + if ( dt < cur || dt > end ) { + remote->deleteIncidence( inR ); + ++delFut; + } + inR = er.next(); + } + } + bar.hide(); + mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); + addresseeLSync->setReadOnly( false ); + addresseeLSync->setDtStart( mLastCalendarSync ); + addresseeRSync->setDtStart( mLastCalendarSync ); + addresseeLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); + addresseeRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); + addresseeRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; + addresseeLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); + addresseeLSync->setReadOnly( true ); + if ( mGlobalSyncMode == SYNC_MODE_NORMAL) + remote->addAddressee( addresseeRSync ); + 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 ); + QString delmess; + if ( delFut ) { + delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture ); + mes += delmess; + } + if ( KOPrefs::instance()->mShowSyncSummary ) { + KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); + } + qDebug( mes ); + mCalendar->checkAlarmForIncidence( 0, true ); + return syncOK; +#endif + return false; } bool KABCore::syncAB(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; 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 ) { + qDebug("saving remote AB "); abLocal.saveAB(); } } setModified(); } if ( syncOK ) - ;//updateView(); + mViewManager->refreshView(); 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() { 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(); setModified(); } void KABCore::syncPhone() { if ( mModified ) save(); qDebug("pending syncPhone(); "); //mView->syncPhone(); setModified(); } |