korganizer
koapp.cpp00001
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 <stdlib.h>
00028 #include <iostream>
00029
00030 #include <kglobal.h>
00031 #include <kcmdlineargs.h>
00032 #include <kconfig.h>
00033 #include <kdebug.h>
00034 #include <klocale.h>
00035 #include <kwin.h>
00036 #include <kurl.h>
00037
00038 #include <libkcal/calformat.h>
00039 #include <libkcal/calendarresources.h>
00040
00041 #include "korganizer.h"
00042 #include "koprefs.h"
00043 #include "version.h"
00044 #include "alarmclient.h"
00045 #include "koglobals.h"
00046 #include "actionmanager.h"
00047 #include "importdialog.h"
00048 #include "kocore.h"
00049 #include "calendarview.h"
00050 #include "stdcalendar.h"
00051
00052 #include "koapp.h"
00053 #include <kstartupinfo.h>
00054
00055 using namespace std;
00056
00057 KOrganizerApp::KOrganizerApp() : KUniqueApplication()
00058 {
00059 QString prodId = "-//K Desktop Environment//NONSGML KOrganizer %1//EN";
00060 CalFormat::setApplication( "KOrganizer", prodId.arg( korgVersion ) );
00061 }
00062
00063 KOrganizerApp::~KOrganizerApp()
00064 {
00065 }
00066
00067 int KOrganizerApp::newInstance()
00068 {
00069 kdDebug(5850) << "KOApp::newInstance()" << endl;
00070 static bool first = true;
00071 if ( isRestored() && first ) {
00072 KOrg::MainWindow *korg = ActionManager::findInstance( KURL() );
00073 if ( korg ) {
00074 KOrg::StdCalendar::self()->load();
00075 korg->view()->updateCategories();
00076 korg->view()->updateView();
00077 }
00078 first = false;
00079 return 0;
00080 }
00081 first = false;
00082
00083 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00084
00085 KOGlobals::self()->alarmClient()->startDaemon();
00086
00087
00088 if ( args->count() > 0 ) {
00089 int i;
00090 for( i = 0; i < args->count(); ++i ) {
00091 processCalendar( args->url( i ) );
00092 }
00093 if ( args->isSet( "import" ) ) {
00094 processCalendar( KURL() );
00095 }
00096 } else {
00097 processCalendar( KURL() );
00098 }
00099
00100 if ( args->isSet( "import" ) ) {
00101 KOrg::MainWindow *korg = ActionManager::findInstance( KURL() );
00102 if ( !korg ) {
00103 kdError() << "Unable to find default calendar resources view." << endl;
00104 } else {
00105 KURL url = KCmdLineArgs::makeURL( args->getOption( "import" ) );
00106 korg->actionManager()->importCalendar( url );
00107 }
00108 }
00109
00110 kdDebug(5850) << "KOApp::newInstance() done" << endl;
00111
00112 return 0;
00113 }
00114
00115
00116 void KOrganizerApp::processCalendar( const KURL &url )
00117 {
00118 KOrg::MainWindow *korg = ActionManager::findInstance( url );
00119 if ( !korg ) {
00120 bool hasDocument = !url.isEmpty();
00121 korg = new KOrganizer( "KOrganizer MainWindow" );
00122 korg->init( hasDocument );
00123 korg->topLevelWidget()->show();
00124
00125 kdDebug(5850) << "KOrganizerApp::processCalendar(): '" << url.url()
00126 << "'" << endl;
00127
00128 if ( hasDocument )
00129 korg->openURL( url );
00130 else {
00131 KOrg::StdCalendar::self()->load();
00132 korg->view()->updateCategories();
00133 korg->view()->updateView();
00134 }
00135 } else {
00136 korg->topLevelWidget()->show();
00137 }
00138
00139
00140 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
00141 KStartupInfo::setNewStartupId( korg->topLevelWidget(), startupId() );
00142 #endif
00143 }
00144
00145 #include "koapp.moc"
|