2009-12-24 20:16:07 +01:00
|
|
|
#ifndef LIBRARY_H
|
|
|
|
#define LIBRARY_H
|
|
|
|
|
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include <QIcon>
|
|
|
|
|
|
|
|
#include "backgroundthread.h"
|
|
|
|
#include "librarybackend.h"
|
|
|
|
#include "librarywatcher.h"
|
|
|
|
#include "libraryquery.h"
|
|
|
|
#include "engine_fwd.h"
|
|
|
|
#include "song.h"
|
2009-12-26 16:13:38 +01:00
|
|
|
#include "libraryitem.h"
|
|
|
|
#include "simpletreemodel.h"
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-02-03 17:17:04 +01:00
|
|
|
class LibraryDirectoryModel;
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2009-12-26 16:13:38 +01:00
|
|
|
class Library : public SimpleTreeModel<LibraryItem> {
|
2009-12-24 20:16:07 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
Library(EngineBase* engine, QObject* parent = 0);
|
|
|
|
~Library();
|
|
|
|
|
|
|
|
enum {
|
|
|
|
Role_Type = Qt::UserRole + 1,
|
|
|
|
Role_SortText,
|
|
|
|
Role_Key,
|
|
|
|
};
|
|
|
|
|
|
|
|
void StartThreads();
|
|
|
|
|
2010-02-03 17:17:04 +01:00
|
|
|
LibraryDirectoryModel* GetDirectoryModel() const { return dir_model_; }
|
|
|
|
|
2009-12-24 21:27:32 +01:00
|
|
|
// Get information about the library
|
2009-12-24 20:16:07 +01:00
|
|
|
void GetChildSongs(LibraryItem* item, QList<QUrl>* urls, SongList* songs) const;
|
|
|
|
SongList GetChildSongs(const QModelIndex& index) const;
|
|
|
|
|
|
|
|
// QAbstractItemModel
|
|
|
|
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
|
|
|
|
Qt::ItemFlags flags(const QModelIndex& index) const;
|
|
|
|
QStringList mimeTypes() const;
|
|
|
|
QMimeData* mimeData(const QModelIndexList& indexes) const;
|
2010-01-15 17:36:34 +01:00
|
|
|
bool canFetchMore(const QModelIndex &parent) const;
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void Error(const QString& message);
|
|
|
|
void TotalSongCountUpdated(int count);
|
|
|
|
|
2010-01-16 18:52:51 +01:00
|
|
|
void ScanStarted();
|
|
|
|
void ScanFinished();
|
|
|
|
|
2010-02-28 19:04:50 +01:00
|
|
|
void BackendReady(boost::shared_ptr<LibraryBackend> backend);
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
public slots:
|
|
|
|
void SetFilterAge(int age);
|
|
|
|
void SetFilterText(const QString& text);
|
|
|
|
|
2009-12-26 16:13:38 +01:00
|
|
|
protected:
|
|
|
|
void LazyPopulate(LibraryItem* item);
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
private slots:
|
|
|
|
// From LibraryBackend
|
|
|
|
void BackendInitialised();
|
|
|
|
void SongsDiscovered(const SongList& songs);
|
|
|
|
void SongsDeleted(const SongList& songs);
|
|
|
|
void Reset();
|
|
|
|
|
|
|
|
// From LibraryWatcher
|
|
|
|
void WatcherInitialised();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void Initialise();
|
|
|
|
|
|
|
|
LibraryItem* CreateCompilationArtistNode(bool signal);
|
|
|
|
LibraryItem* CreateArtistNode(bool signal, const QString& name);
|
2010-02-28 23:07:59 +01:00
|
|
|
LibraryItem* CreateAlbumNode(bool signal, const QString& name,
|
|
|
|
LibraryItem* parent, bool compilation,
|
|
|
|
const QString& art_automatic,
|
|
|
|
const QString& art_manual);
|
2009-12-24 20:16:07 +01:00
|
|
|
LibraryItem* CreateSongNode(bool signal, const Song& song, LibraryItem* parent);
|
|
|
|
|
|
|
|
QString PrettyArtist(QString artist) const;
|
|
|
|
QString PrettyAlbum(QString album) const;
|
|
|
|
|
|
|
|
QString SortTextForArtist(QString artist) const;
|
|
|
|
QString SortTextForAlbum(QString album) const;
|
|
|
|
|
|
|
|
QVariant data(const LibraryItem* item, int role) const;
|
|
|
|
|
|
|
|
bool CompareItems(const LibraryItem* a, const LibraryItem* b) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
EngineBase* engine_;
|
|
|
|
BackgroundThread<LibraryBackend>* backend_;
|
|
|
|
BackgroundThread<LibraryWatcher>* watcher_;
|
2010-02-03 17:17:04 +01:00
|
|
|
LibraryDirectoryModel* dir_model_;
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
int waiting_for_threads_;
|
|
|
|
|
|
|
|
QueryOptions query_options_;
|
|
|
|
|
|
|
|
QMap<int, LibraryItem*> song_nodes_;
|
|
|
|
QMap<QString, LibraryItem*> artist_nodes_;
|
|
|
|
QMap<QChar, LibraryItem*> divider_nodes_;
|
|
|
|
LibraryItem* compilation_artist_node_;
|
|
|
|
|
|
|
|
QIcon artist_icon_;
|
|
|
|
QIcon album_icon_;
|
2010-02-28 23:07:59 +01:00
|
|
|
QIcon no_cover_icon_;
|
2009-12-24 20:16:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LIBRARY_H
|