Improve bookmark management.
[dorian] / model / library.h
1 #ifndef LIBRARY_H
2 #define LIBRARY_H
3
4 #include <QAbstractListModel>
5 #include <QVariant>
6 #include <QString>
7 #include <QList>
8 #include <QStringList>
9
10 class QObject;
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     void setNowReading(const QModelIndex &index);
27     QModelIndex nowReading() const;
28     Book *book(const QModelIndex &index);
29     QStringList bookPaths();
30
31 signals:
32     void nowReadingChanged();
33
34 public slots:
35     bool add(const QString &path);
36     void remove(const QString &path);
37     void remove(const QModelIndex &index);
38     void onBookOpened(const QString &path);
39
40 private:
41     explicit Library(QObject *parent = 0);
42     ~Library();
43     void load();
44     void clear();
45     static Library *mInstance;
46     QList<Book *> mBooks;
47     QModelIndex mNowReading;
48 };
49
50 #endif // LIBRARY_H