Merge lp:~3v1n0/indicator-sound/gtk-application-player-activate into lp:indicator-sound/13.10

Proposed by Marco Trevisan (Treviño) on 2013-04-05
Status: Merged
Approved by: Lars Karlitski on 2013-04-05
Approved revision: 347
Merged at revision: 346
Proposed branch: lp:~3v1n0/indicator-sound/gtk-application-player-activate
Merge into: lp:indicator-sound/13.10
Prerequisite: lp:~3v1n0/indicator-sound/launch-context
Diff against target: 191 lines (+131/-4)
5 files modified
src/Makefile.am (+2/-1)
src/gtk-application-player.vala (+123/-0)
src/metadata-menu-item.vala (+2/-1)
src/mpris2-controller.vala (+2/-2)
src/player-controller.vala (+2/-0)
To merge this branch: bzr merge lp:~3v1n0/indicator-sound/gtk-application-player-activate
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve on 2013-04-05
Lars Karlitski (community) 2013-04-05 Approve on 2013-04-05
Review via email: mp+157358@code.launchpad.net

Commit message

PlayerController use GtkApplicationPlayer and activate it when we need to raise

GtkApplicationPlayer: add a class to handle the GtkApplication players
It allows to check if the given player implements the "org.gtk.Application" interface
and if it's the case, it Activate the application with the proper timestamp when
requested.

Description of the change

Upstream port for lp:~3v1n0/indicator-sound/gtk-application-player-activate/+merge/156919

Add a GtkApplicationPlayer utility class used to check if a player application supports the "org.gtk.Application" dbus interface, and in case it sends the platform_data with activation timestamp to it when raising it.

This fixes bug #627195 for some applications such as Rhythmbox.
Unfortunately the proper fix would need to change the MPRIS interface. See https://bugs.launchpad.net/ayatana-design/+bug/627195/comments/26

To post a comment you must log in.
Lars Karlitski (larsu) wrote :

Approved, same as the one merged in 13.04.

review: Approve
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Unity Merger (unity-merger) wrote :

