Show cover images in library.
[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     static Library *instance();
20     static void close();
21     int rowCount(const QModelIndex &parent = QModelIndex()) const;
22     QVariant data(const QModelIndex &index, int role) const;
23     void save();
24     QModelIndex find(QString path) const;
25     QModelIndex find(const Book *book) const;
26     bool add(QString path);
27     void remove(const QModelIndex &index);
28     void setNowReading(const QModelIndex &index);
29     QModelIndex nowReading() const;
30     Book *book(const QModelIndex &index);
31
32 signals:
33     void nowReadingChanged();
34
35 public slots:
36     void onBookOpened(const QString &path);
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     QModelIndex mNowReading;
46 };
47
48 #endif // LIBRARY_H