diff 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
line wrap: on
line diff
--- a/src/gui/widgets/poster.cc	Wed May 08 17:32:28 2024 -0400
+++ b/src/gui/widgets/poster.cc	Sun May 12 16:31:07 2024 -0400
@@ -27,6 +27,8 @@
 
 	label_.setAlignment(Qt::AlignCenter);
 	layout->addWidget(&label_);
+
+	connect(&get_thread_, &HTTP::RequestThread::ReceivedData, this, &Poster::ImageDownloadFinished);
 }
 
 Poster::Poster(const Anime::Anime& anime, QWidget* parent) : Poster(parent) {
@@ -35,14 +37,12 @@
 
 void Poster::SetAnime(const Anime::Anime& anime) {
 	/* todo: only download on showEvent() */
-	{
-		HTTP::GetThread* thread = new HTTP::GetThread(anime.GetPosterUrl(), {}, this);
+	if (get_thread_.isRunning())
+		get_thread_.Stop();
+	get_thread_.wait();
 
-		connect(thread, &HTTP::GetThread::ReceivedData, this, &Poster::ImageDownloadFinished);
-		connect(thread, &HTTP::GetThread::finished, thread, &HTTP::GetThread::deleteLater);
-
-		thread->start();
-	}
+	get_thread_.SetUrl(anime.GetPosterUrl());
+	get_thread_.start();
 
 	std::optional<std::string> url = anime.GetServiceUrl(session.config.service);
 	if (url)