Store library in database.
[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 load();
24     void save();
25     QModelIndex find(QString path) const;
26     QModelIndex find(const Book *book) const;
27     void setNowReading(const QModelIndex &index);
28     QModelIndex nowReading() const;
29     Book *book(const QModelIndex &index);
30     QStringList bookPaths();
31     void upgrade();
32
33 signals:
34     void nowReadingChanged();
35     void beginUpgrade(int total);
36     void upgrading(const QString &book);
37     void endUpgrade();
38
39 public slots:
40     bool add(const QString &path);
41     void remove(const QString &path);
42     void remove(const QModelIndex &index);
43     void onBookOpened(const QString &path);
44
45 private:
46     explicit Library(QObject *parent = 0);
47     ~Library();
48     void clear();
49     static Library *mInstance;
50     QList<Book *> mBooks;
51     QModelIndex mNowReading;
52 };
53
54 #endif // LIBRARY_H