comparison src/gui/widgets/poster.cc @ 230:2f5a9247e501

torrents: implement download button erg
author Paper <paper@paper.us.eu.org>
date Sat, 13 Jan 2024 09:42:02 -0500
parents 9613d72b097e
children ff0061e75f0f
comparison
equal deleted inserted replaced
229:adc20fa321c1 230:2f5a9247e501
10 #include <QFrame> 10 #include <QFrame>
11 #include <QHBoxLayout> 11 #include <QHBoxLayout>
12 #include <QLabel> 12 #include <QLabel>
13 #include <QMessageBox> 13 #include <QMessageBox>
14 #include <QPixmap> 14 #include <QPixmap>
15 #include <QThreadPool> 15 #include <QThread>
16 #include <QUrl> 16 #include <QUrl>
17 #include <curl/curl.h> 17 #include <curl/curl.h>
18 18
19 Poster::Poster(QWidget* parent) : QFrame(parent) { 19 Poster::Poster(QWidget* parent) : QFrame(parent) {
20 QHBoxLayout* layout = new QHBoxLayout(this); 20 QHBoxLayout* layout = new QHBoxLayout(this);
33 Poster::Poster(const Anime::Anime& anime, QWidget* parent) : Poster(parent) { 33 Poster::Poster(const Anime::Anime& anime, QWidget* parent) : Poster(parent) {
34 SetAnime(anime); 34 SetAnime(anime);
35 } 35 }
36 36
37 void Poster::SetAnime(const Anime::Anime& anime) { 37 void Poster::SetAnime(const Anime::Anime& anime) {
38 QThreadPool::globalInstance()->start([this, anime] { 38 {
39 QByteArray ba = HTTP::Get(anime.GetPosterUrl(), {}); 39 QByteArray ba;
40 ImageDownloadFinished(ba); 40
41 }); 41 QThread* thread = QThread::create([&] {
42 ba = HTTP::Get(anime.GetPosterUrl(), {});
43 });
44
45 connect(thread, &QThread::finished, this, [&] {
46 ImageDownloadFinished(ba);
47 });
48
49 thread->start();
50 }
42 51
43 label->disconnect(); 52 label->disconnect();
44 connect(label, &ClickableLabel::clicked, this, 53 connect(label, &ClickableLabel::clicked, this,
45 [anime] { QDesktopServices::openUrl(Strings::ToQString(anime.GetServiceUrl())); }); 54 [anime] { QDesktopServices::openUrl(Strings::ToQString(anime.GetServiceUrl())); });
46 } 55 }