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
=== modified file 'src/Indicator.vala'
--- src/Indicator.vala 2016-09-09 21:03:14 +0000
+++ src/Indicator.vala 2016-10-23 14:46:21 +0000
@@ -271,7 +271,7 @@
271 int position = 0;271 int position = 0;
272 main_grid = new Gtk.Grid ();272 main_grid = new Gtk.Grid ();
273273
274 var mpris = new Widgets.MprisWidget (settings);274 var mpris = new Widgets.MprisWidget ();
275275
276 mpris.close.connect (() => {276 mpris.close.connect (() => {
277 close ();277 close ();
278278
=== modified file 'src/Services/Settings.vala'
--- src/Services/Settings.vala 2015-06-09 18:43:23 +0000
+++ src/Services/Settings.vala 2016-10-23 14:46:21 +0000
@@ -20,7 +20,17 @@
20 public double max_volume { get; set; }20 public double max_volume { get; set; }
21 public string[] last_title_info { get; set; }21 public string[] last_title_info { get; set; }
2222
23 private static Sound.Services.Settings? instance = null;
24
23 public Settings () {25 public Settings () {
24 base ("org.pantheon.desktop.wingpanel.indicators.sound");26 base ("org.pantheon.desktop.wingpanel.indicators.sound");
25 }27 }
28
29 public static Sound.Services.Settings get_instance () {
30 if (instance == null) {
31 instance = new Sound.Services.Settings ();
32 }
33
34 return instance;
35 }
26}36}
2737
=== modified file 'src/Widgets/MprisGui.vala'
--- src/Widgets/MprisGui.vala 2016-10-23 14:46:21 +0000
+++ src/Widgets/MprisGui.vala 2016-10-23 14:46:21 +0000
@@ -3,7 +3,7 @@
3 *3 *
4 * Copyright4 * Copyright
5 * 2014 Ikey Doherty <ikey.doherty@gmail.com>5 * 2014 Ikey Doherty <ikey.doherty@gmail.com>
6 * 2015 Wingpanel Developers6 * 2016 Wingpanel Developers
7 *7 *
8 * This program is free software; you can redistribute it and/or modify8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by9 * it under the terms of the GNU General Public License as published by
@@ -23,26 +23,85 @@
23public class Sound.Widgets.ClientWidget : Gtk.Box {23public class Sound.Widgets.ClientWidget : Gtk.Box {
24 private const string NOT_PLAYING = _("Not currently playing");24 private const string NOT_PLAYING = _("Not currently playing");
2525
26 public signal void close ();
27
28 private Gtk.Revealer player_revealer;
29 private Gtk.Image? background = null;
30 private Gtk.Label title_label;
31 private Gtk.Label artist_label;
32 private Gtk.Button prev_btn;
33 private Gtk.Button play_btn;
34 private Gtk.Button next_btn;
35 private Icon? app_icon = null;
36 private Cancellable load_remote_art_cancel;
37
38 private bool launched_by_indicator = false;
39 private string app_name = _("Music player");
40 private string last_artUrl;
41
26 public string mpris_name = "";42 public string mpris_name = "";
2743
28 Gtk.Revealer player_revealer;44 private AppInfo? ainfo;
29 Gtk.Image? background = null;45
30 public Services.MprisClient? client = null;46 public AppInfo? app_info {
31 Services.Settings settings;47 get {
3248 return ainfo;
33 Gtk.Label title_label;49 } set {
34 Gtk.Label artist_label;50 ainfo = value;
35 Gtk.Button prev_btn;51 if (ainfo != null) {
36 Gtk.Button play_btn;52 app_name = ainfo.get_display_name ();
37 Gtk.Button next_btn;53 if (app_name == "") {
38 AppInfo? ainfo;54 app_name = ainfo.get_name ();
39 Icon? app_icon = null;55 }
40 string app_name = _("Music player");56
41 Cancellable load_remote_art_cancel;57 app_icon = value.get_icon ();
42 string last_artUrl;58 if (app_icon == null) {
43 bool launched_by_indicator = false;59 app_icon = new ThemedIcon ("application-default-icon");
4460 }
45 public signal void close ();61
62 background.set_from_gicon (app_icon, Gtk.IconSize.DIALOG);
63 }
64 }
65 }
66
67 private Services.MprisClient? client_ = null;
68
69 public Services.MprisClient? client {
70 get {
71 return client_;
72 } set {
73 this.client_ = value;
74 if (value != null) {
75 if (client.player.desktop_entry != "") {
76 app_info = new DesktopAppInfo (client.player.desktop_entry + ".desktop");
77 }
78
79 connect_to_client ();
80 update_play_status ();
81 update_from_meta ();
82 update_controls ();
83
84 if (launched_by_indicator) {
85 Idle.add (()=> {
86 try {
87 launched_by_indicator = false;
88 client.player.play_pause ();
89 } catch (Error e) {
90 warning ("Could not play/pause: %s", e.message);
91 }
92
93 return false;
94 });
95 }
96 } else {
97 (play_btn.get_image () as Gtk.Image).set_from_icon_name ("media-playback-start-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
98 prev_btn.set_sensitive (false);
99 next_btn.set_sensitive (false);
100 Sound.Services.Settings.get_instance ().last_title_info = {app_info.get_id (), title_label.get_text (), artist_label.get_text (), last_artUrl};
101 this.mpris_name = "";
102 }
103 }
104 }
46105
47 /**106 /**
48 * Create a new ClientWidget107 * Create a new ClientWidget
@@ -50,67 +109,42 @@
50 * @param client The underlying MprisClient instance to use109 * @param client The underlying MprisClient instance to use
51 */110 */
52 public ClientWidget (Services.MprisClient mpris_client) {111 public ClientWidget (Services.MprisClient mpris_client) {
53 Object (orientation: Gtk.Orientation.VERTICAL, spacing: 0);112 Object (orientation: Gtk.Orientation.VERTICAL, spacing: 0, client: mpris_client);
54 this.client = mpris_client;
55
56 load_remote_art_cancel = new Cancellable ();
57
58 if (client.player.desktop_entry != "") {
59 ainfo = new DesktopAppInfo (client.player.desktop_entry + ".desktop");
60 if (ainfo != null) {
61 app_icon = ainfo.get_icon ();
62 app_name = ainfo.get_display_name ();
63 if (app_name == "") {
64 app_name = ainfo.get_name ();
65 }
66 }
67 }
68 if (app_icon == null) {
69 app_icon = new ThemedIcon ("application-default-icon");
70 }
71
72 create_ui ();
73 }113 }
74114
75 /**115 /**
76 * Create a new ClientWidget for the default player116 * Create a new ClientWidget for the default player
77 *117 *
78 * @param info The AppInfo of the default music player118 * @param info The AppInfo of the default music player
79 * @param settings Sound indicator settings
80 */119 */
81 public ClientWidget.default (AppInfo info, Services.Settings settings) {120 public ClientWidget.default (AppInfo info) {
82 Object (orientation: Gtk.Orientation.VERTICAL, spacing: 0);121 Object (orientation: Gtk.Orientation.VERTICAL, spacing: 0, app_info: info, client: null);
83122
84 this.client = null;123 if (Sound.Services.Settings.get_instance ().last_title_info.length == 4) {
85 this.settings = settings;124 string[] title_info = Sound.Services.Settings.get_instance ().last_title_info;
86 load_remote_art_cancel = new Cancellable ();125 if (title_info[0] == app_info.get_id ()) {
87
88 ainfo = info;
89 app_icon = ainfo.get_icon ();
90 app_name = ainfo.get_display_name ();
91
92 create_ui ();
93 if (settings.last_title_info.length == 4) {
94 string[] title_info = settings.last_title_info;
95 if (title_info[0] == ainfo.get_id ()) {
96 title_label.set_markup ("<b>%s</b>".printf (Markup.escape_text (title_info[1])));126 title_label.set_markup ("<b>%s</b>".printf (Markup.escape_text (title_info[1])));
97 artist_label.set_text (title_info[2]);127 artist_label.set_text (title_info[2]);
98 if (title_info[3] != "") {128 if (title_info[3] != "") {
99 update_art (title_info[3]);129 update_art (title_info[3]);
100 }130 }
131
101 return;132 return;
102 }133 }
103 }134 }
135
104 title_label.set_markup ("<b>%s</b>".printf (Markup.escape_text (app_name)));136 title_label.set_markup ("<b>%s</b>".printf (Markup.escape_text (app_name)));
105 artist_label.set_text (NOT_PLAYING);137 artist_label.set_text (NOT_PLAYING);
106 }138 }
107139
108 private void create_ui () {140 construct {
141 load_remote_art_cancel = new Cancellable ();
142
109 player_revealer = new Gtk.Revealer ();143 player_revealer = new Gtk.Revealer ();
110 player_revealer.reveal_child = true;144 player_revealer.reveal_child = true;
111 var player_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);145 var player_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
112146
113 background = new Gtk.Image.from_gicon (app_icon, Gtk.IconSize.DIALOG);147 background = new Gtk.Image ();
114148
115 background.margin_start = 4;149 background.margin_start = 4;
116 background.margin_end = 4;150 background.margin_end = 4;
@@ -148,7 +182,7 @@
148 prev_btn = btn;182 prev_btn = btn;
149 btn.clicked.connect (()=> {183 btn.clicked.connect (()=> {
150 Idle.add (()=> {184 Idle.add (()=> {
151 if (client.player.can_go_previous) {185 if (client.player.can_go_previous) {
152 if(!Thread.supported ()) {186 if(!Thread.supported ()) {
153 warning ("Threading is not supported. DBus timeout could be blocking UI");187 warning ("Threading is not supported. DBus timeout could be blocking UI");
154 try {188 try {
@@ -170,6 +204,7 @@
170 return false;204 return false;
171 });205 });
172 });206 });
207
173 controls.pack_start (btn, false, false, 0);208 controls.pack_start (btn, false, false, 0);
174209
175 btn = make_control_button ("media-playback-start-symbolic");210 btn = make_control_button ("media-playback-start-symbolic");
@@ -197,6 +232,7 @@
197 return false;232 return false;
198 });233 });
199 });234 });
235
200 controls.pack_start (btn, false, false, 0);236 controls.pack_start (btn, false, false, 0);
201237
202 btn = make_control_button ("media-skip-forward-symbolic");238 btn = make_control_button ("media-skip-forward-symbolic");
@@ -225,6 +261,7 @@
225 return false;261 return false;
226 });262 });
227 });263 });
264
228 controls.pack_start (btn, false, false, 0);265 controls.pack_start (btn, false, false, 0);
229266
230 controls.set_halign (Gtk.Align.CENTER);267 controls.set_halign (Gtk.Align.CENTER);
@@ -233,7 +270,6 @@
233270
234 player_box.pack_end (controls, false, false, 0);271 player_box.pack_end (controls, false, false, 0);
235272
236
237 if (client != null) {273 if (client != null) {
238 connect_to_client ();274 connect_to_client ();
239 update_play_status ();275 update_play_status ();
@@ -245,36 +281,6 @@
245 pack_start (player_revealer);281 pack_start (player_revealer);
246 }282 }
247283
248 public void set_client (string name, Services.MprisClient client) {
249 this.mpris_name = name;
250 this.client = client;
251 connect_to_client ();
252 update_play_status ();
253 update_from_meta ();
254 update_controls ();
255 if (launched_by_indicator) {
256 Idle.add (()=> {
257 try {
258 launched_by_indicator = false;
259 client.player.play_pause ();
260 } catch (Error e) {
261 warning ("Could not play/pause: %s", e.message);
262 }
263 return false;
264 });
265 }
266 }
267
268 public void remove_client () {
269 (play_btn.get_image () as Gtk.Image).set_from_icon_name ("media-playback-start-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
270 prev_btn.set_sensitive (false);
271 next_btn.set_sensitive (false);
272 settings.last_title_info = {ainfo.get_id (), title_label.get_text (), artist_label.get_text (), last_artUrl};
273
274 this.client = null;
275 this.mpris_name = "";
276 }
277
278 private void connect_to_client () {284 private void connect_to_client () {
279 client.prop.properties_changed.connect ((i,p,inv)=> {285 client.prop.properties_changed.connect ((i,p,inv)=> {
280 if (i == "org.mpris.MediaPlayer2.Player") {286 if (i == "org.mpris.MediaPlayer2.Player") {
@@ -322,8 +328,8 @@
322 return null;328 return null;
323 });329 });
324 }330 }
325 } else if (ainfo != null) {331 } else if (app_info != null) {
326 ainfo.launch (null, null);332 app_info.launch (null, null);
327 }333 }
328 } catch (Error e) {334 } catch (Error e) {
329 warning ("Could not launch player");335 warning ("Could not launch player");
@@ -355,7 +361,7 @@
355 /**361 /**
356 * Update play status based on player requirements362 * Update play status based on player requirements
357 */363 */
358 void update_play_status () {364 private void update_play_status () {
359 switch (client.player.playback_status) {365 switch (client.player.playback_status) {
360 case "Playing":366 case "Playing":
361 (play_btn.get_image () as Gtk.Image).set_from_icon_name ("media-playback-pause-symbolic", Gtk.IconSize.LARGE_TOOLBAR);367 (play_btn.get_image () as Gtk.Image).set_from_icon_name ("media-playback-pause-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
@@ -370,7 +376,7 @@
370 /**376 /**
371 * Update prev/next sensitivity based on player requirements377 * Update prev/next sensitivity based on player requirements
372 */378 */
373 void update_controls () {379 private void update_controls () {
374 prev_btn.set_sensitive (client.player.can_go_previous);380 prev_btn.set_sensitive (client.player.can_go_previous);
375 next_btn.set_sensitive (client.player.can_go_next);381 next_btn.set_sensitive (client.player.can_go_next);
376 }382 }
@@ -378,7 +384,7 @@
378 /**384 /**
379 * Utility, handle updating the album art385 * Utility, handle updating the album art
380 */386 */
381 void update_art (string uri) {387 private void update_art (string uri) {
382 if (!uri.has_prefix ("file://") && !uri.has_prefix ("http")) {388 if (!uri.has_prefix ("file://") && !uri.has_prefix ("http")) {
383 background.set_from_gicon (app_icon, Gtk.IconSize.DIALOG);389 background.set_from_gicon (app_icon, Gtk.IconSize.DIALOG);
384 return;390 return;
@@ -389,7 +395,7 @@
389 var pbuf = new Gdk.Pixbuf.from_file_at_size (fname, ICON_SIZE, ICON_SIZE);395 var pbuf = new Gdk.Pixbuf.from_file_at_size (fname, ICON_SIZE, ICON_SIZE);
390 background.set_from_pixbuf (mask_pixbuf (pbuf));396 background.set_from_pixbuf (mask_pixbuf (pbuf));
391 } catch (Error e) {397 } catch (Error e) {
392 background.set_from_gicon (app_icon, Gtk.IconSize.DIALOG);398 //background.set_from_gicon (app_icon, Gtk.IconSize.DIALOG);
393 }399 }
394 } else {400 } else {
395 load_remote_art_cancel.cancel ();401 load_remote_art_cancel.cancel ();
@@ -398,7 +404,7 @@
398 }404 }
399 }405 }
400406
401 async void load_remote_art (string uri) {407 private async void load_remote_art (string uri) {
402 GLib.File file = GLib.File.new_for_uri (uri);408 GLib.File file = GLib.File.new_for_uri (uri);
403 try {409 try {
404 GLib.InputStream stream = yield file.read_async (Priority.DEFAULT, load_remote_art_cancel);410 GLib.InputStream stream = yield file.read_async (Priority.DEFAULT, load_remote_art_cancel);
@@ -445,7 +451,7 @@
445 }451 }
446 }452 }
447453
448 static Gdk.Pixbuf? mask_pixbuf (Gdk.Pixbuf pixbuf) {454 private static Gdk.Pixbuf? mask_pixbuf (Gdk.Pixbuf pixbuf) {
449 var size = ICON_SIZE;455 var size = ICON_SIZE;
450 var mask_offset = 4;456 var mask_offset = 4;
451 var mask_size_offset = mask_offset * 2;457 var mask_size_offset = mask_offset * 2;
452458
=== modified file 'src/Widgets/MprisWidget.vala'
--- src/Widgets/MprisWidget.vala 2016-10-23 14:46:21 +0000
+++ src/Widgets/MprisWidget.vala 2016-10-23 14:46:21 +0000
@@ -19,7 +19,7 @@
19 HashTable<string,ClientWidget> ifaces;19 HashTable<string,ClientWidget> ifaces;
20 public signal void close ();20 public signal void close ();
2121
22 public MprisWidget(Services.Settings settings) {22 public MprisWidget() {
23 Object (orientation: Gtk.Orientation.VERTICAL, spacing: 1);23 Object (orientation: Gtk.Orientation.VERTICAL, spacing: 1);
2424
25 ifaces = new HashTable<string,ClientWidget>(str_hash, str_equal);25 ifaces = new HashTable<string,ClientWidget>(str_hash, str_equal);
@@ -31,7 +31,7 @@
3131
32 default_music = AppInfo.get_default_for_type ("audio/x-vorbis+ogg", false);32 default_music = AppInfo.get_default_for_type ("audio/x-vorbis+ogg", false);
33 if (default_music != null) {33 if (default_music != null) {
34 default_widget = new ClientWidget.default (default_music, settings);34 default_widget = new ClientWidget.default (default_music);
3535
36 default_widget.close.connect (() => {36 default_widget.close.connect (() => {
37 close ();37 close ();
@@ -62,7 +62,8 @@
62 */62 */
63 void add_iface (string name, Services.MprisClient iface) {63 void add_iface (string name, Services.MprisClient iface) {
64 if (iface.player.desktop_entry == default_music.get_id ().replace (".desktop","")) {64 if (iface.player.desktop_entry == default_music.get_id ().replace (".desktop","")) {
65 default_widget.set_client (name, iface);65 default_widget.mpris_name = name;
66 default_widget.client = iface;
66 ifaces.insert(name, default_widget);67 ifaces.insert(name, default_widget);
67 default_widget.no_show_all = false;68 default_widget.no_show_all = false;
68 default_widget.visible = true;69 default_widget.visible = true;
@@ -89,7 +90,7 @@
89 */90 */
90 void destroy_iface(string name) {91 void destroy_iface(string name) {
91 if (default_widget.mpris_name == name) {92 if (default_widget.mpris_name == name) {
92 default_widget.remove_client ();93 default_widget.client = null;
93 } else {94 } else {
94 var widg = ifaces[name];95 var widg = ifaces[name];
95 if (widg != null) {96 if (widg != null) {

Subscribers

People subscribed via source and target branches

to all changes: