Browse Source

Don't let "program update" dialog steal focus

And also avoid creating an unnecessary event loop.
Closes #14250.
adaptive-webui-19844
Chocobo1 4 years ago
parent
commit
44e4dd3700
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 56
      src/gui/mainwindow.cpp
  2. 2
      src/gui/mainwindow.h

56
src/gui/mainwindow.cpp

@ -1897,35 +1897,57 @@ void MainWindow::on_actionDownloadFromURL_triggered()
} }
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS) #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
void MainWindow::handleUpdateCheckFinished(bool updateAvailable, QString newVersion, bool invokedByUser) void MainWindow::handleUpdateCheckFinished(const bool updateAvailable, const QString &newVersion, const bool invokedByUser)
{ {
QMessageBox::StandardButton answer = QMessageBox::Yes; m_ui->actionCheckForUpdates->setEnabled(true);
m_ui->actionCheckForUpdates->setText(tr("&Check for Updates"));
m_ui->actionCheckForUpdates->setToolTip(tr("Check for program updates"));
QObject *signalSender = sender();
if (updateAvailable) if (updateAvailable)
{ {
answer = QMessageBox::question(this, tr("qBittorrent Update Available") const QString msg {tr("A new version is available.") + "<br/>"
, tr("A new version is available.") + "<br/>"
+ tr("Do you want to download %1?").arg(newVersion) + "<br/><br/>" + tr("Do you want to download %1?").arg(newVersion) + "<br/><br/>"
+ QString::fromLatin1("<a href=\"https://www.qbittorrent.org/news.php\">%1</a>").arg(tr("Open changelog...")) + QString::fromLatin1("<a href=\"https://www.qbittorrent.org/news.php\">%1</a>").arg(tr("Open changelog..."))};
, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); auto *msgBox = new QMessageBox {QMessageBox::Question, tr("qBittorrent Update Available"), msg
if (answer == QMessageBox::Yes) , (QMessageBox::Yes | QMessageBox::No), this};
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setAttribute(Qt::WA_ShowWithoutActivating);
msgBox->setDefaultButton(QMessageBox::Yes);
connect(msgBox, &QMessageBox::buttonClicked, this, [this, msgBox, signalSender](QAbstractButton *button)
{
if (msgBox->buttonRole(button) == QMessageBox::YesRole)
{ {
// The user want to update, let's download the update // The user want to update, let's download the update
ProgramUpdater *updater = dynamic_cast<ProgramUpdater * >(sender()); auto *updater = dynamic_cast<ProgramUpdater *>(signalSender);
updater->updateProgram(); updater->updateProgram();
} }
else
{
if (Preferences::instance()->isUpdateCheckEnabled())
m_programUpdateTimer->start();
}
signalSender->deleteLater();
});
msgBox->open();
} }
else if (invokedByUser) else if (invokedByUser)
{ {
QMessageBox::information(this, QLatin1String("qBittorrent"), auto *msgBox = new QMessageBox {QMessageBox::Information, QLatin1String("qBittorrent")
tr("No updates available.\nYou are already using the latest version.")); , tr("No updates available.\nYou are already using the latest version.")
} , QMessageBox::Ok, this};
sender()->deleteLater(); msgBox->setAttribute(Qt::WA_DeleteOnClose);
m_ui->actionCheckForUpdates->setEnabled(true); connect(msgBox, &QDialog::finished, this, [this, signalSender](const int)
m_ui->actionCheckForUpdates->setText(tr("&Check for Updates")); {
m_ui->actionCheckForUpdates->setToolTip(tr("Check for program updates")); if (Preferences::instance()->isUpdateCheckEnabled())
// Don't bother the user again in this session if he chose to ignore the update
if (Preferences::instance()->isUpdateCheckEnabled() && (answer == QMessageBox::Yes))
m_programUpdateTimer->start(); m_programUpdateTimer->start();
signalSender->deleteLater();
});
msgBox->open();
}
} }
#endif #endif

2
src/gui/mainwindow.h

@ -135,7 +135,7 @@ private slots:
void askRecursiveTorrentDownloadConfirmation(BitTorrent::Torrent *const torrent); void askRecursiveTorrentDownloadConfirmation(BitTorrent::Torrent *const torrent);
void optionsSaved(); void optionsSaved();
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS) #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
void handleUpdateCheckFinished(bool updateAvailable, QString newVersion, bool invokedByUser); void handleUpdateCheckFinished(bool updateAvailable, const QString &newVersion, bool invokedByUser);
#endif #endif
void toggleAlternativeSpeeds(); void toggleAlternativeSpeeds();

Loading…
Cancel
Save