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 <tdeaboutdata.h> 00026 #include <tdecmdlineargs.h> 00027 #include <kdebug.h> 00028 #include <kiconloader.h> 00029 #include <tdelocale.h> 00030 #include <tdestartupinfo.h> 00031 #include <kuniqueapplication.h> 00032 #include <twin.h> 00033 #include <kstandarddirs.h> 00034 #include <ktrader.h> 00035 #include "plugin.h" 00036 00037 #include <tqlabel.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( "TDE personal information manager" ); 00049 00050 static const char version[] = "1.2.9"; 00051 00052 class KontactApp : public KUniqueApplication { 00053 public: 00054 KontactApp() : mMainWindow( 0 ), mSessionRestored( false ) 00055 { 00056 TDEGlobal::iconLoader()->addAppDir( "tdepim" ); 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 TDEInstance instance( "kontact" ); // Can't use KontactApp since it's too late for adding cmdline options 00078 TDETrader::OfferList offers = TDETrader::self()->query( 00079 TQString::fromLatin1( "Kontact/Plugin" ), 00080 TQString( "[X-TDE-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 TQVariant var = service->property( "X-TDE-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 TQValueList<Kontact::Profile> profiles = Kontact::ProfileManager::self()->profiles(); 00094 for( TQValueListIterator<Kontact::Profile> it = profiles.begin() ; it != profiles.end(); ++it ) { 00095 cout << (*it).name().latin1() << endl; 00096 } 00097 } 00098 00099 int KontactApp::newInstance() 00100 { 00101 TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); 00102 TQString moduleName; 00103 if ( Kontact::Prefs::self()->forceStartupPlugin() ) { 00104 moduleName = Kontact::Prefs::self()->forcedStartupPlugin(); 00105 } 00106 if ( args->isSet( "module" ) ) { 00107 moduleName = TQString::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 TQValueList<Kontact::Profile> profiles = Kontact::ProfileManager::self()->profiles(); 00129 for( TQValueListIterator<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 TDEAboutData about( "kontact", I18N_NOOP( "Kontact" ), version, description, 00148 TDEAboutData::License_GPL, 00149 I18N_NOOP("(C) 2008-2018 The Trinity Desktop Project\n(C) 2001-2008 The Kontact developers"), 00150 0, "http://www.trinitydesktop.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 TDECmdLineArgs::init( argc, argv, &about ); 00162 Kontact::UniqueAppHandler::loadKontactCommandLineOptions(); 00163 00164 TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); 00165 if ( args->isSet( "list" ) ) { 00166 listPlugins(); 00167 return 0; 00168 } 00169 00170 if ( args->isSet( "listprofiles" ) ) { 00171 listProfiles(); 00172 return 0; 00173 } 00174 00175 if ( !KontactApp::start() ) { 00176 // Already running, brought to the foreground. 00177 return 0; 00178 } 00179 00180 KontactApp app; 00181 if ( app.restoringSession() ) { 00182 // There can only be one main window 00183 if ( TDEMainWindow::canBeRestored( 1 ) ) { 00184 Kontact::MainWindow *mainWindow = new Kontact::MainWindow(); 00185 app.setMainWindow( mainWindow ); 00186 app.setSessionRestored( true ); 00187 mainWindow->show(); 00188 mainWindow->restore( 1 ); 00189 } 00190 } 00191 00192 bool ret = app.exec(); 00193 while ( TDEMainWindow::memberList->first() ) 00194 delete TDEMainWindow::memberList->first(); 00195 00196 return ret; 00197 }