diff options
| author | 2009-06-02 10:03:27 +0000 | |
|---|---|---|
| committer | 2009-06-02 10:03:27 +0000 | |
| commit | 166fe30e822380eda72f12659d72a520ec791bdc (patch) | |
| tree | c3346088eae92c02239c54ef2ae494ba3d5ebe2b | |
| parent | added missing macro, should fix #461 (diff) | |
| download | KVIrc-166fe30e822380eda72f12659d72a520ec791bdc.tar.gz KVIrc-166fe30e822380eda72f12659d72a520ec791bdc.tar.bz2 KVIrc-166fe30e822380eda72f12659d72a520ec791bdc.zip | |
applied patch for #459, reworked it a bit. thanks goes to Kai Wasserbäch
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@3236 17fca916-40b9-46aa-a4ea-0a15b648b75c
| -rw-r--r-- | data/defscript/popups.kvs | 19 | ||||
| -rw-r--r-- | src/modules/system/libkvisystem.cpp | 72 |
2 files changed, 80 insertions, 11 deletions
diff --git a/data/defscript/popups.kvs b/data/defscript/popups.kvs index 5039fe912..6d0869ab0 100644 --- a/data/defscript/popups.kvs +++ b/data/defscript/popups.kvs @@ -1371,33 +1371,30 @@ defpopup(hostpopup) item(Telnet to $0,25) { - if("$system.ostype" == "unix")run xterm -e telnet $0 - else run telnet $0 + system.runcmd telnet $0 } separator item(Traceroute $0,42) { - if("$system.ostype" == "unix")run xterm -e /bin/sh -c "echo \"Traceroute to $0...\" && traceroute $0 && cat" - else run tracert $0 + if("$system.ostype" == "unix")system.runcmd /bin/sh -c "echo \"Traceroute to $0...\" && traceroute $0" + else system.runcmd tracert $0 } item(Traceroute6 $0,42) { - if("$system.ostype" == "unix")run xterm -e /bin/sh -c "echo \"Traceroute (inet6) to $0...\" && traceroute6 $0 && cat" - else run tracert6 $0 + if("$system.ostype" == "unix")system.runcmd /bin/sh -c "echo \"Traceroute (inet6) to $0...\" && traceroute6 $0" + else system.runcmd tracert6 $0 } item(Ping $0,147) { - if("$system.ostype" == "unix")run xterm -e /bin/sh -c "echo \"Ping $0...\" && ping $0 && cat" - else run ping $0 + system.runcmd ping $0 } item(Ping6 $0,147) { - if("$system.ostype" == "unix")run xterm -e /bin/sh -c "echo \"Ping (inet6) $0...\" && ping6 $0 && cat" - else run ping6 $0 + system.runcmd ping6 $0 } -}
\ No newline at end of file +} diff --git a/src/modules/system/libkvisystem.cpp b/src/modules/system/libkvisystem.cpp index 2f598ccb2..26eea0a9f 100644 --- a/src/modules/system/libkvisystem.cpp +++ b/src/modules/system/libkvisystem.cpp @@ -5,6 +5,7 @@ // // This system is part of the KVirc irc client distribution // Copyright (C) 2001-2008 Szymon Stefanek (pragma at kvirc dot net) +// Copyright © 2009 Kai Wasserbäch <debian@carbon-project.org> // // This program is FREE software. You can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -46,6 +47,11 @@ #ifdef COMPILE_KDE_SUPPORT #include <QtDBus/QtDBus> + #include <KToolInvocation> // invokeTerminal() for system.runcmd +#else // tools we need to work around the absence of + // invokeTerminal() + #include <QProcess> + #include <QList> #endif KviPluginManager * g_pPluginManager; @@ -668,6 +674,71 @@ static bool system_kvs_fnc_plugin_call(KviKvsModuleFunctionCall *c) return g_pPluginManager->pluginCall(c); } +/* + @doc: system.runcmd + @type: + command + @title: + system.runcmd + @short: + Runs the specified command in a terminal + @syntax: + system.runcmd <command:string> + @description: + Tries to run the given command in the system's default (X) + terminal (emulator). + [br] + [br] + [b]Warning: Execute only harmless commands through this![/b] + @examples: + [example] + system.runcmd "ping $0" + [/example] +*/ +// implements https://svn.kvirc.de/kvirc/ticket/459 +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_PARAMETERS_END(c) + + // check for empty szCommand + if(!szCommand.isEmpty()) + { + KviQCString szCmd = szCommand.toLocal8Bit(); +#ifdef COMPILE_KDE_SUPPORT // We have invokeTerminal(). + KToolInvocation::invokeTerminal(szCmd.data()); +#else // No invokeTerminal() for us, we'll use a + // combination of QList and QProcess. + + QProcess oProc; + QStringList args; + QStringList szTerminals; +#ifdef COMPILE_ON_WINDOWS // Only »cmd.exe /k« in the list. + szTerminals.append("cmd.exe"); + args << "/k" << szCommand; +#else + // List: x-terminal-emulator, terminal, xterm + szTerminals.append("x-terminal-emulator"); + szTerminals.append("terminal"); + szTerminals.append("xterm"); + args << "-e" << szCommand; +#endif // endif COMPILE_ON_WINDOWS + + QString szTerm; + while(!szTerminals.isEmpty()) + { + szTerm=szTerminals.takeFirst(); + if (oProc.startDetached(szTerm, args)) + break; + } +#endif // endif COMPILE_KDE_SUPPORT + } + return true; +} + static bool system_module_init(KviModule * m) { KVSM_REGISTER_FUNCTION(m,"ostype",system_kvs_fnc_ostype); @@ -687,6 +758,7 @@ static bool system_module_init(KviModule * m) 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(KviPluginManager); |
