Mercurial > minori
annotate src/gui/window.cpp @ 48:e613772f41d5
statistics.cpp: show requests made
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 25 Sep 2023 01:07:22 -0400 |
parents | d0adc4aedfc8 |
children | 75c804f713b2 |
rev | line source |
---|---|
9 | 1 #include "gui/window.h" |
2 #include "core/config.h" | |
3 #include "core/session.h" | |
46 | 4 #include "gui/dark_theme.h" |
9 | 5 #include "gui/dialog/settings.h" |
6 #include "gui/pages/anime_list.h" | |
7 #include "gui/pages/now_playing.h" | |
8 #include "gui/pages/statistics.h" | |
46 | 9 #include "gui/widgets/sidebar.h" |
15 | 10 #include "services/services.h" |
7 | 11 #include <QApplication> |
9 | 12 #include <QFile> |
7 | 13 #include <QMainWindow> |
14 #include <QMenuBar> | |
15 #include <QPlainTextEdit> | |
16 #include <QStackedWidget> | |
17 #include <QTextStream> | |
5 | 18 #if MACOSX |
15 | 19 # include "sys/osx/dark_theme.h" |
46 | 20 #elif defined(WIN32) |
15 | 21 # include "sys/win32/dark_theme.h" |
2 | 22 #endif |
23 | |
10 | 24 enum class Pages { |
25 NOW_PLAYING, | |
26 | |
27 ANIME_LIST, | |
28 HISTORY, | |
29 STATISTICS, | |
30 | |
31 SEARCH, | |
32 SEASONS, | |
33 TORRENTS | |
34 }; | |
35 | |
9 | 36 MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
37 main_widget = new QWidget(parent); |
10 | 38 |
39 SideBar* sidebar = new SideBar(main_widget); | |
40 sidebar->AddItem("Now Playing", SideBar::CreateIcon(":/icons/16x16/film.png")); | |
41 sidebar->AddSeparator(); | |
42 sidebar->AddItem("Anime List", SideBar::CreateIcon(":/icons/16x16/document-list.png")); | |
43 sidebar->AddItem("History", SideBar::CreateIcon(":/icons/16x16/clock-history-frame.png")); | |
44 sidebar->AddItem("Statistics", SideBar::CreateIcon(":/icons/16x16/chart.png")); | |
45 sidebar->AddSeparator(); | |
46 sidebar->AddItem("Search", SideBar::CreateIcon(":/icons/16x16/magnifier.png")); | |
47 sidebar->AddItem("Seasons", SideBar::CreateIcon(":/icons/16x16/calendar.png")); | |
48 sidebar->AddItem("Torrents", SideBar::CreateIcon(":/icons/16x16/feed.png")); | |
49 sidebar->setFixedWidth(128); | |
36 | 50 sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
10 | 51 |
52 QStackedWidget* stack = new QStackedWidget(main_widget); | |
53 stack->addWidget(new NowPlayingWidget(main_widget)); | |
54 stack->addWidget(new AnimeListWidget(main_widget)); | |
55 stack->addWidget(new StatisticsWidget(main_widget)); | |
56 | |
57 connect(sidebar, &SideBar::CurrentItemChanged, stack, [stack](int index) { | |
58 switch (index) { | |
59 case 0: | |
60 case 1: stack->setCurrentIndex(index); break; | |
61 case 3: stack->setCurrentIndex(2); break; | |
62 default: break; | |
63 } | |
64 }); | |
65 sidebar->setCurrentRow(2); | |
66 | |
2 | 67 /* Menu Bar */ |
68 QAction* action; | |
69 QMenuBar* menubar = new QMenuBar(parent); | |
70 QMenu* menu = menubar->addMenu("&File"); | |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
71 |
2 | 72 QMenu* submenu = menu->addMenu("&Library folders"); |
10 | 73 action = submenu->addAction("&Add new folder..."); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
74 |
10 | 75 action = menu->addAction("&Scan available episodes"); |
2 | 76 |
77 menu->addSeparator(); | |
78 | |
79 action = menu->addAction("Play &next episode"); | |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
80 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N)); |
2 | 81 action = menu->addAction("Play &random episode"); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
82 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R)); |
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
83 |
2 | 84 menu->addSeparator(); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
85 |
2 | 86 action = menu->addAction("E&xit", qApp, &QApplication::quit); |
87 | |
88 menu = menubar->addMenu("&Services"); | |
10 | 89 action = menu->addAction("Synchronize &list", [this, stack] { |
90 Services::Synchronize(); | |
15 | 91 ((AnimeListWidget*)stack->widget((int)Pages::ANIME_LIST))->Refresh(); |
10 | 92 }); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
93 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S)); |
2 | 94 |
95 menu->addSeparator(); | |
96 | |
97 submenu = menu->addMenu("&AniList"); | |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
98 action = submenu->addAction("Go to my &profile"); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
99 action = submenu->addAction("Go to my &stats"); |
2 | 100 |
101 submenu = menu->addMenu("&Kitsu"); | |
102 action = submenu->addAction("Go to my &feed"); | |
103 action = submenu->addAction("Go to my &library"); | |
104 action = submenu->addAction("Go to my &profile"); | |
105 | |
106 submenu = menu->addMenu("&MyAnimeList"); | |
107 action = submenu->addAction("Go to my p&anel"); | |
108 action = submenu->addAction("Go to my &profile"); | |
109 action = submenu->addAction("Go to my &history"); | |
110 | |
111 menu = menubar->addMenu("&Tools"); | |
112 submenu = menu->addMenu("&Export anime list"); | |
113 action = submenu->addAction("Export as &Markdown..."); | |
114 action = submenu->addAction("Export as MyAnimeList &XML..."); | |
115 | |
116 menu->addSeparator(); | |
117 | |
118 action = menu->addAction("Enable anime &recognition"); | |
119 action->setCheckable(true); | |
120 action = menu->addAction("Enable auto &sharing"); | |
121 action->setCheckable(true); | |
122 action = menu->addAction("Enable &auto synchronization"); | |
123 action->setCheckable(true); | |
124 | |
125 menu->addSeparator(); | |
126 | |
9 | 127 action = menu->addAction("&Settings", [this] { |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
128 SettingsDialog dialog(this); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
129 dialog.exec(); |
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
130 }); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
131 action->setMenuRole(QAction::PreferencesRole); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
132 |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
133 menu = menubar->addMenu("&View"); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
134 |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
135 std::map<QAction*, int> page_to_index_map = {}; |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
136 |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
137 QActionGroup* pages_group = new QActionGroup(this); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
138 pages_group->setExclusive(true); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
139 |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
140 action = pages_group->addAction(menu->addAction("&Now Playing")); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
141 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
142 page_to_index_map[action] = 0; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
143 |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
144 action = pages_group->addAction(menu->addAction("&Anime List")); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
145 page_to_index_map[action] = 1; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
146 |
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
147 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
148 action->setChecked(true); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
149 action = pages_group->addAction(menu->addAction("&History")); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
150 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
151 page_to_index_map[action] = 2; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
152 |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
153 action = pages_group->addAction(menu->addAction("&Statistics")); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
154 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
155 page_to_index_map[action] = 3; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
156 |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
157 action = pages_group->addAction(menu->addAction("S&earch")); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
158 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
159 page_to_index_map[action] = 4; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
160 |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
161 action = pages_group->addAction(menu->addAction("Se&asons")); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
162 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
163 page_to_index_map[action] = 5; |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
164 |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
165 action = pages_group->addAction(menu->addAction("&Torrents")); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
166 action->setCheckable(true); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
167 page_to_index_map[action] = 6; |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
168 |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
169 connect(pages_group, &QActionGroup::triggered, this, [page_to_index_map, stack](QAction* action) { |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
170 int index = page_to_index_map.at(action); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
171 switch (index) { |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
172 case 0: |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
173 case 1: stack->setCurrentIndex(index); break; |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
174 case 3: stack->setCurrentIndex(2); |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
175 default: break; |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
176 } |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
177 }); |
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
178 menu->addSeparator(); |
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
179 menu->addAction("Show sidebar"); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
180 |
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
181 menu = menubar->addMenu("&Help"); |
46 | 182 action = menu->addAction("About &Qt", qApp, [this] { qApp->aboutQt(); }); |
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
183 action->setMenuRole(QAction::AboutQtRole); |
2 | 184 |
185 setMenuBar(menubar); | |
7 | 186 |
6
1d82f6e04d7d
Update: add first parts to the settings dialog
Paper <mrpapersonic@gmail.com>
parents:
5
diff
changeset
|
187 QHBoxLayout* layout = new QHBoxLayout(main_widget); |
37
9ae9365dd4ea
window.cpp: fix sidebar on Linux
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
188 layout->addWidget(sidebar); |
7 | 189 layout->addWidget(stack); |
190 setCentralWidget(main_widget); | |
2 | 191 |
46 | 192 DarkTheme::SetTheme(session.config.theme); |
2 | 193 } |
194 | |
195 void MainWindow::SetActivePage(QWidget* page) { | |
196 this->setCentralWidget(page); | |
197 } | |
198 | |
199 void MainWindow::closeEvent(QCloseEvent* event) { | |
200 session.config.Save(); | |
201 event->accept(); | |
202 } | |
203 | |
9 | 204 #include "gui/moc_window.cpp" |