diff options
| author | 2011-12-21 05:07:19 +0000 | |
|---|---|---|
| committer | 2011-12-21 05:07:19 +0000 | |
| commit | 3ef15468104c2b18e62254d1c8af91f3de5c6140 (patch) | |
| tree | 019f6325874725bd8140ae0008d6124807a236d1 /src/modules/system/libkvisystem.cpp | |
| parent | Allow STARTTLS to be used also without CAP support. (diff) | |
| download | KVIrc-3ef15468104c2b18e62254d1c8af91f3de5c6140.tar.gz KVIrc-3ef15468104c2b18e62254d1c8af91f3de5c6140.tar.bz2 KVIrc-3ef15468104c2b18e62254d1c8af91f3de5c6140.zip | |
Add a -t switch to system.runcmd so a terminal can be explicitly provided
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@5998 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src/modules/system/libkvisystem.cpp')
| -rw-r--r-- | src/modules/system/libkvisystem.cpp | 98 |
1 files changed, 59 insertions, 39 deletions
diff --git a/src/modules/system/libkvisystem.cpp b/src/modules/system/libkvisystem.cpp index ca5ed1149..c174f5158 100644 --- a/src/modules/system/libkvisystem.cpp +++ b/src/modules/system/libkvisystem.cpp @@ -714,21 +714,26 @@ static bool system_kvs_fnc_plugin_call(KviKvsModuleFunctionCall *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] + @doc: system.runcmd + @type: + command + @title: + system.runcmd + @short: + Runs the specified command in a terminal + @syntax: + system.runcmd [-t <terminal:string>] <command:string> + @switches: + !sw: -t=<terminal> | --terminal=<terminal> + Use the specified terminal to launch the command instead + of the auto-detected one. + @description: + Tries to run the given command in the system's default (X) + terminal (emulator) or in the terminal specified by the -t + option. + [br] + [br] + [b]Warning: Execute only harmless commands through this![/b] @examples: [example] system.runcmd "ping $0" @@ -743,39 +748,54 @@ static bool system_kvs_cmd_runcmd(KviKvsModuleCommandCall *c) KVSM_PARAMETER("command",KVS_PT_NONEMPTYSTRING,KVS_PF_APPENDREMAINING,szCommand) KVSM_PARAMETERS_END(c) - // check for empty szCommand - if(!szCommand.isEmpty()) + if(szCommand.isEmpty()) + return c->error(__tr2qs("No command specified")); + + QString szTerminal; + QStringList args; + +#if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) // Only »cmd.exe /k« in the list. + args << "/k" << szCommand; +#else + args << "-e" << szCommand; +#endif // endif COMPILE_ON_WINDOWS + + if(c->switches()->getAsStringIfExisting('t',"terminal",szTerminal)) { - QByteArray szCmd = szCommand.toLocal8Bit(); + QProcess oProc; + if(!oProc.startDetached(szTerminal,args)) + return c->error(__tr2qs("Failed to start the terminal program")); + return true; + } + + + #ifdef COMPILE_KDE_SUPPORT // We have invokeTerminal(). - KToolInvocation::invokeTerminal(szCmd.data()); + + KToolInvocation::invokeTerminal(szCommand.toLocal8Bit()); + #else // No invokeTerminal() for us, we'll use a // combination of QStringList and QProcess. - - QProcess oProc; - QStringList args; - QStringList szTerminals; + QStringList szTerminals; #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) // Only »cmd.exe /k« in the list. - szTerminals.append("cmd.exe"); - args << "/k" << szCommand; + szTerminals.append("cmd.exe"); #else - // List: x-terminal-emulator, terminal, xterm - szTerminals.append("x-terminal-emulator"); - szTerminals.append("terminal"); - szTerminals.append("xterm"); - args << "-e" << szCommand; + // List: x-terminal-emulator, terminal, xterm + szTerminals.append("x-terminal-emulator"); + szTerminals.append("terminal"); + szTerminals.append("xterm"); #endif // endif COMPILE_ON_WINDOWS - QString szTerm; - while(!szTerminals.isEmpty()) - { - szTerm=szTerminals.takeFirst(); - if (oProc.startDetached(szTerm, args)) - break; - } -#endif // endif COMPILE_KDE_SUPPORT + QString szTerm; + while(!szTerminals.isEmpty()) + { + szTerm=szTerminals.takeFirst(); + if(oProc.startDetached(szTerm, args)) + return true; } - return true; +#endif // endif COMPILE_KDE_SUPPORT + + return c->error(__tr2qs("Failed to start the terminal program")); } static bool system_module_init(KviModule * m) |
