New version. Update home page link in About box.
[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     /** Search query. */
20     struct Query
21     {
22         QString title;
23         QString author;
24         QStringList languages;
25     };
26
27     /** Search result. */
28     struct Result
29     {
30         QString id;
31         QString source;
32         QString title;
33         QStringList authors;
34         QString language;
35         QImage cover;
36         bool operator ==(const Result &other) const {
37             return (source == other.source) && (id == other.id);
38         }
39     };
40
41     /** Download status. */
42     enum
43     {
44         Ok,
45         DownloadError,
46         FileError,
47     };
48
49     static Search *instance();
50     static void close();
51
52 signals:
53     void beginSearch();
54     void searching();
55     void endSearch();
56     void beginDownload(int totalBlocks);
57     void downloading(int blocks);
58     void endDownload(int status, const Search::Result &result,
59                      const QString &fileName);
60
61 public slots:
62     void start(const Query &query);
63     QList<Result> results();
64     void download(const Result &result, const QString &fileName);
65     void finished();
66     void downloadFinished();
67
68 private:
69     explicit Search();
70     QNetworkAccessManager *manager;
71     QNetworkAccessManager *downloadManager;
72     QNetworkReply *reply;
73     QNetworkReply *downloadReply;
74     QList<Result> searchResults;
75     Search::Result downloadResult;
76     QString downloadFileName;
77 };
78
79 #endif // SEARCH_H