From a59a6ce8e48128f4d3058b1171fd77571b2d5951 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 11 Apr 2022 12:19:05 +0800 Subject: [PATCH 1/2] Remove redundant function This helper function is useless after using `Path` class. --- src/app/application.cpp | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/src/app/application.cpp b/src/app/application.cpp index d3b99d19c..15fa21c52 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -324,15 +324,6 @@ void Application::processMessage(const QString &message) void Application::runExternalProgram(const BitTorrent::Torrent *torrent) const { -#if defined(Q_OS_WIN) - const auto chopPathSep = [](const QString &str) -> QString - { - if (str.endsWith(u'\\')) - return str.mid(0, (str.length() -1)); - return str; - }; -#endif - QString program = Preferences::instance()->getAutoRunProgram().trimmed(); for (int i = (program.length() - 2); i >= 0; --i) @@ -347,18 +338,10 @@ void Application::runExternalProgram(const BitTorrent::Torrent *torrent) const program.replace(i, 2, QString::number(torrent->filesCount())); break; case u'D': -#if defined(Q_OS_WIN) - program.replace(i, 2, chopPathSep(torrent->savePath().toString())); -#else program.replace(i, 2, torrent->savePath().toString()); -#endif break; case u'F': -#if defined(Q_OS_WIN) - program.replace(i, 2, chopPathSep(torrent->contentPath().toString())); -#else program.replace(i, 2, torrent->contentPath().toString()); -#endif break; case u'G': program.replace(i, 2, torrent->tags().join(u","_qs)); @@ -379,11 +362,7 @@ void Application::runExternalProgram(const BitTorrent::Torrent *torrent) const program.replace(i, 2, torrent->name()); break; case u'R': -#if defined(Q_OS_WIN) - program.replace(i, 2, chopPathSep(torrent->rootPath().toString())); -#else program.replace(i, 2, torrent->rootPath().toString()); -#endif break; case u'T': program.replace(i, 2, torrent->currentTracker()); From 3f762a416d742bd50bd6b0408b807e2f49636641 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 12 Apr 2022 16:19:09 +0800 Subject: [PATCH 2/2] Use proper method for deferred calls --- src/app/application.cpp | 3 ++- src/base/search/searchhandler.cpp | 4 +++- src/gui/mainwindow.cpp | 8 ++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/app/application.cpp b/src/app/application.cpp index 15fa21c52..42732978b 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #ifndef DISABLE_GUI @@ -770,7 +771,7 @@ void Application::shutdownCleanup(QSessionManager &manager) // According to the qt docs we shouldn't call quit() inside a slot. // aboutToQuit() is never emitted if the user hits "Cancel" in // the above dialog. - QTimer::singleShot(0, qApp, &QCoreApplication::quit); + QMetaObject::invokeMethod(qApp, &QCoreApplication::quit, Qt::QueuedConnection); } #endif diff --git a/src/base/search/searchhandler.cpp b/src/base/search/searchhandler.cpp index f4946ba2c..5c7fd8eb4 100644 --- a/src/base/search/searchhandler.cpp +++ b/src/base/search/searchhandler.cpp @@ -29,6 +29,7 @@ #include "searchhandler.h" +#include #include #include #include @@ -87,7 +88,8 @@ SearchHandler::SearchHandler(const QString &pattern, const QString &category, co m_searchTimeout->start(180000); // 3 min // deferred start allows clients to handle starting-related signals - QTimer::singleShot(0, this, [this]() { m_searchProcess->start(QIODevice::ReadOnly); }); + QMetaObject::invokeMethod(this, [this]() { m_searchProcess->start(QIODevice::ReadOnly); } + , Qt::QueuedConnection); } bool SearchHandler::isActive() const diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index f668e5672..99119731a 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -348,8 +349,7 @@ MainWindow::MainWindow(QWidget *parent) on_actionWarningMessages_triggered(m_ui->actionWarningMessages->isChecked()); on_actionCriticalMessages_triggered(m_ui->actionCriticalMessages->isChecked()); if (m_ui->actionSearchWidget->isChecked()) - QTimer::singleShot(0, this, &MainWindow::on_actionSearchWidget_triggered); - + QMetaObject::invokeMethod(this, &MainWindow::on_actionSearchWidget_triggered, Qt::QueuedConnection); // Auto shutdown actions auto *autoShutdownGroup = new QActionGroup(this); autoShutdownGroup->setExclusive(true); @@ -1195,7 +1195,7 @@ void MainWindow::closeEvent(QCloseEvent *e) if (!m_forceExit && m_systrayIcon && goToSystrayOnExit && !this->isHidden()) { e->ignore(); - QTimer::singleShot(0, this, &QWidget::hide); + QMetaObject::invokeMethod(this, &QWidget::hide, Qt::QueuedConnection); if (!pref->closeToTrayNotified()) { showNotificationBalloon(tr("qBittorrent is closed to tray"), tr("This behavior can be changed in the settings. You won't be reminded again.")); @@ -1292,7 +1292,7 @@ bool MainWindow::event(QEvent *e) { qDebug("Minimize to Tray enabled, hiding!"); e->ignore(); - QTimer::singleShot(0, this, &QWidget::hide); + QMetaObject::invokeMethod(this, &QWidget::hide, Qt::QueuedConnection); if (!pref->minimizeToTrayNotified()) { showNotificationBalloon(tr("qBittorrent is minimized to tray"), tr("This behavior can be changed in the settings. You won't be reminded again."));