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 "splash.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.0 (proko2 2.1.7)";
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 {
00069 KService::Ptr service = (*it);
00070 cout << service->library().remove( "libkontact_" ).latin1() << endl;
00071 }
00072 }
00073
00074 static KCmdLineOptions options[] =
00075 {
00076 { "module <module>", I18N_NOOP("Start with a specific Kontact module"), 0 },
00077 { "nosplash", I18N_NOOP("Disable the splash screen"), 0 },
00078 { "iconify", I18N_NOOP("Start in iconified (minimized) mode"), 0 },
00079 { "list", I18N_NOOP("List all possible modules and exit"), 0 },
00080 KCmdLineLastOption
00081 };
00082
00083 void KontactApp::startKOrgac()
00084 {
00085 if ( kapp->dcopClient()->isApplicationRegistered( "korgac" ) ) {
00086
00087 return;
00088 }
00089 KGlobal::dirs()->addResourceType("autostart", "share/autostart");
00090 QString desktopFile = locate( "autostart", "korgac.desktop" );
00091 if ( desktopFile.isEmpty() ) {
00092 kdWarning() << "Couldn't find autostart/korgac.desktop!" << endl;
00093 }
00094 else {
00095 QString error;
00096 if ( startServiceByDesktopPath( desktopFile, QStringList(), &error ) != 0 )
00097 kdWarning() << "Failure starting korgac:" << error << endl;
00098 }
00099 }
00100
00101 int KontactApp::newInstance()
00102 {
00103 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00104 QString moduleName;
00105 if ( args->isSet("module") )
00106 {
00107 moduleName = QString::fromLocal8Bit(args->getOption("module"));
00108 }
00109 Kontact::Splash* splash = new Kontact::Splash( 0, "splash" );
00110 if ( !mMainWindow && args->isSet("splash") )
00111 splash->show();
00112
00113 if ( isRestored() ) {
00114
00115 if ( KMainWindow::canBeRestored( 1 ) ) {
00116 mMainWindow = new Kontact::MainWindow(splash);
00117 setMainWidget( mMainWindow );
00118 mMainWindow->show();
00119 mMainWindow->restore( 1 );
00120 }
00121 } else {
00122 if ( !mMainWindow ) {
00123 mMainWindow = new Kontact::MainWindow(splash);
00124 if ( !moduleName.isEmpty() )
00125 mMainWindow->activePluginModule( moduleName );
00126 mMainWindow->show();
00127 setMainWidget( mMainWindow );
00128
00129
00130 if ( args->isSet( "iconify" ) )
00131 KWin::iconifyWindow( mMainWindow->winId(), false );
00132 }
00133 else
00134 {
00135 if ( !moduleName.isEmpty() )
00136 mMainWindow->activePluginModule( moduleName );
00137 }
00138 }
00139
00140 startKOrgac();
00141
00142
00143
00144 return KUniqueApplication::newInstance();
00145 }
00146
00147 int main(int argc, char **argv)
00148 {
00149 KAboutData about( "kontact", I18N_NOOP( "Kontact" ), version, description,
00150 KAboutData::License_GPL, I18N_NOOP("(C) 2001-2006 The Kontact developers"), 0, "http://kontact.org" );
00151 about.addAuthor( "Daniel Molkentin", 0, "molkentin@kde.org" );
00152 about.addAuthor( "Don Sanders", 0, "sanders@kde.org" );
00153 about.addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" );
00154 about.addAuthor( "Tobias K\303\266nig", 0, "tokoe@kde.org" );
00155 about.addAuthor( "David Faure", 0, "faure@kde.org" );
00156 about.addAuthor( "Ingo Kl\303\266cker", 0, "kloecker@kde.org" );
00157 about.addAuthor( "Sven L\303\274ppken", 0, "sven@kde.org" );
00158 about.addAuthor( "Zack Rusin", 0, "zack@kde.org" );
00159 about.addAuthor( "Matthias Hoelzer-Kluepfel", I18N_NOOP("Original Author"), "mhk@kde.org" );
00160
00161 KCmdLineArgs::init( argc, argv, &about );
00162 KCmdLineArgs::addCmdLineOptions( options );
00163 KUniqueApplication::addCmdLineOptions();
00164 KApplication::addCmdLineOptions();
00165
00166 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00167 if ( args->isSet( "list" ) )
00168 {
00169 listPlugins();
00170 return 0;
00171 }
00172
00173 if ( !KontactApp::start() ) {
00174
00175 return 0;
00176 }
00177
00178 KontactApp app;
00179 bool ret = app.exec();
00180 while ( KMainWindow::memberList->first() )
00181 delete KMainWindow::memberList->first();
00182
00183 return ret;
00184 }