From 111c84a27bed5b097aaefad413dd2d79bcbf8a4c Mon Sep 17 00:00:00 2001 From: Jan Grulich Date: Tue, 1 Oct 2024 10:43:59 +0200 Subject: [PATCH] Remove unused code --- src/app/CMakeLists.txt | 2 - src/app/downloadmanager.cpp | 8 +++ src/app/downloadmanager.h | 1 + src/app/main.cpp | 18 +----- src/app/qml/DownloadPage.qml | 54 +++++++++++++--- src/app/qml/Units.qml | 1 + src/app/releasemanager.h | 5 +- src/app/units.cpp | 117 ----------------------------------- src/app/units.h | 62 ------------------- src/app/versionchecker.cpp | 99 ----------------------------- src/app/versionchecker.h | 53 ---------------- 11 files changed, 60 insertions(+), 360 deletions(-) delete mode 100644 src/app/units.cpp delete mode 100644 src/app/units.h delete mode 100644 src/app/versionchecker.cpp delete mode 100644 src/app/versionchecker.h diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 01499197..75fdf759 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -12,9 +12,7 @@ set(MEDIAWRITER_SRCS notifications.cpp portalfiledialog.cpp releasemanager.cpp - units.cpp utilities.cpp - versionchecker.cpp ) if (UNIX AND NOT APPLE) diff --git a/src/app/downloadmanager.cpp b/src/app/downloadmanager.cpp index c79ed368..e1f393c8 100644 --- a/src/app/downloadmanager.cpp +++ b/src/app/downloadmanager.cpp @@ -137,6 +137,14 @@ void DownloadManager::cancel() } } +void DownloadManager::stopDownload() +{ + if (m_current) { + m_current->deleteLater(); + mDebug() << this->metaObject()->className() << "Stopping"; + } +} + bool DownloadManager::isDownloaded(const QUrl &url) const { const QString filePath = QString("%1/%2").arg(DownloadManager::dir()).arg(url.fileName()); diff --git a/src/app/downloadmanager.h b/src/app/downloadmanager.h index 7f475159..fa2b223f 100644 --- a/src/app/downloadmanager.h +++ b/src/app/downloadmanager.h @@ -163,6 +163,7 @@ class DownloadManager : public QObject, public DownloadReceiver QNetworkReply *tryAnotherMirror(); Q_INVOKABLE void cancel(); + Q_INVOKABLE void stopDownload(); Q_INVOKABLE bool isDownloaded(const QUrl &url) const; // DownloadReceiver interface diff --git a/src/app/main.cpp b/src/app/main.cpp index 00adc676..e7512088 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -18,23 +18,14 @@ */ #include -#include -#include -#include #include #include -#include -#include -#include #include -#include #include "crashhandler.h" #include "drivemanager.h" #include "portalfiledialog.h" #include "releasemanager.h" -#include "units.h" -#include "versionchecker.h" int main(int argc, char **argv) { @@ -59,7 +50,7 @@ int main(int argc, char **argv) mDebug() << "Application constructed"; QTranslator translator; - if (translator.load(QLocale(QLocale().language(), QLocale().country()), QLatin1String(), QLatin1String(), ":/translations")) + if (translator.load(QLocale(), QLatin1String(), QLatin1String(), ":/translations")) app.installTranslator(&translator); QGuiApplication::setDesktopFileName("org.fedoraproject.MediaWriter.desktop"); @@ -72,13 +63,6 @@ int main(int argc, char **argv) engine.rootContext()->setContextProperty("portalFileDialog", new PortalFileDialog(&app)); engine.rootContext()->setContextProperty("mediawriterVersion", MEDIAWRITER_VERSION); engine.rootContext()->setContextProperty("releases", new ReleaseManager()); - engine.rootContext()->setContextProperty("units", Units::instance()); - engine.rootContext()->setContextProperty("versionChecker", new VersionChecker()); -#if (defined(__linux) || defined(_WIN32)) - engine.rootContext()->setContextProperty("platformSupportsDelayedWriting", true); -#else - engine.rootContext()->setContextProperty("platformSupportsDelayedWriting", false); -#endif mDebug() << "Loading the QML source code"; diff --git a/src/app/qml/DownloadPage.qml b/src/app/qml/DownloadPage.qml index bb2831d1..24b5bb83 100644 --- a/src/app/qml/DownloadPage.qml +++ b/src/app/qml/DownloadPage.qml @@ -42,6 +42,8 @@ Page { qsTr("Preparing %1").arg(file) else if (currentStatus === Units.DownloadStatus.Ready) qsTr("Ready to write %1").arg(file) + else if (currentStatus === Units.DownloadStatus.Stopped) + qsTr("%1 has been stopped").arg(file) else if (currentStatus == Units.DownloadStatus.Failed_Download) qsTr("Failed to download %1").arg(file) else @@ -78,12 +80,12 @@ Page { } QQC2.Label { - visible: currentStatus == Units.DownloadStatus.Downloading + visible: currentStatus == Units.DownloadStatus.Downloading || currentStatus == Units.DownloadStatus.Stopped text: downloadPage.leftStr } QQC2.Label { - visible: currentStatus == Units.DownloadStatus.Downloading + visible: currentStatus == Units.DownloadStatus.Downloading || currentStatus == Units.DownloadStatus.Stopped text: downloadPage.rightStr } } @@ -135,6 +137,14 @@ Page { wrapMode: QQC2.Label.Wrap } + QQC2.Label { + id: messageContinueDownload + visible: currentStatus === Units.DownloadStatus.Stopped + text: qsTr("Download has been stopped.") + wrapMode: Label.Wrap + width: mainColumn.width + } + QQC2.Label { id: messageSelectedImage visible: releases.selected.isLocal @@ -228,19 +238,37 @@ Page { releases.variant } } + }, + State { + name: "stopped" + when: currentStatus === Units.DownloadStatus.Stopped + PropertyChanges { + target: progressBar; + value: releases.variant.progress.ratio + } + PropertyChanges { + target: messageContinueDownload; + visible: true + } } ] - // There will be only [Finish] button on the right side so [Cancel] button - // is not necessary previousButtonVisible: currentStatus != Units.DownloadStatus.Finished - previousButtonText: qsTr("Cancel") + previousButtonText: { + if (releases.variant.status === Units.DownloadStatus.Downloading) + return qsTr("Pause") + else + return qsTr("Cancel") + } onPreviousButtonClicked: { if (releases.variant.status === Units.DownloadStatus.Write_Verifying || releases.variant.status === Units.DownloadStatus.Writing || - releases.variant.status === Units.DownloadStatus.Downloading || + releases.variant.status === Units.DownloadStatus.Stopped || releases.variant.status === Units.DownloadStatus.Download_Verifying) { cancelDialog.show() + } else if (releases.variant.status === Units.DownloadStatus.Downloading) { + downloadManager.stopDownload() + releases.variant.setStatus(Units.DownloadStatus.Stopped) } else { releases.variant.resetStatus() downloadManager.cancel() @@ -249,7 +277,9 @@ Page { } nextButtonVisible: { - if (currentStatus == Units.DownloadStatus.Finished) + // This will be [Finish] or [Resume] button to finish download or resume download + if (currentStatus == Units.DownloadStatus.Finished || + currentStatus == Units.DownloadStatus.Stopped) return true // This will be [Retry] button to start the process again if there is a drive plugged in else if (currentStatus == Units.DownloadStatus.Ready || @@ -260,7 +290,6 @@ Page { return false } nextButtonText: { - if (releases.variant.status === Units.DownloadStatus.Write_Verifying || releases.variant.status === Units.DownloadStatus.Writing || releases.variant.status === Units.DownloadStatus.Downloading || @@ -268,6 +297,8 @@ Page { return qsTr("Cancel") else if (releases.variant.status == Units.DownloadStatus.Ready) return qsTr("Write") + else if (releases.variant.status === Units.DownloadStatus.Stopped) + return qsTr("Resume") else if (releases.variant.status === Units.DownloadStatus.Finished) return qsTr("Finish") else @@ -288,6 +319,13 @@ Page { releases.variant.download() drives.selected.setImage(releases.variant) drives.selected.write(releases.variant) + } else if (releases.variant.status === Units.DownloadStatus.Stopped) { + if (selectedOption != Units.MainSelect.Write) + releases.variant.download() + if (drives.length) { + drives.selected.setImage(releases.variant) + drives.selected.write(releases.variant) + } } } } diff --git a/src/app/qml/Units.qml b/src/app/qml/Units.qml index 512fd1f9..4cc474b8 100644 --- a/src/app/qml/Units.qml +++ b/src/app/qml/Units.qml @@ -58,6 +58,7 @@ QtObject { Downloading, Download_Verifying, Ready, + Stopped, Writing_Not_Possible, Writing, Write_Verifying, diff --git a/src/app/releasemanager.h b/src/app/releasemanager.h index e85bfd40..100daeec 100644 --- a/src/app/releasemanager.h +++ b/src/app/releasemanager.h @@ -373,12 +373,13 @@ class ReleaseVariant : public QObject, public DownloadReceiver public: enum Type { LIVE = 0, NETINSTALL, FULL, ATOMIC }; Q_ENUMS(Type) - enum Status { PREPARING = 0, DOWNLOADING, DOWNLOAD_VERIFYING, READY, WRITING_NOT_POSSIBLE, WRITING, WRITE_VERIFYING, FINISHED, FAILED_VERIFICATION, FAILED_DOWNLOAD, FAILED }; + enum Status { PREPARING = 0, DOWNLOADING, DOWNLOAD_VERIFYING, READY, STOPPED, WRITING_NOT_POSSIBLE, WRITING, WRITE_VERIFYING, FINISHED, FAILED_VERIFICATION, FAILED_DOWNLOAD, FAILED }; Q_ENUMS(Status) const QStringList m_statusStrings{tr("Preparing"), tr("Downloading"), tr("Checking the download"), tr("Ready to write"), + tr("Download has been stopped"), tr("Image file was saved to your downloads folder. Writing is not possible"), tr("Writing"), tr("Checking the written data"), @@ -414,7 +415,6 @@ class ReleaseVariant : public QObject, public DownloadReceiver Status status() const; QString statusString() const; - void setStatus(Status s); QString errorString() const; void setErrorString(const QString &o); @@ -439,6 +439,7 @@ class ReleaseVariant : public QObject, public DownloadReceiver public slots: void download(); void resetStatus(); + void setStatus(Status s); private: QString m_temporaryIso{}; diff --git a/src/app/units.cpp b/src/app/units.cpp deleted file mode 100644 index 455da2e8..00000000 --- a/src/app/units.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Fedora Media Writer - * Copyright 2013 Marco Martin - * Copyright 2014 Sebastian Kügler - * Copyright 2014 David Edmundson - * Copyright (C) 2020 Jan Grulich - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "units.h" - -#include -#include -#include - -Units *Units::_self = nullptr; - -Units::Units(QObject *parent) - : QObject(parent) - , m_devicePixelRatio(-1) - , m_gridUnit(-1) - , m_smallSpacing(-1) - , m_largeSpacing(-1) -{ - update(); - updateDevicePixelRatio(); -} - -Units *Units::instance() -{ - if (!_self) - _self = new Units(); - return _self; -} - -qreal Units::devicePixelRatio() const -{ - return m_devicePixelRatio; -} - -int Units::gridUnit() const -{ - return m_gridUnit; -} - -int Units::smallSpacing() const -{ - return m_smallSpacing; -} - -int Units::largeSpacing() const -{ - return m_largeSpacing; -} - -bool Units::eventFilter(QObject *watched, QEvent *event) -{ - if (watched == QCoreApplication::instance()) { - if (event->type() == QEvent::ApplicationFontChange) { - update(); - } - } - - return QObject::eventFilter(watched, event); -} - -void Units::update() -{ - int gridUnit = QFontMetrics(QGuiApplication::font()).boundingRect(QStringLiteral("M")).height(); - - if (gridUnit % 2 != 0) { - gridUnit++; - } - - if (gridUnit != m_gridUnit) { - m_gridUnit = gridUnit; - Q_EMIT gridUnitChanged(); - } - - if (gridUnit != m_largeSpacing) { - m_smallSpacing = qMax(2, (int)(gridUnit / 4)); // 1/4 of gridUnit, at least 2 - m_largeSpacing = m_smallSpacing * 2; - Q_EMIT spacingChanged(); - } -} - -void Units::updateDevicePixelRatio() -{ - // Using QGuiApplication::devicePixelRatio() gives too coarse values, - // i.e. it directly jumps from 1.0 to 2.0. We want tighter control on - // sizing, so we compute the exact ratio and use that. - // TODO: make it possible to adapt to the dpi for the current screen dpi - // instead of assuming that all of them use the same dpi which applies for - // X11 but not for other systems. - QScreen *primary = QGuiApplication::primaryScreen(); - if (!primary) { - return; - } - const qreal dpi = primary->logicalDotsPerInchX(); - // Usual "default" is 96 dpi - // that magic ratio follows the definition of "device independent pixel" by Microsoft - m_devicePixelRatio = (qreal)dpi / (qreal)96; - emit devicePixelRatioChanged(); -} diff --git a/src/app/units.h b/src/app/units.h deleted file mode 100644 index 2f1e2f79..00000000 --- a/src/app/units.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Fedora Media Writer - * Copyright (C) 2020 Jan Grulich - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef UNITS_H -#define UNITS_H - -#include - -class Units : public QObject -{ - Q_OBJECT - Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio NOTIFY devicePixelRatioChanged) - Q_PROPERTY(int gridUnit READ gridUnit NOTIFY gridUnitChanged) - Q_PROPERTY(int smallSpacing READ smallSpacing NOTIFY spacingChanged) - Q_PROPERTY(int largeSpacing READ largeSpacing NOTIFY spacingChanged) -public: - explicit Units(QObject *parent = nullptr); - ~Units() override = default; - - static Units *instance(); - - qreal devicePixelRatio() const; - int gridUnit() const; - int smallSpacing() const; - int largeSpacing() const; -Q_SIGNALS: - void devicePixelRatioChanged(); - void gridUnitChanged(); - void spacingChanged(); - -protected: - bool eventFilter(QObject *watched, QEvent *event) override; - -private: - void update(); - void updateDevicePixelRatio(); - - static Units *_self; - - qreal m_devicePixelRatio; - int m_gridUnit; - int m_smallSpacing; - int m_largeSpacing; -}; - -#endif // UNITS_H diff --git a/src/app/versionchecker.cpp b/src/app/versionchecker.cpp deleted file mode 100644 index e2d1e3ab..00000000 --- a/src/app/versionchecker.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Fedora Media Writer - * Copyright (C) 2017 Martin Bříza - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "versionchecker.h" - -#include -#include - -VersionChecker::VersionChecker(QObject *parent) - : QObject(parent) -{ -#if defined(__APPLE__) || defined(_WIN32) - mDebug() << this->metaObject()->className() << "Asking for new FMW version information"; - DownloadManager::instance()->fetchPageAsync(this, "https://getfedora.org/static/fmw-version.json"); -#else - mDebug() << this->metaObject()->className() << "This platform doesn't need to ask about new FMW versions"; -#endif -} - -void VersionChecker::onStringDownloaded(const QString &text) -{ - auto doc = QJsonDocument::fromJson(text.toUtf8()); - QJsonObject obj = doc.object(); -#if defined(__APPLE__) - const char *platform = "osx"; -#elif defined(_WIN32) - const char *platform = "win32"; -#else - const char *platform = nullptr; -#endif - mDebug() << this->metaObject()->className() << "Got new FMW version information"; - if (platform) { - QJsonValueRef versionObject = obj[platform].toObject()["version"]; - if (!versionObject.isNull() && !versionObject.isUndefined()) { - QString currentVersion(MEDIAWRITER_VERSION); - QString newVersion = versionObject.toString(); - QString urlStr = obj[platform].toObject()["url"].toString(); - QUrl url(urlStr); - if (isVersionHigher(currentVersion, newVersion) && url.isValid()) { - mDebug() << this->metaObject()->className() << "New FMW version is" << newVersion << "- we're running on" << currentVersion << "which is older."; - m_newerVersion = newVersion; - m_url = url; - emit newerVersionChanged(); - } else { - mDebug() << this->metaObject()->className() << "New FMW version is" << newVersion << "- we're running on" << currentVersion << "which is newer or the same."; - } - } else { - mWarning() << this->metaObject()->className() << "New FMW version information was empty for this platform"; - } - } else { - mWarning() << this->metaObject()->className() << "Got an answer to query about new versions despite the fact this platform shouldn't support user updates."; - } -} - -void VersionChecker::onDownloadError(const QString &message) -{ - mWarning() << this->metaObject()->className() << "It was impossible to fetch info about a new FMW version:" << message; -} - -QString VersionChecker::newerVersion() const -{ - return m_newerVersion; -} - -QUrl VersionChecker::url() const -{ - return m_url; -} - -bool VersionChecker::isVersionHigher(QString currentVersion, QString newVersion) -{ - QStringList currentSplit = currentVersion.split("."); - QStringList newSplit = newVersion.split("."); - for (int i = 0; i < newSplit.count(); i++) { - if (currentSplit.count() <= i) - return true; - if (currentSplit[i] < newSplit[i]) - return true; - if (currentSplit[i] > newSplit[i]) - return false; - } - return false; -} diff --git a/src/app/versionchecker.h b/src/app/versionchecker.h deleted file mode 100644 index e7820560..00000000 --- a/src/app/versionchecker.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Fedora Media Writer - * Copyright (C) 2017 Martin Bříza - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef VERSIONCHECKER_H -#define VERSIONCHECKER_H - -#include - -#include "downloadmanager.h" -#include "utilities.h" - -class VersionChecker; - -class VersionChecker : public QObject, protected DownloadReceiver -{ - Q_OBJECT - Q_PROPERTY(QString newerVersion READ newerVersion NOTIFY newerVersionChanged) - Q_PROPERTY(QUrl url READ url NOTIFY newerVersionChanged) -public: - VersionChecker(QObject *parent = nullptr); - void onStringDownloaded(const QString &text) override; - void onDownloadError(const QString &message) override; - - QString newerVersion() const; - QUrl url() const; - -protected: - bool isVersionHigher(QString currentVersion, QString newVersion); -signals: - void newerVersionChanged(); - -private: - QString m_newerVersion{}; - QUrl m_url{}; -}; - -#endif // VERSIONCHECKER_H