-rw-r--r-- | korganizer/calendarview.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 687943e..b1da144 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp @@ -1453,181 +1453,182 @@ bool CalendarView::importQtopia( const QString &categories, if ( KOPrefs::instance()->mWriteBackFile ) { // write back XML file } setModified( true ); } } else { QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), question, i18n("Ok")) ; } delete calendar; updateView(); return syncOK; #endif } void CalendarView::setSyncEventsReadOnly() { Event * ev; QPtrList<Event> eL = mCalendar->rawEvents(); ev = eL.first(); while ( ev ) { if ( ev->uid().left(15) == QString("last-syncEvent-") ) ev->setReadOnly( true ); ev = eL.next(); } } bool CalendarView::openCalendar(QString filename, bool merge) { if (filename.isEmpty()) { return false; } if (!QFile::exists(filename)) { KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); return false; } globalFlagBlockAgenda = 1; if (!merge) mCalendar->close(); mStorage->setFileName( filename ); if ( mStorage->load() ) { if ( merge ) ;//setModified( true ); else { //setModified( true ); mViewManager->setDocumentId( filename ); mDialogManager->setDocumentId( filename ); mTodoList->setDocumentId( filename ); } globalFlagBlockAgenda = 2; // if ( getLastSyncEvent() ) // getLastSyncEvent()->setReadOnly( true ); mCalendar->reInitAlarmSettings(); setSyncEventsReadOnly(); updateUnmanagedViews(); updateView(); - loadedFileVersion = QDateTime::currentDateTime(); + setLoadedFileVersion( QDateTime::currentDateTime().addSecs( -1 )); if ( filename != MainWindow::defaultFileName() ) { saveCalendar( MainWindow::defaultFileName() ); watchSavedFile(); } return true; } else { // while failing to load, the calendar object could // have become partially populated. Clear it out. if ( !merge ) { mCalendar->close(); mViewManager->setDocumentId( filename ); mDialogManager->setDocumentId( filename ); mTodoList->setDocumentId( filename ); } //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); globalFlagBlockAgenda = 2; mCalendar->reInitAlarmSettings(); setSyncEventsReadOnly(); updateUnmanagedViews(); updateView(); } return false; } void CalendarView::showOpenError() { KMessageBox::error(this,i18n("Couldn't load calendar\n.")); } void CalendarView::setLoadedFileVersion(QDateTime dt) { loadedFileVersion = dt; } bool CalendarView::checkFileChanged(QString fn) { QFileInfo finf ( fn ); if ( !finf.exists() ) return true; QDateTime dt = finf.lastModified (); if ( dt <= loadedFileVersion ) return false; return true; } void CalendarView::watchSavedFile() { QFileInfo finf ( MainWindow::defaultFileName()); if ( !finf.exists() ) return; QDateTime dt = finf.lastModified (); if ( dt < loadedFileVersion ) { + //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); return; } loadedFileVersion = dt; } bool CalendarView::checkFileVersion(QString fn) { QFileInfo finf ( fn ); if ( !finf.exists() ) return true; QDateTime dt = finf.lastModified (); //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); //qDebug("file on disk version %s",dt.toString().latin1()); 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)) , i18n("KO/Pi Warning"),i18n("Overwrite"), i18n("Sync+save")); if ( km == KMessageBox::Cancel ) return false; if ( km == KMessageBox::Yes ) return true; setSyncDevice("deleteaftersync" ); KOPrefs::instance()->mAskForPreferences = true; KOPrefs::instance()->mSyncAlgoPrefs = 3; KOPrefs::instance()->mWriteBackFile = false; KOPrefs::instance()->mWriteBackExistingOnly = false; KOPrefs::instance()->mShowSyncSummary = false; syncCalendar( fn, 3 ); Event * e = getLastSyncEvent(); mCalendar->deleteEvent ( e ); updateView(); return true; } bool CalendarView::saveCalendar( QString filename ) { // Store back all unsaved data into calendar object // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); if ( mViewManager->currentView() ) mViewManager->currentView()->flushView(); //mStorage->setFileName( filename ); mStorage->setSaveFormat( new ICalFormat() ); mStorage->setFileName( filename ); bool success; success = mStorage->save(); if ( !success ) { return false; } return true; } void CalendarView::closeCalendar() { // child windows no longer valid emit closingDown(); |