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