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.
28 #include "korganizer.h"
31 #include "koglobals.h"
32 #include "actionmanager.h"
33 #include "importdialog.h"
35 #include "calendarview.h"
37 #include "reminderclient.h"
39 #include <kcalcore/calformat.h>
40 #include <kcalcore/calendar.h>
42 #include <kstartupinfo.h>
44 #include <kcmdlineargs.h>
48 #include <kwindowsystem.h>
50 #include <kstandarddirs.h>
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()
73 static bool first
= true;
74 if ( isSessionRestored() && first
) {
75 KOrg::MainWindow
*korg
= ActionManager::findInstance( KUrl() );
77 korg
->view()->updateCategories();
78 korg
->view()->updateView();
85 KCmdLineArgs
*args
= KCmdLineArgs::parsedArgs();
87 KPIM::ReminderClient::startDaemon();
89 // No filenames given => all other args are meaningless, show main Window
90 if ( args
->count() <= 0 ) {
91 processCalendar( KUrl() );
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
) );
101 // Import, merge, or ask => we need the resource calendar window anyway.
102 processCalendar( KUrl() );
103 KOrg::MainWindow
*korg
= ActionManager::findInstance( KUrl() );
105 kError() << "Unable to find default calendar resources view.";
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() );
118 for ( int i
= 0; i
< args
->count(); ++i
) {
119 korg
->actionManager()->importCalendar( args
->url( i
) );
129 void KOrganizerApp::processCalendar( const KUrl
&url
)
131 KOrg::MainWindow
*korg
= ActionManager::findInstance( url
);
133 bool hasDocument
= !url
.isEmpty();
134 korg
= new KOrganizer();
135 korg
->init( hasDocument
);
136 korg
->topLevelWidget()->show();
138 kDebug() << url
.url();
141 korg
->openURL( url
);
143 korg
->view()->updateCategories();
144 korg
->view()->updateView();
147 korg
->topLevelWidget()->show();
150 // Handle window activation
151 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
152 KStartupInfo::setNewStartupId( korg
->topLevelWidget(), startupId() );