diff options
| author | 2016-04-29 23:57:30 +0100 | |
|---|---|---|
| committer | 2016-04-29 23:57:48 +0100 | |
| commit | 690dd7a33ddc90678367d73adf313533536e10f2 (patch) | |
| tree | 2276fe7c384ebbc222b40a19c536d5c3c5606ce8 /src/modules/system | |
| parent | Add config for clang-format. (diff) | |
| download | KVIrc-690dd7a33ddc90678367d73adf313533536e10f2.tar.gz KVIrc-690dd7a33ddc90678367d73adf313533536e10f2.tar.bz2 KVIrc-690dd7a33ddc90678367d73adf313533536e10f2.zip | |
Apply clang-format
Diffstat (limited to 'src/modules/system')
| -rw-r--r-- | src/modules/system/Plugin.cpp | 119 | ||||
| -rw-r--r-- | src/modules/system/Plugin.h | 55 | ||||
| -rw-r--r-- | src/modules/system/libkvisystem.cpp | 282 |
3 files changed, 240 insertions, 216 deletions
diff --git a/src/modules/system/Plugin.cpp b/src/modules/system/Plugin.cpp index fd5fc2fdc..29c5db05b 100644 --- a/src/modules/system/Plugin.cpp +++ b/src/modules/system/Plugin.cpp @@ -104,7 +104,7 @@ [/example] */ -Plugin::Plugin(QLibrary * pLibrary, const QString& name) +Plugin::Plugin(QLibrary * pLibrary, const QString & name) { m_pLibrary = pLibrary; m_szName = name; @@ -112,25 +112,26 @@ Plugin::Plugin(QLibrary * pLibrary, const QString& name) Plugin::~Plugin() { - if(m_pLibrary->isLoaded()) m_pLibrary->unload(); + if(m_pLibrary->isLoaded()) + m_pLibrary->unload(); delete m_pLibrary; } -Plugin* Plugin::load(const QString& szFileName) +Plugin * Plugin::load(const QString & szFileName) { - QLibrary* pLibrary = new QLibrary(szFileName); - if (!pLibrary->load()) + QLibrary * pLibrary = new QLibrary(szFileName); + if(!pLibrary->load()) { delete pLibrary; return 0; } - Plugin* pPlugin = new Plugin(pLibrary,KviFileUtils::extractFileName(szFileName)); + Plugin * pPlugin = new Plugin(pLibrary, KviFileUtils::extractFileName(szFileName)); plugin_load function_load; function_load = (plugin_unload)pLibrary->resolve("_load"); - if (function_load) + if(function_load) { //TODO: THREAD function_load(); @@ -143,10 +144,11 @@ bool Plugin::pfree(char * pBuffer) plugin_free function_free; function_free = (plugin_free)m_pLibrary->resolve("_free"); - if (function_free) + if(function_free) { //TODO: THREAD - if(pBuffer) function_free(pBuffer); + if(pBuffer) + function_free(pBuffer); return true; } return false; @@ -157,7 +159,7 @@ bool Plugin::unload() plugin_unload function_unload; function_unload = (plugin_unload)m_pLibrary->resolve("_unload"); - if (function_unload) + if(function_unload) { //TODO: THREAD function_unload(); @@ -172,7 +174,7 @@ bool Plugin::canunload() plugin_canunload function_canunload; function_canunload = (plugin_canunload)m_pLibrary->resolve("_canunload"); - if (function_canunload) + if(function_canunload) { //TODO: THREAD return function_canunload(); @@ -180,19 +182,22 @@ bool Plugin::canunload() return true; } -int Plugin::call(const QString& pszFunctionName, int argc, char * argv[], char ** pBuffer) +int Plugin::call(const QString & pszFunctionName, int argc, char * argv[], char ** pBuffer) { int r; plugin_function function_call; function_call = (plugin_function)m_pLibrary->resolve(pszFunctionName.toUtf8().data()); - if (!function_call) + if(!function_call) { return -1; - } else { + } + else + { //TODO: THREAD - r = function_call(argc,argv,pBuffer); + r = function_call(argc, argv, pBuffer); } - if (r < 0) r = 0; // negative numbers are for error handling. + if(r < 0) + r = 0; // negative numbers are for error handling. return r; } @@ -201,14 +206,14 @@ QString Plugin::name() const return m_szName; } -void Plugin::setName(const QString& Name) +void Plugin::setName(const QString & Name) { m_szName = Name; } PluginManager::PluginManager() { - m_pPluginDict = new KviPointerHashTable<QString,Plugin>(5,false); + m_pPluginDict = new KviPointerHashTable<QString, Plugin>(5, false); m_pPluginDict->setAutoDelete(false); m_bCanUnload = true; @@ -216,18 +221,18 @@ PluginManager::PluginManager() PluginManager::~PluginManager() { - delete m_pPluginDict; + delete m_pPluginDict; } -bool PluginManager::pluginCall(KviKvsModuleFunctionCall *c) +bool PluginManager::pluginCall(KviKvsModuleFunctionCall * c) { // /echo $system.call("traffic.dll",about) QString szPluginPath; //contains full path and plugin name like "c:/plugin.dll" QString szFunctionName; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("plugin_path",KVS_PT_NONEMPTYSTRING,0,szPluginPath) - KVSM_PARAMETER("function",KVS_PT_NONEMPTYSTRING,0,szFunctionName) + KVSM_PARAMETER("plugin_path", KVS_PT_NONEMPTYSTRING, 0, szPluginPath) + KVSM_PARAMETER("function", KVS_PT_NONEMPTYSTRING, 0, szFunctionName) KVSM_PARAMETERS_END(c) //Check if there is such a plugin @@ -255,40 +260,41 @@ bool PluginManager::pluginCall(KviKvsModuleFunctionCall *c) iArgc = c->parameterCount() - 2; } - if (iArgc > 0) + if(iArgc > 0) { int i = 2; QString tmp; int iSize = 0; //Calculate buffer size - while (i < (iArgc + 2) ) + while(i < (iArgc + 2)) { c->params()->at(i)->asString(tmp); - iSize += tmp.length()+1; //+1 for the \0 characters + iSize += tmp.length() + 1; //+1 for the \0 characters i++; } //Allocate buffer - ppArgv = (char**)malloc(iArgc*sizeof(char*)); - pArgvBuffer = (char*)malloc(iSize); + ppArgv = (char **)malloc(iArgc * sizeof(char *)); + pArgvBuffer = (char *)malloc(iSize); i = 2; char * x = 0; x = pArgvBuffer; - while (i < (iArgc + 2) ) + while(i < (iArgc + 2)) { - ppArgv[i-2] = x; + ppArgv[i - 2] = x; c->params()->at(i)->asString(tmp); - strcpy(x,tmp.toLocal8Bit()); + strcpy(x, tmp.toLocal8Bit()); x += tmp.length(); *x = 0; x++; i++; } - - } else { + } + else + { //Avoid using unfilled variables ppArgv = 0; pArgvBuffer = 0; @@ -300,25 +306,26 @@ bool PluginManager::pluginCall(KviKvsModuleFunctionCall *c) Plugin * plugin; plugin = getPlugin(szPluginPath); - int r = plugin->call(szFunctionName,iArgc,ppArgv,&returnBuffer); + int r = plugin->call(szFunctionName, iArgc, ppArgv, &returnBuffer); if(r == -1) { c->error(__tr2qs("This plugin doesn't export the desired function.")); return true; } - if (r > 0) + if(r > 0) { c->returnValue()->setString(QString::fromLocal8Bit(returnBuffer)); } - //Clean up - if(pArgvBuffer) free(pArgvBuffer); - if(ppArgv) free(ppArgv); + if(pArgvBuffer) + free(pArgvBuffer); + if(ppArgv) + free(ppArgv); if(returnBuffer) { - if (!plugin->pfree(returnBuffer)) + if(!plugin->pfree(returnBuffer)) { c->warning(__tr2qs("The plugin has no function to free memory. This can result in memory leaks!")); } @@ -333,7 +340,7 @@ bool PluginManager::checkUnload() Always called when system module should be unloaded Checking here if all small "modules" can be unloaded */ - KviPointerHashTableIterator<QString,Plugin> it(*m_pPluginDict); + KviPointerHashTableIterator<QString, Plugin> it(*m_pPluginDict); m_bCanUnload = true; @@ -343,7 +350,9 @@ bool PluginManager::checkUnload() { it.current()->unload(); m_pPluginDict->remove(it.currentKey()); - } else { + } + else + { m_bCanUnload = false; } it.moveNext(); @@ -354,7 +363,7 @@ bool PluginManager::checkUnload() void PluginManager::unloadAll() { - KviPointerHashTableIterator<QString,Plugin> it(*m_pPluginDict); + KviPointerHashTableIterator<QString, Plugin> it(*m_pPluginDict); while(it.current()) { @@ -364,22 +373,24 @@ void PluginManager::unloadAll() } } -bool PluginManager::findPlugin(QString& szPath) +bool PluginManager::findPlugin(QString & szPath) { QString szFileName(KviFileUtils::extractFileName(szPath)); -// szFileName.detach(); + // szFileName.detach(); if(KviFileUtils::isAbsolutePath(szPath) && KviFileUtils::fileExists(szPath)) { // Ok, return true; - } else { + } + else + { //Plugin not found in direct way. Looking in kvirc local dir - g_pApp->getGlobalKvircDirectory(szPath,KviApplication::EasyPlugins,szFileName); + g_pApp->getGlobalKvircDirectory(szPath, KviApplication::EasyPlugins, szFileName); if(!KviFileUtils::fileExists(szPath)) { //Plugin not found in kvirc local dir. Looking in kvirc global dir - g_pApp->getLocalKvircDirectory(szPath,KviApplication::EasyPlugins,szFileName); + g_pApp->getLocalKvircDirectory(szPath, KviApplication::EasyPlugins, szFileName); if(!KviFileUtils::fileExists(szPath)) { @@ -390,32 +401,34 @@ bool PluginManager::findPlugin(QString& szPath) return true; } -bool PluginManager::isPluginLoaded(const QString& pSingleName) +bool PluginManager::isPluginLoaded(const QString & pSingleName) { Plugin * p = m_pPluginDict->find(pSingleName); - if (!p) + if(!p) return false; else return true; } -bool PluginManager::loadPlugin(const QString& szPluginPath) +bool PluginManager::loadPlugin(const QString & szPluginPath) { if(isPluginLoaded(szPluginPath)) { - return getPlugin(szPluginPath)!=0; - } else { + return getPlugin(szPluginPath) != 0; + } + else + { Plugin * plugin = Plugin::load(szPluginPath); if(plugin) { - m_pPluginDict->insert(szPluginPath,plugin); + m_pPluginDict->insert(szPluginPath, plugin); return true; } } return false; } -Plugin * PluginManager::getPlugin(const QString& szPluginPath) +Plugin * PluginManager::getPlugin(const QString & szPluginPath) { Plugin * p = m_pPluginDict->find(szPluginPath); return p; diff --git a/src/modules/system/Plugin.h b/src/modules/system/Plugin.h index 749d58a70..bbf46ce12 100644 --- a/src/modules/system/Plugin.h +++ b/src/modules/system/Plugin.h @@ -29,7 +29,7 @@ #include "KviPointerHashTable.h" #include <QLibrary> -typedef int (*plugin_function)(int argc, char* argv[], char ** buffer); +typedef int (*plugin_function)(int argc, char * argv[], char ** buffer); typedef int (*plugin_unload)(); typedef int (*plugin_canunload)(); typedef int (*plugin_load)(); @@ -39,44 +39,51 @@ class Plugin { protected: // You have to create plugin instance by calling Plugin::load() - Plugin(QLibrary * pLibrary,const QString& name); + Plugin(QLibrary * pLibrary, const QString & name); + public: ~Plugin(); + private: // shared // internal - QLibrary *m_pLibrary; - QString m_szName; + QLibrary * m_pLibrary; + QString m_szName; + public: - static Plugin* load(const QString& szFileName); + static Plugin * load(const QString & szFileName); bool pfree(char * pBuffer); bool unload(); bool canunload(); - int call(const QString& szFunctionName, int argc, char * argv[], char ** pBuffer); + int call(const QString & szFunctionName, int argc, char * argv[], char ** pBuffer); QString name() const; - void setName(const QString& szName); + void setName(const QString & szName); + protected: }; class PluginManager { - public: - PluginManager(); - ~PluginManager(); - private: - // shared - bool m_bCanUnload; - // internal - KviPointerHashTable<QString,Plugin> * m_pPluginDict; - public: - bool pluginCall(KviKvsModuleFunctionCall *c); - bool checkUnload(); - void unloadAll(); - protected: - bool findPlugin(QString& szName); - bool isPluginLoaded(const QString& szFileNameOrPathToLoad); - bool loadPlugin(const QString& szPluginPath); - Plugin * getPlugin(const QString& szPluginPath); +public: + PluginManager(); + ~PluginManager(); + +private: + // shared + bool m_bCanUnload; + // internal + KviPointerHashTable<QString, Plugin> * m_pPluginDict; + +public: + bool pluginCall(KviKvsModuleFunctionCall * c); + bool checkUnload(); + void unloadAll(); + +protected: + bool findPlugin(QString & szName); + bool isPluginLoaded(const QString & szFileNameOrPathToLoad); + bool loadPlugin(const QString & szPluginPath); + Plugin * getPlugin(const QString & szPluginPath); }; #endif //_PLUGIN_H_ diff --git a/src/modules/system/libkvisystem.cpp b/src/modules/system/libkvisystem.cpp index b162b6820..9404b5a26 100644 --- a/src/modules/system/libkvisystem.cpp +++ b/src/modules/system/libkvisystem.cpp @@ -40,21 +40,21 @@ #include <QByteArray> #if !defined(COMPILE_ON_WINDOWS) && !defined(COMPILE_ON_MINGW) - #include <sys/utsname.h> - #include <stdlib.h> - #include <unistd.h> +#include <sys/utsname.h> +#include <stdlib.h> +#include <unistd.h> #endif #ifdef COMPILE_DBUS_SUPPORT - #include <QtDBus/QtDBus> +#include <QtDBus/QtDBus> #endif #ifdef COMPILE_KDE_SUPPORT - #include <KToolInvocation> // invokeTerminal() for system.runcmd -#else // tools we need to work around the absence of - // invokeTerminal() - #include <QProcess> - #include <QStringList> +#include <KToolInvocation> // invokeTerminal() for system.runcmd +#else // tools we need to work around the absence of +// invokeTerminal() +#include <QProcess> +#include <QStringList> #endif PluginManager * g_pPluginManager; @@ -94,13 +94,12 @@ static bool system_kvs_fnc_ostype(KviKvsModuleFunctionCall * c) the uname() syscall. */ -static bool system_kvs_fnc_osname(KviKvsModuleFunctionCall *c) +static bool system_kvs_fnc_osname(KviKvsModuleFunctionCall * c) { c->returnValue()->setString(KviRuntimeInfo::name()); return true; } - /* @doc: system.osversion @type: @@ -115,7 +114,7 @@ static bool system_kvs_fnc_osname(KviKvsModuleFunctionCall *c) Returns the version of the operating system.[br] */ -static bool system_kvs_fnc_osversion(KviKvsModuleFunctionCall *c) +static bool system_kvs_fnc_osversion(KviKvsModuleFunctionCall * c) { // no params to process c->returnValue()->setString(KviRuntimeInfo::version()); @@ -136,7 +135,7 @@ static bool system_kvs_fnc_osversion(KviKvsModuleFunctionCall *c) Returns the release of the operating system.[br] */ -static bool system_kvs_fnc_osrelease(KviKvsModuleFunctionCall *c) +static bool system_kvs_fnc_osrelease(KviKvsModuleFunctionCall * c) { // no params to process c->returnValue()->setString(KviRuntimeInfo::release()); @@ -157,7 +156,7 @@ static bool system_kvs_fnc_osrelease(KviKvsModuleFunctionCall *c) Returns the machine of the operating system.[br] */ -static bool system_kvs_fnc_osmachine(KviKvsModuleFunctionCall *c) +static bool system_kvs_fnc_osmachine(KviKvsModuleFunctionCall * c) { // no params to process c->returnValue()->setString(KviRuntimeInfo::machine()); @@ -178,7 +177,7 @@ static bool system_kvs_fnc_osmachine(KviKvsModuleFunctionCall *c) Returns the nodename of the operating system.[br] */ -static bool system_kvs_fnc_osnodename(KviKvsModuleFunctionCall *c) +static bool system_kvs_fnc_osnodename(KviKvsModuleFunctionCall * c) { // no params to process c->returnValue()->setString(KviRuntimeInfo::nodename()); @@ -201,16 +200,16 @@ static bool system_kvs_fnc_osnodename(KviKvsModuleFunctionCall *c) Returns the value of the environment <variable>.[br] */ -static bool system_kvs_fnc_getenv(KviKvsModuleFunctionCall *c) +static bool system_kvs_fnc_getenv(KviKvsModuleFunctionCall * c) { QString szVariable; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("variable",KVS_PT_NONEMPTYSTRING,0,szVariable) + KVSM_PARAMETER("variable", KVS_PT_NONEMPTYSTRING, 0, szVariable) KVSM_PARAMETERS_END(c) QByteArray szVar = szVariable.toLocal8Bit(); -/*#ifdef COMPILE_ON_WINDOWS + /*#ifdef COMPILE_ON_WINDOWS QString env= getenv(szVar.data()); QString def= __tr2qs("No environment variable found, please don't use the %% in the request"); c->returnValue()->setString(env.isEmpty() ? QString::fromLocal8Bit(env) : QString::fromLocal8Bit(def)); @@ -218,7 +217,7 @@ static bool system_kvs_fnc_getenv(KviKvsModuleFunctionCall *c) */ char * b = KviEnvironment::getVariable(szVar.data()); c->returnValue()->setString(b ? QString::fromLocal8Bit(b) : QString()); -//#endif + //#endif return true; } @@ -245,13 +244,12 @@ static bool system_kvs_fnc_getenv(KviKvsModuleFunctionCall *c) [cmd]system.setSelection[/cmd] */ -static bool system_kvs_fnc_clipboard(KviKvsModuleFunctionCall *c) +static bool system_kvs_fnc_clipboard(KviKvsModuleFunctionCall * c) { c->returnValue()->setString(g_pApp->clipboard()->text(QClipboard::Clipboard)); return true; } - /* @doc: system.setClipboard @type: @@ -280,9 +278,9 @@ static bool system_kvs_cmd_setClipboard(KviKvsModuleCommandCall * c) QString szValue; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("data",KVS_PT_STRING,KVS_PF_OPTIONAL,szValue) + KVSM_PARAMETER("data", KVS_PT_STRING, KVS_PF_OPTIONAL, szValue) KVSM_PARAMETERS_END(c) - g_pApp->clipboard()->setText(szValue,QClipboard::Clipboard); + g_pApp->clipboard()->setText(szValue, QClipboard::Clipboard); return true; } @@ -312,9 +310,9 @@ static bool system_kvs_cmd_setSelection(KviKvsModuleCommandCall * c) { QString szValue; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("data",KVS_PT_STRING,KVS_PF_OPTIONAL,szValue) + KVSM_PARAMETER("data", KVS_PT_STRING, KVS_PF_OPTIONAL, szValue) KVSM_PARAMETERS_END(c) - g_pApp->clipboard()->setText(szValue,QClipboard::Selection); + g_pApp->clipboard()->setText(szValue, QClipboard::Selection); return true; } @@ -342,13 +340,12 @@ static bool system_kvs_cmd_setSelection(KviKvsModuleCommandCall * c) [cmd]system.setSelection[/cmd] */ -static bool system_kvs_fnc_selection(KviKvsModuleFunctionCall *c) +static bool system_kvs_fnc_selection(KviKvsModuleFunctionCall * c) { c->returnValue()->setString(g_pApp->clipboard()->text(QClipboard::Selection)); return true; } - /* @doc: system.checkModule @keyterms: @@ -369,19 +366,18 @@ static bool system_kvs_fnc_selection(KviKvsModuleFunctionCall *c) KVIrc engine. */ -static bool system_kvs_fnc_checkModule(KviKvsModuleFunctionCall *c) +static bool system_kvs_fnc_checkModule(KviKvsModuleFunctionCall * c) { QString szModuleName; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("module_name",KVS_PT_STRING,0,szModuleName) + KVSM_PARAMETER("module_name", KVS_PT_STRING, 0, szModuleName) KVSM_PARAMETERS_END(c) c->returnValue()->setBoolean(g_pModuleManager->loadModule(szModuleName)); return true; } - /* @doc: system.hostname @keyterms: @@ -398,14 +394,13 @@ static bool system_kvs_fnc_checkModule(KviKvsModuleFunctionCall *c) Returns the hostname of the machine that KVIrc is running on.[br] */ -static bool system_kvs_fnc_hostname(KviKvsModuleFunctionCall *c) +static bool system_kvs_fnc_hostname(KviKvsModuleFunctionCall * c) { // no params to process c->returnValue()->setString(KviRuntimeInfo::hostname()); return true; } - /* @doc: system.dbus @keyterms: @@ -454,19 +449,19 @@ static bool system_kvs_fnc_hostname(KviKvsModuleFunctionCall *c) [/example] */ -static bool system_kvs_fnc_dbus(KviKvsModuleFunctionCall *c) +static bool system_kvs_fnc_dbus(KviKvsModuleFunctionCall * c) { QString szService, szPath, szInterface, szMethod, szBusType; QStringList parms; - bool bRemoteTest=false; + bool bRemoteTest = false; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("service",KVS_PT_NONEMPTYSTRING,0,szService) - KVSM_PARAMETER("path",KVS_PT_NONEMPTYSTRING,0,szPath) - KVSM_PARAMETER("interface",KVS_PT_NONEMPTYSTRING,0,szInterface) - KVSM_PARAMETER("method",KVS_PT_NONEMPTYSTRING,0,szMethod) - KVSM_PARAMETER("bus_type",KVS_PT_STRING,KVS_PF_OPTIONAL,szBusType) - KVSM_PARAMETER("parameter_list",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,parms) + KVSM_PARAMETER("service", KVS_PT_NONEMPTYSTRING, 0, szService) + KVSM_PARAMETER("path", KVS_PT_NONEMPTYSTRING, 0, szPath) + KVSM_PARAMETER("interface", KVS_PT_NONEMPTYSTRING, 0, szInterface) + KVSM_PARAMETER("method", KVS_PT_NONEMPTYSTRING, 0, szMethod) + KVSM_PARAMETER("bus_type", KVS_PT_STRING, KVS_PF_OPTIONAL, szBusType) + KVSM_PARAMETER("parameter_list", KVS_PT_STRINGLIST, KVS_PF_OPTIONAL, parms) KVSM_PARAMETERS_END(c) #ifdef COMPILE_DBUS_SUPPORT @@ -479,17 +474,21 @@ static bool system_kvs_fnc_dbus(KviKvsModuleFunctionCall *c) if(szBusType == "system") { busType = QDBusConnection::systemBus(); - } else if(szBusType == "session"){ + } + else if(szBusType == "session") + { busType = QDBusConnection::sessionBus(); - } else { + } + else + { c->warning(__tr2qs("No DBus type specified")); return false; } - if(szService.left(1).compare("?")==0) + if(szService.left(1).compare("?") == 0) { - szService.remove(0,1); - bRemoteTest=true; + szService.remove(0, 1); + bRemoteTest = true; } QDBusInterface remoteApp(szService, szPath, szInterface, busType); @@ -499,7 +498,9 @@ static bool system_kvs_fnc_dbus(KviKvsModuleFunctionCall *c) { c->returnValue()->setInteger(0); return true; - } else { + } + else + { c->warning(__tr2qs("Invalid D-Bus interface")); return false; } @@ -513,7 +514,7 @@ static bool system_kvs_fnc_dbus(KviKvsModuleFunctionCall *c) QList<QVariant> ds; - for ( QStringList::Iterator it = parms.begin(); it != parms.end(); ++it ) + for(QStringList::Iterator it = parms.begin(); it != parms.end(); ++it) { KviCString tmp = *it; @@ -523,11 +524,12 @@ static bool system_kvs_fnc_dbus(KviKvsModuleFunctionCall *c) return false; } - KviCString szType = tmp.leftToFirst('=',false); - tmp.cutToFirst('=',true); - if(szType.isEmpty())szType = "int"; + KviCString szType = tmp.leftToFirst('=', false); + tmp.cutToFirst('=', true); + if(szType.isEmpty()) + szType = "int"; bool bOk; - if(kvi_strEqualCI("int",szType.ptr()) || kvi_strEqualCI("long",szType.ptr())) + if(kvi_strEqualCI("int", szType.ptr()) || kvi_strEqualCI("long", szType.ptr())) { int iii = tmp.toInt(&bOk); if(!bOk) @@ -536,19 +538,23 @@ static bool system_kvs_fnc_dbus(KviKvsModuleFunctionCall *c) return false; } ds << iii; - } else if(kvi_strEqualCI("QString",szType.ptr())) + } + else if(kvi_strEqualCI("QString", szType.ptr())) { QString ddd = tmp.ptr(); ds << ddd; - } else if(kvi_strEqualCI("QByteArray",szType.ptr())) + } + else if(kvi_strEqualCI("QByteArray", szType.ptr())) { QByteArray qcs = tmp.ptr(); ds << qcs; - } else if(kvi_strEqualCI("bool",szType.ptr())) + } + else if(kvi_strEqualCI("bool", szType.ptr())) { - bool bbb = kvi_strEqualCI(tmp.ptr(),"true"); + bool bbb = kvi_strEqualCI(tmp.ptr(), "true"); ds << bbb; - } else if(kvi_strEqualCI("unsigned int",szType.ptr()) || kvi_strEqualCI("uint",szType.ptr()) || kvi_strEqualCI("Q_UINT32",szType.ptr())) + } + else if(kvi_strEqualCI("unsigned int", szType.ptr()) || kvi_strEqualCI("uint", szType.ptr()) || kvi_strEqualCI("Q_UINT32", szType.ptr())) { unsigned int uii = tmp.toUInt(&bOk); if(!bOk) @@ -557,23 +563,26 @@ static bool system_kvs_fnc_dbus(KviKvsModuleFunctionCall *c) return false; } ds << uii; - } else { - c->warning(__tr2qs("Unsupported D-Bus parameter type %s"),tmp.ptr()); + } + else + { + c->warning(__tr2qs("Unsupported D-Bus parameter type %s"), tmp.ptr()); return false; } } QDBusMessage reply = remoteApp.callWithArgumentList(QDBus::Block, szMethod, ds); - if (reply.type() == QDBusMessage::ErrorMessage) + if(reply.type() == QDBusMessage::ErrorMessage) { QDBusError err = reply; - c->warning(__tr2qs("The D-Bus call returned an error \"%s\": %s"),qPrintable(err.name()), qPrintable(err.message())); + c->warning(__tr2qs("The D-Bus call returned an error \"%s\": %s"), qPrintable(err.name()), qPrintable(err.message())); return false; } QString szRetType; - foreach (QVariant v, reply.arguments()) { + foreach(QVariant v, reply.arguments()) + { switch(v.type()) { case QVariant::Bool: @@ -596,9 +605,9 @@ static bool system_kvs_fnc_dbus(KviKvsModuleFunctionCall *c) QStringList csl(v.toStringList()); KviKvsArray * arry = new KviKvsArray(); int idx = 0; - for(QStringList::Iterator iter = csl.begin();iter != csl.end();++iter) + for(QStringList::Iterator iter = csl.begin(); iter != csl.end(); ++iter) { - arry->set(idx,new KviKvsVariant(*iter)); + arry->set(idx, new KviKvsVariant(*iter)); idx++; } c->returnValue()->setArray(arry); @@ -609,18 +618,17 @@ static bool system_kvs_fnc_dbus(KviKvsModuleFunctionCall *c) c->returnValue()->setString(""); break; default: - c->warning(__tr2qs("Unsupported D-Bus call return type %s"),v.typeName()); + c->warning(__tr2qs("Unsupported D-Bus call return type %s"), v.typeName()); break; } } #else - c->warning(__tr2qs("D-Bus calls are available only under UNIX")); + c->warning(__tr2qs("D-Bus calls are available only under UNIX")); #endif return true; } - /* @doc: system.setenv @type: @@ -640,31 +648,31 @@ static bool system_kvs_fnc_dbus(KviKvsModuleFunctionCall *c) [fnc]$system.getenv[/fnc] */ - static bool system_kvs_cmd_setenv(KviKvsModuleCommandCall * c) { - QString szVariable,szValue; + QString szVariable, szValue; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("variable",KVS_PT_NONEMPTYSTRING,0,szVariable) - KVSM_PARAMETER("value",KVS_PT_STRING,KVS_PF_OPTIONAL,szValue) + KVSM_PARAMETER("variable", KVS_PT_NONEMPTYSTRING, 0, szVariable) + KVSM_PARAMETER("value", KVS_PT_STRING, KVS_PF_OPTIONAL, szValue) KVSM_PARAMETERS_END(c) QByteArray szVar = szVariable.toLocal8Bit(); QByteArray szVal = szValue.toLocal8Bit(); - if(szVal.isEmpty())KviEnvironment::unsetVariable(szVar.data()); + if(szVal.isEmpty()) + KviEnvironment::unsetVariable(szVar.data()); else { -/*#ifdef COMPILE_ON_WINDOWS + /*#ifdef COMPILE_ON_WINDOWS QString Var,Val,VarAndVal; Val = szVar.data(); Var = szVal.data(); VarAndVal = Var+"="+Val; putenv(VarAndVal); #else*/ // <-- this stuff is implicit in KviEnvironment::setVariable: that's why we have the kvi_ version. - KviEnvironment::setVariable(szVar.data(),szVal.data()); -/*#endif*/ + KviEnvironment::setVariable(szVar.data(), szVal.data()); + /*#endif*/ } return true; } @@ -708,8 +716,7 @@ static bool system_kvs_cmd_setenv(KviKvsModuleCommandCall * c) [/example] */ - -static bool system_kvs_fnc_plugin_call(KviKvsModuleFunctionCall *c) +static bool system_kvs_fnc_plugin_call(KviKvsModuleFunctionCall * c) { return g_pPluginManager->pluginCall(c); } @@ -741,12 +748,12 @@ static bool system_kvs_fnc_plugin_call(KviKvsModuleFunctionCall *c) [/example] */ // implements https://github.com/kvirc/KVIrc/issues/459 -static bool system_kvs_cmd_runcmd(KviKvsModuleCommandCall *c) +static bool system_kvs_cmd_runcmd(KviKvsModuleCommandCall * c) { QString szCommand; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("command",KVS_PT_NONEMPTYSTRING,KVS_PF_APPENDREMAINING,szCommand) + KVSM_PARAMETER("command", KVS_PT_NONEMPTYSTRING, KVS_PF_APPENDREMAINING, szCommand) KVSM_PARAMETERS_END(c) if(szCommand.isEmpty()) @@ -756,7 +763,7 @@ static bool system_kvs_cmd_runcmd(KviKvsModuleCommandCall *c) QStringList args; QProcess oProc; -#if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) // Only »cmd.exe /k« in the list. +#if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) // Only »cmd.exe /k« in the list. args << "/k" << szCommand; #elif defined(COMPILE_ON_MAC) args << "-e" << QString("tell application \"Terminal\" to do script \"%1\"").arg(szCommand); @@ -764,23 +771,21 @@ static bool system_kvs_cmd_runcmd(KviKvsModuleCommandCall *c) args << "-e" << szCommand; #endif // endif COMPILE_ON_WINDOWS - if(c->switches()->getAsStringIfExisting('t',"terminal",szTerminal)) + if(c->switches()->getAsStringIfExisting('t', "terminal", szTerminal)) { - if(!oProc.startDetached(szTerminal,args)) + if(!oProc.startDetached(szTerminal, args)) return c->error(__tr2qs("Failed to start the terminal program")); return true; } - - -#ifdef COMPILE_KDE_SUPPORT // We have invokeTerminal(). +#ifdef COMPILE_KDE_SUPPORT // We have invokeTerminal(). KToolInvocation::invokeTerminal(szCommand.toLocal8Bit()); -#else // No invokeTerminal() for us, we'll use a - // combination of QStringList and QProcess. +#else // No invokeTerminal() for us, we'll use a + // combination of QStringList and QProcess. QStringList szTerminals; -#if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) // Only »cmd.exe /k« in the list. +#if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) // Only »cmd.exe /k« in the list. szTerminals.append("cmd.exe"); #elif defined(COMPILE_ON_MAC) szTerminals.append("osascript"); @@ -791,16 +796,16 @@ static bool system_kvs_cmd_runcmd(KviKvsModuleCommandCall *c) szTerminals.append("x-terminal-emulator"); szTerminals.append("terminal"); szTerminals.append("xterm"); -#endif // endif COMPILE_ON_WINDOWS +#endif // endif COMPILE_ON_WINDOWS QString szTerm; while(!szTerminals.isEmpty()) { - szTerm=szTerminals.takeFirst(); + szTerm = szTerminals.takeFirst(); if(oProc.startDetached(szTerm, args)) return true; } -#endif // endif COMPILE_KDE_SUPPORT +#endif // endif COMPILE_KDE_SUPPORT return c->error(__tr2qs("Failed to start the terminal program")); } @@ -831,36 +836,35 @@ static bool system_kvs_fnc_ntohi(KviKvsModuleFunctionCall * c) kvs_uint_t uBytes; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("value",KVS_PT_INT,0,iValue) - KVSM_PARAMETER("bytecount",KVS_PT_UINT,KVS_PF_OPTIONAL,uBytes) + KVSM_PARAMETER("value", KVS_PT_INT, 0, iValue) + KVSM_PARAMETER("bytecount", KVS_PT_UINT, KVS_PF_OPTIONAL, uBytes) KVSM_PARAMETERS_END(c) switch(uBytes) { case 0: c->returnValue()->setInteger((kvs_int_t)KviByteOrder::networkByteOrderToLocalCpu32((kvi_u32_t)iValue)); - break; + break; case 1: c->returnValue()->setInteger((kvs_int_t)((kvi_u8_t)iValue)); - break; + break; case 2: c->returnValue()->setInteger((kvs_int_t)KviByteOrder::networkByteOrderToLocalCpu16((kvi_u16_t)iValue)); - break; + break; case 4: c->returnValue()->setInteger((kvs_int_t)KviByteOrder::networkByteOrderToLocalCpu32((kvi_u32_t)iValue)); - break; + break; case 8: c->returnValue()->setInteger((kvs_int_t)KviByteOrder::networkByteOrderToLocalCpu64((kvi_u64_t)iValue)); - break; + break; default: return c->error(__tr2qs("Bad bytecount specification: 1, 2, 4 and 8 are allowed")); - break; + break; } return true; } - /* @doc: system.htoni @type: @@ -887,30 +891,30 @@ static bool system_kvs_fnc_htoni(KviKvsModuleFunctionCall * c) kvs_uint_t uBytes; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("value",KVS_PT_INT,0,iValue) - KVSM_PARAMETER("bytecount",KVS_PT_UINT,KVS_PF_OPTIONAL,uBytes) + KVSM_PARAMETER("value", KVS_PT_INT, 0, iValue) + KVSM_PARAMETER("bytecount", KVS_PT_UINT, KVS_PF_OPTIONAL, uBytes) KVSM_PARAMETERS_END(c) switch(uBytes) { case 0: c->returnValue()->setInteger((kvs_int_t)KviByteOrder::localCpuToNetworkByteOrder32((kvi_u32_t)iValue)); - break; + break; case 1: c->returnValue()->setInteger((kvs_int_t)((kvi_u8_t)iValue)); - break; + break; case 2: c->returnValue()->setInteger((kvs_int_t)KviByteOrder::localCpuToNetworkByteOrder16((kvi_u16_t)iValue)); - break; + break; case 4: c->returnValue()->setInteger((kvs_int_t)KviByteOrder::localCpuToNetworkByteOrder32((kvi_u32_t)iValue)); - break; + break; case 8: c->returnValue()->setInteger((kvs_int_t)KviByteOrder::localCpuToNetworkByteOrder64((kvi_u64_t)iValue)); - break; + break; default: return c->error(__tr2qs("Bad bytecount specification: 1, 2, 4 and 8 are allowed")); - break; + break; } return true; @@ -918,26 +922,26 @@ static bool system_kvs_fnc_htoni(KviKvsModuleFunctionCall * c) static bool system_module_init(KviModule * m) { - KVSM_REGISTER_FUNCTION(m,"ostype",system_kvs_fnc_ostype); - KVSM_REGISTER_FUNCTION(m,"osname",system_kvs_fnc_osname); - KVSM_REGISTER_FUNCTION(m,"osversion",system_kvs_fnc_osversion); - KVSM_REGISTER_FUNCTION(m,"osrelease",system_kvs_fnc_osrelease); - KVSM_REGISTER_FUNCTION(m,"osmachine",system_kvs_fnc_osmachine); - 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,"dbus",system_kvs_fnc_dbus); - KVSM_REGISTER_FUNCTION(m,"htoni",system_kvs_fnc_htoni); - KVSM_REGISTER_FUNCTION(m,"ntohi",system_kvs_fnc_ntohi); - 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); - KVSM_REGISTER_FUNCTION(m,"call",system_kvs_fnc_plugin_call); + KVSM_REGISTER_FUNCTION(m, "ostype", system_kvs_fnc_ostype); + KVSM_REGISTER_FUNCTION(m, "osname", system_kvs_fnc_osname); + KVSM_REGISTER_FUNCTION(m, "osversion", system_kvs_fnc_osversion); + KVSM_REGISTER_FUNCTION(m, "osrelease", system_kvs_fnc_osrelease); + KVSM_REGISTER_FUNCTION(m, "osmachine", system_kvs_fnc_osmachine); + 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, "dbus", system_kvs_fnc_dbus); + KVSM_REGISTER_FUNCTION(m, "htoni", system_kvs_fnc_htoni); + KVSM_REGISTER_FUNCTION(m, "ntohi", system_kvs_fnc_ntohi); + 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); + KVSM_REGISTER_FUNCTION(m, "call", system_kvs_fnc_plugin_call); - KVSM_REGISTER_SIMPLE_COMMAND(m,"setenv",system_kvs_cmd_setenv); - KVSM_REGISTER_SIMPLE_COMMAND(m,"setClipboard",system_kvs_cmd_setClipboard); - KVSM_REGISTER_SIMPLE_COMMAND(m,"setSelection",system_kvs_cmd_setSelection); - KVSM_REGISTER_SIMPLE_COMMAND(m,"runcmd",system_kvs_cmd_runcmd); + KVSM_REGISTER_SIMPLE_COMMAND(m, "setenv", system_kvs_cmd_setenv); + KVSM_REGISTER_SIMPLE_COMMAND(m, "setClipboard", system_kvs_cmd_setClipboard); + KVSM_REGISTER_SIMPLE_COMMAND(m, "setSelection", system_kvs_cmd_setSelection); + KVSM_REGISTER_SIMPLE_COMMAND(m, "runcmd", system_kvs_cmd_runcmd); g_pPluginManager = new(PluginManager); @@ -953,20 +957,20 @@ static bool system_module_cleanup(KviModule *) static bool system_module_can_unload(KviModule *) { - if(!g_pPluginManager->checkUnload()) return false; + if(!g_pPluginManager->checkUnload()) + return false; return true; } KVIRC_MODULE( - "System", // module name - "4.0.0", // module version - "Copyright (C) 2001 Szymon Stefanek (pragma at kvirc dot net)" \ - " (C) 2005 Tonino Imbesi (grifisx at barmes dot org)"\ - " (C) 2005 Alessandro Carbone (elfonol at gmail dot com)",// author & (C) - "System information module", - system_module_init, - system_module_can_unload, - 0, - system_module_cleanup, - 0 -) + "System", // module name + "4.0.0", // module version + "Copyright (C) 2001 Szymon Stefanek (pragma at kvirc dot net)" + " (C) 2005 Tonino Imbesi (grifisx at barmes dot org)" + " (C) 2005 Alessandro Carbone (elfonol at gmail dot com)", // author & (C) + "System information module", + system_module_init, + system_module_can_unload, + 0, + system_module_cleanup, + 0) |
