comparison src/gui/widgets/poster.cc @ 291:9a88e1725fd2

*: refactor lots of stuff I forgot to put this into different commits, oops! anyway, it doesn't really matter *that* much since this is an unfinished hobby project anyway. once it starts getting stable commit history will be more important, but for now it's not that big of a deal
author Paper <paper@paper.us.eu.org>
date Sun, 12 May 2024 16:31:07 -0400
parents 53e3c015a973
children b82841e76e79
comparison
equal deleted inserted replaced
290:9347e2eaf6e5 291:9a88e1725fd2
25 setFrameShape(QFrame::Box); 25 setFrameShape(QFrame::Box);
26 setFrameShadow(QFrame::Plain); 26 setFrameShadow(QFrame::Plain);
27 27
28 label_.setAlignment(Qt::AlignCenter); 28 label_.setAlignment(Qt::AlignCenter);
29 layout->addWidget(&label_); 29 layout->addWidget(&label_);
30
31 connect(&get_thread_, &HTTP::RequestThread::ReceivedData, this, &Poster::ImageDownloadFinished);
30 } 32 }
31 33
32 Poster::Poster(const Anime::Anime& anime, QWidget* parent) : Poster(parent) { 34 Poster::Poster(const Anime::Anime& anime, QWidget* parent) : Poster(parent) {
33 SetAnime(anime); 35 SetAnime(anime);
34 } 36 }
35 37
36 void Poster::SetAnime(const Anime::Anime& anime) { 38 void Poster::SetAnime(const Anime::Anime& anime) {
37 /* todo: only download on showEvent() */ 39 /* todo: only download on showEvent() */
38 { 40 if (get_thread_.isRunning())
39 HTTP::GetThread* thread = new HTTP::GetThread(anime.GetPosterUrl(), {}, this); 41 get_thread_.Stop();
42 get_thread_.wait();
40 43
41 connect(thread, &HTTP::GetThread::ReceivedData, this, &Poster::ImageDownloadFinished); 44 get_thread_.SetUrl(anime.GetPosterUrl());
42 connect(thread, &HTTP::GetThread::finished, thread, &HTTP::GetThread::deleteLater); 45 get_thread_.start();
43
44 thread->start();
45 }
46 46
47 std::optional<std::string> url = anime.GetServiceUrl(session.config.service); 47 std::optional<std::string> url = anime.GetServiceUrl(session.config.service);
48 if (url) 48 if (url)
49 service_url_ = Strings::ToQString(url.value()); 49 service_url_ = Strings::ToQString(url.value());
50 50