author | zautrix <zautrix> | 2005-09-18 13:50:46 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-09-18 13:50:46 (UTC) |
commit | c6e493d4e5b9eafcc3402c39e30c4283ce8cc8e5 (patch) (side-by-side diff) | |
tree | 94e7bdc361b68a3a569eebe14f66458b3795dd6a /korganizer/calendarview.cpp | |
parent | e7cd095ea9e80e26c90cbc2d3bf36921b7541c19 (diff) | |
download | kdepimpi-c6e493d4e5b9eafcc3402c39e30c4283ce8cc8e5.zip kdepimpi-c6e493d4e5b9eafcc3402c39e30c4283ce8cc8e5.tar.gz kdepimpi-c6e493d4e5b9eafcc3402c39e30c4283ce8cc8e5.tar.bz2 |
delay
-rw-r--r-- | korganizer/calendarview.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 79fb727..2ba8528 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp @@ -2358,384 +2358,385 @@ bool CalendarView::addCalendar( KopiCalendarFile * cal ) cal->mErrorOnLoad = true; return false; } 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; clearAllViews(); if (!merge) { mViewManager->setDocumentId( filename ); 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(); if ( filename != MainWindow::defaultFileName() ) { saveCalendar( MainWindow::defaultFileName() ); } else { QFileInfo finf ( MainWindow::defaultFileName()); if ( finf.exists() ) { setLoadedFileVersion( finf.lastModified () ); } } 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::mergeFile( QString fn ) { clearAllViews(); mCalendar->mergeCalendarFile( fn ); mCalendar->reInitAlarmSettings(); setSyncEventsReadOnly(); updateUnmanagedViews(); updateView(); } 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::checkAllFileVersions() { QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; KopiCalendarFile * cal = calendars.first(); mCalendar->setDefaultCalendar( 1 ); mCalendar->setDefaultCalendarEnabledOnly(); if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { if ( !checkFileVersion(MainWindow::defaultFileName())) { restoreCalendarSettings(); return false; } } cal = calendars.next(); QDateTime storeTemp = loadedFileVersion; while ( cal ) { if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { mCalendar->setDefaultCalendar( cal->mCalNumber ); mCalendar->setDefaultCalendarEnabledOnly(); loadedFileVersion = cal->mLoadDt.addSecs( 15 ); if ( !checkFileVersion(cal->mFileName )) { loadedFileVersion = storeTemp; restoreCalendarSettings(); return false; } } cal = calendars.next(); } loadedFileVersion = storeTemp; return true; } bool CalendarView::checkFileVersion(QString fn) { QFileInfo finf ( fn ); if ( !finf.exists() ) return true; QDateTime dt = finf.lastModified (); //qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1()); //qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1()); if ( dt <= loadedFileVersion ) return true; int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\non 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(KGlobal::formatMessage(fn,0)).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" ); mSyncManager->mAskForPreferences = true; mSyncManager->mSyncAlgoPrefs = 3; mSyncManager->mWriteBackFile = false; mSyncManager->mWriteBackExistingOnly = false; mSyncManager->mShowSyncSummary = false; syncCalendar( fn, 3 ); Event * e = getLastSyncEvent(); if ( e ) mCalendar->deleteEvent( e ); return true; } bool CalendarView::saveCalendars() { QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; KopiCalendarFile * cal = calendars.first(); mCalendar->setDefaultCalendar( 1 ); mCalendar->setDefaultCalendarEnabledOnly(); QString saveError; if ( !saveCalendar( MainWindow::defaultFileName() ) ) saveError = cal->mName +"\n"; cal = calendars.next(); while ( cal ) { if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { mCalendar->setDefaultCalendar( cal->mCalNumber ); mCalendar->setDefaultCalendarEnabledOnly(); if ( saveCalendar( cal->mFileName ) ) cal->mLoadDt = QDateTime::currentDateTime(); else saveError += cal->mName + "\n"; } cal = calendars.next(); } restoreCalendarSettings(); + //saveError = "test error"; if ( !saveError.isEmpty() ) { saveError = KGlobal::formatMessage( i18n("Calendar(s) not saved:"),0 )+"\n" + saveError; KMessageBox::error(this, saveError, i18n("Error saving data")); return false; } 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(); QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); mStorage->setSaveFormat( new ICalFormat() ); mStorage->setFileName( filename ); bool success; success = mStorage->save(); if ( !success ) { return false; } if ( filename == MainWindow::defaultFileName() ) { setLoadedFileVersion( lfv ); watchSavedFile(); } return true; } void CalendarView::closeCalendar() { // child windows no longer valid clearAllViews(); emit closingDown(); mCalendar->close(); setModified(false); updateView(); } void CalendarView::archiveCalendar() { mDialogManager->showArchiveDialog(); } void CalendarView::readSettings() { // mViewManager->showAgendaView(); QString str; //qDebug("CalendarView::readSettings() "); // read settings from the KConfig, supplying reasonable // defaults where none are to be found KConfig *config = KOGlobals::config(); #ifndef KORG_NOSPLITTER config->setGroup("KOrganizer Geometry"); QValueList<int> sizes = config->readIntListEntry("Separator1"); if (sizes.count() != 2) { sizes << mDateNavigator->minimumSizeHint().width(); sizes << 300; } mPanner->setSizes(sizes); sizes = config->readIntListEntry("Separator2"); if ( ( mResourceView && sizes.count() == 4 ) || ( !mResourceView && sizes.count() == 3 ) ) { mLeftSplitter->setSizes(sizes); } #endif globalFlagBlockAgenda = 1; mViewManager->showAgendaView(); //mViewManager->readSettings( config ); mTodoList->restoreLayout(config,QString("Todo Layout")); readFilterSettings(config); #ifdef DESKTOP_VERSION config->setGroup("WidgetLayout"); QStringList list; list = config->readListEntry("MainLayout"); int x,y,w,h; if ( ! list.isEmpty() ) { x = list[0].toInt(); y = list[1].toInt(); w = list[2].toInt(); h = list[3].toInt(); KApplication::testCoords( &x,&y,&w,&h ); topLevelWidget()->setGeometry(x,y,w,h); } else { topLevelWidget()->setGeometry( 40 ,40 , 640, 440); } list = config->readListEntry("EditEventLayout"); if ( ! list.isEmpty() ) { x = list[0].toInt(); y = list[1].toInt(); w = list[2].toInt(); h = list[3].toInt(); KApplication::testCoords( &x,&y,&w,&h ); mEventEditor->setGeometry(x,y,w,h); } list = config->readListEntry("EditTodoLayout"); if ( ! list.isEmpty() ) { x = list[0].toInt(); y = list[1].toInt(); w = list[2].toInt(); h = list[3].toInt(); KApplication::testCoords( &x,&y,&w,&h ); mTodoEditor->setGeometry(x,y,w,h); } list = config->readListEntry("ViewerLayout"); if ( ! list.isEmpty() ) { x = list[0].toInt(); y = list[1].toInt(); w = list[2].toInt(); h = list[3].toInt(); KApplication::testCoords( &x,&y,&w,&h ); getEventViewerDialog()->setGeometry(x,y,w,h); } #endif config->setGroup( "Views" ); int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame"); int resetval = 0; int maxVal = 0; if (sizes.count() != 3) { if ( KOPrefs::instance()->mVerticalScreen ) { resetval = mDateNavigator->sizeHint().width()+2; } else { resetval = mDateNavigator->sizeHint().height()+2; } } if ( resetval ) { sizes.clear(); if ( KOPrefs::instance()->mVerticalScreen ) { maxVal = QApplication::desktop()->width() -10; } else { maxVal = QApplication::desktop()->height()-10; } sizes << resetval; if ( maxVal < resetval + resetval) resetval = maxVal - resetval; sizes << resetval; sizes << 100; } mLeftFrame->setSizes(sizes); sizes = config->readIntListEntry("Main Splitter Frame"); resetval = 0; maxVal = 0; if (sizes.count() != 2) { if ( !KOPrefs::instance()->mVerticalScreen ) { resetval = mDateNavigator->sizeHint().width()+2; } else { resetval = mDateNavigator->sizeHint().height()+2; } } if ( resetval ) { sizes.clear(); if ( !KOPrefs::instance()->mVerticalScreen ) { maxVal = QApplication::desktop()->width() -10; } else { maxVal = QApplication::desktop()->height()-10; } sizes << resetval; if ( maxVal < resetval + resetval) resetval = maxVal - resetval; sizes << resetval; } mMainFrame->setSizes(sizes); if ( dateCount == 5 ) mNavigator->selectWorkWeek(); else if ( dateCount == 7 ) mNavigator->selectWeek(); else mNavigator->selectDates( dateCount ); // mViewManager->readSettings( config ); updateConfig(); globalFlagBlockAgenda = 2; mViewManager->readSettings( config ); QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) ); } void CalendarView::checkSuspendAlarm() { if ( mSuspendTimer->isActive() ) { KMessageBox::information( this, i18n("<b>WARNING:</b> There is a pending suspended alarm!"), i18n("Pending Suspend Alarm")); @@ -4274,394 +4275,396 @@ void CalendarView::schedule_request(Incidence *incidence) void CalendarView::schedule_refresh(Incidence *incidence) { schedule(Scheduler::Refresh,incidence); } void CalendarView::schedule_cancel(Incidence *incidence) { schedule(Scheduler::Cancel,incidence); } void CalendarView::schedule_add(Incidence *incidence) { schedule(Scheduler::Add,incidence); } void CalendarView::schedule_reply(Incidence *incidence) { schedule(Scheduler::Reply,incidence); } void CalendarView::schedule_counter(Incidence *incidence) { schedule(Scheduler::Counter,incidence); } void CalendarView::schedule_declinecounter(Incidence *incidence) { schedule(Scheduler::Declinecounter,incidence); } void CalendarView::schedule_publish_freebusy(int daysToPublish) { QDateTime start = QDateTime::currentDateTime(); QDateTime end = start.addDays(daysToPublish); FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); freebusy->setOrganizer(KOPrefs::instance()->email()); PublishDialog *publishdlg = new PublishDialog(); if ( publishdlg->exec() == QDialog::Accepted ) { OutgoingDialog *dlg = mDialogManager->outgoingDialog(); if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { delete(freebusy); } } delete publishdlg; } void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) { Event *event = 0; Todo *todo = 0; if (incidence == 0) { incidence = mViewManager->currentView()->selectedIncidences().first(); if (incidence == 0) { incidence = mTodoList->selectedIncidences().first(); } } if ( incidence && incidence->typeID() == eventID ) { event = static_cast<Event *>(incidence); } if ( incidence && incidence->typeID() == todoID ) { todo = static_cast<Todo *>(incidence); } if (!event && !todo) { KMessageBox::sorry(this,i18n("No event selected.")); return; } if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { KMessageBox::sorry(this,i18n("The event has no attendees.")); return; } Event *ev = 0; if (event) ev = new Event(*event); Todo *to = 0; if (todo) to = new Todo(*todo); if (method == Scheduler::Reply || method == Scheduler::Refresh) { Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); if (!me) { KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); return; } if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { StatusDialog *statdlg = new StatusDialog(this); if (!statdlg->exec()==QDialog::Accepted) return; me->setStatus( statdlg->status() ); delete(statdlg); } Attendee *menew = new Attendee(*me); if (ev) { ev->clearAttendees(); ev->addAttendee(menew,false); } else { if (to) { todo->clearAttendees(); todo->addAttendee(menew,false); } } } OutgoingDialog *dlg = mDialogManager->outgoingDialog(); if (ev) { if ( !dlg->addMessage(ev,method) ) delete(ev); } else { if (to) { if ( !dlg->addMessage(to,method) ) delete(to); } } } void CalendarView::openAddressbook() { KRun::runCommand("kaddressbook"); } void CalendarView::setModified(bool modified) { //qDebug("CalendarView::setModified %d ", modified); if ( modified ) emit signalmodified(); mModified = modified; if ( mModified ) emit modifiedChanged(mModified); } bool CalendarView::isReadOnly() { return mReadOnly; } void CalendarView::setReadOnly(bool readOnly) { if (mReadOnly != readOnly) { mReadOnly = readOnly; emit readOnlyChanged(mReadOnly); } } bool CalendarView::isModified() { return mModified; } void CalendarView::slotprintSelInc() { if ( currentSelection() == 0 ) { KMessageBox::sorry(this,i18n("There is nothing selected!")); return; } showIncidence(); getEventViewerDialog()->print(); } void CalendarView::printSetup() { #ifndef KORG_NOPRINTER createPrinter(); mCalPrinter->setupPrinter(); #endif } void CalendarView::print() { #ifndef KORG_NOPRINTER createPrinter(); DateList tmpDateList = mNavigator->selectedDates(); mCalPrinter->print(CalPrinter::Month, tmpDateList.first(), tmpDateList.last()); #endif } void CalendarView::printPreview() { #ifndef KORG_NOPRINTER kdDebug() << "CalendarView::printPreview()" << endl; createPrinter(); DateList tmpDateList = mNavigator->selectedDates(); mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), tmpDateList.last()); #endif } - -void CalendarView::exportICalendar() +bool CalendarView::exportICalendar( QString filename ) { - QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); - // Force correct extension if (filename.right(4) != ".ics") filename += ".ics"; FileStorage storage( mCalendar, filename, new ICalFormat() ); - storage.save(); + return storage.save(); +} + +bool CalendarView::exportICalendar() +{ + return exportICalendar( KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this) ); } bool CalendarView::exportVCalendar( QString filename ) { if (mCalendar->journals().count() > 0) { int result = KMessageBox::warningContinueCancel(this, i18n("The journal entries can not be\nexported to a vCalendar file."), i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), true); if (result != KMessageBox::Continue) return false; } //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); // Force correct extension if (filename.right(4) != ".vcs") filename += ".vcs"; FileStorage storage( mCalendar, filename, new VCalFormat ); return storage.save(); } void CalendarView::eventUpdated(Incidence *) { setModified(); // Don't call updateView here. The code, which has caused the update of the // event is responsible for updating the view. // updateView(); } void CalendarView::adaptNavigationUnits() { if (mViewManager->currentView()->isEventView()) { int days = mViewManager->currentView()->currentDateCount(); if (days == 1) { emit changeNavStringPrev(i18n("&Previous Day")); emit changeNavStringNext(i18n("&Next Day")); } else { emit changeNavStringPrev(i18n("&Previous Week")); emit changeNavStringNext(i18n("&Next Week")); } } } void CalendarView::processMainViewSelection( Incidence *incidence ) { if ( incidence ) mTodoList->clearSelection(); processIncidenceSelection( incidence ); } void CalendarView::processTodoListSelection( Incidence *incidence ) { if ( incidence && mViewManager->currentView() ) { mViewManager->currentView()->clearSelection(); } processIncidenceSelection( incidence ); } void CalendarView::processIncidenceSelection( Incidence *incidence ) { emit incidenceSelected( incidence ); if ( incidence == mSelectedIncidence ) return; mSelectedIncidence = incidence; if ( incidence && incidence->typeID() == eventID ) { Event *event = static_cast<Event *>( incidence ); if ( event->organizer() == KOPrefs::instance()->email() ) { emit organizerEventsSelected( true ); } else { emit organizerEventsSelected(false); } if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, KOPrefs::instance()->email() ) ) { emit groupEventsSelected( true ); } else { emit groupEventsSelected(false); } return; } else { if ( incidence && incidence->typeID() == todoID ) { emit todoSelected( true ); Todo *event = static_cast<Todo *>( incidence ); if ( event->organizer() == KOPrefs::instance()->email() ) { emit organizerEventsSelected( true ); } else { emit organizerEventsSelected(false); } if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, KOPrefs::instance()->email() ) ) { emit groupEventsSelected( true ); } else { emit groupEventsSelected(false); } return; } else { emit todoSelected( false ); emit organizerEventsSelected(false); emit groupEventsSelected(false); } return; } /* if ( incidence && incidence->typeID() == todoID ) { emit todoSelected( true ); } else { emit todoSelected( false ); }*/ } void CalendarView::checkClipboard() { #ifndef KORG_NODND if (ICalDrag::canDecode(QApplication::clipboard()->data())) { emit pasteEnabled(true); } else { emit pasteEnabled(false); } #endif } void CalendarView::showDates(const DateList &selectedDates) { // kdDebug() << "CalendarView::selectDates()" << endl; if ( !mBlockShowDates ) { if ( mViewManager->currentView() ) { updateView( selectedDates.first(), selectedDates.last() ); } else { mViewManager->showAgendaView(); } } QDate date = selectedDates.first(); if ( ! date.isValid() ) { topLevelWidget()->setCaption(""); return; } QString selDates; selDates = KGlobal::locale()->formatDate( date, true); if (selectedDates.first() < selectedDates.last() ) selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); else { QString addString; if ( date == QDateTime::currentDateTime().date() ) addString = i18n("Today"); else if ( date == QDateTime::currentDateTime().date().addDays(1) ) addString = i18n("Tomorrow"); else if ( date == QDateTime::currentDateTime().date().addDays(-1) ) addString = i18n("Yesterday"); else if ( date == QDateTime::currentDateTime().date().addDays(-2) ) addString = i18n("Day before yesterday"); else if ( date == QDateTime::currentDateTime().date().addDays(2) ) addString = i18n("Day after tomorrow"); if ( !addString.isEmpty() ) { topLevelWidget()->setCaption( addString+", " + selDates ); return; } } topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); } QPtrList<CalFilter> CalendarView::filters() { return mFilters; } void CalendarView::editFilters() { // kdDebug() << "CalendarView::editFilters()" << endl; CalFilter *filter = mFilters.first(); while(filter) { filter = mFilters.next(); } mDialogManager->showFilterEditDialog(&mFilters); updateFilter(); } void CalendarView::toggleFilter() { if ( mLeftFrame->isHidden() ) { toggleExpand(); showFilter( true ); } else showFilter(! mCalEditView->isVisible()); } KOFilterView *CalendarView::filterView() |