audrey/src/song_list.vala

86 lines
3.4 KiB
Vala
Raw Normal View History

2024-10-06 11:21:53 +00:00
/* song_list.vala
*
* Copyright 2024 Erica Z
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
[GtkTemplate (ui = "/eu/callcc/Wavelet/song_list.ui")]
public class Wavelet.SongList : Adw.NavigationPage {
[GtkChild] private unowned Gtk.Stack stack;
[GtkChild] private unowned Gtk.ColumnView column_view;
[GtkChild] private unowned Gtk.ColumnViewColumn title_column;
[GtkChild] private unowned Gtk.ColumnViewColumn album_column;
[GtkChild] private unowned Gtk.ColumnViewColumn artist_column;
[GtkChild] private unowned Gtk.ColumnViewColumn track_column;
public ListModel model {
set {
this.column_view.model = new Gtk.SingleSelection (
new Gtk.SortListModel (value, this.column_view.sorter));
}
}
construct {
this.title_column.sorter = new Gtk.StringSorter (
new Gtk.PropertyExpression (typeof (Song), null, "title"));
this.album_column.sorter = new Gtk.StringSorter (
new Gtk.PropertyExpression (typeof (Song), null, "album"));
this.artist_column.sorter = new Gtk.StringSorter (
new Gtk.PropertyExpression (typeof (Song), null, "artist"));
this.track_column.sorter = new Gtk.NumericSorter (
new Gtk.PropertyExpression (typeof (Song), null, "track"));
((Gtk.SignalListItemFactory) this.title_column.factory).bind.connect ((item) => {
var list_item = (Gtk.ListItem) item;
var song = (Song) list_item.item;
list_item.child = new Gtk.Label (song.title) {
halign = Gtk.Align.START,
};
});
((Gtk.SignalListItemFactory) this.album_column.factory).bind.connect ((item) => {
var list_item = (Gtk.ListItem) item;
var song = (Song) list_item.item;
list_item.child = new Gtk.Label (song.album) {
halign = Gtk.Align.START,
};
});
((Gtk.SignalListItemFactory) this.artist_column.factory).bind.connect ((item) => {
var list_item = (Gtk.ListItem) item;
var song = (Song) list_item.item;
list_item.child = new Gtk.Label (song.artist) {
halign = Gtk.Align.START,
};
});
((Gtk.SignalListItemFactory) this.track_column.factory).bind.connect ((item) => {
var list_item = (Gtk.ListItem) item;
var song = (Song) list_item.item;
list_item.child = new Gtk.Label (song.track.to_string ()) {
halign = Gtk.Align.START,
};
});
}
public void set_loading () {
this.stack.visible_child_name = "loading";
}
public void set_ready () {
this.stack.visible_child_name = "ready";
}
}