2
|
1 #include "window.h"
|
|
2 #include "config.h"
|
|
3 #include "anime.h"
|
|
4 #if APPLE
|
|
5 #include "sys/osx/dark_theme.h"
|
|
6 #elif WIN32
|
|
7 #include "sys/win32/dark_theme.h"
|
|
8 #endif
|
|
9
|
|
10 Session session = {
|
|
11 .config = Config()
|
|
12 };
|
|
13
|
|
14 /* note that this code was originally created for use in
|
|
15 wxWidgets, but I thought the API was a little meh, so
|
|
16 I switched to Qt. */
|
|
17
|
|
18 MainWindow::MainWindow(QWidget* parent) :
|
|
19 QMainWindow(parent) {
|
|
20 /* Menu Bar */
|
|
21 QAction* action;
|
|
22 QMenuBar* menubar = new QMenuBar(parent);
|
|
23 QMenu* menu = menubar->addMenu("&File");
|
|
24 QMenu* submenu = menu->addMenu("&Library folders");
|
|
25 action = new QAction("&Add new folder...");
|
|
26 submenu->addAction(action);
|
|
27 action = new QAction("&Scan available episodes");
|
|
28 menu->addAction(action);
|
|
29
|
|
30 menu->addSeparator();
|
|
31
|
|
32 action = menu->addAction("Play &next episode");
|
|
33 action = menu->addAction("Play &random episode");
|
|
34 menu->addSeparator();
|
|
35 action = menu->addAction("E&xit", qApp, &QApplication::quit);
|
|
36
|
|
37 menu = menubar->addMenu("&Services");
|
|
38 action = new QAction("Synchronize &list");
|
|
39
|
|
40 menu->addSeparator();
|
|
41
|
|
42 submenu = menu->addMenu("&AniList");
|
|
43 action = menu->addAction("Go to my &profile");
|
|
44 action = menu->addAction("Go to my &stats");
|
|
45
|
|
46 submenu = menu->addMenu("&Kitsu");
|
|
47 action = submenu->addAction("Go to my &feed");
|
|
48 action = submenu->addAction("Go to my &library");
|
|
49 action = submenu->addAction("Go to my &profile");
|
|
50
|
|
51 submenu = menu->addMenu("&MyAnimeList");
|
|
52 action = submenu->addAction("Go to my p&anel");
|
|
53 action = submenu->addAction("Go to my &profile");
|
|
54 action = submenu->addAction("Go to my &history");
|
|
55
|
|
56 menu = menubar->addMenu("&Tools");
|
|
57 submenu = menu->addMenu("&Export anime list");
|
|
58 action = submenu->addAction("Export as &Markdown...");
|
|
59 action = submenu->addAction("Export as MyAnimeList &XML...");
|
|
60
|
|
61 menu->addSeparator();
|
|
62
|
|
63 action = menu->addAction("Enable anime &recognition");
|
|
64 action->setCheckable(true);
|
|
65 action = menu->addAction("Enable auto &sharing");
|
|
66 action->setCheckable(true);
|
|
67 action = menu->addAction("Enable &auto synchronization");
|
|
68 action->setCheckable(true);
|
|
69
|
|
70 menu->addSeparator();
|
|
71
|
|
72 action = menu->addAction("&Settings");
|
|
73
|
|
74 setMenuBar(menubar);
|
|
75
|
|
76 /* Side toolbar */
|
|
77 QToolBar* toolbar = new QToolBar(parent);
|
|
78 QActionGroup* tb_action_group = new QActionGroup(toolbar);
|
|
79
|
|
80 action = toolbar->addAction("Now Playing");
|
|
81 action->setActionGroup(tb_action_group);
|
|
82 action->setCheckable(true);
|
|
83
|
|
84 toolbar->addSeparator();
|
|
85
|
|
86 action = toolbar->addAction("Anime List", [this]() {
|
|
87 setCentralWidget(anime_list_page);
|
|
88 });
|
|
89 action->setActionGroup(tb_action_group);
|
|
90 action->setCheckable(true);
|
|
91 action->setChecked(true);
|
|
92 anime_list_page = new AnimeListPage(parent);
|
|
93 SetActivePage(anime_list_page);
|
|
94 action = toolbar->addAction("History");
|
|
95 action->setActionGroup(tb_action_group);
|
|
96 action->setCheckable(true);
|
|
97 action = toolbar->addAction("Statistics");
|
|
98 action->setActionGroup(tb_action_group);
|
|
99 action->setCheckable(true);
|
|
100
|
|
101 toolbar->addSeparator();
|
|
102
|
|
103 action = toolbar->addAction("Search");
|
|
104 action->setActionGroup(tb_action_group);
|
|
105 action->setCheckable(true);
|
|
106 action = toolbar->addAction("Seasons");
|
|
107 action->setActionGroup(tb_action_group);
|
|
108 action->setCheckable(true);
|
|
109 action = toolbar->addAction("Torrents");
|
|
110 action->setActionGroup(tb_action_group);
|
|
111 action->setCheckable(true);
|
|
112
|
|
113 toolbar->setMovable(false);
|
|
114 toolbar->setFloatable(false);
|
|
115
|
|
116 addToolBar(Qt::LeftToolBarArea, toolbar);
|
|
117
|
|
118 ThemeChanged();
|
|
119 }
|
|
120
|
|
121 void MainWindow::SetStyleSheet(enum Themes theme) {
|
|
122 switch (theme) {
|
|
123 case DARK: {
|
|
124 QFile f(":qdarkstyle/dark/darkstyle.qss");
|
|
125 if (!f.exists())
|
|
126 return; // fail
|
|
127 f.open(QFile::ReadOnly | QFile::Text);
|
|
128 QTextStream ts(&f);
|
|
129 setStyleSheet(ts.readAll());
|
|
130 break;
|
|
131 }
|
|
132 default:
|
|
133 setStyleSheet("");
|
|
134 break;
|
|
135 }
|
|
136 }
|
|
137
|
|
138 void MainWindow::ThemeChanged() {
|
|
139 switch (session.config.theme) {
|
|
140 case LIGHT: {
|
|
141 #if APPLE
|
|
142 if (osx::DarkThemeAvailable())
|
|
143 osx::SetToLightTheme();
|
|
144 else
|
|
145 SetStyleSheet(LIGHT);
|
|
146 #else
|
|
147 SetStyleSheet(LIGHT);
|
|
148 #endif
|
|
149 break;
|
|
150 }
|
|
151 case DARK: {
|
|
152 #if APPLE
|
|
153 if (osx::DarkThemeAvailable())
|
|
154 osx::SetToDarkTheme();
|
|
155 else
|
|
156 SetStyleSheet(DARK);
|
|
157 #else
|
|
158 SetStyleSheet(DARK);
|
|
159 #endif
|
|
160 break;
|
|
161 }
|
|
162 case OS: {
|
|
163 #if APPLE
|
|
164 if (osx::DarkThemeAvailable())
|
|
165 osx::SetToAutoTheme();
|
|
166 else
|
|
167 SetStyleSheet(LIGHT);
|
|
168 #elif defined(WIN32)
|
|
169 if (win32::DarkThemeAvailable()) {
|
|
170 if (win32::IsInDarkTheme()) {
|
|
171 SetStyleSheet(DARK);
|
|
172 } else {
|
|
173 SetStyleSheet(LIGHT);
|
|
174 }
|
|
175 }
|
|
176 #else
|
|
177 SetStyleSheet(LIGHT);
|
|
178 #endif
|
|
179 break;
|
|
180 }
|
|
181 }
|
|
182 }
|
|
183
|
|
184 void MainWindow::SetActivePage(QWidget* page) {
|
|
185 this->setCentralWidget(page);
|
|
186 }
|
|
187
|
|
188 void MainWindow::closeEvent(QCloseEvent* event) {
|
|
189 session.config.Save();
|
|
190 event->accept();
|
|
191 }
|
|
192
|
|
193 int main(int argc, char** argv) {
|
|
194 QApplication app(argc, argv);
|
|
195
|
|
196 session.config.Load();
|
|
197
|
|
198 MainWindow window;
|
|
199
|
|
200 window.resize(941, 750);
|
|
201 window.setWindowTitle("Weeaboo");
|
|
202 window.show();
|
|
203
|
|
204 return app.exec();
|
|
205 }
|