Merge lp:~philip.scott/wingpanel-indicator-sound/mpris-gui-gobject into lp:~wingpanel-devs/wingpanel-indicator-sound/trunk

Proposed by Felipe Escoto
Status: Merged
Approved by: Djax
Approved revision: 124
Merged at revision: 123
Proposed branch: lp:~philip.scott/wingpanel-indicator-sound/mpris-gui-gobject
Merge into: lp:~wingpanel-devs/wingpanel-indicator-sound/trunk
Prerequisite: lp:~philip.scott/wingpanel-indicator-sound/remember-last-player
Diff against target: 416 lines (+119/-102)
4 files modified
src/Indicator.vala (+1/-1)
src/Services/Settings.vala (+10/-0)
src/Widgets/MprisGui.vala (+103/-97)
src/Widgets/MprisWidget.vala (+5/-4)
To merge this branch: bzr merge lp:~philip.scott/wingpanel-indicator-sound/mpris-gui-gobject
Reviewer Review Type Date Requested Status
Djax Approve
Review via email: mp+309089@code.launchpad.net

Commit message

mprisGUI to GObject Style. There should be no changes to functionality

Description of the change

Updates MprisGui.vala code to use gobject style construction and properties

To post a comment you must log in.
Revision history for this message
Djax (parnold-x) wrote :

