A little refactoring of Library - pass in a table to get songs from
This commit is contained in:
parent
aba44b7a5a
commit
cd8fc47bf3
@ -27,15 +27,15 @@
|
|||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
|
|
||||||
|
|
||||||
Library::Library(EngineBase* engine, QObject* parent)
|
Library::Library(QObject* parent, const QString& table)
|
||||||
: SimpleTreeModel<LibraryItem>(new LibraryItem(this), parent),
|
: SimpleTreeModel<LibraryItem>(new LibraryItem(this), parent),
|
||||||
engine_(engine),
|
|
||||||
backend_factory_(new BackgroundThreadFactoryImplementation<LibraryBackendInterface, LibraryBackend>),
|
backend_factory_(new BackgroundThreadFactoryImplementation<LibraryBackendInterface, LibraryBackend>),
|
||||||
watcher_factory_(new BackgroundThreadFactoryImplementation<LibraryWatcher, LibraryWatcher>),
|
watcher_factory_(new BackgroundThreadFactoryImplementation<LibraryWatcher, LibraryWatcher>),
|
||||||
backend_(NULL),
|
backend_(NULL),
|
||||||
watcher_(NULL),
|
watcher_(NULL),
|
||||||
dir_model_(new LibraryDirectoryModel(this)),
|
dir_model_(new LibraryDirectoryModel(this)),
|
||||||
waiting_for_threads_(2),
|
waiting_for_threads_(2),
|
||||||
|
query_options_(table),
|
||||||
artist_icon_(":artist.png"),
|
artist_icon_(":artist.png"),
|
||||||
album_icon_(":album.png"),
|
album_icon_(":album.png"),
|
||||||
no_cover_icon_(":nocover.png")
|
no_cover_icon_(":nocover.png")
|
||||||
@ -97,8 +97,6 @@ void Library::WatcherInitialised() {
|
|||||||
connect(watcher_->Worker().get(), SIGNAL(ScanStarted()), SIGNAL(ScanStarted()));
|
connect(watcher_->Worker().get(), SIGNAL(ScanStarted()), SIGNAL(ScanStarted()));
|
||||||
connect(watcher_->Worker().get(), SIGNAL(ScanFinished()), SIGNAL(ScanFinished()));
|
connect(watcher_->Worker().get(), SIGNAL(ScanFinished()), SIGNAL(ScanFinished()));
|
||||||
|
|
||||||
watcher_->Worker()->SetEngine(engine_);
|
|
||||||
|
|
||||||
if (--waiting_for_threads_ == 0)
|
if (--waiting_for_threads_ == 0)
|
||||||
Initialise();
|
Initialise();
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ class Library : public SimpleTreeModel<LibraryItem> {
|
|||||||
Q_ENUMS(GroupBy);
|
Q_ENUMS(GroupBy);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Library(EngineBase* engine, QObject* parent = 0);
|
Library(QObject* parent = 0, const QString& table = QueryOptions::kLibraryTable);
|
||||||
~Library();
|
~Library();
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -176,7 +176,6 @@ class Library : public SimpleTreeModel<LibraryItem> {
|
|||||||
bool CompareItems(const LibraryItem* a, const LibraryItem* b) const;
|
bool CompareItems(const LibraryItem* a, const LibraryItem* b) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EngineBase* engine_;
|
|
||||||
boost::scoped_ptr<BackgroundThreadFactory<LibraryBackendInterface> > backend_factory_;
|
boost::scoped_ptr<BackgroundThreadFactory<LibraryBackendInterface> > backend_factory_;
|
||||||
boost::scoped_ptr<BackgroundThreadFactory<LibraryWatcher> > watcher_factory_;
|
boost::scoped_ptr<BackgroundThreadFactory<LibraryWatcher> > watcher_factory_;
|
||||||
BackgroundThread<LibraryBackendInterface>* backend_;
|
BackgroundThread<LibraryBackendInterface>* backend_;
|
||||||
|
@ -21,17 +21,17 @@
|
|||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QSqlError>
|
#include <QSqlError>
|
||||||
|
|
||||||
QueryOptions::QueryOptions()
|
const char* QueryOptions::kLibraryTable = "songs";
|
||||||
: max_age(-1)
|
|
||||||
|
QueryOptions::QueryOptions(const QString& _table)
|
||||||
|
: table(_table),
|
||||||
|
max_age(-1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LibraryQuery::LibraryQuery()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
LibraryQuery::LibraryQuery(const QueryOptions& options)
|
LibraryQuery::LibraryQuery(const QueryOptions& options)
|
||||||
|
: table_(options.table)
|
||||||
{
|
{
|
||||||
if (!options.filter.isEmpty()) {
|
if (!options.filter.isEmpty()) {
|
||||||
where_clauses_ << "("
|
where_clauses_ << "("
|
||||||
@ -73,7 +73,7 @@ void LibraryQuery::AddCompilationRequirement(bool compilation) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QSqlError LibraryQuery::Exec(QSqlDatabase db) {
|
QSqlError LibraryQuery::Exec(QSqlDatabase db) {
|
||||||
QString sql = QString("SELECT %1 FROM songs").arg(column_spec_);
|
QString sql = QString("SELECT %1 FROM %2").arg(column_spec_, table_);
|
||||||
|
|
||||||
if (!where_clauses_.isEmpty())
|
if (!where_clauses_.isEmpty())
|
||||||
sql += " WHERE " + where_clauses_.join(" AND ");
|
sql += " WHERE " + where_clauses_.join(" AND ");
|
||||||
|
@ -26,17 +26,20 @@
|
|||||||
class Song;
|
class Song;
|
||||||
|
|
||||||
struct QueryOptions {
|
struct QueryOptions {
|
||||||
QueryOptions();
|
static const char* kLibraryTable;
|
||||||
|
|
||||||
|
QueryOptions(const QString& _table = kLibraryTable);
|
||||||
|
|
||||||
bool Matches(const Song& song) const;
|
bool Matches(const Song& song) const;
|
||||||
|
|
||||||
|
QString table;
|
||||||
QString filter;
|
QString filter;
|
||||||
int max_age;
|
int max_age;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LibraryQuery {
|
class LibraryQuery {
|
||||||
public:
|
public:
|
||||||
LibraryQuery();
|
LibraryQuery(const QueryOptions& options = QueryOptions());
|
||||||
LibraryQuery(const QueryOptions& options);
|
|
||||||
|
|
||||||
void SetColumnSpec(const QString& spec) { column_spec_ = spec; }
|
void SetColumnSpec(const QString& spec) { column_spec_ = spec; }
|
||||||
void SetOrderBy(const QString& order_by) { order_by_ = order_by; }
|
void SetOrderBy(const QString& order_by) { order_by_ = order_by; }
|
||||||
@ -51,6 +54,7 @@ class LibraryQuery {
|
|||||||
operator const QSqlQuery& () const { return query_; }
|
operator const QSqlQuery& () const { return query_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QString table_;
|
||||||
QString column_spec_;
|
QString column_spec_;
|
||||||
QString order_by_;
|
QString order_by_;
|
||||||
QStringList where_clauses_;
|
QStringList where_clauses_;
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
#include "librarywatcher.h"
|
#include "librarywatcher.h"
|
||||||
#include "librarybackend.h"
|
#include "librarybackend.h"
|
||||||
#include "engines/enginebase.h"
|
|
||||||
|
|
||||||
#include <QFileSystemWatcher>
|
#include <QFileSystemWatcher>
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
#include "directory.h"
|
#include "directory.h"
|
||||||
#include "song.h"
|
#include "song.h"
|
||||||
#include "engines/engine_fwd.h"
|
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
@ -39,7 +38,6 @@ class LibraryWatcher : public QObject {
|
|||||||
LibraryWatcher(QObject* parent = 0);
|
LibraryWatcher(QObject* parent = 0);
|
||||||
|
|
||||||
void SetBackend(boost::shared_ptr<LibraryBackendInterface> backend) { backend_ = backend; }
|
void SetBackend(boost::shared_ptr<LibraryBackendInterface> backend) { backend_ = backend; }
|
||||||
void SetEngine(EngineBase* engine) { engine_ = engine; } // TODO: shared_ptr
|
|
||||||
|
|
||||||
void Stop() { stop_requested_ = true; }
|
void Stop() { stop_requested_ = true; }
|
||||||
|
|
||||||
@ -122,7 +120,6 @@ class LibraryWatcher : public QObject {
|
|||||||
QFileSystemWatcher* watcher;
|
QFileSystemWatcher* watcher;
|
||||||
};
|
};
|
||||||
|
|
||||||
EngineBase* engine_;
|
|
||||||
boost::shared_ptr<LibraryBackendInterface> backend_;
|
boost::shared_ptr<LibraryBackendInterface> backend_;
|
||||||
bool stop_requested_;
|
bool stop_requested_;
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ MainWindow::MainWindow(QNetworkAccessManager* network, Engine::Type engine, QWid
|
|||||||
radio_model_(new RadioModel(this)),
|
radio_model_(new RadioModel(this)),
|
||||||
playlist_(new Playlist(this)),
|
playlist_(new Playlist(this)),
|
||||||
player_(new Player(playlist_, radio_model_->GetLastFMService(), engine, this)),
|
player_(new Player(playlist_, radio_model_->GetLastFMService(), engine, this)),
|
||||||
library_(new Library(player_->GetEngine(), this)),
|
library_(new Library(this)),
|
||||||
global_shortcuts_(new GlobalShortcuts(this)),
|
global_shortcuts_(new GlobalShortcuts(this)),
|
||||||
settings_dialog_(new SettingsDialog),
|
settings_dialog_(new SettingsDialog),
|
||||||
add_stream_dialog_(new AddStreamDialog),
|
add_stream_dialog_(new AddStreamDialog),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user