koapp.cpp
00001 /* 00002 This file is part of KOrganizer. 00003 00004 Copyright (c) 1999 Preston Brown <pbrown@kde.org> 00005 Copyright (c) 2000,2001,2003 Cornelius Schumacher <schumacher@kde.org> 00006 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 2 of the License, or 00011 (at your option) any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program; if not, write to the Free Software 00020 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00021 00022 As a special exception, permission is given to link this program 00023 with any edition of TQt, and distribute the resulting executable, 00024 without including the source code for TQt in the source distribution. 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 TQString 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 // No filenames given => all other args are meaningless, show main Window 00088 if ( args->count() <= 0 ) { 00089 processCalendar( KURL() ); 00090 return 0; 00091 } 00092 00093 // If filenames wer given as arguments, load them as calendars, one per window. 00094 if ( args->isSet( "open" ) ) { 00095 for( int i = 0; i < args->count(); ++i ) { 00096 processCalendar( args->url( i ) ); 00097 } 00098 } else { 00099 // Import, merge, or ask => we need the resource calendar window anyway. 00100 processCalendar( KURL() ); 00101 KOrg::MainWindow *korg = ActionManager::findInstance( KURL() ); 00102 if ( !korg ) { 00103 kdError() << "Unable to find default calendar resources view." << endl; 00104 return -1; 00105 } 00106 // Check for import, merge or ask 00107 if ( args->isSet( "import" ) ) { 00108 for( int i = 0; i < args->count(); ++i ) { 00109 korg->actionManager()->addResource( args->url( i ) ); 00110 } 00111 } else if ( args->isSet( "merge" ) ) { 00112 for( int i = 0; i < args->count(); ++i ) { 00113 korg->actionManager()->mergeURL( args->url( i ).url() ); 00114 } 00115 } else { 00116 for( int i = 0; i < args->count(); ++i ) { 00117 korg->actionManager()->importCalendar( args->url( i ) ); 00118 } 00119 } 00120 } 00121 00122 kdDebug(5850) << "KOApp::newInstance() done" << endl; 00123 00124 return 0; 00125 } 00126 00127 00128 void KOrganizerApp::processCalendar( const KURL &url ) 00129 { 00130 KOrg::MainWindow *korg = ActionManager::findInstance( url ); 00131 if ( !korg ) { 00132 bool hasDocument = !url.isEmpty(); 00133 korg = new KOrganizer( "KOrganizer MainWindow" ); 00134 korg->init( hasDocument ); 00135 korg->topLevelWidget()->show(); 00136 00137 kdDebug(5850) << "KOrganizerApp::processCalendar(): '" << url.url() 00138 << "'" << endl; 00139 00140 if ( hasDocument ) 00141 korg->openURL( url ); 00142 else { 00143 KOrg::StdCalendar::self()->load(); 00144 korg->view()->updateCategories(); 00145 korg->view()->updateView(); 00146 } 00147 } else { 00148 korg->topLevelWidget()->show(); 00149 } 00150 00151 // Handle window activation 00152 #if defined TQ_WS_X11 && ! defined K_WS_TQTONLY 00153 KStartupInfo::setNewStartupId( korg->topLevelWidget(), startupId() ); 00154 #endif 00155 } 00156 00157 #include "koapp.moc"