Seems to have no regressions. Nice. Thx.
Btw. in vala the default visibility is private so it is not really necessary.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Indicator.vala'
2--- src/Indicator.vala 2016-09-09 21:03:14 +0000
3+++ src/Indicator.vala 2016-10-23 14:46:21 +0000
4@@ -271,7 +271,7 @@
5 int position = 0;
6 main_grid = new Gtk.Grid ();
7
8- var mpris = new Widgets.MprisWidget (settings);
9+ var mpris = new Widgets.MprisWidget ();
10
11 mpris.close.connect (() => {
12 close ();
13
14=== modified file 'src/Services/Settings.vala'
15--- src/Services/Settings.vala 2015-06-09 18:43:23 +0000
16+++ src/Services/Settings.vala 2016-10-23 14:46:21 +0000
17@@ -20,7 +20,17 @@
18 public double max_volume { get; set; }
19 public string[] last_title_info { get; set; }
20
21+ private static Sound.Services.Settings? instance = null;
22+
23 public Settings () {
24 base ("org.pantheon.desktop.wingpanel.indicators.sound");
25 }
26+
27+ public static Sound.Services.Settings get_instance () {
28+ if (instance == null) {
29+ instance = new Sound.Services.Settings ();
30+ }
31+
32+ return instance;
33+ }
34 }
35
36=== modified file 'src/Widgets/MprisGui.vala'
37--- src/Widgets/MprisGui.vala 2016-10-23 14:46:21 +0000
38+++ src/Widgets/MprisGui.vala 2016-10-23 14:46:21 +0000
39@@ -3,7 +3,7 @@
40 *
41 * Copyright
42 * 2014 Ikey Doherty <ikey.doherty@gmail.com>
43- * 2015 Wingpanel Developers
44+ * 2016 Wingpanel Developers
45 *
46 * This program is free software; you can redistribute it and/or modify
47 * it under the terms of the GNU General Public License as published by
48@@ -23,26 +23,85 @@
49 public class Sound.Widgets.ClientWidget : Gtk.Box {
50 private const string NOT_PLAYING = _("Not currently playing");
51
52+ public signal void close ();
53+
54+ private Gtk.Revealer player_revealer;
55+ private Gtk.Image? background = null;
56+ private Gtk.Label title_label;
57+ private Gtk.Label artist_label;
58+ private Gtk.Button prev_btn;
59+ private Gtk.Button play_btn;
60+ private Gtk.Button next_btn;
61+ private Icon? app_icon = null;
62+ private Cancellable load_remote_art_cancel;
63+
64+ private bool launched_by_indicator = false;
65+ private string app_name = _("Music player");
66+ private string last_artUrl;
67+
68 public string mpris_name = "";
69
70- Gtk.Revealer player_revealer;
71- Gtk.Image? background = null;
72- public Services.MprisClient? client = null;
73- Services.Settings settings;
74-
75- Gtk.Label title_label;
76- Gtk.Label artist_label;
77- Gtk.Button prev_btn;
78- Gtk.Button play_btn;
79- Gtk.Button next_btn;
80- AppInfo? ainfo;
81- Icon? app_icon = null;
82- string app_name = _("Music player");
83- Cancellable load_remote_art_cancel;
84- string last_artUrl;
85- bool launched_by_indicator = false;
86-
87- public signal void close ();
88+ private AppInfo? ainfo;
89+
90+ public AppInfo? app_info {
91+ get {
92+ return ainfo;
93+ } set {
94+ ainfo = value;
95+ if (ainfo != null) {
96+ app_name = ainfo.get_display_name ();
97+ if (app_name == "") {
98+ app_name = ainfo.get_name ();
99+ }
100+
101+ app_icon = value.get_icon ();
102+ if (app_icon == null) {
103+ app_icon = new ThemedIcon ("application-default-icon");
104+ }
105+
106+ background.set_from_gicon (app_icon, Gtk.IconSize.DIALOG);
107+ }
108+ }
109+ }
110+
111+ private Services.MprisClient? client_ = null;
112+
113+ public Services.MprisClient? client {
114+ get {
115+ return client_;
116+ } set {
117+ this.client_ = value;
118+ if (value != null) {
119+ if (client.player.desktop_entry != "") {
120+ app_info = new DesktopAppInfo (client.player.desktop_entry + ".desktop");
121+ }
122+
123+ connect_to_client ();
124+ update_play_status ();
125+ update_from_meta ();
126+ update_controls ();
127+
128+ if (launched_by_indicator) {
129+ Idle.add (()=> {
130+ try {
131+ launched_by_indicator = false;
132+ client.player.play_pause ();
133+ } catch (Error e) {
134+ warning ("Could not play/pause: %s", e.message);
135+ }
136+
137+ return false;
138+ });
139+ }
140+ } else {
141+ (play_btn.get_image () as Gtk.Image).set_from_icon_name ("media-playback-start-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
142+ prev_btn.set_sensitive (false);
143+ next_btn.set_sensitive (false);
144+ Sound.Services.Settings.get_instance ().last_title_info = {app_info.get_id (), title_label.get_text (), artist_label.get_text (), last_artUrl};
145+ this.mpris_name = "";
146+ }
147+ }
148+ }
149
150 /**
151 * Create a new ClientWidget
152@@ -50,67 +109,42 @@
153 * @param client The underlying MprisClient instance to use
154 */
155 public ClientWidget (Services.MprisClient mpris_client) {
156- Object (orientation: Gtk.Orientation.VERTICAL, spacing: 0);
157- this.client = mpris_client;
158-
159- load_remote_art_cancel = new Cancellable ();
160-
161- if (client.player.desktop_entry != "") {
162- ainfo = new DesktopAppInfo (client.player.desktop_entry + ".desktop");
163- if (ainfo != null) {
164- app_icon = ainfo.get_icon ();
165- app_name = ainfo.get_display_name ();
166- if (app_name == "") {
167- app_name = ainfo.get_name ();
168- }
169- }
170- }
171- if (app_icon == null) {
172- app_icon = new ThemedIcon ("application-default-icon");
173- }
174-
175- create_ui ();
176+ Object (orientation: Gtk.Orientation.VERTICAL, spacing: 0, client: mpris_client);
177 }
178
179 /**
180 * Create a new ClientWidget for the default player
181 *
182 * @param info The AppInfo of the default music player
183- * @param settings Sound indicator settings
184 */
185- public ClientWidget.default (AppInfo info, Services.Settings settings) {
186- Object (orientation: Gtk.Orientation.VERTICAL, spacing: 0);
187-
188- this.client = null;
189- this.settings = settings;
190- load_remote_art_cancel = new Cancellable ();
191-
192- ainfo = info;
193- app_icon = ainfo.get_icon ();
194- app_name = ainfo.get_display_name ();
195-
196- create_ui ();
197- if (settings.last_title_info.length == 4) {
198- string[] title_info = settings.last_title_info;
199- if (title_info[0] == ainfo.get_id ()) {
200+ public ClientWidget.default (AppInfo info) {
201+ Object (orientation: Gtk.Orientation.VERTICAL, spacing: 0, app_info: info, client: null);
202+
203+ if (Sound.Services.Settings.get_instance ().last_title_info.length == 4) {
204+ string[] title_info = Sound.Services.Settings.get_instance ().last_title_info;
205+ if (title_info[0] == app_info.get_id ()) {
206 title_label.set_markup ("<b>%s</b>".printf (Markup.escape_text (title_info[1])));
207 artist_label.set_text (title_info[2]);
208 if (title_info[3] != "") {
209 update_art (title_info[3]);
210 }
211+
212 return;
213 }
214 }
215+
216 title_label.set_markup ("<b>%s</b>".printf (Markup.escape_text (app_name)));
217 artist_label.set_text (NOT_PLAYING);
218 }
219
220- private void create_ui () {
221+ construct {
222+ load_remote_art_cancel = new Cancellable ();
223+
224 player_revealer = new Gtk.Revealer ();
225 player_revealer.reveal_child = true;
226 var player_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
227
228- background = new Gtk.Image.from_gicon (app_icon, Gtk.IconSize.DIALOG);
229+ background = new Gtk.Image ();
230
231 background.margin_start = 4;
232 background.margin_end = 4;
233@@ -148,7 +182,7 @@
234 prev_btn = btn;
235 btn.clicked.connect (()=> {
236 Idle.add (()=> {
237- if (client.player.can_go_previous) {
238+ if (client.player.can_go_previous) {
239 if(!Thread.supported ()) {
240 warning ("Threading is not supported. DBus timeout could be blocking UI");
241 try {
242@@ -170,6 +204,7 @@
243 return false;
244 });
245 });
246+
247 controls.pack_start (btn, false, false, 0);
248
249 btn = make_control_button ("media-playback-start-symbolic");
250@@ -197,6 +232,7 @@
251 return false;
252 });
253 });
254+
255 controls.pack_start (btn, false, false, 0);
256
257 btn = make_control_button ("media-skip-forward-symbolic");
258@@ -225,6 +261,7 @@
259 return false;
260 });
261 });
262+
263 controls.pack_start (btn, false, false, 0);
264
265 controls.set_halign (Gtk.Align.CENTER);
266@@ -233,7 +270,6 @@
267
268 player_box.pack_end (controls, false, false, 0);
269
270-
271 if (client != null) {
272 connect_to_client ();
273 update_play_status ();
274@@ -245,36 +281,6 @@
275 pack_start (player_revealer);
276 }
277
278- public void set_client (string name, Services.MprisClient client) {
279- this.mpris_name = name;
280- this.client = client;
281- connect_to_client ();
282- update_play_status ();
283- update_from_meta ();
284- update_controls ();
285- if (launched_by_indicator) {
286- Idle.add (()=> {
287- try {
288- launched_by_indicator = false;
289- client.player.play_pause ();
290- } catch (Error e) {
291- warning ("Could not play/pause: %s", e.message);
292- }
293- return false;
294- });
295- }
296- }
297-
298- public void remove_client () {
299- (play_btn.get_image () as Gtk.Image).set_from_icon_name ("media-playback-start-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
300- prev_btn.set_sensitive (false);
301- next_btn.set_sensitive (false);
302- settings.last_title_info = {ainfo.get_id (), title_label.get_text (), artist_label.get_text (), last_artUrl};
303-
304- this.client = null;
305- this.mpris_name = "";
306- }
307-
308 private void connect_to_client () {
309 client.prop.properties_changed.connect ((i,p,inv)=> {
310 if (i == "org.mpris.MediaPlayer2.Player") {
311@@ -322,8 +328,8 @@
312 return null;
313 });
314 }
315- } else if (ainfo != null) {
316- ainfo.launch (null, null);
317+ } else if (app_info != null) {
318+ app_info.launch (null, null);
319 }
320 } catch (Error e) {
321 warning ("Could not launch player");
322@@ -355,7 +361,7 @@
323 /**
324 * Update play status based on player requirements
325 */
326- void update_play_status () {
327+ private void update_play_status () {
328 switch (client.player.playback_status) {
329 case "Playing":
330 (play_btn.get_image () as Gtk.Image).set_from_icon_name ("media-playback-pause-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
331@@ -370,7 +376,7 @@
332 /**
333 * Update prev/next sensitivity based on player requirements
334 */
335- void update_controls () {
336+ private void update_controls () {
337 prev_btn.set_sensitive (client.player.can_go_previous);
338 next_btn.set_sensitive (client.player.can_go_next);
339 }
340@@ -378,7 +384,7 @@
341 /**
342 * Utility, handle updating the album art
343 */
344- void update_art (string uri) {
345+ private void update_art (string uri) {
346 if (!uri.has_prefix ("file://") && !uri.has_prefix ("http")) {
347 background.set_from_gicon (app_icon, Gtk.IconSize.DIALOG);
348 return;
349@@ -389,7 +395,7 @@
350 var pbuf = new Gdk.Pixbuf.from_file_at_size (fname, ICON_SIZE, ICON_SIZE);
351 background.set_from_pixbuf (mask_pixbuf (pbuf));
352 } catch (Error e) {
353- background.set_from_gicon (app_icon, Gtk.IconSize.DIALOG);
354+ //background.set_from_gicon (app_icon, Gtk.IconSize.DIALOG);
355 }
356 } else {
357 load_remote_art_cancel.cancel ();
358@@ -398,7 +404,7 @@
359 }
360 }
361
362- async void load_remote_art (string uri) {
363+ private async void load_remote_art (string uri) {
364 GLib.File file = GLib.File.new_for_uri (uri);
365 try {
366 GLib.InputStream stream = yield file.read_async (Priority.DEFAULT, load_remote_art_cancel);
367@@ -445,7 +451,7 @@
368 }
369 }
370
371- static Gdk.Pixbuf? mask_pixbuf (Gdk.Pixbuf pixbuf) {
372+ private static Gdk.Pixbuf? mask_pixbuf (Gdk.Pixbuf pixbuf) {
373 var size = ICON_SIZE;
374 var mask_offset = 4;
375 var mask_size_offset = mask_offset * 2;
376
377=== modified file 'src/Widgets/MprisWidget.vala'
378--- src/Widgets/MprisWidget.vala 2016-10-23 14:46:21 +0000
379+++ src/Widgets/MprisWidget.vala 2016-10-23 14:46:21 +0000
380@@ -19,7 +19,7 @@
381 HashTable<string,ClientWidget> ifaces;
382 public signal void close ();
383
384- public MprisWidget(Services.Settings settings) {
385+ public MprisWidget() {
386 Object (orientation: Gtk.Orientation.VERTICAL, spacing: 1);
387
388 ifaces = new HashTable<string,ClientWidget>(str_hash, str_equal);
389@@ -31,7 +31,7 @@
390
391 default_music = AppInfo.get_default_for_type ("audio/x-vorbis+ogg", false);
392 if (default_music != null) {
393- default_widget = new ClientWidget.default (default_music, settings);
394+ default_widget = new ClientWidget.default (default_music);
395
396 default_widget.close.connect (() => {
397 close ();
398@@ -62,7 +62,8 @@
399 */
400 void add_iface (string name, Services.MprisClient iface) {
401 if (iface.player.desktop_entry == default_music.get_id ().replace (".desktop","")) {
402- default_widget.set_client (name, iface);
403+ default_widget.mpris_name = name;
404+ default_widget.client = iface;
405 ifaces.insert(name, default_widget);
406 default_widget.no_show_all = false;
407 default_widget.visible = true;
408@@ -89,7 +90,7 @@
409 */
410 void destroy_iface(string name) {
411 if (default_widget.mpris_name == name) {
412- default_widget.remove_client ();
413+ default_widget.client = null;
414 } else {
415 var widg = ifaces[name];
416 if (widg != null) {

Subscribers

People subscribed via source and target branches

to all changes: