kontact
main.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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>
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 20100521.1129112)";
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" );
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
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 KInstance *instance = new KInstance( "kontact" );
00094 QValueList<Kontact::Profile> profiles = Kontact::ProfileManager::self()->profiles();
00095 for( QValueListIterator<Kontact::Profile> it = profiles.begin() ; it != profiles.end(); ++it ) {
00096 cout << (*it).name().latin1() << endl;
00097 }
00098 }
00099
00100 int KontactApp::newInstance()
00101 {
00102 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00103 QString moduleName;
00104 if ( Kontact::Prefs::self()->forceStartupPlugin() ) {
00105 moduleName = Kontact::Prefs::self()->forcedStartupPlugin();
00106 }
00107 if ( args->isSet( "module" ) ) {
00108 moduleName = QString::fromLocal8Bit( args->getOption( "module" ) );
00109 }
00110
00111 if ( !mSessionRestored ) {
00112 if ( !mMainWindow ) {
00113 mMainWindow = new Kontact::MainWindow();
00114 if ( !moduleName.isEmpty() )
00115 mMainWindow->setActivePluginModule( moduleName );
00116 mMainWindow->show();
00117 setMainWidget( mMainWindow );
00118
00119
00120 if ( args->isSet( "iconify" ) )
00121 KWin::iconifyWindow( mMainWindow->winId(), false );
00122 } else {
00123 if ( !moduleName.isEmpty() )
00124 mMainWindow->setActivePluginModule( moduleName );
00125 }
00126 }
00127
00128 if ( args->isSet( "profile" ) ) {
00129 QValueList<Kontact::Profile> profiles = Kontact::ProfileManager::self()->profiles();
00130 for( QValueListIterator<Kontact::Profile> it = profiles.begin(); it != profiles.end(); ++it ){
00131 if( args->getOption("profile") == (*it).name().latin1() ) {
00132 Kontact::ProfileManager::self()->loadProfile( (*it).id() );
00133 break;
00134 }
00135 }
00136 }
00137
00138 AlarmClient alarmclient;
00139 alarmclient.startDaemon();
00140
00141
00142
00143 return KUniqueApplication::newInstance();
00144 }
00145
00146 int main( int argc, char **argv )
00147 {
00148 KAboutData about( "kontact", I18N_NOOP( "Kontact" ), version, description,
00149 KAboutData::License_GPL, I18N_NOOP("(C) 2001-2008 The Kontact developers"), 0, "http://kontact.org" );
00150 about.addAuthor( "Daniel Molkentin", 0, "molkentin@kde.org" );
00151 about.addAuthor( "Don Sanders", 0, "sanders@kde.org" );
00152 about.addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" );
00153 about.addAuthor( "Tobias K\303\266nig", 0, "tokoe@kde.org" );
00154 about.addAuthor( "David Faure", 0, "faure@kde.org" );
00155 about.addAuthor( "Ingo Kl\303\266cker", 0, "kloecker@kde.org" );
00156 about.addAuthor( "Sven L\303\274ppken", 0, "sven@kde.org" );
00157 about.addAuthor( "Zack Rusin", 0, "zack@kde.org" );
00158 about.addAuthor( "Matthias Hoelzer-Kluepfel", I18N_NOOP("Original Author"), "mhk@kde.org" );
00159
00160 KCmdLineArgs::init( argc, argv, &about );
00161 Kontact::UniqueAppHandler::loadKontactCommandLineOptions();
00162
00163 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00164 if ( args->isSet( "list" ) ) {
00165 listPlugins();
00166 return 0;
00167 }
00168
00169 if ( args->isSet( "listprofiles" ) ) {
00170 listProfiles();
00171 return 0;
00172 }
00173
00174 if ( !KontactApp::start() ) {
00175
00176 return 0;
00177 }
00178
00179 KontactApp app;
00180 if ( app.restoringSession() ) {
00181
00182 if ( KMainWindow::canBeRestored( 1 ) ) {
00183 Kontact::MainWindow *mainWindow = new Kontact::MainWindow();
00184 app.setMainWindow( mainWindow );
00185 app.setSessionRestored( true );
00186 mainWindow->show();
00187 mainWindow->restore( 1 );
00188 }
00189 }
00190
00191 bool ret = app.exec();
00192 while ( KMainWindow::memberList->first() )
00193 delete KMainWindow::memberList->first();
00194
00195 return ret;
00196 }
|