korganizer Library API Documentation

koapp.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 1999 Preston Brown
00005     Copyright (c) 2000,2001,2003 Cornelius Schumacher <schumacher@kde.org>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 
00021     As a special exception, permission is given to link this program
00022     with any edition of Qt, and distribute the resulting executable,
00023     without including the source code for Qt in the source distribution.
00024 */
00025 
00026 #include <stdlib.h>
00027 #include <iostream>
00028 
00029 #include <kglobal.h>
00030 #include <kcmdlineargs.h>
00031 #include <kconfig.h>
00032 #include <kdebug.h>
00033 #include <klocale.h>
00034 #include <kwin.h>
00035 #include <kurl.h>
00036 
00037 #include <libkcal/calformat.h>
00038 #include <libkcal/calendarresources.h>
00039 
00040 #include "korganizer.h"
00041 #include "koprefs.h"
00042 #include "version.h"
00043 #include "alarmclient.h"
00044 #include "koglobals.h"
00045 #include "actionmanager.h"
00046 #include "importdialog.h"
00047 #include "kocore.h"
00048 #include "calendarview.h"
00049 #include "stdcalendar.h"
00050 
00051 #include "koapp.h"
00052 #include <kstartupinfo.h>
00053 
00054 using namespace std;
00055 
00056 KOrganizerApp::KOrganizerApp() : KUniqueApplication()
00057 {
00058   QString prodId = "-//K Desktop Environment//NONSGML KOrganizer %1//EN";
00059   CalFormat::setApplication( "KOrganizer", prodId.arg( korgVersion ) );
00060 }
00061 
00062 KOrganizerApp::~KOrganizerApp()
00063 {
00064 }
00065 
00066 int KOrganizerApp::newInstance()
00067 {
00068   kdDebug(5850) << "KOApp::newInstance()" << endl;
00069   static bool first = true;
00070   if ( isRestored() && first ) {
00071      first = false;
00072      return 0;
00073   }
00074   first = false;
00075 
00076   KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00077 
00078   KOGlobals::self()->alarmClient()->startDaemon();
00079 
00080   // If filenames was given as argument load this as calendars, one per window.
00081   if ( args->count() > 0 ) {
00082     int i;
00083     for( i = 0; i < args->count(); ++i ) {
00084       processCalendar( args->url( i ) );
00085     }
00086     if ( args->isSet( "import" ) ) {
00087       processCalendar( KURL() );
00088     }
00089   } else {
00090     processCalendar( KURL() );
00091   }
00092 
00093   if ( args->isSet( "import" ) ) {
00094     KOrg::MainWindow *korg = ActionManager::findInstance( KURL() );
00095     if ( !korg ) {
00096       kdError() << "Unable to find default calendar resources view." << endl;
00097     } else {
00098       KURL url = KCmdLineArgs::makeURL( args->getOption( "import" ) );
00099       korg->actionManager()->importCalendar( url );
00100     }
00101   }
00102 
00103   kdDebug(5850) << "KOApp::newInstance() done" << endl;
00104 
00105   return 0;
00106 }
00107 
00108 
00109 void KOrganizerApp::processCalendar( const KURL &url )
00110 {
00111   KOrg::MainWindow *korg = ActionManager::findInstance( url );
00112   if ( !korg ) {
00113     bool hasDocument = !url.isEmpty();
00114     korg = new KOrganizer( "KOrganizer MainWindow" );
00115     korg->init( hasDocument );
00116     korg->topLevelWidget()->show();
00117 
00118     kdDebug(5850) << "KOrganizerApp::processCalendar(): '" << url.url()
00119                   << "'" << endl;
00120 
00121     if ( hasDocument )
00122       korg->openURL( url );
00123     else {
00124       KOrg::StdCalendar::self()->load();
00125       korg->view()->updateCategories();
00126       korg->view()->updateView();
00127     }
00128   } else {
00129     korg->topLevelWidget()->show();
00130   }
00131 
00132   // Handle window activation
00133 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
00134   KStartupInfo::setNewStartupId( korg->topLevelWidget(), startupId() );
00135 #endif
00136 }
00137 
00138 #include "koapp.moc"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 22:45:24 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003