changeset 79:c489dd4434af

*: what did I do again? I really forgot what I did here :)
author Paper <mrpapersonic@gmail.com>
date Thu, 12 Oct 2023 11:31:39 -0400
parents 1ce00c1c8ddc
children 825506f0e221
files include/gui/pages/now_playing.h include/gui/window.h src/gui/pages/now_playing.cpp src/gui/window.cpp
diffstat 4 files changed, 54 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/include/gui/pages/now_playing.h	Wed Oct 11 12:16:15 2023 -0400
+++ b/include/gui/pages/now_playing.h	Thu Oct 12 11:31:39 2023 -0400
@@ -10,7 +10,7 @@
 	public:
 		NowPlayingPage(QWidget* parent = nullptr);
 		void SetDefault();
-		void SetPlaying(int id);
+		void SetPlaying(int id, int episodes);
 		int GetPlayingId();
 
 	private:
--- a/include/gui/window.h	Wed Oct 11 12:16:15 2023 -0400
+++ b/include/gui/window.h	Thu Oct 12 11:31:39 2023 -0400
@@ -1,9 +1,12 @@
 #ifndef __window_h
 #define __window_h
 #include "core/config.h"
-#include <QCloseEvent>
 #include <QMainWindow>
-#include <QWidget>
+
+class QWidget;
+class QStackedWidget;
+class QCloseEvent;
+class SideBar;
 
 class MainWindow : public QMainWindow {
 		Q_OBJECT
@@ -11,10 +14,13 @@
 	public:
 		MainWindow(QWidget* parent = nullptr);
 		void SetActivePage(QWidget* page);
+		void CreateBars();
 		void closeEvent(QCloseEvent* event) override;
 
 	private:
 		QWidget* main_widget;
+		QStackedWidget* stack;
+		SideBar* sidebar;
 };
 
 #endif // __window_h
--- a/src/gui/pages/now_playing.cpp	Wed Oct 11 12:16:15 2023 -0400
+++ b/src/gui/pages/now_playing.cpp	Thu Oct 12 11:31:39 2023 -0400
@@ -21,11 +21,12 @@
 
 	public:
 		Playing(QWidget* parent = nullptr);
-		void SetPlayingAnime(int id);
+		void SetPlayingAnime(int id, int episode);
 		int GetPlayingAnime();
 
 	private:
 		int _id = 0;
+		int _episode = 0;
 		std::unique_ptr<AnimeInfoWidget> info = nullptr;
 };
 
@@ -46,7 +47,9 @@
 	return _id;
 }
 
