Turn library into proper 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 Book;
11
12 /** Library of books. */
13 class Library: public QAbstractListModel
14 {
15     Q_OBJECT
16
17 public:
18     static Library *instance();
19     static void close();
20     int rowCount(const QModelIndex & parent = QModelIndex()) const;
21     QVariant data(const QModelIndex &index, int role) const;
22     void save();
23     int find(QString path) const;
24     int find(const Book *book) const;
25     Book *at(int index) const;
26     int size() const;
27     Book *current() const;
28     bool add(QString path);
29     void remove(int index);
30     void setCurrent(int index);
31
32 signals:
33     void bookAdded();
34     void bookRemoved(int index);
35     void currentBookChanged();
36
37 private:
38     explicit Library(QObject *parent = 0);
39     ~Library();
40     void load();
41     void clear();
42     static Library *mInstance;
43     QList<Book *> mBooks;
44     Book *mCurrent;
45 };
46
47 #endif // LIBRARY_H