Skip to content

Commit ec2bb03

Browse files
committed
unbind properly
1 parent c512dcf commit ec2bb03

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

src/MainWindow.vala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ public class Music.MainWindow : Gtk.ApplicationWindow {
223223
((TrackRow) list_item.child).audio_object = (AudioObject) list_item.item;
224224
});
225225

226+
factory.unbind.connect ((obj) => {
227+
var list_item = (Gtk.ListItem) obj;
228+
((TrackRow) list_item.child).audio_object = null;
229+
});
230+
226231
queue_listview.activate.connect ((index) => {
227232
playback_manager.current_audio = (AudioObject) selection_model.get_item (index);
228233
});

src/Widgets/TrackRow.vala

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,41 @@
44
*/
55

66
public class Music.TrackRow : Granite.Bin {
7-
public AudioObject audio_object { get; set ; }
7+
private AudioObject _audio_object = null;
8+
public AudioObject audio_object {
9+
get {
10+
return _audio_object;
11+
}
12+
13+
set {
14+
if (_audio_object != null) {
15+
artist_binding.unbind ();
16+
texture_binding.unbind ();
17+
title_binding.unbind ();
18+
}
19+
20+
_audio_object = value;
21+
22+
if (_audio_object == null) {
23+
return;
24+
}
25+
26+
artist_binding = _audio_object.bind_property ("artist", artist_label, "label", SYNC_CREATE);
27+
title_binding = _audio_object.bind_property ("title", title_label, "label", SYNC_CREATE);
28+
texture_binding = _audio_object.bind_property ("texture", album_image.image, "paintable", SYNC_CREATE);
29+
}
30+
}
831

932
private static PlaybackManager playback_manager;
1033

34+
private Binding artist_binding;
35+
private Binding texture_binding;
36+
private Binding title_binding;
37+
38+
private Gtk.Label artist_label;
39+
private Gtk.Label title_label;
1140
private Gtk.Spinner play_icon;
41+
private Music.AlbumImage album_image;
1242

1343
static construct {
1444
playback_manager = PlaybackManager.get_default ();
@@ -18,17 +48,17 @@ public class Music.TrackRow : Granite.Bin {
1848
play_icon = new Gtk.Spinner ();
1949
play_icon.add_css_class ("play-indicator");
2050

21-
var album_image = new Music.AlbumImage ();
51+
album_image = new Music.AlbumImage ();
2252
album_image.image.height_request = 32;
2353
album_image.image.width_request = 32;
2454

25-
var title_label = new Gtk.Label (null) {
55+
title_label = new Gtk.Label (null) {
2656
ellipsize = Pango.EllipsizeMode.MIDDLE,
2757
hexpand = true,
2858
xalign = 0
2959
};
3060

31-
var artist_label = new Gtk.Label (null) {
61+
artist_label = new Gtk.Label (null) {
3262
ellipsize = Pango.EllipsizeMode.MIDDLE,
3363
hexpand = true,
3464
xalign = 0
@@ -64,10 +94,6 @@ public class Music.TrackRow : Granite.Bin {
6494
});
6595

6696
notify["audio-object"].connect (() => {
67-
audio_object.bind_property ("artist", artist_label, "label", SYNC_CREATE);
68-
audio_object.bind_property ("title", title_label, "label", SYNC_CREATE);
69-
audio_object.bind_property ("texture", album_image.image, "paintable", SYNC_CREATE);
70-
7197
play_icon.spinning = playback_manager.current_audio == audio_object;
7298
});
7399
}

0 commit comments

Comments
 (0)