random songs button
This commit is contained in:
parent
04ae260dc5
commit
31373051ec
5 changed files with 50 additions and 7 deletions
35
src/api.vala
35
src/api.vala
|
@ -22,6 +22,8 @@ errordomain SubsonicError {
|
|||
ERROR
|
||||
}
|
||||
|
||||
public delegate void Wavelet.SongCallback (Song song);
|
||||
|
||||
public class Wavelet.Artist : Object, Json.Serializable {
|
||||
public string index;
|
||||
public string id;
|
||||
|
@ -131,7 +133,7 @@ public struct Wavelet.API.PlayQueue {
|
|||
this.changed_by = reader.get_string_value ();
|
||||
reader.end_member ();
|
||||
|
||||
print("%s %lli %s %s\n",this.current, this.position, this.changed, this.changed_by);
|
||||
//print("%s %lli %s %s\n",this.current, this.position, this.changed, this.changed_by);
|
||||
|
||||
this.songs = new ListStore (typeof (Song));
|
||||
|
||||
|
@ -193,6 +195,7 @@ public class Wavelet.Subsonic : Object {
|
|||
public async void ping () throws Error {
|
||||
var msg = new Soup.Message ("GET", @"$(this.url)/rest/ping?$(this.parameters)");
|
||||
var bytes = yield this.session.send_and_read_async (msg, Priority.DEFAULT, null);
|
||||
assert (msg.get_status () == Soup.Status.OK);
|
||||
|
||||
var parser = new Json.Parser ();
|
||||
parser.load_from_data ((string) bytes.get_data ());
|
||||
|
@ -323,4 +326,34 @@ public class Wavelet.Subsonic : Object {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async void get_random_songs (string? parameters, SongCallback callback) throws Error {
|
||||
string str_parameters;
|
||||
if (parameters == null) {
|
||||
str_parameters = "";
|
||||
} else {
|
||||
str_parameters = @"$parameters&";
|
||||
}
|
||||
|
||||
var msg = new Soup.Message("GET", @"$(this.url)/rest/getRandomSongs?$(str_parameters)size=500&$(this.parameters)");
|
||||
var bytes = yield this.session.send_and_read_async (msg, Priority.DEFAULT, null);
|
||||
assert (msg.get_status () == Soup.Status.OK);
|
||||
|
||||
var parser = new Json.Parser ();
|
||||
parser.load_from_data ((string) bytes.get_data ());
|
||||
|
||||
var reader = new Json.Reader (parser.get_root ());
|
||||
this.unwrap_response (reader);
|
||||
|
||||
reader.read_member ("randomSongs");
|
||||
reader.read_member ("song");
|
||||
|
||||
for (int i = 0; i < reader.count_elements (); i += 1) {
|
||||
reader.read_element (i);
|
||||
callback (new Song (reader));
|
||||
reader.end_element ();
|
||||
}
|
||||
|
||||
assert (reader.get_error () == null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,6 +71,18 @@ public class Wavelet.Application : Adw.Application {
|
|||
win.song_list.set_ready ();
|
||||
});
|
||||
//api.reload.begin ();
|
||||
|
||||
win.shuffle_all_tracks.sensitive = true;
|
||||
win.shuffle_all_tracks.activated.connect (() => {
|
||||
win.shuffle_all_tracks.sensitive = false;
|
||||
win.play_queue.clear ();
|
||||
api.get_random_songs.begin (null, (song) => {
|
||||
win.play_queue.queue (song);
|
||||
}, (obj, res) => {
|
||||
api.get_random_songs.end (res);
|
||||
win.shuffle_all_tracks.sensitive = true;
|
||||
});
|
||||
});
|
||||
});
|
||||
win.setup.load (config_db);
|
||||
}
|
||||
|
|
|
@ -10,15 +10,11 @@ template $WaveletPlayQueue: Adw.NavigationPage {
|
|||
|
||||
ScrolledWindow {
|
||||
ListView list_view {
|
||||
styles [
|
||||
"view",
|
||||
]
|
||||
|
||||
factory: BuilderListItemFactory {
|
||||
template ListItem {
|
||||
child: Label {
|
||||
halign: start;
|
||||
label: bind template.item as <$WaveletSong>.name;
|
||||
label: bind template.item as <$WaveletSong>.title;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
|
@ -53,9 +53,10 @@ template $WaveletWindow: Adw.ApplicationWindow {
|
|||
"navigation-sidebar",
|
||||
]
|
||||
|
||||
Adw.ButtonRow {
|
||||
Adw.ButtonRow shuffle_all_tracks {
|
||||
title: _("Shuffle all tracks");
|
||||
start-icon-name: "media-playlist-shuffle";
|
||||
sensitive: false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -29,6 +29,7 @@ public class Wavelet.Window : Adw.ApplicationWindow {
|
|||
[GtkChild] public unowned Wavelet.ArtistList artist_list;
|
||||
[GtkChild] public unowned Wavelet.SongList song_list;
|
||||
[GtkChild] public unowned Wavelet.PlayQueue play_queue;
|
||||
[GtkChild] public unowned Adw.ButtonRow shuffle_all_tracks;
|
||||
|
||||
public Window (Gtk.Application app) {
|
||||
Object (application: app);
|
||||
|
|
Loading…
Reference in a new issue