-void Playing::SetPlayingAnime(int id) {
+void Playing::SetPlayingAnime(int id, int episodes) {
+	if (id == _id)
+		return;
 	if (info.get())
 		layout()->removeWidget(info.get());
 	if (Anime::db.items.find(id) != Anime::db.items.end()) {
@@ -87,8 +90,8 @@
 	return reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->GetPlayingAnime();
 }
 
-void NowPlayingPage::SetPlaying(int id) {
-	reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(id);
+void NowPlayingPage::SetPlaying(int id, int episodes) {
+	reinterpret_cast<NowPlayingPages::Playing*>(stack->widget(1))->SetPlayingAnime(id, episodes);
 	stack->setCurrentIndex(1);
 }
 
--- a/src/gui/window.cpp	Wed Oct 11 12:16:15 2023 -0400
+++ b/src/gui/window.cpp	Thu Oct 12 11:31:39 2023 -0400
@@ -59,7 +59,7 @@
 MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
 	main_widget = new QWidget(parent);
 
-	SideBar* sidebar = new SideBar(main_widget);
+	sidebar = new SideBar(main_widget);
 	sidebar->AddItem(tr("Now Playing"), SideBar::CreateIcon(":/icons/16x16/film.png"));
 	sidebar->AddSeparator();
 	sidebar->AddItem(tr("Anime List"), SideBar::CreateIcon(":/icons/16x16/document-list.png"));
@@ -72,7 +72,7 @@
 	sidebar->setFixedWidth(128);
 	sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
 
-	QStackedWidget* stack = new QStackedWidget(main_widget);
+	stack = new QStackedWidget(main_widget);
 	stack->addWidget(new NowPlayingPage(main_widget));
 	stack->addWidget(new AnimeListPage(main_widget));
 	stack->addWidget(new HistoryPage(main_widget));
@@ -84,9 +84,36 @@
 	connect(sidebar, &SideBar::CurrentItemChanged, stack, &QStackedWidget::setCurrentIndex);
 	sidebar->SetCurrentItem(static_cast<int>(Pages::ANIME_LIST));
 
+	QHBoxLayout* layout = new QHBoxLayout(main_widget);
+	layout->addWidget(sidebar);
+	layout->addWidget(stack);
+	setCentralWidget(main_widget);
+
+	CreateBars();
+
+	QTimer* timer = new QTimer(this);
+	connect(timer, &QTimer::timeout, this, [this] {
+		NowPlayingPage* page = reinterpret_cast<NowPlayingPage*>(stack->widget(static_cast<int>(Pages::NOW_PLAYING)));
+
+		Filesystem::Path p = Track::Media::GetCurrentPlaying();
+		std::string title = Track::Media::GetFileTitle(p);
+		int id = Anime::db.GetAnimeFromTitle(title);
+		if (id == 0) {
+			page->SetDefault();
+			return;
+		}
+
+		page->SetPlaying(id, -1);
+	});
+	timer->start(5000);
+
+	DarkTheme::SetTheme(session.config.theme);
+}
+
+void MainWindow::CreateBars() {
 	/* Menu Bar */
 	QAction* action;
-	QMenuBar* menubar = new QMenuBar(parent);
+	QMenuBar* menubar = new QMenuBar(this);
 	QMenu* menu = menubar->addMenu(tr("&File"));
 
 	QMenu* submenu = menu->addMenu(tr("&Library folders"));
@@ -106,7 +133,7 @@
 	action = menu->addAction(tr("E&xit"), qApp, &QApplication::quit);
 
 	menu = menubar->addMenu(tr("&Services"));
-	action = menu->addAction(tr("Synchronize &list"), [stack] { AsyncSynchronize(stack); });
+	action = menu->addAction(tr("Synchronize &list"), [this] { AsyncSynchronize(stack); });
 	action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S));
 
 	menu->addSeparator();
@@ -187,7 +214,7 @@
 	        [pages_group](int index) { pages_group->actions()[index]->setChecked(true); });
 
 	connect(pages_group, &QActionGroup::triggered, this,
-	        [page_to_index_map, sidebar](QAction* action) { sidebar->SetCurrentItem(page_to_index_map.at(action)); });
+	        [this, page_to_index_map](QAction* action) { sidebar->SetCurrentItem(page_to_index_map.at(action)); });
 
 	menu->addSeparator();
 	menu->addAction(tr("Show sidebar"));
@@ -203,9 +230,14 @@
 	setMenuBar(menubar);
 
 	/* Toolbar */
+	/* remove old toolbar(s) */
+	QList<QToolBar*> toolbars = findChildren<QToolBar*>();
+	for (auto& t : toolbars)
+		removeToolBar(t);
+
 	QToolBar* toolbar = new QToolBar(this);
 	toolbar->addAction(QIcon(":/icons/24x24/arrow-circle-double-135.png"), tr("&Synchronize"),
-	                   [stack] { AsyncSynchronize(stack); });
+	                   [this] { AsyncSynchronize(stack); });
 	toolbar->addSeparator();
 
 	QToolButton* button = new QToolButton(toolbar);
@@ -235,28 +267,6 @@
 	});
 	addToolBar(toolbar);
 
-	QHBoxLayout* layout = new QHBoxLayout(main_widget);
-	layout->addWidget(sidebar);
-	layout->addWidget(stack);
-	setCentralWidget(main_widget);
-
-	QTimer* timer = new QTimer(this);
-	connect(timer, &QTimer::timeout, this, [stack] {
-		NowPlayingPage* page = reinterpret_cast<NowPlayingPage*>(stack->widget(static_cast<int>(Pages::NOW_PLAYING)));
-
-		Filesystem::Path p = Track::Media::GetCurrentPlaying();
-		std::string title = Track::Media::GetFileTitle(p);
-		int id = Anime::db.GetAnimeFromTitle(title);
-		if (id == 0) {
-			page->SetDefault();
-			return;
-		}
-
-		page->SetPlaying(id);
-	});
-	timer->start(5000);
-
-	DarkTheme::SetTheme(session.config.theme);
 }
 
 void MainWindow::SetActivePage(QWidget* page) {