aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/thread
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/thread')
-rw-r--r--src/ui/thread/KeyServerImportTask.cpp69
-rw-r--r--src/ui/thread/KeyServerImportTask.h43
-rw-r--r--src/ui/thread/KeyServerSearchTask.cpp34
-rw-r--r--src/ui/thread/KeyServerSearchTask.h37
-rw-r--r--src/ui/thread/ListedKeyServerTestTask.cpp46
-rw-r--r--src/ui/thread/ListedKeyServerTestTask.h37
-rw-r--r--src/ui/thread/ProxyConnectionTestTask.cpp31
-rw-r--r--src/ui/thread/ProxyConnectionTestTask.h34
-rw-r--r--src/ui/thread/VersionCheckTask.cpp178
-rw-r--r--src/ui/thread/VersionCheckTask.h98
10 files changed, 191 insertions, 416 deletions
diff --git a/src/ui/thread/KeyServerImportTask.cpp b/src/ui/thread/KeyServerImportTask.cpp
index fc6a868c..63cabbcd 100644
--- a/src/ui/thread/KeyServerImportTask.cpp
+++ b/src/ui/thread/KeyServerImportTask.cpp
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2021 Saturneric
+ * Copyright (C) 2021 Saturneric <[email protected]>
*
* This file is part of GpgFrontend.
*
@@ -19,47 +19,76 @@
* The initial version of the source code is inherited from
* the gpg4usb project, which is under GPL-3.0-or-later.
*
- * The source code version of this software was modified and released
- * by Saturneric<[email protected]><[email protected]> starting on May 12, 2021.
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#include "ui/thread/KeyServerImportTask.h"
-#include <vector>
+#include "core/function/gpg/GpgKeyImportExporter.h"
+#include "ui/struct/SettingsObject.h"
+#include "ui/struct/settings/KeyServerSO.h"
GpgFrontend::UI::KeyServerImportTask::KeyServerImportTask(
- std::string keyserver_url, std::vector<std::string> keyids)
+ QString keyserver_url, std::vector<QString> keyids)
: Task("key_server_import_task"),
keyserver_url_(std::move(keyserver_url)),
keyids_(std::move(keyids)),
- manager_(new QNetworkAccessManager(this)) {}
+ manager_(new QNetworkAccessManager(this)) {
+ HoldOnLifeCycle(true);
-void GpgFrontend::UI::KeyServerImportTask::run() {
- SetFinishAfterRun(false);
+ if (keyserver_url_.isEmpty()) {
+ KeyServerSO key_server(SettingsObject("general_settings_state"));
+ keyserver_url_ = key_server.GetTargetServer();
+ GF_UI_LOG_DEBUG("key server import task sets key server url: {}",
+ keyserver_url_);
+ }
+}
- QUrl keyserver_url = QUrl(keyserver_url_.c_str());
+auto GpgFrontend::UI::KeyServerImportTask::Run() -> int {
+ QUrl const keyserver_url = QUrl(keyserver_url_);
for (const auto& key_id : keyids_) {
- QUrl req_url(keyserver_url.scheme() + "://" + keyserver_url.host() +
- "/pks/lookup?op=get&search=0x" + key_id.c_str() +
- "&options=mr");
+ QUrl const req_url(keyserver_url.scheme() + "://" + keyserver_url.host() +
+ "/pks/lookup?op=get&search=0x" + key_id + "&options=mr");
reply_ = manager_->get(QNetworkRequest(req_url));
-
connect(reply_, &QNetworkReply::finished, this,
&KeyServerImportTask::dealing_reply_from_server);
}
+ return 0;
}
void GpgFrontend::UI::KeyServerImportTask::dealing_reply_from_server() {
- QByteArray buffer;
- QNetworkReply::NetworkError network_reply = reply_->error();
- if (network_reply == QNetworkReply::NoError) {
- buffer = reply_->readAll();
+ auto const network_reply = reply_->error();
+ auto buffer = reply_->readAll();
+
+ if (network_reply != QNetworkReply::NoError) {
+ GF_UI_LOG_ERROR("key import error, message from key server reply: ",
+ buffer);
+ QString err_msg;
+ switch (network_reply) {
+ case QNetworkReply::ContentNotFoundError:
+ err_msg = tr("Key not found in the Keyserver.");
+ break;
+ case QNetworkReply::TimeoutError:
+ err_msg = tr("Network connection timeout.");
+ break;
+ case QNetworkReply::HostNotFoundError:
+ err_msg = tr("Cannot resolve the address of target key server.");
+ break;
+ default:
+ err_msg = tr("General connection error occurred.");
+ }
+ emit SignalKeyServerImportResult(false, err_msg, buffer, nullptr);
}
- emit SignalKeyServerImportResult(network_reply, buffer);
- if (result_count_++ == keyids_.size() - 1) {
- emit SignalTaskRunnableEnd(0);
+ auto info = GpgKeyImportExporter::GetInstance().ImportKey(GFBuffer(buffer));
+ emit SignalKeyServerImportResult(true, tr("Success"), buffer, info);
+
+ if (static_cast<size_t>(result_count_++) == keyids_.size() - 1) {
+ emit SignalTaskShouldEnd(0);
}
} \ No newline at end of file
diff --git a/src/ui/thread/KeyServerImportTask.h b/src/ui/thread/KeyServerImportTask.h
index 7d3b66c6..8797916c 100644
--- a/src/ui/thread/KeyServerImportTask.h
+++ b/src/ui/thread/KeyServerImportTask.h
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2021 Saturneric
+ * Copyright (C) 2021 Saturneric <[email protected]>
*
* This file is part of GpgFrontend.
*
@@ -19,17 +19,26 @@
* The initial version of the source code is inherited from
* the gpg4usb project, which is under GPL-3.0-or-later.
*
- * The source code version of this software was modified and released
- * by Saturneric<[email protected]><[email protected]> starting on May 12, 2021.
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
*
*/
-#ifndef GPGFRONTEND_KEYSERVERIMPORTTASK_H
-#define GPGFRONTEND_KEYSERVERIMPORTTASK_H
+#pragma once
+
+#include <qnetworkaccessmanager.h>
+#include <qnetworkreply.h>
+
+#include "core/thread/Task.h"
-#include "GpgFrontendUI.h"
+namespace GpgFrontend {
+class GpgImportInformation;
+}
namespace GpgFrontend::UI {
+
class KeyServerImportTask : public Thread::Task {
Q_OBJECT
public:
@@ -39,25 +48,23 @@ class KeyServerImportTask : public Thread::Task {
* @param keyserver_url
* @param search_string
*/
- KeyServerImportTask(std::string keyserver_url,
- std::vector<std::string> keyid);
-
- signals:
+ KeyServerImportTask(QString keyserver_url, std::vector<QString> keyid);
/**
* @brief
*
- * @param result
*/
- void SignalKeyServerImportResult(QNetworkReply::NetworkError reply,
- QByteArray buffer);
+ auto Run() -> int override;
+
+ signals:
- protected:
/**
* @brief
*
+ * @param result
*/
- void run() override;
+ void SignalKeyServerImportResult(bool, QString, QByteArray,
+ std::shared_ptr<GpgImportInformation>);
private slots:
@@ -68,13 +75,11 @@ class KeyServerImportTask : public Thread::Task {
void dealing_reply_from_server();
private:
- std::string keyserver_url_; ///<
- std::vector<std::string> keyids_; ///<
+ QString keyserver_url_; ///<
+ std::vector<QString> keyids_; ///<
int result_count_ = 0;
QNetworkAccessManager *manager_; ///<
QNetworkReply *reply_; ///<
};
} // namespace GpgFrontend::UI
-
-#endif // GPGFRONTEND_KEYSERVERIMPORTTASK_H \ No newline at end of file
diff --git a/src/ui/thread/KeyServerSearchTask.cpp b/src/ui/thread/KeyServerSearchTask.cpp
index 863a4ca3..2f05b774 100644
--- a/src/ui/thread/KeyServerSearchTask.cpp
+++ b/src/ui/thread/KeyServerSearchTask.cpp
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2021 Saturneric
+ * Copyright (C) 2021 Saturneric <[email protected]>
*
* This file is part of GpgFrontend.
*
@@ -19,34 +19,34 @@
* The initial version of the source code is inherited from
* the gpg4usb project, which is under GPL-3.0-or-later.
*
- * The source code version of this software was modified and released
- * by Saturneric<[email protected]><[email protected]> starting on May 12, 2021.
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#include "ui/thread/KeyServerSearchTask.h"
-#include <utility>
-
-GpgFrontend::UI::KeyServerSearchTask::KeyServerSearchTask(
- std::string keyserver_url, std::string search_string)
+GpgFrontend::UI::KeyServerSearchTask::KeyServerSearchTask(QString keyserver_url,
+ QString search_string)
: Task("key_server_search_task"),
keyserver_url_(std::move(keyserver_url)),
search_string_(std::move(search_string)),
- manager_(new QNetworkAccessManager(this)) {}
-
-void GpgFrontend::UI::KeyServerSearchTask::run() {
- SetFinishAfterRun(false);
+ manager_(new QNetworkAccessManager(this)) {
+ HoldOnLifeCycle(true);
+}
- QUrl url_from_remote =
- QString::fromStdString(keyserver_url_) +
- "/pks/lookup?search=" + QString::fromStdString(search_string_) +
- "&op=index&options=mr";
+auto GpgFrontend::UI::KeyServerSearchTask::Run() -> int {
+ QUrl url_from_remote = keyserver_url_ +
+ "/pks/lookup?search=" + search_string_ +
+ "&op=index&options=mr";
reply_ = manager_->get(QNetworkRequest(url_from_remote));
-
connect(reply_, &QNetworkReply::finished, this,
&KeyServerSearchTask::dealing_reply_from_server);
+
+ return 0;
}
void GpgFrontend::UI::KeyServerSearchTask::dealing_reply_from_server() {
@@ -56,5 +56,5 @@ void GpgFrontend::UI::KeyServerSearchTask::dealing_reply_from_server() {
buffer = reply_->readAll();
}
emit SignalKeyServerSearchResult(network_reply, buffer);
- emit SignalTaskRunnableEnd(0);
+ emit SignalTaskShouldEnd(0);
}
diff --git a/src/ui/thread/KeyServerSearchTask.h b/src/ui/thread/KeyServerSearchTask.h
index 3333e949..cdce944d 100644
--- a/src/ui/thread/KeyServerSearchTask.h
+++ b/src/ui/thread/KeyServerSearchTask.h
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2021 Saturneric
+ * Copyright (C) 2021 Saturneric <[email protected]>
*
* This file is part of GpgFrontend.
*
@@ -19,18 +19,22 @@
* The initial version of the source code is inherited from
* the gpg4usb project, which is under GPL-3.0-or-later.
*
- * The source code version of this software was modified and released
- * by Saturneric<[email protected]><[email protected]> starting on May 12, 2021.
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
*
*/
-#ifndef GPGFRONTEND_KEYSERVERSEARCHTASK_H
-#define GPGFRONTEND_KEYSERVERSEARCHTASK_H
+#pragma once
+
+#include <qnetworkaccessmanager.h>
+#include <qnetworkreply.h>
#include "GpgFrontendUI.h"
+#include "core/thread/ThreadingModel.h"
namespace GpgFrontend::UI {
-
class KeyServerSearchTask : public Thread::Task {
Q_OBJECT
public:
@@ -40,37 +44,34 @@ class KeyServerSearchTask : public Thread::Task {
* @param keyserver_url
* @param search_string
*/
- KeyServerSearchTask(std::string keyserver_url, std::string search_string);
-
- signals:
+ KeyServerSearchTask(QString keyserver_url, QString search_string);
/**
* @brief
*
- * @param result
*/
- void SignalKeyServerSearchResult(QNetworkReply::NetworkError reply,
- QByteArray buffer);
+ auto Run() -> int override;
+
+ signals:
- protected:
/**
* @brief
*
+ * @param result
*/
- void run() override;
+ void SignalKeyServerSearchResult(QNetworkReply::NetworkError reply,
+ QByteArray buffer);
private slots:
void dealing_reply_from_server();
private:
- std::string keyserver_url_; ///<
- std::string search_string_; ///<
+ QString keyserver_url_; ///<
+ QString search_string_; ///<
QNetworkAccessManager *manager_; ///<
QNetworkReply *reply_; ///<
};
} // namespace GpgFrontend::UI
-
-#endif // GPGFRONTEND_KEYSERVERSEARCHTASK_H \ No newline at end of file
diff --git a/src/ui/thread/ListedKeyServerTestTask.cpp b/src/ui/thread/ListedKeyServerTestTask.cpp
index 914cd3d6..4ab7ba5f 100644
--- a/src/ui/thread/ListedKeyServerTestTask.cpp
+++ b/src/ui/thread/ListedKeyServerTestTask.cpp
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2021 Saturneric
+ * Copyright (C) 2021 Saturneric <[email protected]>
*
* This file is part of GpgFrontend.
*
@@ -19,46 +19,48 @@
* The initial version of the source code is inherited from
* the gpg4usb project, which is under GPL-3.0-or-later.
*
- * The source code version of this software was modified and released
- * by Saturneric<[email protected]><[email protected]> starting on May 12, 2021.
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#include "ListedKeyServerTestTask.h"
+#include <QtNetwork>
#include <vector>
GpgFrontend::UI::ListedKeyServerTestTask::ListedKeyServerTestTask(
- const QStringList& urls, int timeout, QWidget* parent)
+ QStringList urls, int timeout, QWidget* /*parent*/)
: Task("listed_key_server_test_task"),
- urls_(urls),
- timeout_(timeout),
+ urls_(std::move(urls)),
+ result_(urls_.size(), kTEST_RESULT_TYPE_ERROR),
network_manager_(new QNetworkAccessManager(this)),
- result_(urls_.size(), kTestResultType_Error) {
+ timeout_(timeout) {
+ HoldOnLifeCycle(true);
qRegisterMetaType<std::vector<KeyServerTestResultType>>(
"std::vector<KeyServerTestResultType>");
}
-void GpgFrontend::UI::ListedKeyServerTestTask::run() {
- SetFinishAfterRun(false);
-
+auto GpgFrontend::UI::ListedKeyServerTestTask::Run() -> int {
size_t index = 0;
for (const auto& url : urls_) {
auto key_url = QUrl{url};
- SPDLOG_DEBUG("key server request: {}", key_url.host().toStdString());
+ GF_UI_LOG_DEBUG("key server request: {}", key_url.host().toStdString());
auto* network_reply = network_manager_->get(QNetworkRequest{key_url});
auto* timer = new QTimer(this);
connect(network_reply, &QNetworkReply::finished, this,
[this, index, network_reply]() {
- SPDLOG_DEBUG("key server domain reply: {}",
- urls_[index].toStdString());
+ GF_UI_LOG_DEBUG("key server domain reply: {}",
+ urls_[index].toStdString());
this->slot_process_network_reply(index, network_reply);
});
connect(timer, &QTimer::timeout, this, [this, index, network_reply]() {
- SPDLOG_DEBUG("timeout for key server: {}", urls_[index].toStdString());
+ GF_UI_LOG_DEBUG("timeout for key server: {}", urls_[index].toStdString());
if (network_reply->isRunning()) {
network_reply->abort();
this->slot_process_network_reply(index, network_reply);
@@ -66,24 +68,26 @@ void GpgFrontend::UI::ListedKeyServerTestTask::run() {
});
timer->start(timeout_);
-
index++;
}
+
+ return 0;
}
void GpgFrontend::UI::ListedKeyServerTestTask::slot_process_network_reply(
int index, QNetworkReply* reply) {
if (!reply->isRunning() && reply->error() == QNetworkReply::NoError) {
- result_[index] = kTestResultType_Success;
+ result_[index] = kTEST_RESULT_TYPE_SUCCESS;
} else {
- if (!reply->isFinished())
- result_[index] = kTestResultType_Timeout;
- else
- result_[index] = kTestResultType_Error;
+ if (!reply->isFinished()) {
+ result_[index] = kTEST_RESULT_TYPE_TIMEOUT;
+ } else {
+ result_[index] = kTEST_RESULT_TYPE_ERROR;
+ }
}
if (++result_count_ == urls_.size()) {
emit SignalKeyServerListTestResult(result_);
- emit SignalTaskRunnableEnd(0);
+ emit SignalTaskShouldEnd(0);
}
}
diff --git a/src/ui/thread/ListedKeyServerTestTask.h b/src/ui/thread/ListedKeyServerTestTask.h
index aa1bac5e..fdd036d4 100644
--- a/src/ui/thread/ListedKeyServerTestTask.h
+++ b/src/ui/thread/ListedKeyServerTestTask.h
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2021 Saturneric
+ * Copyright (C) 2021 Saturneric <[email protected]>
*
* This file is part of GpgFrontend.
*
@@ -19,15 +19,21 @@
* The initial version of the source code is inherited from
* the gpg4usb project, which is under GPL-3.0-or-later.
*
- * The source code version of this software was modified and released
- * by Saturneric<[email protected]><[email protected]> starting on May 12, 2021.
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
*
*/
-#ifndef GPGFRONTEND_LISTEDKEYSERVERTESTTHREAD_H
-#define GPGFRONTEND_LISTEDKEYSERVERTESTTHREAD_H
+#pragma once
#include "GpgFrontendUI.h"
+#include "core/thread/ThreadingModel.h"
+
+class QNetworkAccessManager;
+class QNetworkReply;
+
namespace GpgFrontend::UI {
/**
@@ -38,29 +44,28 @@ class ListedKeyServerTestTask : public Thread::Task {
Q_OBJECT
public:
enum KeyServerTestResultType {
- kTestResultType_Success,
- kTestResultType_Timeout,
- kTestResultType_Error,
+ kTEST_RESULT_TYPE_SUCCESS,
+ kTEST_RESULT_TYPE_TIMEOUT,
+ kTEST_RESULT_TYPE_ERROR,
};
- explicit ListedKeyServerTestTask(const QStringList& urls, int timeout,
+ explicit ListedKeyServerTestTask(QStringList urls, int timeout,
QWidget* parent = nullptr);
- signals:
/**
* @brief
*
- * @param result
*/
- void SignalKeyServerListTestResult(
- std::vector<KeyServerTestResultType> result);
+ auto Run() -> int override;
- protected:
+ signals:
/**
* @brief
*
+ * @param result
*/
- void run() override;
+ void SignalKeyServerListTestResult(
+ std::vector<KeyServerTestResultType> result);
private:
QStringList urls_; ///<
@@ -81,5 +86,3 @@ class ListedKeyServerTestTask : public Thread::Task {
} // namespace GpgFrontend::UI
class TestListedKeyServerThread {};
-
-#endif // GPGFRONTEND_LISTEDKEYSERVERTESTTHREAD_H
diff --git a/src/ui/thread/ProxyConnectionTestTask.cpp b/src/ui/thread/ProxyConnectionTestTask.cpp
index c7d623d7..6b0993fe 100644
--- a/src/ui/thread/ProxyConnectionTestTask.cpp
+++ b/src/ui/thread/ProxyConnectionTestTask.cpp
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2021 Saturneric
+ * Copyright (C) 2021 Saturneric <[email protected]>
*
* This file is part of GpgFrontend.
*
@@ -19,35 +19,39 @@
* The initial version of the source code is inherited from
* the gpg4usb project, which is under GPL-3.0-or-later.
*
- * The source code version of this software was modified and released
- * by Saturneric<[email protected]><[email protected]> starting on May 12, 2021.
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#include "ProxyConnectionTestTask.h"
+#include <QtNetwork>
+
GpgFrontend::UI::ProxyConnectionTestTask::ProxyConnectionTestTask(QString url,
int timeout)
: Task("proxy_connection_test_task"),
url_(std::move(url)),
timeout_(timeout),
- network_manager_(new QNetworkAccessManager(this)) {}
-
-void GpgFrontend::UI::ProxyConnectionTestTask::run() {
- SetFinishAfterRun(false);
+ network_manager_(new QNetworkAccessManager(this)) {
+ HoldOnLifeCycle(true);
+}
+auto GpgFrontend::UI::ProxyConnectionTestTask::Run() -> int {
auto* network_reply = network_manager_->get(QNetworkRequest{url_});
auto* timer = new QTimer(this);
connect(network_reply, &QNetworkReply::finished, this,
[this, network_reply]() {
- SPDLOG_DEBUG("key server domain reply: {} received",
- url_.toStdString());
+ GF_UI_LOG_DEBUG("key server domain reply: {} received",
+ url_.toStdString());
this->slot_process_network_reply(network_reply);
});
connect(timer, &QTimer::timeout, this, [this, network_reply]() {
- SPDLOG_DEBUG("timeout for key server: {}", url_.toStdString());
+ GF_UI_LOG_DEBUG("timeout for key server: {}", url_.toStdString());
if (network_reply->isRunning()) {
network_reply->abort();
this->slot_process_network_reply(network_reply);
@@ -55,13 +59,14 @@ void GpgFrontend::UI::ProxyConnectionTestTask::run() {
});
timer->start(timeout_);
+ return 0;
}
void GpgFrontend::UI::ProxyConnectionTestTask::slot_process_network_reply(
QNetworkReply* reply) {
auto buffer = reply->readAll();
- SPDLOG_DEBUG("key server domain reply: {}, buffer size: {}",
- url_.toStdString(), buffer.size());
+ GF_UI_LOG_DEBUG("key server domain reply: {}, buffer size: {}",
+ url_.toStdString(), buffer.size());
if (reply->error() == QNetworkReply::NoError && !buffer.isEmpty()) {
result_ = "Reachable";
@@ -70,5 +75,5 @@ void GpgFrontend::UI::ProxyConnectionTestTask::slot_process_network_reply(
}
emit SignalProxyConnectionTestResult(result_);
- emit SignalTaskRunnableEnd(0);
+ emit SignalTaskShouldEnd(0);
}
diff --git a/src/ui/thread/ProxyConnectionTestTask.h b/src/ui/thread/ProxyConnectionTestTask.h
index 38e78ae4..c15f45bc 100644
--- a/src/ui/thread/ProxyConnectionTestTask.h
+++ b/src/ui/thread/ProxyConnectionTestTask.h
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2021 Saturneric
+ * Copyright (C) 2021 Saturneric <[email protected]>
*
* This file is part of GpgFrontend.
*
@@ -19,19 +19,20 @@
* The initial version of the source code is inherited from
* the gpg4usb project, which is under GPL-3.0-or-later.
*
- * The source code version of this software was modified and released
- * by Saturneric<[email protected]><[email protected]> starting on May 12, 2021.
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
*
*/
-#ifndef GPGFRONTEND_PROXYCONNECTIONTESTTHREAD_H
-#define GPGFRONTEND_PROXYCONNECTIONTESTTHREAD_H
-
-class ProxyConnectionTestThread {};
-
-#include <utility>
+#pragma once
#include "GpgFrontendUI.h"
+#include "core/thread/ThreadingModel.h"
+
+class QNetworkAccessManager;
+class QNetworkReply;
namespace GpgFrontend::UI {
@@ -51,6 +52,12 @@ class ProxyConnectionTestTask : public Thread::Task {
*/
explicit ProxyConnectionTestTask(QString url, int timeout);
+ /**
+ * @brief
+ *
+ */
+ auto Run() -> int override;
+
signals:
/**
* @brief
@@ -59,14 +66,13 @@ class ProxyConnectionTestTask : public Thread::Task {
*/
void SignalProxyConnectionTestResult(const QString& result);
- protected:
+ private slots:
+
/**
* @brief
*
+ * @param reply
*/
- void run() override;
-
- private slots:
void slot_process_network_reply(QNetworkReply* reply);
private:
@@ -77,5 +83,3 @@ class ProxyConnectionTestTask : public Thread::Task {
};
} // namespace GpgFrontend::UI
-
-#endif // GPGFRONTEND_PROXYCONNECTIONTESTTHREAD_H
diff --git a/src/ui/thread/VersionCheckTask.cpp b/src/ui/thread/VersionCheckTask.cpp
deleted file mode 100644
index e9490e1c..00000000
--- a/src/ui/thread/VersionCheckTask.cpp
+++ /dev/null
@@ -1,178 +0,0 @@
-/**
- * Copyright (C) 2021 Saturneric
- *
- * This file is part of GpgFrontend.
- *
- * GpgFrontend is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * GpgFrontend is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
- *
- * The initial version of the source code is inherited from
- * the gpg4usb project, which is under GPL-3.0-or-later.
- *
- * All the source code of GpgFrontend was modified and released by
- * Saturneric<[email protected]> starting on May 12, 2021.
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#include "VersionCheckTask.h"
-
-#include <QMetaType>
-#include <memory>
-
-#include "GpgFrontendBuildInfo.h"
-
-namespace GpgFrontend::UI {
-
-VersionCheckTask::VersionCheckTask()
- : Task("version_check_task"),
- network_manager_(new QNetworkAccessManager(this)),
- current_version_(std::string("v") + std::to_string(VERSION_MAJOR) + "." +
- std::to_string(VERSION_MINOR) + "." +
- std::to_string(VERSION_PATCH)) {
- qRegisterMetaType<SoftwareVersion>("SoftwareVersion");
- version_.current_version = current_version_;
-}
-
-void VersionCheckTask::Run() {
- SetFinishAfterRun(false);
-
- try {
- using namespace nlohmann;
- SPDLOG_DEBUG("current version: {}", current_version_);
- std::string latest_version_url =
- "https://api.github.com/repos/saturneric/gpgfrontend/releases/latest";
-
- QNetworkRequest latest_request;
- latest_request.setUrl(QUrl(latest_version_url.c_str()));
- latest_reply_ = network_manager_->get(latest_request);
- connect(latest_reply_, &QNetworkReply::finished, this,
- &VersionCheckTask::slot_parse_latest_version_info);
-
- // loading done
- version_.load_info_done = true;
-
- } catch (...) {
- SPDLOG_ERROR("unknown error occurred");
- emit SignalTaskRunnableEnd(-1);
- }
-}
-
-void VersionCheckTask::slot_parse_latest_version_info() {
- version_.current_version = current_version_;
-
- try {
- if (latest_reply_ == nullptr ||
- latest_reply_->error() != QNetworkReply::NoError) {
- SPDLOG_ERROR("latest version request error");
- version_.latest_version = current_version_;
- } else {
- latest_reply_bytes_ = latest_reply_->readAll();
-
- auto latest_reply_json =
- nlohmann::json::parse(latest_reply_bytes_.toStdString());
-
- std::string latest_version = latest_reply_json["tag_name"];
-
- SPDLOG_INFO("latest version from Github: {}", latest_version);
-
- QRegularExpression re(R"(^[vV](\d+\.)?(\d+\.)?(\*|\d+))");
- auto version_match = re.match(latest_version.c_str());
- if (version_match.hasMatch()) {
- latest_version = version_match.captured(0).toStdString();
- SPDLOG_DEBUG("latest version matched: {}", latest_version);
- } else {
- latest_version = current_version_;
- SPDLOG_WARN("latest version unknown");
- }
-
- bool prerelease = latest_reply_json["prerelease"],
- draft = latest_reply_json["draft"];
- std::string publish_date = latest_reply_json["published_at"];
- std::string release_note = latest_reply_json["body"];
- version_.latest_version = latest_version;
- version_.latest_prerelease = prerelease;
- version_.latest_draft = draft;
- version_.publish_date = publish_date;
- version_.release_note = release_note;
- }
- } catch (...) {
- SPDLOG_ERROR("unknown error occurred");
- version_.load_info_done = false;
- }
-
- if (latest_reply_ != nullptr) {
- latest_reply_->deleteLater();
- }
-
- try {
- std::string current_version_url =
- "https://api.github.com/repos/saturneric/gpgfrontend/releases/tags/" +
- current_version_;
-
- QNetworkRequest current_request;
- current_request.setUrl(QUrl(current_version_url.c_str()));
- current_reply_ = network_manager_->get(current_request);
-
- connect(current_reply_, &QNetworkReply::finished, this,
- &VersionCheckTask::slot_parse_current_version_info);
- } catch (...) {
- SPDLOG_ERROR("current version request create error");
- emit SignalTaskRunnableEnd(-1);
- }
-}
-
-void VersionCheckTask::slot_parse_current_version_info() {
- try {
- if (current_reply_ == nullptr ||
- current_reply_->error() != QNetworkReply::NoError) {
- if (current_reply_ != nullptr) {
- SPDLOG_ERROR("current version request network error: {}",
- current_reply_->errorString().toStdString());
- } else {
- SPDLOG_ERROR(
- "current version request network error, null reply object");
- }
-
- version_.current_version_found = false;
- version_.load_info_done = false;
- } else {
- version_.current_version_found = true;
- current_reply_bytes_ = current_reply_->readAll();
- SPDLOG_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"],
- current_draft = current_reply_json["draft"];
- version_.latest_prerelease = current_prerelease;
- version_.latest_draft = current_draft;
- version_.load_info_done = true;
- }
- } catch (...) {
- SPDLOG_ERROR("unknown error occurred");
- version_.load_info_done = false;
- }
-
- SPDLOG_DEBUG("current version parse done: {}",
- version_.current_version_found);
-
- if (current_reply_ != nullptr) {
- current_reply_->deleteLater();
- }
-
- emit SignalUpgradeVersion(version_);
- emit SignalTaskRunnableEnd(0);
-}
-
-} // namespace GpgFrontend::UI
diff --git a/src/ui/thread/VersionCheckTask.h b/src/ui/thread/VersionCheckTask.h
deleted file mode 100644
index 0dbce17f..00000000
--- a/src/ui/thread/VersionCheckTask.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/**
- * Copyright (C) 2021 Saturneric
- *
- * This file is part of GpgFrontend.
- *
- * GpgFrontend is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * GpgFrontend is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
- *
- * The initial version of the source code is inherited from
- * the gpg4usb project, which is under GPL-3.0-or-later.
- *
- * All the source code of GpgFrontend was modified and released by
- * Saturneric<[email protected]> starting on May 12, 2021.
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifndef GPGFRONTEND_VERSIONCHECKTHREAD_H
-#define GPGFRONTEND_VERSIONCHECKTHREAD_H
-
-#include <memory>
-#include <string>
-
-#include "core/thread/Task.h"
-#include "ui/GpgFrontendUI.h"
-#include "ui/struct/SoftwareVersion.h"
-
-namespace GpgFrontend::UI {
-
-/**
- * @brief
- *
- */
-class VersionCheckTask : public Thread::Task {
- Q_OBJECT
-
- public:
- /**
- * @brief Construct a new Version Check Thread object
- *
- */
- explicit VersionCheckTask();
-
- signals:
-
- /**
- * @brief
- *
- * @param version
- */
- void SignalUpgradeVersion(SoftwareVersion version);
-
- protected:
- /**
- * @brief
-
- *
- */
- void Run() override;
-
- private slots:
-
- /**
- * @brief
- *
- */
- void slot_parse_latest_version_info();
-
- /**
- * @brief
- *
- */
- void slot_parse_current_version_info();
-
- private:
- QByteArray latest_reply_bytes_; ///<
- QByteArray current_reply_bytes_; ///<
- QNetworkReply* latest_reply_ = nullptr; ///< latest version info reply
- QNetworkReply* current_reply_ = nullptr; ///< current version info reply
- QNetworkAccessManager* network_manager_; ///<
- std::string current_version_;
- SoftwareVersion version_;
-};
-
-} // namespace GpgFrontend::UI
-
-#endif // GPGFRONTEND_VERSIONCHECKTHREAD_H