Fix naming: book parts vs. chapters.
[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     QStringList folders() const;
31     bool addFolder(const QString &folder);
32     bool removeFolder(const QString &folder);
33     void scanFolders();
34
35 signals:
36     void nowReadingChanged();
37
38 public slots:
39     bool add(const QString &path);
40     void remove(const QString &path);
41     void remove(const QModelIndex &index);
42     void onBookOpened(const QString &path);
43
44 private:
45     explicit Library(QObject *parent = 0);
46     ~Library();
47     void load();
48     void clear();
49     static Library *mInstance;
50     QList<Book *> mBooks;
51     QModelIndex mNowReading;
52     QStringList mFolders;
53 };
54
55 #endif // LIBRARY_H