Mercurial > minori
diff src/gui/window.cc @ 223:84e0a3c4737a
library: implement menu bar buttons
I also went ahead and put the links from Taiga in so I don't have to
worry about it later...
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 08 Jan 2024 16:54:16 -0500 |
parents | 975a3f0965e2 |
children | f784b5b1914c |
line wrap: on
line diff
--- a/src/gui/window.cc Mon Jan 08 13:22:09 2024 -0500 +++ b/src/gui/window.cc Mon Jan 08 16:54:16 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,49 @@ } 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... */ + for (std::size_t i = 0; i < session.config.library.paths.size(); i++) { + const QString folder = Strings::ToQString(session.config.library.paths[i]); + QAction* action = folder_menu->addAction(folder, [folder]{ + QDesktopServices::openUrl(QUrl::fromLocalFile(folder)); + }); + if (i < 9) + action->setShortcut(QKeySequence(Qt::ALT | (Qt::Key_1 + i))); + else if (i == 9) + action->setShortcut(QKeySequence(Qt::ALT | Qt::Key_0)); + } + + 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"), + "/home", + QFileDialog::ShowDirsOnly + | QFileDialog::DontResolveSymlinks); + if (dir.isEmpty()) + return; + session.config.library.paths.push_back(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 +218,7 @@ { QAction* action = menu->addAction(tr("E&xit"), qApp, &QApplication::quit); + action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q)); } } @@ -384,10 +412,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 +423,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); }