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
[![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

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
the original code repository and track development progress.
注意:中国用户请访问[这里](https://git.codesdream.com/GpgFrontend.git)
注意:中国用户请访问[这里](https://git.codesdream.com/main/GpgFrontend.git)
### License

View File

@ -29,8 +29,10 @@
#include "SettingsKeyServer.h"
#include "core/function/GlobalSettingStation.h"
#include "core/thread/Task.h"
#include "core/thread/TaskRunnerGetter.h"
#include "ui/struct/SettingsObject.h"
#include "ui/thread/ListedKeyServerTestThread.h"
#include "ui/thread/ListedKeyServerTestTask.h"
#include "ui_KeyServerSettings.h"
namespace GpgFrontend::UI {
@ -128,8 +130,6 @@ void KeyserverTab::SetSettings() {
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);
std::string default_key_server =
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() {
auto timeout =
QInputDialog::getInt(this, _("Set TCP Timeout"), tr("timeout(ms): "),
QLineEdit::Normal, 800, 3000);
auto timeout = QInputDialog::getInt(this, _("Set TCP Timeout"),
tr("timeout(ms): "), 2500, 200, 16000);
QStringList urls;
const auto row_size = ui_->keyServerListTable->rowCount();
@ -234,28 +233,30 @@ void KeyserverTab::slot_test_listed_key_server() {
urls.push_back(keyserver_url);
}
auto thread = new ListedKeyServerTestThread(urls, timeout, this);
connect(thread,
&GpgFrontend::UI::ListedKeyServerTestThread::
SignalKeyServerListTestResult,
this, [=](const QStringList& result) {
const auto row_size = ui_->keyServerListTable->rowCount();
if (result.size() != row_size) return;
ui_->keyServerListTable->blockSignals(true);
for (int i = 0; i < row_size; i++) {
const auto status = result[i];
auto status_iem = ui_->keyServerListTable->item(i, 3);
if (status == "Reachable") {
status_iem->setText(_("Reachable"));
status_iem->setForeground(QBrush(QColor::fromRgb(0, 255, 0)));
} else {
status_iem->setText(_("Not Reachable"));
status_iem->setForeground(QBrush(QColor::fromRgb(255, 0, 0)));
}
}
ui_->keyServerListTable->blockSignals(false);
});
connect(thread, &QThread::finished, thread, &QThread::deleteLater);
auto* task = new ListedKeyServerTestTask(urls, timeout, this);
connect(
task,
&GpgFrontend::UI::ListedKeyServerTestTask::SignalKeyServerListTestResult,
this,
[=](std::vector<ListedKeyServerTestTask::KeyServerTestResultType>
result) {
const auto row_size = ui_->keyServerListTable->rowCount();
if (result.size() != row_size) return;
ui_->keyServerListTable->blockSignals(true);
for (int i = 0; i < row_size; i++) {
const auto status = result[i];
auto status_iem = ui_->keyServerListTable->item(i, 3);
if (status == ListedKeyServerTestTask::kTestResultType_Success) {
status_iem->setText(_("Reachable"));
status_iem->setForeground(QBrush(QColor::fromRgb(0, 255, 0)));
} else {
status_iem->setText(_("Not Reachable"));
status_iem->setForeground(QBrush(QColor::fromRgb(255, 0, 0)));
}
}
ui_->keyServerListTable->blockSignals(false);
});
// Waiting Dialog
auto* waiting_dialog = new QProgressDialog(this);
@ -269,23 +270,18 @@ void KeyserverTab::slot_test_listed_key_server() {
waiting_dialog_label->setWordWrap(true);
waiting_dialog->setLabel(waiting_dialog_label);
waiting_dialog->resize(420, 120);
connect(thread, &QThread::finished, [=]() {
waiting_dialog->finished(0);
waiting_dialog->setModal(true);
connect(task, &Thread::Task::SignalTaskFinished, [=]() {
waiting_dialog->close();
waiting_dialog->deleteLater();
});
connect(waiting_dialog, &QProgressDialog::canceled, [=]() {
LOG(INFO) << "cancel clicked";
if (thread->isRunning()) thread->terminate();
});
// Show Waiting Dialog
waiting_dialog->show();
waiting_dialog->setFocus();
thread->start();
QEventLoop loop;
connect(thread, &QThread::finished, &loop, &QEventLoop::quit);
loop.exec();
Thread::TaskRunnerGetter::GetInstance()
.GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Network)
->PostTask(task);
}
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
#define GPGFRONTEND_LISTEDKEYSERVERTESTTHREAD_H
#include <vector>
#include "GpgFrontendUI.h"
#include "core/thread/Task.h"
namespace GpgFrontend::UI {
@ -35,12 +38,17 @@ namespace GpgFrontend::UI {
* @brief
*
*/
class ListedKeyServerTestThread : public QThread {
class ListedKeyServerTestTask : public Thread::Task {
Q_OBJECT
public:
explicit ListedKeyServerTestThread(const QStringList& urls, int timeout,
QWidget* parent = nullptr)
: QThread(parent), urls_(urls), timeout_(timeout) {}
enum KeyServerTestResultType {
kTestResultType_Success,
kTestResultType_Timeout,
kTestResultType_Error,
};
explicit ListedKeyServerTestTask(const QStringList& urls, int timeout,
QWidget* parent = nullptr);
signals:
/**
@ -48,7 +56,8 @@ class ListedKeyServerTestThread : public QThread {
*
* @param result
*/
void SignalKeyServerListTestResult(const QStringList& result);
void SignalKeyServerListTestResult(
std::vector<KeyServerTestResultType> result);
protected:
/**
@ -58,9 +67,19 @@ class ListedKeyServerTestThread : public QThread {
void run() override;
private:
QStringList urls_; ///<
QStringList result_; ///<
int timeout_ = 500; ///<
QStringList urls_; ///<
std::vector<KeyServerTestResultType> result_; ///<
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

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_);
}