Changes
4 changed files (+70/-68)
-
-
@@ -19,16 +19,8 @@ public errordomain ZonesModelError {SUBSCRIPTION_FAILED, } public class ZoneModel : Object { public Roon.Transport.Zone zone { get; set construct; } public ZoneModel(Roon.Transport.Zone zone) { Object(zone: zone); } public static bool is_same_zone(ZoneModel a, ZoneModel b) { return a.zone.zone_id == b.zone.zone_id; } private static bool is_same_zone(Roon.Transport.Zone a, Roon.Transport.Zone b) { return a.zone_id == b.zone_id; } public class ZonesModel : Object {
-
@@ -45,21 +37,21 @@ get; construct;} private uint zone_position = 0; public ZoneModel? zone { public Roon.Transport.Zone? zone { owned get { return (ZoneModel?) zones.get_item(zone_position); return (Roon.Transport.Zone?) zones.get_item(zone_position); } set { uint position; if (zones.find_with_equal_func(value, (GLib.EqualFunc<ZoneModel>) ZoneModel.is_same_zone, out position)) { if (zones.find_with_equal_func(value, (GLib.EqualFunc<Roon.Transport.Zone>) is_same_zone, out position)) { zone_position = position; } } } public ZonesModel(Connection conn) { Object(conn: conn, zones: new GLib.ListStore(typeof (ZoneModel))); Object(conn: conn, zones: new GLib.ListStore(typeof (Roon.Transport.Zone))); } construct {
-
@@ -100,10 +92,9 @@ throw new ZonesModelError.SUBSCRIPTION_FAILED("Got invalid subscription response.");} foreach (var zone in result.zones) { var model = new ZoneModel(zone); zones.append(model); zones.append(zone); if (this.zone == null) { this.zone = model; this.zone = zone; } }
-
@@ -137,60 +128,56 @@ }foreach (var id in event.removed_zone_ids) { for (uint i = 0; i < zones.n_items; i++) { var model = (ZoneModel) zones.get_item(i); if (model.zone.zone_id == id) { GLib.log("Plac", LEVEL_DEBUG, "Zone removed: %s", model.zone.display_name); var zone = (Roon.Transport.Zone) zones.get_item(i); if (zone.zone_id == id) { GLib.log("Plac", LEVEL_DEBUG, "Zone removed: %s", zone.display_name); zones.remove(i); this.removed(model.zone); this.removed(zone); break; } } } foreach (var added in event.added_zones) { var new_model = new ZoneModel(added); // Roon behaves pretty badly in state updates: they send // an "added" event initially. Subscribe method's response // already contains those zones. uint position; if (zones.find_with_equal_func(new_model, (GLib.EqualFunc<ZoneModel>) ZoneModel.is_same_zone, out position)) { var model = (ZoneModel) zones.get_item(position); model.zone = added; this.changed(added); if (zones.find_with_equal_func(added, (GLib.EqualFunc<Roon.Transport.Zone>) is_same_zone, out position)) { var zone = (Roon.Transport.Zone) zones.get_item(position); zone.update(added); this.changed(zone); } else { GLib.log("Plac", LEVEL_DEBUG, "New zone added: %s", added.display_name); zones.append(new_model); zones.append(added); this.added(added); } } foreach (var changed in event.changed_zones) { var new_model = new ZoneModel(changed); // We might have missed an "added" event, so make sure // we safely handle change events to unknown zones. uint position; if (zones.find_with_equal_func(new_model, (GLib.EqualFunc<ZoneModel>) ZoneModel.is_same_zone, out position)) { var model = (ZoneModel) zones.get_item(position); model.zone = changed; this.changed(changed); if (zones.find_with_equal_func(changed, (GLib.EqualFunc<Roon.Transport.Zone>) is_same_zone, out position)) { var zone = (Roon.Transport.Zone) zones.get_item(position); zone.update(changed); this.changed(zone); } else { GLib.log("Plac", LEVEL_DEBUG, "New zone added by change event: %s", changed.display_name); zones.append(new_model); zones.append(changed); this.added(changed); } } foreach (var seek_change in event.seek_changes) { for (uint i = 0; i < zones.n_items; i++) { var model = (ZoneModel) zones.get_item(i); if (model.zone.zone_id == seek_change.zone_id && model.zone.now_playing != null) { var zone = (Roon.Transport.Zone) zones.get_item(i); if (zone.zone_id == seek_change.zone_id && zone.now_playing != null) { if (seek_change.has_seek_position) { model.zone.now_playing.has_seek_position = true; model.zone.now_playing.seek_position = seek_change.seek_position; zone.now_playing.has_seek_position = true; zone.now_playing.seek_position = seek_change.seek_position; } else { model.zone.now_playing.has_seek_position = false; zone.now_playing.has_seek_position = false; } this.seek(seek_change); break;
-
-
-
@@ -21,15 +21,15 @@ namespace Roon {namespace Transport { public class Zone : Object { public string zone_id { get; construct; } public string display_name { get; construct; } public Array<Output> outputs { get; construct; } public NowPlaying? now_playing { get; construct; } public PlaybackState state { get; construct; } public bool is_next_allowed { get; construct; } public bool is_previous_allowed { get; construct; } public bool is_pause_allowed { get; construct; } public bool is_play_allowed { get; construct; } public bool is_seek_allowed { get; construct; } public string display_name { get; set construct; } public Array<Output> outputs { get; set construct; } public NowPlaying? now_playing { get; set construct; } public PlaybackState state { get; set construct; } public bool is_next_allowed { get; set construct; } public bool is_previous_allowed { get; set construct; } public bool is_pause_allowed { get; set construct; } public bool is_play_allowed { get; set construct; } public bool is_seek_allowed { get; set construct; } internal Zone.from_json_node(Json.Node node, FieldPath? obj_path = null) throws Error { var obj = get_object(node, obj_path);
-
@@ -111,6 +111,21 @@ is_pause_allowed: is_pause_allowed,is_play_allowed: is_play_allowed, is_seek_allowed: is_seek_allowed ); } /** * Copy `other`'s fields into this. */ public void update(Zone other) { this.display_name = other.display_name; this.outputs = other.outputs; this.now_playing = other.now_playing; this.state = other.state; this.is_next_allowed = other.is_next_allowed; this.is_previous_allowed = other.is_previous_allowed; this.is_pause_allowed = other.is_pause_allowed; this.is_play_allowed = other.is_play_allowed; this.is_seek_allowed = other.is_seek_allowed; } } }
-
-
-
@@ -58,12 +58,12 @@public Roon.Browse.Hierarchy hierarchy { get; set; default = BROWSE; } public Plac.ZonesModel? zones_model { get; set; default = null; } public Roon.Transport.Zone? zone { get { owned get { if (zones_model == null || zones_model.zone == null) { return null; } return zones_model.zone.zone; return zones_model.zone; } }
-
-
-
@@ -70,9 +70,9 @@ private bool is_seeking = false;private int64? next_seek = null; private Settings settings = new Settings(); private Plac.ZoneModel? watching_zone = null; private Roon.Transport.Zone? watching_zone = null; private Plac.ZoneModel? selected_zone { private Roon.Transport.Zone? selected_zone { owned get { if (zones_model == null) { return null;
-
@@ -87,7 +87,7 @@ return;} zones_model.zone = value; zone_selected(value.zone); zone_selected(value); next_seek = null; } }
-
@@ -110,12 +110,12 @@ zones_model.notify["zone"].connect(() => {this.render(); if (watching_zone != null) { watching_zone.notify["zone"].disconnect(this.render); watching_zone.notify.disconnect(this.render); watching_zone = null; } if (zones_model.zone != null) { zones_model.zone.notify["zone"].connect(this.render); zones_model.zone.notify.connect(this.render); } });
-
@@ -135,16 +135,16 @@zone_list_factory.bind.connect((item) => { var list_item = (Gtk.ListItem) item; var label = (Gtk.Label) list_item.child; var model = (Plac.ZoneModel) list_item.item; label.label = model.zone.display_name; var zone = (Roon.Transport.Zone) list_item.item; label.label = zone.display_name; }); zone_list.factory = zone_list_factory; zone_list.notify["selected"].connect(() => { var model = (Plac.ZoneModel) zones_model.zones.get_item(zone_list.selected); if (model != null) { this.selected_zone = model; var zone = (Roon.Transport.Zone) zones_model.zones.get_item(zone_list.selected); if (zone != null) { this.selected_zone = zone; this.render(); } });
-
@@ -155,7 +155,7 @@ return;} this.disable_actions(); this.control_async.begin(conn, selected_zone.zone, PLAY, (_obj, res) => { this.control_async.begin(conn, selected_zone, PLAY, (_obj, res) => { try { this.control_async.end(res); } catch (GLib.Error error) {
-
@@ -172,7 +172,7 @@ return;} this.disable_actions(); this.control_async.begin(conn, selected_zone.zone, PAUSE, (_obj, res) => { this.control_async.begin(conn, selected_zone, PAUSE, (_obj, res) => { try { this.control_async.end(res); } catch (GLib.Error error) {
-
@@ -189,7 +189,7 @@ return;} this.disable_actions(); this.control_async.begin(conn, selected_zone.zone, PREVIOUS, (_obj, res) => { this.control_async.begin(conn, selected_zone, PREVIOUS, (_obj, res) => { try { this.control_async.end(res); } catch (GLib.Error error) {
-
@@ -206,7 +206,7 @@ return;} this.disable_actions(); this.control_async.begin(conn, selected_zone.zone, NEXT, (_obj, res) => { this.control_async.begin(conn, selected_zone, NEXT, (_obj, res) => { try { this.control_async.end(res); } catch (GLib.Error error) {
-
@@ -251,7 +251,7 @@var position = next_seek; next_seek = null; seek_async.begin(conn, selected_zone.zone, position, (_obj, res) => { seek_async.begin(conn, selected_zone, position, (_obj, res) => { try { seek_async.end(res); } catch (GLib.Error error) {
-
@@ -286,7 +286,7 @@ return "%02u:%02u:%02u".printf((uint) h, (uint) m, (uint) s);} private void update_seek(Roon.Transport.SeekChange change) { if (selected_zone == null || selected_zone.zone.zone_id != change.zone_id) { if (selected_zone == null || selected_zone.zone_id != change.zone_id) { return; }
-
@@ -303,7 +303,7 @@ pause.visible = false;return; } var zone = selected_zone.zone; var zone = selected_zone; play.sensitive = zone.is_play_allowed; pause.sensitive = zone.is_pause_allowed;
-