doc update
[kdepim.git] / korganizer / koapp.cpp
blob5bded76738655ac6a1815534a47fadf424d03b98
1 /*
2 This file is part of KOrganizer.
4 Copyright (c) 1999 Preston Brown <pbrown@kde.org>
5 Copyright (c) 2000,2001,2003 Cornelius Schumacher <schumacher@kde.org>
6 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 As a special exception, permission is given to link this program
23 with any edition of Qt, and distribute the resulting executable,
24 without including the source code for Qt in the source distribution.
27 #include "koapp.h"
28 #include "korganizer.h"
29 #include "koprefs.h"
30 #include "version.h"
31 #include "koglobals.h"
32 #include "actionmanager.h"
33 #include "importdialog.h"
34 #include "kocore.h"
35 #include "calendarview.h"
37 #include "reminderclient.h"
39 #include <kcal/calformat.h>
40 #include <kcal/calendarresources.h>
42 #include <kstartupinfo.h>
43 #include <kglobal.h>
44 #include <kcmdlineargs.h>
45 #include <kconfig.h>
46 #include <kdebug.h>
47 #include <klocale.h>
48 #include <kwindowsystem.h>
49 #include <kurl.h>
50 #include <kstandarddirs.h>
52 #include <stdlib.h>
53 #include <iostream>
55 using namespace std;
57 KOrganizerApp::KOrganizerApp() : KontactInterface::PimUniqueApplication()
59 QString prodId = "-//K Desktop Environment//NONSGML KOrganizer %1//EN";
60 CalFormat::setApplication( "KOrganizer", prodId.arg( korgVersion ) );
62 // icons shared by the KDE PIM applications
63 KGlobal::dirs()->addResourceType( "appicon", "data", "/kdepim/icons/" );
66 KOrganizerApp::~KOrganizerApp()
70 int KOrganizerApp::newInstance()
72 kDebug();
73 static bool first = true;
74 if ( isSessionRestored() && first ) {
75 KOrg::MainWindow *korg = ActionManager::findInstance( KUrl() );
76 if ( korg ) {
77 korg->view()->updateCategories();
78 korg->view()->updateView();
80 first = false;
81 return 0;
83 first = false;
85 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
87 KOGlobals::self()->reminderClient()->startDaemon();
89 // No filenames given => all other args are meaningless, show main Window
90 if ( args->count() <= 0 ) {
91 processCalendar( KUrl() );
92 return 0;
95 // If filenames were given as arguments, load them as calendars, one per window.
96 if ( args->isSet( "open" ) ) {
97 for ( int i = 0; i < args->count(); ++i ) {
98 processCalendar( args->url( i ) );
100 } else {
101 // Import, merge, or ask => we need the resource calendar window anyway.
102 processCalendar( KUrl() );
103 KOrg::MainWindow *korg = ActionManager::findInstance( KUrl() );
104 if ( !korg ) {
105 kError() << "Unable to find default calendar resources view.";
106 return -1;
108 // Check for import, merge or ask
109 if ( args->isSet( "import" ) ) {
110 for ( int i = 0; i < args->count(); ++i ) {
111 korg->actionManager()->addResource( args->url( i ) );
113 } else if ( args->isSet( "merge" ) ) {
114 for ( int i = 0; i < args->count(); ++i ) {
115 korg->actionManager()->mergeURL( args->url( i ).url() );
117 } else {
118 for ( int i = 0; i < args->count(); ++i ) {
119 korg->actionManager()->importCalendar( args->url( i ) );
124 kDebug() << "done";
126 return 0;
129 void KOrganizerApp::processCalendar( const KUrl &url )
131 KOrg::MainWindow *korg = ActionManager::findInstance( url );
132 if ( !korg ) {
133 bool hasDocument = !url.isEmpty();
134 korg = new KOrganizer();
135 korg->init( hasDocument );
136 korg->topLevelWidget()->show();
138 kDebug() << url.url();
140 if ( hasDocument ) {
141 korg->openURL( url );
142 } else {
143 korg->view()->updateCategories();
144 korg->view()->updateView();
146 } else {
147 korg->topLevelWidget()->show();
150 // Handle window activation
151 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
152 KStartupInfo::setNewStartupId( korg->topLevelWidget(), startupId() );
153 #endif
156 #include "koapp.moc"