1
0

Merge branch 'dev/2.0.8/saturneric' into develop-2.0.8

This commit is contained in:
Saturneric 2022-05-25 10:09:00 +08:00
commit 38f78fa113
6 changed files with 152 additions and 98 deletions

View File

@ -10,7 +10,7 @@ Currently you can download GpgFrontend through various channels.
## SourceForge ## SourceForge
[![Download GpgFrontend](https://a.fsdn.com/con/app/sf-download-button)](https://sourceforge.net/projects/gogfrontend/files/latest/download) [![Download GogFrontend](https://a.fsdn.com/con/app/sf-download-button)](https://sourceforge.net/projects/gpgfrontend/files/latest/download)
## Microsoft Store ## Microsoft Store

View File

@ -53,7 +53,7 @@ The original code repository of Gpg Frontend is hosted on the server of Codes Dr
submitted to the code repository first. You can click [Here](https://global.git.codesdream.com/GpgFrontend.git) to visit submitted to the code repository first. You can click [Here](https://global.git.codesdream.com/GpgFrontend.git) to visit
the original code repository and track development progress. the original code repository and track development progress.
注意:中国用户请访问[这里](https://git.codesdream.com/GpgFrontend.git) 注意:中国用户请访问[这里](https://git.codesdream.com/main/GpgFrontend.git)
### License ### License

View File

@ -29,8 +29,10 @@
#include "SettingsKeyServer.h" #include "SettingsKeyServer.h"
#include "core/function/GlobalSettingStation.h" #include "core/function/GlobalSettingStation.h"
#include "core/thread/Task.h"
#include "core/thread/TaskRunnerGetter.h"
#include "ui/struct/SettingsObject.h" #include "ui/struct/SettingsObject.h"
#include "ui/thread/ListedKeyServerTestThread.h" #include "ui/thread/ListedKeyServerTestTask.h"
#include "ui_KeyServerSettings.h" #include "ui_KeyServerSettings.h"
namespace GpgFrontend::UI { namespace GpgFrontend::UI {
@ -128,8 +130,6 @@ void KeyserverTab::SetSettings() {
this->key_server_str_list_.append(key_server_str.c_str()); this->key_server_str_list_.append(key_server_str.c_str());
} }
auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
int default_key_server_index = key_server_json.Check("default_server", 0); int default_key_server_index = key_server_json.Check("default_server", 0);
std::string default_key_server = std::string default_key_server =
key_server_list[default_key_server_index].get<std::string>(); key_server_list[default_key_server_index].get<std::string>();
@ -223,9 +223,8 @@ void KeyserverTab::slot_refresh_table() {
} }
void KeyserverTab::slot_test_listed_key_server() { void KeyserverTab::slot_test_listed_key_server() {
auto timeout = auto timeout = QInputDialog::getInt(this, _("Set TCP Timeout"),
QInputDialog::getInt(this, _("Set TCP Timeout"), tr("timeout(ms): "), tr("timeout(ms): "), 2500, 200, 16000);
QLineEdit::Normal, 800, 3000);
QStringList urls; QStringList urls;
const auto row_size = ui_->keyServerListTable->rowCount(); const auto row_size = ui_->keyServerListTable->rowCount();
@ -234,28 +233,30 @@ void KeyserverTab::slot_test_listed_key_server() {
urls.push_back(keyserver_url); urls.push_back(keyserver_url);
} }
auto thread = new ListedKeyServerTestThread(urls, timeout, this); auto* task = new ListedKeyServerTestTask(urls, timeout, this);
connect(thread,
&GpgFrontend::UI::ListedKeyServerTestThread:: connect(
SignalKeyServerListTestResult, task,
this, [=](const QStringList& result) { &GpgFrontend::UI::ListedKeyServerTestTask::SignalKeyServerListTestResult,
const auto row_size = ui_->keyServerListTable->rowCount(); this,
if (result.size() != row_size) return; [=](std::vector<ListedKeyServerTestTask::KeyServerTestResultType>
ui_->keyServerListTable->blockSignals(true); result) {
for (int i = 0; i < row_size; i++) { const auto row_size = ui_->keyServerListTable->rowCount();
const auto status = result[i]; if (result.size() != row_size) return;
auto status_iem = ui_->keyServerListTable->item(i, 3); ui_->keyServerListTable->blockSignals(true);
if (status == "Reachable") { for (int i = 0; i < row_size; i++) {
status_iem->setText(_("Reachable")); const auto status = result[i];
status_iem->setForeground(QBrush(QColor::fromRgb(0, 255, 0))); auto status_iem = ui_->keyServerListTable->item(i, 3);
} else { if (status == ListedKeyServerTestTask::kTestResultType_Success) {
status_iem->setText(_("Not Reachable")); status_iem->setText(_("Reachable"));
status_iem->setForeground(QBrush(QColor::fromRgb(255, 0, 0))); status_iem->setForeground(QBrush(QColor::fromRgb(0, 255, 0)));
} } else {
} status_iem->setText(_("Not Reachable"));
ui_->keyServerListTable->blockSignals(false); status_iem->setForeground(QBrush(QColor::fromRgb(255, 0, 0)));
}); }
connect(thread, &QThread::finished, thread, &QThread::deleteLater); }
ui_->keyServerListTable->blockSignals(false);
});
// Waiting Dialog // Waiting Dialog
auto* waiting_dialog = new QProgressDialog(this); auto* waiting_dialog = new QProgressDialog(this);
@ -269,23 +270,18 @@ void KeyserverTab::slot_test_listed_key_server() {
waiting_dialog_label->setWordWrap(true); waiting_dialog_label->setWordWrap(true);
waiting_dialog->setLabel(waiting_dialog_label); waiting_dialog->setLabel(waiting_dialog_label);
waiting_dialog->resize(420, 120); waiting_dialog->resize(420, 120);
connect(thread, &QThread::finished, [=]() { waiting_dialog->setModal(true);
waiting_dialog->finished(0); connect(task, &Thread::Task::SignalTaskFinished, [=]() {
waiting_dialog->close();
waiting_dialog->deleteLater(); waiting_dialog->deleteLater();
}); });
connect(waiting_dialog, &QProgressDialog::canceled, [=]() {
LOG(INFO) << "cancel clicked";
if (thread->isRunning()) thread->terminate();
});
// Show Waiting Dialog // Show Waiting Dialog
waiting_dialog->show(); waiting_dialog->show();
waiting_dialog->setFocus(); waiting_dialog->setFocus();
thread->start(); Thread::TaskRunnerGetter::GetInstance()
QEventLoop loop; .GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Network)
connect(thread, &QThread::finished, &loop, &QEventLoop::quit); ->PostTask(task);
loop.exec();
} }
void KeyserverTab::contextMenuEvent(QContextMenuEvent* event) { void KeyserverTab::contextMenuEvent(QContextMenuEvent* event) {

View File

@ -0,0 +1,88 @@
/**
* 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<eric@bktus.com><eric@bktus.com> starting on May 12, 2021.
*
*/
#include "ListedKeyServerTestTask.h"
#include <vector>
GpgFrontend::UI::ListedKeyServerTestTask::ListedKeyServerTestTask(
const QStringList& urls, int timeout, QWidget* parent)
: urls_(urls),
timeout_(timeout),
network_manager_(new QNetworkAccessManager(this)),
result_(urls_.size(), kTestResultType_Error) {
qRegisterMetaType<std::vector<KeyServerTestResultType>>(
"std::vector<KeyServerTestResultType>");
}
void GpgFrontend::UI::ListedKeyServerTestTask::run() {
SetFinishAfterRun(false);
size_t index = 0;
for (const auto& url : urls_) {
auto key_url = QUrl{url};
LOG(INFO) << "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]() {
LOG(INFO) << "key server domain reply"
<< urls_[index].toStdString();
this->slot_process_network_reply(index, network_reply);
});
connect(timer, &QTimer::timeout, this, [this, index, network_reply]() {
LOG(INFO) << "timeout for key server" << urls_[index].toStdString();
if (network_reply->isRunning()) {
network_reply->abort();
this->slot_process_network_reply(index, network_reply);
}
});
timer->start(timeout_);
index++;
}
}
void GpgFrontend::UI::ListedKeyServerTestTask::slot_process_network_reply(
int index, QNetworkReply* reply) {
if (!reply->isRunning() && reply->error() == QNetworkReply::NoError) {
result_[index] = kTestResultType_Success;
} else {
if (!reply->isFinished())
result_[index] = kTestResultType_Timeout;
else
result_[index] = kTestResultType_Error;
}
if (++result_count_ == urls_.size()) {
emit SignalKeyServerListTestResult(result_);
emit SignalTaskFinished();
}
}

View File

@ -27,7 +27,10 @@
#ifndef GPGFRONTEND_LISTEDKEYSERVERTESTTHREAD_H #ifndef GPGFRONTEND_LISTEDKEYSERVERTESTTHREAD_H
#define GPGFRONTEND_LISTEDKEYSERVERTESTTHREAD_H #define GPGFRONTEND_LISTEDKEYSERVERTESTTHREAD_H
#include <vector>
#include "GpgFrontendUI.h" #include "GpgFrontendUI.h"
#include "core/thread/Task.h"
namespace GpgFrontend::UI { namespace GpgFrontend::UI {
@ -35,12 +38,17 @@ namespace GpgFrontend::UI {
* @brief * @brief
* *
*/ */
class ListedKeyServerTestThread : public QThread { class ListedKeyServerTestTask : public Thread::Task {
Q_OBJECT Q_OBJECT
public: public:
explicit ListedKeyServerTestThread(const QStringList& urls, int timeout, enum KeyServerTestResultType {
QWidget* parent = nullptr) kTestResultType_Success,
: QThread(parent), urls_(urls), timeout_(timeout) {} kTestResultType_Timeout,
kTestResultType_Error,
};
explicit ListedKeyServerTestTask(const QStringList& urls, int timeout,
QWidget* parent = nullptr);
signals: signals:
/** /**
@ -48,7 +56,8 @@ class ListedKeyServerTestThread : public QThread {
* *
* @param result * @param result
*/ */
void SignalKeyServerListTestResult(const QStringList& result); void SignalKeyServerListTestResult(
std::vector<KeyServerTestResultType> result);
protected: protected:
/** /**
@ -58,9 +67,19 @@ class ListedKeyServerTestThread : public QThread {
void run() override; void run() override;
private: private:
QStringList urls_; ///< QStringList urls_; ///<
QStringList result_; ///< std::vector<KeyServerTestResultType> result_; ///<
int timeout_ = 500; ///< QNetworkAccessManager* network_manager_; ///<
int timeout_ = 500; ///<
int result_count_ = 0; ///<
/**
* @brief
*
* @param index
* @param reply
*/
void slot_process_network_reply(int index, QNetworkReply* reply);
}; };
} // namespace GpgFrontend::UI } // namespace GpgFrontend::UI

View File

@ -1,49 +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.
*
* The source code version of this software was modified and released
* by Saturneric<eric@bktus.com><eric@bktus.com> starting on May 12, 2021.
*
*/
#include "ListedKeyServerTestThread.h"
void GpgFrontend::UI::ListedKeyServerTestThread::run() {
for (const auto& url : urls_) {
const auto keyserver_url = url;
auto key_url = QUrl{keyserver_url};
LOG(INFO) << "key server domain" << key_url.host().toStdString();
QTcpSocket socket(nullptr);
socket.abort();
socket.connectToHost(key_url.host(), 80);
if (socket.waitForConnected(timeout_)) {
result_.push_back("Reachable");
} else {
result_.push_back("Not Reachable");
}
socket.close();
}
emit SignalKeyServerListTestResult(result_);
}