1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#ifndef WALLPAPERDOWNLOADCLIENT_H
#define WALLPAPERDOWNLOADCLIENT_H
#include <curl/curl.h>
#include <QString>
#include <QThread>
#include <QDir>
#include <sstream>
#include "nwutils.h"
#include "curlresult.h"
#include "tvshow.h"
#include "filedownloadthread.h"
#include "wallpaperdownloadclient.h"
/// base to dl images form common wallpaper hosting sites
namespace WallpaperDownload {
enum Rating {
ratingInvalid = 0,
ratingSafe = 1 << 0,
ratingQuestionable = 1 << 1,
ratingExplicit = 1 << 2
};
class Entry {
public:
Entry();
QString id;
QStringList tags;
QString fileUrl;
QString sampleUrl;
QString previewUrl;
QString rating;
int width;
int height;
int score;
bool operator <(const Entry& b) const;
bool hasGoodAspectRatio() const;
bool isGoodWallpaper() const;
Rating ratingFromString() const;
};
class SearchResult {
public:
SearchResult(int limit = 10);
void sortEntries();
QList<Entry> entries;
private:
int limit;
};
class Client : public QObject
{
Q_OBJECT
public:
Client(QString baseUrl, int limit = 10, Rating ratingFilter = ratingSafe);
virtual SearchResult fetchPostsBlocking(const TvShow* show, int page = 1);
Rating getRatingFilter() const;
int getLimit() const;
virtual void downloadResults(QDir directory, const QList<Entry> &entries, bool onlyTheBest);
signals:
void wallpaperDownloaded(QString path);
private slots:
void onWallpaperDownloadSucceeded(QString path);
protected:
virtual Entry parseEntry(nw::Describer *de) = 0;
virtual SearchResult parseSearchResult(std::stringstream &, int limit) = 0;
virtual CURL* curlClient(QString tag, CurlResult& userdata, const unsigned int page = 1) = 0;
QString baseUrl;
Rating ratingFilter;
int limit;
int matches;
private:
const QString hostname;
static QDebug err();
};
class FetchThread : public QThread {
Q_OBJECT
public:
FetchThread(Client& client, QList<TvShow*> tvShows, QDir libraryDirectory, QObject* parent);
void run();
void append(QList<TvShow*> tvShows);
signals:
void noEntriesFound(const TvShow* show);
private:
Client& client;
QList<TvShow*> tvShows;
QDir libraryDirectory;
};
}
#endif // WALLPAPERDOWNLOADCLIENT_H