Mercurial > minori
diff src/gui/window.cc @ 369:47c9f8502269
*: clang-format all the things
I've edited the formatting a bit. Now pointer asterisks (and reference
ampersands) are on the variable instead of the type, as well as having
newlines for function braces (but nothing else)
author | Paper <paper@tflc.us> |
---|---|
date | Fri, 25 Jul 2025 10:16:02 -0400 |
parents | 886f66775f31 |
children |
line wrap: on
line diff
--- a/src/gui/window.cc Fri Jul 25 10:05:23 2025 -0400 +++ b/src/gui/window.cc Fri Jul 25 10:16:02 2025 -0400 @@ -43,41 +43,47 @@ #include <iostream> #ifdef MACOSX -# include "sys/osx/dark_theme.h" -# include "sys/osx/permissions.h" +# include "sys/osx/dark_theme.h" +# include "sys/osx/permissions.h" #elif defined(WIN32) -# include "sys/win32/dark_theme.h" +# include "sys/win32/dark_theme.h" #endif -void MainWindowPlayingThread::run() { +void MainWindowPlayingThread::run() +{ std::vector<std::string> files; Track::Media::GetCurrentlyPlaying(files); emit Done(files); } -MainWindowAsyncSynchronizeThread::MainWindowAsyncSynchronizeThread(QAction* action, AnimeListPage* page, QObject* parent) : QThread(parent) { +MainWindowAsyncSynchronizeThread::MainWindowAsyncSynchronizeThread(QAction *action, AnimeListPage *page, + QObject *parent) + : QThread(parent) +{ SetAction(action); SetPage(page); } -void MainWindowAsyncSynchronizeThread::SetAction(QAction* action) { +void MainWindowAsyncSynchronizeThread::SetAction(QAction *action) +{ action_ = action; } -void MainWindowAsyncSynchronizeThread::SetPage(AnimeListPage* page) { +void MainWindowAsyncSynchronizeThread::SetPage(AnimeListPage *page) +{ page_ = page; } -void MainWindowAsyncSynchronizeThread::run() { +void MainWindowAsyncSynchronizeThread::run() +{ action_->setEnabled(false); Services::Synchronize(); page_->Refresh(); action_->setEnabled(true); } -MainWindow::MainWindow(QWidget* parent) - : QMainWindow(parent) - , async_synchronize_thread_(nullptr, nullptr) { +MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), async_synchronize_thread_(nullptr, nullptr) +{ sidebar_.setFixedWidth(128); sidebar_.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); @@ -101,14 +107,14 @@ sidebar_.SetCurrentItem(static_cast<int>(Pages::ANIME_LIST)); setCentralWidget(&main_widget_); - NowPlayingPage* page = reinterpret_cast<NowPlayingPage*>(stack_.widget(static_cast<int>(Pages::NOW_PLAYING))); + NowPlayingPage *page = reinterpret_cast<NowPlayingPage *>(stack_.widget(static_cast<int>(Pages::NOW_PLAYING))); - connect(&playing_thread_, &MainWindowPlayingThread::Done, this, [page](const std::vector<std::string>& files) { - for (const auto& file : files) { + connect(&playing_thread_, &MainWindowPlayingThread::Done, this, [page](const std::vector<std::string> &files) { + for (const auto &file : files) { anitomy::Anitomy anitomy; anitomy.Parse(file); - const auto& elements = anitomy.elements(); + const auto &elements = anitomy.elements(); const std::string title = Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle)); @@ -136,14 +142,16 @@ playing_thread_timer_.start(5000); } -void MainWindow::SetStatusMessage(const std::string& message) { +void MainWindow::SetStatusMessage(const std::string &message) +{ statusBar()->showMessage(Strings::ToQString(message), 2000); } /* FIXME: * ALL of the pages need to have a retranslate function. This would require * huge amounts of refactoring hence why it hasn't been done yet. */ -void MainWindow::AddMainWidgets() { +void MainWindow::AddMainWidgets() +{ int page = sidebar_.GetCurrentItem(); sidebar_.clear(); @@ -164,13 +172,14 @@ main_widget_.layout()->addWidget(&stack_); } -void MainWindow::CreateBars() { - QMenuBar* menubar = new QMenuBar(this); - QAction* sync_action; +void MainWindow::CreateBars() +{ + QMenuBar *menubar = new QMenuBar(this); + QAction *sync_action; { /* File */ - QMenu* menu = menubar->addMenu(tr("&File")); + QMenu *menu = menubar->addMenu(tr("&File")); { folder_menu = menu->addMenu(tr("&Library folders")); @@ -197,14 +206,14 @@ menu->addSeparator(); { - QAction* action = menu->addAction(tr("E&xit"), this, &MainWindow::close); + QAction *action = menu->addAction(tr("E&xit"), this, &MainWindow::close); action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q)); } } { /* Services */ - QMenu* menu = menubar->addMenu(tr("&Services")); + QMenu *menu = menubar->addMenu(tr("&Services")); { { sync_action = menu->addAction(tr("Synchronize &list")); @@ -243,7 +252,7 @@ { /* Tools */ - QMenu* menu = menubar->addMenu(tr("&Tools")); + QMenu *menu = menubar->addMenu(tr("&Tools")); // { // /* Export anime list */ // QMenu* submenu = menu->addMenu(tr("&Export anime list")); @@ -278,7 +287,7 @@ // menu->addSeparator(); { - QAction* action = menu->addAction(tr("&Settings"), [this] { + QAction *action = menu->addAction(tr("&Settings"), [this] { SettingsDialog dialog(this); dialog.exec(); UpdateFolderMenu(); @@ -289,52 +298,52 @@ { /* View */ - QMenu* menu = menubar->addMenu(tr("&View")); + QMenu *menu = menubar->addMenu(tr("&View")); { /* Pages... */ - QActionGroup* pages_group = new QActionGroup(menu); + QActionGroup *pages_group = new QActionGroup(menu); pages_group->setExclusive(true); { - QAction* action = pages_group->addAction(menu->addAction(tr("&Now Playing"))); + QAction *action = pages_group->addAction(menu->addAction(tr("&Now Playing"))); action->setCheckable(true); connect(action, &QAction::toggled, this, [this] { sidebar_.SetCurrentItem(0); }); } { - QAction* action = pages_group->addAction(menu->addAction(tr("&Anime List"))); + QAction *action = pages_group->addAction(menu->addAction(tr("&Anime List"))); action->setCheckable(true); action->setChecked(true); connect(action, &QAction::toggled, this, [this] { sidebar_.SetCurrentItem(1); }); } { - QAction* action = pages_group->addAction(menu->addAction(tr("&History"))); + QAction *action = pages_group->addAction(menu->addAction(tr("&History"))); action->setCheckable(true); connect(action, &QAction::toggled, this, [this] { sidebar_.SetCurrentItem(2); }); } { - QAction* action = pages_group->addAction(menu->addAction(tr("&Statistics"))); + QAction *action = pages_group->addAction(menu->addAction(tr("&Statistics"))); action->setCheckable(true); connect(action, &QAction::toggled, this, [this] { sidebar_.SetCurrentItem(3); }); } { - QAction* action = pages_group->addAction(menu->addAction(tr("S&earch"))); + QAction *action = pages_group->addAction(menu->addAction(tr("S&earch"))); action->setCheckable(true); connect(action, &QAction::toggled, this, [this] { sidebar_.SetCurrentItem(4); }); } { - QAction* action = pages_group->addAction(menu->addAction(tr("Se&asons"))); + QAction *action = pages_group->addAction(menu->addAction(tr("Se&asons"))); action->setCheckable(true); connect(action, &QAction::toggled, this, [this] { sidebar_.SetCurrentItem(5); }); } { - QAction* action = pages_group->addAction(menu->addAction(tr("&Torrents"))); + QAction *action = pages_group->addAction(menu->addAction(tr("&Torrents"))); action->setCheckable(true); connect(action, &QAction::toggled, this, [this] { sidebar_.SetCurrentItem(6); }); } @@ -343,9 +352,9 @@ disconnect(&sidebar_, &SideBar::CurrentItemChanged, nullptr, nullptr); connect(&sidebar_, &SideBar::CurrentItemChanged, &stack_, &QStackedWidget::setCurrentIndex); connect(&sidebar_, &SideBar::CurrentItemChanged, this, [pages_group](int index) { - QAction* checked = pages_group->checkedAction(); + QAction *checked = pages_group->checkedAction(); - const QList<QAction*>& actions = pages_group->actions(); + const QList<QAction *> &actions = pages_group->actions(); if (index > actions.size()) return; @@ -364,7 +373,7 @@ { /* Help */ - QMenu* menu = menubar->addMenu(tr("&Help")); + QMenu *menu = menubar->addMenu(tr("&Help")); { /* About Minori */ @@ -376,7 +385,7 @@ { /* About Qt */ - QAction* action = menu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt); + QAction *action = menu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt); action->setMenuRole(QAction::AboutQtRole); } } @@ -389,32 +398,34 @@ /* remove old toolbar(s) */ /* the empty QString() is a Qt 5 wart... */ - for (QToolBar*& t : findChildren<QToolBar*>(QString(), Qt::FindDirectChildrenOnly)) { + for (QToolBar *&t : findChildren<QToolBar *>(QString(), Qt::FindDirectChildrenOnly)) { removeToolBar(t); delete t; } { /* Toolbar */ - QToolBar* toolbar = new QToolBar(this); + QToolBar *toolbar = new QToolBar(this); toolbar->addAction(sync_action); toolbar->addSeparator(); { - QToolButton* button = new QToolButton(toolbar); - { button->setMenu(folder_menu); } + QToolButton *button = new QToolButton(toolbar); + { + button->setMenu(folder_menu); + } button->setIcon(QIcon(":/icons/24x24/folder-open.png")); button->setPopupMode(QToolButton::InstantPopup); toolbar->addWidget(button); } { - QToolButton* button = new QToolButton(toolbar); + QToolButton *button = new QToolButton(toolbar); { /* links */ - QMenu* menu = new QMenu(button); + QMenu *menu = new QMenu(button); menu->addAction("Hibari", [] { QDesktopServices::openUrl(QUrl("https://hb.wopian.me/")); }); menu->addAction("MALgraph", [] { QDesktopServices::openUrl(QUrl("https://graph.anime.plus/")); }); menu->addSeparator(); @@ -447,7 +458,8 @@ } } -void MainWindow::UpdateFolderMenu() { +void MainWindow::UpdateFolderMenu() +{ if (!folder_menu) return; @@ -455,9 +467,9 @@ /* add in all of our existing folders... */ std::size_t i = 0; - for (const auto& path : session.config.library.paths) { + for (const auto &path : session.config.library.paths) { const QString folder = Strings::ToQString(path); - QAction* action = + QAction *action = folder_menu->addAction(folder, [folder] { QDesktopServices::openUrl(QUrl::fromLocalFile(folder)); }); if (i < 9) { @@ -487,11 +499,13 @@ } } -void MainWindow::SetActivePage(QWidget* page) { +void MainWindow::SetActivePage(QWidget *page) +{ this->setCentralWidget(page); } -void MainWindow::AsyncSynchronize(QAction* action, QStackedWidget* stack) { +void MainWindow::AsyncSynchronize(QAction *action, QStackedWidget *stack) +{ if (session.config.service == Anime::Service::None) { QMessageBox msg; msg.setWindowTitle(tr("Error synchronizing with service!")); @@ -507,7 +521,7 @@ } /* FIXME: make this use a QThread; this is *very* unsafe */ - AnimeListPage* page = reinterpret_cast<AnimeListPage*>(stack->widget(static_cast<int>(Pages::ANIME_LIST))); + AnimeListPage *page = reinterpret_cast<AnimeListPage *>(stack->widget(static_cast<int>(Pages::ANIME_LIST))); if (!async_synchronize_thread_.isRunning()) { async_synchronize_thread_.SetAction(action); async_synchronize_thread_.SetPage(page); @@ -515,7 +529,8 @@ } } -void MainWindow::RetranslateUI() { +void MainWindow::RetranslateUI() +{ /* This sucks a LOT */ setUpdatesEnabled(false); AddMainWidgets(); @@ -523,7 +538,8 @@ setUpdatesEnabled(true); } -void MainWindow::changeEvent(QEvent* event) { +void MainWindow::changeEvent(QEvent *event) +{ if (event) { /* is this really necessary */ switch (event->type()) { // this event is send if a translator is loaded @@ -535,7 +551,8 @@ QMainWindow::changeEvent(event); } -void MainWindow::showEvent(QShowEvent* event) { +void MainWindow::showEvent(QShowEvent *event) +{ QMainWindow::showEvent(event); #ifdef WIN32 /* Technically this *should* be @@ -546,7 +563,8 @@ #endif } -void MainWindow::closeEvent(QCloseEvent* event) { +void MainWindow::closeEvent(QCloseEvent *event) +{ playing_thread_timer_.stop(); playing_thread_.wait(); async_synchronize_thread_.wait();