Skip to content

Commit

Permalink
#32: added count of connected slaves (like in the SoundTouch mobile app)
Browse files Browse the repository at this point in the history
  • Loading branch information
syfds committed Jun 2, 2021
1 parent 9c2a356 commit 523a38f
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Widget/SpeakerPanel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,17 @@ public class SpeakerPanel : Gtk.Box {
return s.hostname != speaker.hostname;
});

var speaker_item = new SpeakerItemView(speaker, without_current_speaker);
uint count_connected_slaves = 0;
if (speaker.is_master) {
speaker_list.foreach(s => {
if (s.hostname != speaker.hostname && s.is_in_zone && s.master_device_id == speaker.device_id) {
count_connected_slaves++;
}
return true;
});
}

var speaker_item = new SpeakerItemView(speaker, without_current_speaker, count_connected_slaves);
speaker_item.halign = Gtk.Align.CENTER;
speaker_item.connect_clicked.connect((speaker) => {
Soundy.Util.execute_in_new_thread("connect to speaker", () => {
Expand Down Expand Up @@ -266,6 +276,7 @@ public class SpeakerPanel : Gtk.Box {
speaker.device_id = speaker_info.device_id;
speaker.ip_address = speaker_info.ip_address;
speaker.is_in_zone = zone_info.is_in_zone();
speaker.master_device_id = zone_info.master_mac_address;
}
}

Expand All @@ -277,7 +288,7 @@ public class SpeakerItemView: Gtk.Box {

public Speaker speaker {get;construct;}

public SpeakerItemView(Speaker speaker, Gee.Iterator<Speaker> available_speaker) {
public SpeakerItemView(Speaker speaker, Gee.Iterator<Speaker> available_speaker, uint count_connected_slaves) {
Object(
speaker: speaker
);
Expand Down Expand Up @@ -315,7 +326,7 @@ public class SpeakerItemView: Gtk.Box {
var master_speaker_in_zone = Soundy.Util.create_icon("user-available", 16);
master_speaker_in_zone.halign = Gtk.Align.CENTER;
master_speaker_in_zone.valign = Gtk.Align.CENTER;
speaker_panel.attach(master_speaker_in_zone, 1, 1, 1, 1);
speaker_panel.attach(Soundy.Util.create_label("+" + count_connected_slaves.to_string()), 1, 1, 1, 1);
} else {
var remove_from_zone_button = Soundy.Util.create_button("list-remove-symbolic", 16);
remove_from_zone_button.tooltip_text = _("Remove from zone");
Expand Down Expand Up @@ -386,6 +397,7 @@ public class Speaker : Object {
public string hostname {get;set;}
public string device_id {get;set;}
public string ip_address {get;set;}
public string master_device_id {get;set; default="";}
public bool is_master {get;set;default=false;}
public bool is_in_zone {get;set;default=false;}

Expand Down

0 comments on commit 523a38f

Please sign in to comment.