korganizer

koapp.cpp
1 /*
2  This file is part of KOrganizer.
3 
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>
7 
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.
12 
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.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 
22  As a special exception, permission is given to link this program
23  with any edition of TQt, and distribute the resulting executable,
24  without including the source code for TQt in the source distribution.
25 */
26 
27 #include <stdlib.h>
28 #include <iostream>
29 
30 #include <tdeglobal.h>
31 #include <tdecmdlineargs.h>
32 #include <tdeconfig.h>
33 #include <kdebug.h>
34 #include <tdelocale.h>
35 #include <twin.h>
36 #include <kurl.h>
37 
38 #include <libkcal/calformat.h>
40 
41 #include "korganizer.h"
42 #include "koprefs.h"
43 #include "version.h"
44 #include "alarmclient.h"
45 #include "koglobals.h"
46 #include "actionmanager.h"
47 #include "importdialog.h"
48 #include "kocore.h"
49 #include "calendarview.h"
50 #include "stdcalendar.h"
51 
52 #include "koapp.h"
53 #include <tdestartupinfo.h>
54 
55 using namespace std;
56 
57 KOrganizerApp::KOrganizerApp() : TDEUniqueApplication()
58 {
59  TQString prodId = "-//K Desktop Environment//NONSGML KOrganizer %1//EN";
60  CalFormat::setApplication( "KOrganizer", prodId.arg( korgVersion ) );
61 }
62 
63 KOrganizerApp::~KOrganizerApp()
64 {
65 }
66 
67 int KOrganizerApp::newInstance()
68 {
69  kdDebug(5850) << "KOApp::newInstance()" << endl;
70  static bool first = true;
71  if ( isRestored() && first ) {
73  if ( korg ) {
74  KOrg::StdCalendar::self()->load();
75  korg->view()->updateCategories();
76  korg->view()->updateView();
77  }
78  first = false;
79  return 0;
80  }
81  first = false;
82 
83  TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
84 
85  KOGlobals::self()->alarmClient()->startDaemon();
86 
87  // No filenames given => all other args are meaningless, show main Window
88  if ( args->count() <= 0 ) {
89  processCalendar( KURL() );
90  return 0;
91  }
92 
93  // If filenames wer given as arguments, load them as calendars, one per window.
94  if ( args->isSet( "open" ) ) {
95  for( int i = 0; i < args->count(); ++i ) {
96  processCalendar( args->url( i ) );
97  }
98  } else {
99  // Import, merge, or ask => we need the resource calendar window anyway.
100  processCalendar( KURL() );
102  if ( !korg ) {
103  kdError() << "Unable to find default calendar resources view." << endl;
104  return -1;
105  }
106  // Check for import, merge or ask
107  if ( args->isSet( "import" ) ) {
108  for( int i = 0; i < args->count(); ++i ) {
109  korg->actionManager()->addResource( args->url( i ) );
110  }
111  } else if ( args->isSet( "merge" ) ) {
112  for( int i = 0; i < args->count(); ++i ) {
113  korg->actionManager()->mergeURL( args->url( i ).url() );
114  }
115  } else {
116  for( int i = 0; i < args->count(); ++i ) {
117  korg->actionManager()->importCalendar( args->url( i ) );
118  }
119  }
120  }
121 
122  kdDebug(5850) << "KOApp::newInstance() done" << endl;
123 
124  return 0;
125 }
126 
127 
128 void KOrganizerApp::processCalendar( const KURL &url )
129 {
131  if ( !korg ) {
132  bool hasDocument = !url.isEmpty();
133  korg = new KOrganizer( "KOrganizer MainWindow" );
134  korg->init( hasDocument );
135  korg->topLevelWidget()->show();
136 
137  kdDebug(5850) << "KOrganizerApp::processCalendar(): '" << url.url()
138  << "'" << endl;
139 
140  if ( hasDocument )
141  korg->openURL( url );
142  else {
143  KOrg::StdCalendar::self()->load();
144  korg->view()->updateCategories();
145  korg->view()->updateView();
146  }
147  } else {
148  korg->topLevelWidget()->show();
149  }
150 
151  // Handle window activation
152 #if defined TQ_WS_X11 && ! defined K_WS_TQTONLY
153  TDEStartupInfo::setNewStartupId( korg->topLevelWidget(), startupId() );
154 #endif
155 }
156 
157 #include "koapp.moc"
bool mergeURL(const TQString &url)
Open calendar file from URL.
static KOrg::MainWindow * findInstance(const KURL &url)
Is there a instance with this URL?
bool addResource(const KURL &mUrl)
Add a new resource.
interface for korganizer main window
Definition: mainwindow.h:41
virtual bool openURL(const KURL &url, bool merge=false)=0
Load calendar file from URL.
virtual ActionManager * actionManager()=0
Return ActionManager of this main window.
virtual TQWidget * topLevelWidget()=0
Return widget whcih represents this main window.
This is the main class for KOrganizer.
Definition: korganizer.h:66