Mercurial > minori
diff src/gui/window.cpp @ 64:fe719c109dbc
*: update
1. add media tracking ability, and it displays info on the `now playing` page
2. the `now playing` page now actually shows something
3. renamed every page class to be more accurate to what it is
4. ...
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 01 Oct 2023 23:15:43 -0400 |
parents | 3d2decf093bb |
children | 2417121d894e |
line wrap: on
line diff
--- a/src/gui/window.cpp Sun Oct 01 06:39:47 2023 -0400 +++ b/src/gui/window.cpp Sun Oct 01 23:15:43 2023 -0400 @@ -1,6 +1,8 @@ #include "gui/window.h" +#include "core/anime_db.h" #include "core/config.h" #include "core/session.h" +#include "core/strings.h" #include "gui/dark_theme.h" #include "gui/dialog/about.h" #include "gui/dialog/settings.h" @@ -13,8 +15,10 @@ #include "gui/pages/torrents.h" #include "gui/widgets/sidebar.h" #include "services/services.h" +#include "track/media.h" #include <QActionGroup> #include <QApplication> +#include <QDebug> #include <QFile> #include <QMainWindow> #include <QMenuBar> @@ -58,16 +62,16 @@ sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); QStackedWidget* stack = new QStackedWidget(main_widget); - stack->addWidget(new NowPlayingWidget(main_widget)); - stack->addWidget(new AnimeListWidget(main_widget)); - stack->addWidget(new HistoryWidget(main_widget)); - stack->addWidget(new StatisticsWidget(main_widget)); - stack->addWidget(new SearchWidget(main_widget)); - stack->addWidget(new SeasonsWidget(main_widget)); - stack->addWidget(new TorrentsWidget(main_widget)); + stack->addWidget(new NowPlayingPage(main_widget)); + stack->addWidget(new AnimeListPage(main_widget)); + stack->addWidget(new HistoryPage(main_widget)); + stack->addWidget(new StatisticsPage(main_widget)); + stack->addWidget(new SearchPage(main_widget)); + stack->addWidget(new SeasonsPage(main_widget)); + stack->addWidget(new TorrentsPage(main_widget)); connect(sidebar, &SideBar::CurrentItemChanged, stack, &QStackedWidget::setCurrentIndex); - sidebar->SetCurrentItem((int)Pages::ANIME_LIST); + sidebar->SetCurrentItem(static_cast<int>(Pages::ANIME_LIST)); /* Menu Bar */ QAction* action; @@ -93,7 +97,7 @@ menu = menubar->addMenu(tr("&Services")); action = menu->addAction(tr("Synchronize &list"), [stack] { Services::Synchronize(); - ((AnimeListWidget*)stack->widget((int)Pages::ANIME_LIST))->Refresh(); + reinterpret_cast<AnimeListPage*>(stack->widget(static_cast<int>(Pages::ANIME_LIST)))->Refresh(); }); action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S)); @@ -181,7 +185,7 @@ menu->addAction(tr("Show sidebar")); menu = menubar->addMenu(tr("&Help")); - action = menu->addAction(tr("About Minori"), this, [this] { + action = menu->addAction(tr("&About Minori"), this, [this] { AboutWindow dialog(this); dialog.exec(); }); @@ -195,6 +199,22 @@ 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); }