diff src/gui/window.cc @ 236:4d461ef7d424

HUGE UPDATE: convert build system to autotools why? because cmake sucks :)
author Paper <mrpapersonic@gmail.com>
date Fri, 19 Jan 2024 00:24:02 -0500
parents ff0061e75f0f
children a7d0d543b334
line wrap: on
line diff
--- a/src/gui/window.cc	Tue Jan 16 15:22:29 2024 -0500
+++ b/src/gui/window.cc	Fri Jan 19 00:24:02 2024 -0500
@@ -93,8 +93,10 @@
 			anitomy.Parse(Strings::ToWstring(file));
 
 			const auto& elements = anitomy.elements();
+			const std::string title = Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle));
+			std::cout << title << std::endl;
 
-			int id = Anime::db.GetAnimeFromTitle(Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle)));
+			int id = Anime::db.GetAnimeFromTitle(title);
 			if (id <= 0)
 				continue;
 
@@ -160,6 +162,7 @@
 void MainWindow::CreateBars() {
 	QMenuBar* menubar = new QMenuBar(this);
 	QMenu* folder_menu; /* this is used twice, so we declare it here */
+	QAction* sync_action;
 
 	{
 		/* File */
@@ -231,8 +234,14 @@
 		QMenu* menu = menubar->addMenu(tr("&Services"));
 		{
 			{
-				QAction* action = menu->addAction(tr("Synchronize &list"), [this] { AsyncSynchronize(stack.get()); });
-				action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S));
+				sync_action = menu->addAction(tr("Synchronize &list"));
+
+				connect(sync_action, &QAction::triggered, this, [this, sync_action]{
+					AsyncSynchronize(sync_action, stack.get());
+				});
+
+				sync_action->setIcon(QIcon(":/icons/24x24/arrow-circle-double-135.png"));
+				sync_action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S));
 			}
 
 //			menu->addSeparator();
@@ -300,6 +309,7 @@
 			QAction* action = menu->addAction(tr("&Settings"), [this] {
 				SettingsDialog dialog(this);
 				dialog.exec();
+				CreateBars();
 			});
 			action->setMenuRole(QAction::PreferencesRole);
 		}
@@ -408,8 +418,7 @@
 	{
 		/* Toolbar */
 		QToolBar* toolbar = new QToolBar(this);
-		toolbar->addAction(QIcon(":/icons/24x24/arrow-circle-double-135.png"), tr("&Synchronize"),
-						   [this] { AsyncSynchronize(stack.get()); });
+		toolbar->addAction(sync_action);
 
 		toolbar->addSeparator();
 
@@ -465,6 +474,7 @@
 		toolbar->addAction(QIcon(":/icons/24x24/gear.png"), tr("S&ettings"), [this] {
 			SettingsDialog dialog(this);
 			dialog.exec();
+			CreateBars();
 		});
 		addToolBar(toolbar);
 	}
@@ -474,7 +484,7 @@
 	this->setCentralWidget(page);
 }
 
-void MainWindow::AsyncSynchronize(QStackedWidget* stack) {
+void MainWindow::AsyncSynchronize(QAction* action, QStackedWidget* stack) {
 	if (session.config.service == Anime::Services::NONE) {
 		QMessageBox msg;
 		msg.setWindowTitle(tr("Error synchronizing with service!"));
@@ -488,9 +498,12 @@
 			dialog.exec();
 		}
 	}
-	QThreadPool::globalInstance()->start([stack] {
+
+	QThreadPool::globalInstance()->start([stack, action] {
+		action->setEnabled(false);
 		Services::Synchronize();
 		reinterpret_cast<AnimeListPage*>(stack->widget(static_cast<int>(Pages::ANIME_LIST)))->Refresh();
+		action->setEnabled(true);
 	});
 }
 
@@ -534,5 +547,3 @@
 	Anime::db.SaveDatabaseToDisk();
 	event->accept();
 }
-
-#include "gui/moc_window.cpp"