A little refactoring of Library - pass in a table to get songs from

This commit is contained in:
David Sansome 2010-05-08 21:54:36 +00:00
parent aba44b7a5a
commit cd8fc47bf3
7 changed files with 18 additions and 21 deletions

View File

@ -27,15 +27,15 @@
#include <boost/bind.hpp>
Library::Library(EngineBase* engine, QObject* parent)
Library::Library(QObject* parent, const QString& table)
: SimpleTreeModel<LibraryItem>(new LibraryItem(this), parent),
engine_(engine),
backend_factory_(new BackgroundThreadFactoryImplementation<LibraryBackendInterface, LibraryBackend>),
watcher_factory_(new BackgroundThreadFactoryImplementation<LibraryWatcher, LibraryWatcher>),
backend_(NULL),
watcher_(NULL),
dir_model_(new LibraryDirectoryModel(this)),
waiting_for_threads_(2),
query_options_(table),
artist_icon_(":artist.png"),
album_icon_(":album.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(ScanFinished()), SIGNAL(ScanFinished()));
watcher_->Worker()->SetEngine(engine_);
if (--waiting_for_threads_ == 0)
Initialise();
}

View File

@ -38,7 +38,7 @@ class Library : public SimpleTreeModel<LibraryItem> {
Q_ENUMS(GroupBy);
public:
Library(EngineBase* engine, QObject* parent = 0);
Library(QObject* parent = 0, const QString& table = QueryOptions::kLibraryTable);
~Library();
enum {
@ -176,7 +176,6 @@ class Library : public SimpleTreeModel<LibraryItem> {
bool CompareItems(const LibraryItem* a, const LibraryItem* b) const;
private:
EngineBase* engine_;
boost::scoped_ptr<BackgroundThreadFactory<LibraryBackendInterface> > backend_factory_;
boost::scoped_ptr<BackgroundThreadFactory<LibraryWatcher> > watcher_factory_;
BackgroundThread<LibraryBackendInterface>* backend_;

View File

@ -21,17 +21,17 @@
#include <QDateTime>
#include <QSqlError>
QueryOptions::QueryOptions()
: max_age(-1)
const char* QueryOptions::kLibraryTable = "songs";
QueryOptions::QueryOptions(const QString& _table)
: table(_table),
max_age(-1)
{
}
LibraryQuery::LibraryQuery()
{
}
LibraryQuery::LibraryQuery(const QueryOptions& options)
: table_(options.table)
{
if (!options.filter.isEmpty()) {
where_clauses_ << "("
@ -73,7 +73,7 @@ void LibraryQuery::AddCompilationRequirement(bool compilation) {
}
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())
sql += " WHERE " + where_clauses_.join(" AND ");

View File

@ -26,17 +26,20 @@
class Song;
struct QueryOptions {
QueryOptions();
static const char* kLibraryTable;
QueryOptions(const QString& _table = kLibraryTable);
bool Matches(const Song& song) const;
QString table;
QString filter;
int max_age;
};
class LibraryQuery {
public:
LibraryQuery();
LibraryQuery(const QueryOptions& options);
LibraryQuery(const QueryOptions& options = QueryOptions());
void SetColumnSpec(const QString& spec) { column_spec_ = spec; }
void SetOrderBy(const QString& order_by) { order_by_ = order_by; }
@ -51,6 +54,7 @@ class LibraryQuery {
operator const QSqlQuery& () const { return query_; }
private:
QString table_;
QString column_spec_;
QString order_by_;
QStringList where_clauses_;

View File

@ -16,7 +16,6 @@
#include "librarywatcher.h"
#include "librarybackend.h"
#include "engines/enginebase.h"
#include <QFileSystemWatcher>
#include <QDirIterator>

View File

@ -19,7 +19,6 @@
#include "directory.h"
#include "song.h"
#include "engines/engine_fwd.h"
#include <QObject>
#include <QStringList>
@ -39,7 +38,6 @@ class LibraryWatcher : public QObject {
LibraryWatcher(QObject* parent = 0);
void SetBackend(boost::shared_ptr<LibraryBackendInterface> backend) { backend_ = backend; }
void SetEngine(EngineBase* engine) { engine_ = engine; } // TODO: shared_ptr
void Stop() { stop_requested_ = true; }
@ -122,7 +120,6 @@ class LibraryWatcher : public QObject {
QFileSystemWatcher* watcher;
};
EngineBase* engine_;
boost::shared_ptr<LibraryBackendInterface> backend_;
bool stop_requested_;

View File

@ -93,7 +93,7 @@ MainWindow::MainWindow(QNetworkAccessManager* network, Engine::Type engine, QWid
radio_model_(new RadioModel(this)),
playlist_(new Playlist(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)),
settings_dialog_(new SettingsDialog),
add_stream_dialog_(new AddStreamDialog),