Playlist fixes
- Fix bug resetting playlist view columns to show all when using more than one playlist. - Add queue to play next
This commit is contained in:
@@ -657,7 +657,7 @@ bool Playlist::dropMimeData(const QMimeData *data, Qt::DropAction action, int ro
|
||||
// Dragged from a collection
|
||||
// We want to check if these songs are from the actual local file backend, if they are we treat them differently.
|
||||
if (song_data->backend && song_data->backend->songs_table() == SCollection::kSongsTable)
|
||||
InsertSongItems<CollectionPlaylistItem>(song_data->songs, row, play_now, enqueue_now);
|
||||
InsertSongItems<CollectionPlaylistItem>(song_data->songs, row, play_now, enqueue_now, enqueue_next_now);
|
||||
else
|
||||
InsertSongItems<SongPlaylistItem>(song_data->songs, row, play_now, enqueue_now, enqueue_next_now);
|
||||
}
|
||||
@@ -700,7 +700,7 @@ bool Playlist::dropMimeData(const QMimeData *data, Qt::DropAction action, int ro
|
||||
|
||||
if (items.count() > kUndoItemLimit) {
|
||||
// Too big to keep in the undo stack. Also clear the stack because it might have been invalidated.
|
||||
InsertItemsWithoutUndo(items, row, false);
|
||||
InsertItemsWithoutUndo(items, row, false, false);
|
||||
undo_stack_->clear();
|
||||
}
|
||||
else {
|
||||
@@ -718,11 +718,11 @@ bool Playlist::dropMimeData(const QMimeData *data, Qt::DropAction action, int ro
|
||||
else if (data->hasFormat(kCddaMimeType)) {
|
||||
SongLoaderInserter *inserter = new SongLoaderInserter(task_manager_, collection_, backend_->app()->player());
|
||||
connect(inserter, SIGNAL(Error(QString)), SIGNAL(Error(QString)));
|
||||
inserter->LoadAudioCD(this, row, play_now, enqueue_now);
|
||||
inserter->LoadAudioCD(this, row, play_now, enqueue_now, enqueue_next_now);
|
||||
}
|
||||
else if (data->hasUrls()) {
|
||||
// URL list dragged from the file list or some other app
|
||||
InsertUrls(data->urls(), row, play_now, enqueue_now);
|
||||
InsertUrls(data->urls(), row, play_now, enqueue_now, enqueue_next_now);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -734,7 +734,7 @@ void Playlist::InsertUrls(const QList<QUrl> &urls, int pos, bool play_now, bool
|
||||
SongLoaderInserter *inserter = new SongLoaderInserter(task_manager_, collection_, backend_->app()->player());
|
||||
connect(inserter, SIGNAL(Error(QString)), SIGNAL(Error(QString)));
|
||||
|
||||
inserter->Load(this, pos, play_now, enqueue, urls);
|
||||
inserter->Load(this, pos, play_now, enqueue, enqueue_next, urls);
|
||||
|
||||
}
|
||||
|
||||
@@ -891,17 +891,17 @@ void Playlist::InsertItems(const PlaylistItemList &itemsIn, int pos, bool play_n
|
||||
|
||||
if (items.count() > kUndoItemLimit) {
|
||||
// Too big to keep in the undo stack. Also clear the stack because it might have been invalidated.
|
||||
InsertItemsWithoutUndo(items, pos, enqueue);
|
||||
InsertItemsWithoutUndo(items, pos, enqueue, enqueue_next);
|
||||
undo_stack_->clear();
|
||||
} else {
|
||||
undo_stack_->push(new PlaylistUndoCommands::InsertItems(this, items, pos, enqueue));
|
||||
undo_stack_->push(new PlaylistUndoCommands::InsertItems(this, items, pos, enqueue, enqueue_next));
|
||||
}
|
||||
|
||||
if (play_now) emit PlayRequested(index(start, 0));
|
||||
|
||||
}
|
||||
|
||||
void Playlist::InsertItemsWithoutUndo(const PlaylistItemList &items, int pos, bool enqueue) {
|
||||
void Playlist::InsertItemsWithoutUndo(const PlaylistItemList &items, int pos, bool enqueue, bool enqueue_next) {
|
||||
|
||||
if (items.isEmpty()) return;
|
||||
|
||||
@@ -937,6 +937,14 @@ void Playlist::InsertItemsWithoutUndo(const PlaylistItemList &items, int pos, bo
|
||||
queue_->ToggleTracks(indexes);
|
||||
}
|
||||
|
||||
if (enqueue_next) {
|
||||
QModelIndexList indexes;
|
||||
for (int i = start; i <= end; ++i) {
|
||||
indexes << index(i, 0);
|
||||
}
|
||||
queue_->InsertFirst(indexes);
|
||||
}
|
||||
|
||||
Save();
|
||||
ReshuffleIndices();
|
||||
|
||||
@@ -1110,6 +1118,7 @@ bool Playlist::CompareItems(int column, Qt::SortOrder order, shared_ptr<Playlist
|
||||
|
||||
case Column_Comment: strcmp(comment);
|
||||
case Column_Source: cmp(source);
|
||||
default: qLog(Error) << "No such column" << column;
|
||||
}
|
||||
|
||||
#undef cmp
|
||||
@@ -1165,7 +1174,7 @@ QString Playlist::column_name(Column column) {
|
||||
|
||||
case Column_Comment: return tr("Comment");
|
||||
case Column_Source: return tr("Source");
|
||||
default: return QString();
|
||||
default: qLog(Error) << "No such column" << column;;
|
||||
}
|
||||
return "";
|
||||
|
||||
@@ -1263,10 +1272,6 @@ void Playlist::Save() const {
|
||||
|
||||
}
|
||||
|
||||
//namespace {
|
||||
//typedef QFutureWatcher<QList<PlaylistItemPtr>> PlaylistItemFutureWatcher;
|
||||
//}
|
||||
|
||||
void Playlist::Restore() {
|
||||
|
||||
if (!backend_) return;
|
||||
@@ -1824,7 +1829,7 @@ void Playlist::RemoveDeletedSongs() {
|
||||
PlaylistItemPtr item = items_[row];
|
||||
Song song = item->Metadata();
|
||||
|
||||
if (!QFile::exists(song.url().toLocalFile())) {
|
||||
if (!song.is_stream() && !QFile::exists(song.url().toLocalFile())) {
|
||||
rows_to_remove.append(row);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,7 +308,7 @@ private:
|
||||
void InsertSongItems(const SongList &songs, int pos, bool play_now, bool enqueue, bool enqueue_next = false);
|
||||
|
||||
// Modify the playlist without changing the undo stack. These are used by our friends in PlaylistUndoCommands
|
||||
void InsertItemsWithoutUndo(const PlaylistItemList &items, int pos, bool enqueue = false);
|
||||
void InsertItemsWithoutUndo(const PlaylistItemList &items, int pos, bool enqueue = false, bool enqueue_next = false);
|
||||
PlaylistItemList RemoveItemsWithoutUndo(int pos, int count);
|
||||
void MoveItemsWithoutUndo(const QList<int> &source_rows, int pos);
|
||||
void MoveItemWithoutUndo(int source, int dest);
|
||||
|
||||
@@ -45,28 +45,29 @@ PlaylistFilter::PlaylistFilter(QObject *parent)
|
||||
column_names_["artist"] = Playlist::Column_Artist;
|
||||
column_names_["album"] = Playlist::Column_Album;
|
||||
column_names_["albumartist"] = Playlist::Column_AlbumArtist;
|
||||
column_names_["composer"] = Playlist::Column_Composer;
|
||||
column_names_["performer"] = Playlist::Column_Performer;
|
||||
column_names_["grouping"] = Playlist::Column_Grouping;
|
||||
column_names_["length"] = Playlist::Column_Length;
|
||||
column_names_["track"] = Playlist::Column_Track;
|
||||
column_names_["disc"] = Playlist::Column_Disc;
|
||||
column_names_["composer"] = Playlist::Column_Composer;
|
||||
column_names_["year"] = Playlist::Column_Year;
|
||||
column_names_["originalyear"] = Playlist::Column_OriginalYear;
|
||||
column_names_["track"] = Playlist::Column_Track;
|
||||
column_names_["disc"] = Playlist::Column_Disc;
|
||||
column_names_["length"] = Playlist::Column_Length;
|
||||
column_names_["genre"] = Playlist::Column_Genre;
|
||||
column_names_["comment"] = Playlist::Column_Comment;
|
||||
column_names_["bitrate"] = Playlist::Column_Bitrate;
|
||||
column_names_["samplerate"] = Playlist::Column_Samplerate;
|
||||
column_names_["bitdepth"] = Playlist::Column_Bitdepth;
|
||||
column_names_["bitrate"] = Playlist::Column_Bitrate;
|
||||
column_names_["filename"] = Playlist::Column_Filename;
|
||||
column_names_["grouping"] = Playlist::Column_Grouping;
|
||||
column_names_["comment"] = Playlist::Column_Comment;
|
||||
|
||||
numerical_columns_ << Playlist::Column_Length
|
||||
numerical_columns_ << Playlist::Column_Year
|
||||
<< Playlist::Column_OriginalYear
|
||||
<< Playlist::Column_Track
|
||||
<< Playlist::Column_Disc
|
||||
<< Playlist::Column_Year
|
||||
<< Playlist::Column_Bitrate
|
||||
<< Playlist::Column_Length
|
||||
<< Playlist::Column_Samplerate
|
||||
<< Playlist::Column_Bitdepth;
|
||||
<< Playlist::Column_Bitdepth
|
||||
<< Playlist::Column_Bitrate;
|
||||
}
|
||||
|
||||
PlaylistFilter::~PlaylistFilter() {
|
||||
|
||||
@@ -36,17 +36,18 @@ namespace PlaylistUndoCommands {
|
||||
Base::Base(Playlist* playlist) : QUndoCommand(0), playlist_(playlist) {}
|
||||
|
||||
|
||||
InsertItems::InsertItems(Playlist *playlist, const PlaylistItemList &items, int pos, bool enqueue)
|
||||
InsertItems::InsertItems(Playlist *playlist, const PlaylistItemList &items, int pos, bool enqueue, bool enqueue_next)
|
||||
: Base(playlist),
|
||||
items_(items),
|
||||
pos_(pos),
|
||||
enqueue_(enqueue)
|
||||
enqueue_(enqueue),
|
||||
enqueue_next_(enqueue_next)
|
||||
{
|
||||
setText(tr("add %n songs", "", items_.count()));
|
||||
}
|
||||
|
||||
void InsertItems::redo() {
|
||||
playlist_->InsertItemsWithoutUndo(items_, pos_, enqueue_);
|
||||
playlist_->InsertItemsWithoutUndo(items_, pos_, enqueue_, enqueue_next_);
|
||||
}
|
||||
|
||||
void InsertItems::undo() {
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace PlaylistUndoCommands {
|
||||
|
||||
class InsertItems : public Base {
|
||||
public:
|
||||
InsertItems(Playlist *playlist, const PlaylistItemList &items, int pos, bool enqueue = false);
|
||||
InsertItems(Playlist *playlist, const PlaylistItemList &items, int pos, bool enqueue = false, bool enqueue_next = false);
|
||||
|
||||
void undo();
|
||||
void redo();
|
||||
@@ -64,6 +64,7 @@ namespace PlaylistUndoCommands {
|
||||
PlaylistItemList items_;
|
||||
int pos_;
|
||||
bool enqueue_;
|
||||
bool enqueue_next_;
|
||||
};
|
||||
|
||||
class RemoveItems : public Base {
|
||||
|
||||
@@ -80,7 +80,6 @@
|
||||
|
||||
using std::sort;
|
||||
|
||||
const int PlaylistView::kStateVersion = 6;
|
||||
const int PlaylistView::kGlowIntensitySteps = 24;
|
||||
const int PlaylistView::kAutoscrollGraceTimeout = 30; // seconds
|
||||
const int PlaylistView::kDropIndicatorWidth = 2;
|
||||
@@ -135,8 +134,8 @@ PlaylistView::PlaylistView(QWidget *parent)
|
||||
style_(new PlaylistProxyStyle(style())),
|
||||
playlist_(nullptr),
|
||||
header_(new PlaylistHeader(Qt::Horizontal, this, this)),
|
||||
initialized_(false),
|
||||
setting_initial_header_layout_(false),
|
||||
upgrading_from_qheaderview_(false),
|
||||
read_only_settings_(true),
|
||||
header_loaded_(false),
|
||||
background_initialized_(false),
|
||||
@@ -159,19 +158,18 @@ PlaylistView::PlaylistView(QWidget *parent)
|
||||
currenttrack_pause_(":/pictures/currenttrack_pause.png"),
|
||||
cached_current_row_row_(-1),
|
||||
drop_indicator_row_(-1),
|
||||
drag_over_(false)
|
||||
{
|
||||
drag_over_(false) {
|
||||
|
||||
setHeader(header_);
|
||||
header_->setSectionsMovable(true);
|
||||
setStyle(style_);
|
||||
setMouseTracking(true);
|
||||
|
||||
|
||||
connect(header_, SIGNAL(sectionResized(int,int,int)), SLOT(SaveGeometry()));
|
||||
connect(header_, SIGNAL(sectionMoved(int,int,int)), SLOT(SaveGeometry()));
|
||||
connect(header_, SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), SLOT(SaveGeometry()));
|
||||
connect(header_, SIGNAL(SectionVisibilityChanged(int,bool)), SLOT(SaveGeometry()));
|
||||
|
||||
connect(header_, SIGNAL(sectionResized(int,int,int)), SLOT(InvalidateCachedCurrentPixmap()));
|
||||
connect(header_, SIGNAL(sectionMoved(int,int,int)), SLOT(InvalidateCachedCurrentPixmap()));
|
||||
connect(header_, SIGNAL(SectionVisibilityChanged(int,bool)), SLOT(InvalidateCachedCurrentPixmap()));
|
||||
@@ -196,6 +194,8 @@ PlaylistView::PlaylistView(QWidget *parent)
|
||||
connect(fade_animation_, SIGNAL(valueChanged(qreal)), SLOT(FadePreviousBackgroundImage(qreal)));
|
||||
fade_animation_->setDirection(QTimeLine::Backward); // 1.0 -> 0.0
|
||||
|
||||
initialized_ = true;
|
||||
|
||||
}
|
||||
|
||||
PlaylistView::~PlaylistView() {
|
||||
@@ -253,7 +253,7 @@ void PlaylistView::SetPlaylist(Playlist *playlist) {
|
||||
}
|
||||
|
||||
playlist_ = playlist;
|
||||
if (!header_loaded_) LoadGeometry();
|
||||
LoadGeometry();
|
||||
ReloadSettings();
|
||||
setFocus();
|
||||
read_only_settings_ = false;
|
||||
@@ -285,7 +285,6 @@ void PlaylistView::setModel(QAbstractItemModel *m) {
|
||||
void PlaylistView::LoadGeometry() {
|
||||
|
||||
QSettings settings;
|
||||
header_loaded_ = true;
|
||||
settings.beginGroup(Playlist::kSettingsGroup);
|
||||
|
||||
QByteArray state(settings.value("state").toByteArray());
|
||||
@@ -317,7 +316,7 @@ void PlaylistView::LoadGeometry() {
|
||||
setting_initial_header_layout_ = true;
|
||||
}
|
||||
else {
|
||||
upgrading_from_qheaderview_ = true;
|
||||
setting_initial_header_layout_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,11 +332,13 @@ void PlaylistView::LoadGeometry() {
|
||||
header_->ShowSection(Playlist::Column_Title);
|
||||
}
|
||||
|
||||
header_loaded_ = true;
|
||||
|
||||
}
|
||||
|
||||
void PlaylistView::SaveGeometry() {
|
||||
|
||||
if (read_only_settings_) return;
|
||||
if (!initialized_ || read_only_settings_) return;
|
||||
|
||||
QSettings settings;
|
||||
settings.beginGroup(Playlist::kSettingsGroup);
|
||||
@@ -929,11 +930,10 @@ void PlaylistView::ReloadSettings() {
|
||||
glow_enabled_ = s.value("glow_effect", true).toBool();
|
||||
s.endGroup();
|
||||
|
||||
if (setting_initial_header_layout_ || upgrading_from_qheaderview_) {
|
||||
if (setting_initial_header_layout_) {
|
||||
s.beginGroup(Playlist::kSettingsGroup);
|
||||
header_->SetStretchEnabled(s.value("stretch", true).toBool());
|
||||
s.endGroup();
|
||||
upgrading_from_qheaderview_ = false;
|
||||
}
|
||||
|
||||
if (currently_glowing_ && glow_enabled_ && isVisible()) StartGlowing();
|
||||
@@ -1035,7 +1035,7 @@ void PlaylistView::ReloadSettings() {
|
||||
|
||||
void PlaylistView::SaveSettings() {
|
||||
|
||||
if (read_only_settings_) return;
|
||||
if (!initialized_ || read_only_settings_) return;
|
||||
|
||||
QSettings s;
|
||||
|
||||
@@ -1054,6 +1054,7 @@ void PlaylistView::SaveSettings() {
|
||||
}
|
||||
|
||||
void PlaylistView::StretchChanged(bool stretch) {
|
||||
if (!initialized_) return;
|
||||
setHorizontalScrollBarPolicy(stretch ? Qt::ScrollBarAlwaysOff : Qt::ScrollBarAsNeeded);
|
||||
SaveGeometry();
|
||||
}
|
||||
@@ -1084,17 +1085,17 @@ ColumnAlignmentMap PlaylistView::DefaultColumnAlignment() {
|
||||
|
||||
ColumnAlignmentMap ret;
|
||||
|
||||
ret[Playlist::Column_Length] =
|
||||
ret[Playlist::Column_Year] =
|
||||
ret[Playlist::Column_OriginalYear] =
|
||||
ret[Playlist::Column_Track] =
|
||||
ret[Playlist::Column_Disc] =
|
||||
ret[Playlist::Column_Year] =
|
||||
ret[Playlist::Column_Bitrate] =
|
||||
ret[Playlist::Column_Length] =
|
||||
ret[Playlist::Column_Samplerate] =
|
||||
ret[Playlist::Column_Bitdepth] =
|
||||
ret[Playlist::Column_Bitrate] =
|
||||
ret[Playlist::Column_Filesize] =
|
||||
ret[Playlist::Column_PlayCount] =
|
||||
ret[Playlist::Column_SkipCount] =
|
||||
ret[Playlist::Column_OriginalYear] =
|
||||
(Qt::AlignRight | Qt::AlignVCenter);
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -99,7 +99,6 @@ class PlaylistView : public QTreeView {
|
||||
PlaylistView(QWidget *parent = nullptr);
|
||||
~PlaylistView();
|
||||
|
||||
static const int kStateVersion;
|
||||
// Constants for settings: are persistent, values should not be changed
|
||||
static const char *kSettingBackgroundImageType;
|
||||
static const char *kSettingBackgroundImageFilename;
|
||||
@@ -214,8 +213,8 @@ class PlaylistView : public QTreeView {
|
||||
PlaylistProxyStyle *style_;
|
||||
Playlist *playlist_;
|
||||
PlaylistHeader *header_;
|
||||
bool initialized_;
|
||||
bool setting_initial_header_layout_;
|
||||
bool upgrading_from_qheaderview_;
|
||||
bool read_only_settings_;
|
||||
bool header_loaded_;
|
||||
|
||||
|
||||
@@ -43,12 +43,13 @@ SongLoaderInserter::SongLoaderInserter(TaskManager *task_manager, CollectionBack
|
||||
|
||||
SongLoaderInserter::~SongLoaderInserter() { qDeleteAll(pending_); }
|
||||
|
||||
void SongLoaderInserter::Load(Playlist *destination, int row, bool play_now, bool enqueue, const QList<QUrl> &urls) {
|
||||
void SongLoaderInserter::Load(Playlist *destination, int row, bool play_now, bool enqueue, bool enqueue_next, const QList<QUrl> &urls) {
|
||||
|
||||
destination_ = destination;
|
||||
row_ = row;
|
||||
play_now_ = play_now;
|
||||
enqueue_ = enqueue;
|
||||
enqueue_next_ = enqueue_next;
|
||||
|
||||
connect(destination, SIGNAL(destroyed()), SLOT(DestinationDestroyed()));
|
||||
connect(this, SIGNAL(PreloadFinished()), SLOT(InsertSongs()));
|
||||
@@ -84,12 +85,13 @@ void SongLoaderInserter::Load(Playlist *destination, int row, bool play_now, boo
|
||||
// First, we add tracks (without metadata) into the playlist
|
||||
// In the meantime, MusicBrainz will be queried to get songs' metadata.
|
||||
// AudioCDTagsLoaded will be called next, and playlist's items will be updated.
|
||||
void SongLoaderInserter::LoadAudioCD(Playlist *destination, int row, bool play_now, bool enqueue) {
|
||||
void SongLoaderInserter::LoadAudioCD(Playlist *destination, int row, bool play_now, bool enqueue, bool enqueue_next) {
|
||||
|
||||
destination_ = destination;
|
||||
row_ = row;
|
||||
play_now_ = play_now;
|
||||
enqueue_ = enqueue;
|
||||
enqueue_next_ = enqueue_next;
|
||||
|
||||
SongLoader *loader = new SongLoader(collection_, player_, this);
|
||||
NewClosure(loader, SIGNAL(AudioCDTracksLoaded()), this, SLOT(AudioCDTracksLoaded(SongLoader*)), loader);
|
||||
@@ -128,7 +130,7 @@ void SongLoaderInserter::AudioCDTagsLoaded(bool success) {
|
||||
void SongLoaderInserter::InsertSongs() {
|
||||
// Insert songs (that haven't been completely loaded) to allow user to see and play them while not loaded completely
|
||||
if (destination_) {
|
||||
destination_->InsertSongsOrCollectionItems(songs_, row_, play_now_, enqueue_);
|
||||
destination_->InsertSongsOrCollectionItems(songs_, row_, play_now_, enqueue_, enqueue_next_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@ class SongLoaderInserter : public QObject {
|
||||
SongLoaderInserter(TaskManager *task_manager, CollectionBackendInterface *collection, const Player *player);
|
||||
~SongLoaderInserter();
|
||||
|
||||
void Load(Playlist *destination, int row, bool play_now, bool enqueue, const QList<QUrl> &urls);
|
||||
void LoadAudioCD(Playlist *destination, int row, bool play_now, bool enqueue);
|
||||
void Load(Playlist *destination, int row, bool play_now, bool enqueue, bool enqueue_next, const QList<QUrl> &urls);
|
||||
void LoadAudioCD(Playlist *destination, int row, bool play_now, bool enqueue, bool enqueue_next);
|
||||
|
||||
signals:
|
||||
void Error(const QString &message);
|
||||
@@ -68,6 +68,7 @@ signals:
|
||||
int row_;
|
||||
bool play_now_;
|
||||
bool enqueue_;
|
||||
bool enqueue_next_;
|
||||
|
||||
SongList songs_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user