diff src/gui/window.cpp @ 77:6f7385bd334c

*: update formatted all source files, no more subclassing QThread... many other changes :)
author Paper <mrpapersonic@gmail.com>
date Fri, 06 Oct 2023 06:18:53 -0400
parents 27a19dd6cba1
children c489dd4434af
line wrap: on
line diff
--- a/src/gui/window.cpp	Wed Oct 04 01:46:33 2023 -0400
+++ b/src/gui/window.cpp	Fri Oct 06 06:18:53 2023 -0400
@@ -27,6 +27,7 @@
 #include <QPlainTextEdit>
 #include <QStackedWidget>
 #include <QTextStream>
+#include <QThreadPool>
 #include <QTimer>
 #include <QToolBar>
 #include <QToolButton>
@@ -48,6 +49,13 @@
 	TORRENTS
 };
 
+static void AsyncSynchronize(QStackedWidget* stack) {
+	QThreadPool::globalInstance()->start([stack] {
+		Services::Synchronize();
+		reinterpret_cast<AnimeListPage*>(stack->widget(static_cast<int>(Pages::ANIME_LIST)))->Refresh();
+	});
+}
+
 MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
 	main_widget = new QWidget(parent);
 
@@ -98,10 +106,7 @@
 	action = menu->addAction(tr("E&xit"), qApp, &QApplication::quit);
 
 	menu = menubar->addMenu(tr("&Services"));
-	action = menu->addAction(tr("Synchronize &list"), [stack] {
-		Services::Synchronize();
-		reinterpret_cast<AnimeListPage*>(stack->widget(static_cast<int>(Pages::ANIME_LIST)))->Refresh();
-	});
+	action = menu->addAction(tr("Synchronize &list"), [stack] { AsyncSynchronize(stack); });
 	action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S));
 
 	menu->addSeparator();
@@ -199,10 +204,8 @@
 
 	/* Toolbar */
 	QToolBar* toolbar = new QToolBar(this);
-	toolbar->addAction(QIcon(":/icons/24x24/arrow-circle-double-135.png"), tr("&Synchronize"), [stack] {
-		Services::Synchronize();
-		reinterpret_cast<AnimeListPage*>(stack->widget(static_cast<int>(Pages::ANIME_LIST)))->Refresh();
-	});
+	toolbar->addAction(QIcon(":/icons/24x24/arrow-circle-double-135.png"), tr("&Synchronize"),
+	                   [stack] { AsyncSynchronize(stack); });
 	toolbar->addSeparator();
 
 	QToolButton* button = new QToolButton(toolbar);