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