Merge lp:~jeremy-munsch/synapse-project/fix-ssh-terminal into lp:synapse-project

Proposed by Jeremy Munsch on 2015-11-09
Status: Merged
Merged at revision: 664
Proposed branch: lp:~jeremy-munsch/synapse-project/fix-ssh-terminal
Merge into: lp:synapse-project
Diff against target: 118 lines (+64/-22)
3 files modified
src/core/common-actions.vala (+1/-11)
src/core/utils.vala (+62/-0)
src/plugins/ssh-plugin.vala (+1/-11)
To merge this branch: bzr merge lp:~jeremy-munsch/synapse-project/fix-ssh-terminal
Reviewer Review Type Date Requested Status
Rico Tzschichholz 2015-11-09 Pending
Review via email: mp+277061@code.launchpad.net

Description of the change

Use
  x-terminal-emulator -e 'ssh %s' if x-terminal-emulator is available or default to GLib NEEDS_TERMINAL if a terminal is needed

to respect user default terminal instead of unefficient Glib default terminal
https://mail.gnome.org/archives/vala-list/2012-June/msg00061.html

It is only launching gnome-terminal or xterm, this is not the wanted behaviour.

The -e should work with any terminal emulator, this is i think a reliable and simple solution since synapse is targeting Debian based distros.
The fallback still supports other DE though.

To post a comment you must log in.
Jeremy Munsch (jeremy-munsch) wrote :

I just saw in common actions that the problem is also to fix there.
I will also test if x-terminal-emulator is present and fall back to GLib solution if not.

I think of refactoring this into an Utils method.

Jeremy Munsch (jeremy-munsch) wrote :

I just did the just above.

If this is merged modifications would have to be done in PR https://code.launchpad.net/~jeremy-munsch/synapse-project/add-script-execute/+merge/277502 to make usage of the introduced "Utils.open_command_line"

Rico Tzschichholz (ricotz) wrote :

Was about to say that "x-terminal-emulator" might not be available/set.

Jeremy Munsch (jeremy-munsch) wrote :

Oops i made a mistake correcting now
"if (null != Environment.find_program_in_path ("zeal"))"

Jeremy Munsch (jeremy-munsch) wrote :

I just saw that redhat based distros use /usr/sbin/alternatives
and that synapse is distributed in redhat (fedora it seems at least).
http://rpmfind.net/linux/rpm2html/search.php?query=synapse

Should i update testing /usr/sbin/alternatives so it could be packaged more easily ?

Jeremy Munsch (jeremy-munsch) wrote :

Just updated the branch and corrected the commit message.

Jeremy Munsch (jeremy-munsch) wrote :

I have updated this. It now uses gconf to get default terminal, then fallbacks on x-terminal and then fallback on native and not reliable at all vala way.

Jeremy Munsch (jeremy-munsch) wrote :

So it is now using GLib.Settings

Jeremy Munsch (jeremy-munsch) wrote :

This should be ok now.

Jeremy Munsch (jeremy-munsch) wrote :

I have faith it should be ok.

637. By Rico Tzschichholz on 2016-02-26

plugins: Add suport for MATE Screensaver

638. By Rico Tzschichholz on 2016-02-26

po: Update translations

639. By Rico Tzschichholz on 2016-02-27

desktop-file-plugin: correct ApplicationsMatch to DesktopFileMatch

640. By Rico Tzschichholz on 2016-02-27

src: Drop "using Gee;"

641. By Rico Tzschichholz on 2016-02-27

src: Drop "using Json;"

642. By Rico Tzschichholz on 2016-02-27

src: Drop "using Zeitgeist;"

643. By Rico Tzschichholz on 2016-02-27

src: Drop "using Gtk;"

644. By Rico Tzschichholz on 2016-02-27

src: Drop "using Cairo;"

645. By Rico Tzschichholz on 2016-02-27

src: Drop last usages of "using *;"

646. By Rico Tzschichholz on 2016-02-27

ui: Show release-name in about-dialog only

647. By Rico Tzschichholz on 2016-02-27

ui: Bump to 2016

648. By Rico Tzschichholz on 2016-02-28

Release 0.2.99.2

649. By Rico Tzschichholz on 2016-03-02

ui: Set and update client-window of Gtk.IMMulticontext

650. By Rico Tzschichholz on 2016-03-08

main: Properly construct OptionEntry

Stop using an empty string where is getting treated as translateable.

651. By Michael Aquilina on 2016-04-01

Add pass plugin

652. By Rico Tzschichholz on 2016-09-29

Fix non-matching generic types

