Remember the ordering of playlists
This commit is contained in:
parent
119c6fbd6e
commit
98235eea03
@ -176,5 +176,6 @@
|
||||
<file>icons/32x32/document-new.png</file>
|
||||
<file>icons/48x48/document-new.png</file>
|
||||
<file>schema-10.sql</file>
|
||||
<file>schema-11.sql</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
4
data/schema-11.sql
Normal file
4
data/schema-11.sql
Normal file
@ -0,0 +1,4 @@
|
||||
ALTER TABLE playlists ADD COLUMN ui_order INTEGER NOT NULL DEFAULT 0;
|
||||
|
||||
UPDATE schema_version SET version=11;
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include <QVariant>
|
||||
|
||||
const char* Database::kDatabaseFilename = "clementine.db";
|
||||
const int Database::kSchemaVersion = 10;
|
||||
const int Database::kSchemaVersion = 11;
|
||||
|
||||
int (*Database::_sqlite3_create_function) (
|
||||
sqlite3*, const char*, int, int, void*,
|
||||
|
@ -35,7 +35,7 @@ PlaylistBackend::PlaylistList PlaylistBackend::GetAllPlaylists() {
|
||||
|
||||
PlaylistList ret;
|
||||
|
||||
QSqlQuery q("SELECT ROWID, name, last_played FROM playlists", db);
|
||||
QSqlQuery q("SELECT ROWID, name, last_played FROM playlists ORDER BY ui_order", db);
|
||||
q.exec();
|
||||
if (db_->CheckErrors(q.lastError()))
|
||||
return ret;
|
||||
@ -196,3 +196,20 @@ void PlaylistBackend::RenamePlaylist(int id, const QString &new_name) {
|
||||
q.exec();
|
||||
db_->CheckErrors(q.lastError());
|
||||
}
|
||||
|
||||
void PlaylistBackend::SetPlaylistOrder(const QList<int>& ids) {
|
||||
QSqlDatabase db(db_->Connect());
|
||||
QSqlQuery q("UPDATE playlists SET ui_order=:index WHERE ROWID=:id", db);
|
||||
|
||||
ScopedTransaction transaction(&db);
|
||||
|
||||
for (int i=0 ; i<ids.count() ; ++i) {
|
||||
q.bindValue(":index", i);
|
||||
q.bindValue(":id", ids[i]);
|
||||
q.exec();
|
||||
if (db_->CheckErrors(q.lastError()))
|
||||
return;
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ class PlaylistBackend : public QObject {
|
||||
PlaylistItemList GetPlaylistItems(int playlist);
|
||||
void SavePlaylistAsync(int playlist, const PlaylistItemList& items,
|
||||
int last_played);
|
||||
void SetPlaylistOrder(const QList<int>& ids);
|
||||
|
||||
int CreatePlaylist(const QString& name);
|
||||
void RemovePlaylist(int id);
|
||||
|
@ -84,6 +84,8 @@ void PlaylistContainer::SetManager(PlaylistManager *manager) {
|
||||
manager, SLOT(Rename(int,QString)));
|
||||
connect(ui_->tab_bar, SIGNAL(Remove(int)),
|
||||
manager, SLOT(Remove(int)));
|
||||
connect(ui_->tab_bar, SIGNAL(PlaylistOrderChanged(QList<int>)),
|
||||
manager, SLOT(ChangePlaylistOrder(QList<int>)));
|
||||
|
||||
connect(manager, SIGNAL(CurrentChanged(Playlist*)),
|
||||
SLOT(SetViewModel(Playlist*)));
|
||||
|
@ -162,3 +162,7 @@ void PlaylistManager::SetActiveStopped() {
|
||||
void PlaylistManager::SetActiveStreamMetadata(const QUrl &url, const Song &song) {
|
||||
active()->SetStreamMetadata(url, song);
|
||||
}
|
||||
|
||||
void PlaylistManager::ChangePlaylistOrder(const QList<int>& ids) {
|
||||
playlist_backend_->SetPlaylistOrder(ids);
|
||||
}
|
||||
|
@ -58,6 +58,7 @@ public slots:
|
||||
void Save(int id, const QString& filename);
|
||||
void Rename(int id, const QString& new_name);
|
||||
void Remove(int id);
|
||||
void ChangePlaylistOrder(const QList<int>& ids);
|
||||
|
||||
void SetCurrentPlaylist(int id);
|
||||
void SetActivePlaylist(int id);
|
||||
|
@ -32,6 +32,7 @@ PlaylistTabBar::PlaylistTabBar(QWidget *parent)
|
||||
menu_->addSeparator();
|
||||
|
||||
connect(this, SIGNAL(currentChanged(int)), this, SLOT(CurrentIndexChanged(int)));
|
||||
connect(this, SIGNAL(tabMoved(int,int)), this, SLOT(TabMoved()));
|
||||
}
|
||||
|
||||
void PlaylistTabBar::SetActions(
|
||||
@ -117,3 +118,11 @@ void PlaylistTabBar::InsertTab(int id, int index, const QString& text) {
|
||||
if (currentIndex() == index)
|
||||
emit CurrentIdChanged(id);
|
||||
}
|
||||
|
||||
void PlaylistTabBar::TabMoved() {
|
||||
QList<int> ids;
|
||||
for (int i=0 ; i<count() ; ++i) {
|
||||
ids << tabData(i).toInt();
|
||||
}
|
||||
emit PlaylistOrderChanged(ids);
|
||||
}
|
||||
|
@ -47,11 +47,13 @@ signals:
|
||||
void CurrentIdChanged(int id);
|
||||
void Rename(int id, const QString& name);
|
||||
void Remove(int id);
|
||||
void PlaylistOrderChanged(const QList<int>& ids);
|
||||
|
||||
private slots:
|
||||
void CurrentIndexChanged(int index);
|
||||
void Rename();
|
||||
void Remove();
|
||||
void TabMoved();
|
||||
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent *);
|
||||
|
Loading…
x
Reference in New Issue
Block a user