diff options
author | Saturn&Eric <[email protected]> | 2022-03-19 07:55:26 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2022-03-19 07:55:26 +0000 |
commit | d1e305cda3a8ddc066213f3309826caf29064423 (patch) | |
tree | fabeb080e66df2fe944011ba5690f680ebabe7b6 /src/ui/UserInterfaceUtils.cpp | |
parent | <doc>(project): update README.md. (diff) | |
parent | Merge branch 'main' into develop-2.0.5 (diff) | |
download | GpgFrontend-d1e305cda3a8ddc066213f3309826caf29064423.tar.gz GpgFrontend-d1e305cda3a8ddc066213f3309826caf29064423.zip |
Merge pull request #49 from saturneric/develop-2.0.5
v2.0.5
Diffstat (limited to 'src/ui/UserInterfaceUtils.cpp')
-rw-r--r-- | src/ui/UserInterfaceUtils.cpp | 154 |
1 files changed, 83 insertions, 71 deletions
diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp index 967dcc32..8353d28b 100644 --- a/src/ui/UserInterfaceUtils.cpp +++ b/src/ui/UserInterfaceUtils.cpp @@ -1,4 +1,6 @@ /** + * Copyright (C) 2021 Saturneric + * * This file is part of GpgFrontend. * * GpgFrontend is free software: you can redistribute it and/or modify @@ -6,19 +8,21 @@ * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * Foobar is distributed in the hope that it will be useful, + * 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 Foobar. If not, see <https://www.gnu.org/licenses/>. + * 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 initial version of the source code is inherited from gpg4usb-team. - * Their source code version also complies with GNU General Public License. + * All the source code of GpgFrontend was modified and released by + * Saturneric<[email protected]> starting on May 12, 2021. * - * The source code version of this software was modified and released - * by Saturneric<[email protected]> starting on May 12, 2021. + * SPDX-License-Identifier: GPL-3.0-or-later * */ @@ -26,23 +30,24 @@ #include <utility> -#include "gpg/result_analyse/ResultAnalyse.h" +#include "core/function/FileOperator.h" +#include "core/function/result_analyse/GpgResultAnalyse.h" #include "ui/SignalStation.h" -#include "ui/WaitingDialog.h" -#include "ui/settings/GlobalSettingStation.h" -#include "ui/smtp/SendMailDialog.h" +#include "ui/dialog/WaitingDialog.h" +#include "ui/mail/SendMailDialog.h" +#include "core/function/GlobalSettingStation.h" #include "ui/widgets/InfoBoardWidget.h" #include "ui/widgets/TextEdit.h" namespace GpgFrontend::UI { std::unique_ptr<GpgFrontend::UI::CommonUtils> - GpgFrontend::UI::CommonUtils::_instance = nullptr; + GpgFrontend::UI::CommonUtils::instance_ = nullptr; #ifdef SMTP_SUPPORT -void send_an_email(QWidget* parent, InfoBoardWidget* info_board, - const QString& text, bool attach_signature) { - info_board->addOptionalAction(_("Send Encrypted Mail"), [=]() { +void send_an_email(QWidget *parent, InfoBoardWidget *info_board, + const QString &text, bool attach_signature) { + info_board->AddOptionalAction(_("Send Encrypted Mail"), [=]() { bool smtp_enabled = false; try { smtp_enabled = GlobalSettingStation::GetInstance().GetUISettings().lookup( @@ -52,8 +57,8 @@ void send_an_email(QWidget* parent, InfoBoardWidget* info_board, } if (smtp_enabled) { auto dialog = new SendMailDialog(text, parent); - dialog->setContentEncryption(false); - dialog->setAttachSignature(attach_signature); + dialog->SetContentEncryption(false); + dialog->SetAttachSignature(attach_signature); dialog->show(); } else { QMessageBox::warning(nullptr, _("Function Disabled"), @@ -64,17 +69,17 @@ void send_an_email(QWidget* parent, InfoBoardWidget* info_board, } #endif -void show_verify_details(QWidget* parent, InfoBoardWidget* info_board, - GpgError error, const GpgVerifyResult& verify_result) { +void show_verify_details(QWidget *parent, InfoBoardWidget *info_board, + GpgError error, const GpgVerifyResult &verify_result) { // take out result - info_board->resetOptionActionsMenu(); - info_board->addOptionalAction("Show Verify Details", [=]() { + info_board->ResetOptionActionsMenu(); + info_board->AddOptionalAction("Show Verify Details", [=]() { VerifyDetailsDialog(parent, error, verify_result); }); } -void import_unknown_key_from_keyserver(QWidget* parent, - const VerifyResultAnalyse& verify_res) { +void import_unknown_key_from_keyserver( + QWidget *parent, const GpgVerifyResultAnalyse &verify_res) { QMessageBox::StandardButton reply; reply = QMessageBox::question( parent, _("Public key not found locally"), @@ -85,57 +90,57 @@ void import_unknown_key_from_keyserver(QWidget* parent, if (reply == QMessageBox::Yes) { auto dialog = KeyServerImportDialog(true, parent); auto key_ids = std::make_unique<KeyIdArgsList>(); - auto* signature = verify_res.GetSignatures(); + auto *signature = verify_res.GetSignatures(); while (signature != nullptr) { LOG(INFO) << "signature fpr" << signature->fpr; key_ids->push_back(signature->fpr); signature = signature->next; } dialog.show(); - dialog.slotImport(key_ids); + dialog.SlotImport(key_ids); } } -void refresh_info_board(InfoBoardWidget* info_board, int status, - const std::string& report_text) { +void refresh_info_board(InfoBoardWidget *info_board, int status, + const std::string &report_text) { if (status < 0) - info_board->slotRefresh(QString::fromStdString(report_text), + info_board->SlotRefresh(QString::fromStdString(report_text), INFO_ERROR_CRITICAL); else if (status > 0) - info_board->slotRefresh(QString::fromStdString(report_text), INFO_ERROR_OK); + info_board->SlotRefresh(QString::fromStdString(report_text), INFO_ERROR_OK); else - info_board->slotRefresh(QString::fromStdString(report_text), + info_board->SlotRefresh(QString::fromStdString(report_text), INFO_ERROR_WARN); } -void process_result_analyse(TextEdit* edit, InfoBoardWidget* info_board, - const ResultAnalyse& result_analyse) { - info_board->associateTabWidget(edit->tabWidget); - refresh_info_board(info_board, result_analyse.getStatus(), - result_analyse.getResultReport()); +void process_result_analyse(TextEdit *edit, InfoBoardWidget *info_board, + const GpgResultAnalyse &result_analyse) { + info_board->AssociateTabWidget(edit->tab_widget_); + refresh_info_board(info_board, result_analyse.GetStatus(), + result_analyse.GetResultReport()); } -void process_result_analyse(TextEdit* edit, InfoBoardWidget* info_board, - const ResultAnalyse& result_analyse_a, - const ResultAnalyse& result_analyse_b) { +void process_result_analyse(TextEdit *edit, InfoBoardWidget *info_board, + const GpgResultAnalyse &result_analyse_a, + const GpgResultAnalyse &result_analyse_b) { LOG(INFO) << "process_result_analyse Started"; - info_board->associateTabWidget(edit->tabWidget); + info_board->AssociateTabWidget(edit->tab_widget_); refresh_info_board( info_board, - std::min(result_analyse_a.getStatus(), result_analyse_b.getStatus()), - result_analyse_a.getResultReport() + result_analyse_b.getResultReport()); + std::min(result_analyse_a.GetStatus(), result_analyse_b.GetStatus()), + result_analyse_a.GetResultReport() + result_analyse_b.GetResultReport()); } -void process_operation(QWidget* parent, const std::string& waiting_title, - const std::function<void()>& func) { +void process_operation(QWidget *parent, const std::string &waiting_title, + const std::function<void()> &func) { auto thread = QThread::create(func); - QApplication::connect(thread, SIGNAL(finished()), thread, - SLOT(deleteLater())); + QApplication::connect(thread, &QThread::finished, thread, + &QThread::deleteLater); thread->start(); - auto* dialog = + auto *dialog = new WaitingDialog(QString::fromStdString(waiting_title), parent); while (thread->isRunning()) { QApplication::processEvents(); @@ -143,17 +148,18 @@ void process_operation(QWidget* parent, const std::string& waiting_title, dialog->close(); } -CommonUtils* CommonUtils::GetInstance() { - if (_instance == nullptr) { - _instance = std::make_unique<CommonUtils>(); +CommonUtils *CommonUtils::GetInstance() { + if (instance_ == nullptr) { + instance_ = std::make_unique<CommonUtils>(); } - return _instance.get(); + return instance_.get(); } CommonUtils::CommonUtils() : QWidget(nullptr) { - connect(this, SIGNAL(signalKeyStatusUpdated()), SignalStation::GetInstance(), - SIGNAL(KeyDatabaseRefresh())); - connect(this, &CommonUtils::signalGnupgNotInstall, this, []() { + connect(this, &CommonUtils::SignalKeyStatusUpdated, + SignalStation::GetInstance(), + &SignalStation::SignalKeyDatabaseRefresh); + connect(this, &CommonUtils::SignalGnupgNotInstall, this, []() { QMessageBox::critical( nullptr, _("ENV Loading Failed"), _("Gnupg(gpg) is not installed correctly, please follow the " @@ -164,42 +170,48 @@ CommonUtils::CommonUtils() : QWidget(nullptr) { }); } -void CommonUtils::slotImportKeys(QWidget* parent, - const std::string& in_buffer) { +void CommonUtils::SlotImportKeys(QWidget *parent, + const std::string &in_buffer) { GpgImportInformation result = GpgKeyImportExporter::GetInstance().ImportKey( std::make_unique<ByteArray>(in_buffer)); - emit signalKeyStatusUpdated(); + emit SignalKeyStatusUpdated(); new KeyImportDetailDialog(result, false, parent); } -void CommonUtils::slotImportKeyFromFile(QWidget* parent) { +void CommonUtils::SlotImportKeyFromFile(QWidget *parent) { QString file_name = QFileDialog::getOpenFileName( this, _("Open Key"), QString(), QString(_("Key Files")) + " (*.asc *.txt);;" + _("Keyring files") + " (*.gpg);;All Files (*)"); if (!file_name.isNull()) { - slotImportKeys(parent, read_all_data_in_file(file_name.toStdString())); + QByteArray key_buffer; + if (!FileOperator::ReadFile(file_name, key_buffer)) { + QMessageBox::critical(nullptr, _("File Open Failed"), + _("Failed to open file: ") + file_name); + return; + } + SlotImportKeys(parent, key_buffer.toStdString()); } } -void CommonUtils::slotImportKeyFromKeyServer(QWidget* parent) { +void CommonUtils::SlotImportKeyFromKeyServer(QWidget *parent) { auto dialog = new KeyServerImportDialog(false, parent); dialog->show(); } -void CommonUtils::slotImportKeyFromClipboard(QWidget* parent) { - QClipboard* cb = QApplication::clipboard(); - slotImportKeys(parent, +void CommonUtils::SlotImportKeyFromClipboard(QWidget *parent) { + QClipboard *cb = QApplication::clipboard(); + SlotImportKeys(parent, cb->text(QClipboard::Clipboard).toUtf8().toStdString()); } -void CommonUtils::slotExecuteGpgCommand( - const QStringList& arguments, - const std::function<void(QProcess*)>& interact_func) { +void CommonUtils::SlotExecuteGpgCommand( + const QStringList &arguments, + const std::function<void(QProcess *)> &interact_func) { QEventLoop looper; auto dialog = new WaitingDialog(_("Processing"), nullptr); dialog->show(); - auto* gpg_process = new QProcess(&looper); + auto *gpg_process = new QProcess(&looper); gpg_process->setProcessChannelMode(QProcess::MergedChannels); connect(gpg_process, @@ -239,13 +251,13 @@ void CommonUtils::slotExecuteGpgCommand( dialog->deleteLater(); } -void CommonUtils::slotImportKeyFromKeyServer( - int ctx_channel, const KeyIdArgsList& key_ids, - const ImportCallbackFunctiopn& callback) { +void CommonUtils::SlotImportKeyFromKeyServer( + int ctx_channel, const KeyIdArgsList &key_ids, + const ImportCallbackFunctiopn &callback) { std::string target_keyserver; if (target_keyserver.empty()) { try { - auto& settings = GlobalSettingStation::GetInstance().GetUISettings(); + auto &settings = GlobalSettingStation::GetInstance().GetUISettings(); target_keyserver = settings.lookup("keyserver.default_server").c_str(); @@ -268,7 +280,7 @@ void CommonUtils::slotImportKeyFromKeyServer( auto network_manager = std::make_unique<QNetworkAccessManager>(); // LOOP decltype(key_ids.size()) current_index = 1, all_index = key_ids.size(); - for (const auto& key_id : key_ids) { + for (const auto &key_id : key_ids) { // New Req Url QUrl req_url(target_keyserver_url.scheme() + "://" + target_keyserver_url.host() + @@ -278,7 +290,7 @@ void CommonUtils::slotImportKeyFromKeyServer( LOG(INFO) << "request url" << req_url.toString().toStdString(); // Waiting for reply - QNetworkReply* reply = network_manager->get(QNetworkRequest(req_url)); + QNetworkReply *reply = network_manager->get(QNetworkRequest(req_url)); QEventLoop loop; connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit); loop.exec(); |