653. By Rico Tzschichholz on 2016-10-06

Fix non-matching generic types of interface implementations

654. By Jeremy Munsch on 2016-12-18

utils: Add generic method open_command_line
common-actions/ssh-plugin: usage of open_command_line

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/core/common-actions.vala'
2--- src/core/common-actions.vala 2015-11-18 12:08:18 +0000
3+++ src/core/common-actions.vala 2016-12-18 20:17:23 +0000
4@@ -153,17 +153,7 @@
5 AppInfo original = app_match.app_info ??
6 new DesktopAppInfo.from_filename (app_match.filename);
7
8- try
9- {
10- AppInfo app = AppInfo.create_from_commandline (
11- original.get_commandline (), original.get_name (),
12- AppInfoCreateFlags.NEEDS_TERMINAL);
13- app.launch (null, Gdk.Display.get_default ().get_app_launch_context ());
14- }
15- catch (Error err)
16- {
17- warning ("%s", err.message);
18- }
19+ Utils.open_command_line (original.get_commandline (), original.get_name (), true);
20 }
21 else if (match is UriMatch)
22 {
23
24=== modified file 'src/core/utils.vala'
25--- src/core/utils.vala 2015-11-19 09:11:34 +0000
26+++ src/core/utils.vala 2016-12-18 20:17:23 +0000
27@@ -112,6 +112,68 @@
28 }
29 }
30
31+ public static void open_command_line (string command, string? app_name = null, bool needs_terminal = false)
32+ {
33+ AppInfoCreateFlags using_terminal = AppInfoCreateFlags.NONE;
34+ string commandline = command;
35+ string? application_name = app_name;
36+
37+ if (needs_terminal)
38+ {
39+ if (GLib.SettingsSchemaSource.get_default ().lookup ("org.gnome.desktop.default-applications.terminal", true) != null)
40+ {
41+ application_name = (new GLib.Settings("org.gnome.desktop.default-applications.terminal")).get_string ("exec");
42+ }
43+
44+ if (Environment.find_program_in_path ("x-terminal-emulator") != null)
45+ {
46+ // try to determine default terminal application and make exceptions
47+ try {
48+ Regex regex = new Regex ("[a-zA-Z0-9-_]*");
49+
50+ Process.spawn_command_line_sync ("sh -c \"cat \\\"$(which x-terminal-emulator)\\\" | grep @ | cut -d$ -f1\"",
51+ out application_name);
52+
53+ if (!regex.match (application_name))
54+ application_name = "x-terminal-emulator";
55+
56+ } catch (Error e) {
57+ warning ("Error: %s\n", e.message);
58+ application_name = "x-terminal-emulator";
59+ }
60+ }
61+
62+ if (application_name == null)
63+ using_terminal = AppInfoCreateFlags.NEEDS_TERMINAL;
64+ }
65+
66+ if (application_name != null)
67+ switch (application_name) {
68+ case "terminator":
69+ commandline = "%s -x \"%s\"".printf (application_name, commandline);
70+ break;
71+ case "aterm":
72+ commandline = "%s -e %s".printf (application_name, commandline);
73+ break;
74+ // case "gnome-terminal":
75+ // case "x-terminal-emulator":
76+ default:
77+ commandline = "%s -e '%s'".printf (application_name, commandline);
78+ break;
79+ }
80+
81+ try
82+ {
83+ debug (commandline);
84+ AppInfo app = AppInfo.create_from_commandline (commandline, application_name, using_terminal);
85+ app.launch (null, Gdk.Display.get_default ().get_app_launch_context ());
86+ }
87+ catch (Error err)
88+ {
89+ warning ("%s", err.message);
90+ }
91+ }
92+
93 public static string extract_type_name (Type obj_type)
94 {
95 string obj_class = obj_type.name ();
96
97=== modified file 'src/plugins/ssh-plugin.vala'
98--- src/plugins/ssh-plugin.vala 2016-02-27 14:12:03 +0000
99+++ src/plugins/ssh-plugin.vala 2016-12-18 20:17:23 +0000
100@@ -168,17 +168,7 @@
101
102 public override void do_action ()
103 {
104- try
105- {
106- AppInfo ai = AppInfo.create_from_commandline (
107- "ssh %s".printf (this.title),
108- "ssh", AppInfoCreateFlags.NEEDS_TERMINAL);
109- ai.launch (null, null);
110- }
111- catch (Error err)
112- {
113- warning ("%s", err.message);
114- }
115+ Utils.open_command_line ("ssh %s".printf (title), null, true);
116 }
117
118 public SshHost (string host_name)