e8142e147af266250794897be42671024441048d
[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     enum {
19         BookRole = Qt::UserRole + 1,
20     };
21
22     static Library *instance();
23     static void close();
24     int rowCount(const QModelIndex & parent = QModelIndex()) const;
25     QVariant data(const QModelIndex &index, int role) const;
26     void save();
27     int find(QString path) const;
28     int find(const Book *book) const;
29     Book *at(int index) const;
30     int size() const;
31     Book *current() const;
32     bool add(QString path);
33     void remove(int index);
34     void setCurrent(int index);
35
36 signals:
37     void currentBookChanged();
38
39 private:
40     explicit Library(QObject *parent = 0);
41     ~Library();
42     void load();
43     void clear();
44     static Library *mInstance;
45     QList<Book *> mBooks;
46     Book *mCurrent;
47 };
48
49 #endif // LIBRARY_H