logic: remove update checking code (#1226)

Removed because we are not planning to release any further versions of this software.
This commit is contained in:
Malte Langkabel
2021-11-22 13:21:39 +01:00
committed by GitHub
parent 1a2a81b137
commit cb2e3d369e
19 changed files with 51 additions and 848 deletions
-1
View File
@@ -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
-23
View File
@@ -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);
-4
View File
@@ -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<MessageRefresh>
, public MessageListener<MessageRefreshUI>
, public MessageListener<MessageSwitchColorScheme>
, public MessageListener<MessageWindowFocus>
{
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<MainView> m_mainView;
std::shared_ptr<IDECommunicationController> m_ideCommunicationController;
std::shared_ptr<UpdateChecker> m_updateChecker;
};
#endif // APPLICATION_H
-11
View File
@@ -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
-1
View File
@@ -15,7 +15,6 @@ public:
virtual std::shared_ptr<IDECommunicationController> createIDECommunicationController(
StorageAccess* storageAccess) const = 0;
virtual std::shared_ptr<UpdateChecker> createUpdateChecker() const = 0;
};
#endif // NETWORK_FACTORY_H
+21 -95
View File
@@ -58,7 +58,8 @@ bool ApplicationSettings::load(const FilePath& filePath, bool readOnly)
migrator.addMigration(
4,
std::make_shared<SettingsMigrationLambda>(
[](const SettingsMigration* migration, Settings* settings) {
[](const SettingsMigration* migration, Settings* settings)
{
std::wstring colorSchemePathString = migration->getValueFromSettings<std::wstring>(
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<SettingsMigrationLambda>([](const SettingsMigration* migration,
Settings* settings) {
std::vector<std::string> recentProjects;
recentProjects.push_back("./projects/tictactoe_py/tictactoe_py.srctrlprj");
utility::append(
recentProjects,
migration->getValuesFromSettings(
settings, "user/recent_projects/recent_project", std::vector<std::string>()));
for (size_t i = 0; i < recentProjects.size(); i++)
std::make_shared<SettingsMigrationLambda>(
[](const SettingsMigration* migration, Settings* settings)
{
if (recentProjects[i] == "./projects/tictactoe/tictactoe.srctrlprj")
std::vector<std::string> recentProjects;
recentProjects.push_back("./projects/tictactoe_py/tictactoe_py.srctrlprj");
utility::append(
recentProjects,
migration->getValuesFromSettings(
settings, "user/recent_projects/recent_project", std::vector<std::string>()));
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<SettingsMigrationLambda>(
[](const SettingsMigration* migration, Settings* settings) {
[](const SettingsMigration* migration, Settings* settings)
{
std::vector<FilePath> cxxHeaderSearchPaths = migration->getValuesFromSettings(
settings,
"indexing/cxx/header_search_paths/header_search_path",
@@ -582,83 +585,6 @@ bool ApplicationSettings::setRecentProjects(const std::vector<FilePath>& recentP
return setPathValues("user/recent_projects/recent_project", recentProjects);
}
std::string ApplicationSettings::getUserToken() const
{
return getValue<std::string>("user/token", "");
}
void ApplicationSettings::setUserToken(std::string token)
{
setValue<std::string>("user/token", token);
}
bool ApplicationSettings::getAutomaticUpdateCheck() const
{
return getValue<bool>("user/update_check/automatic", true);
}
void ApplicationSettings::setAutomaticUpdateCheck(bool automaticUpdates)
{
setValue<bool>("user/update_check/automatic", automaticUpdates);
}
TimeStamp ApplicationSettings::getLastUpdateCheck() const
{
return TimeStamp(getValue<std::string>("user/update_check/time_stamp", ""));
}
void ApplicationSettings::setLastUpdateCheck(const TimeStamp& time)
{
setValue<std::string>("user/update_check/time_stamp", time.toString());
}
Version ApplicationSettings::getSkipUpdateForVersion() const
{
return Version::fromString(getValue<std::string>("user/update_check/skip_version", "2017.1.0"));
}
void ApplicationSettings::setSkipUpdateForVersion(const Version& version)
{
if (version.isValid())
{
setValue<std::string>("user/update_check/skip_version", version.toDisplayString());
}
}
std::string ApplicationSettings::getUpdateDownloadUrl() const
{
return getValue<std::string>("user/update_check/update_url", "");
}
void ApplicationSettings::setUpdateDownloadUrl(const std::string& url)
{
setValue<std::string>("user/update_check/update_url", url);
}
Version ApplicationSettings::getUpdateVersion() const
{
return Version::fromString(
getValue<std::string>("user/update_check/update_version", "2017.1.0"));
}
std::string ApplicationSettings::getUpdateNews() const
{
return getValue<std::string>("user/update_check/news", "");
}
void ApplicationSettings::setUpdateNews(const std::string& news)
{
setValue<std::string>("user/update_check/news", news);
}
void ApplicationSettings::setUpdateVersion(const Version& version)
{
if (version.isValid())
{
setValue<std::string>("user/update_check/update_version", version.toDisplayString());
}
}
bool ApplicationSettings::getSeenErrorHelpMessage() const
{
return getValue<bool>("user/seen_error_help_message", false);
-21
View File
@@ -154,27 +154,6 @@ public:
std::vector<FilePath> getRecentProjects() const;
bool setRecentProjects(const std::vector<FilePath>& 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);
-6
View File
@@ -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
@@ -1,231 +0,0 @@
#include "QtNewsWidget.h"
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QStyle>
#include <QVBoxLayout>
#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": "<b>Hello World!</b>",
// 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);
}
}
}
@@ -1,32 +0,0 @@
#ifndef QT_NEWS_WIDGET_H
#define QT_NEWS_WIDGET_H
#include <QWidget>
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
@@ -1,109 +0,0 @@
#include "QtUpdateCheckerWidget.h"
#include <QDesktopServices>
#include <QHBoxLayout>
#include <QPushButton>
#include <QTimer>
#include <QUrl>
#include "ApplicationSettings.h"
#include "QtUpdateChecker.h"
#include "TimeStamp.h"
QtUpdateCheckerWidget::QtUpdateCheckerWidget(QWidget* parent)
: QWidget(parent), m_deleteCheck(std::make_shared<bool>(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<bool> 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<bool> 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);
}
@@ -1,30 +0,0 @@
#ifndef QT_UPDATE_CHECKER_WIDGET_H
#define QT_UPDATE_CHECKER_WIDGET_H
#include <memory>
#include <QWidget>
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<bool> m_deleteCheck;
};
#endif // QT_UPDATE_CHECKER_WIDGET_H
@@ -1,7 +1,6 @@
#include "QtNetworkFactory.h"
#include "QtIDECommunicationController.h"
#include "QtUpdateChecker.h"
QtNetworkFactory::QtNetworkFactory() {}
@@ -12,8 +11,3 @@ std::shared_ptr<IDECommunicationController> QtNetworkFactory::createIDECommunica
{
return std::make_shared<QtIDECommunicationController>(nullptr, storageAccess);
}
std::shared_ptr<UpdateChecker> QtNetworkFactory::createUpdateChecker() const
{
return std::make_shared<QtUpdateChecker>();
}
@@ -11,7 +11,6 @@ public:
virtual std::shared_ptr<IDECommunicationController> createIDECommunicationController(
StorageAccess* storageAccess) const override;
virtual std::shared_ptr<UpdateChecker> createUpdateChecker() const override;
};
#endif // QT_NETWORK_FACTORY_H
-179
View File
@@ -1,179 +0,0 @@
#include "QtUpdateChecker.h"
#include <QDesktopServices>
#include <QJsonDocument>
#include <QJsonObject>
#include <QMessageBox>
#include <QUrl>
#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<void(Result)> 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: <a href=\"" + url +
"\">" + url + "</a>");
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) {}); });
}
-27
View File
@@ -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<void(Result)> callback);
virtual void checkUpdate() override;
private:
QtThreadedLambdaFunctor m_onQtThread;
};
#endif // QT_UPDATE_CHECKER_H
@@ -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<br />Update Check"),
QStringLiteral("Check automatically for updates"),
QStringLiteral(
"<p>Automatically connects to the Sourcetrail server once a day to check "
"if a new release is available.</p>"
"<p>Note: No personally identifiable information will be transmitted to conduct this "
"check.</p>"),
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);
@@ -125,8 +125,6 @@ private:
QCheckBox* m_verboseIndexerLoggingEnabled;
QtLocationPicker* m_logPath;
QCheckBox* m_automaticUpdateCheck;
QLineEdit* m_sourcetrailPort;
QLineEdit* m_pluginPort;
+17 -40
View File
@@ -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<void()> 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();