diff src/gui/window.cc @ 231:69f4768a820c

chore: merge divergent branches
author Paper <paper@paper.us.eu.org>
date Sat, 13 Jan 2024 09:43:41 -0500
parents d030b30526d5
children ff0061e75f0f
line wrap: on
line diff
--- a/src/gui/window.cc	Sat Jan 13 09:42:02 2024 -0500
+++ b/src/gui/window.cc	Sat Jan 13 09:43:41 2024 -0500
@@ -16,13 +16,16 @@
 #include "gui/widgets/sidebar.h"
 #include "services/services.h"
 #include "track/media.h"
+#include "library/library.h"
 
 #include "anitomy/anitomy.h"
 
 #include <QActionGroup>
 #include <QApplication>
 #include <QDebug>
+#include <QDesktopServices>
 #include <QFile>
+#include <QFileDialog>
 #include <QHBoxLayout>
 #include <QMainWindow>
 #include <QMenuBar>
@@ -154,25 +157,52 @@
 }
 
 void MainWindow::CreateBars() {
-	/* Menu Bar
-	   The notation of these might seem ugly at first, but it's actually very nice
-	   (just trust me). It makes it much easier to edit the lists and makes it clear
-	   if you're in submenu or not. */
 	QMenuBar* menubar = new QMenuBar(this);
+	QMenu* folder_menu; /* this is used twice, so we declare it here */
 
 	{
 		/* File */
 		QMenu* menu = menubar->addMenu(tr("&File"));
 
 		{
-			QMenu* submenu = menu->addMenu(tr("&Library folders"));
+			folder_menu = menu->addMenu(tr("&Library folders"));
+
+			/* add in all of our existing folders... */
+			std::size_t i = 0;
+			for (const auto& path : session.config.library.paths) {
+				const QString folder = Strings::ToQString(path);
+				QAction* action = folder_menu->addAction(folder, [folder]{
+					QDesktopServices::openUrl(QUrl::fromLocalFile(folder));
+				});
+				if (i < 9)
+					action->setShortcut(QKeySequence(Qt::ALT | static_cast<Qt::Modifier>(Qt::Key_1 + i)));
+				else if (i == 9)
+					action->setShortcut(QKeySequence(Qt::ALT | Qt::Key_0));
+				/* don't bother with a shortcut in case of more... */
+				i++;
+			}
+
+			folder_menu->addSeparator();
+
 			{
-				QAction* action = submenu->addAction(tr("&Add new folder..."));
+				folder_menu->addAction(tr("&Add new folder..."), [this]{
+					const QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
+																		  QDir::homePath(),
+																		  QFileDialog::ShowDirsOnly
+																		  | QFileDialog::DontResolveSymlinks);
+					if (dir.isEmpty())
+						return;
+					session.config.library.paths.insert(Strings::ToUtf8String(dir));
+					/* we have to recreate the menu bar to add the new folder */
+					CreateBars();
+				});
 			}
 		}
 
 		{
-			QAction* action = menu->addAction(tr("&Scan available episodes"));
+			menu->addAction(tr("&Scan available episodes"), []{
+				Library::SearchLibraryFolders();
+			});
 		}
 
 		menu->addSeparator();
@@ -191,6 +221,7 @@
 
 		{
 			QAction* action = menu->addAction(tr("E&xit"), qApp, &QApplication::quit);
+			action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q));
 		}
 	}
 
@@ -384,10 +415,7 @@
 		{
 			QToolButton* button = new QToolButton(toolbar);
 			{
-				QMenu* menu = new QMenu(button);
-				QAction* action = menu->addAction(tr("..."));
-
-				button->setMenu(menu);
+				button->setMenu(folder_menu);
 			}
 			button->setIcon(QIcon(":/icons/24x24/folder-open.png"));
 			button->setPopupMode(QToolButton::InstantPopup);
@@ -398,8 +426,31 @@
 			QToolButton* button = new QToolButton(toolbar);
 
 			{
+				/* links */
 				QMenu* menu = new QMenu(button);
-				QAction* action = menu->addAction(tr("..."));
+				menu->addAction("Hibari", []{
+					QDesktopServices::openUrl(QUrl("https://hb.wopian.me/"));
+				});
+				menu->addAction("MALgraph", []{
+					QDesktopServices::openUrl(QUrl("https://graph.anime.plus/"));
+				});
+				menu->addSeparator();
+				menu->addAction("AniChart", []{
+					QDesktopServices::openUrl(QUrl("https://anichart.net/airing"));
+				});
+				menu->addAction("Monthly.moe", []{
+					QDesktopServices::openUrl(QUrl("https://www.monthly.moe/weekly"));
+				});
+				menu->addAction("Senpai Anime Charts", []{
+					QDesktopServices::openUrl(QUrl("https://www.senpai.moe/?mode=calendar"));
+				});
+				menu->addSeparator();
+				menu->addAction("Anime Streaming Search Engine", []{
+					QDesktopServices::openUrl(QUrl("https://because.moe/"));
+				});
+				menu->addAction("The Fansub Database", []{
+					QDesktopServices::openUrl(QUrl("https://fansubdb.com"));
+				});
 
 				button->setMenu(menu);
 			}