diff options
Diffstat (limited to 'utils/rbutilqt/rbutilqt.cpp')
-rw-r--r-- | utils/rbutilqt/rbutilqt.cpp | 76 |
1 files changed, 56 insertions, 20 deletions
diff --git a/utils/rbutilqt/rbutilqt.cpp b/utils/rbutilqt/rbutilqt.cpp index aa405418be..f5872f268e 100644 --- a/utils/rbutilqt/rbutilqt.cpp +++ b/utils/rbutilqt/rbutilqt.cpp @@ -88,6 +88,7 @@ RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent) ui.setupUi(this); QIcon windowIcon(":/icons/rockbox-clef.svg"); this->setWindowIcon(windowIcon); + ui.logoLabel->load(QLatin1String(":/icons/rockbox-logo.svg")); #if defined(Q_OS_MACX) // don't translate menu entries that are handled specially on OS X // (Configure, Quit). Qt handles them for us if they use english string. @@ -204,6 +205,7 @@ void RbUtilQt::downloadInfo() // try to get the current build information daily = new HttpGet(this); connect(daily, &HttpGet::done, this, &RbUtilQt::downloadDone); + connect(daily, &HttpGet::sslError, this, &RbUtilQt::sslError); connect(qApp, &QGuiApplication::lastWindowClosed, daily, &HttpGet::abort); daily->setCache(false); ui.statusbar->showMessage(tr("Downloading build information, please wait ...")); @@ -212,10 +214,49 @@ void RbUtilQt::downloadInfo() daily->getFile(QUrl(PlayerBuildInfo::instance()->value(PlayerBuildInfo::BuildInfoUrl).toString())); } +void RbUtilQt::sslError(const QSslError& error, const QSslCertificate& peerCert) +{ + LOG_WARNING() << "sslError" << (int)error.error(); + // On Rockbox Utility start we always try to get the build info first. + // Thus we can use that to catch potential certificate errors. + // If the user accepts the certificate we'll have HttpGet ignore all cert + // errors for the exact certificate we got during this first request. + // Thus we don't need to handle cert errors later anymore. + if (error.error() == QSslError::UnableToGetLocalIssuerCertificate) { + QMessageBox mb(this); + mb.setWindowTitle(tr("Certificate error")); + mb.setIcon(QMessageBox::Warning); + mb.setText(tr("%1\n\n" + "Issuer: %2\n" + "Subject: %3\n" + "Valid since: %4\n" + "Valid until: %5\n\n" + "Temporarily trust certificate?") + .arg(error.errorString()) + .arg(peerCert.issuerInfo(QSslCertificate::Organization).at(0)) + .arg(peerCert.subjectDisplayName()) + .arg(peerCert.effectiveDate().toString()) + .arg(peerCert.expiryDate().toString()) + ); + mb.setDetailedText(peerCert.toText()); + mb.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + + auto r = mb.exec(); + if (r == QMessageBox::Yes) { + HttpGet::addTrustedPeerCert(peerCert); + downloadInfo(); + } + else { + downloadDone(QNetworkReply::OperationCanceledError); + } + } +} -void RbUtilQt::downloadDone(bool error) + +void RbUtilQt::downloadDone(QNetworkReply::NetworkError error) { - if(error) { + if(error != QNetworkReply::NoError + && error != QNetworkReply::SslHandshakeFailedError) { LOG_INFO() << "network error:" << daily->errorString(); ui.statusbar->showMessage(tr("Can't get version information!")); QMessageBox::critical(this, tr("Network error"), @@ -366,10 +407,10 @@ void RbUtilQt::updateDevice() playerBuildInfo->value(PlayerBuildInfo::BootloaderMethod).toString()); /* Disable uninstallation actions if they are not supported. */ - bool bootloaderUninstallable = !(bootloaderCapabilities & BootloaderInstallBase::Uninstall); - ui.labelRemoveBootloader->setEnabled(bootloaderUninstallable); - ui.buttonRemoveBootloader->setEnabled(bootloaderUninstallable); - ui.actionRemove_bootloader->setEnabled(bootloaderUninstallable); + bool canUninstall = (bootloaderCapabilities & BootloaderInstallBase::Uninstall); + ui.labelRemoveBootloader->setEnabled(canUninstall); + ui.buttonRemoveBootloader->setEnabled(canUninstall); + ui.actionRemove_bootloader->setEnabled(canUninstall); /* Disable the whole tab widget if configuration is invalid */ bool configurationValid = !chkConfig(nullptr); @@ -466,13 +507,9 @@ void RbUtilQt::uninstallBootloader(void) logger->setFinished(); return; } - QStringList blfile = PlayerBuildInfo::instance()->value(PlayerBuildInfo::BootloaderFile).toStringList(); - QStringList blfilepath; - for(int a = 0; a < blfile.size(); a++) { - blfilepath.append(RbSettings::value(RbSettings::Mountpoint).toString() - + blfile.at(a)); - } - bl->setBlFile(blfilepath); + QStringList blfile = PlayerBuildInfo::instance()->value( + PlayerBuildInfo::BootloaderFile).toStringList(); + bl->setBlFile(RbSettings::value(RbSettings::Mountpoint).toString(), blfile); bl->setLogfile(RbSettings::value(RbSettings::Mountpoint).toString() + "/.rockbox/rbutil.log"); @@ -608,21 +645,20 @@ void RbUtilQt::checkUpdate(void) update->getFile(QUrl(url)); } -void RbUtilQt::downloadUpdateDone(bool error) +void RbUtilQt::downloadUpdateDone(QNetworkReply::NetworkError error) { - if(error) { + if(error != QNetworkReply::NoError) { LOG_INFO() << "network error:" << update->errorString(); } else { QString toParse(update->readAll()); - QRegExp searchString("<a[^>]*>([a-zA-Z]+[^<]*)</a>"); + QRegularExpression searchString("<a[^>]*>([a-zA-Z]+[^<]*)</a>"); QStringList rbutilList; - int pos = 0; - while ((pos = searchString.indexIn(toParse, pos)) != -1) + auto it = searchString.globalMatch(toParse); + while (it.hasNext()) { - rbutilList << searchString.cap(1); - pos += searchString.matchedLength(); + rbutilList << it.next().captured(1); } LOG_INFO() << "Checking for update"; |