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::Empty:
|
||||||
case Engine::Idle: {
|
case Engine::Idle: {
|
||||||
int i = playlist_->current_index();
|
|
||||||
if (i == -1) {
|
|
||||||
if (playlist_->rowCount() == 0)
|
if (playlist_->rowCount() == 0)
|
||||||
break;
|
break;
|
||||||
i = 0;
|
|
||||||
}
|
int i = playlist_->current_index();
|
||||||
|
if (i == -1) i = playlist_->last_played_index();
|
||||||
|
if (i == -1) i = 0;
|
||||||
|
|
||||||
PlayAt(i, false);
|
PlayAt(i, false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,6 +190,10 @@ int Playlist::current_index() const {
|
||||||
return current_item_.isValid() ? current_item_.row() : -1;
|
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) {
|
void Playlist::ShuffleModeChanged(PlaylistSequence::ShuffleMode mode) {
|
||||||
is_shuffled_ = (mode != PlaylistSequence::Shuffle_Off);
|
is_shuffled_ = (mode != PlaylistSequence::Shuffle_Off);
|
||||||
ReshuffleIndices();
|
ReshuffleIndices();
|
||||||
|
@ -266,6 +270,8 @@ void Playlist::set_current_index(int i) {
|
||||||
ClearStreamMetadata();
|
ClearStreamMetadata();
|
||||||
|
|
||||||
current_item_ = QPersistentModelIndex(index(i, 0, QModelIndex()));
|
current_item_ = QPersistentModelIndex(index(i, 0, QModelIndex()));
|
||||||
|
last_played_item_ = old_current;
|
||||||
|
Save();
|
||||||
|
|
||||||
if (old_current.isValid())
|
if (old_current.isValid())
|
||||||
emit dataChanged(old_current, old_current.sibling(old_current.row(), ColumnCount));
|
emit dataChanged(old_current, old_current.sibling(old_current.row(), ColumnCount));
|
||||||
|
@ -624,6 +630,8 @@ void Playlist::Save() const {
|
||||||
items_.at(i)->Save(s);
|
items_.at(i)->Save(s);
|
||||||
}
|
}
|
||||||
s.endArray();
|
s.endArray();
|
||||||
|
|
||||||
|
s.setValue("last_index", last_played_index());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Playlist::Restore() {
|
void Playlist::Restore() {
|
||||||
|
@ -650,6 +658,8 @@ void Playlist::Restore() {
|
||||||
s.endArray();
|
s.endArray();
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
|
last_played_item_ = index(s.value("last_index", -1).toInt(), 0, QModelIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Playlist::removeRows(int row, int count, const QModelIndex& parent) {
|
bool Playlist::removeRows(int row, int count, const QModelIndex& parent) {
|
||||||
|
|
|
@ -77,10 +77,12 @@ class Playlist : public QAbstractListModel {
|
||||||
|
|
||||||
// Persistence
|
// Persistence
|
||||||
void Save() const;
|
void Save() const;
|
||||||
|
void SaveLast() const;
|
||||||
void Restore();
|
void Restore();
|
||||||
|
|
||||||
// Accessors
|
// Accessors
|
||||||
int current_index() const;
|
int current_index() const;
|
||||||
|
int last_played_index() const;
|
||||||
int next_index() const;
|
int next_index() const;
|
||||||
int previous_index() const;
|
int previous_index() const;
|
||||||
bool stop_after_current() const;
|
bool stop_after_current() const;
|
||||||
|
@ -156,6 +158,7 @@ class Playlist : public QAbstractListModel {
|
||||||
// that they will be played.
|
// that they will be played.
|
||||||
|
|
||||||
QPersistentModelIndex current_item_;
|
QPersistentModelIndex current_item_;
|
||||||
|
QPersistentModelIndex last_played_item_;
|
||||||
QPersistentModelIndex stop_after_;
|
QPersistentModelIndex stop_after_;
|
||||||
bool current_is_paused_;
|
bool current_is_paused_;
|
||||||
int current_virtual_index_;
|
int current_virtual_index_;
|
||||||
|
|
Loading…
Reference in New Issue