mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-31 11:35:24 +01:00
Remember which track was being played last. Fixes issue #56
This commit is contained in:
parent
a25fd395f1
commit
e755868b74
@ -141,12 +141,13 @@ void Player::PlayPause() {
|
||||
|
||||
case Engine::Empty:
|
||||
case Engine::Idle: {
|
||||
int i = playlist_->current_index();
|
||||
if (i == -1) {
|
||||
if (playlist_->rowCount() == 0)
|
||||
break;
|
||||
i = 0;
|
||||
}
|
||||
if (playlist_->rowCount() == 0)
|
||||
break;
|
||||
|
||||
int i = playlist_->current_index();
|
||||
if (i == -1) i = playlist_->last_played_index();
|
||||
if (i == -1) i = 0;
|
||||
|
||||
PlayAt(i, false);
|
||||
break;
|
||||
}
|
||||
|
@ -190,6 +190,10 @@ int Playlist::current_index() const {
|
||||
return current_item_.isValid() ? current_item_.row() : -1;
|
||||
}
|
||||
|
||||
int Playlist::last_played_index() const {
|
||||
return last_played_item_.isValid() ? last_played_item_.row() : -1;
|
||||
}
|
||||
|
||||
void Playlist::ShuffleModeChanged(PlaylistSequence::ShuffleMode mode) {
|
||||
is_shuffled_ = (mode != PlaylistSequence::Shuffle_Off);
|
||||
ReshuffleIndices();
|
||||
@ -266,6 +270,8 @@ void Playlist::set_current_index(int i) {
|
||||
ClearStreamMetadata();
|
||||
|
||||
current_item_ = QPersistentModelIndex(index(i, 0, QModelIndex()));
|
||||
last_played_item_ = old_current;
|
||||
Save();
|
||||
|
||||
if (old_current.isValid())
|
||||
emit dataChanged(old_current, old_current.sibling(old_current.row(), ColumnCount));
|
||||
@ -624,6 +630,8 @@ void Playlist::Save() const {
|
||||
items_.at(i)->Save(s);
|
||||
}
|
||||
s.endArray();
|
||||
|
||||
s.setValue("last_index", last_played_index());
|
||||
}
|
||||
|
||||
void Playlist::Restore() {
|
||||
@ -650,6 +658,8 @@ void Playlist::Restore() {
|
||||
s.endArray();
|
||||
|
||||
reset();
|
||||
|
||||
last_played_item_ = index(s.value("last_index", -1).toInt(), 0, QModelIndex());
|
||||
}
|
||||
|
||||
bool Playlist::removeRows(int row, int count, const QModelIndex& parent) {
|
||||
|
@ -77,10 +77,12 @@ class Playlist : public QAbstractListModel {
|
||||
|
||||
// Persistence
|
||||
void Save() const;
|
||||
void SaveLast() const;
|
||||
void Restore();
|
||||
|
||||
// Accessors
|
||||
int current_index() const;
|
||||
int last_played_index() const;
|
||||
int next_index() const;
|
||||
int previous_index() const;
|
||||
bool stop_after_current() const;
|
||||
@ -156,6 +158,7 @@ class Playlist : public QAbstractListModel {
|
||||
// that they will be played.
|
||||
|
||||
QPersistentModelIndex current_item_;
|
||||
QPersistentModelIndex last_played_item_;
|
||||
QPersistentModelIndex stop_after_;
|
||||
bool current_is_paused_;
|
||||
int current_virtual_index_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user