aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ui/function/VersionCheckThread.cpp49
-rw-r--r--src/ui/help/AboutDialog.cpp60
-rw-r--r--src/ui/help/AboutDialog.h5
-rw-r--r--src/ui/settings/SettingsGeneral.cpp3
4 files changed, 45 insertions, 72 deletions
diff --git a/src/ui/function/VersionCheckThread.cpp b/src/ui/function/VersionCheckThread.cpp
index 50a4160e..765ccd2f 100644
--- a/src/ui/function/VersionCheckThread.cpp
+++ b/src/ui/function/VersionCheckThread.cpp
@@ -24,51 +24,54 @@
#include "VersionCheckThread.h"
-#include "GpgFrontendBuildInfo.h"
-#include "rapidjson/document.h"
+#include <iterator>
+#include <regex>
-using namespace rapidjson;
+#include "GpgFrontendBuildInfo.h"
+#include "json/json.hpp"
namespace GpgFrontend::UI {
void VersionCheckThread::run() {
- LOG(INFO) << "Start Version Thread to get latest version from Github";
+ using namespace nlohmann;
- auto currentVersion = "v" + QString::number(VERSION_MAJOR) + "." +
- QString::number(VERSION_MINOR) + "." +
- QString::number(VERSION_PATCH);
+ LOG(INFO) << "get latest version from Github";
+
+ auto current_version = std::string("v") + std::to_string(VERSION_MAJOR) +
+ "." + std::to_string(VERSION_MINOR) + "." +
+ std::to_string(VERSION_PATCH);
while (mNetworkReply->isRunning()) {
QApplication::processEvents();
}
if (mNetworkReply->error() != QNetworkReply::NoError) {
- LOG(ERROR) << "VersionCheckThread Found Network Error";
+ LOG(ERROR) << "network error";
return;
}
- QByteArray bytes = mNetworkReply->readAll();
+ auto bytes = mNetworkReply->readAll();
- Document d;
- d.Parse(bytes.constData());
+ auto reply_json = nlohmann::json::parse(bytes.toStdString());
- QString latestVersion = d["tag_name"].GetString();
+ std::string latest_version = reply_json["tag_name"];
- LOG(INFO) << "Latest Version From Github" << latestVersion.toStdString();
+ LOG(INFO) << "latest version from Github" << latest_version;
- QRegularExpression re(R"(^[vV](\d+\.)?(\d+\.)?(\*|\d+))");
- QRegularExpressionMatch match = re.match(latestVersion);
- if (match.hasMatch()) {
- latestVersion = match.captured(0); // matched == "23 def"
- LOG(INFO) << "Latest Version Matched" << latestVersion.toStdString();
+ std::regex re(R"(^[vV](\d+\.)?(\d+\.)?(\*|\d+))");
+ auto version_begin =
+ std::sregex_iterator(latest_version.begin(), latest_version.end(), re);
+ auto version_end = std::sregex_iterator();
+ if (std::distance(version_begin, version_end)) {
+ std::smatch match = *version_begin;
+ latest_version = match.str();
+ LOG(INFO) << "latest version matched" << latest_version;
} else {
- latestVersion = currentVersion;
- LOG(WARNING) << "Latest Version Unknown" << latestVersion.toStdString();
+ latest_version = current_version;
+ LOG(WARNING) << "latest version unknown";
}
- if (latestVersion != currentVersion) {
- emit upgradeVersion(currentVersion, latestVersion);
- }
+ emit upgradeVersion(current_version.c_str(), latest_version.c_str());
}
VersionCheckThread::VersionCheckThread(QNetworkReply* networkReply)
diff --git a/src/ui/help/AboutDialog.cpp b/src/ui/help/AboutDialog.cpp
index 7358ced5..836c165e 100644
--- a/src/ui/help/AboutDialog.cpp
+++ b/src/ui/help/AboutDialog.cpp
@@ -25,10 +25,7 @@
#include "ui/help/AboutDialog.h"
#include "GpgFrontendBuildInfo.h"
-#include "rapidjson/document.h"
-#include "rapidjson/writer.h"
-
-using namespace rapidjson;
+#include "function/VersionCheckThread.h"
namespace GpgFrontend::UI {
@@ -53,7 +50,7 @@ AboutDialog::AboutDialog(int defaultIndex, QWidget* parent) : QDialog(parent) {
auto* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(close()));
-
+
auto* mainLayout = new QVBoxLayout;
mainLayout->addWidget(tabWidget);
mainLayout->addWidget(buttonBox);
@@ -185,56 +182,29 @@ UpdateTab::UpdateTab(QWidget* parent) {
void UpdateTab::getLatestVersion() {
this->pb->setHidden(false);
- qDebug() << "Try to get latest version";
+ LOG(INFO) << "try to get latest version";
- QString baseUrl =
+ QString base_url =
"https://api.github.com/repos/saturneric/gpgfrontend/releases/latest";
+ QNetworkRequest request;
+ request.setUrl(QUrl(base_url));
+ auto version_thread = new VersionCheckThread(manager->get(request));
- auto manager = new QNetworkAccessManager(this);
+ connect(version_thread, SIGNAL(finished()), version_thread,
+ SLOT(deleteLater()));
+ connect(version_thread, &VersionCheckThread::upgradeVersion, this,
+ &UpdateTab::slotShowVersionStatus);
- QNetworkRequest request;
- request.setUrl(QUrl(baseUrl));
- QNetworkReply* replay = manager->get(request);
- auto thread = QThread::create([replay, this]() {
- while (replay->isRunning()) QApplication::processEvents();
- emit replyFromUpdateServer(replay->readAll());
- });
- connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
- thread->start();
+ version_thread->start();
}
-void UpdateTab::processReplyDataFromUpdateServer(const QByteArray& data) {
- qDebug() << "Try to Process Reply Data From Update Server";
-
+void UpdateTab::slotShowVersionStatus(const QString& current,
+ const QString& server) {
this->pb->setHidden(true);
- Document d;
- if (d.Parse(data.constData()).HasParseError() || !d.IsObject()) {
- qDebug() << "VersionCheckThread Found Network Error";
- auto latestVersion = "Unknown";
- latestVersionLabel->setText(QString("<center><b>") +
- _("Latest Version From Github") + ": " +
- latestVersion + "</b></center>");
- return;
- }
-
- QString latestVersion = d["tag_name"].GetString();
-
- qDebug() << "Latest Version From Github" << latestVersion;
-
- QRegularExpression re(R"(^[vV](\d+\.)?(\d+\.)?(\*|\d+))");
- QRegularExpressionMatch match = re.match(latestVersion);
- if (match.hasMatch()) {
- latestVersion = match.captured(0);
- qDebug() << "Latest Version Matched" << latestVersion;
- } else
- latestVersion = "Unknown";
-
latestVersionLabel->setText("<center><b>" +
QString(_("Latest Version From Github")) + ": " +
- latestVersion + "</b></center>");
-
- if (latestVersion > currentVersion) upgradeLabel->setHidden(false);
+ server + "</b></center>");
}
} // namespace GpgFrontend::UI
diff --git a/src/ui/help/AboutDialog.h b/src/ui/help/AboutDialog.h
index a7d7099b..4d43600e 100644
--- a/src/ui/help/AboutDialog.h
+++ b/src/ui/help/AboutDialog.h
@@ -68,14 +68,15 @@ class UpdateTab : public QWidget {
QString currentVersion;
+ QNetworkAccessManager* manager = new QNetworkAccessManager(this);
+
public:
explicit UpdateTab(QWidget* parent = nullptr);
void getLatestVersion();
private slots:
- void processReplyDataFromUpdateServer(const QByteArray& data);
- ;
+ void slotShowVersionStatus(const QString& current, const QString& server);
signals:
void replyFromUpdateServer(QByteArray data);
diff --git a/src/ui/settings/SettingsGeneral.cpp b/src/ui/settings/SettingsGeneral.cpp
index 98610e12..4f9bfbae 100644
--- a/src/ui/settings/SettingsGeneral.cpp
+++ b/src/ui/settings/SettingsGeneral.cpp
@@ -34,7 +34,6 @@
#include "GlobalSettingStation.h"
#include "gpg/function/GpgKeyGetter.h"
-#include "rapidjson/prettywriter.h"
#include "ui/widgets/KeyList.h"
namespace GpgFrontend::UI {
@@ -282,7 +281,7 @@ void GeneralTab::applySettings() {
general["lang"] = lang.key(langSelectBox->currentText()).toStdString();
}
#endif
-
+
#ifdef SERVER_SUPPORT
settings.setValue(
"general/ownKeyId",