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