Mercurial > minori
annotate 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 |
rev | line source |
---|---|
9 | 1 #include "gui/window.h" |
64 | 2 #include "core/anime_db.h" |
9 | 3 #include "core/config.h" |
4 #include "core/session.h" | |
64 | 5 #include "core/strings.h" |
46 | 6 #include "gui/dark_theme.h" |
62 | 7 #include "gui/dialog/about.h" |
9 | 8 #include "gui/dialog/settings.h" |
9 #include "gui/pages/anime_list.h" | |
62 | 10 #include "gui/pages/history.h" |
9 | 11 #include "gui/pages/now_playing.h" |
62 | 12 #include "gui/pages/search.h" |
13 #include "gui/pages/seasons.h" | |
9 | 14 #include "gui/pages/statistics.h" |
54
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
51
diff
changeset
|
15 #include "gui/pages/torrents.h" |
46 | 16 #include "gui/widgets/sidebar.h" |
15 | 17 #include "services/services.h" |
64 | 18 #include "track/media.h" |
63 | 19 #include <QActionGroup> |
7 | 20 #include <QApplication> |
64 | 21 #include <QDebug> |
9 | 22 #include <QFile> |
7 | 23 #include <QMainWindow> |
24 #include <QMenuBar> | |
63 | 25 #include <QMessageBox> |
7 | 26 #include <QPlainTextEdit> |
27 #include <QStackedWidget> | |
63 | 28 #include <QTextStream> |
62 | 29 #include <QTimer> |
5 | 30 #if MACOSX |
15 | 31 # include "sys/osx/dark_theme.h" |
46 | 32 #elif defined(WIN32) |
15 | 33 # include "sys/win32/dark_theme.h" |
2 | 34 #endif |
35 | |
10 | 36 enum class Pages { |
37 NOW_PLAYING, | |
38 | |
39 ANIME_LIST, | |
40 HISTORY, | |
41 STATISTICS, | |
42 | |
43 SEARCH, | |
44 SEASONS, | |
45 TORRENTS | |
46 }; | |
47 | |
9 | 48 MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
49 main_widget = new QWidget(parent); |
10 | 50 |
51 SideBar* sidebar = new SideBar(main_widget); | |
51 | 52 sidebar->AddItem(tr("Now Playing"), SideBar::CreateIcon(":/icons/16x16/film.png")); |
10 | 53 sidebar->AddSeparator(); |
51 | 54 sidebar->AddItem(tr("Anime List"), SideBar::CreateIcon(":/icons/16x16/document-list.png")); |
55 sidebar->AddItem(tr("History"), SideBar::CreateIcon(":/icons/16x16/clock-history-frame.png")); | |
56 sidebar->AddItem(tr("Statistics"), SideBar::CreateIcon(":/icons/16x16/chart.png")); | |
10 | 57 sidebar->AddSeparator(); |
51 | 58 sidebar->AddItem(tr("Search"), SideBar::CreateIcon(":/icons/16x16/magnifier.png")); |
59 sidebar->AddItem(tr("Seasons"), SideBar::CreateIcon(":/icons/16x16/calendar.png")); | |
60 sidebar->AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/16x16/feed.png")); | |
10 | 61 sidebar->setFixedWidth(128); |
36 | 62 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
10 | 63 |
64 QStackedWidget* stack = new QStackedWidget(main_widget); | |
64 | 65 stack->addWidget(new NowPlayingPage(main_widget)); |
66 stack->addWidget(new AnimeListPage(main_widget)); | |
67 stack->addWidget(new HistoryPage(main_widget)); | |
68 stack->addWidget(new StatisticsPage(main_widget)); | |
69 stack->addWidget(new SearchPage(main_widget)); | |
70 stack->addWidget(new SeasonsPage(main_widget)); | |
71 stack->addWidget(new TorrentsPage(main_widget)); | |
10 | 72 |
54
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
51
diff
changeset
|
73 connect(sidebar, &SideBar::CurrentItemChanged, stack, &QStackedWidget::setCurrentIndex); |
64 | 74 sidebar->SetCurrentItem(static_cast<int>(Pages::ANIME_LIST)); |
10 | 75 |
2 | 76 /* Menu Bar */ |
77 QAction* action; | |
78 QMenuBar* menubar = new QMenuBar(parent); | |
51 | 79 QMenu* menu = menubar->addMenu(tr("&File")); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
80 |
51 | 81 QMenu* submenu = menu->addMenu(tr("&Library folders")); |
82 action = submenu->addAction(tr("&Add new folder...")); | |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
83 |
51 | 84 action = menu->addAction(tr("&Scan available episodes")); |
2 | 85 |
86 menu->addSeparator(); | |
87 | |
51 | 88 action = menu->addAction(tr("Play &next episode")); |
62 | 89 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_N)); |
51 | 90 action = menu->addAction(tr("Play &random episode")); |
62 | 91 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R)); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
92 |
2 | 93 menu->addSeparator(); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
94 |
51 | 95 action = menu->addAction(tr("E&xit"), qApp, &QApplication::quit); |
2 | 96 |
51 | 97 menu = menubar->addMenu(tr("&Services")); |
63 | 98 action = menu->addAction(tr("Synchronize &list"), [stack] { |
10 | 99 Services::Synchronize(); |
64 | 100 reinterpret_cast<AnimeListPage*>(stack->widget(static_cast<int>(Pages::ANIME_LIST)))->Refresh(); |
10 | 101 }); |
62 | 102 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S)); |
2 | 103 |
104 menu->addSeparator(); | |
105 | |
51 | 106 submenu = menu->addMenu(tr("&AniList")); |
107 action = submenu->addAction(tr("Go to my &profile")); | |
108 action = submenu->addAction(tr("Go to my &stats")); | |
2 | 109 |
51 | 110 submenu = menu->addMenu(tr("&Kitsu")); |
111 action = submenu->addAction(tr("Go to my &feed")); | |
112 action = submenu->addAction(tr("Go to my &library")); | |
113 action = submenu->addAction(tr("Go to my &profile")); | |
2 | 114 |
51 | 115 submenu = menu->addMenu(tr("&MyAnimeList")); |
116 action = submenu->addAction(tr("Go to my p&anel")); | |
117 action = submenu->addAction(tr("Go to my &profile")); | |
118 action = submenu->addAction(tr("Go to my &history")); | |
2 | 119 |
51 | 120 menu = menubar->addMenu(tr("&Tools")); |
121 submenu = menu->addMenu(tr("&Export anime list")); | |
122 action = submenu->addAction(tr("Export as &Markdown...")); | |
123 action = submenu->addAction(tr("Export as MyAnimeList &XML...")); | |
2 | 124 |
125 menu->addSeparator(); | |
126 | |
51 | 127 action = menu->addAction(tr("Enable anime &recognition")); |
2 | 128 action->setCheckable(true); |
51 | 129 action = menu->addAction(tr("Enable auto &sharing")); |
2 | 130 action->setCheckable(true); |
51 | 131 action = menu->addAction(tr("Enable &auto synchronization")); |
2 | 132 action->setCheckable(true); |
133 | |
134 menu->addSeparator(); | |
135 | |
51 | 136 action = menu->addAction(tr("&Settings"), [this] { |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
137 SettingsDialog dialog(this); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
138 dialog.exec(); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
139 }); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
140 action->setMenuRole(QAction::PreferencesRole); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
141 |
51 | 142 menu = menubar->addMenu(tr("&View")); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
143 |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
144 std::map<QAction*, int> page_to_index_map = {}; |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
145 |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
146 QActionGroup* pages_group = new QActionGroup(this); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
147 pages_group->setExclusive(true); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
148 |
51 | 149 action = pages_group->addAction(menu->addAction(tr("&Now Playing"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
150 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
151 page_to_index_map[action] = 0; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
152 |
51 | 153 action = pages_group->addAction(menu->addAction(tr("&Anime List"))); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
154 page_to_index_map[action] = 1; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
155 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
156 action->setChecked(true); |
58
b7a1c0010ffd
sidebar: link view menu and sidebar together
Paper <mrpapersonic@gmail.com>
parents:
54
diff
changeset
|
157 |
51 | 158 action = pages_group->addAction(menu->addAction(tr("&History"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
159 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
160 page_to_index_map[action] = 2; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
161 |
51 | 162 action = pages_group->addAction(menu->addAction(tr("&Statistics"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
163 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
164 page_to_index_map[action] = 3; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
165 |
51 | 166 action = pages_group->addAction(menu->addAction(tr("S&earch"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
167 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
168 page_to_index_map[action] = 4; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
169 |
51 | 170 action = pages_group->addAction(menu->addAction(tr("Se&asons"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
171 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
172 page_to_index_map[action] = 5; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
173 |
51 | 174 action = pages_group->addAction(menu->addAction(tr("&Torrents"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
175 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
176 page_to_index_map[action] = 6; |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
177 |
63 | 178 connect(sidebar, &SideBar::CurrentItemChanged, this, |
179 [pages_group](int index) { pages_group->actions()[index]->setChecked(true); }); | |
54
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
51
diff
changeset
|
180 |
63 | 181 connect(pages_group, &QActionGroup::triggered, this, |
182 [page_to_index_map, sidebar](QAction* action) { sidebar->SetCurrentItem(page_to_index_map.at(action)); }); | |
54
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
51
diff
changeset
|
183 |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
184 menu->addSeparator(); |
51 | 185 menu->addAction(tr("Show sidebar")); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
186 |
51 | 187 menu = menubar->addMenu(tr("&Help")); |
64 | 188 action = menu->addAction(tr("&About Minori"), this, [this] { |
51 | 189 AboutWindow dialog(this); |
190 dialog.exec(); | |
191 }); | |
192 action = menu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt); | |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
193 action->setMenuRole(QAction::AboutQtRole); |
2 | 194 |
195 setMenuBar(menubar); | |
7 | 196 |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
197 QHBoxLayout* layout = new QHBoxLayout(main_widget); |
37
9ae9365dd4ea
window.cpp: fix sidebar on Linux
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
198 layout->addWidget(sidebar); |
7 | 199 layout->addWidget(stack); |
200 setCentralWidget(main_widget); | |
2 | 201 |
64 | 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 | |
46 | 218 DarkTheme::SetTheme(session.config.theme); |
2 | 219 } |
220 | |
221 void MainWindow::SetActivePage(QWidget* page) { | |
222 this->setCentralWidget(page); | |
223 } | |
224 | |
225 void MainWindow::closeEvent(QCloseEvent* event) { | |
226 session.config.Save(); | |
227 event->accept(); | |
228 } | |
229 | |
9 | 230 #include "gui/moc_window.cpp" |