Mercurial > minori
annotate src/main.cpp @ 8:b1f73678ef61
update
text paragraphs are now their own objects, as they should be
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sat, 26 Aug 2023 03:39:34 -0400 |
parents | 07a9095eaeed |
children | 5c0397762b53 |
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 stack->setCurrentIndex(index); | |
117 break; | |
8 | 118 case 3: |
119 stack->setCurrentIndex(2); | |
120 break; | |
7 | 121 default: |
122 break; | |
123 } | |
124 }); | |
125 sidebar->setCurrentRow(2); | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
126 |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
127 QHBoxLayout* layout = new QHBoxLayout(main_widget); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
128 layout->addWidget(sidebar, 0, Qt::AlignLeft | Qt::AlignTop); |
7 | 129 layout->addWidget(stack); |
130 setCentralWidget(main_widget); | |
2 | 131 |
132 ThemeChanged(); | |
133 } | |
134 | |
135 void MainWindow::SetStyleSheet(enum Themes theme) { | |
136 switch (theme) { | |
137 case DARK: { | |
138 QFile f(":qdarkstyle/dark/darkstyle.qss"); | |
139 if (!f.exists()) | |
140 return; // fail | |
141 f.open(QFile::ReadOnly | QFile::Text); | |
142 QTextStream ts(&f); | |
143 setStyleSheet(ts.readAll()); | |
144 break; | |
145 } | |
146 default: | |
147 setStyleSheet(""); | |
148 break; | |
149 } | |
150 } | |
151 | |
152 void MainWindow::ThemeChanged() { | |
153 switch (session.config.theme) { | |
154 case LIGHT: { | |
5 | 155 #if MACOSX |
2 | 156 if (osx::DarkThemeAvailable()) |
157 osx::SetToLightTheme(); | |
158 else | |
159 SetStyleSheet(LIGHT); | |
160 #else | |
161 SetStyleSheet(LIGHT); | |
162 #endif | |
163 break; | |
164 } | |
165 case DARK: { | |
5 | 166 #if MACOSX |
2 | 167 if (osx::DarkThemeAvailable()) |
168 osx::SetToDarkTheme(); | |
169 else | |
170 SetStyleSheet(DARK); | |
171 #else | |
172 SetStyleSheet(DARK); | |
173 #endif | |
174 break; | |
175 } | |
176 case OS: { | |
5 | 177 #if MACOSX |
2 | 178 if (osx::DarkThemeAvailable()) |
179 osx::SetToAutoTheme(); | |
180 else | |
181 SetStyleSheet(LIGHT); | |
182 #elif defined(WIN32) | |
183 if (win32::DarkThemeAvailable()) { | |
184 if (win32::IsInDarkTheme()) { | |
185 SetStyleSheet(DARK); | |
186 } else { | |
187 SetStyleSheet(LIGHT); | |
188 } | |
189 } | |
190 #else | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
191 /* 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
|
192 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
|
193 (or desktop environments, or window managers) */ |
2 | 194 SetStyleSheet(LIGHT); |
195 #endif | |
196 break; | |
197 } | |
198 } | |
199 } | |
200 | |
201 void MainWindow::SetActivePage(QWidget* page) { | |
202 this->setCentralWidget(page); | |
203 } | |
204 | |
205 void MainWindow::closeEvent(QCloseEvent* event) { | |
206 session.config.Save(); | |
207 event->accept(); | |
208 } | |
209 | |
210 int main(int argc, char** argv) { | |
211 QApplication app(argc, argv); | |
212 | |
213 session.config.Load(); | |
214 | |
215 MainWindow window; | |
216 | |
217 window.resize(941, 750); | |
218 window.setWindowTitle("Weeaboo"); | |
219 window.show(); | |
220 | |
221 return app.exec(); | |
222 } |