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
00031
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 using namespace Kontact;
00070
00071 int UniqueAppHandler::newInstance()
00072 {
00073
00074 if ( kapp->mainWidget() ) {
00075 kapp->mainWidget()->show();
00076 KWin::forceActiveWindow( kapp->mainWidget()->winId() );
00077 KStartupInfo::appStarted();
00078 }
00079
00080
00081 mPlugin->core()->selectPlugin( mPlugin );
00082 return 0;
00083 }
00084
00085 bool UniqueAppHandler::process( const QCString &fun, const QByteArray &data,
00086 QCString& replyType, QByteArray &replyData )
00087 {
00088 if ( fun == "newInstance()" ) {
00089 replyType = "int";
00090
00091 KCmdLineArgs::reset();
00092 loadCommandLineOptions();
00093
00094
00095 QDataStream ds( data, IO_ReadOnly );
00096 KCmdLineArgs::loadAppArgs( ds );
00097 if ( !ds.atEnd() ) {
00098 QCString asn_id;
00099 ds >> asn_id;
00100 kapp->setStartupId( asn_id );
00101 }
00102
00103 QDataStream _replyStream( replyData, IO_WriteOnly );
00104 _replyStream << newInstance( );
00105 } else if ( fun == "load()" ) {
00106 replyType = "bool";
00107 (void)mPlugin->part();
00108
00109 QDataStream _replyStream( replyData, IO_WriteOnly );
00110 _replyStream << true;
00111 } else {
00112 return DCOPObject::process( fun, data, replyType, replyData );
00113 }
00114 return true;
00115 }
00116
00117 QCStringList UniqueAppHandler::interfaces()
00118 {
00119 QCStringList ifaces = DCOPObject::interfaces();
00120 ifaces += "Kontact::UniqueAppHandler";
00121 return ifaces;
00122 }
00123
00124 QCStringList UniqueAppHandler::functions()
00125 {
00126 QCStringList funcs = DCOPObject::functions();
00127 funcs << "int newInstance()";
00128 funcs << "bool load()";
00129 return funcs;
00130 }
00131
00132 UniqueAppWatcher::UniqueAppWatcher( UniqueAppHandlerFactoryBase* factory, Plugin* plugin )
00133 : QObject( plugin ), mFactory( factory ), mPlugin( plugin )
00134 {
00135
00136 mRunningStandalone = kapp->dcopClient()->isApplicationRegistered( plugin->name() );
00137
00138
00139 if ( mRunningStandalone && kapp->dcopClient()->findLocalClient( plugin->name() ) )
00140 mRunningStandalone = false;
00141
00142 if ( mRunningStandalone ) {
00143 kapp->dcopClient()->setNotifications( true );
00144 connect( kapp->dcopClient(), SIGNAL( applicationRemoved( const QCString& ) ),
00145 this, SLOT( unregisteredFromDCOP( const QCString& ) ) );
00146 } else {
00147 mFactory->createHandler( mPlugin );
00148 }
00149 }
00150
00151 UniqueAppWatcher::~UniqueAppWatcher()
00152 {
00153 if ( mRunningStandalone )
00154 kapp->dcopClient()->setNotifications( false );
00155
00156 delete mFactory;
00157 }
00158
00159 void UniqueAppWatcher::unregisteredFromDCOP( const QCString& appId )
00160 {
00161 if ( appId == mPlugin->name() && mRunningStandalone ) {
00162 disconnect( kapp->dcopClient(), SIGNAL( applicationRemoved( const QCString& ) ),
00163 this, SLOT( unregisteredFromDCOP( const QCString& ) ) );
00164 kdDebug(5601) << k_funcinfo << appId << endl;
00165 mFactory->createHandler( mPlugin );
00166 kapp->dcopClient()->setNotifications( false );
00167 mRunningStandalone = false;
00168 }
00169 }
00170
00171 #include "uniqueapphandler.moc"
|