Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 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 @@ -17,6 +17,11 @@
<summary>The queue from last session to restore</summary>
<description>An array of strings representing the files played last</description>
</key>
<key type="s" name="uri-last-played">
<default>''</default>
<summary>The item that was playing when the user closed Music</summary>
<description>A string representing the uri of the last played music file</description>
</key>

<key name="window-height" type="i">
<default>475</default>
Expand Down
2 changes: 0 additions & 2 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ 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 ();
}

Expand Down
4 changes: 4 additions & 0 deletions src/AudioObject.vala
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ public class Music.AudioObject : Object {
public AudioObject (string uri) {
Object (uri: uri);
}

public static bool equal_func (AudioObject a, AudioObject b) {
return (a.uri == b.uri);
}
}
21 changes: 21 additions & 0 deletions src/PlaybackManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ 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);

var uri_last_played = current_audio != null ? current_audio.uri : "";
settings.set_string ("uri-last-played", uri_last_played);
}

private void save_queue () {
Expand All @@ -519,6 +522,10 @@ public class Music.PlaybackManager : Object {
}

public void restore_queue () {
// Restoring the queue overwrites the last played. So we need to retrieve it before taking care of the queue
var uri_last_played = settings.get_string ("uri-last-played");
var file_last_played = File.new_for_uri (uri_last_played);

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

Expand All @@ -530,5 +537,19 @@ public class Music.PlaybackManager : Object {

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

if (uri_last_played != "" && file_last_played.query_exists ()) {
var audio_object = new AudioObject (uri_last_played);
uint position = -1;
if (!queue_liststore.find_with_equal_func (
audio_object,
(EqualFunc<AudioObject>) AudioObject.equal_func,
out position
)) {
return;
}

current_audio = (AudioObject) queue_liststore.get_item (position);
}
}
}