8f2f2e86603a521b4a29d40a5e72afb49149c415
[dorian] / library.h
1 #ifndef LIBRARY_H
2 #define LIBRARY_H
3
4 #include <QAbstractListModel>
5 #include <QVariant>
6 #include <QString>
7 #include <QList>
8
9 class QObject;
10 class QModelIndex;
11 class Book;
12
13 /** Library of books. */
14 class Library: public QAbstractListModel
15 {
16     Q_OBJECT
17
18 public:
19     enum {
20         BookRole = Qt::UserRole + 1,
21     };
22
23     static Library *instance();
24     static void close();
25     int rowCount(const QModelIndex &parent = QModelIndex()) const;
26     QVariant data(const QModelIndex &index, int role) const;
27     void save();
28     QModelIndex find(QString path) const;
29     QModelIndex find(const Book *book) const;
30     Book *current() const;
31     bool add(QString path);
32     void remove(const QModelIndex &index);
33     void setCurrent(const QModelIndex index);
34
35 signals:
36     void currentBookChanged();
37
38 private:
39     explicit Library(QObject *parent = 0);
40     ~Library();
41     void load();
42     void clear();
43     static Library *mInstance;
44     QList<Book *> mBooks;
45     Book *mCurrent;
46 };
47
48 #endif // LIBRARY_H