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