-rw-r--r-- | korganizer/calendarview.cpp | 73 | ||||
-rw-r--r-- | korganizer/calendarview.h | 4 | ||||
-rw-r--r-- | korganizer/mainwindow.cpp | 14 | ||||
-rw-r--r-- | korganizer/mainwindow.h | 4 | ||||
-rw-r--r-- | libkcal/calendar.h | 1 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 16 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 1 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.cpp | 24 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.h | 6 |
9 files changed, 118 insertions, 25 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 8965d3b..307027a 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp @@ -365,8 +365,9 @@ CalendarView::CalendarView( Calendar *calendar, } void CalendarView::init() { + mMultiResourceSync = false; flag_blockConflict = false; flag_blockScrollBar = false; flag_checkFileFirsttime = true; flag_clearallviewsEventDisplay = false; @@ -1551,8 +1552,9 @@ Event* CalendarView::getLastSyncEvent() lse->setDtStart( mLastCalendarSync ); lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); lse->setCategories( i18n("SyncEvent") ); lse->setReadOnly( true ); + lse->setCalID( 1 ); mCalendar->addEvent( lse ); } return lse; @@ -1901,18 +1903,23 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int } } bar.hide(); mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); - eventLSync->setReadOnly( false ); - eventLSync->setDtStart( mLastCalendarSync ); - eventRSync->setDtStart( mLastCalendarSync ); - eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); - eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); - eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; - eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); - eventLSync->setReadOnly( true ); + if ( mMultiResourceSync ) { + remote->removeSyncInfo( "" ); //all + + } else { + eventLSync->setReadOnly( false ); + eventLSync->setDtStart( mLastCalendarSync ); + eventRSync->setDtStart( mLastCalendarSync ); + eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); + eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); + eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; + eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); + eventLSync->setReadOnly( true ); + } qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); - if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... + if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop() && !mMultiResourceSync ) // kde is abnormal... remote->addEvent( eventRSync ); else delete eventRSync; qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); @@ -2434,8 +2441,34 @@ void CalendarView::mergeFile( QString fn ) setSyncEventsReadOnly(); updateUnmanagedViews(); updateView(); } +void CalendarView::mergeFileResource( QString fn ,QString resource ) +{ + + if ( resource == "ALL" ) { + mergeFile( fn ); + return; + } + + int exclusiveResource = KOPrefs::instance()->getFuzzyCalendarID( resource ); + if ( !exclusiveResource ) { + qDebug("KO: CalendarView::mergeFileResource: resource not found %s", resource.latin1() ); + return; + } + clearAllViews(); + mCalendar->setCalendarRemove( exclusiveResource ); + int def = mCalendar->defaultCalendar(); + mCalendar->setDefaultCalendar(exclusiveResource); + if ( !mCalendar->addCalendarFile( fn, exclusiveResource )) { + qDebug("KO: CalendarView::mergeFileResource: error adding file %s", fn.latin1() ); + } + mCalendar->setDefaultCalendar( def ); + mCalendar->reInitAlarmSettings(); + setSyncEventsReadOnly(); + updateUnmanagedViews(); + updateView(); +} void CalendarView::showOpenError() { KMessageBox::error(this,i18n("Couldn't load calendar\n.")); } @@ -2521,8 +2554,9 @@ bool CalendarView::checkFileVersion(QString fn) mSyncManager->mSyncAlgoPrefs = 3; mSyncManager->mWriteBackFile = false; mSyncManager->mWriteBackExistingOnly = false; mSyncManager->mShowSyncSummary = false; + mMultiResourceSync = false; syncCalendar( fn, 3 ); Event * e = getLastSyncEvent(); if ( e ) mCalendar->deleteEvent( e ); @@ -2557,8 +2591,25 @@ bool CalendarView::saveCalendars() return false; } return true; } +bool CalendarView::saveCalendarResource(QString filename, QString resource) +{ + if ( resource == "ALL" ) + return saveCalendar( filename ); + int exclusiveResource = KOPrefs::instance()->getFuzzyCalendarID( resource ); + if ( !exclusiveResource ) { + qDebug("KO: CalendarView::saveCalendarResource: resource not found %s", resource.latin1() ); + return false; + } + mCalendar->setDefaultCalendar( exclusiveResource ); + mCalendar->setDefaultCalendarEnabledOnly(); + mCalendar->setSyncEventsEnabled(); + bool res = saveCalendar( filename ); + restoreCalendarSettings(); + return res; + +} bool CalendarView::saveCalendar( QString filename ) { // Store back all unsaved data into calendar object @@ -5031,9 +5082,13 @@ void CalendarView::keyPressEvent ( QKeyEvent *e) //qDebug("CalendarView::keyPressEvent "); e->ignore(); } +void CalendarView::multiResourceSyncStart( bool start ) +{ + mMultiResourceSync = start; +} bool CalendarView::sync(KSyncManager* manager, QString filename, int mode,QString resource) { if ( manager != mSyncManager) diff --git a/korganizer/calendarview.h b/korganizer/calendarview.h index f85b6a3..60b1276 100644 --- a/korganizer/calendarview.h +++ b/korganizer/calendarview.h @@ -138,8 +138,9 @@ class CalendarView : public KOrg::CalendarViewBase, public KCal::Calendar::Obser KOEventViewerDialog* getEventViewerDialog(); Incidence *currentSelection(); void checkSuspendAlarm(); void mergeFile( QString fn ); + void mergeFileResource( QString fn ,QString res); signals: void save (); void saveStopTimer (); @@ -200,8 +201,9 @@ class CalendarView : public KOrg::CalendarViewBase, public KCal::Calendar::Obser void filtersUpdated(); public slots: + void multiResourceSyncStart( bool ); void displayCalendarInfo( int id ); void nextConflict( bool all, bool allday ); void conflictAll(); void conflictAllday(); @@ -245,8 +247,9 @@ class CalendarView : public KOrg::CalendarViewBase, public KCal::Calendar::Obser Save calendar data to file. Return true if calendar could be successfully saved. */ bool saveCalendar(QString filename); + bool saveCalendarResource(QString filename, QString resource); /** Close calendar. Clear calendar data and reset views to display an empty calendar. @@ -538,8 +541,9 @@ class CalendarView : public KOrg::CalendarViewBase, public KCal::Calendar::Obser void setBlockShowDates( bool b ) { mBlockShowDates = b ;} void setScrollBarStep(int val ); protected: + bool mMultiResourceSync; Event *mConflictingEvent; void schedule(Scheduler::Method, Incidence *incidence = 0); // returns KMsgBox::OKCandel() diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp index 66bb19b..69ccde1 100644 --- a/korganizer/mainwindow.cpp +++ b/korganizer/mainwindow.cpp @@ -373,10 +373,12 @@ MainWindow::MainWindow( QWidget *parent, const char *name ) : connect(mSyncManager , SIGNAL( save() ), this, SLOT( save() ) ); connect(mView , SIGNAL( saveStopTimer() ), this, SLOT( saveStopTimer() ) ); - connect(mSyncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) ); - connect(mSyncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) ); + connect(mSyncManager , SIGNAL( request_file(const QString &) ), this, SLOT( syncFileRequest(const QString &) ) ); + connect(mSyncManager , SIGNAL( getFile( bool, const QString &)), this, SLOT(getFile( bool,const QString & ) ) ); + connect(mSyncManager , SIGNAL( multiResourceSyncStart( bool )), mView, SLOT( multiResourceSyncStart( bool ) ) ); + mSyncManager->setDefaultFileName( sentSyncFile()); connect ( syncMenu, SIGNAL( activated ( int ) ), mSyncManager, SLOT (slotSyncMenu( int ) ) ); mSyncManager->fillSyncMenu(); @@ -2703,9 +2705,9 @@ QString MainWindow::sentSyncFile() return QString( "/tmp/copysynccal.ics" ); #endif } -void MainWindow::syncFileRequest() +void MainWindow::syncFileRequest(const QString& resource) { while ( mSyncManager->blockSave() ) { qApp->processEvents(); } @@ -2715,20 +2717,20 @@ void MainWindow::syncFileRequest() mSyncManager->slotSyncMenu( 999 ); } setCaption(i18n("Saving Data to temp file ..." )); - mView->saveCalendar( sentSyncFile() ); + mView->saveCalendarResource( sentSyncFile(), resource ); setCaption(i18n("Data saved to temp file!" )); mSyncManager->setBlockSave( false ); } -void MainWindow::getFile( bool success ) +void MainWindow::getFile( bool success ,const QString& resource) { if ( ! success ) { setCaption( i18n("Error receiving file. Nothing changed!") ); return; } - mView->mergeFile( sentSyncFile() ); + mView->mergeFileResource( sentSyncFile(), resource); if ( KOPrefs::instance()->mPassiveSyncWithDesktop ) { mSyncManager->slotSyncMenu( 999 ); } setCaption( i18n("Pi-Sync successful!") ); diff --git a/korganizer/mainwindow.h b/korganizer/mainwindow.h index d8018b6..a533d8b 100644 --- a/korganizer/mainwindow.h +++ b/korganizer/mainwindow.h @@ -109,10 +109,10 @@ class MainWindow : public QMainWindow private slots: void slotResetFocus(); void slotResetFocusLoop(); void showConfigureAgenda(); - void getFile( bool ); - void syncFileRequest(); + void getFile( bool ,const QString &); + void syncFileRequest(const QString &); protected: int mFocusLoop; void hideEvent ( QHideEvent * ); diff --git a/libkcal/calendar.h b/libkcal/calendar.h index 4b8b3ff..0a94914 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h @@ -78,8 +78,9 @@ public: virtual bool addCalendarFile( QString name, int id ) = 0; virtual bool mergeCalendarFile( QString name ) = 0; virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ) = 0; virtual void setSyncEventsReadOnly() = 0; + virtual void setSyncEventsEnabled() = 0; virtual void stopAllTodos() = 0; virtual void clearUndo( Incidence * newUndo ); /** diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 0ddfeca..45e3128 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp @@ -172,15 +172,27 @@ bool CalendarLocal::addCalendarFile( QString name, int id ) return true; } return false; } -void CalendarLocal::setSyncEventsReadOnly() +void CalendarLocal::setSyncEventsEnabled() { Event * ev; ev = mEventList.first(); while ( ev ) { if ( ev->uid().left(15) == QString("last-syncEvent-") ) - ev->setReadOnly( true ); + ev->setCalEnabled( true ); + ev = mEventList.next(); + } +} +void CalendarLocal::setSyncEventsReadOnly() +{ + Event * ev; + ev = mEventList.first(); + while ( ev ) { + if ( ev->uid().left(15) == QString("last-syncEvent-") ) { + ev->setReadOnly( true ); + ev->setCalID( 1 ); + } ev = mEventList.next(); } } void CalendarLocal::addCalendar( Calendar* cal ) diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index ca0bd98..eb7bf34 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h @@ -48,8 +48,9 @@ class CalendarLocal : public Calendar bool mergeCalendarFile( QString name ); bool mergeCalendar( Calendar* cal ); Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ); void setSyncEventsReadOnly(); + void setSyncEventsEnabled(); void stopAllTodos(); /** Loads a calendar on disk in vCalendar or iCalendar format into the current calendar. Any information already present is lost. diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index a64eb34..719d80b 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp @@ -195,9 +195,10 @@ void KSyncManager::slotClearMenu( int action ) } void KSyncManager::slotSyncMenu( int action ) { qDebug("KSM::syncaction %d ", action); - mCurrentResourceLocal = ""; + mCurrentResourceLocal = ""; + emit multiResourceSyncStart( false ); if ( action == 5000 ) return; mSyncWithDesktop = false; if ( action == 0 ) { @@ -440,8 +441,10 @@ void KSyncManager::enableQuick( bool ask ) mPrefs->writeConfig(); } connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); + connect( mServerSocket, SIGNAL ( request_file(const QString &) ),this, SIGNAL ( request_file(const QString &) ) ); + connect( mServerSocket, SIGNAL ( file_received( bool ,const QString &) ), this, SIGNAL ( getFile( bool,const QString & ) ) ); } void KSyncManager::displayErrorPort() { KMessageBox::information( 0, i18n("<b>Enabling Pi-Sync failed!</b> Failed to bind or listen to the port %1! Is another instance already listening to that port?").arg( mPrefs->mPassiveSyncPort) , i18n("Pi-Sync Port Error")); @@ -568,9 +571,9 @@ void KSyncManager::multiSync( bool askforPrefs ) } int KSyncManager::ringSync() { - + emit multiResourceSyncStart( false ); int syncedProfiles = 0; unsigned int i; QTime timer; KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); @@ -1139,9 +1142,12 @@ void KSyncManager::syncPi() mCurrentResourceRemote = ""; if ( mSpecificResources.count() ) { int startLocal = 0; int startRemote = mSpecificResources.count()/2; + emit multiResourceSyncStart( true ); while ( startLocal < mSpecificResources.count()/2 ) { + if ( startLocal+1 >= mSpecificResources.count()/2 ) + emit multiResourceSyncStart( false ); mPisyncFinished = false; mCurrentResourceLocal = mSpecificResources[ startLocal ]; mCurrentResourceRemote = mSpecificResources[ startRemote ]; KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote, mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); @@ -1218,9 +1224,9 @@ void KSyncManager::readFileFromSocket() if ( ! syncWithFile( fileName , true ) ) { mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); syncOK = false; } - KCommandSocket* commandSocket = new KCommandSocket( "",mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); + KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote,mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); if ( mWriteBackFile && syncOK ) { mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") ); commandSocket->writeFile( fileName ); @@ -1282,8 +1288,9 @@ void KServerSocket::readClient() mErrorMessage = 999; error_connect("ERROR_ED\r\n\r\n"); return; } + mResource = ""; mErrorMessage = 0; //qDebug("KServerSocket::readClient()"); if ( mSocket->canReadLine() ) { QString line = mSocket->readLine(); @@ -1298,8 +1305,9 @@ void KServerSocket::readClient() KSyncManager::mRequestedSyncEvent = dt; } else KSyncManager::mRequestedSyncEvent = QDateTime(); + mResource =tokens[3]; send_file(); } else { mErrorMessage = 1; @@ -1309,8 +1317,9 @@ void KServerSocket::readClient() if ( tokens[0] == "PUT" ) { if ( tokens[1] == mPassWord ) { //emit getFile( mSocket ); blockRC = true; + mResource =tokens[2]; get_file(); } else { mErrorMessage = 2; @@ -1405,8 +1414,9 @@ void KServerSocket::send_file() } else mSyncActionDialog->setFixedSize( 230, 120); mSyncActionDialog->show(); mSyncActionDialog->raise(); + emit request_file(mResource); emit request_file(); qApp->processEvents(); QString fileName = mFileName; QFile file( fileName ); @@ -1466,9 +1476,10 @@ void KServerSocket::readBackFileFromSocket() delete mSyncActionDialog; mSyncActionDialog = 0; qDebug("KSS:Error open read back file "); piFileString = ""; - emit file_received( false ); + emit file_received( false, mResource); + emit file_received( false); blockRC = false; return ; } @@ -1482,9 +1493,10 @@ void KServerSocket::readBackFileFromSocket() if ( mSocket->state() == QSocket::Idle ) QTimer::singleShot( 10, this , SLOT ( discardClient())); file.close(); piFileString = ""; - emit file_received( true ); + emit file_received( true, mResource ); + emit file_received( true); delete mSyncActionDialog; mSyncActionDialog = 0; blockRC = false; @@ -1595,9 +1607,9 @@ void KCommandSocket::writeFileToSocket() QTextStream ts2( &file2 ); ts2.setEncoding( QTextStream::Latin1 ); QTextStream os2( mSocket ); os2.setEncoding( QTextStream::Latin1 ); - os2 << "PUT " << mPassWord << "\r\n\r\n";; + os2 << "PUT " << mPassWord << mRemoteResource << "\r\n\r\n";; int byteCount = 0; int byteMax = file2.size()/53; while ( ! ts2.atEnd() ) { qApp->processEvents(); diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h index f4654ce..53c611d 100644 --- a/libkdepim/ksyncmanager.h +++ b/libkdepim/ksyncmanager.h @@ -52,8 +52,10 @@ class KServerSocket : public QServerSocket void setFileName( QString fn ) {mFileName = fn;}; signals: void file_received( bool ); void request_file(); + void file_received( bool, const QString &); + void request_file(const QString &); void saveFile(); void endConnect(); private slots: void discardClient(); @@ -61,8 +63,9 @@ class KServerSocket : public QServerSocket void readClient(); void displayErrorMessage(); void readBackFileFromSocket(); private : + QString mResource; int mErrorMessage; bool blockRC; void send_file(); void get_file(); @@ -173,8 +176,11 @@ class KSyncManager : public QObject signals: void save(); void request_file(); void getFile( bool ); + void getFile( bool, const QString &); + void request_file(const QString &); + void multiResourceSyncStart( bool ); public slots: void slotSyncMenu( int ); void slotClearMenu( int action ); |