Mercurial > minori
annotate src/gui/window.cc @ 102:b315f3759c56
*: big patch
1. use a wrapper for mINI that enables case sensitivity
(personal preference)
2. rename dark_theme.cc to theme.cc and change it to be
a class
3. include the "dep" folder so we don't have stupidity in
json.h or ini.h
4. I think the graph was also tweaked a lot in this, nothing
is constexpr and size is found at runtime...
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Fri, 03 Nov 2023 21:32:52 -0400 |
parents | d02fdf1d6708 |
children | 621084cc542c |
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> | |
5 | 34 #if 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) { |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
60 main_widget = new QWidget(parent); |
10 | 61 |
79 | 62 sidebar = new SideBar(main_widget); |
51 | 63 sidebar->AddItem(tr("Now Playing"), SideBar::CreateIcon(":/icons/16x16/film.png")); |
10 | 64 sidebar->AddSeparator(); |
51 | 65 sidebar->AddItem(tr("Anime List"), SideBar::CreateIcon(":/icons/16x16/document-list.png")); |
66 sidebar->AddItem(tr("History"), SideBar::CreateIcon(":/icons/16x16/clock-history-frame.png")); | |
67 sidebar->AddItem(tr("Statistics"), SideBar::CreateIcon(":/icons/16x16/chart.png")); | |
10 | 68 sidebar->AddSeparator(); |
51 | 69 sidebar->AddItem(tr("Search"), SideBar::CreateIcon(":/icons/16x16/magnifier.png")); |
70 sidebar->AddItem(tr("Seasons"), SideBar::CreateIcon(":/icons/16x16/calendar.png")); | |
71 sidebar->AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/16x16/feed.png")); | |
10 | 72 sidebar->setFixedWidth(128); |
36 | 73 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
10 | 74 |
79 | 75 stack = new QStackedWidget(main_widget); |
64 | 76 stack->addWidget(new NowPlayingPage(main_widget)); |
77 stack->addWidget(new AnimeListPage(main_widget)); | |
78 stack->addWidget(new HistoryPage(main_widget)); | |
79 stack->addWidget(new StatisticsPage(main_widget)); | |
80 stack->addWidget(new SearchPage(main_widget)); | |
81 stack->addWidget(new SeasonsPage(main_widget)); | |
82 stack->addWidget(new TorrentsPage(main_widget)); | |
10 | 83 |
54
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
51
diff
changeset
|
84 connect(sidebar, &SideBar::CurrentItemChanged, stack, &QStackedWidget::setCurrentIndex); |
64 | 85 sidebar->SetCurrentItem(static_cast<int>(Pages::ANIME_LIST)); |
10 | 86 |
79 | 87 QHBoxLayout* layout = new QHBoxLayout(main_widget); |
88 layout->addWidget(sidebar); | |
89 layout->addWidget(stack); | |
90 setCentralWidget(main_widget); | |
91 | |
92 CreateBars(); | |
93 | |
94 QTimer* timer = new QTimer(this); | |
95 connect(timer, &QTimer::timeout, this, [this] { | |
96 NowPlayingPage* page = reinterpret_cast<NowPlayingPage*>(stack->widget(static_cast<int>(Pages::NOW_PLAYING))); | |
97 | |
98 Filesystem::Path p = Track::Media::GetCurrentPlaying(); | |
80 | 99 std::unordered_map<std::string, std::string> elements = Track::Media::GetFileElements(p); |
100 int id = Anime::db.GetAnimeFromTitle(elements["title"]); | |
83 | 101 if (id <= 0) { |
79 | 102 page->SetDefault(); |
103 return; | |
104 } | |
105 | |
83 | 106 page->SetPlaying(Anime::db.items[id], elements); |
79 | 107 }); |
108 timer->start(5000); | |
109 } | |
110 | |
111 void MainWindow::CreateBars() { | |
2 | 112 /* Menu Bar */ |
113 QAction* action; | |
79 | 114 QMenuBar* menubar = new QMenuBar(this); |
51 | 115 QMenu* menu = menubar->addMenu(tr("&File")); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
116 |
51 | 117 QMenu* submenu = menu->addMenu(tr("&Library folders")); |
118 action = submenu->addAction(tr("&Add new folder...")); | |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
119 |
51 | 120 action = menu->addAction(tr("&Scan available episodes")); |
2 | 121 |
122 menu->addSeparator(); | |
123 | |
51 | 124 action = menu->addAction(tr("Play &next episode")); |
62 | 125 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_N)); |
51 | 126 action = menu->addAction(tr("Play &random episode")); |
62 | 127 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R)); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
128 |
2 | 129 menu->addSeparator(); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
130 |
51 | 131 action = menu->addAction(tr("E&xit"), qApp, &QApplication::quit); |
2 | 132 |
51 | 133 menu = menubar->addMenu(tr("&Services")); |
79 | 134 action = menu->addAction(tr("Synchronize &list"), [this] { AsyncSynchronize(stack); }); |
62 | 135 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S)); |
2 | 136 |
137 menu->addSeparator(); | |
138 | |
51 | 139 submenu = menu->addMenu(tr("&AniList")); |
140 action = submenu->addAction(tr("Go to my &profile")); | |
141 action = submenu->addAction(tr("Go to my &stats")); | |
2 | 142 |
51 | 143 submenu = menu->addMenu(tr("&Kitsu")); |
144 action = submenu->addAction(tr("Go to my &feed")); | |
145 action = submenu->addAction(tr("Go to my &library")); | |
146 action = submenu->addAction(tr("Go to my &profile")); | |
2 | 147 |
51 | 148 submenu = menu->addMenu(tr("&MyAnimeList")); |
149 action = submenu->addAction(tr("Go to my p&anel")); | |
150 action = submenu->addAction(tr("Go to my &profile")); | |
151 action = submenu->addAction(tr("Go to my &history")); | |
2 | 152 |
51 | 153 menu = menubar->addMenu(tr("&Tools")); |
154 submenu = menu->addMenu(tr("&Export anime list")); | |
155 action = submenu->addAction(tr("Export as &Markdown...")); | |
156 action = submenu->addAction(tr("Export as MyAnimeList &XML...")); | |
2 | 157 |
158 menu->addSeparator(); | |
159 | |
51 | 160 action = menu->addAction(tr("Enable anime &recognition")); |
2 | 161 action->setCheckable(true); |
51 | 162 action = menu->addAction(tr("Enable auto &sharing")); |
2 | 163 action->setCheckable(true); |
51 | 164 action = menu->addAction(tr("Enable &auto synchronization")); |
2 | 165 action->setCheckable(true); |
166 | |
167 menu->addSeparator(); | |
168 | |
51 | 169 action = menu->addAction(tr("&Settings"), [this] { |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
170 SettingsDialog dialog(this); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
171 dialog.exec(); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
172 }); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
173 action->setMenuRole(QAction::PreferencesRole); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
174 |
51 | 175 menu = menubar->addMenu(tr("&View")); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
176 |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
177 std::map<QAction*, int> page_to_index_map = {}; |
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 QActionGroup* pages_group = new QActionGroup(this); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
180 pages_group->setExclusive(true); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
181 |
51 | 182 action = pages_group->addAction(menu->addAction(tr("&Now Playing"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
183 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
184 page_to_index_map[action] = 0; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
185 |
51 | 186 action = pages_group->addAction(menu->addAction(tr("&Anime List"))); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
187 page_to_index_map[action] = 1; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
188 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
189 action->setChecked(true); |
58
b7a1c0010ffd
sidebar: link view menu and sidebar together
Paper <mrpapersonic@gmail.com>
parents:
54
diff
changeset
|
190 |
51 | 191 action = pages_group->addAction(menu->addAction(tr("&History"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
192 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
193 page_to_index_map[action] = 2; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
194 |
51 | 195 action = pages_group->addAction(menu->addAction(tr("&Statistics"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
196 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
197 page_to_index_map[action] = 3; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
198 |
51 | 199 action = pages_group->addAction(menu->addAction(tr("S&earch"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
200 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
201 page_to_index_map[action] = 4; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
202 |
51 | 203 action = pages_group->addAction(menu->addAction(tr("Se&asons"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
204 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
205 page_to_index_map[action] = 5; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
206 |
51 | 207 action = pages_group->addAction(menu->addAction(tr("&Torrents"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
208 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
209 page_to_index_map[action] = 6; |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
210 |
63 | 211 connect(sidebar, &SideBar::CurrentItemChanged, this, |
212 [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
|
213 |
63 | 214 connect(pages_group, &QActionGroup::triggered, this, |
79 | 215 [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
|
216 |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
217 menu->addSeparator(); |
51 | 218 menu->addAction(tr("Show sidebar")); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
219 |
51 | 220 menu = menubar->addMenu(tr("&Help")); |
64 | 221 action = menu->addAction(tr("&About Minori"), this, [this] { |
51 | 222 AboutWindow dialog(this); |
223 dialog.exec(); | |
224 }); | |
225 action = menu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt); | |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
226 action->setMenuRole(QAction::AboutQtRole); |
2 | 227 |
228 setMenuBar(menubar); | |
7 | 229 |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
230 /* Toolbar */ |
79 | 231 /* remove old toolbar(s) */ |
232 QList<QToolBar*> toolbars = findChildren<QToolBar*>(); | |
233 for (auto& t : toolbars) | |
234 removeToolBar(t); | |
235 | |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
236 QToolBar* toolbar = new QToolBar(this); |
77 | 237 toolbar->addAction(QIcon(":/icons/24x24/arrow-circle-double-135.png"), tr("&Synchronize"), |
79 | 238 [this] { AsyncSynchronize(stack); }); |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
239 toolbar->addSeparator(); |
69 | 240 |
241 QToolButton* button = new QToolButton(toolbar); | |
242 | |
243 menu = new QMenu(button); | |
244 action = menu->addAction(tr("Add new folder...")); | |
245 | |
246 button->setMenu(menu); | |
247 button->setIcon(QIcon(":/icons/24x24/folder-open.png")); | |
248 button->setPopupMode(QToolButton::InstantPopup); | |
249 toolbar->addWidget(button); | |
250 | |
251 button = new QToolButton(toolbar); | |
252 | |
253 menu = new QMenu(button); | |
254 action = menu->addAction(tr("Placeholder")); | |
255 | |
256 button->setMenu(menu); | |
257 button->setIcon(QIcon(":/icons/24x24/application-export.png")); | |
258 button->setPopupMode(QToolButton::InstantPopup); | |
259 toolbar->addWidget(button); | |
260 | |
261 toolbar->addSeparator(); | |
262 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
|
263 SettingsDialog dialog(this); |
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
264 dialog.exec(); |
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
265 }); |
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
266 addToolBar(toolbar); |
2 | 267 } |
268 | |
269 void MainWindow::SetActivePage(QWidget* page) { | |
270 this->setCentralWidget(page); | |
271 } | |
272 | |
273 void MainWindow::closeEvent(QCloseEvent* event) { | |
274 session.config.Save(); | |
275 event->accept(); | |
276 } | |
277 | |
9 | 278 #include "gui/moc_window.cpp" |