annotate src/main.cpp @ 2:23d0d9319a00

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