Search Project Gutenberg.
[dorian] / search.h
1 #ifndef SEARCH_H
2 #define SEARCH_H
3
4 #include <QObject>
5 #include <QString>
6 #include <QStringList>
7 #include <QImage>
8 #include <QList>
9
10 class QNetworkAccessManager;
11 class QNetworkReply;
12
13 /** Search for books, display and download results. */
14 class Search: public QObject
15 {
16     Q_OBJECT
17
18 public:
19     struct Query
20     {
21         QString title;
22         QString author;
23         QStringList languages;
24     };
25
26     struct Result
27     {
28         QString id;
29         QString source;
30         QString title;
31         QStringList authors;
32         QString language;
33         QImage cover;
34     };
35
36     static Search *instance();
37     static void close();
38
39 signals:
40     void beginSearch();
41     void searching();
42     void endSearch();
43     void beginDownload(int totalBlocks);
44     void downloading(int blocks);
45     void endDownload();
46
47 public slots:
48     void start(const Query &query);
49     QList<Result> results();
50     bool download(const Result &result, const QString &fileName);
51     void finished();
52
53 protected:
54     explicit Search();
55     QNetworkAccessManager *manager;
56     QNetworkReply *reply;
57 };
58
59 #endif // SEARCH_H