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 <ktrader.h>
00034 #include "plugin.h"
00035 
00036 #include <qlabel.h>
00037 #include "splash.h"
00038 
00039 #include "mainwindow.h"
00040 
00041 using namespace std;
00042 
00043 static const char description[] =
00044     I18N_NOOP( "KDE personal information manager" );
00045 
00046 static const char version[] = "1.0.2";
00047 
00048 class KontactApp : public KUniqueApplication {
00049   public:
00050     KontactApp() : mMainWindow( 0 ) {}
00051     ~KontactApp() {}
00052 
00053     int newInstance();
00054 
00055   private:
00056     Kontact::MainWindow *mMainWindow;
00057 };
00058 
00059 static void listPlugins()
00060 {
00061   KInstance instance( "kontact" ); // Can't use KontactApp since it's too late for adding cmdline options
00062   KTrader::OfferList offers = KTrader::self()->query(
00063     QString::fromLatin1( "Kontact/Plugin" ),
00064     QString( "[X-KDE-KontactPluginVersion] == %1" ).arg( KONTACT_PLUGIN_VERSION ) );
00065   for(KService::List::Iterator it = offers.begin(); it != offers.end(); ++it)
00066   {
00067     KService::Ptr service = (*it);
00068     cout << service->library().remove( "libkontact_" ).latin1() << endl;
00069   }
00070 }
00071 
00072 static KCmdLineOptions options[] =
00073 {
00074     { "module <module>",   I18N_NOOP("Start with a specific Kontact module"), 0 },
00075     { "nosplash",   I18N_NOOP("Disable the splash screen"), 0 },
00076     { "list", I18N_NOOP("List all possible modules and exit"), 0 },
00077     KCmdLineLastOption
00078 };
00079 
00080 
00081 int KontactApp::newInstance()
00082 {
00083   KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00084   QString moduleName;
00085   if ( args->isSet("module") )
00086   {
00087     moduleName = QString::fromLocal8Bit(args->getOption("module"));
00088   }
00089   Kontact::Splash* splash = new Kontact::Splash( 0, "splash" );
00090   if ( !mMainWindow && args->isSet("splash") ) // only the first time
00091     splash->show();
00092 
00093   if ( isRestored() ) {
00094     // There can only be one main window
00095     if ( KMainWindow::canBeRestored( 1 ) ) {
00096       mMainWindow = new Kontact::MainWindow(splash);
00097       setMainWidget( mMainWindow );
00098       mMainWindow->show();
00099       mMainWindow->restore( 1 );
00100     }
00101   } else {
00102     if ( !mMainWindow ) {
00103       mMainWindow = new Kontact::MainWindow(splash);
00104       if ( !moduleName.isEmpty() )
00105         mMainWindow->activePluginModule( moduleName );
00106       mMainWindow->show();
00107       setMainWidget( mMainWindow );
00108     }
00109     else
00110     {
00111       if ( !moduleName.isEmpty() )
00112         mMainWindow->activePluginModule( moduleName );
00113     }
00114   }
00115 
00116   // Handle startup notification and window activation
00117   // (The first time it will do nothing except note that it was called)
00118   return KUniqueApplication::newInstance();
00119 }
00120 
00121 int main(int argc, char **argv)
00122 {
00123   KAboutData about( "kontact", I18N_NOOP( "Kontact" ), version, description,
00124                     KAboutData::License_GPL, I18N_NOOP("(C) 2001-2004 The Kontact developers"), 0, "http://kontact.org" );
00125   about.addAuthor( "Daniel Molkentin", 0, "molkentin@kde.org" );
00126   about.addAuthor( "Don Sanders", 0, "sanders@kde.org" );
00127   about.addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" );
00128   about.addAuthor( "Tobias K\303\266nig", 0, "tokoe@kde.org" );
00129   about.addAuthor( "David Faure", 0, "faure@kde.org" );
00130   about.addAuthor( "Ingo Kl\303\266cker", 0, "kloecker@kde.org" );
00131   about.addAuthor( "Sven L\303\274ppken", 0, "sven@kde.org" );
00132   about.addAuthor( "Zack Rusin", 0, "zack@kde.org" );
00133   about.addAuthor( "Matthias Hoelzer-Kluepfel", I18N_NOOP("Original Author"), "mhk@kde.org" );
00134 
00135   KCmdLineArgs::init( argc, argv, &about );
00136   KCmdLineArgs::addCmdLineOptions( options );
00137   KUniqueApplication::addCmdLineOptions();
00138   KApplication::addCmdLineOptions();
00139 
00140   KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00141   if ( args->isSet( "list" ) )
00142   {
00143     listPlugins();
00144     return 0;
00145   }
00146 
00147   if ( !KontactApp::start() ) {
00148     // Already running, brought to the foreground.
00149     return 0;
00150   }
00151 
00152   KontactApp app;
00153   bool ret = app.exec();
00154   while ( KMainWindow::memberList->first() )
00155     delete KMainWindow::memberList->first();
00156 
00157   return ret;
00158 }
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 Mon Apr 4 04:50:12 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003