Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 last song played by 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
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 @@ -530,6 +530,9 @@ public class Music.PlaybackManager : Object {
update_next_previous_sensitivity ();

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 @@ -544,6 +547,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 @@ -555,5 +562,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);
}
}
}