From cb2e3d369ef881b9415262f9a23c5d77f05fb0ef Mon Sep 17 00:00:00 2001 From: Malte Langkabel Date: Mon, 22 Nov 2021 13:21:39 +0100 Subject: [PATCH] logic: remove update checking code (#1226) Removed because we are not planning to release any further versions of this software. --- src/lib/CMakeLists.txt | 1 - src/lib/app/Application.cpp | 23 -- src/lib/app/Application.h | 4 - src/lib/app/UpdateChecker.h | 11 - src/lib/component/NetworkFactory.h | 1 - src/lib/settings/ApplicationSettings.cpp | 116 ++------- src/lib/settings/ApplicationSettings.h | 21 -- src/lib_gui/CMakeLists.txt | 6 - .../qt/element/dialog/QtNewsWidget.cpp | 231 ------------------ src/lib_gui/qt/element/dialog/QtNewsWidget.h | 32 --- .../element/dialog/QtUpdateCheckerWidget.cpp | 109 --------- .../qt/element/dialog/QtUpdateCheckerWidget.h | 30 --- src/lib_gui/qt/network/QtNetworkFactory.cpp | 6 - src/lib_gui/qt/network/QtNetworkFactory.h | 1 - src/lib_gui/qt/network/QtUpdateChecker.cpp | 179 -------------- src/lib_gui/qt/network/QtUpdateChecker.h | 27 -- .../QtProjectWizardContentPreferences.cpp | 42 +--- .../QtProjectWizardContentPreferences.h | 2 - src/lib_gui/qt/window/QtStartScreen.cpp | 57 ++--- 19 files changed, 51 insertions(+), 848 deletions(-) delete mode 100644 src/lib/app/UpdateChecker.h delete mode 100644 src/lib_gui/qt/element/dialog/QtNewsWidget.cpp delete mode 100644 src/lib_gui/qt/element/dialog/QtNewsWidget.h delete mode 100644 src/lib_gui/qt/element/dialog/QtUpdateCheckerWidget.cpp delete mode 100644 src/lib_gui/qt/element/dialog/QtUpdateCheckerWidget.h delete mode 100644 src/lib_gui/qt/network/QtUpdateChecker.cpp delete mode 100644 src/lib_gui/qt/network/QtUpdateChecker.h diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index e9e4bb1f..6ab97446 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -14,7 +14,6 @@ add_files( app/LanguagePackage.h app/LanguagePackageManager.cpp app/LanguagePackageManager.h - app/UpdateChecker.h component/controller/helper/ActivationListener.cpp component/controller/helper/ActivationListener.h diff --git a/src/lib/app/Application.cpp b/src/lib/app/Application.cpp index 08dddb39..b5d05d3b 100644 --- a/src/lib/app/Application.cpp +++ b/src/lib/app/Application.cpp @@ -23,7 +23,6 @@ #include "TabId.h" #include "TaskManager.h" #include "TaskScheduler.h" -#include "UpdateChecker.h" #include "UserPaths.h" #include "Version.h" #include "ViewFactory.h" @@ -76,8 +75,6 @@ void Application::createInstance( s_instance->m_ideCommunicationController = networkFactory->createIDECommunicationController( s_instance->m_storageCache.get()); s_instance->m_ideCommunicationController->startListening(); - - s_instance->m_updateChecker = networkFactory->createUpdateChecker(); } s_instance->startMessagingAndScheduling(); @@ -371,19 +368,6 @@ void Application::handleMessage(MessageSwitchColorScheme* message) MessageRefreshUI().noStyleReload().dispatch(); } -void Application::handleMessage(MessageWindowFocus* message) -{ - if (!message->focusIn) - { - return; - } - - if (m_project && ApplicationSettings::getInstance()->getAutomaticUpdateCheck()) - { - m_updateChecker->checkUpdate(); - } -} - void Application::startMessagingAndScheduling() { TaskManager::getScheduler(TabId::app())->startSchedulerLoopThreaded(); @@ -409,13 +393,6 @@ void Application::loadWindow(bool showStartWindow) { ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); - // delay first update check by 24 hours at first launch - if (!appSettings->getLastUpdateCheck().isValid()) - { - appSettings->setLastUpdateCheck(TimeStamp::now()); - appSettings->save(); - } - updateTitle(); m_mainView->loadWindow(showStartWindow); diff --git a/src/lib/app/Application.h b/src/lib/app/Application.h index 7422a559..9c0151c4 100644 --- a/src/lib/app/Application.h +++ b/src/lib/app/Application.h @@ -12,7 +12,6 @@ #include "MessageRefresh.h" #include "MessageRefreshUI.h" #include "MessageSwitchColorScheme.h" -#include "MessageWindowFocus.h" #include "Project.h" class Bookmark; @@ -32,7 +31,6 @@ class Application , public MessageListener , public MessageListener , public MessageListener - , public MessageListener { public: static void createInstance( @@ -73,7 +71,6 @@ private: void handleMessage(MessageRefresh* message) override; void handleMessage(MessageRefreshUI* message) override; void handleMessage(MessageSwitchColorScheme* message) override; - void handleMessage(MessageWindowFocus* message) override; void startMessagingAndScheduling(); @@ -97,7 +94,6 @@ private: std::shared_ptr m_mainView; std::shared_ptr m_ideCommunicationController; - std::shared_ptr m_updateChecker; }; #endif // APPLICATION_H diff --git a/src/lib/app/UpdateChecker.h b/src/lib/app/UpdateChecker.h deleted file mode 100644 index 21500f9d..00000000 --- a/src/lib/app/UpdateChecker.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef UPDATE_CHECKER_H -#define UPDATE_CHECKER_H - -class UpdateChecker -{ -public: - virtual ~UpdateChecker() = default; - virtual void checkUpdate() = 0; -}; - -#endif // UPDATE_CHECKER_H diff --git a/src/lib/component/NetworkFactory.h b/src/lib/component/NetworkFactory.h index 8c3424c8..873c928f 100644 --- a/src/lib/component/NetworkFactory.h +++ b/src/lib/component/NetworkFactory.h @@ -15,7 +15,6 @@ public: virtual std::shared_ptr createIDECommunicationController( StorageAccess* storageAccess) const = 0; - virtual std::shared_ptr createUpdateChecker() const = 0; }; #endif // NETWORK_FACTORY_H diff --git a/src/lib/settings/ApplicationSettings.cpp b/src/lib/settings/ApplicationSettings.cpp index 2e652afb..1a9e2fdc 100644 --- a/src/lib/settings/ApplicationSettings.cpp +++ b/src/lib/settings/ApplicationSettings.cpp @@ -58,7 +58,8 @@ bool ApplicationSettings::load(const FilePath& filePath, bool readOnly) migrator.addMigration( 4, std::make_shared( - [](const SettingsMigration* migration, Settings* settings) { + [](const SettingsMigration* migration, Settings* settings) + { std::wstring colorSchemePathString = migration->getValueFromSettings( settings, "application/color_scheme", L""); if (!colorSchemePathString.empty()) @@ -72,29 +73,31 @@ bool ApplicationSettings::load(const FilePath& filePath, bool readOnly) })); migrator.addMigration( 7, - std::make_shared([](const SettingsMigration* migration, - Settings* settings) { - std::vector recentProjects; - recentProjects.push_back("./projects/tictactoe_py/tictactoe_py.srctrlprj"); - utility::append( - recentProjects, - migration->getValuesFromSettings( - settings, "user/recent_projects/recent_project", std::vector())); - - for (size_t i = 0; i < recentProjects.size(); i++) + std::make_shared( + [](const SettingsMigration* migration, Settings* settings) { - if (recentProjects[i] == "./projects/tictactoe/tictactoe.srctrlprj") + std::vector recentProjects; + recentProjects.push_back("./projects/tictactoe_py/tictactoe_py.srctrlprj"); + utility::append( + recentProjects, + migration->getValuesFromSettings( + settings, "user/recent_projects/recent_project", std::vector())); + + for (size_t i = 0; i < recentProjects.size(); i++) { - recentProjects[i] = "./projects/tictactoe_cpp/tictactoe_cpp.srctrlprj"; + if (recentProjects[i] == "./projects/tictactoe/tictactoe.srctrlprj") + { + recentProjects[i] = "./projects/tictactoe_cpp/tictactoe_cpp.srctrlprj"; + } } - } - migration->setValuesInSettings( - settings, "user/recent_projects/recent_project", recentProjects); - })); + migration->setValuesInSettings( + settings, "user/recent_projects/recent_project", recentProjects); + })); migrator.addMigration( 8, std::make_shared( - [](const SettingsMigration* migration, Settings* settings) { + [](const SettingsMigration* migration, Settings* settings) + { std::vector cxxHeaderSearchPaths = migration->getValuesFromSettings( settings, "indexing/cxx/header_search_paths/header_search_path", @@ -582,83 +585,6 @@ bool ApplicationSettings::setRecentProjects(const std::vector& recentP return setPathValues("user/recent_projects/recent_project", recentProjects); } -std::string ApplicationSettings::getUserToken() const -{ - return getValue("user/token", ""); -} - -void ApplicationSettings::setUserToken(std::string token) -{ - setValue("user/token", token); -} - -bool ApplicationSettings::getAutomaticUpdateCheck() const -{ - return getValue("user/update_check/automatic", true); -} - -void ApplicationSettings::setAutomaticUpdateCheck(bool automaticUpdates) -{ - setValue("user/update_check/automatic", automaticUpdates); -} - -TimeStamp ApplicationSettings::getLastUpdateCheck() const -{ - return TimeStamp(getValue("user/update_check/time_stamp", "")); -} - -void ApplicationSettings::setLastUpdateCheck(const TimeStamp& time) -{ - setValue("user/update_check/time_stamp", time.toString()); -} - -Version ApplicationSettings::getSkipUpdateForVersion() const -{ - return Version::fromString(getValue("user/update_check/skip_version", "2017.1.0")); -} - -void ApplicationSettings::setSkipUpdateForVersion(const Version& version) -{ - if (version.isValid()) - { - setValue("user/update_check/skip_version", version.toDisplayString()); - } -} - -std::string ApplicationSettings::getUpdateDownloadUrl() const -{ - return getValue("user/update_check/update_url", ""); -} - -void ApplicationSettings::setUpdateDownloadUrl(const std::string& url) -{ - setValue("user/update_check/update_url", url); -} - -Version ApplicationSettings::getUpdateVersion() const -{ - return Version::fromString( - getValue("user/update_check/update_version", "2017.1.0")); -} - -std::string ApplicationSettings::getUpdateNews() const -{ - return getValue("user/update_check/news", ""); -} - -void ApplicationSettings::setUpdateNews(const std::string& news) -{ - setValue("user/update_check/news", news); -} - -void ApplicationSettings::setUpdateVersion(const Version& version) -{ - if (version.isValid()) - { - setValue("user/update_check/update_version", version.toDisplayString()); - } -} - bool ApplicationSettings::getSeenErrorHelpMessage() const { return getValue("user/seen_error_help_message", false); diff --git a/src/lib/settings/ApplicationSettings.h b/src/lib/settings/ApplicationSettings.h index 4cc4d654..ccb422b0 100644 --- a/src/lib/settings/ApplicationSettings.h +++ b/src/lib/settings/ApplicationSettings.h @@ -154,27 +154,6 @@ public: std::vector getRecentProjects() const; bool setRecentProjects(const std::vector& recentProjects); - std::string getUserToken() const; - void setUserToken(std::string token); - - bool getAutomaticUpdateCheck() const; - void setAutomaticUpdateCheck(bool automaticUpdates); - - TimeStamp getLastUpdateCheck() const; - void setLastUpdateCheck(const TimeStamp& time); - - Version getSkipUpdateForVersion() const; - void setSkipUpdateForVersion(const Version& version); - - std::string getUpdateDownloadUrl() const; - void setUpdateDownloadUrl(const std::string& url); - - Version getUpdateVersion() const; - void setUpdateVersion(const Version& version); - - std::string getUpdateNews() const; - void setUpdateNews(const std::string& news); - bool getSeenErrorHelpMessage() const; void setSeenErrorHelpMessage(bool seen); diff --git a/src/lib_gui/CMakeLists.txt b/src/lib_gui/CMakeLists.txt index f5689b93..b17c9ac3 100644 --- a/src/lib_gui/CMakeLists.txt +++ b/src/lib_gui/CMakeLists.txt @@ -68,8 +68,6 @@ add_files( qt/element/dialog/QtListBoxItem.h qt/element/dialog/QtLocationPicker.cpp qt/element/dialog/QtLocationPicker.h - qt/element/dialog/QtNewsWidget.cpp - qt/element/dialog/QtNewsWidget.h qt/element/dialog/QtPathListBox.cpp qt/element/dialog/QtPathListBox.h qt/element/dialog/QtPathListBoxItem.cpp @@ -82,8 +80,6 @@ add_files( qt/element/dialog/QtStringListBoxItem.h qt/element/dialog/QtTextEdit.cpp qt/element/dialog/QtTextEdit.h - qt/element/dialog/QtUpdateCheckerWidget.cpp - qt/element/dialog/QtUpdateCheckerWidget.h qt/element/QtTooltip.cpp qt/element/QtTooltip.h @@ -146,8 +142,6 @@ add_files( qt/network/QtRequest.h qt/network/QtTcpWrapper.cpp qt/network/QtTcpWrapper.h - qt/network/QtUpdateChecker.cpp - qt/network/QtUpdateChecker.h qt/project_wizard/content/path/QtProjectWizardContentPath.cpp qt/project_wizard/content/path/QtProjectWizardContentPath.h diff --git a/src/lib_gui/qt/element/dialog/QtNewsWidget.cpp b/src/lib_gui/qt/element/dialog/QtNewsWidget.cpp deleted file mode 100644 index 1cc99c5e..00000000 --- a/src/lib_gui/qt/element/dialog/QtNewsWidget.cpp +++ /dev/null @@ -1,231 +0,0 @@ -#include "QtNewsWidget.h" - -#include -#include -#include -#include -#include - -#include "ApplicationSettings.h" -#include "QtTextEdit.h" -#include "TimeStamp.h" -#include "Version.h" -#include "logging.h" -#include "utilityApp.h" - -QtNewsWidget::QtNewsWidget(QWidget* parent): QWidget(parent) -{ - QVBoxLayout* layout = new QVBoxLayout(this); - layout->setContentsMargins(0, 0, 0, 0); - layout->setSpacing(0); - - m_text = new QtTextEdit(); - m_text->setObjectName(QStringLiteral("textField")); - m_text->setReadOnly(true); - m_text->setTabStopDistance(8 * m_text->fontMetrics().boundingRect('9').width()); - m_text->setViewportMargins(6, 4, 16, 4); - m_text->setOpenExternalLinks(true); - layout->addWidget(m_text); - - QString placeholder = QStringLiteral("No news available"); - if (!ApplicationSettings::getInstance()->getAutomaticUpdateCheck()) - { - placeholder += QLatin1String("\n(Enable update check to fetch)"); - } - m_text->setPlaceholderText(placeholder); - - updateNews(); -} - -/* -syntax: -[ - { - // required - "version": 1, - "content": "Hello World!", - - // optional - "conditions": - { - "os": ["windows", "macOS", "linux"], - "min_version": "2017.2.0", - "max_version": "2018.4.2", - "weekday": ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] - } - - // optional - "flags": - { - "important": true - } - } -] -*/ - -void QtNewsWidget::updateNews() -{ - const int supportedNewsItemVersion = 1; - - resetFlags(); - - ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); - const std::string newsRaw = appSettings->getUpdateNews(); - if (!newsRaw.size()) - { - setNews(QLatin1String("")); - return; - } - - if (TimeStamp::now().deltaHours(appSettings->getLastUpdateCheck()) >= 120) - { - LOG_INFO_STREAM(<< "Ignore news string, because older than 5 days."); - setNews(QLatin1String("")); - return; - } - - LOG_INFO_STREAM(<< "Process news string: " << newsRaw); - - QJsonParseError error; - QJsonDocument doc = QJsonDocument::fromJson(QString::fromStdString(newsRaw).toUtf8(), &error); - if (doc.isNull() || !doc.isArray()) - { - LOG_ERROR_STREAM( - << "News string couldn't be parsed as JSON: " << error.errorString().toStdString() - << "\nJSON: " << newsRaw); - setNews(QLatin1String("")); - return; - } - - size_t itemNum = 0; - for (QJsonValueRef value: doc.array()) - { - if (!value.isObject()) - { - continue; - } - - itemNum++; - QJsonObject newsItem = value.toObject(); - - int version = newsItem.value(QStringLiteral("version")).toInt(); - if (version > supportedNewsItemVersion) - { - LOG_INFO_STREAM(<< "News item " << itemNum << " version " << version << " is not supported."); - continue; - } - - if (!checkConditions(newsItem.value(QStringLiteral("conditions")).toObject())) - { - LOG_INFO_STREAM(<< "News item " << itemNum << " conditions failed."); - continue; - } - - processFlags(newsItem.value(QStringLiteral("flags")).toObject()); - setNews(newsItem.value(QStringLiteral("content")).toString()); - return; - } - - setNews(QLatin1String("")); -} - -void QtNewsWidget::resetFlags() -{ - setImportant(false); -} - -void QtNewsWidget::setNews(const QString& news) -{ - m_text->setHtml(news); -} - -void QtNewsWidget::setImportant(bool important) -{ - m_text->setProperty("important", important); - m_text->style()->unpolish(m_text); - m_text->style()->polish(m_text); -} - -bool QtNewsWidget::checkConditions(const QJsonObject& conditions) const -{ - if (conditions.isEmpty()) - { - return true; - } - - // min_version - { - QString minVersionString = conditions.value(QStringLiteral("min_version")).toString(); - if (!minVersionString.isEmpty()) - { - Version minVersion = Version::fromString(minVersionString.toStdString()); - if (minVersion.isValid() && minVersion > Version::getApplicationVersion()) - { - LOG_INFO_STREAM(<< "Failed condition min_version."); - return false; - } - } - } - - // max_version - { - QString maxVersionString = conditions.value(QStringLiteral("max_version")).toString(); - if (!maxVersionString.isEmpty()) - { - Version maxVersion = Version::fromString(maxVersionString.toStdString()); - if (maxVersion.isValid() && maxVersion < Version::getApplicationVersion()) - { - LOG_INFO_STREAM(<< "Failed condition max_version."); - return false; - } - } - } - - // OS - { - QJsonArray osStrings = conditions.value(QStringLiteral("os")).toArray(); - if (!osStrings.isEmpty()) - { - QString osString = QString::fromStdString(utility::getOsTypeString()); - if (!osStrings.contains(QJsonValue(osString))) - { - LOG_INFO_STREAM(<< "Failed condition os."); - return false; - } - } - } - - // weekday - { - QJsonArray weekdayStrings = conditions.value(QStringLiteral("weekday")).toArray(); - if (!weekdayStrings.isEmpty()) - { - QString weekdayString = QString::fromStdString(TimeStamp::now().dayOfWeekShort()); - if (!weekdayStrings.contains(QJsonValue(weekdayString))) - { - LOG_INFO_STREAM(<< "Failed condition weekday."); - return false; - } - } - } - - return true; -} - -void QtNewsWidget::processFlags(const QJsonObject& flags) -{ - if (flags.isEmpty()) - { - return; - } - - // important - { - bool important = flags.value(QStringLiteral("important")).toBool(); - if (important) - { - LOG_INFO_STREAM(<< "Flag important enabled."); - setImportant(true); - } - } -} diff --git a/src/lib_gui/qt/element/dialog/QtNewsWidget.h b/src/lib_gui/qt/element/dialog/QtNewsWidget.h deleted file mode 100644 index 303f57c0..00000000 --- a/src/lib_gui/qt/element/dialog/QtNewsWidget.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef QT_NEWS_WIDGET_H -#define QT_NEWS_WIDGET_H - -#include - -class QtTextEdit; -class QJsonObject; - -class QtNewsWidget: public QWidget -{ - Q_OBJECT - -public: - QtNewsWidget(QWidget* parent = nullptr); - virtual ~QtNewsWidget() = default; - -public slots: - void updateNews(); - -private: - void resetFlags(); - - void setNews(const QString& news); - void setImportant(bool important); - - bool checkConditions(const QJsonObject& conditions) const; - void processFlags(const QJsonObject& flags); - - QtTextEdit* m_text; -}; - -#endif // QT_NEWS_WIDGET_H diff --git a/src/lib_gui/qt/element/dialog/QtUpdateCheckerWidget.cpp b/src/lib_gui/qt/element/dialog/QtUpdateCheckerWidget.cpp deleted file mode 100644 index 50cf3343..00000000 --- a/src/lib_gui/qt/element/dialog/QtUpdateCheckerWidget.cpp +++ /dev/null @@ -1,109 +0,0 @@ -#include "QtUpdateCheckerWidget.h" - -#include -#include -#include -#include -#include - -#include "ApplicationSettings.h" -#include "QtUpdateChecker.h" -#include "TimeStamp.h" - -QtUpdateCheckerWidget::QtUpdateCheckerWidget(QWidget* parent) - : QWidget(parent), m_deleteCheck(std::make_shared(false)) -{ - ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); - - QHBoxLayout* layout = new QHBoxLayout(this); - layout->setContentsMargins(0, 0, 0, 0); - layout->setSpacing(0); - - m_button = new QPushButton(QStringLiteral("check for new version")); - m_button->setObjectName(QStringLiteral("updateButton")); - m_button->setCursor(Qt::PointingHandCursor); - layout->addWidget(m_button); - - if (appSettings->getAutomaticUpdateCheck()) - { - if (QtUpdateChecker::needsAutomaticCheck()) - { - m_button->setText(QStringLiteral("checking for update...")); - m_button->setEnabled(false); - - std::shared_ptr deleteCheck = m_deleteCheck; - - QTimer::singleShot(250, [deleteCheck, this]() { - if (*deleteCheck.get()) - { - return; - } - - checkUpdate(false); - }); - } - else - { - Version version = appSettings->getUpdateVersion(); - QString url = QString::fromStdString(appSettings->getUpdateDownloadUrl()); - if (version > Version::getApplicationVersion() && !url.isEmpty()) - { - setDownloadUrl(url); - } - else - { - m_button->setText(QStringLiteral("up-to-date")); - m_button->setEnabled(false); - } - } - } - else - { - connect(m_button, &QPushButton::clicked, [this]() { checkUpdate(true); }); - } -} - -QtUpdateCheckerWidget::~QtUpdateCheckerWidget() -{ - *m_deleteCheck.get() = true; -} - -void QtUpdateCheckerWidget::checkUpdate(bool force) -{ - m_button->setText(QStringLiteral("checking for update...")); - m_button->setEnabled(false); - - std::shared_ptr deleteCheck = m_deleteCheck; - - QtUpdateChecker::check(force, [deleteCheck, this](const QtUpdateChecker::Result& result) { - if (*deleteCheck.get()) - { - return; - } - - if (!result.success) - { - m_button->setText(QStringLiteral("update check failed")); - } - else if (result.url.isEmpty()) - { - m_button->setText(QStringLiteral("up-to-date")); - } - else - { - setDownloadUrl(result.url); - } - - emit updateReceived(); - }); -} - -void QtUpdateCheckerWidget::setDownloadUrl(const QString& url) -{ - m_button->setText(QStringLiteral("new version available")); - m_button->disconnect(); - connect(m_button, &QPushButton::clicked, this, [url]() { - QDesktopServices::openUrl(QUrl(url, QUrl::TolerantMode)); - }); - m_button->setEnabled(true); -} diff --git a/src/lib_gui/qt/element/dialog/QtUpdateCheckerWidget.h b/src/lib_gui/qt/element/dialog/QtUpdateCheckerWidget.h deleted file mode 100644 index f446a243..00000000 --- a/src/lib_gui/qt/element/dialog/QtUpdateCheckerWidget.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef QT_UPDATE_CHECKER_WIDGET_H -#define QT_UPDATE_CHECKER_WIDGET_H - -#include - -#include - -class QPushButton; - -class QtUpdateCheckerWidget: public QWidget -{ - Q_OBJECT - -public: - QtUpdateCheckerWidget(QWidget* parent = nullptr); - virtual ~QtUpdateCheckerWidget(); - -signals: - void updateReceived(); - -private: - void checkUpdate(bool force); - void setDownloadUrl(const QString& url); - - QPushButton* m_button; - - std::shared_ptr m_deleteCheck; -}; - -#endif // QT_UPDATE_CHECKER_WIDGET_H diff --git a/src/lib_gui/qt/network/QtNetworkFactory.cpp b/src/lib_gui/qt/network/QtNetworkFactory.cpp index 9e13ab92..83bf3e90 100644 --- a/src/lib_gui/qt/network/QtNetworkFactory.cpp +++ b/src/lib_gui/qt/network/QtNetworkFactory.cpp @@ -1,7 +1,6 @@ #include "QtNetworkFactory.h" #include "QtIDECommunicationController.h" -#include "QtUpdateChecker.h" QtNetworkFactory::QtNetworkFactory() {} @@ -12,8 +11,3 @@ std::shared_ptr QtNetworkFactory::createIDECommunica { return std::make_shared(nullptr, storageAccess); } - -std::shared_ptr QtNetworkFactory::createUpdateChecker() const -{ - return std::make_shared(); -} diff --git a/src/lib_gui/qt/network/QtNetworkFactory.h b/src/lib_gui/qt/network/QtNetworkFactory.h index 9497eb1a..ffff793b 100644 --- a/src/lib_gui/qt/network/QtNetworkFactory.h +++ b/src/lib_gui/qt/network/QtNetworkFactory.h @@ -11,7 +11,6 @@ public: virtual std::shared_ptr createIDECommunicationController( StorageAccess* storageAccess) const override; - virtual std::shared_ptr createUpdateChecker() const override; }; #endif // QT_NETWORK_FACTORY_H diff --git a/src/lib_gui/qt/network/QtUpdateChecker.cpp b/src/lib_gui/qt/network/QtUpdateChecker.cpp deleted file mode 100644 index 8a303fb5..00000000 --- a/src/lib_gui/qt/network/QtUpdateChecker.cpp +++ /dev/null @@ -1,179 +0,0 @@ -#include "QtUpdateChecker.h" - -#include -#include -#include -#include -#include - -#include "ApplicationSettings.h" -#include "MessageStatus.h" -#include "QtRequest.h" -#include "TimeStamp.h" -#include "Version.h" -#include "logging.h" -#include "utilityApp.h" -#include "utilityUuid.h" - -bool QtUpdateChecker::needsAutomaticCheck() -{ - ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); - return TimeStamp::now().deltaHours(appSettings->getLastUpdateCheck()) >= 24; -} - -void QtUpdateChecker::check(bool force, std::function callback) -{ - Result result; - - if (!force && !needsAutomaticCheck()) - { - callback(result); - return; - } - - ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); - appSettings->setLastUpdateCheck(TimeStamp::now()); - appSettings->setUpdateVersion(Version::getApplicationVersion()); - appSettings->setUpdateDownloadUrl(""); - appSettings->save(); - - std::string urlString = "https://www.sourcetrail.com/api/v2/versions/latest"; - - // OS - std::string osString = utility::getOsTypeString(); - urlString += "?os=" + osString; - - // architecture - std::string platformString = - (utility::getApplicationArchitectureType() == APPLICATION_ARCHITECTURE_X86_64 ? "64" : "32"); - urlString += "&platform=" + platformString + "bit"; - - // version - // Version::setApplicationVersion(Version::fromString("2017.3.48")); // for debugging - urlString += "&version=" + Version::getApplicationVersion().toDisplayString(); - - // license - urlString += "&license=free"; // options: test, private, commercial - - // user token - std::string token = appSettings->getUserToken(); - if (!token.size()) - { - token = utility::getUuidString(); - appSettings->setUserToken(token); - appSettings->save(); - } - - urlString += "&token=" + token; - - // send request - QtRequest* request = new QtRequest(); - QObject::connect( - request, &QtRequest::receivedData, [force, callback, request](const QByteArray& bytes) { - Result result; - - ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); - bool saveAppSettings = false; - - do - { - QJsonParseError error; - QJsonDocument doc = QJsonDocument::fromJson(bytes, &error); - if (doc.isNull() || !doc.isObject()) - { - LOG_ERROR_STREAM( - << "Update response couldn't be parsed as JSON: " - << error.errorString().toStdString()); - break; - } - - QString news = doc.object().find(QStringLiteral("news"))->toString(); - if (news.toStdString() != appSettings->getUpdateNews()) - { - appSettings->setUpdateNews(news.toStdString()); - saveAppSettings = true; - } - - - QString version = doc.object().find(QStringLiteral("version"))->toString(); - QString url = doc.object().find(QStringLiteral("url"))->toString(); - - Version updateVersion = Version::fromString(version.toStdString()); - if (!updateVersion.isValid()) - { - LOG_ERROR_STREAM( - << "update version string is not valid: " << version.toStdString()); - break; - } - - result.success = true; - - if (updateVersion > Version::getApplicationVersion()) - { - MessageStatus(L"Newest available version: " + updateVersion.toDisplayWString()) - .dispatch(); - - result.version = updateVersion; - result.url = url; - - appSettings->setUpdateVersion(updateVersion); - appSettings->setUpdateDownloadUrl(url.toStdString()); - saveAppSettings = true; - - if (!force && appSettings->getSkipUpdateForVersion() == updateVersion) - { - break; - } - - QMessageBox msgBox; - msgBox.setText(QStringLiteral("Update Check")); - msgBox.setInformativeText( - "Sourcetrail " + version + " is available for download: " + url + ""); - msgBox.addButton(QStringLiteral("Close"), QMessageBox::ButtonRole::NoRole); - msgBox.addButton( - QStringLiteral("Skip this Version"), QMessageBox::ButtonRole::NoRole); - QPushButton* but = msgBox.addButton( - QStringLiteral("Download"), QMessageBox::ButtonRole::YesRole); - msgBox.setDefaultButton(but); - - int val = msgBox.exec(); - - if (val == 1) - { - appSettings->setSkipUpdateForVersion(updateVersion); - } - else if (val == 2) - { - QDesktopServices::openUrl(QUrl(url, QUrl::TolerantMode)); - } - } - else - { - MessageStatus(L"Sourcetrail is up-to-date").dispatch(); - } - } while (false); - - if (saveAppSettings) - { - appSettings->save(); - } - - if (!result.success) - { - MessageStatus(L"Update check failed", true).dispatch(); - } - - request->deleteLater(); - - callback(result); - }); - - request->sendRequest(QString::fromStdString(urlString)); - MessageStatus(L"Checking for new version", false, true).dispatch(); -} - -void QtUpdateChecker::checkUpdate() -{ - m_onQtThread([]() { check(false, [](Result) {}); }); -} diff --git a/src/lib_gui/qt/network/QtUpdateChecker.h b/src/lib_gui/qt/network/QtUpdateChecker.h deleted file mode 100644 index 6804edb4..00000000 --- a/src/lib_gui/qt/network/QtUpdateChecker.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef QT_UPDATE_CHECKER_H -#define QT_UPDATE_CHECKER_H - -#include "QtThreadedFunctor.h" -#include "UpdateChecker.h" -#include "Version.h" - -class QtUpdateChecker: public UpdateChecker -{ -public: - struct Result - { - bool success = false; - Version version; - QString url; - }; - - static bool needsAutomaticCheck(); - static void check(bool force, std::function callback); - - virtual void checkUpdate() override; - -private: - QtThreadedLambdaFunctor m_onQtThread; -}; - -#endif // QT_UPDATE_CHECKER_H diff --git a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentPreferences.cpp b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentPreferences.cpp index b5eb1294..70aee685 100644 --- a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentPreferences.cpp +++ b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentPreferences.cpp @@ -52,18 +52,22 @@ void QtProjectWizardContentPreferences::populate(QGridLayout* layout, int& row) addLabelAndWidget(QStringLiteral("Font Face"), m_fontFacePlaceHolder, layout, row); int rowNum = row; - connect(m_fontFacePlaceHolder, &QtComboBoxPlaceHolder::opened, [this, rowNum, layout]() { - m_fontFacePlaceHolder->hide(); + connect( + m_fontFacePlaceHolder, + &QtComboBoxPlaceHolder::opened, + [this, rowNum, layout]() + { + m_fontFacePlaceHolder->hide(); - QString name = m_fontFace->currentText(); - m_fontFace->setFontFilters(QFontComboBox::MonospacedFonts); - m_fontFace->setWritingSystem(QFontDatabase::Latin); - m_fontFace->setCurrentText(name); + QString name = m_fontFace->currentText(); + m_fontFace->setFontFilters(QFontComboBox::MonospacedFonts); + m_fontFace->setWritingSystem(QFontDatabase::Latin); + m_fontFace->setCurrentText(name); - addWidget(m_fontFace, layout, rowNum); + addWidget(m_fontFace, layout, rowNum); - QTimer::singleShot(10, [this]() { m_fontFace->showPopup(); }); - }); + QTimer::singleShot(10, [this]() { m_fontFace->showPopup(); }); + }); row++; // font size @@ -268,22 +272,6 @@ void QtProjectWizardContentPreferences::populate(QGridLayout* layout, int& row) addGap(layout, row); - // Network - addTitle(QStringLiteral("NETWORK"), layout, row); - - // Update check - m_automaticUpdateCheck = addCheckBox( - QStringLiteral("Automatic
Update Check"), - QStringLiteral("Check automatically for updates"), - QStringLiteral( - "

Automatically connects to the Sourcetrail server once a day to check " - "if a new release is available.

" - "

Note: No personally identifiable information will be transmitted to conduct this " - "check.

"), - layout, - row); - addGap(layout, row); - // Plugins addTitle(QStringLiteral("PLUGIN"), layout, row); @@ -531,8 +519,6 @@ void QtProjectWizardContentPreferences::load() m_logPath->setText(QString::fromStdWString(appSettings->getLogDirectoryPath().wstr())); } - m_automaticUpdateCheck->setChecked(appSettings->getAutomaticUpdateCheck()); - m_sourcetrailPort->setText(QString::number(appSettings->getSourcetrailPort())); m_pluginPort->setText(QString::number(appSettings->getPluginPort())); @@ -605,8 +591,6 @@ void QtProjectWizardContentPreferences::save() } } - appSettings->setAutomaticUpdateCheck(m_automaticUpdateCheck->isChecked()); - int sourcetrailPort = m_sourcetrailPort->text().toInt(); if (sourcetrailPort) appSettings->setSourcetrailPort(sourcetrailPort); diff --git a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentPreferences.h b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentPreferences.h index 876cd247..1e617e2f 100644 --- a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentPreferences.h +++ b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentPreferences.h @@ -125,8 +125,6 @@ private: QCheckBox* m_verboseIndexerLoggingEnabled; QtLocationPicker* m_logPath; - QCheckBox* m_automaticUpdateCheck; - QLineEdit* m_sourcetrailPort; QLineEdit* m_pluginPort; diff --git a/src/lib_gui/qt/window/QtStartScreen.cpp b/src/lib_gui/qt/window/QtStartScreen.cpp index 92382b1b..0bfd3a92 100644 --- a/src/lib_gui/qt/window/QtStartScreen.cpp +++ b/src/lib_gui/qt/window/QtStartScreen.cpp @@ -11,8 +11,6 @@ #include "ApplicationSettings.h" #include "MessageLoadProject.h" #include "ProjectSettings.h" -#include "QtNewsWidget.h" -#include "QtUpdateCheckerWidget.h" #include "ResourcePaths.h" #include "Version.h" #include "utilityQt.h" @@ -190,9 +188,6 @@ void QtStartScreen::setupStartScreen() versionLabel->setObjectName(QStringLiteral("boldLabel")); col->addWidget(versionLabel); - QtUpdateCheckerWidget* checker = new QtUpdateCheckerWidget(this); - col->addWidget(checker); - col->addSpacing(15); QPushButton* githubButton = new QPushButton(QStringLiteral("Contribute on GitHub"), this); @@ -200,10 +195,15 @@ void QtStartScreen::setupStartScreen() githubButton->setObjectName(QStringLiteral("infoButton")); githubButton->setIcon(m_githubIcon); githubButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - connect(githubButton, &QPushButton::clicked, []() { - QDesktopServices::openUrl(QUrl( - QStringLiteral("https://github.com/CoatiSoftware/Sourcetrail"), QUrl::TolerantMode)); - }); + connect( + githubButton, + &QPushButton::clicked, + []() + { + QDesktopServices::openUrl(QUrl( + QStringLiteral("https://github.com/CoatiSoftware/Sourcetrail"), + QUrl::TolerantMode)); + }); col->addWidget(githubButton); col->addSpacing(8); @@ -214,39 +214,16 @@ void QtStartScreen::setupStartScreen() patreonButton->setObjectName(QStringLiteral("infoButton")); patreonButton->setIcon(m_patreonIcon); patreonButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - connect(patreonButton, &QPushButton::clicked, []() { - QDesktopServices::openUrl( - QUrl(QStringLiteral("https://www.patreon.com/sourcetrail"), QUrl::TolerantMode)); - }); + connect( + patreonButton, + &QPushButton::clicked, + []() + { + QDesktopServices::openUrl(QUrl( + QStringLiteral("https://www.patreon.com/sourcetrail"), QUrl::TolerantMode)); + }); col->addWidget(patreonButton); - col->addSpacing(15); - - { - QLabel* newsHeader = new QLabel(QStringLiteral("News:")); - newsHeader->setObjectName(QStringLiteral("boldLabel")); - col->addWidget(newsHeader); - - QtNewsWidget* newsWidget = new QtNewsWidget(this); - col->addWidget(newsWidget); - - std::function updateNews = [newsHeader, newsWidget]() { - const bool newsAvailable = - ApplicationSettings::getInstance()->getAutomaticUpdateCheck() && - !ApplicationSettings::getInstance()->getUpdateNews().empty(); - newsHeader->setVisible(newsAvailable); - newsWidget->setVisible(newsAvailable); - if (newsAvailable) - { - newsWidget->updateNews(); - } - }; - - updateNews(); - - QObject::connect(checker, &QtUpdateCheckerWidget::updateReceived, updateNews); - } - col->addSpacing(35); col->addStretch();