comparison src/main.cpp @ 9:5c0397762b53

INCOMPLETE: megacommit :)
author Paper <mrpapersonic@gmail.com>
date Sun, 10 Sep 2023 03:59:16 -0400
parents b1f73678ef61
children 4b198a111713
comparison
equal deleted inserted replaced
8:b1f73678ef61 9:5c0397762b53
1 #include "core/session.h"
2 #include "gui/window.h"
1 #include <QApplication> 3 #include <QApplication>
2 #include <QMainWindow>
3 #include <QMenuBar>
4 #include <QPlainTextEdit>
5 #include <QStackedWidget>
6 #include <QFile>
7 #include <QTextStream>
8 #include <QMessageBox>
9 #include "window.h"
10 #include "config.h"
11 #include "anime_list.h"
12 #include "now_playing.h"
13 #include "statistics.h"
14 #include "sidebar.h"
15 #include "ui_utils.h"
16 #include "settings.h"
17 #include "session.h"
18 #if MACOSX
19 #include "sys/osx/dark_theme.h"
20 #elif WIN32
21 #include "sys/win32/dark_theme.h"
22 #endif
23 4
24 Session session; 5 Session session;
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) {
32 main_widget = new QWidget(parent);
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");
56 action = submenu->addAction("Go to my &profile");
57 action = submenu->addAction("Go to my &stats");
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
85 action = menu->addAction("&Settings", [this]{
86 SettingsDialog dialog(this);
87 dialog.exec();
88 });
89
90 setMenuBar(menubar);
91
92 SideBar* sidebar = new SideBar(main_widget);
93 sidebar->AddItem("Now Playing", UiUtils::CreateSideBarIcon(":/icons/16x16/film.png"));
94 sidebar->AddSeparator();
95 sidebar->AddItem("Anime List", UiUtils::CreateSideBarIcon(":/icons/16x16/document-list.png"));
96 sidebar->AddItem("History", UiUtils::CreateSideBarIcon(":/icons/16x16/clock-history-frame.png"));
97 sidebar->AddItem("Statistics", UiUtils::CreateSideBarIcon(":/icons/16x16/chart.png"));
98 sidebar->AddSeparator();
99 sidebar->AddItem("Search", UiUtils::CreateSideBarIcon(":/icons/16x16/magnifier.png"));
100 sidebar->AddItem("Seasons", UiUtils::CreateSideBarIcon(":/icons/16x16/calendar.png"));
101 sidebar->AddItem("Torrents", UiUtils::CreateSideBarIcon(":/icons/16x16/feed.png"));
102 sidebar->setFixedWidth(128);
103 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
104
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;
118 case 3:
119 stack->setCurrentIndex(2);
120 break;
121 default:
122 break;
123 }
124 });
125 sidebar->setCurrentRow(2);
126
127 QHBoxLayout* layout = new QHBoxLayout(main_widget);
128 layout->addWidget(sidebar, 0, Qt::AlignLeft | Qt::AlignTop);
129 layout->addWidget(stack);
130 setCentralWidget(main_widget);
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: {
155 #if MACOSX
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: {
166 #if MACOSX
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: {
177 #if MACOSX
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
191 /* Currently OS detection only supports Windows and macOS.
192 Please don't be shy if you're willing to port it to other OSes
193 (or desktop environments, or window managers) */
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 6
210 int main(int argc, char** argv) { 7 int main(int argc, char** argv) {
211 QApplication app(argc, argv); 8 QApplication app(argc, argv);
212 9
213 session.config.Load(); 10 session.config.Load();