comparison 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
comparison
equal deleted inserted replaced
63:3d2decf093bb 64:fe719c109dbc
1 #include "gui/window.h" 1 #include "gui/window.h"
2 #include "core/anime_db.h"
2 #include "core/config.h" 3 #include "core/config.h"
3 #include "core/session.h" 4 #include "core/session.h"
5 #include "core/strings.h"
4 #include "gui/dark_theme.h" 6 #include "gui/dark_theme.h"
5 #include "gui/dialog/about.h" 7 #include "gui/dialog/about.h"
6 #include "gui/dialog/settings.h" 8 #include "gui/dialog/settings.h"
7 #include "gui/pages/anime_list.h" 9 #include "gui/pages/anime_list.h"
8 #include "gui/pages/history.h" 10 #include "gui/pages/history.h"
11 #include "gui/pages/seasons.h" 13 #include "gui/pages/seasons.h"
12 #include "gui/pages/statistics.h" 14 #include "gui/pages/statistics.h"
13 #include "gui/pages/torrents.h" 15 #include "gui/pages/torrents.h"
14 #include "gui/widgets/sidebar.h" 16 #include "gui/widgets/sidebar.h"
15 #include "services/services.h" 17 #include "services/services.h"
18 #include "track/media.h"
16 #include <QActionGroup> 19 #include <QActionGroup>
17 #include <QApplication> 20 #include <QApplication>
21 #include <QDebug>
18 #include <QFile> 22 #include <QFile>
19 #include <QMainWindow> 23 #include <QMainWindow>
20 #include <QMenuBar> 24 #include <QMenuBar>
21 #include <QMessageBox> 25 #include <QMessageBox>
22 #include <QPlainTextEdit> 26 #include <QPlainTextEdit>
56 sidebar->AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/16x16/feed.png")); 60 sidebar->AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/16x16/feed.png"));
57 sidebar->setFixedWidth(128); 61 sidebar->setFixedWidth(128);
58 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); 62 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
59 63
60 QStackedWidget* stack = new QStackedWidget(main_widget); 64 QStackedWidget* stack = new QStackedWidget(main_widget);
61 stack->addWidget(new NowPlayingWidget(main_widget)); 65 stack->addWidget(new NowPlayingPage(main_widget));
62 stack->addWidget(new AnimeListWidget(main_widget)); 66 stack->addWidget(new AnimeListPage(main_widget));
63 stack->addWidget(new HistoryWidget(main_widget)); 67 stack->addWidget(new HistoryPage(main_widget));
64 stack->addWidget(new StatisticsWidget(main_widget)); 68 stack->addWidget(new StatisticsPage(main_widget));
65 stack->addWidget(new SearchWidget(main_widget)); 69 stack->addWidget(new SearchPage(main_widget));
66 stack->addWidget(new SeasonsWidget(main_widget)); 70 stack->addWidget(new SeasonsPage(main_widget));
67 stack->addWidget(new TorrentsWidget(main_widget)); 71 stack->addWidget(new TorrentsPage(main_widget));
68 72
69 connect(sidebar, &SideBar::CurrentItemChanged, stack, &QStackedWidget::setCurrentIndex); 73 connect(sidebar, &SideBar::CurrentItemChanged, stack, &QStackedWidget::setCurrentIndex);
70 sidebar->SetCurrentItem((int)Pages::ANIME_LIST); 74 sidebar->SetCurrentItem(static_cast<int>(Pages::ANIME_LIST));
71 75
72 /* Menu Bar */ 76 /* Menu Bar */
73 QAction* action; 77 QAction* action;
74 QMenuBar* menubar = new QMenuBar(parent); 78 QMenuBar* menubar = new QMenuBar(parent);
75 QMenu* menu = menubar->addMenu(tr("&File")); 79 QMenu* menu = menubar->addMenu(tr("&File"));
91 action = menu->addAction(tr("E&xit"), qApp, &QApplication::quit); 95 action = menu->addAction(tr("E&xit"), qApp, &QApplication::quit);
92 96
93 menu = menubar->addMenu(tr("&Services")); 97 menu = menubar->addMenu(tr("&Services"));
94 action = menu->addAction(tr("Synchronize &list"), [stack] { 98 action = menu->addAction(tr("Synchronize &list"), [stack] {
95 Services::Synchronize(); 99 Services::Synchronize();
96 ((AnimeListWidget*)stack->widget((int)Pages::ANIME_LIST))->Refresh(); 100 reinterpret_cast<AnimeListPage*>(stack->widget(static_cast<int>(Pages::ANIME_LIST)))->Refresh();
97 }); 101 });
98 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S)); 102 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S));
99 103
100 menu->addSeparator(); 104 menu->addSeparator();
101 105
179 183
180 menu->addSeparator(); 184 menu->addSeparator();
181 menu->addAction(tr("Show sidebar")); 185 menu->addAction(tr("Show sidebar"));
182 186
183 menu = menubar->addMenu(tr("&Help")); 187 menu = menubar->addMenu(tr("&Help"));
184 action = menu->addAction(tr("About Minori"), this, [this] { 188 action = menu->addAction(tr("&About Minori"), this, [this] {
185 AboutWindow dialog(this); 189 AboutWindow dialog(this);
186 dialog.exec(); 190 dialog.exec();
187 }); 191 });
188 action = menu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt); 192 action = menu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt);
189 action->setMenuRole(QAction::AboutQtRole); 193 action->setMenuRole(QAction::AboutQtRole);
193 QHBoxLayout* layout = new QHBoxLayout(main_widget); 197 QHBoxLayout* layout = new QHBoxLayout(main_widget);
194 layout->addWidget(sidebar); 198 layout->addWidget(sidebar);
195 layout->addWidget(stack); 199 layout->addWidget(stack);
196 setCentralWidget(main_widget); 200 setCentralWidget(main_widget);
197 201
202 QTimer* timer = new QTimer(this);
203 connect(timer, &QTimer::timeout, this, [stack] {
204 NowPlayingPage* page = reinterpret_cast<NowPlayingPage*>(stack->widget(static_cast<int>(Pages::NOW_PLAYING)));
205
206 Filesystem::Path p = Track::Media::GetCurrentPlaying();
207 std::string title = Track::Media::GetFileTitle(p);
208 int id = Anime::db.GetAnimeFromTitle(title);
209 if (id == 0) {
210 page->SetDefault();
211 return;
212 }
213
214 page->SetPlaying(id);
215 });
216 timer->start(5000);
217
198 DarkTheme::SetTheme(session.config.theme); 218 DarkTheme::SetTheme(session.config.theme);
199 } 219 }
200 220
201 void MainWindow::SetActivePage(QWidget* page) { 221 void MainWindow::SetActivePage(QWidget* page) {
202 this->setCentralWidget(page); 222 this->setCentralWidget(page);