summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Munsch <[email protected]>2018-02-03 22:20:12 +0100
committerRico Tzschichholz <[email protected]>2018-02-03 22:20:12 +0100
commit1318b74ef6f568a853ff8322f07ecbfeeb1ca896 (patch)
treeb02b1f0dc78f92b84ba6da659762a93fed07cee3
parent114376f437a702c557cda9fb9bb8bc9a92c51a3e (diff)
core: Add generic method open_command_line() and use it in ssh-plugin
https://launchpad.net/bugs/1504433 https://launchpad.net/bugs/1080755
-rw-r--r--src/core/common-actions.vala12
-rw-r--r--src/core/utils.vala64
-rw-r--r--src/plugins/ssh-plugin.vala12
3 files changed, 66 insertions, 22 deletions
diff --git a/src/core/common-actions.vala b/src/core/common-actions.vala
index 590c9e1..886f82f 100644
--- a/src/core/common-actions.vala
+++ b/src/core/common-actions.vala
@@ -153,17 +153,7 @@ namespace Synapse
AppInfo original = app_match.app_info ??
new DesktopAppInfo.from_filename (app_match.filename);
- try
- {
- AppInfo app = AppInfo.create_from_commandline (
- original.get_commandline (), original.get_name (),
- AppInfoCreateFlags.NEEDS_TERMINAL);
- app.launch (null, Gdk.Display.get_default ().get_app_launch_context ());
- }
- catch (Error err)
- {
- warning ("%s", err.message);
- }
+ Utils.open_command_line (original.get_commandline (), original.get_name (), true);
}
else if (match is UriMatch)
{
diff --git a/src/core/utils.vala b/src/core/utils.vala
index bb117d8..1904bbc 100644
--- a/src/core/utils.vala
+++ b/src/core/utils.vala
@@ -112,6 +112,70 @@ namespace Synapse
}
}
+ public static void open_command_line (string command, string? app_name = null, bool needs_terminal = false)
+ {
+ AppInfoCreateFlags using_terminal = AppInfoCreateFlags.NONE;
+ string commandline = command;
+ string? application_name = app_name;
+
+ if (needs_terminal)
+ {
+ var schema = GLib.SettingsSchemaSource.get_default ().lookup ("org.gnome.desktop.default-applications.terminal", true);
+ if (schema != null)
+ {
+ var settings = new GLib.Settings.full (schema, null, null);
+ application_name = settings.get_string ("exec");
+ }
+
+ if (Environment.find_program_in_path ("x-terminal-emulator") != null)
+ {
+ // try to determine default terminal application and make exceptions
+ try {
+ Regex regex = new Regex ("[a-zA-Z0-9-_]*");
+
+ Process.spawn_command_line_sync ("sh -c \"cat \\\"$(which x-terminal-emulator)\\\" | grep @ | cut -d$ -f1\"",
+ out application_name);
+
+ if (!regex.match (application_name))
+ application_name = "x-terminal-emulator";
+
+ } catch (Error e) {
+ warning ("Error: %s\n", e.message);
+ application_name = "x-terminal-emulator";
+ }
+ }
+
+ if (application_name == null)
+ using_terminal = AppInfoCreateFlags.NEEDS_TERMINAL;
+ }
+
+ if (application_name != null)
+ switch (application_name) {
+ case "terminator":
+ commandline = "%s -x \"%s\"".printf (application_name, commandline);
+ break;
+ case "aterm":
+ commandline = "%s -e %s".printf (application_name, commandline);
+ break;
+ // case "gnome-terminal":
+ // case "x-terminal-emulator":
+ default:
+ commandline = "%s -e '%s'".printf (application_name, commandline);
+ break;
+ }
+
+ try
+ {
+ debug (commandline);
+ AppInfo app = AppInfo.create_from_commandline (commandline, application_name, using_terminal);
+ app.launch (null, Gdk.Display.get_default ().get_app_launch_context ());
+ }
+ catch (Error err)
+ {
+ warning ("%s", err.message);
+ }
+ }
+
public static string extract_type_name (Type obj_type)
{
string obj_class = obj_type.name ();
diff --git a/src/plugins/ssh-plugin.vala b/src/plugins/ssh-plugin.vala
index aae589e..f17b3ad 100644
--- a/src/plugins/ssh-plugin.vala
+++ b/src/plugins/ssh-plugin.vala
@@ -168,17 +168,7 @@ namespace Synapse
public override void do_action ()
{
- try
- {
- AppInfo ai = AppInfo.create_from_commandline (
- "ssh %s".printf (this.title),
- "ssh", AppInfoCreateFlags.NEEDS_TERMINAL);
- ai.launch (null, null);
- }
- catch (Error err)
- {
- warning ("%s", err.message);
- }
+ Utils.open_command_line ("ssh %s".printf (title), null, true);
}
public SshHost (string host_name)