No proposals found for merge of lp:~3v1n0/indicator-sound/launch-context into lp:indicator-sound.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Makefile.am'
2--- src/Makefile.am 2013-04-05 13:40:51 +0000
3+++ src/Makefile.am 2013-04-05 13:40:51 +0000
4@@ -67,7 +67,8 @@
5 settings-manager.vala \
6 playlists-menu-item.vala \
7 freedesktop-interfaces.vala \
8- fetch-file.vala
9+ fetch-file.vala \
10+ gtk-application-player.vala
11
12 music_bridge_VALAFLAGS = \
13 --ccode \
14
15=== added file 'src/gtk-application-player.vala'
16--- src/gtk-application-player.vala 1970-01-01 00:00:00 +0000
17+++ src/gtk-application-player.vala 2013-04-05 13:40:51 +0000
18@@ -0,0 +1,123 @@
19+/*
20+Copyright 2013 Canonical Ltd.
21+
22+Authors:
23+ Marco Trevisan <marco.trevisan@canonical.com>
24+
25+This program is free software: you can redistribute it and/or modify it
26+under the terms of the GNU General Public License version 3, as published
27+by the Free Software Foundation.
28+
29+This program is distributed in the hope that it will be useful, but
30+WITHOUT ANY WARRANTY; without even the implied warranties of
31+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
32+PURPOSE. See the GNU General Public License for more details.
33+
34+You should have received a copy of the GNU General Public License along
35+with this program. If not, see <http://www.gnu.org/licenses/>.
36+*/
37+
38+[DBus (name = "org.gtk.Application")]
39+public interface DBusGtkApplication : Object {
40+ public abstract void Activate(GLib.HashTable<string, Variant?> platform_data) throws IOError;
41+}
42+
43+public class GtkApplicationPlayer : GLib.Object
44+{
45+ public PlayerController owner {get; construct;}
46+
47+ private bool gtk_application_searched = false;
48+ private DBusGtkApplication gtk_application;
49+
50+ public GtkApplicationPlayer(PlayerController ctrl)
51+ {
52+ GLib.Object(owner: ctrl);
53+ }
54+
55+ public void activate(uint timestamp)
56+ {
57+ this.setup_gtk_application();
58+
59+ if (this.gtk_application == null) {
60+ return;
61+ }
62+
63+ var context = Gdk.Display.get_default().get_app_launch_context();
64+ context.set_timestamp(timestamp);
65+
66+ var data = new GLib.HashTable<string, Variant?>(str_hash, str_equal);
67+ data["desktop-startup-id"] = context.get_startup_notify_id(this.owner.app_info, new GLib.List<GLib.File>());
68+
69+ try {
70+ this.gtk_application.Activate(data);
71+ }
72+ catch (IOError e) {}
73+ }
74+
75+ private void setup_gtk_application()
76+ {
77+ if (owner.current_state != PlayerController.state.CONNECTED)
78+ return;
79+
80+ if (this.gtk_application != null || this.gtk_application_searched)
81+ return;
82+
83+ try {
84+ var connection = Bus.get_sync(BusType.SESSION);
85+ var name = this.owner.dbus_name;
86+ string gtk_application_path;
87+ this.find_iface_path(connection, name, "/", "org.gtk.Application", out gtk_application_path);
88+ this.gtk_application_searched = true;
89+
90+ if (gtk_application_path != null) {
91+ this.gtk_application = Bus.get_proxy_sync(BusType.SESSION, this.owner.dbus_name, gtk_application_path);
92+ }
93+ } catch (Error e) {
94+ return;
95+ }
96+ }
97+
98+ private void find_iface_path(DBusConnection connection, string name, string path, string target_iface, out string found_path)
99+ {
100+ found_path = null;
101+ DBusNodeInfo node = null;
102+
103+ try {
104+ unowned string xml_string;
105+ var xml = connection.call_sync(name, path, "org.freedesktop.DBus.Introspectable", "Introspect", null, new VariantType("(s)"), DBusCallFlags.NONE, 1000);
106+ xml.get("(&s)", out xml_string);
107+ node = new DBusNodeInfo.for_xml(xml_string);
108+ } catch (Error e) {
109+ return;
110+ }
111+
112+ if (node == null) {
113+ return;
114+ }
115+
116+ foreach (var iface in node.interfaces) {
117+ if (iface.name == target_iface) {
118+ found_path = path;
119+ return;
120+ }
121+ }
122+
123+ bool is_root = (path == "/");
124+
125+ foreach (var subnode in node.nodes) {
126+ string new_path = path;
127+
128+ if (!is_root) {
129+ new_path += "/";
130+ }
131+
132+ new_path += subnode.path;
133+
134+ find_iface_path(connection, name, new_path, target_iface, out found_path);
135+
136+ if (found_path != null) {
137+ return;
138+ }
139+ }
140+ }
141+}
142\ No newline at end of file
143
144=== modified file 'src/metadata-menu-item.vala'
145--- src/metadata-menu-item.vala 2013-04-05 13:40:51 +0000
146+++ src/metadata-menu-item.vala 2013-04-05 13:40:51 +0000
147@@ -176,7 +176,8 @@
148 {
149 this.owner.instantiate(timestamp);
150 }
151- else if(this.owner.current_state == PlayerController.state.CONNECTED){
152+ else if (this.owner.current_state == PlayerController.state.CONNECTED) {
153+ this.owner.gtk_app_player.activate(timestamp);
154 this.owner.mpris_bridge.expose(timestamp);
155 }
156 }
157
158=== modified file 'src/mpris2-controller.vala'
159--- src/mpris2-controller.vala 2013-04-05 13:40:51 +0000
160+++ src/mpris2-controller.vala 2013-04-05 13:40:51 +0000
161@@ -208,9 +208,9 @@
162 return (this.player != null && this.mpris2_root != null);
163 }
164
165- public void expose(uint timestamp)
166+ public void expose(uint timestmap)
167 {
168- if(this.connected() == true){
169+ if (this.connected() == true) {
170 this.mpris2_root.Raise.begin();
171 }
172 }
173
174=== modified file 'src/player-controller.vala'
175--- src/player-controller.vala 2013-04-05 13:40:51 +0000
176+++ src/player-controller.vala 2013-04-05 13:40:51 +0000
177@@ -45,6 +45,7 @@
178 public string dbus_name { get; set;}
179 public ArrayList<PlayerItem> custom_items;
180 public Mpris2Controller mpris_bridge;
181+ public GtkApplicationPlayer gtk_app_player;
182 public AppInfo? app_info { get; set;}
183 public int menu_offset { get; set;}
184 public string icon_name { get; set; }
185@@ -149,6 +150,7 @@
186 debug ( " establish mpris connection - use playlists value = %s ",
187 this.use_playlists.to_string() );
188 this.mpris_bridge = new Mpris2Controller (this);
189+ this.gtk_app_player = new GtkApplicationPlayer (this);
190 this.determine_state ();
191 }
192

Subscribers

People subscribed via source and target branches