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