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

Proposed by Marco Trevisan (Treviño)
Status: Superseded
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
Indicator Applet Developers Pending
Review via email: mp+156518@code.launchpad.net

This proposal has been superseded by a proposal from 2013-04-03.

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

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.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Unmerged revisions

Preview Diff

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

Subscribers

People subscribed via source and target branches