Mercurial > minori
changeset 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 | b9f111d84d95 |
children | 7ca56c4ac0bc |
files | dep/animia/include/animia/util.h dep/animia/src/win/wayland.cc include/library/library.h src/core/config.cc src/gui/window.cc src/library/library.cc |
diffstat | 6 files changed, 92 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/dep/animia/include/animia/util.h Mon Jan 08 13:22:09 2024 -0500 +++ b/dep/animia/include/animia/util.h Mon Jan 08 16:54:16 2024 -0500 @@ -2,6 +2,7 @@ #define __animia__animia__util_h #include <string> +#include <sstream> namespace animia::internal::util { @@ -12,6 +13,14 @@ bool TrimLeft(std::string& str, const char* chars); bool TrimRight(std::string& str, const char* chars); +template<typename T = int, + std::enable_if_t<std::is_integral<T>::value, bool> = true> +T StringToInt(const std::string& str, T def = 0) { + std::istringstream s(str); + s >> std::noboolalpha >> def; + return def; +} + } // namespace animia::internal::util -#endif // __animia__animia__util_h \ No newline at end of file +#endif // __animia__animia__util_h
--- a/dep/animia/src/win/wayland.cc Mon Jan 08 13:22:09 2024 -0500 +++ b/dep/animia/src/win/wayland.cc Mon Jan 08 16:54:16 2024 -0500 @@ -1,6 +1,7 @@ #include "animia/win/wayland.h" #include "animia.h" #include "animia/win.h" +#include "animia/util.h" #include <cstring> #include <iostream> @@ -90,9 +91,10 @@ reinterpret_cast<Window*>(data)->text = title; } -static void ext_foreign_handle_handle_identifier(void*, ext_foreign_toplevel_handle_v1*, const char* identifier) { - if (identifier) - reinterpret_cast<Window*>(data)->id = identifier; +static void ext_foreign_handle_handle_identifier(void* data, ext_foreign_toplevel_handle_v1* handle, const char* identifier) { + if (identifier) { + reinterpret_cast<Window*>(data)->id = util::StringToInt(identifier, 0); + } } static void ext_foreign_handle_handle_done(void* data, struct ext_foreign_toplevel_handle_v1* handle) {
--- a/include/library/library.h Mon Jan 08 13:22:09 2024 -0500 +++ b/include/library/library.h Mon Jan 08 16:54:16 2024 -0500 @@ -6,9 +6,13 @@ #include <unordered_map> #include <string> +namespace Library { + // int = anime id, map = episode, paths extern std::unordered_map<int, std::unordered_map<int, std::string>> library; void SearchLibraryFolders(); -#endif // __library__library_h \ No newline at end of file +} + +#endif // __library__library_h
--- a/src/core/config.cc Mon Jan 08 13:22:09 2024 -0500 +++ b/src/core/config.cc Mon Jan 08 16:54:16 2024 -0500 @@ -90,6 +90,8 @@ theme.SetTheme(Translate::ToTheme(INI::GetIniValue<std::string>(ini, "Appearance", "Theme", "Default"))); + library.paths = Strings::Split(INI::GetIniValue<std::string>(ini, "Library", "Folders", ""), ";"); + return 0; } @@ -131,6 +133,8 @@ } } + INI::SetIniValue(ini, "Library", "Folders", Strings::Implode(library.paths, ";")); + file.write(ini); return 0;
--- 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); }
--- a/src/library/library.cc Mon Jan 08 13:22:09 2024 -0500 +++ b/src/library/library.cc Mon Jan 08 16:54:16 2024 -0500 @@ -9,6 +9,10 @@ #include <unordered_map> #include <string> +#include <iostream> + +namespace Library { + // int = anime id, map = episode, paths std::unordered_map<int, std::unordered_map<int, std::string>> library; @@ -21,7 +25,7 @@ if (!std::filesystem::is_regular_file(entry.path())) continue; - const std::string basename = path.filename(); + const std::string basename = entry.path().filename(); anitomy::Anitomy anitomy; anitomy.Parse(Strings::ToWstring(basename)); @@ -34,10 +38,12 @@ if (id <= 0) continue; - const int episode = Strings::ToInt(Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle))); + const int episode = Strings::ToInt(Strings::ToUtf8String(elements.get(anitomy::kElementEpisodeNumber))); // we have an ID now! library[id][episode] = entry.path(); } } } + +}