-rw-r--r-- | korganizer/calendarview.cpp | 45 | ||||
-rw-r--r-- | korganizer/calendarview.h | 1 | ||||
-rw-r--r-- | korganizer/kofilterview.cpp | 18 | ||||
-rw-r--r-- | korganizer/koprefs.h | 3 | ||||
-rw-r--r-- | korganizer/mainwindow.cpp | 12 |
5 files changed, 68 insertions, 11 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 6e60c56..b0be340 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp @@ -1880,9 +1880,12 @@ void CalendarView::addCalendarId( int id ) bool CalendarView::addCalendar( KopiCalendarFile * cal ) { - - if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) + cal->mErrorOnLoad = false; + if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { + cal->mLoadDt = QDateTime::currentDateTime(); return true; + } qDebug("KO: Error adding calendar file %1 ",cal->mFileName.latin1() ); KMessageBox::error(this,i18n("Error loading calendar file\n%1.").arg(cal->mFileName)); + cal->mErrorOnLoad = true; return false; } @@ -1984,5 +1987,31 @@ void CalendarView::watchSavedFile() loadedFileVersion = dt; } - +bool CalendarView::checkAllFileVersions() +{ + QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; + KopiCalendarFile * cal = calendars.first(); + mCalendar->setDefaultCalendar( 1 ); + mCalendar->setDefaultCalendarEnabledOnly(); + if ( !checkFileVersion(MainWindow::defaultFileName())) + return false; + cal = calendars.next(); + QDateTime storeTemp = loadedFileVersion; + while ( cal ) { + if ( !cal->mErrorOnLoad ) { + mCalendar->setDefaultCalendar( cal->mCalNumber ); + mCalendar->setDefaultCalendarEnabledOnly(); + loadedFileVersion = cal->mLoadDt.addSecs( 15 ); + if ( !checkFileVersion(cal->mFileName )) { + loadedFileVersion = storeTemp; + updateView(); + return false; + } + } + cal = calendars.next(); + } + loadedFileVersion = storeTemp; + updateView(); + return true; +} bool CalendarView::checkFileVersion(QString fn) { @@ -1995,5 +2024,5 @@ bool CalendarView::checkFileVersion(QString fn) if ( dt <= loadedFileVersion ) return true; - int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , + int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\n on disk has changed!\nFile size: %2 bytes.\nLast modified: %3\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg(fn).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , i18n("KO/Pi Warning"),i18n("Overwrite"), i18n("Sync+save")); @@ -2013,6 +2042,5 @@ bool CalendarView::checkFileVersion(QString fn) Event * e = getLastSyncEvent(); if ( e ) - deleteEvent ( e ); - updateView(); + mCalendar->deleteEvent( e ); return true; } @@ -2026,8 +2054,9 @@ bool CalendarView::saveCalendars() cal = calendars.next(); while ( cal ) { - if ( !cal->isReadOnly ) { + if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { mCalendar->setDefaultCalendar( cal->mCalNumber ); mCalendar->setDefaultCalendarEnabledOnly(); - saveCalendar( cal->mFileName ); + if ( saveCalendar( cal->mFileName ) ) + cal->mLoadDt = QDateTime::currentDateTime(); } cal = calendars.next(); diff --git a/korganizer/calendarview.h b/korganizer/calendarview.h index ec5b7ab..d836fee 100644 --- a/korganizer/calendarview.h +++ b/korganizer/calendarview.h @@ -511,4 +511,5 @@ class CalendarView : public KOrg::CalendarViewBase, public KCal::Calendar::Obser void setLoadedFileVersion(QDateTime); bool checkFileVersion(QString fn); + bool checkAllFileVersions(); bool checkFileChanged(QString fn); Event* getLastSyncEvent(); diff --git a/korganizer/kofilterview.cpp b/korganizer/kofilterview.cpp index 361eec8..19d731f 100644 --- a/korganizer/kofilterview.cpp +++ b/korganizer/kofilterview.cpp @@ -232,5 +232,13 @@ void KOCalEditView::infoCal( int id ) QString name = KOPrefs::instance()->getCalendar( id )->mName; QString file = KOPrefs::instance()->getCalendar( id )->mFileName; - KMessageBox::information( this, i18n("The calendar <b>%1</b> is displaying file <b>%2</b>").arg(name).arg(file) ); + if ( KOPrefs::instance()->getCalendar( id )->mErrorOnLoad ) { + if ( KMessageBox::Yes == KMessageBox::questionYesNo( this, i18n("The calendar <b>%1</b> is not loaded! Loading of file <b>%2</b> failed! <b>Try again to load the calendar?</b>").arg(name).arg(file) ) ) { + emit calendarAdded( id ); + readConfig(); + emit needsUpdate(); + } + } + else + KMessageBox::information( this, i18n("The calendar <b>%1</b> is displaying file <b>%2</b>").arg(name).arg(file) ); } void KOCalEditView::readConfig() @@ -295,8 +303,12 @@ void KOCalEditView::readConfig() cb->setNum( kkf->mCalNumber ); connect (cb, SIGNAL (selectNum(int,bool)), SLOT ( selectStdCal(int,bool) ) ); + if ( kkf->mErrorOnLoad ) + cb->setEnabled( false ); cb = new KOCalCheckButton( mw ); mainLayout->addWidget( cb,row,1 );mEnabledB.append( cb ); cb->setChecked( kkf->isEnabled ); cb->setNum( kkf->mCalNumber ); + if ( kkf->mErrorOnLoad ) + cb->setEnabled( false ); connect (cb, SIGNAL (selectNum(int,bool)), SLOT ( selectCal(int,bool) ) ); KOCalButton* name = new KOCalButton( mw ); @@ -310,4 +322,6 @@ void KOCalEditView::readConfig() cb->setNum( kkf->mCalNumber ); connect (cb, SIGNAL (selectNum(int,bool)), SLOT ( selectCalAlarm(int,bool) ) ); + if ( kkf->mErrorOnLoad ) + cb->setEnabled( false ); cb = new KOCalCheckButton( mw ); mainLayout->addWidget( cb,row,4 );mROB.append( cb ); @@ -315,4 +329,6 @@ void KOCalEditView::readConfig() cb->setNum( kkf->mCalNumber ); connect (cb, SIGNAL (selectNum(int,bool)), SLOT ( selectReadOnly(int,bool) ) ); + if ( kkf->mErrorOnLoad ) + cb->setEnabled( false ); KColorButton *colb = new KColorButton( mw ); mainLayout->addWidget( colb,row,5 ); diff --git a/korganizer/koprefs.h b/korganizer/koprefs.h index f114d88..463fc33 100644 --- a/korganizer/koprefs.h +++ b/korganizer/koprefs.h @@ -57,4 +57,5 @@ class KopiCalendarFile : public QObject mCalNumber = 0; mDefaultColor = Qt::red; + mErrorOnLoad = false; } bool isStandard; @@ -62,8 +63,10 @@ class KopiCalendarFile : public QObject bool isAlarmEnabled; bool isReadOnly; + bool mErrorOnLoad; QString mName; QString mFileName; int mCalNumber; QColor mDefaultColor; + QDateTime mLoadDt; }; class KOPrefs : public KPimPrefs diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp index f05ada5..472a978 100644 --- a/korganizer/mainwindow.cpp +++ b/korganizer/mainwindow.cpp @@ -1825,5 +1825,5 @@ void MainWindow::save() return; mSyncManager->setBlockSave(true); - if ( mView->checkFileVersion( defaultFileName()) ) { + if ( mView->checkAllFileVersions() ) { if ( KPimGlobalPrefs::instance()->mBackupEnabled ){ QDate reference ( 2000,1,1); @@ -1844,6 +1844,14 @@ void MainWindow::save() qDebug("KO: Backup created."); // backup ok + QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; + KopiCalendarFile * cal = calendars.first(); + cal = calendars.next(); + while ( cal ) { + if ( !cal->mErrorOnLoad ) { + int retval = KApplication::createBackup( cal->mFileName, bupDir, KPimGlobalPrefs::instance()->mBackupNumbers ); + } + cal = calendars.next(); + } KOPrefs::instance()->mLastBackupDate = daysTo; - } else if ( retval == 2 ){ qDebug("KO: Backup globally cancelled."); |