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
00028
00029 #include <stdlib.h>
00030
00031 #include <qcursor.h>
00032 #include <qtimer.h>
00033 #include <qvbox.h>
00034 #include <qfile.h>
00035
00036 #include <kglobal.h>
00037 #include <kdebug.h>
00038 #include <kiconloader.h>
00039 #include <kstandarddirs.h>
00040 #include <kstdaccel.h>
00041 #include <kfiledialog.h>
00042 #include <kaction.h>
00043 #include <kstdaction.h>
00044 #include <kedittoolbar.h>
00045 #include <ktempfile.h>
00046 #include <kio/netaccess.h>
00047 #include <kmessagebox.h>
00048 #include <dcopclient.h>
00049 #include <kprocess.h>
00050 #include <kwin.h>
00051 #include <kkeydialog.h>
00052 #include <ktip.h>
00053 #include <kstdguiitem.h>
00054
00055 #include <korganizer/part.h>
00056
00057 #include "komailclient.h"
00058 #include "calprinter.h"
00059 #include "calendarview.h"
00060 #include "koviewmanager.h"
00061 #include "kodialogmanager.h"
00062 #include "kowindowlist.h"
00063 #include "koprefs.h"
00064 #include "kocore.h"
00065 #include "konewstuff.h"
00066 #include "exportwebdialog.h"
00067
00068 #include "korganizer.h"
00069 using namespace KOrg;
00070 #include "korganizer.moc"
00071
00072
00073 KOWindowList *KOrganizer::windowList = 0;
00074
00075 KOrganizer::KOrganizer( const char *name )
00076 : MainWindow(name), DCOPObject("KOrganizerIface"),
00077 mAlarmDaemonIface("kalarmd","ad")
00078 {
00079 kdDebug() << "KOrganizer::KOrganizer()" << endl;
00080
00081 mTempFile = 0;
00082 mActive = false;
00083 mNewStuff = 0;
00084
00085
00086 if (!windowList) {
00087 windowList = new KOWindowList;
00088
00089 QTimer::singleShot(0,this,SLOT(showTipOnStart()));
00090 }
00091 windowList->addWindow(this);
00092
00093
00094
00095 mCalendarView = new CalendarView( this, "KOrganizer::CalendarView" );
00096 setCentralWidget(mCalendarView);
00097
00098
00099
00100 statusBar()->insertItem("",ID_GENERAL,10);
00101
00102
00103
00104 statusBar()->insertItem(i18n(" Incoming messages: %1 ").arg(0),
00105 ID_MESSAGES_IN);
00106 statusBar()->insertItem(i18n(" Outgoing messages: %2 ").arg(0),
00107 ID_MESSAGES_OUT);
00108 statusBar()->setItemAlignment(ID_MESSAGES_IN,AlignRight);
00109 statusBar()->setItemAlignment(ID_MESSAGES_OUT,AlignRight);
00110 connect(statusBar(),SIGNAL(pressed(int)),SLOT(statusBarPressed(int)));
00111
00112 initActions();
00113
00114 mParts = KOCore::self()->loadParts( this );
00115
00116 readSettings();
00117 mCalendarView->readSettings();
00118
00119
00120 mAutoSaveTimer = new QTimer(this);
00121 connect(mAutoSaveTimer,SIGNAL(timeout()),SLOT(checkAutoSave()));
00122 if (KOPrefs::instance()->mAutoSave &&
00123 KOPrefs::instance()->mAutoSaveInterval > 0) {
00124 mAutoSaveTimer->start(1000*60*KOPrefs::instance()->mAutoSaveInterval);
00125 }
00126
00127 setTitle();
00128
00129 connect(mCalendarView,SIGNAL(modifiedChanged(bool)),SLOT(setTitle()));
00130 connect(mCalendarView,SIGNAL(configChanged()),SLOT(updateConfig()));
00131
00132 connect(mCalendarView,SIGNAL(numIncomingChanged(int)),
00133 SLOT(setNumIncoming(int)));
00134 connect(mCalendarView,SIGNAL(numOutgoingChanged(int)),
00135 SLOT(setNumOutgoing(int)));
00136
00137 connect(mCalendarView,SIGNAL(statusMessage(const QString &)),
00138 SLOT(showStatusMessage(const QString &)));
00139
00140 connect( mCalendarView, SIGNAL( incidenceSelected( Incidence * ) ),
00141 SLOT( processIncidenceSelection( Incidence * ) ) );
00142
00143 processIncidenceSelection( 0 );
00144
00145
00146 mCalendarView->checkClipboard();
00147
00148 mCalendarView->lookForOutgoingMessages();
00149 mCalendarView->lookForIncomingMessages();
00150
00151 mHtmlExportSync = false;
00152
00153 kdDebug() << "KOrganizer::KOrganizer() done" << endl;
00154 }
00155
00156 bool KOrganizer::startedKAddressBook = false;
00157
00158 KOrganizer::~KOrganizer()
00159 {
00160 kdDebug() << "~KOrganizer()" << endl;
00161
00162 delete mNewStuff;
00163
00164
00165 KOCore::self()->unloadParts( this, mParts );
00166
00167
00168 if (KOrganizer::startedKAddressBook == true)
00169 {
00170 kdDebug() << "Closing down kaddressbook" << endl;
00171 DCOPClient *client = KApplication::kApplication()->dcopClient();
00172 const QByteArray noParamData;
00173 client->send("kaddressbook", "KAddressBookIface", "exit()", noParamData);
00174 }
00175
00176 if (mTempFile) delete mTempFile;
00177
00178
00179 windowList->removeWindow(this);
00180
00181 delete mCalendarView;
00182
00183 kdDebug() << "~KOrganizer() done" << endl;
00184 }
00185
00186
00187 void KOrganizer::readSettings()
00188 {
00189
00190
00191
00192 KConfig *config = kapp->config();
00193
00194 config->setGroup("KOrganizer Geometry");
00195
00196 int windowWidth = config->readNumEntry("Width",600);
00197 int windowHeight = config->readNumEntry("Height",400);
00198
00199 resize(windowWidth,windowHeight);
00200
00201 mRecent->loadEntries(config);
00202
00203 mCalendarView->readSettings();
00204
00205 config->sync();
00206 }
00207
00208
00209 void KOrganizer::writeSettings()
00210 {
00211 kdDebug() << "KOrganizer::writeSettings" << endl;
00212
00213 KConfig *config = kapp->config();
00214
00215 config->setGroup("KOrganizer Geometry");
00216
00217 config->writeEntry("Width",width());
00218 config->writeEntry("Height",height());
00219
00220 mCalendarView->writeSettings();
00221
00222 config->setGroup("Settings");
00223 config->writeEntry("Filter Visible",mFilterViewAction->isChecked());
00224
00225 mRecent->saveEntries(config);
00226
00227 saveMainWindowSettings(config,"MainWindow");
00228
00229 config->sync();
00230 }
00231
00232
00233 void KOrganizer::initActions()
00234 {
00235 KAction *action;
00236
00237
00238
00239 KStdAction::openNew(this, SLOT(file_new()), actionCollection());
00240 KStdAction::open(this, SLOT(file_open()), actionCollection());
00241 mRecent = KStdAction::openRecent(this, SLOT(file_openRecent(const KURL&)),
00242 actionCollection());
00243 KStdAction::revert(this,SLOT(file_revert()),actionCollection());
00244 KStdAction::save(this, SLOT(file_save()), actionCollection());
00245 KStdAction::saveAs(this, SLOT(file_saveas()), actionCollection());
00246 KStdAction::close(this, SLOT(file_close()), actionCollection());
00247 (void)new KAction(i18n("&Import From Ical"), 0, this, SLOT(file_import()),
00248 actionCollection(), "import_ical");
00249 (void)new KAction(i18n("&Merge Calendar..."), 0, this, SLOT(file_merge()),
00250 actionCollection(), "merge_calendar");
00251 (void)new KAction(i18n("Archive Old Entries..."), 0, this, SLOT(file_archive()),
00252 actionCollection(), "file_archive");
00253
00254 (void)new KAction(i18n("iCalendar..."), 0,
00255 mCalendarView, SLOT(exportICalendar()),
00256 actionCollection(), "export_icalendar");
00257 (void)new KAction(i18n("vCalendar..."), 0,
00258 mCalendarView, SLOT(exportVCalendar()),
00259 actionCollection(), "export_vcalendar");
00260
00261
00262 #if 0
00263 (void)new KAction(i18n("Print Setup..."), 0,
00264 mCalendarView, SLOT(printSetup()),
00265 actionCollection(), "print_setup");
00266 #endif
00267
00268 KStdAction::print(mCalendarView, SLOT(print()), actionCollection());
00269 #if 1
00270 KStdAction::printPreview(mCalendarView, SLOT(printPreview()),
00271 actionCollection());
00272 #endif
00273 (void)new KAction(i18n("Make Active"),0,this,SLOT(makeActive()),
00274 actionCollection(),"make_active");
00275 KStdAction::quit(this, SLOT(close()), actionCollection());
00276
00277
00278 new KAction( i18n("delete completed To-Dos","Purge Completed"), 0,
00279 mCalendarView, SLOT( purgeCompleted() ), actionCollection(),
00280 "purge_completed" );
00281
00282
00283
00284 mCutAction = KStdAction::cut(mCalendarView,SLOT(edit_cut()),
00285 actionCollection());
00286
00287 mCopyAction = KStdAction::copy(mCalendarView,SLOT(edit_copy()),
00288 actionCollection());
00289
00290 action = KStdAction::paste(mCalendarView,SLOT(edit_paste()),
00291 actionCollection());
00292 action->setEnabled( false );
00293 connect( mCalendarView, SIGNAL( pasteEnabled( bool ) ),
00294 action, SLOT( setEnabled( bool ) ) );
00295
00296 mDeleteAction = new KAction(i18n("&Delete"),"editdelete",0,
00297 mCalendarView,SLOT(appointment_delete()),
00298 actionCollection(), "edit_delete");
00299
00300 KStdAction::find(mCalendarView->dialogManager(), SLOT(showSearchDialog()),
00301 actionCollection());
00302
00303
00304
00305
00306 (void)new KAction(i18n("What's &Next"), "whatsnext", 0,
00307 mCalendarView->viewManager(), SLOT(showWhatsNextView()),
00308 actionCollection(), "view_whatsnext");
00309 (void)new KAction(i18n("&List"), "list", 0,
00310 mCalendarView->viewManager(), SLOT(showListView()),
00311 actionCollection(), "view_list");
00312 (void)new KAction(i18n("&Day"), "1day", 0,
00313 mCalendarView->viewManager(), SLOT(showDayView()),
00314 actionCollection(), "view_day");
00315 (void)new KAction(i18n("W&ork Week"), "5days", 0,
00316 mCalendarView->viewManager(), SLOT(showWorkWeekView()),
00317 actionCollection(), "view_workweek");
00318 (void)new KAction(i18n("&Week"), "7days", 0,
00319 mCalendarView->viewManager(), SLOT(showWeekView()),
00320 actionCollection(), "view_week");
00321 mNextXDays = new KAction("", "xdays", 0,mCalendarView->viewManager(),
00322 SLOT(showNextXView()),actionCollection(), "view_nextx");
00323 mNextXDays->setText(i18n("&Next Day", "&Next %n Days", KOPrefs::instance()->mNextXDays));
00324 (void)new KAction(i18n("&Month"), "month", 0,
00325 mCalendarView->viewManager(), SLOT(showMonthView()),
00326 actionCollection(), "view_month");
00327 (void)new KAction(i18n("&To-Do List"), "todo", 0,
00328 mCalendarView->viewManager(), SLOT(showTodoView()),
00329 actionCollection(), "view_todo");
00330 (void)new KAction(i18n("&Journal"), "journal", 0,
00331 mCalendarView->viewManager(), SLOT(showJournalView()),
00332 actionCollection(), "view_journal");
00333 (void)new KAction(i18n("&Time Span"), "timespan", 0,
00334 mCalendarView->viewManager(), SLOT(showTimeSpanView()),
00335 actionCollection(), "view_timespan");
00336 (void)new KAction(i18n("&Update"), 0,
00337 mCalendarView, SLOT(update()),
00338 actionCollection(), "update");
00339
00340
00341
00342 (void)new KAction(i18n("New E&vent..."), "appointment", 0,
00343 mCalendarView,SLOT( newEvent() ),
00344 actionCollection(), "new_event");
00345 (void)new KAction(i18n("New &To-Do..."), "newtodo", 0,
00346 mCalendarView,SLOT(newTodo()),
00347 actionCollection(), "new_todo");
00348 action = new KAction(i18n("New Su&b-To-Do..."), 0,
00349 mCalendarView,SLOT(newSubTodo()),
00350 actionCollection(), "new_subtodo");
00351 action->setEnabled(false);
00352 connect(mCalendarView,SIGNAL(todoSelected(bool)),
00353 action,SLOT(setEnabled(bool)));
00354
00355 mShowIncidenceAction = new KAction(i18n("&Show"), 0,
00356 mCalendarView,SLOT(showIncidence()),
00357 actionCollection(), "show_incidence");
00358 mEditIncidenceAction = new KAction(i18n("&Edit..."), 0,
00359 mCalendarView,SLOT(editIncidence()),
00360 actionCollection(), "edit_incidence");
00361 mDeleteIncidenceAction = new KAction(i18n("&Delete"), 0,
00362 mCalendarView,SLOT(deleteIncidence()),
00363 actionCollection(), "delete_incidence");
00364
00365 #if 0
00366 action = new KAction(i18n("T&ake over Event"), 0,
00367 mCalendarView,SLOT(takeOverEvent()),
00368 actionCollection(), "takeover_event");
00369 connect(mCalendarView,SIGNAL(eventsSelected(bool)),
00370 action,SLOT(setEnabled(bool)));
00371 (void)new KAction(i18n("T&ake over Calendar"), 0,
00372 mCalendarView,SLOT(takeOverCalendar()),
00373 actionCollection(), "takeover_calendar");
00374
00375 action = new KAction(i18n("&Mail Appointment"), "mail_generic", 0,
00376 mCalendarView,SLOT(action_mail()),
00377 actionCollection(), "mail_appointment");
00378 connect(mCalendarView,SIGNAL(eventsSelected(bool)),
00379 action,SLOT(setEnabled(bool)));
00380 #endif
00381
00382 action = new KAction(i18n("&Make Sub-To-Do Independent"), 0,
00383 mCalendarView,SLOT(todo_unsub()),
00384 actionCollection(), "unsub_todo");
00385 action->setEnabled(false);
00386 connect(mCalendarView,SIGNAL(todoSelected(bool)),
00387 action,SLOT(setEnabled(bool)));
00388
00389
00390
00391 (void)new KAction(i18n("Outgoing Messages"),0,
00392 mCalendarView->dialogManager(),SLOT(showOutgoingDialog()),
00393 actionCollection(),"outgoing");
00394 (void)new KAction(i18n("Incoming Messages"),0,
00395 mCalendarView->dialogManager(),SLOT(showIncomingDialog()),
00396 actionCollection(),"incoming");
00397 mPublishEvent = new KAction(i18n("Publish..."),"mail_send",0,
00398 mCalendarView,SLOT(schedule_publish()),
00399 actionCollection(),"publish");
00400 mPublishEvent->setEnabled(false);
00401 action = new KAction(i18n("Request"),"mail_generic",0,
00402 mCalendarView,SLOT(schedule_request()),
00403 actionCollection(),"request");
00404 action->setEnabled(false);
00405 connect(mCalendarView,SIGNAL(organizerEventsSelected(bool)),
00406 action,SLOT(setEnabled(bool)));
00407 action = new KAction(i18n("Refresh"),0,
00408 mCalendarView,SLOT(schedule_refresh()),
00409 actionCollection(),"refresh");
00410 action->setEnabled(false);
00411 connect(mCalendarView,SIGNAL(groupEventsSelected(bool)),
00412 action,SLOT(setEnabled(bool)));
00413 action = new KAction(i18n("Cancel"),0,
00414 mCalendarView,SLOT(schedule_cancel()),
00415 actionCollection(),"cancel");
00416 action->setEnabled(false);
00417 connect(mCalendarView,SIGNAL(organizerEventsSelected(bool)),
00418 action,SLOT(setEnabled(bool)));
00419
00420
00421
00422
00423
00424 action = new KAction(i18n("Reply"),"mail_reply",0,
00425 mCalendarView,SLOT(schedule_reply()),
00426 actionCollection(),"reply");
00427 action->setEnabled(false);
00428 connect(mCalendarView,SIGNAL(groupEventsSelected(bool)),
00429 action,SLOT(setEnabled(bool)));
00430 action = new KAction(i18n("counter proposal","Counter"),0,
00431 mCalendarView,SLOT(schedule_counter()),
00432 actionCollection(),"counter");
00433 action->setEnabled(false);
00434 connect(mCalendarView,SIGNAL(groupEventsSelected(bool)),
00435 action,SLOT(setEnabled(bool)));
00436 action = new KAction(i18n("Publish Free Busy Information"),0,
00437 mCalendarView,SLOT(schedule_publish_freebusy()),
00438 actionCollection(),"publish_freebusy");
00439 action->setEnabled(true);
00440
00441
00442
00443
00444
00445
00446 action = new KAction(i18n("Addressbook"),"contents",0,
00447 mCalendarView,SLOT(openAddressbook()),
00448 actionCollection(),"addressbook");
00449
00450
00451 bool isRTL = QApplication::reverseLayout();
00452
00453 (void)new KAction(i18n("Go to &Today"), "today", 0,
00454 mCalendarView,SLOT(goToday()),
00455 actionCollection(), "go_today");
00456 action = new KAction(i18n("Go &Backward"), isRTL ? "1rightarrow" : "1leftarrow", 0,
00457 mCalendarView,SLOT(goPrevious()),
00458 actionCollection(), "go_previous");
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468 action = new KAction(i18n("Go &Forward"), isRTL ? "1leftarrow" : "1rightarrow", 0,
00469 mCalendarView,SLOT(goNext()),
00470 actionCollection(), "go_next");
00471
00472
00473
00474
00475
00476
00477
00478
00479 (void)new KAction(i18n("Configure &Date && Time..."), 0,
00480 this,SLOT(configureDateTime()),
00481 actionCollection(), "conf_datetime");
00482
00483 mStatusBarAction = KStdAction::showStatusbar(this,SLOT(toggleStatusBar()),
00484 actionCollection());
00485
00486 mFilterViewAction = new KToggleAction(i18n("Show Filter"),0,this,
00487 SLOT(toggleFilterView()),
00488 actionCollection(),
00489 "show_filter");
00490
00491 KStdAction::configureToolbars(this, SLOT(configureToolbars()),
00492 actionCollection());
00493 KStdAction::preferences(mCalendarView, SLOT(edit_options()),
00494 actionCollection());
00495 KStdAction::keyBindings(this, SLOT(editKeys()), actionCollection());
00496
00497 (void)new KAction(i18n("Edit C&ategories..."), 0,
00498 mCalendarView->dialogManager(),
00499 SLOT(showCategoryEditDialog()),
00500 actionCollection(),"edit_categories");
00501 (void)new KAction(i18n("Edit &Filters..."), 0,
00502 mCalendarView,SLOT(editFilters()),
00503 actionCollection(),"edit_filters");
00504 (void)new KAction(i18n("Configure &Plugins..."), 0,
00505 mCalendarView->dialogManager(),SLOT(showPluginDialog()),
00506 actionCollection(),"configure_plugins");
00507
00508 #if 0
00509 (void)new KAction(i18n("Show Intro Page"), 0,
00510 mCalendarView,SLOT(showIntro()),
00511 actionCollection(),"show_intro");
00512 #endif
00513
00514 (void)new KAction(i18n("&Tip of the Day"), 0,
00515 this, SLOT(showTip()), actionCollection(), "help_tipofday");
00516
00517 new KAction( i18n("Get Hot New Stuff..."), 0, this,
00518 SLOT( downloadNewStuff() ), actionCollection(),
00519 "downloadnewstuff" );
00520
00521 new KAction( i18n("Upload Hot New Stuff..."), 0, this,
00522 SLOT( uploadNewStuff() ), actionCollection(),
00523 "uploadnewstuff" );
00524
00525 setInstance( KGlobal::instance() );
00526
00527 setXMLFile("korganizerui.rc");
00528 createGUI(0);
00529
00530 KConfig *config = kapp->config();
00531
00532 applyMainWindowSettings(config,"MainWindow");
00533
00534 config->setGroup("Settings");
00535 mFilterViewAction->setChecked(config->readBoolEntry("Filter Visible",false));
00536 toggleFilterView();
00537
00538 mStatusBarAction->setChecked(!statusBar()->isHidden());
00539
00540 QPtrListIterator<KToolBar> it = toolBarIterator();
00541 for ( ; it.current() ; ++it ) {
00542 KToggleAction *act = new KToggleAction(i18n("Show %1 Toolbar")
00543 .arg((*it)->text()),0,
00544 actionCollection(),(*it)->name());
00545 connect( act,SIGNAL(toggled(bool)),SLOT(toggleToolBars(bool)));
00546 act->setChecked(!(*it)->isHidden());
00547 mToolBarToggles.append(act);
00548 }
00549 plugActionList("toolbartoggles",mToolBarToggles);
00550 }
00551
00552 #if 0
00553 void KOrganizer::initViews()
00554 {
00555 kdDebug() << "KOrganizer::initViews()" << endl;
00556
00557
00558 KOrg::View::List views = KOCore::self()->views(this);
00559 KOrg::View *it;
00560 for( it=views.first(); it; it=views.next() ) {
00561 guiFactory()->addClient(it);
00562 }
00563 }
00564 #endif
00565
00566 void KOrganizer::file_new()
00567 {
00568
00569 (new KOrganizer())->show();
00570 }
00571
00572 void KOrganizer::file_open()
00573 {
00574 KURL url;
00575 QString defaultPath = locateLocal("appdata", "");
00576 url = KFileDialog::getOpenURL(defaultPath,i18n("*.vcs *.ics|Calendar files"),this);
00577
00578 if (url.isEmpty()) return;
00579
00580 KOrganizer *korg=KOrganizer::findInstance(url);
00581 if ((0 != korg)&&(korg != this)) {
00582 KWin::setActiveWindow(korg->winId());
00583 return;
00584 }
00585
00586 kdDebug() << "KOrganizer::file_open(): " << url.prettyURL() << endl;
00587
00588 if (!mCalendarView->isModified() && mFile.isEmpty()) {
00589 openURL(url);
00590 } else {
00591 KOrganizer *korg = new KOrganizer;
00592 if (korg->openURL(url)) {
00593 korg->show();
00594 } else {
00595 delete korg;
00596 }
00597 }
00598 }
00599
00600 void KOrganizer::file_openRecent(const KURL& url)
00601 {
00602 if (!url.isEmpty()) {
00603 KOrganizer *korg=KOrganizer::findInstance(url);
00604 if ((0 != korg)&&(korg != this)) {
00605 KWin::setActiveWindow(korg->winId());
00606 return;
00607 }
00608 openURL(url);
00609 }
00610 }
00611
00612 void KOrganizer::file_import()
00613 {
00614
00615
00616 int retVal = -1;
00617 QString progPath;
00618 KTempFile tmpfn;
00619
00620 QString homeDir = QDir::homeDirPath() + QString::fromLatin1("/.calendar");
00621
00622 if (!QFile::exists(homeDir)) {
00623 KMessageBox::error(this,
00624 i18n("You have no ical file in your home directory.\n"
00625 "Import cannot proceed.\n"));
00626 return;
00627 }
00628
00629 KProcess proc;
00630 proc << "ical2vcal" << tmpfn.name();
00631 bool success = proc.start( KProcess::Block );
00632
00633 if ( !success ) {
00634 kdDebug() << "Error starting ical2vcal." << endl;
00635 return;
00636 } else {
00637 retVal = proc.exitStatus();
00638 }
00639
00640 kdDebug() << "ical2vcal return value: " << retVal << endl;
00641
00642 if (retVal >= 0 && retVal <= 2) {
00643
00644 mCalendarView->openCalendar(tmpfn.name(),1);
00645 if (!retVal)
00646 KMessageBox::information(this,
00647 i18n("KOrganizer succesfully imported and "
00648 "merged your .calendar file from ical "
00649 "into the currently opened calendar."));
00650 else
00651 KMessageBox::information(this,
00652 i18n("KOrganizer encountered some unknown fields while "
00653 "parsing your .calendar ical file, and had to "
00654 "discard them. Please check to see that all "
00655 "your relevant data was correctly imported."),
00656 i18n("ICal Import Successful With Warning"));
00657 } else if (retVal == -1) {
00658 KMessageBox::error(this,
00659 i18n("KOrganizer encountered an error parsing your "
00660 ".calendar file from ical. Import has failed."));
00661 } else if (retVal == -2) {
00662 KMessageBox::error(this,
00663 i18n("KOrganizer doesn't think that your .calendar "
00664 "file is a valid ical calendar. Import has failed."));
00665 }
00666 tmpfn.unlink();
00667 }
00668
00669 void KOrganizer::file_merge()
00670 {
00671 KURL url = KFileDialog::getOpenURL(locateLocal("appdata", ""),
00672 i18n("*.vcs *.ics|Calendar files"),this);
00673 openURL(url,true);
00674 }
00675
00676 void KOrganizer::file_archive()
00677 {
00678 mCalendarView->archiveCalendar();
00679 }
00680
00681 void KOrganizer::file_revert()
00682 {
00683 openURL(mURL);
00684 }
00685
00686 void KOrganizer::file_saveas()
00687 {
00688 KURL url = getSaveURL();
00689
00690 if (url.isEmpty()) return;
00691
00692 saveAsURL(url);
00693 }
00694
00695 void KOrganizer::file_save()
00696 {
00697 if (mURL.isEmpty()) file_saveas();
00698 else saveURL();
00699 }
00700
00701 void KOrganizer::file_close()
00702 {
00703 if (!saveModifiedURL()) return;
00704
00705 mCalendarView->closeCalendar();
00706 KIO::NetAccess::removeTempFile(mFile);
00707 mURL="";
00708 mFile="";
00709
00710 setActive(false);
00711
00712 setTitle();
00713 }
00714
00715 void KOrganizer::file_quit()
00716 {
00717 close();
00718 }
00719
00720
00721 bool KOrganizer::openURL(const KURL &url,bool merge)
00722 {
00723 kdDebug() << "KOrganizer::openURL()" << endl;
00724
00725 if (url.isEmpty()) {
00726 kdDebug() << "KOrganizer::openURL(): Error! Empty URL." << endl;
00727 return false;
00728 }
00729 if (url.isMalformed()) {
00730 kdDebug() << "KOrganizer::openURL(): Error! URL is malformed." << endl;
00731 return false;
00732 }
00733
00734 QString tmpFile;
00735 if(KIO::NetAccess::download(url,tmpFile)) {
00736 kdDebug() << "--- Downloaded to " << tmpFile << endl;
00737 bool success = mCalendarView->openCalendar(tmpFile,merge);
00738 if (merge) {
00739 KIO::NetAccess::removeTempFile(tmpFile);
00740 if (success) {
00741 showStatusMessage(i18n("Merged calendar '%1'.").arg(url.prettyURL()));
00742 }
00743 } else {
00744 if (success) {
00745 KIO::NetAccess::removeTempFile(mFile);
00746 mURL = url;
00747 mFile = tmpFile;
00748 KGlobal::config()->setGroup("General");
00749 QString active = KGlobal::config()->readEntry("Active Calendar");
00750 if (KURL(active) == mURL) setActive(true);
00751 else setActive(false);
00752 setTitle();
00753 kdDebug() << "-- Add recent URL: " << url.prettyURL() << endl;
00754 mRecent->addURL(url);
00755 showStatusMessage(i18n("Opened calendar '%1'.").arg(mURL.prettyURL()));
00756 }
00757 }
00758 return success;
00759 } else {
00760 QString msg;
00761 msg = i18n("Cannot download calendar from '%1'.").arg(url.prettyURL());
00762 KMessageBox::error(this,msg);
00763 return false;
00764 }
00765 }
00766
00767 void KOrganizer::closeURL()
00768 {
00769 kdDebug() << "KOrganizer::closeURL()" << endl;
00770
00771 file_close();
00772 }
00773
00774 bool KOrganizer::saveURL()
00775 {
00776 QString ext;
00777
00778 if (mURL.isLocalFile()) {
00779 ext = mFile.right(4);
00780 } else {
00781 ext = mURL.filename().right(4);
00782 }
00783
00784 if (ext == ".vcs") {
00785 int result = KMessageBox::warningContinueCancel(this,
00786 i18n("Your calendar will be saved in iCalendar format. Use "
00787 "'Export vCalendar' to save in vCalendar format."),
00788 i18n("Format Conversion"),i18n("Proceed"),"dontaskFormatConversion",
00789 true);
00790 if (result != KMessageBox::Continue) return false;
00791
00792
00793 mAlarmDaemonIface.removeCal( mURL.url() );
00794 if (!mAlarmDaemonIface.ok() ) {
00795 kdDebug() << "KOrganizer::saveURL(): dcop send failed" << endl;
00796 }
00797
00798 QString filename = mURL.fileName();
00799 filename.replace(filename.length()-4,4,".ics");
00800 mURL.setFileName(filename);
00801 if (mURL.isLocalFile()) {
00802 mFile = mURL.path();
00803 }
00804 writeActiveState();
00805 setTitle();
00806 mRecent->addURL(mURL);
00807 }
00808
00809 if (!mCalendarView->saveCalendar(mFile)) {
00810 kdDebug() << "KOrganizer::saveURL(): calendar view save failed." << endl;
00811 return false;
00812 } else {
00813 mCalendarView->setModified( false );
00814 }
00815
00816 if (!mURL.isLocalFile()) {
00817 if (!KIO::NetAccess::upload(mFile,mURL)) {
00818 QString msg = i18n("Cannot upload calendar to '%1'").arg(mURL.prettyURL());
00819 KMessageBox::error(this,msg);
00820 return false;
00821 }
00822 }
00823
00824 if (isActive()) {
00825 kdDebug() << "KOrganizer::saveURL(): Notify alarm daemon" << endl;
00826 mAlarmDaemonIface.reloadCal("korgac",mURL.url());
00827 if (!mAlarmDaemonIface.ok()) {
00828 kdDebug() << "KOrganizer::saveUrl(): reloadCal call failed." << endl;
00829 }
00830 }
00831
00832
00833 if (KOPrefs::instance()->mAutoSave) {
00834 mAutoSaveTimer->stop();
00835 mAutoSaveTimer->start(1000*60*KOPrefs::instance()->mAutoSaveInterval);
00836 }
00837
00838 showStatusMessage(i18n("Saved calendar '%1'.").arg(mURL.prettyURL()));
00839
00840 if (KOPrefs::instance()->mHtmlWithSave==true) {
00841 ExportWebDialog *dlg = new ExportWebDialog(mCalendarView->calendar());
00842 dlg->exportWebPage(mHtmlExportSync);
00843 }
00844
00845 return true;
00846 }
00847
00848 bool KOrganizer::saveAsURL(const KURL &url)
00849 {
00850 kdDebug() << "KOrganizer::saveAsURL() " << url.prettyURL() << endl;
00851
00852 if (url.isEmpty()) {
00853 kdDebug() << "KOrganizer::saveAsURL(): Empty URL." << endl;
00854 return false;
00855 }
00856 if (url.isMalformed()) {
00857 kdDebug() << "KOrganizer::saveAsURL(): Malformed URL." << endl;
00858 return false;
00859 }
00860
00861 QString fileOrig = mFile;
00862 KURL URLOrig = mURL;
00863
00864 KTempFile *tempFile = 0;
00865 if (url.isLocalFile()) {
00866 mFile = url.path();
00867 } else {
00868 tempFile = new KTempFile;
00869 mFile = tempFile->name();
00870 }
00871 mURL = url;
00872
00873 bool success = saveURL();
00874 if (success) {
00875 delete mTempFile;
00876 mTempFile = tempFile;
00877 KIO::NetAccess::removeTempFile(fileOrig);
00878 KGlobal::config()->setGroup("General");
00879 QString active = KGlobal::config()->readEntry("Active Calendar");
00880 if (KURL(active) == mURL) {
00881 setActive(true);
00882
00883 } else {
00884 setActive(false);
00885 }
00886 setTitle();
00887 mRecent->addURL(mURL);
00888 } else {
00889 kdDebug() << "KOrganizer::saveAsURL() failed" << endl;
00890 mURL = URLOrig;
00891 mFile = fileOrig;
00892 delete tempFile;
00893 }
00894
00895 return success;
00896 }
00897
00898
00899 bool KOrganizer::saveModifiedURL()
00900 {
00901 kdDebug() << "KOrganizer::saveModifiedURL()" << endl;
00902
00903
00904 if (!mCalendarView->isModified()) return true;
00905
00906 mHtmlExportSync = true;
00907 if (KOPrefs::instance()->mAutoSave && !mURL.isEmpty()) {
00908
00909 return saveURL();
00910 } else {
00911 int result = KMessageBox::warningYesNoCancel(this,
00912 i18n("The calendar has been modified.\nDo you want to save it?"),
00913 QString::null,
00914 KStdGuiItem::save(), KStdGuiItem::discard());
00915 switch(result) {
00916 case KMessageBox::Yes:
00917 if (mURL.isEmpty()) {
00918 KURL url = getSaveURL();
00919 return saveAsURL(url);
00920 } else {
00921 return saveURL();
00922 }
00923 case KMessageBox::No:
00924 return true;
00925 case KMessageBox::Cancel:
00926 default:
00927 {
00928 mHtmlExportSync = false;
00929 return false;
00930 }
00931 }
00932 }
00933 }
00934
00935
00936 KURL KOrganizer::getSaveURL()
00937 {
00938 KURL url = KFileDialog::getSaveURL(locateLocal("appdata", ""),
00939 i18n("*.vcs *.ics|Calendar files"),this);
00940
00941 if (url.isEmpty()) return url;
00942
00943 QString filename = url.fileName(false);
00944
00945 QString e = filename.right(4);
00946 if (e != ".vcs" && e != ".ics") {
00947
00948 filename += ".ics";
00949 #if 0
00950 if (KOPrefs::instance()->mDefaultFormat == KOPrefs::FormatVCalendar) {
00951 filename += ".vcs";
00952 } else if (KOPrefs::instance()->mDefaultFormat == KOPrefs::FormatICalendar) {
00953 filename += ".ics";
00954 }
00955 #endif
00956 }
00957
00958 url.setFileName(filename);
00959
00960 kdDebug() << "KOrganizer::getSaveURL(): url: " << url.url() << endl;
00961
00962 return url;
00963 }
00964
00965
00966 bool KOrganizer::queryClose()
00967 {
00968 if (windowList->lastInstance() && !isActive() && !mURL.isEmpty()) {
00969 int result = KMessageBox::questionYesNo(this,i18n("Do you want to make this"
00970 " calendar active?\nThis means that it is monitored for alarms and loaded"
00971 " as default calendar."));
00972 if (result == KMessageBox::Yes) makeActive();
00973 }
00974
00975 bool success = saveModifiedURL();
00976
00977
00978
00979 writeSettings();
00980
00981 return success;
00982 }
00983
00984 bool KOrganizer::queryExit()
00985 {
00986
00987
00988
00989 return true;
00990 }
00991
00992
00993 void KOrganizer::saveProperties(KConfig *config)
00994 {
00995 config->writeEntry("Calendar",mURL.url());
00996 }
00997
00998 void KOrganizer::readProperties(KConfig *config)
00999 {
01000 QString calendarUrl = config->readEntry("Calendar");
01001 if (!calendarUrl.isEmpty()) {
01002 KURL u(calendarUrl);
01003 openURL(u);
01004
01005 KGlobal::config()->setGroup("General");
01006 QString active = KGlobal::config()->readEntry("Active Calendar");
01007 if (active == calendarUrl) setActive(true);
01008 }
01009 }
01010
01011
01012 void KOrganizer::setTitle()
01013 {
01014
01015
01016 QString tmpStr;
01017
01018 if (!mURL.isEmpty()) {
01019 if (mURL.isLocalFile()) tmpStr = mURL.fileName();
01020 else tmpStr = mURL.prettyURL();
01021 }
01022 else tmpStr = i18n("New Calendar");
01023
01024 if (mCalendarView->isReadOnly())
01025 tmpStr += " [" + i18n("read-only") + "]";
01026
01027 if (isActive()) tmpStr += " [" + i18n("active") + "]";
01028
01029 setCaption(tmpStr,!mCalendarView->isReadOnly()&&mCalendarView->isModified());
01030 }
01031
01032 void KOrganizer::checkAutoSave()
01033 {
01034 kdDebug() << "KOrganizer::checkAutoSave()" << endl;
01035
01036
01037 if (KOPrefs::instance()->mAutoSaveInterval == 0) return;
01038
01039
01040 if (KOPrefs::instance()->mAutoSave && !mURL.isEmpty()) {
01041 saveURL();
01042 }
01043 }
01044
01045
01046
01047 void KOrganizer::updateConfig()
01048 {
01049 kdDebug() << "KOrganizer::updateConfig()" << endl;
01050
01051 if (KOPrefs::instance()->mAutoSave && !mAutoSaveTimer->isActive()) {
01052 checkAutoSave();
01053 if (KOPrefs::instance()->mAutoSaveInterval > 0) {
01054 mAutoSaveTimer->start(1000*60*KOPrefs::instance()->mAutoSaveInterval);
01055 }
01056 }
01057 if (!KOPrefs::instance()->mAutoSave) mAutoSaveTimer->stop();
01058 mNextXDays->setText(i18n("&Next Day", "&Next %n Days", KOPrefs::instance()->mNextXDays));
01059
01060 KOCore::self()->reloadPlugins();
01061 mParts = KOCore::self()->reloadParts( this, mParts );
01062 }
01063
01064 void KOrganizer::configureDateTime()
01065 {
01066 KProcess *proc = new KProcess;
01067 *proc << "kcmshell" << "language";
01068
01069 connect(proc,SIGNAL(processExited(KProcess *)),
01070 SLOT(configureDateTimeFinished(KProcess *)));
01071
01072 if (!proc->start()) {
01073 KMessageBox::sorry(this,
01074 i18n("Couldn't start control module for date and time format."));
01075 }
01076 }
01077
01078 void KOrganizer::configureToolbars()
01079 {
01080 saveMainWindowSettings( KGlobal::config(), "MainWindow" );
01081
01082 KEditToolbar dlg(factory());
01083 connect(&dlg,SIGNAL(newToolbarConfig()),this,SLOT(slotNewToolbarConfig()));
01084
01085 dlg.exec();
01086 }
01087
01088 void KOrganizer::slotNewToolbarConfig()
01089 {
01090 plugActionList("toolbartoggles",mToolBarToggles);
01091
01092 applyMainWindowSettings( KGlobal::config(), "MainWindow" );
01093 }
01094
01095 void KOrganizer::editKeys()
01096 {
01097 KKeyDialog::configureKeys(actionCollection(),xmlFile(),true,this);
01098 }
01099
01100 void KOrganizer::showTip()
01101 {
01102 KTipDialog::showTip(this,QString::null,true);
01103 }
01104
01105 void KOrganizer::showTipOnStart()
01106 {
01107 KTipDialog::showTip(this);
01108 }
01109
01110 KOrganizer* KOrganizer::findInstance(const KURL &url)
01111 {
01112 if (windowList)
01113 return windowList->findInstance(url);
01114 else
01115 return 0;
01116 }
01117
01118 void KOrganizer::setActive(bool active)
01119 {
01120 if (active == mActive) return;
01121
01122 mActive = active;
01123 setTitle();
01124 }
01125
01126 void KOrganizer::makeActive()
01127 {
01128 if (mURL.isEmpty()) {
01129 KMessageBox::sorry(this,i18n("The calendar does not have a filename. "
01130 "Please save it before activating."));
01131 return;
01132 }
01133
01134 if (!mURL.isLocalFile()) {
01135 int result = KMessageBox::warningContinueCancel(this,
01136 i18n("Your calendar is a remote file. Activating it can cause "
01137 "synchronization problems leading to data loss.\n"
01138 "Make sure that it is accessed by no more than one single "
01139 "KOrganizer instance at the same time."),
01140 i18n("Activating Calendar."),i18n("Activate Calendar"),"dontaskActivate",
01141 true);
01142 if (result == KMessageBox::Cancel) return;
01143 }
01144
01145 writeActiveState();
01146
01147 mAlarmDaemonIface.reloadCal( "korgac", mURL.url() );
01148 if ( !mAlarmDaemonIface.ok() ) {
01149 kdDebug() << "KOrganizer::makeActive(): dcop send failed" << endl;
01150 }
01151 setActive();
01152 emit calendarActivated(this);
01153 }
01154
01155 void KOrganizer::writeActiveState()
01156 {
01157 KConfig *config(kapp->config());
01158 config->setGroup("General");
01159 config->writeEntry("Active Calendar",mURL.url());
01160 config->sync();
01161 }
01162
01163 void KOrganizer::dumpText(const QString &str)
01164 {
01165 kdDebug() << "KOrganizer::dumpText(): " << str << endl;
01166 }
01167
01168 void KOrganizer::toggleToolBars(bool toggle)
01169 {
01170 KToolBar *bar = toolBar(sender()->name());
01171 if (bar) {
01172 if (toggle) bar->show();
01173 else bar->hide();
01174 } else {
01175 kdDebug() << "KOrganizer::toggleToolBars(): Toolbar not found" << endl;
01176 }
01177 }
01178
01179 void KOrganizer::toggleToolBar()
01180 {
01181 QPtrListIterator<KToolBar> it = toolBarIterator();
01182 for ( ; it.current() ; ++it ) {
01183 if (mToolBarToggleAction->isChecked()) (*it)->show();
01184 else (*it)->hide();
01185 }
01186 }
01187
01188 void KOrganizer::toggleStatusBar()
01189 {
01190 bool show_statusbar = mStatusBarAction->isChecked();
01191 if (show_statusbar)
01192 statusBar()->show();
01193 else
01194 statusBar()->hide();
01195 }
01196
01197 void KOrganizer::toggleFilterView()
01198 {
01199 bool visible = mFilterViewAction->isChecked();
01200 mCalendarView->showFilter(visible);
01201 }
01202
01203 void KOrganizer::statusBarPressed(int id)
01204 {
01205 if (id == ID_MESSAGES_IN)
01206 mCalendarView->dialogManager()->showIncomingDialog();
01207 else if (id == ID_MESSAGES_OUT)
01208 mCalendarView->dialogManager()->showOutgoingDialog();
01209 }
01210
01211 void KOrganizer::setNumIncoming(int num)
01212 {
01213 statusBar()->changeItem(i18n(" Incoming messages: %1 ").arg(num),
01214 ID_MESSAGES_IN);
01215 }
01216
01217 void KOrganizer::setNumOutgoing(int num)
01218 {
01219 statusBar()->changeItem(i18n(" Outgoing messages: %1 ").arg(num),
01220 ID_MESSAGES_OUT);
01221 }
01222
01223 void KOrganizer::showStatusMessage(const QString &message)
01224 {
01225 statusBar()->message(message,2000);
01226 }
01227
01228 bool KOrganizer::openURL(QString url)
01229 {
01230 return openURL(KURL(url));
01231 }
01232
01233 bool KOrganizer::mergeURL(QString url)
01234 {
01235 return openURL(KURL(url),true);
01236 }
01237
01238 bool KOrganizer::saveAsURL(QString url)
01239 {
01240 return saveAsURL(KURL(url));
01241 }
01242
01243 QString KOrganizer::getCurrentURLasString() const
01244 {
01245 return mURL.url();
01246 }
01247
01248 bool KOrganizer::deleteEvent(QString uid)
01249 {
01250 return mCalendarView->deleteEvent(uid);
01251 }
01252
01253 void KOrganizer::configureDateTimeFinished(KProcess *proc)
01254 {
01255 delete proc;
01256 }
01257
01258 void KOrganizer::processIncidenceSelection( Incidence *incidence )
01259 {
01260
01261
01262 if ( !incidence ) {
01263 enableIncidenceActions( false );
01264 return;
01265 }
01266
01267 enableIncidenceActions( true );
01268
01269 if ( incidence->type() == "Event" ) {
01270 mShowIncidenceAction->setText( i18n("&Show Event") );
01271 mEditIncidenceAction->setText( i18n("&Edit Event...") );
01272 mDeleteIncidenceAction->setText( i18n("&Delete Event") );
01273 } else if ( incidence->type() == "Todo" ) {
01274 mShowIncidenceAction->setText( i18n("&Show To-Do") );
01275 mEditIncidenceAction->setText( i18n("&Edit To-Do...") );
01276 mDeleteIncidenceAction->setText( i18n("&Delete To-Do") );
01277 } else {
01278 mShowIncidenceAction->setText( i18n("&Show") );
01279 mShowIncidenceAction->setText( i18n("&Edit...") );
01280 mShowIncidenceAction->setText( i18n("&Delete") );
01281 }
01282 }
01283
01284 void KOrganizer::enableIncidenceActions( bool enabled )
01285 {
01286 mShowIncidenceAction->setEnabled( enabled );
01287 mEditIncidenceAction->setEnabled( enabled );
01288 mDeleteIncidenceAction->setEnabled( enabled );
01289
01290 mCutAction->setEnabled( enabled );
01291 mCopyAction->setEnabled( enabled );
01292 mDeleteAction->setEnabled( enabled );
01293 mPublishEvent->setEnabled( enabled );
01294 }
01295
01296 void KOrganizer::downloadNewStuff()
01297 {
01298 kdDebug() << "KOrganizer::downloadNewStuff()" << endl;
01299
01300 if ( !mNewStuff ) mNewStuff = new KONewStuff( mCalendarView );
01301 mNewStuff->download();
01302 }
01303
01304 void KOrganizer::uploadNewStuff()
01305 {
01306 if ( !mNewStuff ) mNewStuff = new KONewStuff( mCalendarView );
01307 mNewStuff->upload();
01308 }
01309
01310 QString KOrganizer::localFileName()
01311 {
01312 return mFile;
01313 }