Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions data/music.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
<summary>An index representing the repeat mode</summary>
<description>An index representing the repeat mode</description>
</key>
<key type="as" name="previous-queue">
<default>['']</default>
<summary>The queue from last session to restore</summary>
<description>An array of strings representing the files played last</description>
</key>

<key name="window-height" type="i">
<default>475</default>
Expand Down
4 changes: 4 additions & 0 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public class Music.Application : Gtk.Application {
}

settings.bind ("window-maximized", main_window, "maximized", SettingsBindFlags.SET);

// This needs to be done after window is constructed
// Else music plays but the queue seems empty
playback_manager.restore_queue ();
}

private static File[] list_directory (string directory) {
Expand Down
27 changes: 27 additions & 0 deletions src/PlaybackManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class Music.PlaybackManager : Object {
private PlaybackManager () {}

construct {
settings = new Settings ("io.elementary.music");
queue_liststore = new ListStore (typeof (AudioObject));

playbin = Gst.ElementFactory.make ("playbin", "playbin");
Expand Down Expand Up @@ -455,4 +456,30 @@ public class Music.PlaybackManager : Object {
var play_pause_action = (SimpleAction) GLib.Application.get_default ().lookup_action (Application.ACTION_PLAY_PAUSE);
play_pause_action.set_enabled (current_audio != null);
}

public void save_queue () {
Comment thread
teamcons marked this conversation as resolved.
Outdated
Comment thread
teamcons marked this conversation as resolved.
Outdated
// Save current queue in gsettings
string[] list_uri = new string[queue_liststore.n_items];

for (var i = 0; i < queue_liststore.n_items; i++) {
var item = (Music.AudioObject)queue_liststore.get_item (i);
list_uri[i] = item.uri;
}

settings.set_strv ("previous-queue", list_uri);
}

public void restore_queue () {
var last_session_uri = settings.get_strv ("previous-queue");
var last_session_files = new File[last_session_uri.length];

for (var i = 0; i < last_session_uri.length; i++) {
var uri = last_session_uri[i];
var file = File.new_for_uri (uri);
last_session_files[i] = file;
}

var files_to_play = Application.loop_through_files (last_session_files);
queue_files (files_to_play);
}
}