diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/kvilib/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/kvilib/ext/kvi_dcophelper.cpp | 356 | ||||
| -rw-r--r-- | src/kvilib/ext/kvi_dcophelper.h | 82 | ||||
| -rw-r--r-- | src/modules/system/libkvisystem.cpp | 29 |
4 files changed, 15 insertions, 453 deletions
diff --git a/src/kvilib/CMakeLists.txt b/src/kvilib/CMakeLists.txt index a4111c18e..71d169aac 100644 --- a/src/kvilib/CMakeLists.txt +++ b/src/kvilib/CMakeLists.txt @@ -65,7 +65,6 @@ SET(kvilib_SRCS ext/kvi_crypt.cpp ext/kvi_databuffer.cpp ext/kvi_dbusadaptor.cpp - ext/kvi_dcophelper.cpp ext/kvi_garbage.cpp ext/kvi_md5.cpp ext/kvi_mediatype.cpp diff --git a/src/kvilib/ext/kvi_dcophelper.cpp b/src/kvilib/ext/kvi_dcophelper.cpp deleted file mode 100644 index 2d58350c2..000000000 --- a/src/kvilib/ext/kvi_dcophelper.cpp +++ /dev/null @@ -1,356 +0,0 @@ -//============================================================================= -// -// File : kvi_dcophelper.cpp -// Creation date : Sat 20 Jan 2005 12:35:21 by Szymon Stefanek -// -// This file is part of the KVIrc IRC client distribution -// Copyright (C) 2005 Szymon Stefanek <pragma at kvirc dot net> -// Copyright (C) 2007-2008 Alexander Stillich <torque at pltn dot org> -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -//============================================================================= - -#include "kvi_dcophelper.h" - -#ifdef COMPILE_KDE3_SUPPORT - -#include "dcopclient.h" - -#include <QDataStream> -#include <QList> - -// must be included this way, since kvilib is built -// before kvirc and symlinks to headers aren't set yet -#include "../../kvirc/kernel/kvi_app.h" -#include "kvi_thread.h" - -KviDCOPHelper::KviDCOPHelper(bool bStartApp, const KviQCString &szAppId) -{ - m_szAppId = szAppId; -} - -KviDCOPHelper::~KviDCOPHelper() -{ -} - -bool KviDCOPHelper::ensureAppRunning(const QString &szApp) -{ - if (findRunningApp(m_szAppId)) - return true; - - if (m_bStartApp) - return startApp(m_szAppId,400); - - return false; -} - - -bool KviDCOPHelper::voidRetVoidDCOPCall(const KviQCString &szObj,const KviQCString &szFunc) -{ - if(!ensureAppRunning(m_szAppId))return false; - QByteArray data; - return g_pApp->dcopClient()->send(m_szAppId,szObj,szFunc,data); -} - -bool KviDCOPHelper::voidRetBoolDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,bool bVal) -{ - if(!ensureAppRunning(m_szAppId))return false; - QByteArray data; - QDataStream arg(data, IO_WriteOnly); - arg << bVal; - return g_pApp->dcopClient()->send(m_szAppId,szObj,szFunc,data); -} - -bool KviDCOPHelper::voidRetIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,int iVal) -{ - if(!ensureAppRunning(m_szAppId))return false; - QByteArray data; - QDataStream arg(data, IO_WriteOnly); - arg << iVal; - return g_pApp->dcopClient()->send(m_szAppId,szObj,szFunc,data); -} - -bool KviDCOPHelper::voidRetIntBoolDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,int iVal, bool bVal) -{ - if(!ensureAppRunning(m_szAppId))return false; - QByteArray data; - QDataStream arg(data, IO_WriteOnly); - arg << iVal; - arg << bVal; - return g_pApp->dcopClient()->send(m_szAppId,szObj,szFunc,data); -} - -bool KviDCOPHelper::voidRetIntIntIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,int iVal1, int iVal2, int iVal3) -{ - if(!ensureAppRunning(m_szAppId))return false; - QByteArray data; - QDataStream arg(data, IO_WriteOnly); - arg << iVal1; - arg << iVal2; - arg << iVal3; - return g_pApp->dcopClient()->send(m_szAppId,szObj,szFunc,data); -} - -bool KviDCOPHelper::voidRetFloatDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,float fVal) -{ - if(!ensureAppRunning(m_szAppId))return false; - QByteArray data; - QDataStream arg(data, IO_WriteOnly); - arg << fVal; - return g_pApp->dcopClient()->send(m_szAppId,szObj,szFunc,data); -} - -bool KviDCOPHelper::voidRetStringDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,const QString &szVal) -{ - if(!ensureAppRunning(m_szAppId))return false; - QByteArray data; - QDataStream arg(data, IO_WriteOnly); - arg << szVal; - return g_pApp->dcopClient()->send(m_szAppId,szObj,szFunc,data); -} - -bool KviDCOPHelper::stringRetVoidDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,QString &szRet) -{ - if(!ensureAppRunning(m_szAppId))return false; - QByteArray data, replyData; - KviQCString replyType; - if(!g_pApp->dcopClient()->call(m_szAppId,szObj,szFunc,data,replyType,replyData)) - return false; - QDataStream reply( replyData, IO_ReadOnly ); - if(replyType == "QString") - { - reply >> szRet; - return true; - } - return false; -} - -bool KviDCOPHelper::stringRetIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,QString &szRet,int iVal) -{ - if(!ensureAppRunning(m_szAppId))return false; - QByteArray data, replyData; - KviQCString replyType; - - QDataStream arg(data, IO_WriteOnly); - arg << iVal; - - if(!g_pApp->dcopClient()->call(m_szAppId,szObj,szFunc,data,replyType,replyData)) - return false; - - QDataStream reply( replyData, IO_ReadOnly ); - if(replyType == "QString") - { - reply >> szRet; - return true; - } - return false; -} - -bool KviDCOPHelper::intRetVoidDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,int &ret) -{ - if(!ensureAppRunning(m_szAppId))return false; - QByteArray data, replyData; - KviQCString replyType; - if(!g_pApp->dcopClient()->call(m_szAppId,szObj,szFunc,data,replyType,replyData)) - return false; - QDataStream reply( replyData, IO_ReadOnly ); - if(replyType == "int") - { - reply >> ret; - return true; - } - return false; -} - -bool KviDCOPHelper::intRetIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,int &ret, int iVal) -{ - if(!ensureAppRunning(m_szAppId))return false; - QByteArray data, replyData; - KviQCString replyType; - - QDataStream arg(data, IO_WriteOnly); - arg << iVal; - - if(!g_pApp->dcopClient()->call(m_szAppId,szObj,szFunc,data,replyType,replyData)) - return false; - - QDataStream reply( replyData, IO_ReadOnly ); - if(replyType == "int") - { - reply >> ret; - return true; - } - return false; -} - -bool KviDCOPHelper::boolRetVoidDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,bool &ret) -{ - if(!ensureAppRunning(m_szAppId))return false; - QByteArray data, replyData; - KviQCString replyType; - if(!g_pApp->dcopClient()->call(m_szAppId,szObj,szFunc,data,replyType,replyData)) - return false; - QDataStream reply( replyData, IO_ReadOnly ); - if(replyType == "bool") - { - reply >> ret; - return true; - } - return false; -} - -bool KviDCOPHelper::qvalueListIntRetIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,QList<int> &ret, int iVal) -{ - if(!ensureAppRunning(m_szAppId)) - return false; - - QByteArray data, replyData; - KviQCString replyType; - QDataStream arg(data, IO_WriteOnly); - - arg << iVal; - - - if(!g_pApp->dcopClient()->call(m_szAppId,szObj,szFunc,data,replyType,replyData)) - return false; - - if(replyType != "QList<int>") - return false; - - QDataStream replyStream(replyData, IO_ReadOnly); - replyStream >> ret; - - return true; -} - -bool KviDCOPHelper::qcstringListRetVoidDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,KviQCStringList &ret) -{ - QByteArray data, replyData; - KviQCString replyType; - - if (!g_pApp->dcopClient()->call(m_szAppId,szObj,szFunc,data,replyType,replyData)) - return false; - - if (replyType != "KviQCStringList") - return false; - - QDataStream replyStream(replyData, IO_ReadOnly); - replyStream >> ret; - - return true; -} - -bool KviDCOPHelper::qcstringListRetIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,KviQCStringList &ret, int iVal) -{ - QByteArray data, replyData; - KviQCString replyType; - - QDataStream arg(data, IO_WriteOnly); - arg << iVal; - - if (!g_pApp->dcopClient()->call(m_szAppId,szObj,szFunc,data,replyType,replyData)) - return false; - - if (replyType != "KviQCStringList") - return false; - - QDataStream replyStream(replyData, IO_ReadOnly); - replyStream >> ret; - - return true; -} - -bool KviDCOPHelper::findRunningApp(const QString &szApp) -{ - QList<KviQCString> allApps = g_pApp->dcopClient() ->registeredApplications(); - QList<KviQCString>::iterator iterator; - KviQCString sz = szApp.toLocal8Bit(); - for (iterator = allApps.begin();iterator != allApps.end();iterator++) - { - if(*iterator == sz) - return true; - } - return false; -} - -int KviDCOPHelper::detectApp(const QString &szApp,bool bStart,int iScoreWhenFound,int iScoreWhenStarted) -{ - // dcop available - if(!g_pApp->dcopClient()) - return 0; - - if(findRunningApp(szApp)) - return 95; // found a running app, no need to run further - - // no app found running - if(bStart) - { - // try to start it - if(!startApp(szApp,5000)) - return 10; // very low possibility - return findRunningApp(szApp) ? 99 : 0; // try to find it again - } - - return 30; // it still might be installed on the system but we're just unable to start it... -} - - -bool KviDCOPHelper::startApp(const QString &szApp,int iWaitMSecs) -{ - // we could use KApplication::startServiceByDesktopName here - // but we want to be able to wait a defined amount of time - QStringList tmp; - QByteArray data, replyData; - KviQCString replyType; - QDataStream arg(data, IO_WriteOnly); - arg << szApp << tmp; - if(!g_pApp->dcopClient()->call( - "klauncher", - "klauncher", - "start_service_by_desktop_name(QString,QStringList)", - data, - replyType, - replyData)) - { - return false; - } else { - QDataStream reply(replyData, IO_ReadOnly); - if(replyType != "serviceResult")return false; - int result; - KviQCString dcopName; - QString error; - reply >> result >> dcopName >> error; - if(result != 0)return false; - } - // ok , we seem to have started it.. but it might take some seconds - // for the app to get registered - // we wait up to five seconds - if(iWaitMSecs > 0) - { - int i = 0; - while(i < iWaitMSecs) - { - if(findRunningApp(szApp))return true; - KviThread::msleep(100); - i += 100; - } - return findRunningApp(szApp); - } - return true; -} - - -#endif //COMPILE_KDE_SUPPORT diff --git a/src/kvilib/ext/kvi_dcophelper.h b/src/kvilib/ext/kvi_dcophelper.h deleted file mode 100644 index 6a997eb18..000000000 --- a/src/kvilib/ext/kvi_dcophelper.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef _KVI_DCOPHELPER_H_ -#define _KVI_DCOPHELPER_H_ -//============================================================================= -// -// File : kvi_dcophelper.h -// Creation date : Sat 20 Jan 2005 12:35:21 by Szymon Stefanek -// -// This file is part of the KVIrc IRC client distribution -// Copyright (C) 2005 Szymon Stefanek <pragma at kvirc dot net> -// Copyright (C) 2007-2008 Alexander Stillich <torque at pltn dot org> -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -//============================================================================= - -#include "kvi_settings.h" -#include "kvi_qstring.h" -#include "kvi_qcstring.h" -#include <QList> - -#ifdef COMPILE_KDE3_SUPPORT - -typedef QList<KviQCString> KviQCStringList; - -class KVILIB_API KviDCOPHelper -{ - -public: - - // Constructs a DCOP helper object. - // bStartApp: tries to start application when a dcop call is about to be made and the app is not already running - // szAppID: application name as seen by DCOP - KviDCOPHelper(bool bStartApp, const KviQCString &szAppId); - ~KviDCOPHelper(); - -protected: - - KviQCString m_szAppId; - bool m_bStartApp; - -protected: - - bool ensureAppRunning(const QString &szApp); - bool findRunningApp(const QString &szApp); - bool startApp(const QString &szApp,int iWaitMSecs = 0); - int detectApp(const QString &szApp,bool bStart,int iScoreWhenFound,int iScoreWhenStarted); - - // naming convention: [return value] Ret [argument type(s)] DCOPCall - - bool voidRetVoidDCOPCall(const KviQCString &szObj,const KviQCString &szFunc); - bool voidRetIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,int iVal); - bool voidRetIntBoolDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,int iVal, bool bVal); - bool voidRetIntIntIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,int iVal1, int iVal2, int iVal3); - bool voidRetBoolDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,bool bVal); - bool voidRetStringDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,const QString &szVal); - bool voidRetFloatDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,float fVal); - bool stringRetVoidDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,QString &szRet); - bool stringRetIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,QString &szRet,int iVal); - bool intRetVoidDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,int &ret); - bool intRetIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,int &ret, int iVal); - bool boolRetVoidDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,bool &ret); - - bool qvalueListIntRetIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,QList<int> &ret, int iVal); - bool qcstringListRetIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,KviQCStringList &ret, int iVal); - bool qcstringListRetVoidDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,KviQCStringList &ret); -}; - -#endif //COMPILE_KDE_SUPPORT - -#endif // _KVI_DCOPHELPER_H_ diff --git a/src/modules/system/libkvisystem.cpp b/src/modules/system/libkvisystem.cpp index 964922cec..29447176d 100644 --- a/src/modules/system/libkvisystem.cpp +++ b/src/modules/system/libkvisystem.cpp @@ -44,8 +44,8 @@ #include <unistd.h> #endif -#ifdef COMPILE_KDE3_SUPPORT - #include <dcopclient.h> +#ifdef COMPILE_KDE_SUPPORT + #include <QtDBus/QtDBus> #endif KviPluginManager * g_pPluginManager; @@ -398,19 +398,19 @@ static bool system_kvs_fnc_hostname(KviKvsModuleFunctionCall *c) /* - @doc: system.dcop + @doc: system.dbus @keyterms: System information @type: function @title: - $system.dcop + $system.dbus @short: - Performs a DCOP call + Performs a DBus call @syntax: - <variant> $system.dcop(<application:string>,<objectid:string>,<function:string>[,<parameter1:string>[,<parameter2:string>[,...]]]) + <variant> $system.dbus(<service:string>,<path:string>,<interface:string>,<method:string>[,<parameter1:string>[,<parameter2:string>[,...]]]) @description: - This function allows performing simple DCOP calls without executing + This function allows performing simple Dbus calls without executing an external process. This feature is available ONLY when KDE support is compiled in the executable: this means that this function is absolutely non portable (don't use it in scripts that you're going to distribute). @@ -443,7 +443,7 @@ static bool system_kvs_fnc_hostname(KviKvsModuleFunctionCall *c) [/example] */ -static bool system_kvs_fnc_dcop(KviKvsModuleFunctionCall *c) +static bool system_kvs_fnc_dbus(KviKvsModuleFunctionCall *c) { bool bTestMode = false; @@ -451,12 +451,13 @@ static bool system_kvs_fnc_dcop(KviKvsModuleFunctionCall *c) QStringList parms; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("application",KVS_PT_NONEMPTYCSTRING,0,szApp) - KVSM_PARAMETER("objectid",KVS_PT_NONEMPTYCSTRING,0,szObj) - KVSM_PARAMETER("function",KVS_PT_NONEMPTYCSTRING,0,szFun) + KVSM_PARAMETER("service",KVS_PT_NONEMPTYCSTRING,0,szService) + KVSM_PARAMETER("path",KVS_PT_NONEMPTYCSTRING,0,szPath) + KVSM_PARAMETER("interface",KVS_PT_NONEMPTYCSTRING,0,szInterface) + KVSM_PARAMETER("method",KVS_PT_NONEMPTYCSTRING,0,szMethod) KVSM_PARAMETER("parameter_list",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,parms) KVSM_PARAMETERS_END(c) - +/* if((szApp.data()) && (szApp.length() > 1)) { if(*(szApp.data()) == '?') @@ -585,7 +586,7 @@ static bool system_kvs_fnc_dcop(KviKvsModuleFunctionCall *c) c->warning(__tr2qs("DCOP calls are available only when KDE support is compiled in")); c->returnValue()->setInteger(0); #endif - +*/ return true; } @@ -693,7 +694,7 @@ static bool system_module_init(KviModule * m) KVSM_REGISTER_FUNCTION(m,"osnodename",system_kvs_fnc_osnodename); KVSM_REGISTER_FUNCTION(m,"getenv",system_kvs_fnc_getenv); KVSM_REGISTER_FUNCTION(m,"hostname",system_kvs_fnc_hostname); - KVSM_REGISTER_FUNCTION(m,"dcop",system_kvs_fnc_dcop); + KVSM_REGISTER_FUNCTION(m,"dbus",system_kvs_fnc_dbus); KVSM_REGISTER_FUNCTION(m,"clipboard",system_kvs_fnc_clipboard); KVSM_REGISTER_FUNCTION(m,"selection",system_kvs_fnc_selection); KVSM_REGISTER_FUNCTION(m,"checkModule",system_kvs_fnc_checkModule); |
