aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2022-06-05 11:39:38 +0000
committerSaturneric <[email protected]>2022-06-05 11:40:22 +0000
commit96009aba6df716ac3abdae1acdfa32125681bbf1 (patch)
tree5dc8e78ea5903a85062676ac69fb41abcc611ef1
parentfix(ui): fix crash when start app. (diff)
downloadGpgFrontend-96009aba6df716ac3abdae1acdfa32125681bbf1.tar.gz
GpgFrontend-96009aba6df716ac3abdae1acdfa32125681bbf1.zip
fix: fix some issues
1. fix crash when keyserver list is empty. 2. refactor KeyServerImportDialog 3. reduce header file including
-rw-r--r--src/ui/UserInterfaceUtils.cpp3
-rw-r--r--src/ui/UserInterfaceUtils.h10
-rw-r--r--src/ui/import_export/KeyServerImportDialog.cpp169
-rw-r--r--src/ui/import_export/KeyServerImportDialog.h36
-rw-r--r--src/ui/main_window/MainWindow.cpp9
-rw-r--r--src/ui/settings/SettingsKeyServer.cpp35
-rw-r--r--src/ui/thread/KeyServerImportTask.cpp64
-rw-r--r--src/ui/thread/KeyServerImportTask.h80
-rw-r--r--src/ui/thread/KeyServerSearchTask.cpp59
-rw-r--r--src/ui/thread/KeyServerSearchTask.h76
-rw-r--r--src/ui/thread/ListedKeyServerTestTask.h4
11 files changed, 428 insertions, 117 deletions
diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp
index adcbd6ff..586d72ab 100644
--- a/src/ui/UserInterfaceUtils.cpp
+++ b/src/ui/UserInterfaceUtils.cpp
@@ -276,6 +276,9 @@ void CommonUtils::SlotImportKeyFromKeyServer(
const int target_key_server_index =
key_server_json.Check("default_server", 0);
+ if (target_key_server_index >= key_server_list.size()) {
+ throw std::runtime_error("default_server index out of range");
+ }
target_keyserver =
key_server_list[target_key_server_index].get<std::string>();
diff --git a/src/ui/UserInterfaceUtils.h b/src/ui/UserInterfaceUtils.h
index bfd8a3ae..bcfa28d2 100644
--- a/src/ui/UserInterfaceUtils.h
+++ b/src/ui/UserInterfaceUtils.h
@@ -110,6 +110,16 @@ void process_operation(
/**
* @brief
*
+ * @param parent
+ * @param key_id
+ * @param key_server
+ */
+void import_key_from_keyserver(QWidget* parent, const std::string& key_id,
+ const std::string& key_server);
+
+/**
+ * @brief
+ *
*/
class CommonUtils : public QWidget {
Q_OBJECT
diff --git a/src/ui/import_export/KeyServerImportDialog.cpp b/src/ui/import_export/KeyServerImportDialog.cpp
index e359238c..3a61dbbe 100644
--- a/src/ui/import_export/KeyServerImportDialog.cpp
+++ b/src/ui/import_export/KeyServerImportDialog.cpp
@@ -28,12 +28,15 @@
#include "KeyServerImportDialog.h"
+#include <string>
#include <utility>
#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgKeyImportExporter.h"
+#include "thread/KeyServerImportTask.h"
#include "ui/SignalStation.h"
#include "ui/struct/SettingsObject.h"
+#include "ui/thread/KeyServerSearchTask.h"
namespace GpgFrontend::UI {
@@ -174,6 +177,9 @@ QComboBox* KeyServerImportDialog::create_comboBox() {
}
int default_key_server_index = key_server_json.Check("default_server", 0);
+ if (default_key_server_index >= key_server_list.size()) {
+ throw std::runtime_error("default_server index out of range");
+ }
std::string default_key_server =
key_server_list[default_key_server_index].get<std::string>();
@@ -227,45 +233,44 @@ void KeyServerImportDialog::slot_search() {
return;
}
- QUrl url_from_remote = key_server_combo_box_->currentText() +
- "/pks/lookup?search=" + search_line_edit_->text() +
- "&op=index&options=mr";
- network_access_manager_ = new QNetworkAccessManager(this);
- QNetworkReply* reply =
- network_access_manager_->get(QNetworkRequest(url_from_remote));
+ auto* task = new KeyServerSearchTask(
+ key_server_combo_box_->currentText().toStdString(),
+ search_line_edit_->text().toStdString());
- connect(reply, &QNetworkReply::finished, this,
+ connect(task, &KeyServerSearchTask::SignalKeyServerSearchResult, this,
&KeyServerImportDialog::slot_search_finished);
+ connect(task, &KeyServerSearchTask::SignalKeyServerSearchResult, this, [=]() {
+ this->search_button_->setDisabled(false);
+ this->key_server_combo_box_->setDisabled(false);
+ this->search_line_edit_->setReadOnly(false);
+ this->import_button_->setDisabled(false);
+ set_loading(false);
+ });
+
set_loading(true);
this->search_button_->setDisabled(true);
this->key_server_combo_box_->setDisabled(true);
this->search_line_edit_->setReadOnly(true);
this->import_button_->setDisabled(true);
- while (reply->isRunning()) {
- QApplication::processEvents();
- }
-
- this->search_button_->setDisabled(false);
- this->key_server_combo_box_->setDisabled(false);
- this->search_line_edit_->setReadOnly(false);
- this->import_button_->setDisabled(false);
- set_loading(false);
+ Thread::TaskRunnerGetter::GetInstance()
+ .GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Network)
+ ->PostTask(task);
}
-void KeyServerImportDialog::slot_search_finished() {
- LOG(INFO) << "Called";
-
- auto* reply = qobject_cast<QNetworkReply*>(sender());
+void KeyServerImportDialog::slot_search_finished(
+ QNetworkReply::NetworkError error, QByteArray buffer) {
+ LOG(INFO) << "Called" << error << buffer.size();
+ LOG(INFO) << buffer.toStdString();
keys_table_->clearContents();
keys_table_->setRowCount(0);
- QString first_line = QString(reply->readLine(1024));
- auto error = reply->error();
+ auto stream = QTextStream(buffer);
+
if (error != QNetworkReply::NoError) {
- LOG(INFO) << "Error From Reply" << reply->errorString().toStdString();
+ LOG(INFO) << "Error From Reply" << error;
switch (error) {
case QNetworkReply::ContentNotFoundError:
@@ -283,8 +288,9 @@ void KeyServerImportDialog::slot_search_finished() {
return;
}
- if (first_line.contains("Error")) {
- QString text = QString(reply->readLine(1024));
+ if (stream.readLine().contains("Error")) {
+ auto text = stream.readLine(1024);
+
if (text.contains("Too many responses")) {
set_message(
"<h4>" + QString(_("Too many responses from keyserver!")) + "</h4>",
@@ -324,11 +330,14 @@ void KeyServerImportDialog::slot_search_finished() {
} else {
int row = 0;
bool strikeout = false;
- while (reply->canReadLine()) {
- auto line_buff = reply->readLine().trimmed();
- QString decoded =
- QString::fromUtf8(line_buff.constData(), line_buff.size());
- QStringList line = decoded.split(":");
+
+ // read lines until end of steam
+ while (!stream.atEnd()) {
+ QStringList line =
+ QString::fromUtf8(QByteArray::fromPercentEncoding(
+ stream.readLine().trimmed().toUtf8()))
+ .split(":");
+
// TODO: have a look at two following pub lines
if (line[0] == "pub") {
strikeout = false;
@@ -354,7 +363,9 @@ void KeyServerImportDialog::slot_search_finished() {
}
}
- QStringList line2 = QString(reply->readLine()).split(":");
+ QStringList line2 = QString(QByteArray::fromPercentEncoding(
+ stream.readLine().trimmed().toUtf8()))
+ .split(":");
auto* uid = new QTableWidgetItem();
if (line2.size() > 1) {
@@ -400,32 +411,45 @@ void KeyServerImportDialog::slot_search_finished() {
keys_table_->resizeColumnsToContents();
import_button_->setDisabled(keys_table_->size().isEmpty());
}
- reply->deleteLater();
}
void KeyServerImportDialog::slot_import() {
- LOG(INFO) << _("Current Row") << keys_table_->currentRow();
- if (keys_table_->currentRow() > -1) {
- QString keyid = keys_table_->item(keys_table_->currentRow(), 2)->text();
- SlotImport(QStringList(keyid), key_server_combo_box_->currentText());
+ std::vector<std::string> key_ids;
+ const int row_count = keys_table_->rowCount();
+ for (int i = 0; i < row_count; ++i) {
+ if (keys_table_->item(i, 2)->isSelected()) {
+ QString keyid = keys_table_->item(i, 2)->text();
+ key_ids.push_back(keyid.toStdString());
+ }
}
+ if (!key_ids.empty())
+ SlotImport(key_ids, key_server_combo_box_->currentText().toStdString());
}
void KeyServerImportDialog::SlotImport(const KeyIdArgsListPtr& keys) {
+ // keyserver host url
std::string target_keyserver;
+
if (key_server_combo_box_ != nullptr) {
target_keyserver = key_server_combo_box_->currentText().toStdString();
}
if (target_keyserver.empty()) {
try {
- auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+ SettingsObject key_server_json("key_server");
+ const auto key_server_list =
+ key_server_json.Check("server_list", nlohmann::json::array());
- target_keyserver = settings.lookup("keyserver.default_server").c_str();
+ int default_key_server_index = key_server_json.Check("default_server", 0);
+ if (default_key_server_index >= key_server_list.size()) {
+ throw std::runtime_error("default_server index out of range");
+ }
+ std::string default_key_server =
+ key_server_list[default_key_server_index].get<std::string>();
- LOG(INFO) << _("Set target Key Server to default Key Server")
- << target_keyserver;
+ target_keyserver = default_key_server;
} catch (...) {
- LOG(ERROR) << _("Cannot read default_keyserver From Settings");
+ LOG(ERROR) << _("Setting Operation Error") << "server_list"
+ << "default_server";
QMessageBox::critical(
nullptr, _("Default Keyserver Not Found"),
_("Cannot read default keyserver from your settings, "
@@ -433,42 +457,31 @@ void KeyServerImportDialog::SlotImport(const KeyIdArgsListPtr& keys) {
return;
}
}
- auto key_ids = QStringList();
- for (const auto& key_id : *keys)
- key_ids.append(QString::fromStdString(key_id));
- SlotImport(key_ids, QUrl(target_keyserver.c_str()));
-}
-
-void KeyServerImportDialog::SlotImport(const QStringList& keyIds,
- const QUrl& keyserverUrl) {
- for (const auto& keyId : keyIds) {
- QUrl req_url(keyserverUrl.scheme() + "://" + keyserverUrl.host() +
- "/pks/lookup?op=get&search=0x" + keyId + "&options=mr");
-
- LOG(INFO) << "request url" << req_url.toString().toStdString();
- auto manager = new QNetworkAccessManager(this);
-
- QNetworkReply* reply = manager->get(QNetworkRequest(req_url));
- connect(reply, &QNetworkReply::finished, this,
- [&, keyId]() { this->slot_import_finished(keyId); });
- LOG(INFO) << "loading start";
- set_loading(true);
- while (reply->isRunning()) QApplication::processEvents();
- set_loading(false);
- LOG(INFO) << "loading done";
+ std::vector<std::string> key_ids;
+ for (const auto& key_id : *keys) {
+ key_ids.push_back(key_id);
}
+ SlotImport(key_ids, target_keyserver);
}
-void KeyServerImportDialog::slot_import_finished(const QString& keyid) {
- LOG(INFO) << _("Called");
+void KeyServerImportDialog::SlotImport(std::vector<std::string> key_ids,
+ std::string keyserver_url) {
+ auto* task = new KeyServerImportTask(keyserver_url, key_ids);
- auto* reply = qobject_cast<QNetworkReply*>(sender());
+ connect(task, &KeyServerImportTask::SignalKeyServerImportResult, this,
+ &KeyServerImportDialog::slot_import_finished);
- QByteArray key = reply->readAll();
+ Thread::TaskRunnerGetter::GetInstance()
+ .GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Network)
+ ->PostTask(task);
+}
+
+void KeyServerImportDialog::slot_import_finished(
+ QNetworkReply::NetworkError error, QByteArray buffer) {
+ LOG(INFO) << _("Called");
- auto error = reply->error();
if (error != QNetworkReply::NoError) {
- LOG(ERROR) << "Error From Reply" << reply->errorString().toStdString();
+ LOG(ERROR) << "Error From Reply" << buffer.toStdString();
if (!m_automatic_) {
switch (error) {
case QNetworkReply::ContentNotFoundError:
@@ -486,10 +499,8 @@ void KeyServerImportDialog::slot_import_finished(const QString& keyid) {
} else {
switch (error) {
case QNetworkReply::ContentNotFoundError:
- QMessageBox::critical(
- nullptr, _("Public key Not Found"),
- QString(_("Public key fingerprint %1 not found in the Keyserver"))
- .arg(keyid));
+ QMessageBox::critical(nullptr, _("Key Not Found"),
+ QString(_("key not found in the Keyserver")));
break;
case QNetworkReply::TimeoutError:
QMessageBox::critical(nullptr, _("Timeout"), "Connection timeout");
@@ -510,9 +521,8 @@ void KeyServerImportDialog::slot_import_finished(const QString& keyid) {
return;
}
- reply->deleteLater();
-
- this->import_keys(std::make_unique<ByteArray>(key.constData(), key.length()));
+ this->import_keys(
+ std::make_unique<ByteArray>(buffer.constData(), buffer.length()));
if (!m_automatic_) {
set_message(QString("<h4>") + _("Key Imported") + "</h4>", false);
@@ -522,14 +532,17 @@ void KeyServerImportDialog::slot_import_finished(const QString& keyid) {
void KeyServerImportDialog::import_keys(ByteArrayPtr in_data) {
GpgImportInformation result =
GpgKeyImportExporter::GetInstance().ImportKey(std::move(in_data));
+
+ // refresh the key database
emit SignalKeyImported();
+
QWidget* _parent = qobject_cast<QWidget*>(parent());
if (m_automatic_) {
auto dialog = new KeyImportDetailDialog(result, true, _parent);
dialog->show();
this->accept();
} else {
- auto dialog = new KeyImportDetailDialog(result, false, _parent);
+ auto dialog = new KeyImportDetailDialog(result, false, this);
dialog->exec();
}
}
diff --git a/src/ui/import_export/KeyServerImportDialog.h b/src/ui/import_export/KeyServerImportDialog.h
index 37362859..6bde96b8 100644
--- a/src/ui/import_export/KeyServerImportDialog.h
+++ b/src/ui/import_export/KeyServerImportDialog.h
@@ -29,6 +29,8 @@
#ifndef __KEY_SERVER_IMPORT_DIALOG_H__
#define __KEY_SERVER_IMPORT_DIALOG_H__
+#include <string>
+
#include "KeyImportDetailDialog.h"
#include "core/GpgContext.h"
#include "ui/GpgFrontendUI.h"
@@ -74,7 +76,8 @@ class KeyServerImportDialog : public QDialog {
* @param keyIds
* @param keyserverUrl
*/
- void SlotImport(const QStringList& keyIds, const QUrl& keyserverUrl);
+ void SlotImport(std::vector<std::string> key_ids_list,
+ std::string keyserver_url);
signals:
@@ -87,7 +90,7 @@ class KeyServerImportDialog : public QDialog {
private slots:
/**
- * @brief
+ * @brief import key(s) for the key table selection
*
*/
void slot_import();
@@ -96,14 +99,16 @@ class KeyServerImportDialog : public QDialog {
* @brief
*
*/
- void slot_search_finished();
+ void slot_search_finished(QNetworkReply::NetworkError reply,
+ QByteArray buffer);
/**
* @brief
*
* @param keyid
*/
- void slot_import_finished(const QString& keyid);
+ void slot_import_finished(QNetworkReply::NetworkError error,
+ QByteArray buffer);
/**
* @brief
@@ -164,18 +169,17 @@ class KeyServerImportDialog : public QDialog {
bool m_automatic_ = false; ///<
- QLineEdit* search_line_edit_{}; ///<
- QComboBox* key_server_combo_box_{}; ///<
- QProgressBar* waiting_bar_; ///<
- QLabel* search_label_{}; ///<
- QLabel* key_server_label_{}; ///<
- QLabel* message_{}; ///<
- QLabel* icon_{}; ///<
- QPushButton* close_button_{}; ///<
- QPushButton* import_button_{}; ///<
- QPushButton* search_button_{}; ///<
- QTableWidget* keys_table_{}; ///<
- QNetworkAccessManager* network_access_manager_{}; ///<
+ QLineEdit* search_line_edit_{}; ///<
+ QComboBox* key_server_combo_box_{}; ///<
+ QProgressBar* waiting_bar_; ///<
+ QLabel* search_label_{}; ///<
+ QLabel* key_server_label_{}; ///<
+ QLabel* message_{}; ///<
+ QLabel* icon_{}; ///<
+ QPushButton* close_button_{}; ///<
+ QPushButton* import_button_{}; ///<
+ QPushButton* search_button_{}; ///<
+ QTableWidget* keys_table_{}; ///<
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp
index d04e3dbd..e6da65d2 100644
--- a/src/ui/main_window/MainWindow.cpp
+++ b/src/ui/main_window/MainWindow.cpp
@@ -185,13 +185,11 @@ void MainWindow::restore_settings() {
LOG(INFO) << "restore settings key_server";
SettingsObject key_server_json("key_server");
-
- if (!key_server_json.contains("server_list")) {
+ if (!key_server_json.contains("server_list") ||
+ key_server_json["server_list"].empty()) {
key_server_json["server_list"] = {"https://keyserver.ubuntu.com",
- "http://keys.gnupg.net",
- "http://pool.sks-keyservers.net"};
+ "https://keys.openpgp.org"};
}
-
if (!key_server_json.contains("default_server")) {
key_server_json["default_server"] = 0;
}
@@ -264,6 +262,7 @@ void MainWindow::save_settings() {
main_windows_state["window_size"]["width"] = size().width();
main_windows_state["window_size"]["height"] = size().height();
+ main_windows_state["window_save"] = true;
bool save_key_checked = settings.lookup("general.save_key_checked");
diff --git a/src/ui/settings/SettingsKeyServer.cpp b/src/ui/settings/SettingsKeyServer.cpp
index 94655871..2c09b66c 100644
--- a/src/ui/settings/SettingsKeyServer.cpp
+++ b/src/ui/settings/SettingsKeyServer.cpp
@@ -120,23 +120,30 @@ KeyserverTab::KeyserverTab(QWidget* parent)
* appropriately
**********************************/
void KeyserverTab::SetSettings() {
- SettingsObject key_server_json("key_server");
-
- const auto key_server_list =
- key_server_json.Check("server_list", nlohmann::json::array());
+ try {
+ SettingsObject key_server_json("key_server");
- for (const auto& key_server : key_server_list) {
- const auto key_server_str = key_server.get<std::string>();
- this->key_server_str_list_.append(key_server_str.c_str());
- }
+ const auto key_server_list =
+ key_server_json.Check("server_list", nlohmann::json::array());
- int default_key_server_index = key_server_json.Check("default_server", 0);
- std::string default_key_server =
- key_server_list[default_key_server_index].get<std::string>();
+ for (const auto& key_server : key_server_list) {
+ const auto key_server_str = key_server.get<std::string>();
+ this->key_server_str_list_.append(key_server_str.c_str());
+ }
- if (!key_server_str_list_.contains(default_key_server.c_str()))
- key_server_str_list_.append(default_key_server.c_str());
- default_key_server_ = QString::fromStdString(default_key_server);
+ int default_key_server_index = key_server_json.Check("default_server", 0);
+ if (default_key_server_index >= key_server_list.size()) {
+ throw std::runtime_error("default_server index out of range");
+ }
+ std::string default_key_server =
+ key_server_list[default_key_server_index].get<std::string>();
+
+ if (!key_server_str_list_.contains(default_key_server.c_str()))
+ key_server_str_list_.append(default_key_server.c_str());
+ default_key_server_ = QString::fromStdString(default_key_server);
+ } catch (const std::exception& e) {
+ LOG(ERROR) << "Error reading key-server settings: " << e.what();
+ }
}
void KeyserverTab::slot_add_key_server() {
diff --git a/src/ui/thread/KeyServerImportTask.cpp b/src/ui/thread/KeyServerImportTask.cpp
new file mode 100644
index 00000000..bf3e1822
--- /dev/null
+++ b/src/ui/thread/KeyServerImportTask.cpp
@@ -0,0 +1,64 @@
+/**
+ * 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.
+ *
+ * The source code version of this software was modified and released
+ * by Saturneric<[email protected]><[email protected]> starting on May 12, 2021.
+ *
+ */
+
+#include "ui/thread/KeyServerImportTask.h"
+
+#include <vector>
+
+GpgFrontend::UI::KeyServerImportTask::KeyServerImportTask(
+ std::string keyserver_url, std::vector<std::string> keyids)
+ : keyserver_url_(std::move(keyserver_url)),
+ keyids_(std::move(keyids)),
+ manager_(new QNetworkAccessManager(this)) {}
+
+void GpgFrontend::UI::KeyServerImportTask::run() {
+ SetFinishAfterRun(false);
+
+ QUrl keyserver_url = QUrl(keyserver_url_.c_str());
+ 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");
+
+ reply_ = manager_->get(QNetworkRequest(req_url));
+
+ connect(reply_, &QNetworkReply::finished, this,
+ &KeyServerImportTask::dealing_reply_from_server);
+ }
+}
+
+void GpgFrontend::UI::KeyServerImportTask::dealing_reply_from_server() {
+ QByteArray buffer;
+ QNetworkReply::NetworkError network_reply = reply_->error();
+ if (network_reply == QNetworkReply::NoError) {
+ buffer = reply_->readAll();
+ }
+ emit SignalKeyServerImportResult(network_reply, buffer);
+
+ if (result_count_++ == keyids_.size() - 1) {
+ emit SignalTaskFinished();
+ }
+} \ No newline at end of file
diff --git a/src/ui/thread/KeyServerImportTask.h b/src/ui/thread/KeyServerImportTask.h
new file mode 100644
index 00000000..7d3b66c6
--- /dev/null
+++ b/src/ui/thread/KeyServerImportTask.h
@@ -0,0 +1,80 @@
+/**
+ * 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.
+ *
+ * The source code version of this software was modified and released
+ * by Saturneric<[email protected]><[email protected]> starting on May 12, 2021.
+ *
+ */
+
+#ifndef GPGFRONTEND_KEYSERVERIMPORTTASK_H
+#define GPGFRONTEND_KEYSERVERIMPORTTASK_H
+
+#include "GpgFrontendUI.h"
+
+namespace GpgFrontend::UI {
+class KeyServerImportTask : public Thread::Task {
+ Q_OBJECT
+ public:
+ /**
+ * @brief Construct a new Key Server Search Task object
+ *
+ * @param keyserver_url
+ * @param search_string
+ */
+ KeyServerImportTask(std::string keyserver_url,
+ std::vector<std::string> keyid);
+
+ signals:
+
+ /**
+ * @brief
+ *
+ * @param result
+ */
+ void SignalKeyServerImportResult(QNetworkReply::NetworkError reply,
+ QByteArray buffer);
+
+ protected:
+ /**
+ * @brief
+ *
+ */
+ void run() override;
+
+ private slots:
+
+ /**
+ * @brief
+ *
+ */
+ void dealing_reply_from_server();
+
+ private:
+ std::string keyserver_url_; ///<
+ std::vector<std::string> 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
new file mode 100644
index 00000000..bdbb8080
--- /dev/null
+++ b/src/ui/thread/KeyServerSearchTask.cpp
@@ -0,0 +1,59 @@
+/**
+ * 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.
+ *
+ * The source code version of this software was modified and released
+ * by Saturneric<[email protected]><[email protected]> starting on May 12, 2021.
+ *
+ */
+
+#include "ui/thread/KeyServerSearchTask.h"
+
+#include <utility>
+
+GpgFrontend::UI::KeyServerSearchTask::KeyServerSearchTask(
+ std::string keyserver_url, std::string search_string)
+ : keyserver_url_(std::move(keyserver_url)),
+ search_string_(std::move(search_string)),
+ manager_(new QNetworkAccessManager(this)) {}
+
+void GpgFrontend::UI::KeyServerSearchTask::run() {
+ SetFinishAfterRun(false);
+
+ QUrl url_from_remote =
+ QString::fromStdString(keyserver_url_) +
+ "/pks/lookup?search=" + QString::fromStdString(search_string_) +
+ "&op=index&options=mr";
+
+ reply_ = manager_->get(QNetworkRequest(url_from_remote));
+
+ connect(reply_, &QNetworkReply::finished, this,
+ &KeyServerSearchTask::dealing_reply_from_server);
+}
+
+void GpgFrontend::UI::KeyServerSearchTask::dealing_reply_from_server() {
+ QByteArray buffer;
+ QNetworkReply::NetworkError network_reply = reply_->error();
+ if(network_reply == QNetworkReply::NoError) {
+ buffer = reply_->readAll();
+ }
+ emit SignalKeyServerSearchResult(network_reply, buffer);
+ emit SignalTaskFinished();
+}
diff --git a/src/ui/thread/KeyServerSearchTask.h b/src/ui/thread/KeyServerSearchTask.h
new file mode 100644
index 00000000..3333e949
--- /dev/null
+++ b/src/ui/thread/KeyServerSearchTask.h
@@ -0,0 +1,76 @@
+/**
+ * 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.
+ *
+ * The source code version of this software was modified and released
+ * by Saturneric<[email protected]><[email protected]> starting on May 12, 2021.
+ *
+ */
+
+#ifndef GPGFRONTEND_KEYSERVERSEARCHTASK_H
+#define GPGFRONTEND_KEYSERVERSEARCHTASK_H
+
+#include "GpgFrontendUI.h"
+
+namespace GpgFrontend::UI {
+
+class KeyServerSearchTask : public Thread::Task {
+ Q_OBJECT
+ public:
+ /**
+ * @brief Construct a new Key Server Search Task object
+ *
+ * @param keyserver_url
+ * @param search_string
+ */
+ KeyServerSearchTask(std::string keyserver_url, std::string search_string);
+
+ signals:
+
+ /**
+ * @brief
+ *
+ * @param result
+ */
+ void SignalKeyServerSearchResult(QNetworkReply::NetworkError reply,
+ QByteArray buffer);
+
+ protected:
+ /**
+ * @brief
+ *
+ */
+ void run() override;
+
+ private slots:
+
+ void dealing_reply_from_server();
+
+ private:
+ std::string keyserver_url_; ///<
+ std::string 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.h b/src/ui/thread/ListedKeyServerTestTask.h
index 8edaccb0..aa1bac5e 100644
--- a/src/ui/thread/ListedKeyServerTestTask.h
+++ b/src/ui/thread/ListedKeyServerTestTask.h
@@ -27,11 +27,7 @@
#ifndef GPGFRONTEND_LISTEDKEYSERVERTESTTHREAD_H
#define GPGFRONTEND_LISTEDKEYSERVERTESTTHREAD_H
-#include <vector>
-
#include "GpgFrontendUI.h"
-#include "core/thread/Task.h"
-
namespace GpgFrontend::UI {
/**