korganizer Library API Documentation

actionmanager.cpp

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