1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-11 07:18:08 +00:00

Merge pull request #16863 from Chocobo1/run

Remove redundant function
This commit is contained in:
Chocobo1 2022-04-13 12:05:58 +08:00 committed by GitHub
commit dc22109fa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 27 deletions

View File

@ -47,6 +47,7 @@
#include <QByteArray> #include <QByteArray>
#include <QDebug> #include <QDebug>
#include <QLibraryInfo> #include <QLibraryInfo>
#include <QMetaObject>
#include <QProcess> #include <QProcess>
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
@ -324,15 +325,6 @@ void Application::processMessage(const QString &message)
void Application::runExternalProgram(const BitTorrent::Torrent *torrent) const 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(); QString program = Preferences::instance()->getAutoRunProgram().trimmed();
for (int i = (program.length() - 2); i >= 0; --i) for (int i = (program.length() - 2); i >= 0; --i)
@ -347,18 +339,10 @@ void Application::runExternalProgram(const BitTorrent::Torrent *torrent) const
program.replace(i, 2, QString::number(torrent->filesCount())); program.replace(i, 2, QString::number(torrent->filesCount()));
break; break;
case u'D': case u'D':
#if defined(Q_OS_WIN)
program.replace(i, 2, chopPathSep(torrent->savePath().toString()));
#else
program.replace(i, 2, torrent->savePath().toString()); program.replace(i, 2, torrent->savePath().toString());
#endif
break; break;
case u'F': case u'F':
#if defined(Q_OS_WIN)
program.replace(i, 2, chopPathSep(torrent->contentPath().toString()));
#else
program.replace(i, 2, torrent->contentPath().toString()); program.replace(i, 2, torrent->contentPath().toString());
#endif
break; break;
case u'G': case u'G':
program.replace(i, 2, torrent->tags().join(u","_qs)); program.replace(i, 2, torrent->tags().join(u","_qs));
@ -379,11 +363,7 @@ void Application::runExternalProgram(const BitTorrent::Torrent *torrent) const
program.replace(i, 2, torrent->name()); program.replace(i, 2, torrent->name());
break; break;
case u'R': case u'R':
#if defined(Q_OS_WIN)
program.replace(i, 2, chopPathSep(torrent->rootPath().toString()));
#else
program.replace(i, 2, torrent->rootPath().toString()); program.replace(i, 2, torrent->rootPath().toString());
#endif
break; break;
case u'T': case u'T':
program.replace(i, 2, torrent->currentTracker()); program.replace(i, 2, torrent->currentTracker());
@ -791,7 +771,7 @@ void Application::shutdownCleanup(QSessionManager &manager)
// According to the qt docs we shouldn't call quit() inside a slot. // According to the qt docs we shouldn't call quit() inside a slot.
// aboutToQuit() is never emitted if the user hits "Cancel" in // aboutToQuit() is never emitted if the user hits "Cancel" in
// the above dialog. // the above dialog.
QTimer::singleShot(0, qApp, &QCoreApplication::quit); QMetaObject::invokeMethod(qApp, &QCoreApplication::quit, Qt::QueuedConnection);
} }
#endif #endif

View File

@ -29,6 +29,7 @@
#include "searchhandler.h" #include "searchhandler.h"
#include <QMetaObject>
#include <QProcess> #include <QProcess>
#include <QTimer> #include <QTimer>
#include <QVector> #include <QVector>
@ -87,7 +88,8 @@ SearchHandler::SearchHandler(const QString &pattern, const QString &category, co
m_searchTimeout->start(180000); // 3 min m_searchTimeout->start(180000); // 3 min
// deferred start allows clients to handle starting-related signals // 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 bool SearchHandler::isActive() const

View File

@ -40,6 +40,7 @@
#include <QFileSystemWatcher> #include <QFileSystemWatcher>
#include <QKeyEvent> #include <QKeyEvent>
#include <QMessageBox> #include <QMessageBox>
#include <QMetaObject>
#include <QMimeData> #include <QMimeData>
#include <QProcess> #include <QProcess>
#include <QPushButton> #include <QPushButton>
@ -348,8 +349,7 @@ MainWindow::MainWindow(QWidget *parent)
on_actionWarningMessages_triggered(m_ui->actionWarningMessages->isChecked()); on_actionWarningMessages_triggered(m_ui->actionWarningMessages->isChecked());
on_actionCriticalMessages_triggered(m_ui->actionCriticalMessages->isChecked()); on_actionCriticalMessages_triggered(m_ui->actionCriticalMessages->isChecked());
if (m_ui->actionSearchWidget->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 shutdown actions
auto *autoShutdownGroup = new QActionGroup(this); auto *autoShutdownGroup = new QActionGroup(this);
autoShutdownGroup->setExclusive(true); autoShutdownGroup->setExclusive(true);
@ -1195,7 +1195,7 @@ void MainWindow::closeEvent(QCloseEvent *e)
if (!m_forceExit && m_systrayIcon && goToSystrayOnExit && !this->isHidden()) if (!m_forceExit && m_systrayIcon && goToSystrayOnExit && !this->isHidden())
{ {
e->ignore(); e->ignore();
QTimer::singleShot(0, this, &QWidget::hide); QMetaObject::invokeMethod(this, &QWidget::hide, Qt::QueuedConnection);
if (!pref->closeToTrayNotified()) 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.")); 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!"); qDebug("Minimize to Tray enabled, hiding!");
e->ignore(); e->ignore();
QTimer::singleShot(0, this, &QWidget::hide); QMetaObject::invokeMethod(this, &QWidget::hide, Qt::QueuedConnection);
if (!pref->minimizeToTrayNotified()) 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.")); showNotificationBalloon(tr("qBittorrent is minimized to tray"), tr("This behavior can be changed in the settings. You won't be reminded again."));