00001
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 "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.2";
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" );
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 KService::Ptr service = (*it);
00069
00070 QVariant var = service->property( "X-KDE-KontactPluginHasPart" );
00071 if ( var.isValid() && var.toBool() == false )
00072 continue;
00073 cout << service->library().remove( "libkontact_" ).latin1() << endl;
00074 }
00075 }
00076
00077 static KCmdLineOptions options[] =
00078 {
00079 { "module <module>", I18N_NOOP( "Start with a specific Kontact module" ), 0 },
00080 { "iconify", I18N_NOOP( "Start in iconified (minimized) mode" ), 0 },
00081 { "list", I18N_NOOP( "List all possible modules and exit" ), 0 },
00082 KCmdLineLastOption
00083 };
00084
00085 void KontactApp::startKOrgac()
00086 {
00087 if ( kapp->dcopClient()->isApplicationRegistered( "korgac" ) ) {
00088
00089 return;
00090 }
00091 KGlobal::dirs()->addResourceType("autostart", "share/autostart");
00092 QString desktopFile = locate( "autostart", "korgac.desktop" );
00093 if ( desktopFile.isEmpty() ) {
00094 kdWarning() << "Couldn't find autostart/korgac.desktop!" << endl;
00095 }
00096 else {
00097 QString error;
00098 if ( startServiceByDesktopPath( desktopFile, QStringList(), &error ) != 0 )
00099 kdWarning() << "Failure starting korgac:" << error << endl;
00100 }
00101 }
00102
00103 int KontactApp::newInstance()
00104 {
00105 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00106 QString moduleName;
00107 if ( Kontact::Prefs::self()->forceStartupPlugin() ) {
00108 moduleName = Kontact::Prefs::self()->forcedStartupPlugin();
00109 }
00110 if ( args->isSet( "module" ) ) {
00111 moduleName = QString::fromLocal8Bit( args->getOption( "module" ) );
00112 }
00113
00114 if ( isRestored() ) {
00115
00116 if ( KMainWindow::canBeRestored( 1 ) ) {
00117 mMainWindow = new Kontact::MainWindow();
00118 setMainWidget( mMainWindow );
00119 mMainWindow->show();
00120 mMainWindow->restore( 1 );
00121 }
00122 } else {
00123 if ( !mMainWindow ) {
00124 mMainWindow = new Kontact::MainWindow();
00125 if ( !moduleName.isEmpty() )
00126 mMainWindow->setActivePluginModule( moduleName );
00127 mMainWindow->show();
00128 setMainWidget( mMainWindow );
00129
00130
00131 if ( args->isSet( "iconify" ) )
00132 KWin::iconifyWindow( mMainWindow->winId(), false );
00133 } else {
00134 if ( !moduleName.isEmpty() )
00135 mMainWindow->setActivePluginModule( moduleName );
00136 }
00137 }
00138
00139 startKOrgac();
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-2004 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 KCmdLineArgs::addCmdLineOptions( options );
00162 KUniqueApplication::addCmdLineOptions();
00163 KApplication::addCmdLineOptions();
00164
00165 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00166 if ( args->isSet( "list" ) ) {
00167 listPlugins();
00168 return 0;
00169 }
00170
00171 if ( !KontactApp::start() ) {
00172
00173 return 0;
00174 }
00175
00176 KontactApp app;
00177 bool ret = app.exec();
00178 while ( KMainWindow::memberList->first() )
00179 delete KMainWindow::memberList->first();
00180
00181 return ret;
00182 }