kontact Library API Documentation

main.cpp

00001 /*
00002     This file is part of KDE Kontact.
00003 
00004     Copyright (c) 2001 Matthias Hoelzer-Kluepfel <mhk@kde.org>
00005     Copyright (c) 2002-2003 Daniel Molkentin <molkentin@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 
00022 #include <iostream>
00023 
00024 #include <dcopclient.h>
00025 #include <kaboutdata.h>
00026 #include <kcmdlineargs.h>
00027 #include <kdebug.h>
00028 #include <kiconloader.h>
00029 #include <klocale.h>
00030 #include <kstartupinfo.h>
00031 #include <kuniqueapplication.h>
00032 #include <kwin.h>
00033 #include <kstandarddirs.h>
00034 #include <ktrader.h>
00035 #include "plugin.h"
00036 
00037 #include <qlabel.h>
00038 #include "splash.h"
00039 
00040 #include "mainwindow.h"
00041 
00042 using namespace std;
00043 
00044 static const char description[] =
00045     I18N_NOOP( "KDE personal information manager" );
00046 
00047 static const char version[] = "1.0 (proko2 2.1.10)";
00048 
00049 class KontactApp : public KUniqueApplication {
00050   public:
00051     KontactApp() : mMainWindow( 0 ) {}
00052     ~KontactApp() {}
00053 
00054     int newInstance();
00055 
00056   private:
00057     void startKOrgac();
00058     Kontact::MainWindow *mMainWindow;
00059 };
00060 
00061 static void listPlugins()
00062 {
00063   KInstance instance( "kontact" ); // Can't use KontactApp since it's too late for adding cmdline options
00064   KTrader::OfferList offers = KTrader::self()->query(
00065     QString::fromLatin1( "Kontact/Plugin" ),
00066     QString( "[X-KDE-KontactPluginVersion] == %1" ).arg( KONTACT_PLUGIN_VERSION ) );
00067   for(KService::List::Iterator it = offers.begin(); it != offers.end(); ++it)
00068   {
00069     KService::Ptr service = (*it);
00070     cout << service->library().remove( "libkontact_" ).latin1() << endl;
00071   }
00072 }
00073 
00074 static KCmdLineOptions options[] =
00075 {
00076     { "module <module>",   I18N_NOOP("Start with a specific Kontact module"), 0 },
00077     { "nosplash",   I18N_NOOP("Disable the splash screen"), 0 },
00078     { "iconify",   I18N_NOOP("Start in iconified (minimized) mode"), 0 },
00079     { "list", I18N_NOOP("List all possible modules and exit"), 0 },
00080     KCmdLineLastOption
00081 };
00082 
00083 void KontactApp::startKOrgac()
00084 {
00085   if ( kapp->dcopClient()->isApplicationRegistered( "korgac" ) ) {
00086     // Alarm daemon already runs
00087     return;
00088   }
00089   KGlobal::dirs()->addResourceType("autostart", "share/autostart");
00090   QString desktopFile = locate( "autostart", "korgac.desktop" );
00091   if ( desktopFile.isEmpty() ) {
00092     kdWarning() << "Couldn't find autostart/korgac.desktop!" << endl;
00093   }
00094   else {
00095     QString error;
00096     if ( startServiceByDesktopPath( desktopFile, QStringList(), &error ) != 0 )
00097       kdWarning() << "Failure starting korgac:" << error << endl;
00098   }
00099 }
00100 
00101 int KontactApp::newInstance()
00102 {
00103   KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00104   QString moduleName;
00105   if ( args->isSet("module") )
00106   {
00107     moduleName = QString::fromLocal8Bit(args->getOption("module"));
00108   }
00109   Kontact::Splash* splash = new Kontact::Splash( 0, "splash" );
00110   if ( !mMainWindow && args->isSet("splash") ) // only the first time
00111     splash->show();
00112 
00113   if ( isRestored() ) {
00114     // There can only be one main window
00115     if ( KMainWindow::canBeRestored( 1 ) ) {
00116       mMainWindow = new Kontact::MainWindow(splash);
00117       setMainWidget( mMainWindow );
00118       mMainWindow->show();
00119       mMainWindow->restore( 1 );
00120     }
00121   } else {
00122     if ( !mMainWindow ) {
00123       mMainWindow = new Kontact::MainWindow(splash);
00124       if ( !moduleName.isEmpty() )
00125         mMainWindow->activePluginModule( moduleName );
00126       mMainWindow->show();
00127       setMainWidget( mMainWindow );
00128       // --iconify is needed in kontact, although kstart can do that too,
00129       // because kstart returns immediately so it's too early to talk DCOP to the app.
00130       if ( args->isSet( "iconify" ) )
00131         KWin::iconifyWindow( mMainWindow->winId(), false /*no animation*/ );
00132     }
00133     else
00134     {
00135       if ( !moduleName.isEmpty() )
00136         mMainWindow->activePluginModule( moduleName );
00137     }
00138   }
00139 
00140   startKOrgac();
00141 
00142   // Handle startup notification and window activation
00143   // (The first time it will do nothing except note that it was called)
00144   return KUniqueApplication::newInstance();
00145 }
00146 
00147 int main(int argc, char **argv)
00148 {
00149   KAboutData about( "kontact", I18N_NOOP( "Kontact" ), version, description,
00150                     KAboutData::License_GPL, I18N_NOOP("(C) 2001-2006 The Kontact developers"), 0, "http://kontact.org" );
00151   about.addAuthor( "Daniel Molkentin", 0, "molkentin@kde.org" );
00152   about.addAuthor( "Don Sanders", 0, "sanders@kde.org" );
00153   about.addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" );
00154   about.addAuthor( "Tobias K\303\266nig", 0, "tokoe@kde.org" );
00155   about.addAuthor( "David Faure", 0, "faure@kde.org" );
00156   about.addAuthor( "Ingo Kl\303\266cker", 0, "kloecker@kde.org" );
00157   about.addAuthor( "Sven L\303\274ppken", 0, "sven@kde.org" );
00158   about.addAuthor( "Zack Rusin", 0, "zack@kde.org" );
00159   about.addAuthor( "Matthias Hoelzer-Kluepfel", I18N_NOOP("Original Author"), "mhk@kde.org" );
00160 
00161   KCmdLineArgs::init( argc, argv, &about );
00162   KCmdLineArgs::addCmdLineOptions( options );
00163   KUniqueApplication::addCmdLineOptions();
00164   KApplication::addCmdLineOptions();
00165 
00166   KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00167   if ( args->isSet( "list" ) )
00168   {
00169     listPlugins();
00170     return 0;
00171   }
00172 
00173   if ( !KontactApp::start() ) {
00174     // Already running, brought to the foreground.
00175     return 0;
00176   }
00177 
00178   KontactApp app;
00179   bool ret = app.exec();
00180   while ( KMainWindow::memberList->first() )
00181     delete KMainWindow::memberList->first();
00182 
00183   return ret;
00184 }
KDE Logo
This file is part of the documentation for kontact Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Aug 23 18:22:46 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003