defuze.me
Client
|
00001 #ifndef LIBRARYMODEL_HPP 00002 #define LIBRARYMODEL_HPP 00003 00004 #include <QSqlQuery> 00005 #include "audiotrack.hpp" 00006 #include "treemodel.hpp" 00007 00008 namespace Library 00009 { 00010 class LibraryPlugin; 00011 00012 class LibraryModel : public TreeModel 00013 { 00014 public: 00015 00016 enum SortKeys 00017 { 00018 INVALID, ALBUM, ARTIST, ALBUM_ARTIST, GENRE, TITLE, TRACK 00019 }; 00020 enum SortKeysInfoData 00021 { 00022 TEXT = 0, FIELD = 1, ORDER_BY = 2, DEFAULT = 3 00023 }; 00024 00025 LibraryModel(LibraryPlugin *library); 00026 LibraryPlugin* getLibrary() const; 00027 int getIdByIndex(const QModelIndex &index) const; 00028 SortKeys getKindByIndex(const QModelIndex &index) const; 00029 void update(int sort = -1, QString search = QString()); 00030 QStringList mimeTypes() const; 00031 QMimeData* mimeData(const QModelIndexList &indexes) const; 00032 Qt::ItemFlags flags(const QModelIndex &index) const; 00033 QVariant data(const QModelIndex &index, int role) const; 00034 00035 protected: 00036 void setupModelData(); 00037 00038 private: 00039 bool isLowestLevelSortKey(SortKeys key); 00040 void updateSortKeys(int sort); 00041 QString updateSearch(); 00042 QString orderByKeys() const; 00043 void initKeys(); 00044 void buildQuery(QSqlQuery *query, int sort, const QString &search); 00045 void buildTree(QSqlQuery *query, TreeItem *parent); 00046 void clear(); 00047 00048 LibraryPlugin *library; 00049 QHash<SortKeys, QStringList> sortKeysInfo; 00050 QList<SortKeys> sortKeys; 00051 QHash<QModelIndex, int> idByIndexes; 00052 QHash<QModelIndex, SortKeys> kindByIndexes; 00053 QString currentSearch; 00054 }; 00055 } 00056 00057 #endif // LIBRARYMODEL_HPP