00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "actionmanager.h"
00027
00028 #include <qapplication.h>
00029 #include <qtimer.h>
00030
00031 #include <dcopclient.h>
00032 #include <kaction.h>
00033 #include <kfiledialog.h>
00034 #include <kio/netaccess.h>
00035 #include <kkeydialog.h>
00036 #include <kpopupmenu.h>
00037 #include <kstandarddirs.h>
00038 #include <ktip.h>
00039 #include <ktempfile.h>
00040 #include <kxmlguiclient.h>
00041 #include <kwin.h>
00042 #include <knotifyclient.h>
00043
00044 #include <libkcal/htmlexport.h>
00045 #include <libkcal/calendarlocal.h>
00046 #include <libkcal/calendarresources.h>
00047 #include <libkcal/resourcelocal.h>
00048
00049 #include "alarmclient.h"
00050 #include "calendarview.h"
00051 #include "kocore.h"
00052 #include "kodialogmanager.h"
00053 #include "koglobals.h"
00054 #include "koprefs.h"
00055 #include "koviewmanager.h"
00056 #include "kowindowlist.h"
00057 #include "korganizer.h"
00058 #include "kprocess.h"
00059 #include "konewstuff.h"
00060 #include "history.h"
00061 #include "kogroupware.h"
00062 #include "resourceview.h"
00063 #include "resourceimportdialog.h"
00064
00065 KOWindowList *ActionManager::mWindowList = 0;
00066
00067 ActionManager::ActionManager( KXMLGUIClient *client, CalendarView *widget,
00068 QObject *parent, KOrg::MainWindow *mainWindow,
00069 bool isPart )
00070 : QObject( parent ), KCalendarIface(), mRecent( 0 ), mCalendar( 0 ),
00071 mCalendarResources( 0 ), mIsClosing( false )
00072 {
00073 mGUIClient = client;
00074 mACollection = mGUIClient->actionCollection();
00075 mCalendarView = widget;
00076 mIsPart = isPart;
00077 mTempFile = 0;
00078 mNewStuff = 0;
00079 mHtmlExportSync = false;
00080 mMainWindow = mainWindow;
00081 }
00082
00083 ActionManager::~ActionManager()
00084 {
00085 delete mNewStuff;
00086
00087
00088 KOCore::self()->unloadParts( mMainWindow, mParts );
00089
00090 delete mTempFile;
00091
00092
00093 mWindowList->removeWindow( mMainWindow );
00094
00095 delete mCalendarView;
00096
00097 delete mCalendar;
00098 delete mCalendarResources;
00099
00100 kdDebug(5850) << "~ActionManager() done" << endl;
00101 }
00102
00103
00104 void ActionManager::ActionManager::init()
00105 {
00106
00107 if ( !mWindowList ) {
00108 mWindowList = new KOWindowList;
00109
00110 if ( !mIsPart )
00111 QTimer::singleShot( 0, this, SLOT( showTipOnStart() ) );
00112 }
00113
00114
00115
00116 mWindowList->addWindow( mMainWindow );
00117
00118 initActions();
00119
00120
00121 mAutoSaveTimer = new QTimer( this );
00122 connect( mAutoSaveTimer,SIGNAL( timeout() ), SLOT( checkAutoSave() ) );
00123 if ( KOPrefs::instance()->mAutoSave &&
00124 KOPrefs::instance()->mAutoSaveInterval > 0 ) {
00125 mAutoSaveTimer->start( 1000 * 60 * KOPrefs::instance()->mAutoSaveInterval );
00126 }
00127
00128 setTitle();
00129
00130 connect( mCalendarView, SIGNAL( modifiedChanged( bool ) ), SLOT( setTitle() ) );
00131 connect( mCalendarView, SIGNAL( configChanged() ), SLOT( updateConfig() ) );
00132
00133 connect( mCalendarView, SIGNAL( incidenceSelected( Incidence * ) ),
00134 this, SLOT( processIncidenceSelection( Incidence * ) ) );
00135
00136 processIncidenceSelection( 0 );
00137
00138
00139 mCalendarView->checkClipboard();
00140
00141 mCalendarView->lookForOutgoingMessages();
00142 mCalendarView->lookForIncomingMessages();
00143 }
00144
00145 void ActionManager::createCalendarLocal()
00146 {
00147 mCalendar = new CalendarLocal( KOPrefs::instance()->mTimeZoneId );
00148 mCalendarView->setCalendar( mCalendar );
00149 mCalendarView->readSettings();
00150
00151 initCalendar( mCalendar );
00152 }
00153
00154 void ActionManager::createCalendarResources()
00155 {
00156 mCalendarResources = KOCore::self()->calendarResources();
00157
00158 CalendarResourceManager *manager = mCalendarResources->resourceManager();
00159
00160 kdDebug(5850) << "CalendarResources used by KOrganizer:" << endl;
00161 CalendarResourceManager::Iterator it;
00162 for( it = manager->begin(); it != manager->end(); ++it ) {
00163 (*it)->dump();
00164 }
00165
00166 setDestinationPolicy();
00167
00168 mCalendarView->setCalendar( mCalendarResources );
00169 mCalendarView->readSettings();
00170
00171
00172 KOGroupware::create( mCalendarView, mCalendarResources );
00173
00174 ResourceViewFactory factory( mCalendarResources, mCalendarView );
00175 mCalendarView->addExtension( &factory );
00176
00177 connect( mCalendarResources, SIGNAL( calendarChanged() ),
00178 mCalendarView, SLOT( slotCalendarChanged() ) );
00179
00180 connect( mCalendarView, SIGNAL( configChanged() ),
00181 SLOT( updateConfig() ) );
00182
00183 initCalendar( mCalendarResources );
00184 }
00185
00186 void ActionManager::initCalendar( Calendar *cal )
00187 {
00188 cal->setOwner( KOPrefs::instance()->fullName() );
00189 cal->setEmail( KOPrefs::instance()->email() );
00190
00191 mCalendarView->setModified( false );
00192 }
00193
00194 void ActionManager::initActions()
00195 {
00196 KAction *action;
00197
00198
00199 if ( mIsPart ) {
00200 if ( mMainWindow->hasDocument() ) {
00201 new KAction( i18n("&New"), "filenew", CTRL+Key_N, this,
00202 SLOT( file_new() ), mACollection, "korganizer_openNew" );
00203 new KAction( i18n("&Open"), "fileopen", CTRL+Key_O, this,
00204 SLOT( file_open() ), mACollection, "korganizer_open" );
00205 mRecent = new KRecentFilesAction( i18n("Open &Recent"), 0, 0, this,
00206 SLOT( file_openRecent( const KURL & ) ),
00207 mACollection, "korganizer_openRecent" );
00208 new KAction( i18n("Re&vert"), "revert", 0, this,
00209 SLOT( file_revert() ), mACollection, "korganizer_revert" );
00210 new KAction( i18n("Save &As..."), "filesaveas", 0, this,
00211 SLOT( file_saveas() ), mACollection, "korganizer_saveAs" );
00212 new KAction( i18n("&Close"), "fileclose", CTRL+Key_W, this,
00213 SLOT( file_close() ), mACollection, "korganizer_close" );
00214 }
00215 new KAction( i18n("&Save"), "filesave", CTRL+Key_S, this,
00216 SLOT( file_save() ), mACollection, "korganizer_save" );
00217 } else {
00218 KStdAction::openNew(this, SLOT(file_new()), mACollection);
00219 KStdAction::open(this, SLOT(file_open()), mACollection);
00220 mRecent = KStdAction::openRecent(this, SLOT(file_openRecent(const KURL&)),
00221 mACollection);
00222 KStdAction::revert(this,SLOT(file_revert()),mACollection);
00223 KStdAction::save(this, SLOT(file_save()), mACollection);
00224 KStdAction::saveAs(this, SLOT(file_saveas()), mACollection);
00225 KStdAction::close(this, SLOT(file_close()), mACollection);
00226 }
00227
00228 (void)new KAction(i18n("&Import From Ical"), 0, this, SLOT(file_import()),
00229 mACollection, "import_ical");
00230 (void)new KAction(i18n("&Merge Calendar..."), 0, this, SLOT(file_merge()),
00231 mACollection, "merge_calendar");
00232 (void)new KAction(i18n("Archive Old Entries..."), 0, this, SLOT(file_archive()),
00233 mACollection, "file_archive");
00234
00235
00236
00237 (void)new KAction(i18n("Configure &Date && Time..."), 0,
00238 this,SLOT(configureDateTime()),
00239 mACollection, "conf_datetime");
00240
00241 mFilterViewAction = new KToggleAction(i18n("Show Filter"),0,this,
00242 SLOT(toggleFilterView()),
00243 mACollection,
00244 "show_filter");
00245
00246 KStdAction::tipOfDay( this, SLOT( showTip() ), mACollection,
00247 "help_tipofday" );
00248
00249 new KAction( i18n("Get Hot New Stuff..."), 0, this,
00250 SLOT( downloadNewStuff() ), mACollection,
00251 "downloadnewstuff" );
00252
00253 new KAction( i18n("Upload Hot New Stuff..."), 0, this,
00254 SLOT( uploadNewStuff() ), mACollection,
00255 "uploadnewstuff" );
00256
00257 (void)new KAction(i18n("iCalendar..."), 0,
00258 mCalendarView, SLOT(exportICalendar()),
00259 mACollection, "export_icalendar");
00260 (void)new KAction(i18n("vCalendar..."), 0,
00261 mCalendarView, SLOT(exportVCalendar()),
00262 mACollection, "export_vcalendar");
00263
00264
00265 #if 0
00266 (void)new KAction(i18n("Print Setup..."), 0,
00267 mCalendarView, SLOT(printSetup()),
00268 mACollection, "print_setup");
00269 #endif
00270
00271 if (mIsPart) {
00272 new KAction(i18n("&Print..."), "fileprint", CTRL+Key_P, mCalendarView,
00273 SLOT(print()), mACollection, "korganizer_print" );
00274 } else {
00275 KStdAction::print(mCalendarView, SLOT(print()), mACollection);
00276 }
00277
00278 #if 1
00279 if (mIsPart) {
00280 new KAction(i18n("Print Previe&w..."), "filequickprint", 0, mCalendarView,
00281 SLOT(printPreview()), mACollection, "korganizer_quickprint" );
00282 } else {
00283 KStdAction::printPreview(mCalendarView, SLOT(printPreview()),
00284 mACollection);
00285 }
00286 #endif
00287
00288 new KAction( i18n("delete completed To-Dos","Purge Completed"), 0,
00289 mCalendarView, SLOT( purgeCompleted() ), mACollection,
00290 "purge_completed" );
00291
00292 KOrg::History *h = mCalendarView->history();
00293
00294 KAction *pasteAction;
00295
00296 if ( mIsPart ) {
00297
00298 mCutAction = new KAction(i18n("Cu&t"), "editcut", CTRL+Key_X, mCalendarView,
00299 SLOT(edit_cut()), mACollection, "korganizer_cut");
00300 mCopyAction = new KAction(i18n("&Copy"), "editcopy", CTRL+Key_C, mCalendarView,
00301 SLOT(edit_copy()), mACollection, "korganizer_copy");
00302 pasteAction = new KAction(i18n("&Paste"), "editpaste", CTRL+Key_V, mCalendarView,
00303 SLOT(edit_paste()), mACollection, "korganizer_paste");
00304 mUndoAction = new KAction( i18n("&Undo"), "undo", CTRL+Key_Z, h,
00305 SLOT( undo() ), mACollection, "korganizer_undo" );
00306 mRedoAction = new KAction( i18n("Re&do"), "redo", CTRL+SHIFT+Key_Z, h,
00307 SLOT( redo() ), mACollection, "korganizer_redo" );
00308 } else {
00309 mCutAction = KStdAction::cut(mCalendarView,SLOT(edit_cut()),
00310 mACollection);
00311
00312 mCopyAction = KStdAction::copy(mCalendarView,SLOT(edit_copy()),
00313 mACollection);
00314
00315 pasteAction = KStdAction::paste(mCalendarView,SLOT(edit_paste()),
00316 mACollection);
00317
00318 mUndoAction = KStdAction::undo( h, SLOT( undo() ), mACollection );
00319 mRedoAction = KStdAction::redo( h, SLOT( redo() ), mACollection );
00320 }
00321
00322 pasteAction->setEnabled( false );
00323 connect( mCalendarView, SIGNAL( pasteEnabled( bool ) ),
00324 pasteAction, SLOT( setEnabled( bool ) ) );
00325
00326 connect( h, SIGNAL( undoAvailable( const QString & ) ),
00327 SLOT( updateUndoAction( const QString & ) ) );
00328 connect( h, SIGNAL( redoAvailable( const QString & ) ),
00329 SLOT( updateRedoAction( const QString & ) ) );
00330 mUndoAction->setEnabled( false );
00331 mRedoAction->setEnabled( false );
00332
00333 mDeleteAction = new KAction(i18n("&Delete"),"editdelete",0,
00334 mCalendarView,SLOT(appointment_delete()),
00335 mACollection, "edit_delete");
00336
00337 if ( mIsPart ) {
00338 new KAction(i18n("&Find..."),"find",CTRL+Key_F,
00339 mCalendarView->dialogManager(), SLOT(showSearchDialog()),
00340 mACollection, "korganizer_find");
00341 } else {
00342 KStdAction::find(mCalendarView->dialogManager(), SLOT(showSearchDialog()),
00343 mACollection);
00344 }
00345
00346
00347
00348 (void)new KAction(i18n("What's &Next"), "whatsnext", 0,
00349 mCalendarView->viewManager(), SLOT(showWhatsNextView()),
00350 mACollection, "view_whatsnext");
00351 (void)new KAction(i18n("&List"), "list", 0,
00352 mCalendarView->viewManager(), SLOT(showListView()),
00353 mACollection, "view_list");
00354 (void)new KAction(i18n("&Day"), "1day", 0,
00355 mCalendarView->viewManager(), SLOT(showDayView()),
00356 mACollection, "view_day");
00357 (void)new KAction(i18n("W&ork Week"), "5days", 0,
00358 mCalendarView->viewManager(), SLOT(showWorkWeekView()),
00359 mACollection, "view_workweek");
00360 (void)new KAction(i18n("&Week"), "7days", 0,
00361 mCalendarView->viewManager(), SLOT(showWeekView()),
00362 mACollection, "view_week");
00363 mNextXDays = new KAction("", "xdays", 0,mCalendarView->viewManager(),
00364 SLOT(showNextXView()),mACollection, "view_nextx");
00365 mNextXDays->setText(i18n("&Next Day", "Ne&xt %n Days", KOPrefs::instance()->mNextXDays));
00366 (void)new KAction(i18n("&Month"), "month", 0,
00367 mCalendarView->viewManager(), SLOT(showMonthView()),
00368 mACollection, "view_month");
00369 (void)new KAction(i18n("&To-Do List"), "todo", 0,
00370 mCalendarView->viewManager(), SLOT(showTodoView()),
00371 mACollection, "view_todo");
00372 (void)new KAction(i18n("&Journal"), "journal", 0,
00373 mCalendarView->viewManager(), SLOT(showJournalView()),
00374 mACollection, "view_journal");
00375 (void)new KAction(i18n("&Time Span"), "timespan", 0,
00376 mCalendarView->viewManager(), SLOT(showTimeSpanView()),
00377 mACollection, "view_timespan");
00378 (void)new KAction(i18n("&Update"), 0,
00379 mCalendarView, SLOT( updateView() ),
00380 mACollection, "update");
00381
00382
00383
00384 (void)new KAction(i18n("New E&vent..."), "appointment", 0,
00385 mCalendarView,SLOT( newEvent() ),
00386 mACollection, "new_event");
00387 (void)new KAction(i18n("New &To-Do..."), "newtodo", 0,
00388 mCalendarView,SLOT(newTodo()),
00389 mACollection, "new_todo");
00390 action = new KAction(i18n("New Su&b-To-Do..."), 0,
00391 mCalendarView,SLOT(newSubTodo()),
00392 mACollection, "new_subtodo");
00393 action->setEnabled(false);
00394 connect(mCalendarView,SIGNAL(todoSelected(bool)),
00395 action,SLOT(setEnabled(bool)));
00396
00397 mShowIncidenceAction = new KAction(i18n("&Show"), 0,
00398 mCalendarView,SLOT(showIncidence()),
00399 mACollection, "show_incidence");
00400 mEditIncidenceAction = new KAction(i18n("&Edit..."), 0,
00401 mCalendarView,SLOT(editIncidence()),
00402 mACollection, "edit_incidence");
00403 mDeleteIncidenceAction = new KAction(i18n("&Delete"), Key_Delete,
00404 mCalendarView,SLOT(deleteIncidence()),
00405 mACollection, "delete_incidence");
00406
00407 #if 0
00408 action = new KAction(i18n("T&ake over Event"), 0,
00409 mCalendarView,SLOT(takeOverEvent()),
00410 mACollection, "takeover_event");
00411 connect(mCalendarView,SIGNAL(eventsSelected(bool)),
00412 action,SLOT(setEnabled(bool)));
00413 (void)new KAction(i18n("T&ake over Calendar"), 0,
00414 mCalendarView,SLOT(takeOverCalendar()),
00415 mACollection, "takeover_calendar");
00416
00417 action = new KAction(i18n("&Mail Appointment"), "mail_generic", 0,
00418 mCalendarView,SLOT(action_mail()),
00419 mACollection, "mail_appointment");
00420 connect(mCalendarView,SIGNAL(eventsSelected(bool)),
00421 action,SLOT(setEnabled(bool)));
00422 #endif
00423
00424 action = new KAction(i18n("&Make Sub-To-Do Independent"), 0,
00425 mCalendarView,SLOT(todo_unsub()),
00426 mACollection, "unsub_todo");
00427 action->setEnabled(false);
00428 connect(mCalendarView,SIGNAL(todoSelected(bool)),
00429 action,SLOT(setEnabled(bool)));
00430
00431
00432
00433 (void)new KAction(i18n("Outgoing Messages"),0,
00434 mCalendarView->dialogManager(),SLOT(showOutgoingDialog()),
00435 mACollection,"outgoing");
00436 (void)new KAction(i18n("Incoming Messages"),0,
00437 mCalendarView->dialogManager(),SLOT(showIncomingDialog()),
00438 mACollection,"incoming");
00439 mPublishEvent = new KAction(i18n("Publish..."),"mail_send",0,
00440 mCalendarView,SLOT(schedule_publish()),
00441 mACollection,"publish");
00442 mPublishEvent->setEnabled(false);
00443 action = new KAction(i18n("Request"),"mail_generic",0,
00444 mCalendarView,SLOT(schedule_request()),
00445 mACollection,"request");
00446 action->setEnabled(false);
00447 connect(mCalendarView,SIGNAL(organizerEventsSelected(bool)),
00448 action,SLOT(setEnabled(bool)));
00449 action = new KAction(i18n("Refresh"),0,
00450 mCalendarView,SLOT(schedule_refresh()),
00451 mACollection,"refresh");
00452 action->setEnabled(false);
00453 connect(mCalendarView,SIGNAL(groupEventsSelected(bool)),
00454 action,SLOT(setEnabled(bool)));
00455 action = new KAction(i18n("Cancel"),0,
00456 mCalendarView,SLOT(schedule_cancel()),
00457 mACollection,"cancel");
00458 action->setEnabled(false);
00459 connect(mCalendarView,SIGNAL(organizerEventsSelected(bool)),
00460 action,SLOT(setEnabled(bool)));
00461
00462
00463
00464
00465
00466 action = new KAction(i18n("Reply"),"mail_reply",0,
00467 mCalendarView,SLOT(schedule_reply()),
00468 mACollection,"reply");
00469 action->setEnabled(false);
00470 connect(mCalendarView,SIGNAL(groupEventsSelected(bool)),
00471 action,SLOT(setEnabled(bool)));
00472 action = new KAction(i18n("counter proposal","Counter"),0,
00473 mCalendarView,SLOT(schedule_counter()),
00474 mACollection,"counter");
00475 action->setEnabled(false);
00476 connect(mCalendarView,SIGNAL(groupEventsSelected(bool)),
00477 action,SLOT(setEnabled(bool)));
00478 action = new KAction(i18n("Publish Free Busy Information"),0,
00479 mCalendarView,SLOT(schedule_publish_freebusy()),
00480 mACollection,"publish_freebusy");
00481 action->setEnabled(true);
00482
00483
00484
00485
00486
00487
00488 if ( !mIsPart ) {
00489 action = new KAction(i18n("Addressbook"),"contents",0,
00490 mCalendarView,SLOT(openAddressbook()),
00491 mACollection,"addressbook");
00492 }
00493
00494
00495 bool isRTL = QApplication::reverseLayout();
00496
00497 (void)new KAction(i18n("Go to &Today"), "today", 0,
00498 mCalendarView,SLOT(goToday()),
00499 mACollection, "go_today");
00500
00501 action = new KAction(i18n("Go &Backward"), isRTL ? "1rightarrow" : "1leftarrow", 0,
00502 mCalendarView,SLOT(goPrevious()),
00503 mACollection, "go_previous");
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514 action = new KAction(i18n("Go &Forward"), isRTL ? "1leftarrow" : "1rightarrow", 0,
00515 mCalendarView,SLOT(goNext()),
00516 mACollection, "go_next");
00517
00518
00519
00520
00521
00522
00523
00524 if ( mIsPart ) {
00525 new KAction( i18n("&Configure KOrganizer..."),
00526 "configure", 0, mCalendarView,
00527 SLOT(edit_options()), mACollection,
00528 "korganizer_configure" );
00529 new KAction( i18n("Configure S&hortcuts..."),
00530 "configure_shortcuts", 0, this,
00531 SLOT(keyBindings()), mACollection,
00532 "korganizer_configure_shortcuts" );
00533 } else {
00534 KStdAction::preferences(mCalendarView, SLOT(edit_options()),
00535 mACollection);
00536 KStdAction::keyBindings(this, SLOT(keyBindings()), mACollection);
00537 }
00538
00539 (void)new KAction(i18n("Edit C&ategories..."), 0,
00540 mCalendarView->dialogManager(),
00541 SLOT(showCategoryEditDialog()),
00542 mACollection,"edit_categories");
00543 (void)new KAction(i18n("Edit &Filters..."), 0,
00544 mCalendarView,SLOT(editFilters()),
00545 mACollection,"edit_filters");
00546 (void)new KAction(i18n("Configure &Plugins..."), 0,
00547 mCalendarView->dialogManager(),SLOT(showPluginDialog()),
00548 mACollection,"configure_plugins");
00549
00550 #if 0
00551 (void)new KAction(i18n("Show Intro Page"), 0,
00552 mCalendarView,SLOT(showIntro()),
00553 mACollection,"show_intro");
00554 #endif
00555
00556 KConfig *config = KOGlobals::self()->config();
00557 config->setGroup("Settings");
00558 mFilterViewAction->setChecked(config->readBoolEntry("Filter Visible",false));
00559 toggleFilterView();
00560 }
00561
00562 void ActionManager::readSettings()
00563 {
00564
00565
00566
00567 KConfig *config = KOGlobals::self()->config();
00568 if ( mRecent ) mRecent->loadEntries( config );
00569 mCalendarView->readSettings();
00570 }
00571
00572 void ActionManager::writeSettings()
00573 {
00574 kdDebug(5850) << "ActionManager::writeSettings" << endl;
00575 KConfig *config = KOGlobals::self()->config();
00576 mCalendarView->writeSettings();
00577
00578 config->setGroup( "Settings" );
00579 config->writeEntry( "Filter Visible", mFilterViewAction->isChecked() );
00580 if ( mRecent ) mRecent->saveEntries( config );
00581 }
00582
00583 void ActionManager::file_new()
00584 {
00585 emit actionNew();
00586 }
00587
00588 void ActionManager::file_open()
00589 {
00590 KURL url;
00591 QString defaultPath = locateLocal("data","korganizer/");
00592 url = KFileDialog::getOpenURL(defaultPath,i18n("*.vcs *.ics|Calendar Files"),
00593 mCalendarView->topLevelWidget());
00594
00595 if (url.isEmpty()) return;
00596
00597 KOrg::MainWindow *korg=ActionManager::findInstance(url);
00598 if ((0 != korg)&&(korg != mMainWindow)) {
00599 KWin::setActiveWindow(korg->topLevelWidget()->winId());
00600 return;
00601 }
00602
00603 kdDebug(5850) << "ActionManager::file_open(): " << url.prettyURL() << endl;
00604
00605
00606 if (!mCalendarView->isModified() && mFile.isEmpty() && !mCalendarResources ) {
00607 openURL(url);
00608 } else {
00609 emit actionNew( url );
00610 }
00611 }
00612
00613 void ActionManager::file_openRecent(const KURL& url)
00614 {
00615 if (!url.isEmpty()) {
00616 KOrg::MainWindow *korg=ActionManager::findInstance(url);
00617 if ((0 != korg)&&(korg != mMainWindow)) {
00618 KWin::setActiveWindow(korg->topLevelWidget()->winId());
00619 return;
00620 }
00621 openURL(url);
00622 }
00623 }
00624
00625 void ActionManager::file_import()
00626 {
00627
00628
00629 int retVal = -1;
00630 QString progPath;
00631 KTempFile tmpfn;
00632
00633 QString homeDir = QDir::homeDirPath() + QString::fromLatin1("/.calendar");
00634
00635 if (!QFile::exists(homeDir)) {
00636 KMessageBox::error(mCalendarView->topLevelWidget(),
00637 i18n("You have no ical file in your home directory.\n"
00638 "Import cannot proceed.\n"));
00639 return;
00640 }
00641
00642 KProcess proc;
00643 proc << "ical2vcal" << tmpfn.name();
00644 bool success = proc.start( KProcess::Block );
00645
00646 if ( !success ) {
00647 kdDebug(5850) << "Error starting ical2vcal." << endl;
00648 return;
00649 } else {
00650 retVal = proc.exitStatus();
00651 }
00652
00653 kdDebug(5850) << "ical2vcal return value: " << retVal << endl;
00654
00655 if (retVal >= 0 && retVal <= 2) {
00656
00657 mCalendarView->openCalendar(tmpfn.name(),1);
00658 if (!retVal)
00659 KMessageBox::information(mCalendarView->topLevelWidget(),
00660 i18n("KOrganizer successfully imported and "
00661 "merged your .calendar file from ical "
00662 "into the currently opened calendar."));
00663 else
00664 KMessageBox::information(mCalendarView->topLevelWidget(),
00665 i18n("KOrganizer encountered some unknown fields while "
00666 "parsing your .calendar ical file, and had to "
00667 "discard them. Please check to see that all "
00668 "your relevant data was correctly imported."),
00669 i18n("ICal Import Successful With Warning"));
00670 } else if (retVal == -1) {
00671 KMessageBox::error(mCalendarView->topLevelWidget(),
00672 i18n("KOrganizer encountered an error parsing your "
00673 ".calendar file from ical. Import has failed."));
00674 } else if (retVal == -2) {
00675 KMessageBox::error(mCalendarView->topLevelWidget(),
00676 i18n("KOrganizer doesn't think that your .calendar "
00677 "file is a valid ical calendar. Import has failed."));
00678 }
00679 tmpfn.unlink();
00680 }
00681
00682 void ActionManager::file_merge()
00683 {
00684 KURL url = KFileDialog::getOpenURL(locateLocal("data","korganizer/"),
00685 i18n("*.vcs *.ics|Calendar Files"),
00686 mCalendarView->topLevelWidget());
00687 openURL(url,true);
00688 }
00689
00690 void ActionManager::file_archive()
00691 {
00692 mCalendarView->archiveCalendar();
00693 }
00694
00695 void ActionManager::file_revert()
00696 {
00697 openURL(mURL);
00698 }
00699
00700 void ActionManager::file_saveas()
00701 {
00702 KURL url = getSaveURL();
00703
00704 if (url.isEmpty()) return;
00705
00706 saveAsURL(url);
00707 }
00708
00709 void ActionManager::file_save()
00710 {
00711 if ( mMainWindow->hasDocument() ) {
00712 if (mURL.isEmpty()) {
00713 file_saveas();
00714 } else {
00715 saveURL();
00716 }
00717 } else {
00718 mCalendarView->calendar()->save();
00719 }
00720 }
00721
00722 void ActionManager::file_close()
00723 {
00724 if (!saveModifiedURL()) return;
00725
00726 mCalendarView->closeCalendar();
00727 KIO::NetAccess::removeTempFile(mFile);
00728 mURL="";
00729 mFile="";
00730
00731 setTitle();
00732 }
00733
00734 bool ActionManager::openURL(const KURL &url,bool merge)
00735 {
00736 kdDebug(5850) << "ActionManager::openURL()" << endl;
00737
00738 if (url.isEmpty()) {
00739 kdDebug(5850) << "ActionManager::openURL(): Error! Empty URL." << endl;
00740 return false;
00741 }
00742 if ( !url.isValid() ) {
00743 kdDebug(5850) << "ActionManager::openURL(): Error! URL is malformed." << endl;
00744 return false;
00745 }
00746
00747 QString tmpFile;
00748 if( KIO::NetAccess::download( url, tmpFile, view() ) ) {
00749 kdDebug(5850) << "--- Downloaded to " << tmpFile << endl;
00750 bool success = mCalendarView->openCalendar(tmpFile,merge);
00751 if (merge) {
00752 KIO::NetAccess::removeTempFile(tmpFile);
00753 if (success)
00754 mMainWindow->showStatusMessage(i18n("Merged calendar '%1'.").arg(url.prettyURL()));
00755 } else {
00756 if (success) {
00757 KIO::NetAccess::removeTempFile(mFile);
00758 mURL = url;
00759 mFile = tmpFile;
00760 KConfig *config = KOGlobals::self()->config();
00761 config->setGroup("General");
00762 setTitle();
00763 kdDebug(5850) << "-- Add recent URL: " << url.prettyURL() << endl;
00764 if ( mRecent ) mRecent->addURL(url);
00765 mMainWindow->showStatusMessage(i18n("Opened calendar '%1'.").arg(mURL.prettyURL()));
00766 }
00767 }
00768 return success;
00769 } else {
00770 QString msg;
00771 msg = i18n("Cannot download calendar from '%1'.").arg(url.prettyURL());
00772 KMessageBox::error(mCalendarView->topLevelWidget(),msg);
00773 return false;
00774 }
00775 }
00776
00777 void ActionManager::closeURL()
00778 {
00779 kdDebug(5850) << "ActionManager::closeURL()" << endl;
00780
00781 file_close();
00782 }
00783
00784 bool ActionManager::saveURL()
00785 {
00786 QString ext;
00787
00788 if ( mURL.isLocalFile() ) {
00789 ext = mFile.right( 4 );
00790 } else {
00791 ext = mURL.filename().right( 4 );
00792 }
00793
00794 if ( ext == ".vcs" ) {
00795 int result = KMessageBox::warningContinueCancel(
00796 mCalendarView->topLevelWidget(),
00797 i18n("Your calendar will be saved in iCalendar format. Use "
00798 "'Export vCalendar' to save in vCalendar format."),
00799 i18n("Format Conversion"), i18n("Proceed"), "dontaskFormatConversion",
00800 true );
00801 if ( result != KMessageBox::Continue ) return false;
00802
00803 QString filename = mURL.fileName();
00804 filename.replace( filename.length() - 4, 4, ".ics" );
00805 mURL.setFileName( filename );
00806 if ( mURL.isLocalFile() ) {
00807 mFile = mURL.path();
00808 }
00809 setTitle();
00810 if ( mRecent ) mRecent->addURL( mURL );
00811 }
00812
00813 if ( !mCalendarView->saveCalendar( mFile ) ) {
00814 kdDebug(5850) << "ActionManager::saveURL(): calendar view save failed."
00815 << endl;
00816 return false;
00817 } else {
00818 mCalendarView->setModified( false );
00819 }
00820
00821 if ( !mURL.isLocalFile() ) {
00822 if ( !KIO::NetAccess::upload( mFile, mURL, view() ) ) {
00823 QString msg = i18n("Cannot upload calendar to '%1'")
00824 .arg( mURL.prettyURL() );
00825 KMessageBox::error( mCalendarView->topLevelWidget() ,msg );
00826 return false;
00827 }
00828 }
00829
00830
00831 if (KOPrefs::instance()->mAutoSave) {
00832 mAutoSaveTimer->stop();
00833 mAutoSaveTimer->start(1000*60*KOPrefs::instance()->mAutoSaveInterval);
00834 }
00835
00836 mMainWindow->showStatusMessage(i18n("Saved calendar '%1'.").arg(mURL.prettyURL()));
00837
00838
00839 if ( KOPrefs::instance()->mHtmlWithSave==true &&
00840 !KOPrefs::instance()->mHtmlExportFile.isNull() ) {
00841 KURL dest( KOPrefs::instance()->mHtmlExportFile );
00842 KCal::HtmlExport mExport( mCalendarView->calendar() );
00843 mExport.setEmail( KOPrefs::instance()->email() );
00844 mExport.setFullName( KOPrefs::instance()->fullName() );
00845
00846 KConfig *cfg = KOGlobals::self()->config();
00847 cfg->setGroup( "HtmlExport" );
00848
00849 mExport.setMonthViewEnabled( cfg->readBoolEntry( "Month", false ) );
00850 mExport.setEventsEnabled( cfg->readBoolEntry( "Event", true ) );
00851 mExport.setTodosEnabled( cfg->readBoolEntry( "Todo", true ) );
00852 mExport.setCategoriesEventEnabled( cfg->readBoolEntry( "CategoriesEvent", false ) );
00853 mExport.setAttendeesEventEnabled( cfg->readBoolEntry( "AttendeesEvent", false ) );
00854 mExport.setExcludePrivateEventEnabled( cfg->readBoolEntry( "ExcludePrivateEvent", true ) );
00855 mExport.setExcludeConfidentialEventEnabled( cfg->readBoolEntry( "ExcludeConfidentialEvent", true ) );
00856 mExport.setCategoriesTodoEnabled( cfg->readBoolEntry( "CategoriesTodo", false ) );
00857 mExport.setAttendeesTodoEnabled( cfg->readBoolEntry( "AttendeesTodo", false ) );
00858 mExport.setExcludePrivateTodoEnabled( cfg->readBoolEntry( "ExcludePrivateTodo", true ) );
00859 mExport.setExcludeConfidentialTodoEnabled( cfg->readBoolEntry( "ExcludeConfidentialTodo", true ) );
00860 mExport.setDueDateEnabled( cfg->readBoolEntry( "DueDates", true ) );
00861 QDate qd1;
00862 qd1 = QDate::currentDate();
00863 QDate qd2;
00864 qd2 = QDate::currentDate();
00865 if ( mExport.monthViewEnabled() )
00866 qd2.addMonths( 1 );
00867 else
00868 qd2.addDays( 7 );
00869
00870 mExport.setDateRange( qd1, qd2 );
00871 QDate cdate=qd1;
00872 while (cdate<=qd2)
00873 {
00874 if ( !KOCore::self()->holiday(cdate).isEmpty() )
00875 mExport.addHoliday( cdate, KOCore::self()->holiday(cdate) );
00876 cdate = cdate.addDays(1);
00877 }
00878
00879 if ( dest.isLocalFile() ) {
00880 mExport.save( dest.path() );
00881 } else {
00882 KTempFile tf;
00883 QString tfile = tf.name();
00884 tf.close();
00885 mExport.save( tfile );
00886 if (!KIO::NetAccess::upload( tfile, dest, view() ) ) {
00887 KNotifyClient::event ( view()->winId(),
00888 i18n("Could not upload file.") );
00889 }
00890 tf.unlink();
00891 }
00892 }
00893
00894 return true;
00895 }
00896
00897 bool ActionManager::saveAsURL(const KURL &url)
00898 {
00899 kdDebug(5850) << "ActionManager::saveAsURL() " << url.prettyURL() << endl;
00900
00901 if ( url.isEmpty() ) {
00902 kdDebug(5850) << "ActionManager::saveAsURL(): Empty URL." << endl;
00903 return false;
00904 }
00905 if ( !url.isValid() ) {
00906 kdDebug(5850) << "ActionManager::saveAsURL(): Malformed URL." << endl;
00907 return false;
00908 }
00909
00910 QString fileOrig = mFile;
00911 KURL URLOrig = mURL;
00912
00913 KTempFile *tempFile = 0;
00914 if (url.isLocalFile()) {
00915 mFile = url.path();
00916 } else {
00917 tempFile = new KTempFile;
00918 mFile = tempFile->name();
00919 }
00920 mURL = url;
00921
00922 bool success = saveURL();
00923 if (success) {
00924 delete mTempFile;
00925 mTempFile = tempFile;
00926 KIO::NetAccess::removeTempFile(fileOrig);
00927 KConfig *config = KOGlobals::self()->config();
00928 config->setGroup("General");
00929 setTitle();
00930 if ( mRecent ) mRecent->addURL(mURL);
00931 } else {
00932 kdDebug(5850) << "ActionManager::saveAsURL() failed" << endl;
00933 mURL = URLOrig;
00934 mFile = fileOrig;
00935 delete tempFile;
00936 }
00937
00938 return success;
00939 }
00940
00941
00942 bool ActionManager::saveModifiedURL()
00943 {
00944 kdDebug(5850) << "ActionManager::saveModifiedURL()" << endl;
00945
00946
00947 if (!mCalendarView->isModified()) return true;
00948
00949 mHtmlExportSync = true;
00950 if (KOPrefs::instance()->mAutoSave && !mURL.isEmpty()) {
00951
00952 return saveURL();
00953 } else {
00954 int result = KMessageBox::warningYesNoCancel(
00955 mCalendarView->topLevelWidget(),
00956 i18n("The calendar has been modified.\nDo you want to save it?"),
00957 QString::null,
00958 KStdGuiItem::save(), KStdGuiItem::discard());
00959 switch(result) {
00960 case KMessageBox::Yes:
00961 if (mURL.isEmpty()) {
00962 KURL url = getSaveURL();
00963 return saveAsURL(url);
00964 } else {
00965 return saveURL();
00966 }
00967 case KMessageBox::No:
00968 return true;
00969 case KMessageBox::Cancel:
00970 default:
00971 {
00972 mHtmlExportSync = false;
00973 return false;
00974 }
00975 }
00976 }
00977 }
00978
00979
00980 KURL ActionManager::getSaveURL()
00981 {
00982 KURL url = KFileDialog::getSaveURL(locateLocal("data","korganizer/"),
00983 i18n("*.vcs *.ics|Calendar Files"),
00984 mCalendarView->topLevelWidget());
00985
00986 if (url.isEmpty()) return url;
00987
00988 QString filename = url.fileName(false);
00989
00990 QString e = filename.right(4);
00991 if (e != ".vcs" && e != ".ics") {
00992
00993 filename += ".ics";
00994 }
00995
00996 url.setFileName(filename);
00997
00998 kdDebug(5850) << "ActionManager::getSaveURL(): url: " << url.url() << endl;
00999
01000 return url;
01001 }
01002
01003 void ActionManager::saveProperties(KConfig *config)
01004 {
01005 kdDebug() << "ActionManager::saveProperties" << endl;
01006
01007 config->writeEntry( "UseResourceCalendar", !mMainWindow->hasDocument() );
01008 if ( mMainWindow->hasDocument() ) {
01009 config->writePathEntry("Calendar",mURL.url());
01010 }
01011 }
01012
01013 void ActionManager::readProperties(KConfig *config)
01014 {
01015 kdDebug() << "ActionManager::readProperties" << endl;
01016
01017 bool isResourceCalendar(
01018 config->readBoolEntry( "UseResourceCalendar", true ) );
01019 QString calendarUrl = config->readPathEntry("Calendar");
01020
01021 if (!isResourceCalendar && !calendarUrl.isEmpty()) {
01022 mMainWindow->init( true );
01023 KURL u(calendarUrl);
01024 openURL(u);
01025 } else {
01026 mMainWindow->init( false );
01027 }
01028 }
01029
01030 void ActionManager::checkAutoSave()
01031 {
01032 kdDebug(5850) << "ActionManager::checkAutoSave()" << endl;
01033
01034
01035 if (KOPrefs::instance()->mAutoSaveInterval == 0) return;
01036
01037
01038 if ( KOPrefs::instance()->mAutoSave ) {
01039 if ( mCalendarResources || ( mCalendar && !url().isEmpty() ) ) {
01040 saveCalendar();
01041 }
01042 }
01043 }
01044
01045
01046
01047 void ActionManager::updateConfig()
01048 {
01049 kdDebug(5850) << "ActionManager::updateConfig()" << endl;
01050
01051 if ( KOPrefs::instance()->mAutoSave && !mAutoSaveTimer->isActive() ) {
01052 checkAutoSave();
01053 if ( KOPrefs::instance()->mAutoSaveInterval > 0) {
01054 mAutoSaveTimer->start( 1000 * 60 *
01055 KOPrefs::instance()->mAutoSaveInterval );
01056 }
01057 }
01058 if ( !KOPrefs::instance()->mAutoSave ) mAutoSaveTimer->stop();
01059 mNextXDays->setText( i18n( "&Next Day", "&Next %n Days",
01060 KOPrefs::instance()->mNextXDays ) );
01061
01062 KOCore::self()->reloadPlugins();
01063 mParts = KOCore::self()->reloadParts( mMainWindow, mParts );
01064
01065 setDestinationPolicy();
01066 }
01067
01068 void ActionManager::setDestinationPolicy()
01069 {
01070 if ( mCalendarResources ) {
01071 if ( KOPrefs::instance()->mDestination == KOPrefs::askDestination )
01072 mCalendarResources->setAskDestinationPolicy();
01073 else
01074 mCalendarResources->setStandardDestinationPolicy();
01075 }
01076 }
01077
01078 void ActionManager::configureDateTime()
01079 {
01080 KProcess *proc = new KProcess;
01081 *proc << "kcmshell" << "language";
01082
01083 connect(proc,SIGNAL(processExited(KProcess *)),
01084 SLOT(configureDateTimeFinished(KProcess *)));
01085
01086 if (!proc->start()) {
01087 KMessageBox::sorry(mCalendarView->topLevelWidget(),
01088 i18n("Couldn't start control module for date and time format."));
01089 delete proc;
01090 }
01091 }
01092
01093 void ActionManager::showTip()
01094 {
01095 KTipDialog::showTip(mCalendarView->topLevelWidget(),QString::null,true);
01096 }
01097
01098 void ActionManager::showTipOnStart()
01099 {
01100 KTipDialog::showTip(mCalendarView->topLevelWidget());
01101 }
01102
01103 KOrg::MainWindow *ActionManager::findInstance( const KURL &url )
01104 {
01105 if ( mWindowList ) {
01106 if ( url.isEmpty() ) return mWindowList->defaultInstance();
01107 else return mWindowList->findInstance( url );
01108 } else {
01109 return 0;
01110 }
01111 }
01112
01113 void ActionManager::dumpText(const QString &str)
01114 {
01115 kdDebug(5850) << "ActionManager::dumpText(): " << str << endl;
01116 }
01117
01118 void ActionManager::toggleFilterView()
01119 {
01120 bool visible = mFilterViewAction->isChecked();
01121 mCalendarView->showFilter(visible);
01122 }
01123
01124 bool ActionManager::openURL(QString url)
01125 {
01126 return openURL(KURL(url));
01127 }
01128
01129 bool ActionManager::mergeURL(QString url)
01130 {
01131 return openURL(KURL(url),true);
01132 }
01133
01134 bool ActionManager::saveAsURL(QString url)
01135 {
01136 return saveAsURL(KURL(url));
01137 }
01138
01139 QString ActionManager::getCurrentURLasString() const
01140 {
01141 return mURL.url();
01142 }
01143
01144 bool ActionManager::deleteEvent(QString uid)
01145 {
01146 return mCalendarView->deleteEvent(uid);
01147 }
01148
01149 bool ActionManager::eventRequest(QString request, QCString receiver,
01150 QString ical)
01151 {
01152 if( !KOGroupware::instance() ) return false;
01153 return KOGroupware::instance()->incomingEventRequest(request, receiver,
01154 ical);
01155 }
01156
01157 bool ActionManager::eventReply( QString ical )
01158 {
01159 if( !KOGroupware::instance() ) return false;
01160 return KOGroupware::instance()->incidenceAnswer( ical );
01161 }
01162
01163 void ActionManager::configureDateTimeFinished(KProcess *proc)
01164 {
01165 delete proc;
01166 }
01167
01168 void ActionManager::downloadNewStuff()
01169 {
01170 kdDebug(5850) << "ActionManager::downloadNewStuff()" << endl;
01171
01172 if ( !mNewStuff ) mNewStuff = new KONewStuff( mCalendarView );
01173 mNewStuff->download();
01174 }
01175
01176 void ActionManager::uploadNewStuff()
01177 {
01178 if ( !mNewStuff ) mNewStuff = new KONewStuff( mCalendarView );
01179 mNewStuff->upload();
01180 }
01181
01182 QString ActionManager::localFileName()
01183 {
01184 return mFile;
01185 }
01186
01187 void ActionManager::processIncidenceSelection( Incidence *incidence )
01188 {
01189
01190
01191 if ( !incidence ) {
01192 enableIncidenceActions( false );
01193 return;
01194 }
01195
01196 enableIncidenceActions( true );
01197
01198 if ( incidence->type() == "Event" ) {
01199 mShowIncidenceAction->setText( i18n("&Show Event") );
01200 mEditIncidenceAction->setText( i18n("&Edit Event...") );
01201 mDeleteIncidenceAction->setText( i18n("&Delete Event") );
01202 } else if ( incidence->type() == "Todo" ) {
01203 mShowIncidenceAction->setText( i18n("&Show To-Do") );
01204 mEditIncidenceAction->setText( i18n("&Edit To-Do...") );
01205 mDeleteIncidenceAction->setText( i18n("&Delete To-Do") );
01206 } else {
01207 mShowIncidenceAction->setText( i18n("&Show") );
01208 mEditIncidenceAction->setText( i18n("&Edit...") );
01209 mDeleteIncidenceAction->setText( i18n("&Delete") );
01210 }
01211 }
01212
01213 void ActionManager::enableIncidenceActions( bool enabled )
01214 {
01215 mShowIncidenceAction->setEnabled( enabled );
01216 mEditIncidenceAction->setEnabled( enabled );
01217 mDeleteIncidenceAction->setEnabled( enabled );
01218
01219 mCutAction->setEnabled( enabled );
01220 mCopyAction->setEnabled( enabled );
01221 mDeleteAction->setEnabled( enabled );
01222 mPublishEvent->setEnabled( enabled );
01223 }
01224
01225 void ActionManager::keyBindings()
01226 {
01227 emit actionKeyBindings();
01228 }
01229
01230
01231 void ActionManager::loadParts()
01232 {
01233 mParts = KOCore::self()->loadParts( mMainWindow );
01234 }
01235
01236 void ActionManager::setTitle()
01237 {
01238 mMainWindow->setTitle();
01239 }
01240
01241 KCalendarIface::ResourceRequestReply ActionManager::resourceRequest( const QValueList<QPair<QDateTime, QDateTime> >&,
01242 const QCString& resource,
01243 const QString& vCalIn )
01244 {
01245 kdDebug(5850) << k_funcinfo << "resource=" << resource << " vCalIn=" << vCalIn << endl;
01246 KCalendarIface::ResourceRequestReply reply;
01247 reply.vCalOut = "VCalOut";
01248 return reply;
01249 }
01250
01251 void ActionManager::openEventEditor( QString text )
01252 {
01253 mCalendarView->newEvent( text );
01254 }
01255
01256 void ActionManager::openEventEditor( QString summary, QString description,
01257 QString attachment )
01258 {
01259 mCalendarView->newEvent( summary, description, attachment );
01260 }
01261
01262 void ActionManager::openTodoEditor( QString text )
01263 {
01264 mCalendarView->newTodo( text );
01265 }
01266
01267 void ActionManager::openTodoEditor( QString summary, QString description,
01268 QString attachment )
01269 {
01270 mCalendarView->newTodo( summary, description, attachment );
01271 }
01272
01273 void ActionManager::showTodoView()
01274 {
01275 mCalendarView->viewManager()->showTodoView();
01276 }
01277
01278 void ActionManager::showEventView()
01279 {
01280 mCalendarView->viewManager()->showEventView();
01281 }
01282
01283 void ActionManager::updateUndoAction( const QString &text )
01284 {
01285 if ( text.isNull() ) {
01286 mUndoAction->setEnabled( false );
01287 mUndoAction->setText( i18n("Undo") );
01288 } else {
01289 mUndoAction->setEnabled( true );
01290 if ( text.isEmpty() ) mUndoAction->setText( i18n("Undo") );
01291 else mUndoAction->setText( i18n("Undo (%1)").arg( text ) );
01292 }
01293 }
01294
01295 void ActionManager::updateRedoAction( const QString &text )
01296 {
01297 if ( text.isNull() ) {
01298 mRedoAction->setEnabled( false );
01299 mRedoAction->setText( i18n("Redo") );
01300 } else {
01301 mRedoAction->setEnabled( true );
01302 if ( text.isEmpty() ) mRedoAction->setText( i18n("Redo") );
01303 else mRedoAction->setText( i18n("Redo (%1)").arg( text ) );
01304 }
01305 }
01306
01307 bool ActionManager::queryClose()
01308 {
01309 kdDebug() << "ActionManager::queryClose()" << endl;
01310
01311 bool close = true;
01312
01313 if ( mCalendar ) {
01314 close = saveModifiedURL();
01315 } else if ( mCalendarResources ) {
01316 mCalendarResources->resourceManager()->writeConfig();
01317 if ( !mIsClosing ) {
01318 kdDebug(5850) << "!mIsClosing" << endl;
01319 if ( !saveResourceCalendar() ) return false;
01320
01321
01322 mIsClosing = true;
01323
01324
01325
01326 }
01327 if ( mCalendarResources->isSaving() ) {
01328 kdDebug(5850) << "KOrganizer::queryClose(): isSaving" << endl;
01329 close = false;
01330 } else {
01331 kdDebug(5850) << "KOrganizer::queryClose(): close = true" << endl;
01332 close = true;
01333 }
01334 } else {
01335 close = true;
01336 }
01337
01338 return close;
01339 }
01340
01341 void ActionManager::saveCalendar()
01342 {
01343 if ( mCalendar ) {
01344 if ( view()->isModified() ) {
01345 if ( !url().isEmpty() ) {
01346 saveURL();
01347 } else {
01348 QString location = locateLocal( "data", "korganizer/kontact.ics" );
01349 saveAsURL( location );
01350 }
01351 }
01352 } else if ( mCalendarResources ) {
01353 mCalendarResources->save();
01354
01355 }
01356 }
01357
01358 bool ActionManager::saveResourceCalendar()
01359 {
01360 if ( !mCalendarResources ) return false;
01361 CalendarResourceManager *m = mCalendarResources->resourceManager();
01362
01363 CalendarResourceManager::ActiveIterator it;
01364 for ( it = m->activeBegin(); it != m->activeEnd(); ++it ) {
01365 if ( (*it)->readOnly() ) continue;
01366 if ( !(*it)->save() ) {
01367 int result = KMessageBox::warningContinueCancel( view(),
01368 i18n("Saving '%1' failed. Please check, if the resource is "
01369 "properly configured.\nIgnore problem and continue without "
01370 "saving or cancel save?").arg( (*it)->resourceName() ),
01371 i18n("Save Error"), i18n("Don't save") );
01372 if ( result == KMessageBox::Cancel ) return false;
01373 }
01374 }
01375 return true;
01376 }
01377
01378 void ActionManager::importResource( const QString &url )
01379 {
01380 ResourceImportDialog *dialog;
01381 dialog = new ResourceImportDialog( url, mMainWindow->topLevelWidget() );
01382 dialog->show();
01383 }
01384
01385 #include "actionmanager.moc"