Mercurial > minori
annotate include/gui/window.h @ 307:8769c5d50b06
pages/anime_list: don't call GUI functions in a non-GUI thread
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Sun, 19 May 2024 18:25:14 -0400 |
parents | 9a88e1725fd2 |
children | 34347fd2a2de |
rev | line source |
---|---|
261
3ec7804abf17
include: make header guards more sane
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
1 #ifndef MINORI_WINDOW_H_ |
3ec7804abf17
include: make header guards more sane
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
2 #define MINORI_WINDOW_H_ |
291 | 3 |
9 | 4 #include "core/config.h" |
291 | 5 #include "gui/widgets/sidebar.h" |
79 | 6 |
291 | 7 /* pages; these should really be in a namespace */ |
8 #include "gui/pages/anime_list.h" | |
9 #include "gui/pages/history.h" | |
10 #include "gui/pages/now_playing.h" | |
11 #include "gui/pages/search.h" | |
12 #include "gui/pages/seasons.h" | |
13 #include "gui/pages/statistics.h" | |
14 #include "gui/pages/torrents.h" | |
15 | |
16 #include <QMainWindow> | |
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
112
diff
changeset
|
17 #include <QCloseEvent> |
258 | 18 #include <QStackedWidget> |
170
c8375765f0fc
window: make threading somewhat sane
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
19 #include <QThread> |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
20 #include <QTimer> |
258 | 21 #include <QWidget> |
2 | 22 |
291 | 23 #include <memory> |
24 | |
250 | 25 class QMenu; |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
26 class AnimeListPage; |
250 | 27 |
291 | 28 /* ... :) */ |
170
c8375765f0fc
window: make threading somewhat sane
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
29 Q_DECLARE_METATYPE(std::vector<std::string>); |
c8375765f0fc
window: make threading somewhat sane
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
30 |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
31 class MainWindowPlayingThread final : public QThread { |
258 | 32 Q_OBJECT |
170
c8375765f0fc
window: make threading somewhat sane
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
33 |
258 | 34 public: |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
35 MainWindowPlayingThread(QObject* object = nullptr) : QThread(object) {} |
170
c8375765f0fc
window: make threading somewhat sane
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
36 |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
37 protected: |
258 | 38 void run() override; |
170
c8375765f0fc
window: make threading somewhat sane
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
39 |
258 | 40 signals: |
41 void Done(const std::vector<std::string>& files); | |
170
c8375765f0fc
window: make threading somewhat sane
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
42 }; |
c8375765f0fc
window: make threading somewhat sane
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
43 |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
44 class MainWindowAsyncSynchronizeThread final : public QThread { |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
45 Q_OBJECT |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
46 |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
47 public: |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
48 MainWindowAsyncSynchronizeThread(QAction* action, AnimeListPage* page, QObject* object = nullptr); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
49 void SetAction(QAction* action); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
50 void SetPage(AnimeListPage* page); |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
51 |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
52 protected: |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
53 void run() override; |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
54 |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
55 private: |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
56 QAction* action_ = nullptr; |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
57 AnimeListPage* page_ = nullptr; |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
58 }; |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
59 |
95
8043152ef9d4
include: set classes as final where appropriate
Paper <mrpapersonic@gmail.com>
parents:
79
diff
changeset
|
60 class MainWindow final : public QMainWindow { |
258 | 61 Q_OBJECT |
9 | 62 |
258 | 63 public: |
64 enum class Pages { | |
65 NOW_PLAYING, | |
250 | 66 |
258 | 67 ANIME_LIST, |
68 HISTORY, | |
69 STATISTICS, | |
250 | 70 |
258 | 71 SEARCH, |
72 SEASONS, | |
73 TORRENTS | |
74 }; | |
250 | 75 |
258 | 76 MainWindow(QWidget* parent = nullptr); |
77 void SetActivePage(QWidget* page); | |
78 void CreateBars(); | |
79 void AddMainWidgets(); | |
80 void RetranslateUI(); | |
81 void UpdateFolderMenu(); | |
82 void AsyncSynchronize(QAction* action, QStackedWidget* stack); | |
83 void changeEvent(QEvent* event) override; | |
84 void showEvent(QShowEvent* event) override; | |
85 void closeEvent(QCloseEvent* event) override; | |
2 | 86 |
258 | 87 private: |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
88 QWidget main_widget_; |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
89 QStackedWidget stack_; |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
90 SideBar sidebar_; |
170
c8375765f0fc
window: make threading somewhat sane
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
91 |
291 | 92 AnimeListPage anime_list_page_; |
93 HistoryPage history_page_; | |
94 NowPlayingPage now_playing_page_; | |
95 SearchPage search_page_; | |
96 SeasonsPage seasons_page_; | |
97 StatisticsPage statistics_page_; | |
98 TorrentsPage torrents_page_; | |
99 | |
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
100 MainWindowPlayingThread playing_thread_; |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
101 QTimer playing_thread_timer_; |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
102 |
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
261
diff
changeset
|
103 MainWindowAsyncSynchronizeThread async_synchronize_thread_; |
250 | 104 |
258 | 105 QMenu* folder_menu = nullptr; |
2 | 106 }; |
107 | |
261
3ec7804abf17
include: make header guards more sane
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
108 #endif // MINORI_WINDOW_H_ |