Mercurial > minori
annotate src/main.cpp @ 7:07a9095eaeed
Update
Refactored some code, moved some around
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Thu, 24 Aug 2023 23:11:38 -0400 |
parents | 1d82f6e04d7d |
children | b1f73678ef61 |
rev | line source |
---|---|
7 | 1 #include <QApplication> |
2 #include <QMainWindow> | |
3 #include <QMenuBar> | |
4 #include <QPlainTextEdit> | |
5 #include <QStackedWidget> | |
6 #include <QFile> | |
7 #include <QTextStream> | |
8 #include <QMessageBox> | |
2 | 9 #include "window.h" |
10 #include "config.h" | |
7 | 11 #include "anime_list.h" |
12 #include "now_playing.h" | |
13 #include "statistics.h" | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
14 #include "sidebar.h" |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
15 #include "ui_utils.h" |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
16 #include "settings.h" |
7 | 17 #include "session.h" |
5 | 18 #if MACOSX |
2 | 19 #include "sys/osx/dark_theme.h" |
20 #elif WIN32 | |
21 #include "sys/win32/dark_theme.h" | |
22 #endif | |
23 | |
7 | 24 Session session; |
2 | 25 |
26 /* note that this code was originally created for use in | |
27 wxWidgets, but I thought the API was a little meh, so | |
28 I switched to Qt. */ | |
29 | |
30 MainWindow::MainWindow(QWidget* parent) : | |
31 QMainWindow(parent) { | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
32 main_widget = new QWidget(parent); |
2 | 33 /* Menu Bar */ |
34 QAction* action; | |
35 QMenuBar* menubar = new QMenuBar(parent); | |
36 QMenu* menu = menubar->addMenu("&File"); | |
37 QMenu* submenu = menu->addMenu("&Library folders"); | |
38 action = new QAction("&Add new folder..."); | |
39 submenu->addAction(action); | |
40 action = new QAction("&Scan available episodes"); | |
41 menu->addAction(action); | |
42 | |
43 menu->addSeparator(); | |
44 | |
45 action = menu->addAction("Play &next episode"); | |
46 action = menu->addAction("Play &random episode"); | |
47 menu->addSeparator(); | |
48 action = menu->addAction("E&xit", qApp, &QApplication::quit); | |
49 | |
50 menu = menubar->addMenu("&Services"); | |
51 action = new QAction("Synchronize &list"); | |
52 | |
53 menu->addSeparator(); | |
54 | |
55 submenu = menu->addMenu("&AniList"); | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
56 action = submenu->addAction("Go to my &profile"); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
57 action = submenu->addAction("Go to my &stats"); |
2 | 58 |
59 submenu = menu->addMenu("&Kitsu"); | |
60 action = submenu->addAction("Go to my &feed"); | |
61 action = submenu->addAction("Go to my &library"); | |
62 action = submenu->addAction("Go to my &profile"); | |
63 | |
64 submenu = menu->addMenu("&MyAnimeList"); | |
65 action = submenu->addAction("Go to my p&anel"); | |
66 action = submenu->addAction("Go to my &profile"); | |
67 action = submenu->addAction("Go to my &history"); | |
68 | |
69 menu = menubar->addMenu("&Tools"); | |
70 submenu = menu->addMenu("&Export anime list"); | |
71 action = submenu->addAction("Export as &Markdown..."); | |
72 action = submenu->addAction("Export as MyAnimeList &XML..."); | |
73 | |
74 menu->addSeparator(); | |
75 | |
76 action = menu->addAction("Enable anime &recognition"); | |
77 action->setCheckable(true); | |
78 action = menu->addAction("Enable auto &sharing"); | |
79 action->setCheckable(true); | |
80 action = menu->addAction("Enable &auto synchronization"); | |
81 action->setCheckable(true); | |
82 | |
83 menu->addSeparator(); | |
84 | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
85 action = menu->addAction("&Settings", [this]{ |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
86 SettingsDialog dialog(this); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
87 dialog.exec(); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
88 }); |
2 | 89 |
90 setMenuBar(menubar); | |
7 | 91 |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
92 SideBar* sidebar = new SideBar(main_widget); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
93 sidebar->AddItem("Now Playing", UiUtils::CreateSideBarIcon(":/icons/16x16/film.png")); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
94 sidebar->AddSeparator(); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
95 sidebar->AddItem("Anime List", UiUtils::CreateSideBarIcon(":/icons/16x16/document-list.png")); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
96 sidebar->AddItem("History", UiUtils::CreateSideBarIcon(":/icons/16x16/clock-history-frame.png")); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
97 sidebar->AddItem("Statistics", UiUtils::CreateSideBarIcon(":/icons/16x16/chart.png")); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
98 sidebar->AddSeparator(); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
99 sidebar->AddItem("Search", UiUtils::CreateSideBarIcon(":/icons/16x16/magnifier.png")); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
100 sidebar->AddItem("Seasons", UiUtils::CreateSideBarIcon(":/icons/16x16/calendar.png")); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
101 sidebar->AddItem("Torrents", UiUtils::CreateSideBarIcon(":/icons/16x16/feed.png")); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
102 sidebar->setFixedWidth(128); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
103 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
104 |
7 | 105 QStackedWidget* stack = new QStackedWidget(main_widget); |
106 stack->addWidget(new NowPlayingWidget(parent)); | |
107 AnimeListWidget* list_widget = new AnimeListWidget(parent); | |
108 list_widget->SyncAnimeList(); | |
109 stack->addWidget(list_widget); | |
110 stack->addWidget(new StatisticsWidget(list_widget, parent)); | |
111 | |
112 connect(sidebar, &SideBar::CurrentItemChanged, stack, [stack](int index){ | |
113 switch (index) { | |
114 case 0: | |
115 case 1: | |
116 case 2: | |
117 stack->setCurrentIndex(index); | |
118 break; | |
119 default: | |
120 break; | |
121 } | |
122 }); | |
123 sidebar->setCurrentRow(2); | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
124 |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
125 QHBoxLayout* layout = new QHBoxLayout(main_widget); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
126 layout->addWidget(sidebar, 0, Qt::AlignLeft | Qt::AlignTop); |
7 | 127 layout->addWidget(stack); |
128 setCentralWidget(main_widget); | |
2 | 129 |
130 ThemeChanged(); | |
131 } | |
132 | |
133 void MainWindow::SetStyleSheet(enum Themes theme) { | |
134 switch (theme) { | |
135 case DARK: { | |
136 QFile f(":qdarkstyle/dark/darkstyle.qss"); | |
137 if (!f.exists()) | |
138 return; // fail | |
139 f.open(QFile::ReadOnly | QFile::Text); | |
140 QTextStream ts(&f); | |
141 setStyleSheet(ts.readAll()); | |
142 break; | |
143 } | |
144 default: | |
145 setStyleSheet(""); | |
146 break; | |
147 } | |
148 } | |
149 | |
150 void MainWindow::ThemeChanged() { | |
151 switch (session.config.theme) { | |
152 case LIGHT: { | |
5 | 153 #if MACOSX |
2 | 154 if (osx::DarkThemeAvailable()) |
155 osx::SetToLightTheme(); | |
156 else | |
157 SetStyleSheet(LIGHT); | |
158 #else | |
159 SetStyleSheet(LIGHT); | |
160 #endif | |
161 break; | |
162 } | |
163 case DARK: { | |
5 | 164 #if MACOSX |
2 | 165 if (osx::DarkThemeAvailable()) |
166 osx::SetToDarkTheme(); | |
167 else | |
168 SetStyleSheet(DARK); | |
169 #else | |
170 SetStyleSheet(DARK); | |
171 #endif | |
172 break; | |
173 } | |
174 case OS: { | |
5 | 175 #if MACOSX |
2 | 176 if (osx::DarkThemeAvailable()) |
177 osx::SetToAutoTheme(); | |
178 else | |
179 SetStyleSheet(LIGHT); | |
180 #elif defined(WIN32) | |
181 if (win32::DarkThemeAvailable()) { | |
182 if (win32::IsInDarkTheme()) { | |
183 SetStyleSheet(DARK); | |
184 } else { | |
185 SetStyleSheet(LIGHT); | |
186 } | |
187 } | |
188 #else | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
189 /* Currently OS detection only supports Windows and macOS. |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
190 Please don't be shy if you're willing to port it to other OSes |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
191 (or desktop environments, or window managers) */ |
2 | 192 SetStyleSheet(LIGHT); |
193 #endif | |
194 break; | |
195 } | |
196 } | |
197 } | |
198 | |
199 void MainWindow::SetActivePage(QWidget* page) { | |
200 this->setCentralWidget(page); | |
201 } | |
202 | |
203 void MainWindow::closeEvent(QCloseEvent* event) { | |
204 session.config.Save(); | |
205 event->accept(); | |
206 } | |
207 | |
208 int main(int argc, char** argv) { | |
209 QApplication app(argc, argv); | |
210 | |
211 session.config.Load(); | |
212 | |
213 MainWindow window; | |
214 | |
215 window.resize(941, 750); | |
216 window.setWindowTitle("Weeaboo"); | |
217 window.show(); | |
218 | |
219 return app.exec(); | |
220 } |