changeset 307:8769c5d50b06

pages/anime_list: don't call GUI functions in a non-GUI thread
author Paper <paper@paper.us.eu.org>
date Sun, 19 May 2024 18:25:14 -0400
parents f4538a4c91ba
children da2c5a8ff306
files include/gui/pages/anime_list.h src/gui/pages/anime_list.cc
diffstat 2 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/include/gui/pages/anime_list.h	Sun May 19 17:48:52 2024 -0400
+++ b/include/gui/pages/anime_list.h	Sun May 19 18:25:14 2024 -0400
@@ -15,11 +15,16 @@
 class AnimeListPage;
 
 class AnimeListPageUpdateEntryThread final : public QThread {
+	Q_OBJECT
+
 public:
 	AnimeListPageUpdateEntryThread(AnimeListPage* parent);
 
 	void AddToQueue(int id);
 
+signals:
+	void NeedRefresh();
+
 protected:
 	void run() override;
 
@@ -73,13 +78,13 @@
 	std::vector<Anime::Anime> list;
 };
 
-/* todo: rename these to "page" or something more
-   sensible than "widget" */
 class AnimeListPage final : public QWidget {
 	Q_OBJECT
 
 public:
 	AnimeListPage(QWidget* parent = nullptr);
+
+public slots:
 	void Refresh();
 
 protected:
--- a/src/gui/pages/anime_list.cc	Sun May 19 17:48:52 2024 -0400
+++ b/src/gui/pages/anime_list.cc	Sun May 19 18:25:14 2024 -0400
@@ -51,7 +51,7 @@
 			queue_.pop();
 		}
 	}
-	page_->Refresh();
+	emit NeedRefresh();
 }
 
 AnimeListPageSortFilter::AnimeListPageSortFilter(QObject* parent) : QSortFilterProxyModel(parent) {
@@ -512,6 +512,8 @@
 			tree_view->setModel(sort_models[index]);
 	});
 
+	connect(&update_entry_thread_, &AnimeListPageUpdateEntryThread::NeedRefresh, this, &AnimeListPage::Refresh);
+
 	SetColumnDefaults();
 	setFocusPolicy(Qt::TabFocus);
 	setFocusProxy(tab_bar);