kontact
uniqueapphandler.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "uniqueapphandler.h"
00023 #include <kstartupinfo.h>
00024 #include <kapplication.h>
00025 #include <kcmdlineargs.h>
00026 #include "core.h"
00027 #include <kwin.h>
00028 #include <dcopclient.h>
00029 #include <kdebug.h>
00030 #include <klocale.h>
00031 #include <kuniqueapplication.h>
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 using namespace Kontact;
00078
00079 int UniqueAppHandler::newInstance()
00080 {
00081
00082 if ( kapp->mainWidget() ) {
00083 kapp->mainWidget()->show();
00084 KWin::forceActiveWindow( kapp->mainWidget()->winId() );
00085 KStartupInfo::appStarted();
00086 }
00087
00088
00089 mPlugin->core()->selectPlugin( mPlugin );
00090 return 0;
00091 }
00092
00093 bool UniqueAppHandler::process( const QCString &fun, const QByteArray &data,
00094 QCString& replyType, QByteArray &replyData )
00095 {
00096 if ( fun == "newInstance()" ) {
00097 replyType = "int";
00098
00099 KCmdLineArgs::reset();
00100 loadCommandLineOptions();
00101
00102
00103 QDataStream ds( data, IO_ReadOnly );
00104 KCmdLineArgs::loadAppArgs( ds );
00105 if ( !ds.atEnd() ) {
00106 QCString asn_id;
00107 ds >> asn_id;
00108 kapp->setStartupId( asn_id );
00109 }
00110
00111 QDataStream _replyStream( replyData, IO_WriteOnly );
00112 _replyStream << newInstance();
00113
00114
00115
00116
00117 KCmdLineArgs::reset();
00118 loadKontactCommandLineOptions();
00119
00120 } else if ( fun == "load()" ) {
00121 replyType = "bool";
00122 (void)mPlugin->part();
00123
00124 QDataStream _replyStream( replyData, IO_WriteOnly );
00125 _replyStream << true;
00126 } else {
00127 return DCOPObject::process( fun, data, replyType, replyData );
00128 }
00129 return true;
00130 }
00131
00132 QCStringList UniqueAppHandler::interfaces()
00133 {
00134 QCStringList ifaces = DCOPObject::interfaces();
00135 ifaces += "Kontact::UniqueAppHandler";
00136 return ifaces;
00137 }
00138
00139 QCStringList UniqueAppHandler::functions()
00140 {
00141 QCStringList funcs = DCOPObject::functions();
00142 funcs << "int newInstance()";
00143 funcs << "bool load()";
00144 return funcs;
00145 }
00146
00147 UniqueAppWatcher::UniqueAppWatcher( UniqueAppHandlerFactoryBase* factory, Plugin* plugin )
00148 : QObject( plugin ), mFactory( factory ), mPlugin( plugin )
00149 {
00150
00151 mRunningStandalone = kapp->dcopClient()->isApplicationRegistered( plugin->name() );
00152
00153
00154 if ( mRunningStandalone && kapp->dcopClient()->findLocalClient( plugin->name() ) )
00155 mRunningStandalone = false;
00156
00157 if ( mRunningStandalone ) {
00158 kapp->dcopClient()->setNotifications( true );
00159 connect( kapp->dcopClient(), SIGNAL( applicationRemoved( const QCString& ) ),
00160 this, SLOT( unregisteredFromDCOP( const QCString& ) ) );
00161 } else {
00162 mFactory->createHandler( mPlugin );
00163 }
00164 }
00165
00166 UniqueAppWatcher::~UniqueAppWatcher()
00167 {
00168 if ( mRunningStandalone )
00169 kapp->dcopClient()->setNotifications( false );
00170
00171 delete mFactory;
00172 }
00173
00174 void UniqueAppWatcher::unregisteredFromDCOP( const QCString& appId )
00175 {
00176 if ( appId == mPlugin->name() && mRunningStandalone ) {
00177 disconnect( kapp->dcopClient(), SIGNAL( applicationRemoved( const QCString& ) ),
00178 this, SLOT( unregisteredFromDCOP( const QCString& ) ) );
00179 kdDebug(5601) << k_funcinfo << appId << endl;
00180 mFactory->createHandler( mPlugin );
00181 kapp->dcopClient()->setNotifications( false );
00182 mRunningStandalone = false;
00183 }
00184 }
00185
00186 static KCmdLineOptions options[] =
00187 {
00188 { "module <module>", I18N_NOOP( "Start with a specific Kontact module" ), 0 },
00189 { "iconify", I18N_NOOP( "Start in iconified (minimized) mode" ), 0 },
00190 { "list", I18N_NOOP( "List all possible modules and exit" ), 0 },
00191 KCmdLineLastOption
00192 };
00193
00194 void Kontact::UniqueAppHandler::loadKontactCommandLineOptions()
00195 {
00196 KCmdLineArgs::addCmdLineOptions( options );
00197 KUniqueApplication::addCmdLineOptions();
00198 KApplication::addCmdLineOptions();
00199 }
00200
00201 #include "uniqueapphandler.moc"
|