kontact

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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 "prefs.h"
00039 
00040 #include "alarmclient.h"
00041 #include "mainwindow.h"
00042 #include <uniqueapphandler.h> // in ../interfaces
00043 #include "profilemanager.h"
00044 
00045 using namespace std;
00046 
00047 static const char description[] =
00048     I18N_NOOP( "KDE personal information manager" );
00049 
00050 static const char version[] = "1.2.9 (enterprise35 20090313.938853)";
00051 
00052 class KontactApp : public KUniqueApplication {
00053   public:
00054     KontactApp() : mMainWindow( 0 ), mSessionRestored( false ) {}
00055     ~KontactApp() {}
00056 
00057     int newInstance();
00058     void setMainWindow( Kontact::MainWindow *window ) {
00059         mMainWindow = window;
00060         setMainWidget( window );
00061     }
00062     void setSessionRestored( bool restored ) {
00063         mSessionRestored = restored;
00064     }
00065 
00066   private:
00067     void startKOrgac();
00068     Kontact::MainWindow *mMainWindow;
00069     bool mSessionRestored;
00070 };
00071 
00072 static void listPlugins()
00073 {
00074   KInstance instance( "kontact" ); // Can't use KontactApp since it's too late for adding cmdline options
00075   KTrader::OfferList offers = KTrader::self()->query(
00076     QString::fromLatin1( "Kontact/Plugin" ),
00077     QString( "[X-KDE-KontactPluginVersion] == %1" ).arg( KONTACT_PLUGIN_VERSION ) );
00078   for ( KService::List::Iterator it = offers.begin(); it != offers.end(); ++it ) {
00079     KService::Ptr service = (*it);
00080     // skip summary only plugins
00081     QVariant var = service->property( "X-KDE-KontactPluginHasPart" );
00082     if ( var.isValid() && var.toBool() == false )
00083       continue;
00084     cout << service->library().remove( "libkontact_" ).latin1() << endl;
00085   }
00086 }
00087 
00088 static void listProfiles()
00089 {
00090     KInstance *instance = new KInstance( "kontact" ); // Can't use KontactApp since it's too late for adding cmdline options
00091     QValueList<Kontact::Profile> profiles = Kontact::ProfileManager::self()->profiles();
00092     for( QValueListIterator<Kontact::Profile> it = profiles.begin() ; it != profiles.end(); ++it ) {
00093         cout << (*it).name().latin1() << endl;
00094     }
00095 }
00096 
00097 int KontactApp::newInstance()
00098 {
00099   KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00100   QString moduleName;
00101   if ( Kontact::Prefs::self()->forceStartupPlugin() ) {
00102     moduleName = Kontact::Prefs::self()->forcedStartupPlugin();
00103   }
00104   if ( args->isSet( "module" ) ) {
00105     moduleName = QString::fromLocal8Bit( args->getOption( "module" ) );
00106   }
00107 
00108   if ( !mSessionRestored ) {
00109     if ( !mMainWindow ) {
00110       mMainWindow = new Kontact::MainWindow();
00111       if ( !moduleName.isEmpty() )
00112         mMainWindow->setActivePluginModule( moduleName );
00113       mMainWindow->show();
00114       setMainWidget( mMainWindow );
00115       // --iconify is needed in kontact, although kstart can do that too,
00116       // because kstart returns immediately so it's too early to talk DCOP to the app.
00117       if ( args->isSet( "iconify" ) )
00118         KWin::iconifyWindow( mMainWindow->winId(), false /*no animation*/ );
00119     } else {
00120       if ( !moduleName.isEmpty() )
00121         mMainWindow->setActivePluginModule( moduleName );
00122     }
00123   }
00124 
00125     if ( args->isSet( "profile" ) ) {
00126         QValueList<Kontact::Profile>  profiles = Kontact::ProfileManager::self()->profiles();
00127         for( QValueListIterator<Kontact::Profile> it = profiles.begin(); it != profiles.end(); ++it ){
00128            if( args->getOption("profile") == (*it).name().latin1() ) {
00129              Kontact::ProfileManager::self()->loadProfile( (*it).id() );
00130              break;
00131            }
00132         }
00133     }
00134 
00135   AlarmClient alarmclient;
00136   alarmclient.startDaemon();
00137 
00138   // Handle startup notification and window activation
00139   // (The first time it will do nothing except note that it was called)
00140   return KUniqueApplication::newInstance();
00141 }
00142 
00143 int main( int argc, char **argv )
00144 {
00145   KAboutData about( "kontact", I18N_NOOP( "Kontact" ), version, description,
00146                     KAboutData::License_GPL, I18N_NOOP("(C) 2001-2008 The Kontact developers"), 0, "http://kontact.org" );
00147   about.addAuthor( "Daniel Molkentin", 0, "molkentin@kde.org" );
00148   about.addAuthor( "Don Sanders", 0, "sanders@kde.org" );
00149   about.addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" );
00150   about.addAuthor( "Tobias K\303\266nig", 0, "tokoe@kde.org" );
00151   about.addAuthor( "David Faure", 0, "faure@kde.org" );
00152   about.addAuthor( "Ingo Kl\303\266cker", 0, "kloecker@kde.org" );
00153   about.addAuthor( "Sven L\303\274ppken", 0, "sven@kde.org" );
00154   about.addAuthor( "Zack Rusin", 0, "zack@kde.org" );
00155   about.addAuthor( "Matthias Hoelzer-Kluepfel", I18N_NOOP("Original Author"), "mhk@kde.org" );
00156 
00157   KCmdLineArgs::init( argc, argv, &about );
00158   Kontact::UniqueAppHandler::loadKontactCommandLineOptions();
00159 
00160   KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00161   if ( args->isSet( "list" ) ) {
00162     listPlugins();
00163     return 0;
00164   }
00165 
00166   if ( args->isSet( "listprofiles" ) ) {
00167     listProfiles();
00168     return 0;
00169   }
00170  
00171   if ( !KontactApp::start() ) {
00172     // Already running, brought to the foreground.
00173     return 0;
00174   }
00175 
00176   KontactApp app;
00177   if ( app.restoringSession() ) {
00178      // There can only be one main window
00179     if ( KMainWindow::canBeRestored( 1 ) ) {
00180       Kontact::MainWindow *mainWindow = new Kontact::MainWindow();
00181       app.setMainWindow( mainWindow );
00182       app.setSessionRestored( true );
00183       mainWindow->show();
00184       mainWindow->restore( 1 );
00185     }
00186   }
00187 
00188   bool ret = app.exec();
00189   while ( KMainWindow::memberList->first() )
00190     delete KMainWindow::memberList->first();
00191 
00192   return ret;
00193 }
KDE Home | KDE Accessibility Home | Description of Access Keys