Mercurial > minori
annotate src/gui/window.cc @ 383:27c462bc7815
make the "Now Playing" page actually work
| author | Paper <paper@tflc.us> |
|---|---|
| date | Thu, 06 Nov 2025 07:10:58 -0500 |
| parents | 47c9f8502269 |
| children |
| rev | line source |
|---|---|
| 9 | 1 #include "gui/window.h" |
| 64 | 2 #include "core/anime_db.h" |
| 9 | 3 #include "core/config.h" |
| 4 #include "core/session.h" | |
| 64 | 5 #include "core/strings.h" |
| 62 | 6 #include "gui/dialog/about.h" |
| 9 | 7 #include "gui/dialog/settings.h" |
| 8 #include "gui/pages/anime_list.h" | |
| 62 | 9 #include "gui/pages/history.h" |
| 9 | 10 #include "gui/pages/now_playing.h" |
| 62 | 11 #include "gui/pages/search.h" |
| 12 #include "gui/pages/seasons.h" | |
| 9 | 13 #include "gui/pages/statistics.h" |
|
54
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
51
diff
changeset
|
14 #include "gui/pages/torrents.h" |
| 258 | 15 #include "gui/theme.h" |
| 46 | 16 #include "gui/widgets/sidebar.h" |
| 258 | 17 #include "library/library.h" |
| 15 | 18 #include "services/services.h" |
| 64 | 19 #include "track/media.h" |
|
147
6fdf0632c003
track: use a bit of a more sane way to manage recognition
Paper <mrpapersonic@gmail.com>
parents:
139
diff
changeset
|
20 |
| 154 | 21 #include "anitomy/anitomy.h" |
| 22 | |
| 63 | 23 #include <QActionGroup> |
| 7 | 24 #include <QApplication> |
| 64 | 25 #include <QDebug> |
|
223
84e0a3c4737a
library: implement menu bar buttons
Paper <mrpapersonic@gmail.com>
parents:
195
diff
changeset
|
26 #include <QDesktopServices> |
| 9 | 27 #include <QFile> |
|
223
84e0a3c4737a
library: implement menu bar buttons
Paper <mrpapersonic@gmail.com>
parents:
195
diff
changeset
|
28 #include <QFileDialog> |
| 69 | 29 #include <QHBoxLayout> |
| 7 | 30 #include <QMainWindow> |
| 31 #include <QMenuBar> | |
| 63 | 32 #include <QMessageBox> |
| 7 | 33 #include <QPlainTextEdit> |
| 34 #include <QStackedWidget> | |
|
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
309
diff
changeset
|
35 #include <QStatusBar> |
| 63 | 36 #include <QTextStream> |
|
168
79a2a24453fa
window: improve performance when getting running files
paper@DavesDouble.local
parents:
154
diff
changeset
|
37 #include <QThread> |
| 77 | 38 #include <QThreadPool> |
| 62 | 39 #include <QTimer> |
| 69 | 40 #include <QToolBar> |
| 41 #include <QToolButton> | |
|
147
6fdf0632c003
track: use a bit of a more sane way to manage recognition
Paper <mrpapersonic@gmail.com>
parents:
139
diff
changeset
|
42 |
|
190
2d5823df870f
dep/animia: finalize de-objc-ifying quartz
Paper <mrpapersonic@gmail.com>
parents:
174
diff
changeset
|
43 #include <iostream> |
|
2d5823df870f
dep/animia: finalize de-objc-ifying quartz
Paper <mrpapersonic@gmail.com>
parents:
174
diff
changeset
|
44 |
|
106
c8c72278f6fd
*: #if -> #ifdef, remove outdated comments in sys/win32/dark_theme.cc
Paper <mrpapersonic@gmail.com>
parents:
105
diff
changeset
|
45 #ifdef MACOSX |
| 369 | 46 # include "sys/osx/dark_theme.h" |
| 47 # include "sys/osx/permissions.h" | |
| 46 | 48 #elif defined(WIN32) |
| 369 | 49 # include "sys/win32/dark_theme.h" |
| 2 | 50 #endif |
| 51 | |
| 369 | 52 void MainWindowPlayingThread::run() |
| 53 { | |
|
170
c8375765f0fc
window: make threading somewhat sane
Paper <mrpapersonic@gmail.com>
parents:
168
diff
changeset
|
54 std::vector<std::string> files; |
|
c8375765f0fc
window: make threading somewhat sane
Paper <mrpapersonic@gmail.com>
parents:
168
diff
changeset
|
55 Track::Media::GetCurrentlyPlaying(files); |
|
c8375765f0fc
window: make threading somewhat sane
Paper <mrpapersonic@gmail.com>
parents:
168
diff
changeset
|
56 emit Done(files); |
|
c8375765f0fc
window: make threading somewhat sane
Paper <mrpapersonic@gmail.com>
parents:
168
diff
changeset
|
57 } |
|
c8375765f0fc
window: make threading somewhat sane
Paper <mrpapersonic@gmail.com>
parents:
168
diff
changeset
|
58 |
| 369 | 59 MainWindowAsyncSynchronizeThread::MainWindowAsyncSynchronizeThread(QAction *action, AnimeListPage *page, |
| 60 QObject *parent) | |
| 61 : QThread(parent) | |
| 62 { | |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
63 SetAction(action); |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
64 SetPage(page); |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
65 } |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
66 |
| 369 | 67 void MainWindowAsyncSynchronizeThread::SetAction(QAction *action) |
| 68 { | |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
69 action_ = action; |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
70 } |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
71 |
| 369 | 72 void MainWindowAsyncSynchronizeThread::SetPage(AnimeListPage *page) |
| 73 { | |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
74 page_ = page; |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
75 } |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
76 |
| 369 | 77 void MainWindowAsyncSynchronizeThread::run() |
| 78 { | |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
79 action_->setEnabled(false); |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
80 Services::Synchronize(); |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
81 page_->Refresh(); |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
82 action_->setEnabled(true); |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
83 } |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
84 |
| 369 | 85 MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), async_synchronize_thread_(nullptr, nullptr) |
| 86 { | |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
87 sidebar_.setFixedWidth(128); |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
88 sidebar_.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
89 |
|
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
309
diff
changeset
|
90 statusBar(); |
|
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
309
diff
changeset
|
91 |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
92 new QHBoxLayout(&main_widget_); |
| 10 | 93 |
| 291 | 94 CreateBars(); |
| 95 | |
| 96 stack_.addWidget(&now_playing_page_); | |
| 97 /* ---- */ | |
| 98 stack_.addWidget(&anime_list_page_); | |
| 99 stack_.addWidget(&history_page_); | |
| 100 stack_.addWidget(&statistics_page_); | |
| 101 /* ---- */ | |
| 102 stack_.addWidget(&search_page_); | |
| 103 stack_.addWidget(&seasons_page_); | |
| 104 stack_.addWidget(&torrents_page_); | |
| 105 | |
|
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
106 AddMainWidgets(); |
| 291 | 107 sidebar_.SetCurrentItem(static_cast<int>(Pages::ANIME_LIST)); |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
108 setCentralWidget(&main_widget_); |
| 79 | 109 |
|
383
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
369
diff
changeset
|
110 /* This is disgusting */ |
| 369 | 111 NowPlayingPage *page = reinterpret_cast<NowPlayingPage *>(stack_.widget(static_cast<int>(Pages::NOW_PLAYING))); |
| 79 | 112 |
| 369 | 113 connect(&playing_thread_, &MainWindowPlayingThread::Done, this, [page](const std::vector<std::string> &files) { |
|
383
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
369
diff
changeset
|
114 if (!files.size()) { |
|
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
369
diff
changeset
|
115 page->SetDefault(); |
|
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
369
diff
changeset
|
116 return; |
|
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
369
diff
changeset
|
117 } |
|
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
369
diff
changeset
|
118 |
| 369 | 119 for (const auto &file : files) { |
|
232
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
228
diff
changeset
|
120 anitomy::Anitomy anitomy; |
|
347
a0aa8c8c4307
dep/anitomy: port to use UCS-4 rather than wide strings
Paper <paper@paper.us.eu.org>
parents:
328
diff
changeset
|
121 anitomy.Parse(file); |
|
232
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
228
diff
changeset
|
122 |
| 369 | 123 const auto &elements = anitomy.elements(); |
|
347
a0aa8c8c4307
dep/anitomy: port to use UCS-4 rather than wide strings
Paper <paper@paper.us.eu.org>
parents:
328
diff
changeset
|
124 |
|
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
125 const std::string title = Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle)); |
|
232
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
228
diff
changeset
|
126 |
|
319
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
315
diff
changeset
|
127 int id = Anime::db.LookupAnimeTitle(title); |
|
232
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
228
diff
changeset
|
128 if (id <= 0) |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
228
diff
changeset
|
129 continue; |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
228
diff
changeset
|
130 |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
228
diff
changeset
|
131 page->SetPlaying(Anime::db.items[id], elements); |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
228
diff
changeset
|
132 break; |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
228
diff
changeset
|
133 } |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
228
diff
changeset
|
134 }); |
|
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
228
diff
changeset
|
135 |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
136 connect(&playing_thread_timer_, &QTimer::timeout, this, [this] { |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
137 if (playing_thread_.isRunning()) |
|
170
c8375765f0fc
window: make threading somewhat sane
Paper <mrpapersonic@gmail.com>
parents:
168
diff
changeset
|
138 return; |
|
190
2d5823df870f
dep/animia: finalize de-objc-ifying quartz
Paper <mrpapersonic@gmail.com>
parents:
174
diff
changeset
|
139 |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
140 playing_thread_.start(); |
| 79 | 141 }); |
|
170
c8375765f0fc
window: make threading somewhat sane
Paper <mrpapersonic@gmail.com>
parents:
168
diff
changeset
|
142 |
| 237 | 143 #ifdef MACOSX |
|
383
27c462bc7815
make the "Now Playing" page actually work
Paper <paper@tflc.us>
parents:
369
diff
changeset
|
144 /* Anitomy needs specific permissions for window title grabbing */ |
| 237 | 145 if (!osx::AskForPermissions()) |
| 146 return; | |
| 147 #endif | |
| 148 | |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
149 playing_thread_timer_.start(5000); |
| 79 | 150 } |
| 151 | |
| 369 | 152 void MainWindow::SetStatusMessage(const std::string &message) |
| 153 { | |
|
315
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
309
diff
changeset
|
154 statusBar()->showMessage(Strings::ToQString(message), 2000); |
|
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
309
diff
changeset
|
155 } |
|
34347fd2a2de
session: allow printing status messages
Paper <paper@paper.us.eu.org>
parents:
309
diff
changeset
|
156 |
|
366
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
347
diff
changeset
|
157 /* FIXME: |
|
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
347
diff
changeset
|
158 * ALL of the pages need to have a retranslate function. This would require |
|
886f66775f31
animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents:
347
diff
changeset
|
159 * huge amounts of refactoring hence why it hasn't been done yet. */ |
| 369 | 160 void MainWindow::AddMainWidgets() |
| 161 { | |
| 291 | 162 int page = sidebar_.GetCurrentItem(); |
| 250 | 163 |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
164 sidebar_.clear(); |
|
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
165 |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
166 sidebar_.AddItem(tr("Now Playing"), SideBar::CreateIcon(":/icons/16x16/film.png")); |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
167 sidebar_.AddSeparator(); |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
168 sidebar_.AddItem(tr("Anime List"), SideBar::CreateIcon(":/icons/16x16/document-list.png")); |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
169 sidebar_.AddItem(tr("History"), SideBar::CreateIcon(":/icons/16x16/clock-history-frame.png")); |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
170 sidebar_.AddItem(tr("Statistics"), SideBar::CreateIcon(":/icons/16x16/chart.png")); |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
171 sidebar_.AddSeparator(); |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
172 sidebar_.AddItem(tr("Search"), SideBar::CreateIcon(":/icons/16x16/magnifier.png")); |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
173 sidebar_.AddItem(tr("Seasons"), SideBar::CreateIcon(":/icons/16x16/calendar.png")); |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
174 sidebar_.AddItem(tr("Torrents"), SideBar::CreateIcon(":/icons/16x16/feed.png")); |
|
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
175 |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
176 sidebar_.SetCurrentItem(page); |
|
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
177 |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
178 main_widget_.layout()->addWidget(&sidebar_); |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
179 main_widget_.layout()->addWidget(&stack_); |
|
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
180 } |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
181 |
| 369 | 182 void MainWindow::CreateBars() |
| 183 { | |
| 184 QMenuBar *menubar = new QMenuBar(this); | |
| 185 QAction *sync_action; | |
|
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
186 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
187 { |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
188 /* File */ |
| 369 | 189 QMenu *menu = menubar->addMenu(tr("&File")); |
|
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
190 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
191 { |
|
223
84e0a3c4737a
library: implement menu bar buttons
Paper <mrpapersonic@gmail.com>
parents:
195
diff
changeset
|
192 folder_menu = menu->addMenu(tr("&Library folders")); |
|
84e0a3c4737a
library: implement menu bar buttons
Paper <mrpapersonic@gmail.com>
parents:
195
diff
changeset
|
193 |
| 250 | 194 UpdateFolderMenu(); |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
195 } |
| 2 | 196 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
197 { |
|
328
71396ecb6f7e
library: convert to class + database
Paper <paper@paper.us.eu.org>
parents:
319
diff
changeset
|
198 menu->addAction(tr("&Scan available episodes"), [] { Library::db.Refresh(); }); |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
199 } |
|
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
200 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
201 menu->addSeparator(); |
|
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
202 |
| 258 | 203 // { |
| 204 // QAction* action = menu->addAction(tr("Play &next episode")); | |
| 205 // action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_N)); | |
| 206 // } | |
| 207 // | |
| 208 // { | |
| 209 // QAction* action = menu->addAction(tr("Play &random episode")); | |
| 210 // action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R)); | |
| 211 // } | |
| 2 | 212 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
213 menu->addSeparator(); |
| 2 | 214 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
215 { |
| 369 | 216 QAction *action = menu->addAction(tr("E&xit"), this, &MainWindow::close); |
|
223
84e0a3c4737a
library: implement menu bar buttons
Paper <mrpapersonic@gmail.com>
parents:
195
diff
changeset
|
217 action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q)); |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
218 } |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
219 } |
| 2 | 220 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
221 { |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
222 /* Services */ |
| 369 | 223 QMenu *menu = menubar->addMenu(tr("&Services")); |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
224 { |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
225 { |
|
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
226 sync_action = menu->addAction(tr("Synchronize &list")); |
|
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
227 |
| 258 | 228 connect(sync_action, &QAction::triggered, this, |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
229 [this, sync_action] { AsyncSynchronize(sync_action, &stack_); }); |
|
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
230 |
|
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
231 sync_action->setIcon(QIcon(":/icons/24x24/arrow-circle-double-135.png")); |
|
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
232 sync_action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S)); |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
233 } |
| 2 | 234 |
| 258 | 235 // menu->addSeparator(); |
| 236 // | |
| 237 // { | |
| 238 // /* AniList */ | |
| 239 // QMenu* submenu = menu->addMenu(tr("&AniList")); | |
| 240 // QAction* action = submenu->addAction(tr("Go to my &profile")); | |
| 241 // action = submenu->addAction(tr("Go to my &stats")); | |
| 242 // } | |
| 243 // | |
| 244 // { | |
| 245 // /* Kitsu */ | |
| 246 // QMenu* submenu = menu->addMenu(tr("&Kitsu")); | |
| 247 // QAction* action = submenu->addAction(tr("Go to my &feed")); | |
| 248 // action = submenu->addAction(tr("Go to my &library")); | |
| 249 // action = submenu->addAction(tr("Go to my &profile")); | |
| 250 // } | |
| 251 // { | |
| 252 // QMenu* submenu = menu->addMenu(tr("&MyAnimeList")); | |
| 253 // QAction* action = submenu->addAction(tr("Go to my p&anel")); | |
| 254 // action = submenu->addAction(tr("Go to my &profile")); | |
| 255 // action = submenu->addAction(tr("Go to my &history")); | |
| 256 // } | |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
257 } |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
258 } |
| 2 | 259 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
260 { |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
261 /* Tools */ |
| 369 | 262 QMenu *menu = menubar->addMenu(tr("&Tools")); |
| 258 | 263 // { |
| 264 // /* Export anime list */ | |
| 265 // QMenu* submenu = menu->addMenu(tr("&Export anime list")); | |
| 266 // | |
| 267 // { | |
| 268 // /* Markdown export */ | |
| 269 // QAction* action = submenu->addAction(tr("Export as &Markdown...")); | |
| 270 // } | |
| 271 // | |
| 272 // { | |
| 273 // /* XML export */ | |
| 274 // QAction* action = submenu->addAction(tr("Export as MyAnimeList &XML...")); | |
| 275 // } | |
| 276 // } | |
| 277 // menu->addSeparator(); | |
| 278 // | |
| 279 // { | |
| 280 // QAction* action = menu->addAction(tr("Enable anime &recognition")); | |
| 281 // action->setCheckable(true); | |
| 282 // } | |
| 283 // | |
| 284 // { | |
| 285 // QAction* action = menu->addAction(tr("Enable auto &sharing")); | |
| 286 // action->setCheckable(true); | |
| 287 // } | |
| 288 // | |
| 289 // { | |
| 290 // QAction* action = menu->addAction(tr("Enable &auto synchronization")); | |
| 291 // action->setCheckable(true); | |
| 292 // } | |
| 293 // | |
| 294 // menu->addSeparator(); | |
|
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
295 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
296 { |
| 369 | 297 QAction *action = menu->addAction(tr("&Settings"), [this] { |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
298 SettingsDialog dialog(this); |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
299 dialog.exec(); |
| 250 | 300 UpdateFolderMenu(); |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
301 }); |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
302 action->setMenuRole(QAction::PreferencesRole); |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
303 } |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
304 } |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
305 |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
306 { |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
307 /* View */ |
| 369 | 308 QMenu *menu = menubar->addMenu(tr("&View")); |
|
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
309 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
310 { |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
311 /* Pages... */ |
| 369 | 312 QActionGroup *pages_group = new QActionGroup(menu); |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
313 pages_group->setExclusive(true); |
|
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
314 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
315 { |
| 369 | 316 QAction *action = pages_group->addAction(menu->addAction(tr("&Now Playing"))); |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
317 action->setCheckable(true); |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
318 connect(action, &QAction::toggled, this, [this] { sidebar_.SetCurrentItem(0); }); |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
319 } |
|
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
320 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
321 { |
| 369 | 322 QAction *action = pages_group->addAction(menu->addAction(tr("&Anime List"))); |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
323 action->setCheckable(true); |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
324 action->setChecked(true); |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
325 connect(action, &QAction::toggled, this, [this] { sidebar_.SetCurrentItem(1); }); |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
326 } |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
327 |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
328 { |
| 369 | 329 QAction *action = pages_group->addAction(menu->addAction(tr("&History"))); |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
330 action->setCheckable(true); |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
331 connect(action, &QAction::toggled, this, [this] { sidebar_.SetCurrentItem(2); }); |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
332 } |
|
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
333 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
334 { |
| 369 | 335 QAction *action = pages_group->addAction(menu->addAction(tr("&Statistics"))); |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
336 action->setCheckable(true); |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
337 connect(action, &QAction::toggled, this, [this] { sidebar_.SetCurrentItem(3); }); |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
338 } |
|
48
e613772f41d5
statistics.cpp: show requests made
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
339 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
340 { |
| 369 | 341 QAction *action = pages_group->addAction(menu->addAction(tr("S&earch"))); |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
342 action->setCheckable(true); |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
343 connect(action, &QAction::toggled, this, [this] { sidebar_.SetCurrentItem(4); }); |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
344 } |
|
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
345 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
346 { |
| 369 | 347 QAction *action = pages_group->addAction(menu->addAction(tr("Se&asons"))); |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
348 action->setCheckable(true); |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
349 connect(action, &QAction::toggled, this, [this] { sidebar_.SetCurrentItem(5); }); |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
350 } |
|
54
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
51
diff
changeset
|
351 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
352 { |
| 369 | 353 QAction *action = pages_group->addAction(menu->addAction(tr("&Torrents"))); |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
354 action->setCheckable(true); |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
355 connect(action, &QAction::toggled, this, [this] { sidebar_.SetCurrentItem(6); }); |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
356 } |
|
54
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
51
diff
changeset
|
357 |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
358 /* pain in the ass */ |
| 291 | 359 disconnect(&sidebar_, &SideBar::CurrentItemChanged, nullptr, nullptr); |
| 360 connect(&sidebar_, &SideBar::CurrentItemChanged, &stack_, &QStackedWidget::setCurrentIndex); | |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
361 connect(&sidebar_, &SideBar::CurrentItemChanged, this, [pages_group](int index) { |
| 369 | 362 QAction *checked = pages_group->checkedAction(); |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
363 |
| 369 | 364 const QList<QAction *> &actions = pages_group->actions(); |
| 250 | 365 if (index > actions.size()) |
| 366 return; | |
| 367 | |
| 368 if (checked) | |
| 369 checked->setChecked(false); | |
| 370 actions[index]->setChecked(true); | |
| 371 }); | |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
372 } |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
373 |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
374 menu->addSeparator(); |
|
44
619cbd6e69f9
filesystem: fix CreateDirectories function
Paper <mrpapersonic@gmail.com>
parents:
37
diff
changeset
|
375 |
| 258 | 376 // { |
| 377 // QAction* action = menu->addAction(tr("Show sidebar")); | |
| 378 // } | |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
379 } |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
380 |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
381 { |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
382 /* Help */ |
| 369 | 383 QMenu *menu = menubar->addMenu(tr("&Help")); |
| 2 | 384 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
385 { |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
386 /* About Minori */ |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
387 menu->addAction(tr("&About Minori"), this, [this] { |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
388 AboutWindow dialog(this); |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
389 dialog.exec(); |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
390 }); |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
391 } |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
392 |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
393 { |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
394 /* About Qt */ |
| 369 | 395 QAction *action = menu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt); |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
396 action->setMenuRole(QAction::AboutQtRole); |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
397 } |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
398 } |
|
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
399 /* QMainWindow will delete the old one for us, |
| 255 | 400 * according to the docs |
| 258 | 401 */ |
| 2 | 402 setMenuBar(menubar); |
| 7 | 403 |
|
68
2417121d894e
*: normalize usage of layouts
Paper <mrpapersonic@gmail.com>
parents:
64
diff
changeset
|
404 /* Toolbar */ |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
405 |
| 79 | 406 /* remove old toolbar(s) */ |
| 115 | 407 /* the empty QString() is a Qt 5 wart... */ |
| 369 | 408 for (QToolBar *&t : findChildren<QToolBar *>(QString(), Qt::FindDirectChildrenOnly)) { |
| 79 | 409 removeToolBar(t); |
|
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
410 delete t; |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
411 } |
| 79 | 412 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
413 { |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
414 /* Toolbar */ |
| 369 | 415 QToolBar *toolbar = new QToolBar(this); |
|
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
416 toolbar->addAction(sync_action); |
| 69 | 417 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
418 toolbar->addSeparator(); |
| 69 | 419 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
420 { |
| 369 | 421 QToolButton *button = new QToolButton(toolbar); |
| 422 { | |
| 423 button->setMenu(folder_menu); | |
| 424 } | |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
425 button->setIcon(QIcon(":/icons/24x24/folder-open.png")); |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
426 button->setPopupMode(QToolButton::InstantPopup); |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
427 toolbar->addWidget(button); |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
428 } |
| 69 | 429 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
430 { |
| 369 | 431 QToolButton *button = new QToolButton(toolbar); |
| 69 | 432 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
433 { |
|
223
84e0a3c4737a
library: implement menu bar buttons
Paper <mrpapersonic@gmail.com>
parents:
195
diff
changeset
|
434 /* links */ |
| 369 | 435 QMenu *menu = new QMenu(button); |
| 258 | 436 menu->addAction("Hibari", [] { QDesktopServices::openUrl(QUrl("https://hb.wopian.me/")); }); |
| 437 menu->addAction("MALgraph", [] { QDesktopServices::openUrl(QUrl("https://graph.anime.plus/")); }); | |
|
223
84e0a3c4737a
library: implement menu bar buttons
Paper <mrpapersonic@gmail.com>
parents:
195
diff
changeset
|
438 menu->addSeparator(); |
| 258 | 439 menu->addAction("AniChart", [] { QDesktopServices::openUrl(QUrl("https://anichart.net/airing")); }); |
| 440 menu->addAction("Monthly.moe", | |
| 441 [] { QDesktopServices::openUrl(QUrl("https://www.monthly.moe/weekly")); }); | |
| 442 menu->addAction("Senpai Anime Charts", | |
| 443 [] { QDesktopServices::openUrl(QUrl("https://www.senpai.moe/?mode=calendar")); }); | |
|
223
84e0a3c4737a
library: implement menu bar buttons
Paper <mrpapersonic@gmail.com>
parents:
195
diff
changeset
|
444 menu->addSeparator(); |
| 258 | 445 menu->addAction("Anime Streaming Search Engine", |
| 446 [] { QDesktopServices::openUrl(QUrl("https://because.moe/")); }); | |
| 447 menu->addAction("The Fansub Database", [] { QDesktopServices::openUrl(QUrl("https://fansubdb.com")); }); | |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
448 |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
449 button->setMenu(menu); |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
450 } |
| 69 | 451 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
452 button->setIcon(QIcon(":/icons/24x24/application-export.png")); |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
453 button->setPopupMode(QToolButton::InstantPopup); |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
454 toolbar->addWidget(button); |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
455 } |
| 69 | 456 |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
457 toolbar->addSeparator(); |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
458 toolbar->addAction(QIcon(":/icons/24x24/gear.png"), tr("S&ettings"), [this] { |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
459 SettingsDialog dialog(this); |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
460 dialog.exec(); |
| 250 | 461 /* library folders might have changed! */ |
| 462 UpdateFolderMenu(); | |
|
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
463 }); |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
464 addToolBar(toolbar); |
|
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
113
diff
changeset
|
465 } |
| 2 | 466 } |
| 467 | |
| 369 | 468 void MainWindow::UpdateFolderMenu() |
| 469 { | |
| 250 | 470 if (!folder_menu) |
| 471 return; | |
| 472 | |
| 473 folder_menu->clear(); | |
| 474 | |
| 475 /* add in all of our existing folders... */ | |
| 476 std::size_t i = 0; | |
| 369 | 477 for (const auto &path : session.config.library.paths) { |
| 250 | 478 const QString folder = Strings::ToQString(path); |
| 369 | 479 QAction *action = |
| 258 | 480 folder_menu->addAction(folder, [folder] { QDesktopServices::openUrl(QUrl::fromLocalFile(folder)); }); |
| 250 | 481 |
| 482 if (i < 9) { | |
| 483 /* Qt::Key_1 is equivalent to 1 in ASCII, so we can use the same | |
| 484 * stupid `'0' + i` trick here | |
| 258 | 485 */ |
| 250 | 486 action->setShortcut(QKeySequence(Qt::ALT | static_cast<Qt::Modifier>(Qt::Key_1 + i))); |
| 487 } else if (i == 9) { | |
| 488 action->setShortcut(QKeySequence(Qt::ALT | Qt::Key_0)); | |
| 489 } | |
| 490 /* don't bother with a shortcut in case of more... */ | |
| 491 i++; | |
| 492 } | |
| 493 | |
| 494 folder_menu->addSeparator(); | |
| 495 | |
| 496 { | |
| 258 | 497 folder_menu->addAction(tr("&Add new folder..."), [this] { |
| 498 const QString dir = | |
| 499 QFileDialog::getExistingDirectory(this, tr("Open Directory"), QDir::homePath(), | |
| 500 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); | |
| 250 | 501 if (dir.isEmpty()) |
| 502 return; | |
| 503 session.config.library.paths.insert(Strings::ToUtf8String(dir)); | |
| 504 UpdateFolderMenu(); | |
| 505 }); | |
| 506 } | |
| 507 } | |
| 508 | |
| 369 | 509 void MainWindow::SetActivePage(QWidget *page) |
| 510 { | |
| 2 | 511 this->setCentralWidget(page); |
| 512 } | |
| 513 | |
| 369 | 514 void MainWindow::AsyncSynchronize(QAction *action, QStackedWidget *stack) |
| 515 { | |
| 279 | 516 if (session.config.service == Anime::Service::None) { |
|
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
517 QMessageBox msg; |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
518 msg.setWindowTitle(tr("Error synchronizing with service!")); |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
519 msg.setText(tr("It seems you haven't yet selected a service to use.")); |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
520 msg.setInformativeText(tr("Would you like to select one now?")); |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
521 msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No); |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
522 msg.setDefaultButton(QMessageBox::Yes); |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
523 int ret = msg.exec(); |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
524 if (ret == QMessageBox::Yes) { |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
525 SettingsDialog dialog; |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
526 dialog.exec(); |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
527 } |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
528 } |
|
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
232
diff
changeset
|
529 |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
530 /* FIXME: make this use a QThread; this is *very* unsafe */ |
| 369 | 531 AnimeListPage *page = reinterpret_cast<AnimeListPage *>(stack->widget(static_cast<int>(Pages::ANIME_LIST))); |
|
273
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
532 if (!async_synchronize_thread_.isRunning()) { |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
533 async_synchronize_thread_.SetAction(action); |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
534 async_synchronize_thread_.SetPage(page); |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
535 async_synchronize_thread_.start(); |
|
f31305b9f60a
*: various code safety changes
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
536 } |
|
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
537 } |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
538 |
| 369 | 539 void MainWindow::RetranslateUI() |
| 540 { | |
| 291 | 541 /* This sucks a LOT */ |
|
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
542 setUpdatesEnabled(false); |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
543 AddMainWidgets(); |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
544 CreateBars(); |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
545 setUpdatesEnabled(true); |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
546 } |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
547 |
| 369 | 548 void MainWindow::changeEvent(QEvent *event) |
| 549 { | |
|
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
550 if (event) { /* is this really necessary */ |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
551 switch (event->type()) { |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
552 // this event is send if a translator is loaded |
| 258 | 553 case QEvent::LanguageChange: RetranslateUI(); break; |
|
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
554 |
| 258 | 555 default: break; |
|
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
556 } |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
557 } |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
558 QMainWindow::changeEvent(event); |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
559 } |
|
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
560 |
| 369 | 561 void MainWindow::showEvent(QShowEvent *event) |
| 562 { | |
|
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
103
diff
changeset
|
563 QMainWindow::showEvent(event); |
|
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
103
diff
changeset
|
564 #ifdef WIN32 |
|
112
80f49f623d30
locale: allow switching locales without restarting
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
565 /* Technically this *should* be |
| 291 | 566 * session.config.theme.IsInDarkTheme() && win32::IsInDarkTheme() |
| 567 * but I prefer the title bar being black even when light mode | |
| 568 * is enabled :/ */ | |
| 108 | 569 win32::SetTitleBarsToBlack(session.config.theme.IsInDarkTheme()); |
|
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
103
diff
changeset
|
570 #endif |
|
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
103
diff
changeset
|
571 } |
|
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
103
diff
changeset
|
572 |
| 369 | 573 void MainWindow::closeEvent(QCloseEvent *event) |
| 574 { | |
| 291 | 575 playing_thread_timer_.stop(); |
| 576 playing_thread_.wait(); | |
| 577 async_synchronize_thread_.wait(); | |
| 578 | |
| 2 | 579 session.config.Save(); |
|
174
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
170
diff
changeset
|
580 Anime::db.SaveDatabaseToDisk(); |
| 2 | 581 event->accept(); |
| 582 } |
