aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2024-01-15 09:40:59 +0000
committersaturneric <[email protected]>2024-01-15 09:40:59 +0000
commit73a5de11797b4a517d3f0b34b51dd2e944ede11b (patch)
treee65ee088dfde09bf703c5242a59496fd021b323b
parentfeat: use qt json support components in data object and infos gathering module (diff)
downloadGpgFrontend-73a5de11797b4a517d3f0b34b51dd2e944ede11b.tar.gz
GpgFrontend-73a5de11797b4a517d3f0b34b51dd2e944ede11b.zip
refactor: remove nlohmann json library from project
-rw-r--r--.gitmodules3
-rw-r--r--src/core/CMakeLists.txt4
-rw-r--r--src/module/integrated/gnupg_info_gathering_module/GpgInfo.h2
-rw-r--r--src/module/integrated/version_checking_module/VersionCheckTask.cpp143
-rw-r--r--src/module/integrated/version_checking_module/VersionCheckingModule.cpp4
-rw-r--r--third_party/CMakeLists.txt1
m---------third_party/json0
7 files changed, 59 insertions, 98 deletions
diff --git a/.gitmodules b/.gitmodules
index 951cfffe..e05878f7 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,6 +1,3 @@
-[submodule "third_party/json"]
- path = third_party/json
- url = https://github.com/nlohmann/json.git
[submodule "third_party/qt-aes"]
path = third_party/qt-aes
url = https://github.com/bricke/Qt-AES.git
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 28216653..4e3a5d49 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -92,10 +92,6 @@ endif()
find_package(LibArchive REQUIRED)
target_include_directories(gpgfrontend_core PRIVATE ${LibArchive_INCLUDE_DIR})
target_link_libraries(gpgfrontend_core PRIVATE archive)
-
-# link json
-target_link_libraries(gpgfrontend_core
- PUBLIC nlohmann_json::nlohmann_json)
# link Qt core
if(Qt6_DIR)
diff --git a/src/module/integrated/gnupg_info_gathering_module/GpgInfo.h b/src/module/integrated/gnupg_info_gathering_module/GpgInfo.h
index 72513bc8..fb12b811 100644
--- a/src/module/integrated/gnupg_info_gathering_module/GpgInfo.h
+++ b/src/module/integrated/gnupg_info_gathering_module/GpgInfo.h
@@ -28,8 +28,6 @@
#pragma once
-#include <nlohmann/json.hpp>
-
namespace GpgFrontend::Module::Integrated::GnuPGInfoGatheringModule {
/**
* @brief Use to record some info about gnupg
diff --git a/src/module/integrated/version_checking_module/VersionCheckTask.cpp b/src/module/integrated/version_checking_module/VersionCheckTask.cpp
index edc22cc1..1aa5d534 100644
--- a/src/module/integrated/version_checking_module/VersionCheckTask.cpp
+++ b/src/module/integrated/version_checking_module/VersionCheckTask.cpp
@@ -30,7 +30,6 @@
#include <QMetaType>
#include <QtNetwork>
-#include <nlohmann/json.hpp>
#include "GpgFrontendBuildInfo.h"
@@ -47,70 +46,50 @@ VersionCheckTask::VersionCheckTask()
}
void VersionCheckTask::Run() {
- try {
- using namespace nlohmann;
- MODULE_LOG_DEBUG("current version: {}", current_version_);
- QString latest_version_url =
- "https://api.github.com/repos/saturneric/gpgfrontend/releases/latest";
-
- QNetworkRequest latest_request;
- latest_request.setUrl(QUrl(latest_version_url));
- latest_reply_ = network_manager_->get(latest_request);
- connect(latest_reply_, &QNetworkReply::finished, this,
- &VersionCheckTask::slot_parse_latest_version_info);
-
- // loading done
- version_.loading_done = true;
-
- } catch (...) {
- MODULE_LOG_ERROR("unknown error occurred");
- emit SignalTaskShouldEnd(-1);
- }
+ MODULE_LOG_DEBUG("current version: {}", current_version_);
+ QString latest_version_url =
+ "https://api.github.com/repos/saturneric/gpgfrontend/releases/latest";
+
+ QNetworkRequest latest_request;
+ latest_request.setUrl(QUrl(latest_version_url));
+ latest_reply_ = network_manager_->get(latest_request);
+ connect(latest_reply_, &QNetworkReply::finished, this,
+ &VersionCheckTask::slot_parse_latest_version_info);
}
void VersionCheckTask::slot_parse_latest_version_info() {
version_.current_version = current_version_;
- try {
- if (latest_reply_ == nullptr ||
- latest_reply_->error() != QNetworkReply::NoError) {
- MODULE_LOG_ERROR("latest version request error");
- version_.latest_version = current_version_;
+ if (latest_reply_ == nullptr ||
+ latest_reply_->error() != QNetworkReply::NoError) {
+ MODULE_LOG_ERROR("latest version request error");
+ version_.latest_version = current_version_;
+ } else {
+ latest_reply_bytes_ = latest_reply_->readAll();
+ auto latest_reply_json = QJsonDocument::fromJson(latest_reply_bytes_);
+
+ QString latest_version = latest_reply_json["tag_name"].toString();
+ MODULE_LOG_INFO("latest version from Github: {}", latest_version);
+
+ QRegularExpression re(R"(^[vV](\d+\.)?(\d+\.)?(\*|\d+))");
+ auto version_match = re.match(latest_version);
+ if (version_match.hasMatch()) {
+ latest_version = version_match.captured(0);
+ MODULE_LOG_DEBUG("latest version matched: {}", latest_version);
} else {
- latest_reply_bytes_ = latest_reply_->readAll();
-
- auto latest_reply_json =
- nlohmann::json::parse(latest_reply_bytes_.toStdString());
-
- QString latest_version =
- QString::fromStdString(latest_reply_json["tag_name"]);
-
- MODULE_LOG_INFO("latest version from Github: {}", latest_version);
-
- QRegularExpression re(R"(^[vV](\d+\.)?(\d+\.)?(\*|\d+))");
- auto version_match = re.match(latest_version);
- if (version_match.hasMatch()) {
- latest_version = version_match.captured(0);
- MODULE_LOG_DEBUG("latest version matched: {}", latest_version);
- } else {
- latest_version = current_version_;
- MODULE_LOG_WARN("latest version unknown");
- }
-
- bool prerelease = latest_reply_json["prerelease"];
- bool draft = latest_reply_json["draft"];
- auto publish_date =
- QString::fromStdString(latest_reply_json["published_at"]);
- auto release_note = QString::fromStdString(latest_reply_json["body"]);
- version_.latest_version = latest_version;
- version_.latest_prerelease_version_from_remote = prerelease;
- version_.latest_draft_from_remote = draft;
- version_.publish_date = publish_date;
- version_.release_note = release_note;
+ latest_version = current_version_;
+ MODULE_LOG_WARN("latest version unknown");
}
- } catch (...) {
- MODULE_LOG_ERROR("unknown error occurred");
- version_.loading_done = false;
+
+ bool prerelease = latest_reply_json["prerelease"].toBool();
+ bool draft = latest_reply_json["draft"].toBool();
+ auto publish_date = latest_reply_json["published_at"].toString();
+ auto release_note = latest_reply_json["body"].toString();
+ version_.latest_version = latest_version;
+ version_.latest_prerelease_version_from_remote = prerelease;
+ version_.latest_draft_from_remote = draft;
+ version_.publish_date = publish_date;
+ version_.release_note = release_note;
}
if (latest_reply_ != nullptr) {
@@ -135,42 +114,38 @@ void VersionCheckTask::slot_parse_latest_version_info() {
}
void VersionCheckTask::slot_parse_current_version_info() {
- try {
- if (current_reply_ == nullptr ||
- current_reply_->error() != QNetworkReply::NoError) {
- if (current_reply_ != nullptr) {
- MODULE_LOG_ERROR("current version request network error: {}",
- current_reply_->errorString().toStdString());
- } else {
- MODULE_LOG_ERROR(
- "current version request network error, null reply object");
- }
- version_.current_version_publish_in_remote = false;
- version_.loading_done = false;
+ if (current_reply_ == nullptr ||
+ current_reply_->error() != QNetworkReply::NoError) {
+ if (current_reply_ != nullptr) {
+ MODULE_LOG_ERROR("current version request network error: {}",
+ current_reply_->errorString().toStdString());
} else {
- version_.current_version_publish_in_remote = true;
- current_reply_bytes_ = current_reply_->readAll();
- MODULE_LOG_DEBUG("current version: {}", current_reply_bytes_.size());
- auto current_reply_json =
- nlohmann::json::parse(current_reply_bytes_.toStdString());
- bool current_prerelease = current_reply_json["prerelease"];
- bool current_draft = current_reply_json["draft"];
+ MODULE_LOG_ERROR(
+ "current version request network error, null reply object");
+ }
+ version_.current_version_publish_in_remote = false;
+ } else {
+ version_.current_version_publish_in_remote = true;
+ current_reply_bytes_ = current_reply_->readAll();
+ auto current_reply_json = QJsonDocument::fromJson(current_reply_bytes_);
+
+ if (current_reply_json.isObject()) {
+ bool current_prerelease = current_reply_json["prerelease"].toBool();
+ bool current_draft = current_reply_json["draft"].toBool();
version_.latest_prerelease_version_from_remote = current_prerelease;
version_.latest_draft_from_remote = current_draft;
+
+ // loading done
version_.loading_done = true;
+ } else {
+ MODULE_LOG_WARN("cannot parse data got from github");
}
- } catch (...) {
- MODULE_LOG_ERROR("unknown error occurred");
- version_.loading_done = false;
}
MODULE_LOG_DEBUG("current version parse done: {}",
version_.current_version_publish_in_remote);
- if (current_reply_ != nullptr) {
- current_reply_->deleteLater();
- }
-
+ if (current_reply_ != nullptr) current_reply_->deleteLater();
emit SignalUpgradeVersion(version_);
emit SignalTaskShouldEnd(0);
}
diff --git a/src/module/integrated/version_checking_module/VersionCheckingModule.cpp b/src/module/integrated/version_checking_module/VersionCheckingModule.cpp
index b1eb7a16..9b62a9c8 100644
--- a/src/module/integrated/version_checking_module/VersionCheckingModule.cpp
+++ b/src/module/integrated/version_checking_module/VersionCheckingModule.cpp
@@ -28,10 +28,6 @@
#include "VersionCheckingModule.h"
-#include <qobject.h>
-
-#include <utility>
-
#include "Log.h"
#include "SoftwareVersion.h"
#include "VersionCheckTask.h"
diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt
index b0ddc488..dbee3026 100644
--- a/third_party/CMakeLists.txt
+++ b/third_party/CMakeLists.txt
@@ -27,7 +27,6 @@
# json
set(JSON_BuildTests OFF CACHE INTERNAL "")
-add_subdirectory(json EXCLUDE_FROM_ALL)
add_subdirectory(spdlog EXCLUDE_FROM_ALL)
# not working at macOS
diff --git a/third_party/json b/third_party/json
deleted file mode 160000
-Subproject db78ac1d7716f56fc9f1b030b715f872f93964e