Mercurial > minori
annotate src/gui/window.cc @ 112:80f49f623d30
locale: allow switching locales without restarting
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 06 Nov 2023 13:41:30 -0500 |
parents | 2004b41d4a59 |
children | 32afe0e940bf |
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> | |
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
34 #include <iostream> |
106
c8c72278f6fd
*: #if -> #ifdef, remove outdated comments in sys/win32/dark_theme.cc
Paper <mrpapersonic@gmail.com>
parents:
105
diff
changeset
|
35 #ifdef MACOSX |
15 | 36 # include "sys/osx/dark_theme.h" |
46 | 37 #elif defined(WIN32) |
15 | 38 # include "sys/win32/dark_theme.h" |
2 | 39 #endif |
40 | |
10 | 41 enum class Pages { |
42 NOW_PLAYING, | |
43 | |
44 ANIME_LIST, | |
45 HISTORY, | |
46 STATISTICS, | |
47 | |
48 SEARCH, | |
49 SEASONS, | |
50 TORRENTS | |
51 }; | |
52 | |
9 | 53 MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { |
103 | 54 setWindowIcon(QIcon(":/favicon.png")); |
55 | |
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
56 main_widget = new QWidget(this); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
57 /*QHBoxLayout* layout = */new QHBoxLayout(main_widget); |
10 | 58 |
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
59 AddMainWidgets(); |
10 | 60 |
79 | 61 setCentralWidget(main_widget); |
62 | |
63 CreateBars(); | |
64 | |
65 QTimer* timer = new QTimer(this); | |
66 connect(timer, &QTimer::timeout, this, [this] { | |
67 NowPlayingPage* page = reinterpret_cast<NowPlayingPage*>(stack->widget(static_cast<int>(Pages::NOW_PLAYING))); | |
68 | |
69 Filesystem::Path p = Track::Media::GetCurrentPlaying(); | |
80 | 70 std::unordered_map<std::string, std::string> elements = Track::Media::GetFileElements(p); |
71 int id = Anime::db.GetAnimeFromTitle(elements["title"]); | |
83 | 72 if (id <= 0) { |
79 | 73 page->SetDefault(); |
74 return; | |
75 } | |
76 | |
83 | 77 page->SetPlaying(Anime::db.items[id], elements); |
79 | 78 }); |
79 timer->start(5000); | |
80 } | |
81 | |
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
82 void MainWindow::AddMainWidgets() { |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
83 int page = static_cast<int>(Pages::ANIME_LIST); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
84 if (sidebar) { |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
85 main_widget->layout()->removeWidget(sidebar); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
86 delete sidebar; |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
87 } |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
88 |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
89 if (stack) { |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
90 page = stack->currentIndex(); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
91 main_widget->layout()->removeWidget(stack); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
92 delete stack; |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
93 } |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
94 |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
95 sidebar = new SideBar(main_widget); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
96 sidebar->setFixedWidth(128); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
97 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
98 |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
99 sidebar->AddItem(tr("Now Playing"), SideBar::CreateIcon(":/icons/16x16/film.png")); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
100 sidebar->AddSeparator(); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
101 sidebar->AddItem(tr("Anime List"), SideBar::CreateIcon(":/icons/16x16/document-list.png")); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
102 sidebar->AddItem(tr("History"), SideBar::CreateIcon(":/icons/16x16/clock-history-frame.png")); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
103 sidebar->AddItem(tr("Statistics"), SideBar::CreateIcon(":/icons/16x16/chart.png")); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
104 sidebar->AddSeparator(); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
105 sidebar->AddItem(tr("Search"), SideBar::CreateIcon(":/icons/16x16/magnifier.png")); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
106 sidebar->AddItem(tr("Seasons"), SideBar::CreateIcon(":/icons/16x16/calendar.png")); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
107 sidebar->AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/16x16/feed.png")); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
108 |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
109 stack = new QStackedWidget(main_widget); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
110 stack->addWidget(new NowPlayingPage(main_widget)); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
111 stack->addWidget(new AnimeListPage(main_widget)); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
112 stack->addWidget(new HistoryPage(main_widget)); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
113 stack->addWidget(new StatisticsPage(main_widget)); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
114 stack->addWidget(new SearchPage(main_widget)); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
115 stack->addWidget(new SeasonsPage(main_widget)); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
116 stack->addWidget(new TorrentsPage(main_widget)); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
117 |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
118 connect(sidebar, &SideBar::CurrentItemChanged, this, [](int index){ |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
119 std::cout << index << std::endl; |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
120 }); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
121 |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
122 connect(sidebar, &SideBar::CurrentItemChanged, stack, &QStackedWidget::setCurrentIndex); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
123 sidebar->SetCurrentItem(page); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
124 |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
125 main_widget->layout()->addWidget(sidebar); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
126 main_widget->layout()->addWidget(stack); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
127 } |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
128 |
79 | 129 void MainWindow::CreateBars() { |
2 | 130 /* Menu Bar */ |
131 QAction* action; | |
79 | 132 QMenuBar* menubar = new QMenuBar(this); |
51 | 133 QMenu* menu = menubar->addMenu(tr("&File")); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
134 |
51 | 135 QMenu* submenu = menu->addMenu(tr("&Library folders")); |
136 action = submenu->addAction(tr("&Add new folder...")); | |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
137 |
51 | 138 action = menu->addAction(tr("&Scan available episodes")); |
2 | 139 |
140 menu->addSeparator(); | |
141 | |
51 | 142 action = menu->addAction(tr("Play &next episode")); |
62 | 143 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_N)); |
51 | 144 action = menu->addAction(tr("Play &random episode")); |
62 | 145 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R)); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
146 |
2 | 147 menu->addSeparator(); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
148 |
51 | 149 action = menu->addAction(tr("E&xit"), qApp, &QApplication::quit); |
2 | 150 |
51 | 151 menu = menubar->addMenu(tr("&Services")); |
79 | 152 action = menu->addAction(tr("Synchronize &list"), [this] { AsyncSynchronize(stack); }); |
62 | 153 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S)); |
2 | 154 |
155 menu->addSeparator(); | |
156 | |
51 | 157 submenu = menu->addMenu(tr("&AniList")); |
158 action = submenu->addAction(tr("Go to my &profile")); | |
159 action = submenu->addAction(tr("Go to my &stats")); | |
2 | 160 |
51 | 161 submenu = menu->addMenu(tr("&Kitsu")); |
162 action = submenu->addAction(tr("Go to my &feed")); | |
163 action = submenu->addAction(tr("Go to my &library")); | |
164 action = submenu->addAction(tr("Go to my &profile")); | |
2 | 165 |
51 | 166 submenu = menu->addMenu(tr("&MyAnimeList")); |
167 action = submenu->addAction(tr("Go to my p&anel")); | |
168 action = submenu->addAction(tr("Go to my &profile")); | |
169 action = submenu->addAction(tr("Go to my &history")); | |
2 | 170 |
51 | 171 menu = menubar->addMenu(tr("&Tools")); |
172 submenu = menu->addMenu(tr("&Export anime list")); | |
173 action = submenu->addAction(tr("Export as &Markdown...")); | |
174 action = submenu->addAction(tr("Export as MyAnimeList &XML...")); | |
2 | 175 |
176 menu->addSeparator(); | |
177 | |
51 | 178 action = menu->addAction(tr("Enable anime &recognition")); |
2 | 179 action->setCheckable(true); |
51 | 180 action = menu->addAction(tr("Enable auto &sharing")); |
2 | 181 action->setCheckable(true); |
51 | 182 action = menu->addAction(tr("Enable &auto synchronization")); |
2 | 183 action->setCheckable(true); |
184 | |
185 menu->addSeparator(); | |
186 | |
51 | 187 action = menu->addAction(tr("&Settings"), [this] { |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
188 SettingsDialog dialog(this); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
189 dialog.exec(); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
190 }); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
191 action->setMenuRole(QAction::PreferencesRole); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
192 |
51 | 193 menu = menubar->addMenu(tr("&View")); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
194 |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
195 std::map<QAction*, int> page_to_index_map = {}; |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
196 |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
197 QActionGroup* pages_group = new QActionGroup(this); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
198 pages_group->setExclusive(true); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
199 |
51 | 200 action = pages_group->addAction(menu->addAction(tr("&Now Playing"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
201 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
202 page_to_index_map[action] = 0; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
203 |
51 | 204 action = pages_group->addAction(menu->addAction(tr("&Anime List"))); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
205 page_to_index_map[action] = 1; |
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 action->setChecked(true); |
58
b7a1c0010ffd
sidebar: link view menu and sidebar together
Paper <mrpapersonic@gmail.com>
parents:
54
diff
changeset
|
208 |
51 | 209 action = pages_group->addAction(menu->addAction(tr("&History"))); |
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] = 2; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
212 |
51 | 213 action = pages_group->addAction(menu->addAction(tr("&Statistics"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
214 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
215 page_to_index_map[action] = 3; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
216 |
51 | 217 action = pages_group->addAction(menu->addAction(tr("S&earch"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
218 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
219 page_to_index_map[action] = 4; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
220 |
51 | 221 action = pages_group->addAction(menu->addAction(tr("Se&asons"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
222 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
223 page_to_index_map[action] = 5; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
224 |
51 | 225 action = pages_group->addAction(menu->addAction(tr("&Torrents"))); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
226 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
227 page_to_index_map[action] = 6; |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
228 |
63 | 229 connect(sidebar, &SideBar::CurrentItemChanged, this, |
230 [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
|
231 |
63 | 232 connect(pages_group, &QActionGroup::triggered, this, |
79 | 233 [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
|
234 |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
235 menu->addSeparator(); |
51 | 236 menu->addAction(tr("Show sidebar")); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
237 |
51 | 238 menu = menubar->addMenu(tr("&Help")); |
64 | 239 action = menu->addAction(tr("&About Minori"), this, [this] { |
51 | 240 AboutWindow dialog(this); |
241 dialog.exec(); | |
242 }); | |
243 action = menu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt); | |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
244 action->setMenuRole(QAction::AboutQtRole); |
2 | 245 |
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
246 /* QMainWindow will delete the old one for us, |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
247 according to the docs */ |
2 | 248 setMenuBar(menubar); |
7 | 249 |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
250 /* Toolbar */ |
79 | 251 /* remove old toolbar(s) */ |
252 QList<QToolBar*> toolbars = findChildren<QToolBar*>(); | |
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
253 for (auto& t : toolbars) { |
79 | 254 removeToolBar(t); |
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
255 delete t; |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
256 } |
79 | 257 |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
258 QToolBar* toolbar = new QToolBar(this); |
77 | 259 toolbar->addAction(QIcon(":/icons/24x24/arrow-circle-double-135.png"), tr("&Synchronize"), |
79 | 260 [this] { AsyncSynchronize(stack); }); |
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
261 toolbar->addSeparator(); |
69 | 262 |
263 QToolButton* button = new QToolButton(toolbar); | |
264 | |
265 menu = new QMenu(button); | |
266 action = menu->addAction(tr("Add new folder...")); | |
267 | |
268 button->setMenu(menu); | |
269 button->setIcon(QIcon(":/icons/24x24/folder-open.png")); | |
270 button->setPopupMode(QToolButton::InstantPopup); | |
271 toolbar->addWidget(button); | |
272 | |
273 button = new QToolButton(toolbar); | |
274 | |
275 menu = new QMenu(button); | |
276 action = menu->addAction(tr("Placeholder")); | |
277 | |
278 button->setMenu(menu); | |
279 button->setIcon(QIcon(":/icons/24x24/application-export.png")); | |
280 button->setPopupMode(QToolButton::InstantPopup); | |
281 toolbar->addWidget(button); | |
282 | |
283 toolbar->addSeparator(); | |
284 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
|
285 SettingsDialog dialog(this); |
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
286 dialog.exec(); |
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
287 }); |
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
288 addToolBar(toolbar); |
2 | 289 } |
290 | |
291 void MainWindow::SetActivePage(QWidget* page) { | |
292 this->setCentralWidget(page); | |
293 } | |
294 | |
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
295 void MainWindow::AsyncSynchronize(QStackedWidget* stack) { |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
296 if (session.config.service == Anime::Services::NONE) { |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
297 QMessageBox msg; |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
298 msg.setWindowTitle(tr("Error synchronizing with service!")); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
299 msg.setText(tr("It seems you haven't yet selected a service to use.")); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
300 msg.setInformativeText(tr("Would you like to select one now?")); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
301 msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
302 msg.setDefaultButton(QMessageBox::Yes); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
303 int ret = msg.exec(); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
304 if (ret == QMessageBox::Yes) { |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
305 SettingsDialog dialog; |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
306 dialog.exec(); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
307 } |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
308 } |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
309 QThreadPool::globalInstance()->start([stack] { |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
310 Services::Synchronize(); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
311 reinterpret_cast<AnimeListPage*>(stack->widget(static_cast<int>(Pages::ANIME_LIST)))->Refresh(); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
312 }); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
313 } |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
314 |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
315 void MainWindow::RetranslateUI() { |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
316 /* Temporarily disable UI updates so we don't flash the screen */ |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
317 setUpdatesEnabled(false); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
318 AddMainWidgets(); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
319 CreateBars(); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
320 setUpdatesEnabled(true); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
321 } |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
322 |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
323 void MainWindow::changeEvent(QEvent* event) { |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
324 if (event) { /* is this really necessary */ |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
325 switch (event->type()) { |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
326 // this event is send if a translator is loaded |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
327 case QEvent::LanguageChange: |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
328 RetranslateUI(); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
329 break; |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
330 |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
331 default: |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
332 break; |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
333 } |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
334 } |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
335 QMainWindow::changeEvent(event); |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
336 } |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
337 |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
103
diff
changeset
|
338 void MainWindow::showEvent(QShowEvent* event) { |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
103
diff
changeset
|
339 QMainWindow::showEvent(event); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
103
diff
changeset
|
340 #ifdef WIN32 |
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
341 /* Technically this *should* be |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
342 session.config.theme.IsInDarkTheme() && win32::IsInDarkTheme() |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
343 but I prefer the title bar being black even when light mode |
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
344 is enabled :/ */ |
108 | 345 win32::SetTitleBarsToBlack(session.config.theme.IsInDarkTheme()); |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
103
diff
changeset
|
346 #endif |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
103
diff
changeset
|
347 } |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
103
diff
changeset
|
348 |
2 | 349 void MainWindow::closeEvent(QCloseEvent* event) { |
350 session.config.Save(); | |
351 event->accept(); | |
352 } | |
353 | |
9 | 354 #include "gui/moc_window.cpp" |