korganizer

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 Qt, and distribute the resulting executable,
00024     without including the source code for Qt 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   QString 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   // If filenames was given as argument load this as calendars, one per window.
00088   if ( args->count() > 0 ) {
00089     int i;
00090     for( i = 0; i < args->count(); ++i ) {
00091       processCalendar( args->url( i ) );
00092     }
00093     if ( args->isSet( "import" ) ) {
00094       processCalendar( KURL() );
00095     }
00096   } else {
00097     processCalendar( KURL() );
00098   }
00099 
00100   if ( args->isSet( "import" ) ) {
00101     KOrg::MainWindow *korg = ActionManager::findInstance( KURL() );
00102     if ( !korg ) {
00103       kdError() << "Unable to find default calendar resources view." << endl;
00104     } else {
00105       KURL url = KCmdLineArgs::makeURL( args->getOption( "import" ) );
00106       korg->actionManager()->importCalendar( url );
00107     }
00108   }
00109 
00110   kdDebug(5850) << "KOApp::newInstance() done" << endl;
00111 
00112   return 0;
00113 }
00114 
00115 
00116 void KOrganizerApp::processCalendar( const KURL &url )
00117 {
00118   KOrg::MainWindow *korg = ActionManager::findInstance( url );
00119   if ( !korg ) {
00120     bool hasDocument = !url.isEmpty();
00121     korg = new KOrganizer( "KOrganizer MainWindow" );
00122     korg->init( hasDocument );
00123     korg->topLevelWidget()->show();
00124 
00125     kdDebug(5850) << "KOrganizerApp::processCalendar(): '" << url.url()
00126                   << "'" << endl;
00127 
00128     if ( hasDocument )
00129       korg->openURL( url );
00130     else {
00131       KOrg::StdCalendar::self()->load();
00132       korg->view()->updateCategories();
00133       korg->view()->updateView();
00134     }
00135   } else {
00136     korg->topLevelWidget()->show();
00137   }
00138 
00139   // Handle window activation
00140 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
00141   KStartupInfo::setNewStartupId( korg->topLevelWidget(), startupId() );
00142 #endif
00143 }
00144 
00145 #include "koapp.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys