Add check for updates setting
This commit is contained in:
parent
d6dfab1805
commit
09c2ed6b30
6 changed files with 49 additions and 6 deletions
|
@ -26,6 +26,9 @@
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="checkBox_MonitorProjectFiles">
|
<widget class="QCheckBox" name="checkBox_MonitorProjectFiles">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>If checked, a prompt to reload your project will appear if relevant project files are edited</string>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Monitor project files</string>
|
<string>Monitor project files</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -33,11 +36,24 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="checkBox_OpenRecentProject">
|
<widget class="QCheckBox" name="checkBox_OpenRecentProject">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>If checked, Porymap will automatically open your most recently opened project on startup</string>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Open recent project on launch</string>
|
<string>Open recent project on launch</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="checkBox_CheckForUpdates">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>If checked, Porymap will automatically alert you on startup if a new release is available</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Automatically check for updates</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
@ -74,6 +74,7 @@ public:
|
||||||
this->paletteEditorBitDepth = 24;
|
this->paletteEditorBitDepth = 24;
|
||||||
this->projectSettingsTab = 0;
|
this->projectSettingsTab = 0;
|
||||||
this->warpBehaviorWarningDisabled = false;
|
this->warpBehaviorWarningDisabled = false;
|
||||||
|
this->checkForUpdates = true;
|
||||||
}
|
}
|
||||||
void addRecentProject(QString project);
|
void addRecentProject(QString project);
|
||||||
void setRecentProjects(QStringList projects);
|
void setRecentProjects(QStringList projects);
|
||||||
|
@ -105,6 +106,7 @@ public:
|
||||||
void setPaletteEditorBitDepth(int bitDepth);
|
void setPaletteEditorBitDepth(int bitDepth);
|
||||||
void setProjectSettingsTab(int tab);
|
void setProjectSettingsTab(int tab);
|
||||||
void setWarpBehaviorWarningDisabled(bool disabled);
|
void setWarpBehaviorWarningDisabled(bool disabled);
|
||||||
|
void setCheckForUpdates(bool enabled);
|
||||||
QString getRecentProject();
|
QString getRecentProject();
|
||||||
QStringList getRecentProjects();
|
QStringList getRecentProjects();
|
||||||
bool getReopenOnLaunch();
|
bool getReopenOnLaunch();
|
||||||
|
@ -135,6 +137,7 @@ public:
|
||||||
int getPaletteEditorBitDepth();
|
int getPaletteEditorBitDepth();
|
||||||
int getProjectSettingsTab();
|
int getProjectSettingsTab();
|
||||||
bool getWarpBehaviorWarningDisabled();
|
bool getWarpBehaviorWarningDisabled();
|
||||||
|
bool getCheckForUpdates();
|
||||||
protected:
|
protected:
|
||||||
virtual QString getConfigFilepath() override;
|
virtual QString getConfigFilepath() override;
|
||||||
virtual void parseConfigKeyValue(QString key, QString value) override;
|
virtual void parseConfigKeyValue(QString key, QString value) override;
|
||||||
|
@ -183,6 +186,7 @@ private:
|
||||||
int paletteEditorBitDepth;
|
int paletteEditorBitDepth;
|
||||||
int projectSettingsTab;
|
int projectSettingsTab;
|
||||||
bool warpBehaviorWarningDisabled;
|
bool warpBehaviorWarningDisabled;
|
||||||
|
bool checkForUpdates;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern PorymapConfig porymapConfig;
|
extern PorymapConfig porymapConfig;
|
||||||
|
|
|
@ -400,7 +400,7 @@ private:
|
||||||
void addCustomHeaderValue(QString key, QJsonValue value, bool isNew = false);
|
void addCustomHeaderValue(QString key, QJsonValue value, bool isNew = false);
|
||||||
int insertTilesetLabel(QStringList * list, QString label);
|
int insertTilesetLabel(QStringList * list, QString label);
|
||||||
|
|
||||||
void checkForUpdates();
|
void checkForUpdates(bool requestedByUser);
|
||||||
};
|
};
|
||||||
|
|
||||||
enum MapListUserRoles {
|
enum MapListUserRoles {
|
||||||
|
|
|
@ -407,6 +407,8 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
|
||||||
this->projectSettingsTab = getConfigInteger(key, value, 0);
|
this->projectSettingsTab = getConfigInteger(key, value, 0);
|
||||||
} else if (key == "warp_behavior_warning_disabled") {
|
} else if (key == "warp_behavior_warning_disabled") {
|
||||||
this->warpBehaviorWarningDisabled = getConfigBool(key, value);
|
this->warpBehaviorWarningDisabled = getConfigBool(key, value);
|
||||||
|
} else if (key == "check_for_updates") {
|
||||||
|
this->checkForUpdates = getConfigBool(key, value);
|
||||||
} else {
|
} else {
|
||||||
logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->getConfigFilepath()).arg(key));
|
logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->getConfigFilepath()).arg(key));
|
||||||
}
|
}
|
||||||
|
@ -453,6 +455,7 @@ QMap<QString, QString> PorymapConfig::getKeyValueMap() {
|
||||||
map.insert("palette_editor_bit_depth", QString::number(this->paletteEditorBitDepth));
|
map.insert("palette_editor_bit_depth", QString::number(this->paletteEditorBitDepth));
|
||||||
map.insert("project_settings_tab", QString::number(this->projectSettingsTab));
|
map.insert("project_settings_tab", QString::number(this->projectSettingsTab));
|
||||||
map.insert("warp_behavior_warning_disabled", QString::number(this->warpBehaviorWarningDisabled));
|
map.insert("warp_behavior_warning_disabled", QString::number(this->warpBehaviorWarningDisabled));
|
||||||
|
map.insert("check_for_updates", QString::number(this->checkForUpdates));
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
@ -790,6 +793,15 @@ bool PorymapConfig::getWarpBehaviorWarningDisabled() {
|
||||||
return this->warpBehaviorWarningDisabled;
|
return this->warpBehaviorWarningDisabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PorymapConfig::setCheckForUpdates(bool enabled) {
|
||||||
|
this->checkForUpdates = enabled;
|
||||||
|
this->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PorymapConfig::getCheckForUpdates() {
|
||||||
|
return this->checkForUpdates;
|
||||||
|
}
|
||||||
|
|
||||||
const QStringList ProjectConfig::versionStrings = {
|
const QStringList ProjectConfig::versionStrings = {
|
||||||
"pokeruby",
|
"pokeruby",
|
||||||
"pokefirered",
|
"pokefirered",
|
||||||
|
|
|
@ -66,6 +66,9 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
// there is a bug affecting macOS users, where the trackpad deilveres a bad touch-release gesture
|
// there is a bug affecting macOS users, where the trackpad deilveres a bad touch-release gesture
|
||||||
// the warning is a bit annoying, so it is disabled here
|
// the warning is a bit annoying, so it is disabled here
|
||||||
QLoggingCategory::setFilterRules(QStringLiteral("qt.pointer.dispatch=false"));
|
QLoggingCategory::setFilterRules(QStringLiteral("qt.pointer.dispatch=false"));
|
||||||
|
|
||||||
|
if (porymapConfig.getCheckForUpdates())
|
||||||
|
this->checkForUpdates(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
@ -242,28 +245,31 @@ void MainWindow::initExtraSignals() {
|
||||||
label_MapRulerStatus->setAlignment(Qt::AlignCenter);
|
label_MapRulerStatus->setAlignment(Qt::AlignCenter);
|
||||||
label_MapRulerStatus->setTextFormat(Qt::PlainText);
|
label_MapRulerStatus->setTextFormat(Qt::PlainText);
|
||||||
label_MapRulerStatus->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
label_MapRulerStatus->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
||||||
|
|
||||||
// TODO: (if enabled) queue an automatic "Check for Updates"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Relocate
|
// TODO: Relocate
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
void MainWindow::on_actionCheck_for_Updates_triggered() {
|
void MainWindow::on_actionCheck_for_Updates_triggered() {
|
||||||
checkForUpdates();
|
checkForUpdates(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::checkForUpdates() {
|
void MainWindow::checkForUpdates(bool requestedByUser) {
|
||||||
if (!this->networkAccessManager)
|
if (!this->networkAccessManager)
|
||||||
this->networkAccessManager = new QNetworkAccessManager(this);
|
this->networkAccessManager = new QNetworkAccessManager(this);
|
||||||
|
|
||||||
// We could get ".../releases/latest" to retrieve less data, but this would run into problems if the
|
// We could get ".../releases/latest" to retrieve less data, but this would run into problems if the
|
||||||
// most recent item on the releases page is not actually a new release (like the static windows build).
|
// most recent item on the releases page is not actually a new release (like the static windows build).
|
||||||
QNetworkRequest request(QUrl("https://api.github.com/repos/huderlem/porymap/releases"));
|
static const QUrl url("https://api.github.com/repos/huderlem/porymap/releases");
|
||||||
|
QNetworkRequest request(url);
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||||
|
|
||||||
QNetworkReply * reply = this->networkAccessManager->get(request);
|
QNetworkReply * reply = this->networkAccessManager->get(request);
|
||||||
|
|
||||||
|
if (requestedByUser) {
|
||||||
|
// TODO: Show dialog
|
||||||
|
}
|
||||||
|
|
||||||
connect(reply, &QNetworkReply::finished, [this, reply] {
|
connect(reply, &QNetworkReply::finished, [this, reply] {
|
||||||
QJsonDocument data = QJsonDocument::fromJson(reply->readAll());
|
QJsonDocument data = QJsonDocument::fromJson(reply->readAll());
|
||||||
QJsonArray releases = data.array();
|
QJsonArray releases = data.array();
|
||||||
|
|
|
@ -49,6 +49,7 @@ void PreferenceEditor::updateFields() {
|
||||||
ui->lineEdit_TextEditorGotoLine->setText(porymapConfig.getTextEditorGotoLine());
|
ui->lineEdit_TextEditorGotoLine->setText(porymapConfig.getTextEditorGotoLine());
|
||||||
ui->checkBox_MonitorProjectFiles->setChecked(porymapConfig.getMonitorFiles());
|
ui->checkBox_MonitorProjectFiles->setChecked(porymapConfig.getMonitorFiles());
|
||||||
ui->checkBox_OpenRecentProject->setChecked(porymapConfig.getReopenOnLaunch());
|
ui->checkBox_OpenRecentProject->setChecked(porymapConfig.getReopenOnLaunch());
|
||||||
|
ui->checkBox_CheckForUpdates->setChecked(porymapConfig.getCheckForUpdates());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreferenceEditor::saveFields() {
|
void PreferenceEditor::saveFields() {
|
||||||
|
@ -58,10 +59,14 @@ void PreferenceEditor::saveFields() {
|
||||||
emit themeChanged(theme);
|
emit themeChanged(theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
porymapConfig.setSaveDisabled(true);
|
||||||
porymapConfig.setTextEditorOpenFolder(ui->lineEdit_TextEditorOpenFolder->text());
|
porymapConfig.setTextEditorOpenFolder(ui->lineEdit_TextEditorOpenFolder->text());
|
||||||
porymapConfig.setTextEditorGotoLine(ui->lineEdit_TextEditorGotoLine->text());
|
porymapConfig.setTextEditorGotoLine(ui->lineEdit_TextEditorGotoLine->text());
|
||||||
porymapConfig.setMonitorFiles(ui->checkBox_MonitorProjectFiles->isChecked());
|
porymapConfig.setMonitorFiles(ui->checkBox_MonitorProjectFiles->isChecked());
|
||||||
porymapConfig.setReopenOnLaunch(ui->checkBox_OpenRecentProject->isChecked());
|
porymapConfig.setReopenOnLaunch(ui->checkBox_OpenRecentProject->isChecked());
|
||||||
|
porymapConfig.setCheckForUpdates(ui->checkBox_CheckForUpdates->isChecked());
|
||||||
|
porymapConfig.setSaveDisabled(false);
|
||||||
|
porymapConfig.save();
|
||||||
|
|
||||||
emit preferencesSaved();
|
emit preferencesSaved();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue