Mercurial > minori
annotate src/gui/window.cc @ 108:2004b41d4a59
*: huge commit
1. WORKING LOCALIZATION + translation for Spanish and British English
2. idk like 2 changes for the dark theme :)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 05 Nov 2023 23:31:49 -0500 |
parents | c8c72278f6fd |
children | 80f49f623d30 |
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" |
102 | 6 #include "gui/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> |
69 | 23 #include <QHBoxLayout> |
7 | 24 #include <QMainWindow> |
25 #include <QMenuBar> | |
63 | 26 #include <QMessageBox> |
7 | 27 #include <QPlainTextEdit> |
28 #include <QStackedWidget> | |
63 | 29 #include <QTextStream> |
77 | 30 #include <QThreadPool> |
62 | 31 #include <QTimer> |
69 | 32 #include <QToolBar> |
33 #include <QToolButton> | |
106
c8c72278f6fd
*: #if -> #ifdef, remove outdated comments in sys/win32/dark_theme.cc
Paper <mrpapersonic@gmail.com>
parents:
105
diff
changeset
|
34 #ifdef MACOSX |
15 | 35 # include "sys/osx/dark_theme.h" |
46 | 36 #elif defined(WIN32) |
15 | 37 # include "sys/win32/dark_theme.h" |
2 | 38 #endif |
39 | |
10 | 40 enum class Pages { |
41 NOW_PLAYING, | |
42 | |
43 ANIME_LIST, | |
44 HISTORY, | |
45 STATISTICS, | |
46 | |
47 SEARCH, | |
48 SEASONS, | |
49 TORRENTS | |
50 }; | |
51 | |
77 | 52 static void AsyncSynchronize(QStackedWidget* stack) { |
53 QThreadPool::globalInstance()->start([stack] { | |
54 Services::Synchronize(); | |
55 reinterpret_cast<AnimeListPage*>(stack->widget(static_cast<int>(Pages::ANIME_LIST)))->Refresh(); | |
56 }); | |
57 } | |
58 | |
9 | 59 MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { |
103 | 60 setWindowIcon(QIcon(":/favicon.png")); |
61 | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
62 main_widget = new QWidget(parent); |
10 | 63 |
79 | 64 sidebar = new SideBar(main_widget); |
51 | 65 sidebar->AddItem(tr("Now Playing"), SideBar::CreateIcon(":/icons/16x16/film.png")); |
10 | 66 sidebar->AddSeparator(); |
51 | 67 sidebar->AddItem(tr("Anime List"), SideBar::CreateIcon(":/icons/16x16/document-list.png")); |
68 sidebar->AddItem(tr("History"), SideBar::CreateIcon(":/icons/16x16/clock-history-frame.png")); | |
69 sidebar->AddItem(tr("Statistics"), SideBar::CreateIcon(":/icons/16x16/chart.png")); | |
10 | 70 sidebar->AddSeparator(); |
51 | 71 sidebar->AddItem(tr("Search"), SideBar::CreateIcon(":/icons/16x16/magnifier.png")); |
72 sidebar->AddItem(tr("Seasons"), SideBar::CreateIcon(":/icons/16x16/calendar.png")); | |
73 sidebar->AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/16x16/feed.png")); | |
10 | 74 sidebar->setFixedWidth(128); |
36 | 75 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
10 | 76 |
79 | 77 stack = new QStackedWidget(main_widget); |
64 | 78 stack->addWidget(new NowPlayingPage(main_widget)); |
79 stack->addWidget(new AnimeListPage(main_widget)); | |
80 stack->addWidget(new HistoryPage(main_widget)); | |
81 stack->addWidget(new StatisticsPage(main_widget)); | |
82 stack->addWidget(new SearchPage(main_widget)); | |
83 stack->addWidget(new SeasonsPage(main_widget)); | |
84 stack->addWidget(new TorrentsPage(main_widget)); | |
10 | 85 |
54
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
51
diff
changeset
|
86 connect(sidebar, &SideBar::CurrentItemChanged, stack, &QStackedWidget::setCurrentIndex); |
64 | 87 sidebar->SetCurrentItem(static_cast<int>(Pages::ANIME_LIST)); |
10 | 88 |
79 | 89 QHBoxLayout* layout = new QHBoxLayout(main_widget); |
90 layout->addWidget(sidebar); | |
91 layout->addWidget(stack); | |
92 setCentralWidget(main_widget); | |
93 | |
94 CreateBars(); | |
95 | |
96 QTimer* timer = new QTimer(this); | |
97 connect(timer, &QTimer::timeout, this, [this] { | |
98 NowPlayingPage* page = reinterpret_cast<NowPlayingPage*>(stack->widget(static_cast<int>(Pages::NOW_PLAYING))); | |
99 | |
100 Filesystem::Path p = Track::Media::GetCurrentPlaying(); | |
80 | 101 std::unordered_map<std::string, std::string> elements = Track::Media::GetFileElements(p); |
102 int id = Anime::db.GetAnimeFromTitle(elements["title"]); | |
83 | 103 if (id <= 0) { |
79 | 104 page->SetDefault(); |
105 return; | |
106 } | |
107 | |
83 | 108 page->SetPlaying(Anime::db.items[id], elements); |
79 | 109 }); |
110 timer->start(5000); | |
111 } | |
112 | |
113 void MainWindow::CreateBars() { | |
2 | 114 /* Menu Bar */ |
115 QAction* action; | |
79 | 116 QMenuBar* menubar = new QMenuBar(this); |
51 | 117 QMenu* menu = menubar->addMenu(tr("&File")); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
118 |
51 | 119 QMenu* submenu = menu->addMenu(tr("&Library folders")); |
120 action = submenu->addAction(tr("&Add new folder...")); | |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
121 |
51 | 122 action = menu->addAction(tr("&Scan available episodes")); |
2 | 123 |
124 menu->addSeparator(); | |
125 | |
51 | 126 action = menu->addAction(tr("Play &next episode")); |
62 | 127 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_N)); |
51 | 128 action = menu->addAction(tr("Play &random episode")); |
62 | 129 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R)); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
130 |
2 | 131 menu->addSeparator(); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
132 |
51 | 133 action = menu->addAction(tr("E&xit"), qApp, &QApplication::quit); |
2 | 134 |
51 | 135 menu = menubar->addMenu(tr("&Services")); |
79 | 136 action = menu->addAction(tr("Synchronize &list"), [this] { AsyncSynchronize(stack); }); |
62 | 137 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S)); |
2 | 138 |
139 menu->addSeparator(); | |
140 | |
51 | 141 submenu = menu->addMenu(tr("&AniList")); |
142 action = submenu->addAction(tr("Go to my &profile")); | |
143 action = submenu->addAction(tr("Go to my &stats")); | |
2 | 144 |
51 | 145 submenu = menu->addMenu(tr("&Kitsu")); |
146 action = submenu->addAction(tr("Go to my &feed")); | |
147 action = submenu->addAction(tr("Go to my &library")); | |
148 action = submenu->addAction(tr("Go to my &profile")); | |
2 | 149 |
51 | 150 submenu = menu->addMenu(tr("&MyAnimeList")); |
151 action = submenu->addAction(tr("Go to my p&anel")); | |
152 action = submenu->addAction(tr("Go to my &profile")); | |
153 action = submenu->addAction(tr("Go to my &history")); | |
2 | 154 |
51 | 155 menu = menubar->addMenu(tr("&Tools")); |
156 submenu = menu->addMenu(tr("&Export anime list")); | |
157 action = submenu->addAction(tr("Export as &Markdown...")); | |
158 action = submenu->addAction(tr("Export as MyAnimeList &XML...")); | |
2 | 159 |
160 menu->addSeparator(); | |
161 | |
51 | 162 action = menu->addAction(tr("Enable anime &recognition")); |
2 | 163 action->setCheckable(true); |
51 | 164 action = menu->addAction(tr("Enable auto &sharing")); |
2 | 165 action->setCheckable(true); |
51 | 166 action = menu->addAction(tr("Enable &auto synchronization")); |
2 | 167 action->setCheckable(true); |
168 | |
169 menu->addSeparator(); | |
170 | |
51 | 171 action = menu->addAction(tr("&Settings"), [this] { |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
172 SettingsDialog dialog(this); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
173 dialog.exec(); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
174 }); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
175 action->setMenuRole(QAction::PreferencesRole); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
176 |
51 | 177 menu = menubar->addMenu(tr("&View")); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
178 |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
179 std::map<QAction*, int> page_to_index_map = {}; |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
180 |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
181 QActionGroup* pages_group = new QActionGroup(this); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
182 pages_group->setExclusive(true); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
183 |
51 | 184 action = pages_group->addAction(menu->addAction(tr("&Now Playing"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
185 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
186 page_to_index_map[action] = 0; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
187 |
51 | 188 action = pages_group->addAction(menu->addAction(tr("&Anime List"))); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
189 page_to_index_map[action] = 1; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
190 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
191 action->setChecked(true); |
58
b7a1c0010ffd
sidebar: link view menu and sidebar together
Paper <mrpapersonic@gmail.com>
parents:
54
diff
changeset
|
192 |
51 | 193 action = pages_group->addAction(menu->addAction(tr("&History"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
194 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
195 page_to_index_map[action] = 2; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
196 |
51 | 197 action = pages_group->addAction(menu->addAction(tr("&Statistics"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
198 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
199 page_to_index_map[action] = 3; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
200 |
51 | 201 action = pages_group->addAction(menu->addAction(tr("S&earch"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
202 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
203 page_to_index_map[action] = 4; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
204 |
51 | 205 action = pages_group->addAction(menu->addAction(tr("Se&asons"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
206 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
207 page_to_index_map[action] = 5; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
208 |
51 | 209 action = pages_group->addAction(menu->addAction(tr("&Torrents"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
210 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
211 page_to_index_map[action] = 6; |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
212 |
63 | 213 connect(sidebar, &SideBar::CurrentItemChanged, this, |
214 [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
|
215 |
63 | 216 connect(pages_group, &QActionGroup::triggered, this, |
79 | 217 [this, page_to_index_map](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
|
218 |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
219 menu->addSeparator(); |
51 | 220 menu->addAction(tr("Show sidebar")); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
221 |
51 | 222 menu = menubar->addMenu(tr("&Help")); |
64 | 223 action = menu->addAction(tr("&About Minori"), this, [this] { |
51 | 224 AboutWindow dialog(this); |
225 dialog.exec(); | |
226 }); | |
227 action = menu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt); | |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
228 action->setMenuRole(QAction::AboutQtRole); |
2 | 229 |
230 setMenuBar(menubar); | |
7 | 231 |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
232 /* Toolbar */ |
79 | 233 /* remove old toolbar(s) */ |
234 QList<QToolBar*> toolbars = findChildren<QToolBar*>(); | |
235 for (auto& t : toolbars) | |
236 removeToolBar(t); | |
237 | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
238 QToolBar* toolbar = new QToolBar(this); |
77 | 239 toolbar->addAction(QIcon(":/icons/24x24/arrow-circle-double-135.png"), tr("&Synchronize"), |
79 | 240 [this] { AsyncSynchronize(stack); }); |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
241 toolbar->addSeparator(); |
69 | 242 |
243 QToolButton* button = new QToolButton(toolbar); | |
244 | |
245 menu = new QMenu(button); | |
246 action = menu->addAction(tr("Add new folder...")); | |
247 | |
248 button->setMenu(menu); | |
249 button->setIcon(QIcon(":/icons/24x24/folder-open.png")); | |
250 button->setPopupMode(QToolButton::InstantPopup); | |
251 toolbar->addWidget(button); | |
252 | |
253 button = new QToolButton(toolbar); | |
254 | |
255 menu = new QMenu(button); | |
256 action = menu->addAction(tr("Placeholder")); | |
257 | |
258 button->setMenu(menu); | |
259 button->setIcon(QIcon(":/icons/24x24/application-export.png")); | |
260 button->setPopupMode(QToolButton::InstantPopup); | |
261 toolbar->addWidget(button); | |
262 | |
263 toolbar->addSeparator(); | |
264 toolbar->addAction(QIcon(":/icons/24x24/gear.png"), tr("S&ettings"), [this] { | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
265 SettingsDialog dialog(this); |
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
266 dialog.exec(); |
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
267 }); |
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
268 addToolBar(toolbar); |
2 | 269 } |
270 | |
271 void MainWindow::SetActivePage(QWidget* page) { | |
272 this->setCentralWidget(page); | |
273 } | |
274 | |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
103
diff
changeset
|
275 void MainWindow::showEvent(QShowEvent* event) { |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
103
diff
changeset
|
276 QMainWindow::showEvent(event); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
103
diff
changeset
|
277 #ifdef WIN32 |
108 | 278 win32::SetTitleBarsToBlack(session.config.theme.IsInDarkTheme()); |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
103
diff
changeset
|
279 #endif |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
103
diff
changeset
|
280 } |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
103
diff
changeset
|
281 |
2 | 282 void MainWindow::closeEvent(QCloseEvent* event) { |
283 session.config.Save(); | |
284 event->accept(); | |
285 } | |
286 | |
9 | 287 #include "gui/moc_window.cpp" |