]> git.sur5r.net Git - minitube/blob - src/yt/ytthumb.cpp
New upstream version 3.9.1
[minitube] / src / yt / ytthumb.cpp
1 #include "ytthumb.h"
2
3 #include "http.h"
4 #include "httpreply.h"
5 #include "httputils.h"
6
7 YTThumb::YTThumb(int width, int height, const QString &url)
8     : width(width), height(height), url(url) {}
9
10 VariantPromise &YTThumb::load(QObject *parent) {
11     qDebug() << parent;
12     if (promise) {
13         qDebug() << "Already loading" << promise;
14         return *promise;
15     }
16     promise = new VariantPromise(parent);
17     promise->connect(HttpUtils::yt().get(url), &HttpReply::finished, promise, [this](auto &reply) {
18         // clear promise member before emitting signals
19         auto promise2 = promise;
20         promise = nullptr;
21         if (reply.isSuccessful()) {
22             promise2->resolve(reply.body());
23         } else {
24             promise2->reject(reply.reasonPhrase());
25         }
26     });
27     return *promise;
28 }