uniqueapphandler.cpp
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 if ( fun == "load()" ) {
00107 replyType = "bool";
00108 (void)mPlugin->part();
00109
00110 QDataStream _replyStream( replyData, IO_WriteOnly );
00111 _replyStream << true;
00112 } else {
00113 return DCOPObject::process( fun, data, replyType, replyData );
00114 }
00115 return true;
00116 }
00117
00118 QCStringList UniqueAppHandler::interfaces()
00119 {
00120 QCStringList ifaces = DCOPObject::interfaces();
00121 ifaces += "Kontact::UniqueAppHandler";
00122 return ifaces;
00123 }
00124
00125 QCStringList UniqueAppHandler::functions()
00126 {
00127 QCStringList funcs = DCOPObject::functions();
00128 funcs << "int newInstance()";
00129 funcs << "bool load()";
00130 return funcs;
00131 }
00132
00133 UniqueAppWatcher::UniqueAppWatcher( UniqueAppHandlerFactoryBase* factory, Plugin* plugin )
00134 : QObject( plugin ), mFactory( factory ), mPlugin( plugin )
00135 {
00136
00137 mRunningStandalone = kapp->dcopClient()->isApplicationRegistered( plugin->name() );
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 delete mFactory;
00156 }
00157
00158 void UniqueAppWatcher::unregisteredFromDCOP( const QCString& appId )
00159 {
00160 if ( appId == mPlugin->name() && mRunningStandalone ) {
00161 disconnect( kapp->dcopClient(), SIGNAL( applicationRemoved( const QCString&)),
00162 this, SLOT( unregisteredFromDCOP( const QCString& )) );
00163 kdDebug(5601) << k_funcinfo << appId << endl;
00164 mFactory->createHandler( mPlugin );
00165 kapp->dcopClient()->setNotifications( false );
00166 mRunningStandalone = false;
00167 }
00168 }
00169
00170 }
00171
00172 #include "uniqueapphandler.moc"
This file is part of the documentation for kontact Library Version 3.3.2.