More on model.
[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 private:
36     explicit Library(QObject *parent = 0);
37     ~Library();
38     void load();
39     void clear();
40     static Library *mInstance;
41     QList<Book *> mBooks;
42     Book *mNowReading;
43 };
44
45 #endif // LIBRARY_H