1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-16 11:19:18 +01:00

Remember which library a dynamic playlist was using when you restart clementine

This commit is contained in:
David Sansome 2010-11-27 19:11:36 +00:00
parent 623b90e5e2
commit b1bf95a668
10 changed files with 40 additions and 9 deletions

View File

@ -291,5 +291,6 @@
<file>providers/jamendo.png</file>
<file>schema/schema-22.sql</file>
<file>schema/jamendo.sql</file>
<file>schema/schema-23.sql</file>
</qresource>
</RCC>

View File

@ -30,7 +30,7 @@
#include <QVariant>
const char* Database::kDatabaseFilename = "clementine.db";
const int Database::kSchemaVersion = 22;
const int Database::kSchemaVersion = 23;
const char* Database::kMagicAllSongsTables = "%allsongstables";
int Database::sNextConnectionId = 1;

View File

@ -884,7 +884,7 @@ LibraryModel::GroupBy& LibraryModel::Grouping::operator [](int i) {
void LibraryModel::CreateSmartPlaylists() {
smart_playlist_node_ = new LibraryItem(LibraryItem::Type_PlaylistContainer, root_);
smart_playlist_node_->container_level = 0;
smart_playlist_node_->sort_text = "\0smart";
smart_playlist_node_->sort_text = "\0";
smart_playlist_node_->key = tr("Smart playlists");
QSettings s;

View File

@ -69,6 +69,7 @@ Playlist::Playlist(PlaylistBackend* backend,
int id,
QObject *parent)
: QAbstractListModel(parent),
is_loading_(false),
proxy_(new PlaylistFilter(this)),
queue_(new Queue(this)),
backend_(backend),
@ -991,7 +992,7 @@ void Playlist::SetCurrentIsPaused(bool paused) {
}
void Playlist::Save() const {
if (!backend_)
if (!backend_ || is_loading_)
return;
backend_->SavePlaylistAsync(id_, items_, last_played_index(), dynamic_playlist_);
@ -1020,7 +1021,9 @@ void Playlist::ItemsLoaded() {
watcher->deleteLater();
PlaylistItemList items = watcher->future().results();
is_loading_ = true;
InsertItems(items, 0);
is_loading_ = false;
PlaylistBackend::Playlist p = backend_->GetPlaylist(id_);
@ -1030,9 +1033,20 @@ void Playlist::ItemsLoaded() {
if (!p.dynamic_type.isEmpty()) {
GeneratorPtr gen = Generator::Create(p.dynamic_type);
if (gen) {
gen->set_library(library_);
gen->Load(p.dynamic_data);
TurnOnDynamicPlaylist(gen);
// Hack: can't think of a better way to get the right backend
LibraryBackend* backend = NULL;
if (p.dynamic_backend == library_->songs_table())
backend = library_;
else if (p.dynamic_backend == MagnatuneService::kSongsTable)
backend = RadioModel::Service<MagnatuneService>()->library_backend();
else if (p.dynamic_backend == JamendoService::kSongsTable)
backend = RadioModel::Service<JamendoService>()->library_backend();
if (backend) {
gen->set_library(backend);
gen->Load(p.dynamic_data);
TurnOnDynamicPlaylist(gen);
}
}
}
}

View File

@ -228,6 +228,7 @@ class Playlist : public QAbstractListModel {
void ItemsLoaded();
private:
bool is_loading_;
PlaylistFilter* proxy_;
Queue* queue_;

View File

@ -19,6 +19,7 @@
#include "core/database.h"
#include "core/scopedtransaction.h"
#include "core/song.h"
#include "library/librarybackend.h"
#include "library/sqlrow.h"
#include "smartplaylists/generator.h"
@ -41,7 +42,9 @@ PlaylistBackend::PlaylistList PlaylistBackend::GetAllPlaylists() {
PlaylistList ret;
QSqlQuery q("SELECT ROWID, name, last_played FROM playlists ORDER BY ui_order", db);
QSqlQuery q("SELECT ROWID, name, last_played, dynamic_playlist_type,"
" dynamic_playlist_data, dynamic_playlist_backend"
" FROM playlists", db);
q.exec();
if (db_->CheckErrors(q.lastError()))
return ret;
@ -51,6 +54,9 @@ PlaylistBackend::PlaylistList PlaylistBackend::GetAllPlaylists() {
p.id = q.value(0).toInt();
p.name = q.value(1).toString();
p.last_played = q.value(2).toInt();
p.dynamic_type = q.value(3).toString();
p.dynamic_data = q.value(4).toByteArray();
p.dynamic_backend = q.value(5).toString();
ret << p;
}
@ -62,7 +68,7 @@ PlaylistBackend::Playlist PlaylistBackend::GetPlaylist(int id) {
QSqlDatabase db(db_->Connect());
QSqlQuery q("SELECT ROWID, name, last_played, dynamic_playlist_type,"
" dynamic_playlist_data"
" dynamic_playlist_data, dynamic_playlist_backend"
" FROM playlists"
" WHERE ROWID=:id", db);
q.bindValue(":id", id);
@ -78,6 +84,7 @@ PlaylistBackend::Playlist PlaylistBackend::GetPlaylist(int id) {
p.last_played = q.value(2).toInt();
p.dynamic_type = q.value(3).toString();
p.dynamic_data = q.value(4).toByteArray();
p.dynamic_backend = q.value(5).toString();
return p;
}
@ -147,7 +154,8 @@ void PlaylistBackend::SavePlaylist(int playlist, const PlaylistItemList& items,
QSqlQuery update("UPDATE playlists SET "
" last_played=:last_played,"
" dynamic_playlist_type=:dynamic_type,"
" dynamic_playlist_data=:dynamic_data"
" dynamic_playlist_data=:dynamic_data,"
" dynamic_playlist_backend=:dynamic_backend"
" WHERE ROWID=:playlist", db);
ScopedTransaction transaction(&db);
@ -172,9 +180,11 @@ void PlaylistBackend::SavePlaylist(int playlist, const PlaylistItemList& items,
if (dynamic) {
update.bindValue(":dynamic_type", dynamic->type());
update.bindValue(":dynamic_data", dynamic->Save());
update.bindValue(":dynamic_backend", dynamic->library()->songs_table());
} else {
update.bindValue(":dynamic_type", QString());
update.bindValue(":dynamic_data", QByteArray());
update.bindValue(":dynamic_backend", QString());
}
update.bindValue(":playlist", playlist);
update.exec();

View File

@ -41,6 +41,7 @@ class PlaylistBackend : public QObject {
QString name;
int last_played;
QString dynamic_type;
QString dynamic_backend;
QByteArray dynamic_data;
};
typedef QList<Playlist> PlaylistList;

View File

@ -46,6 +46,8 @@ class JamendoService : public RadioService {
QWidget* HeaderWidget() const;
LibraryBackend* library_backend() const { return library_backend_; }
static const char* kServiceName;
static const char* kDirectoryUrl;
static const char* kMp3StreamUrl;

View File

@ -82,6 +82,7 @@ class MagnatuneService : public RadioService {
PreferredFormat preferred_format() const { return format_; }
QString username() const { return username_; }
QString password() const { return password_; }
LibraryBackend* library_backend() const { return library_backend_; }
QUrl ModifyUrl(const QUrl& url) const;

View File

@ -43,6 +43,7 @@ public:
// Should be called before Load on a new Generator
void set_library(LibraryBackend* backend) { backend_ = backend; }
void set_name(const QString& name) { name_ = name; }
LibraryBackend* library() const { return backend_; }
QString name() const { return name_; }
// Name of the subclass