#include <QImage>
#include <QList>
+class QNetworkAccessManager;
+class QNetworkReply;
+
+/** Search for books, display and download results. */
class Search: public QObject
{
Q_OBJECT
public:
+ /** Search query. */
struct Query
{
QString title;
QStringList languages;
};
+ /** Search result. */
struct Result
{
QString id;
QStringList authors;
QString language;
QImage cover;
+ bool operator ==(const Result &other) const {
+ return (source == other.source) && (id == other.id);
+ }
+ };
+
+ /** Download status. */
+ enum
+ {
+ Ok,
+ DownloadError,
+ FileError,
};
static Search *instance();
void endSearch();
void beginDownload(int totalBlocks);
void downloading(int blocks);
- void endDownload();
+ void endDownload(int status, const Search::Result &result,
+ const QString &fileName);
public slots:
void start(const Query &query);
QList<Result> results();
- bool download(const Result &result, const QString &fileName);
+ void download(const Result &result, const QString &fileName);
+ void finished();
+ void downloadFinished();
-protected:
+private:
explicit Search();
+ QNetworkAccessManager *manager;
+ QNetworkAccessManager *downloadManager;
+ QNetworkReply *reply;
+ QNetworkReply *downloadReply;
+ QList<Result> searchResults;
+ Search::Result downloadResult;
+ QString downloadFileName;
};
#endif // SEARCH_H