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/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/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