summaryrefslogtreecommitdiff
path: root/src/core/utils.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/utils.vala')
-rw-r--r--src/core/utils.vala64
1 files changed, 64 insertions, 0 deletions
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 ();