aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
authorSaturn&Eric <[email protected]>2022-07-23 14:54:51 +0000
committerGitHub <[email protected]>2022-07-23 14:54:51 +0000
commitb244320b2d228189767aa6d59febceb6b64527fb (patch)
tree179d34e2a3e84231fad72c4bbe9f74673d0b74d0 /src/ui
parentMerge pull request #68 from saturneric/develop-2.0.8 (diff)
parentfeat(project): add rpm package support (diff)
downloadGpgFrontend-2.0.9.tar.gz
GpgFrontend-2.0.9.zip
Merge pull request #70 from saturneric/dev/2.0.8/saturnericv2.0.9
Develop 2.0.9.1
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/CMakeLists.txt12
-rw-r--r--src/ui/GpgFrontendApplication.cpp7
-rw-r--r--src/ui/GpgFrontendApplication.h2
-rw-r--r--src/ui/GpgFrontendUIInit.cpp2
-rw-r--r--src/ui/UserInterfaceUtils.cpp3
-rw-r--r--src/ui/UserInterfaceUtils.h10
-rw-r--r--src/ui/dialog/GeneralDialog.cpp88
-rw-r--r--src/ui/dialog/GeneralDialog.h66
-rwxr-xr-xsrc/ui/dialog/QuitDialog.cpp4
-rwxr-xr-xsrc/ui/dialog/QuitDialog.h3
-rw-r--r--src/ui/dialog/SignersPicker.cpp (renamed from src/ui/widgets/SignersPicker.cpp)23
-rw-r--r--src/ui/dialog/SignersPicker.h (renamed from src/ui/widgets/SignersPicker.h)17
-rw-r--r--src/ui/dialog/Wizard.h6
-rw-r--r--src/ui/dialog/details/SignatureDetailsDialog.cpp (renamed from src/ui/details/SignatureDetailsDialog.cpp)0
-rw-r--r--src/ui/dialog/details/SignatureDetailsDialog.h (renamed from src/ui/details/SignatureDetailsDialog.h)1
-rw-r--r--src/ui/dialog/details/VerifyDetailsDialog.cpp (renamed from src/ui/details/VerifyDetailsDialog.cpp)0
-rw-r--r--src/ui/dialog/details/VerifyDetailsDialog.h (renamed from src/ui/details/VerifyDetailsDialog.h)0
-rw-r--r--src/ui/dialog/help/AboutDialog.cpp (renamed from src/ui/help/AboutDialog.cpp)28
-rw-r--r--src/ui/dialog/help/AboutDialog.h (renamed from src/ui/help/AboutDialog.h)3
-rw-r--r--src/ui/dialog/help/GnupgTab.cpp66
-rw-r--r--src/ui/dialog/help/GnupgTab.h53
-rw-r--r--src/ui/dialog/import_export/ExportKeyPackageDialog.cpp (renamed from src/ui/import_export/ExportKeyPackageDialog.cpp)6
-rw-r--r--src/ui/dialog/import_export/ExportKeyPackageDialog.h (renamed from src/ui/import_export/ExportKeyPackageDialog.h)3
-rw-r--r--src/ui/dialog/import_export/KeyImportDetailDialog.cpp (renamed from src/ui/import_export/KeyImportDetailDialog.cpp)6
-rw-r--r--src/ui/dialog/import_export/KeyImportDetailDialog.h (renamed from src/ui/import_export/KeyImportDetailDialog.h)3
-rw-r--r--src/ui/dialog/import_export/KeyServerImportDialog.cpp (renamed from src/ui/import_export/KeyServerImportDialog.cpp)270
-rw-r--r--src/ui/dialog/import_export/KeyServerImportDialog.h (renamed from src/ui/import_export/KeyServerImportDialog.h)45
-rw-r--r--src/ui/dialog/import_export/KeyUploadDialog.cpp (renamed from src/ui/import_export/KeyUploadDialog.cpp)8
-rw-r--r--src/ui/dialog/import_export/KeyUploadDialog.h (renamed from src/ui/import_export/KeyUploadDialog.h)3
-rw-r--r--src/ui/dialog/key_generate/KeygenDialog.cpp (renamed from src/ui/key_generate/KeygenDialog.cpp)5
-rw-r--r--src/ui/dialog/key_generate/KeygenDialog.h (renamed from src/ui/key_generate/KeygenDialog.h)3
-rw-r--r--src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp (renamed from src/ui/key_generate/SubkeyGenerateDialog.cpp)5
-rw-r--r--src/ui/dialog/key_generate/SubkeyGenerateDialog.h (renamed from src/ui/key_generate/SubkeyGenerateDialog.h)3
-rw-r--r--src/ui/dialog/keypair_details/KeyDetailsDialog.cpp (renamed from src/ui/keypair_details/KeyDetailsDialog.cpp)12
-rw-r--r--src/ui/dialog/keypair_details/KeyDetailsDialog.h (renamed from src/ui/keypair_details/KeyDetailsDialog.h)3
-rw-r--r--src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp (renamed from src/ui/keypair_details/KeyNewUIDDialog.cpp)14
-rw-r--r--src/ui/dialog/keypair_details/KeyNewUIDDialog.h (renamed from src/ui/keypair_details/KeyNewUIDDialog.h)3
-rw-r--r--src/ui/dialog/keypair_details/KeyPairDetailTab.cpp (renamed from src/ui/keypair_details/KeyPairDetailTab.cpp)2
-rw-r--r--src/ui/dialog/keypair_details/KeyPairDetailTab.h (renamed from src/ui/keypair_details/KeyPairDetailTab.h)24
-rw-r--r--src/ui/dialog/keypair_details/KeyPairOperaTab.cpp (renamed from src/ui/keypair_details/KeyPairOperaTab.cpp)4
-rw-r--r--src/ui/dialog/keypair_details/KeyPairOperaTab.h (renamed from src/ui/keypair_details/KeyPairOperaTab.h)0
-rw-r--r--src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp (renamed from src/ui/keypair_details/KeyPairSubkeyTab.cpp)2
-rw-r--r--src/ui/dialog/keypair_details/KeyPairSubkeyTab.h (renamed from src/ui/keypair_details/KeyPairSubkeyTab.h)2
-rw-r--r--src/ui/dialog/keypair_details/KeyPairUIDTab.cpp (renamed from src/ui/keypair_details/KeyPairUIDTab.cpp)2
-rw-r--r--src/ui/dialog/keypair_details/KeyPairUIDTab.h (renamed from src/ui/keypair_details/KeyPairUIDTab.h)0
-rw-r--r--src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp (renamed from src/ui/keypair_details/KeySetExpireDateDialog.cpp)6
-rw-r--r--src/ui/dialog/keypair_details/KeySetExpireDateDialog.h (renamed from src/ui/keypair_details/KeySetExpireDateDialog.h)3
-rw-r--r--src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp (renamed from src/ui/keypair_details/KeyUIDSignDialog.cpp)6
-rw-r--r--src/ui/dialog/keypair_details/KeyUIDSignDialog.h (renamed from src/ui/keypair_details/KeyUIDSignDialog.h)3
-rw-r--r--src/ui/dialog/settings/SettingsAdvanced.cpp (renamed from src/ui/settings/SettingsAdvanced.cpp)0
-rw-r--r--src/ui/dialog/settings/SettingsAdvanced.h (renamed from src/ui/settings/SettingsAdvanced.h)0
-rw-r--r--src/ui/dialog/settings/SettingsAppearance.cpp (renamed from src/ui/settings/SettingsAppearance.cpp)26
-rw-r--r--src/ui/dialog/settings/SettingsAppearance.h (renamed from src/ui/settings/SettingsAppearance.h)0
-rw-r--r--src/ui/dialog/settings/SettingsDialog.cpp (renamed from src/ui/settings/SettingsDialog.cpp)13
-rw-r--r--[-rwxr-xr-x]src/ui/dialog/settings/SettingsDialog.h (renamed from src/ui/settings/SettingsDialog.h)5
-rw-r--r--src/ui/dialog/settings/SettingsGeneral.cpp (renamed from src/ui/settings/SettingsGeneral.cpp)0
-rw-r--r--src/ui/dialog/settings/SettingsGeneral.h (renamed from src/ui/settings/SettingsGeneral.h)0
-rw-r--r--src/ui/dialog/settings/SettingsKeyServer.cpp (renamed from src/ui/settings/SettingsKeyServer.cpp)35
-rw-r--r--src/ui/dialog/settings/SettingsKeyServer.h (renamed from src/ui/settings/SettingsKeyServer.h)0
-rw-r--r--src/ui/dialog/settings/SettingsNetwork.cpp (renamed from src/ui/settings/SettingsNetwork.cpp)0
-rw-r--r--src/ui/dialog/settings/SettingsNetwork.h (renamed from src/ui/settings/SettingsNetwork.h)0
-rw-r--r--src/ui/main_window/GeneralMainWindow.cpp135
-rw-r--r--src/ui/main_window/GeneralMainWindow.h81
-rw-r--r--[-rwxr-xr-x]src/ui/main_window/KeyMgmt.cpp (renamed from src/ui/KeyMgmt.cpp)119
-rw-r--r--[-rwxr-xr-x]src/ui/main_window/KeyMgmt.h (renamed from src/ui/KeyMgmt.h)25
-rw-r--r--src/ui/main_window/MainWindow.cpp70
-rw-r--r--src/ui/main_window/MainWindow.h15
-rw-r--r--src/ui/main_window/MainWindowFileSlotFunction.cpp5
-rw-r--r--src/ui/main_window/MainWindowSlotFunction.cpp11
-rw-r--r--src/ui/main_window/MainWindowSlotUI.cpp10
-rw-r--r--src/ui/main_window/MainWindowUI.cpp9
-rw-r--r--src/ui/struct/SettingsObject.h3
-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
-rw-r--r--src/ui/widgets/FilePage.h2
-rw-r--r--src/ui/widgets/FindWidget.cpp6
-rw-r--r--src/ui/widgets/InfoBoardWidget.cpp4
-rw-r--r--src/ui/widgets/InfoBoardWidget.h2
-rw-r--r--src/ui/widgets/KeyList.h2
-rw-r--r--src/ui/widgets/VerifyKeyDetailBox.cpp2
-rw-r--r--src/ui/widgets/VerifyKeyDetailBox.h2
84 files changed, 1172 insertions, 533 deletions
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index 6e3ee4be..24158e27 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -26,16 +26,16 @@
# tracking source files
aux_source_directory(. UI_SOURCE)
-aux_source_directory(keypair_details UI_SOURCE)
+aux_source_directory(dialog/keypair_details UI_SOURCE)
aux_source_directory(widgets UI_SOURCE)
-aux_source_directory(key_generate UI_SOURCE)
+aux_source_directory(dialog/key_generate UI_SOURCE)
aux_source_directory(main_window UI_SOURCE)
-aux_source_directory(help UI_SOURCE)
-aux_source_directory(settings UI_SOURCE)
+aux_source_directory(dialog/help UI_SOURCE)
+aux_source_directory(dialog/settings UI_SOURCE)
aux_source_directory(thread UI_SOURCE)
-aux_source_directory(details UI_SOURCE)
+aux_source_directory(dialog/details UI_SOURCE)
aux_source_directory(struct UI_SOURCE)
-aux_source_directory(import_export UI_SOURCE)
+aux_source_directory(dialog/import_export UI_SOURCE)
aux_source_directory(dialog UI_SOURCE)
# define libgpgfrontend_ui
diff --git a/src/ui/GpgFrontendApplication.cpp b/src/ui/GpgFrontendApplication.cpp
index 4cb50b43..b1c5beed 100644
--- a/src/ui/GpgFrontendApplication.cpp
+++ b/src/ui/GpgFrontendApplication.cpp
@@ -30,7 +30,7 @@
namespace GpgFrontend::UI {
-GpgFrontendApplication::GpgFrontendApplication(int &argc, char **argv)
+GpgFrontendApplication::GpgFrontendApplication(int &argc, char *argv[])
: QApplication(argc, argv) {
#ifndef MACOS
this->setWindowIcon(QIcon(":gpgfrontend.png"));
@@ -57,12 +57,15 @@ GpgFrontendApplication *GpgFrontendApplication::GetInstance(int argc,
char *argv[],
bool new_instance) {
static GpgFrontendApplication *instance = nullptr;
+ static int static_argc = argc;
+ static char **static_argv = argv;
+
if (new_instance || !instance) {
if (instance != nullptr) {
instance->quit();
delete instance;
}
- instance = new GpgFrontendApplication(argc, argv);
+ instance = new GpgFrontendApplication(static_argc, static_argv);
}
return instance;
}
diff --git a/src/ui/GpgFrontendApplication.h b/src/ui/GpgFrontendApplication.h
index 52a0a610..06338bb6 100644
--- a/src/ui/GpgFrontendApplication.h
+++ b/src/ui/GpgFrontendApplication.h
@@ -40,7 +40,7 @@ class GPGFRONTEND_UI_EXPORT GpgFrontendApplication : public QApplication {
* @param argc
* @param argv
*/
- explicit GpgFrontendApplication(int &argc, char **argv);
+ explicit GpgFrontendApplication(int &argc, char *argv[]);
/**
* @brief Destroy the GpgFrontend Application object
diff --git a/src/ui/GpgFrontendUIInit.cpp b/src/ui/GpgFrontendUIInit.cpp
index 022f0748..5cbca31b 100644
--- a/src/ui/GpgFrontendUIInit.cpp
+++ b/src/ui/GpgFrontendUIInit.cpp
@@ -103,8 +103,8 @@ void InitGpgFrontendUI(QApplication* app) {
// show the loading window
waiting_dialog->setModal(true);
- waiting_dialog->show();
waiting_dialog->setFocus();
+ waiting_dialog->show();
// new local event looper
QEventLoop looper;
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/dialog/GeneralDialog.cpp b/src/ui/dialog/GeneralDialog.cpp
new file mode 100644
index 00000000..d07c2497
--- /dev/null
+++ b/src/ui/dialog/GeneralDialog.cpp
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2022. 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 "GeneralDialog.h"
+
+#include "ui/struct/SettingsObject.h"
+
+GpgFrontend::UI::GeneralDialog::GeneralDialog(std::string name, QWidget *parent)
+ : name_(std::move(name)), QDialog(parent) {
+ slot_restore_settings();
+ connect(this, &QDialog::finished, this, &GeneralDialog::slot_save_settings);
+}
+
+GpgFrontend::UI::GeneralDialog::~GeneralDialog() = default;
+
+void GpgFrontend::UI::GeneralDialog::slot_restore_settings() noexcept {
+ try {
+ LOG(INFO) << name_ << _("Called");
+
+ SettingsObject general_windows_state(name_ + "_dialog_state");
+
+ bool window_save = general_windows_state.Check("window_save", true);
+
+ // Restore window size & location
+ if (window_save) {
+ int x = general_windows_state.Check("window_pos").Check("x", 100),
+ y = general_windows_state.Check("window_pos").Check("y", 100);
+
+ this->move({x, y});
+ pos_ = {x, y};
+
+ int width =
+ general_windows_state.Check("window_size").Check("width", 400),
+ height =
+ general_windows_state.Check("window_size").Check("height", 247);
+
+ this->resize({width, height});
+ size_ = {width, height};
+
+ }
+
+ } catch (...) {
+ LOG(ERROR) << name_ << "error";
+ }
+}
+
+void GpgFrontend::UI::GeneralDialog::slot_save_settings() noexcept {
+ try {
+ LOG(INFO) << name_ << _("Called");
+
+ SettingsObject general_windows_state(name_ + "_dialog_state");
+
+ // window position and size
+ general_windows_state["window_pos"]["x"] = pos().x();
+ general_windows_state["window_pos"]["y"] = pos().y();
+
+ general_windows_state["window_size"]["width"] = size_.width();
+ general_windows_state["window_size"]["height"] = size_.height();
+ general_windows_state["window_save"] = true;
+
+ } catch (...) {
+ LOG(ERROR) << name_ << "error";
+ }
+}
diff --git a/src/ui/dialog/GeneralDialog.h b/src/ui/dialog/GeneralDialog.h
new file mode 100644
index 00000000..ca480c8b
--- /dev/null
+++ b/src/ui/dialog/GeneralDialog.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2022. 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_GENERALDIALOG_H
+#define GPGFRONTEND_GENERALDIALOG_H
+
+#include "ui/GpgFrontendUI.h"
+
+namespace GpgFrontend::UI {
+
+class GeneralDialog : public QDialog {
+ public:
+ /**
+ *
+ * @param name
+ */
+ explicit GeneralDialog(std::string name, QWidget* parent = nullptr);
+
+ /**
+ *
+ */
+ ~GeneralDialog() override;
+
+ private slots:
+ /**
+ *
+ */
+ void slot_restore_settings() noexcept;
+
+ /**
+ *
+ */
+ void slot_save_settings() noexcept;
+
+ private:
+ std::string name_; ///<
+ QPoint pos_; ///<
+ QSize size_; ///<
+};
+} // namespace GpgFrontend::UI
+
+#endif // GPGFRONTEND_GENERALDIALOG_H
diff --git a/src/ui/dialog/QuitDialog.cpp b/src/ui/dialog/QuitDialog.cpp
index da0be488..87b1c1e1 100755
--- a/src/ui/dialog/QuitDialog.cpp
+++ b/src/ui/dialog/QuitDialog.cpp
@@ -33,7 +33,7 @@
namespace GpgFrontend::UI {
QuitDialog::QuitDialog(QWidget* parent, const QHash<int, QString>& unsavedDocs)
- : QDialog(parent) {
+ : GeneralDialog("quit_dialog", parent) {
setWindowTitle(_("Unsaved Files"));
setModal(true);
discarded_ = false;
@@ -111,7 +111,7 @@ QuitDialog::QuitDialog(QWidget* parent, const QHash<int, QString>& unsavedDocs)
connect(buttonBox, &QDialogButtonBox::accepted, this, &QuitDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QuitDialog::reject);
QPushButton* btnNoKey = buttonBox->button(QDialogButtonBox::Discard);
- connect(btnNoKey, &QPushButton::clicked, this,&QuitDialog::slot_my_discard);
+ connect(btnNoKey, &QPushButton::clicked, this, &QuitDialog::slot_my_discard);
/*
* Set the layout
diff --git a/src/ui/dialog/QuitDialog.h b/src/ui/dialog/QuitDialog.h
index 2d09790b..2fd9e382 100755
--- a/src/ui/dialog/QuitDialog.h
+++ b/src/ui/dialog/QuitDialog.h
@@ -30,6 +30,7 @@
#define __QUITDIALOG_H__
#include "ui/GpgFrontendUI.h"
+#include "ui/dialog/GeneralDialog.h"
namespace GpgFrontend::UI {
@@ -37,7 +38,7 @@ namespace GpgFrontend::UI {
* @brief
*
*/
-class QuitDialog : public QDialog {
+class QuitDialog : public GeneralDialog {
Q_OBJECT
public:
diff --git a/src/ui/widgets/SignersPicker.cpp b/src/ui/dialog/SignersPicker.cpp
index 75f6b2ba..a670e514 100644
--- a/src/ui/widgets/SignersPicker.cpp
+++ b/src/ui/dialog/SignersPicker.cpp
@@ -1,7 +1,7 @@
-/**
- * Copyright (C) 2021 Saturneric
+/*
+ * Copyright (c) 2022. Saturneric
*
- * This file is part of GpgFrontend.
+ * 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
@@ -23,18 +23,24 @@
* Saturneric<[email protected]> starting on May 12, 2021.
*
* SPDX-License-Identifier: GPL-3.0-or-later
- *
*/
-#include "ui/widgets/SignersPicker.h"
+#include "SignersPicker.h"
#include "ui/widgets/KeyList.h"
namespace GpgFrontend::UI {
-SignersPicker::SignersPicker(QWidget* parent) : QDialog(parent) {
+SignersPicker::SignersPicker(QWidget* parent)
+ : GeneralDialog(typeid(SignersPicker).name(), parent) {
auto confirm_button = new QPushButton(_("Confirm"));
- connect(confirm_button, &QPushButton::clicked, this, &SignersPicker::accept);
+ auto cancel_button = new QPushButton(_("Cancel"));
+
+ connect(confirm_button, &QPushButton::clicked, [=]() {
+ this->accepted_ = true;
+ });
+ connect(confirm_button, &QPushButton::clicked, this, &QDialog::accept);
+ connect(cancel_button, &QPushButton::clicked, this, &QDialog::reject);
/*Setup KeyList*/
key_list_ = new KeyList(false, this);
@@ -55,6 +61,7 @@ SignersPicker::SignersPicker(QWidget* parent) : QDialog(parent) {
"\n" +
_("If no key is selected, the default key will be used for signing.")));
vbox2->addWidget(confirm_button);
+ vbox2->addWidget(cancel_button);
vbox2->addStretch(0);
setLayout(vbox2);
@@ -71,4 +78,6 @@ GpgFrontend::KeyIdArgsListPtr SignersPicker::GetCheckedSigners() {
return key_list_->GetPrivateChecked();
}
+bool SignersPicker::GetStatus() const { return this->accepted_; }
+
} // namespace GpgFrontend::UI
diff --git a/src/ui/widgets/SignersPicker.h b/src/ui/dialog/SignersPicker.h
index 30f872f8..5533f9d8 100644
--- a/src/ui/widgets/SignersPicker.h
+++ b/src/ui/dialog/SignersPicker.h
@@ -1,7 +1,7 @@
-/**
- * Copyright (C) 2021 Saturneric
+/*
+ * Copyright (c) 2022. Saturneric
*
- * This file is part of GpgFrontend.
+ * 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
@@ -23,13 +23,13 @@
* Saturneric<[email protected]> starting on May 12, 2021.
*
* SPDX-License-Identifier: GPL-3.0-or-later
- *
*/
#ifndef GPGFRONTEND_ZH_CN_TS_SIGNERSPIRCKER_H
#define GPGFRONTEND_ZH_CN_TS_SIGNERSPIRCKER_H
#include "GpgFrontendUI.h"
+#include "ui/dialog//GeneralDialog.h"
namespace GpgFrontend::UI {
@@ -39,7 +39,7 @@ class KeyList;
* @brief
*
*/
-class SignersPicker : public QDialog {
+class SignersPicker : public GeneralDialog {
Q_OBJECT
public:
@@ -57,8 +57,15 @@ class SignersPicker : public QDialog {
*/
GpgFrontend::KeyIdArgsListPtr GetCheckedSigners();
+ /**
+ *
+ * @return
+ */
+ [[nodiscard]] bool GetStatus() const;
+
private:
KeyList* key_list_; ///<
+ bool accepted_ = false;
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/dialog/Wizard.h b/src/ui/dialog/Wizard.h
index eb093550..879dc5d9 100644
--- a/src/ui/dialog/Wizard.h
+++ b/src/ui/dialog/Wizard.h
@@ -30,10 +30,10 @@
#define WIZARD_H
#include "core/GpgConstants.h"
+#include "main_window/KeyMgmt.h"
#include "ui/GpgFrontendUI.h"
-#include "ui/KeyMgmt.h"
-#include "ui/key_generate/KeygenDialog.h"
-#include "ui/settings/SettingsDialog.h"
+#include "ui/dialog/key_generate/KeygenDialog.h"
+#include "ui/dialog/settings/SettingsDialog.h"
namespace GpgFrontend::UI {
diff --git a/src/ui/details/SignatureDetailsDialog.cpp b/src/ui/dialog/details/SignatureDetailsDialog.cpp
index a3ad03b3..a3ad03b3 100644
--- a/src/ui/details/SignatureDetailsDialog.cpp
+++ b/src/ui/dialog/details/SignatureDetailsDialog.cpp
diff --git a/src/ui/details/SignatureDetailsDialog.h b/src/ui/dialog/details/SignatureDetailsDialog.h
index 847b320b..7b01d054 100644
--- a/src/ui/details/SignatureDetailsDialog.h
+++ b/src/ui/dialog/details/SignatureDetailsDialog.h
@@ -28,6 +28,7 @@
#ifndef GPGFRONTEND_SIGNATUREDETAILSDIALOG_H
#define GPGFRONTEND_SIGNATUREDETAILSDIALOG_H
+
#include "ui/GpgFrontendUI.h"
class SignatureDetailsDialog : public QDialog {
diff --git a/src/ui/details/VerifyDetailsDialog.cpp b/src/ui/dialog/details/VerifyDetailsDialog.cpp
index d2af4ee1..d2af4ee1 100644
--- a/src/ui/details/VerifyDetailsDialog.cpp
+++ b/src/ui/dialog/details/VerifyDetailsDialog.cpp
diff --git a/src/ui/details/VerifyDetailsDialog.h b/src/ui/dialog/details/VerifyDetailsDialog.h
index 97e2cc2d..97e2cc2d 100644
--- a/src/ui/details/VerifyDetailsDialog.h
+++ b/src/ui/dialog/details/VerifyDetailsDialog.h
diff --git a/src/ui/help/AboutDialog.cpp b/src/ui/dialog/help/AboutDialog.cpp
index e8fbeb1b..6b6e4356 100644
--- a/src/ui/help/AboutDialog.cpp
+++ b/src/ui/dialog/help/AboutDialog.cpp
@@ -26,39 +26,43 @@
*
*/
-#include "ui/help/AboutDialog.h"
+#include "AboutDialog.h"
#include "GpgFrontendBuildInfo.h"
#include "core/function/GlobalSettingStation.h"
#include "core/thread/TaskRunnerGetter.h"
+#include "ui/dialog/help/GnupgTab.h"
#include "ui/thread/VersionCheckTask.h"
namespace GpgFrontend::UI {
-AboutDialog::AboutDialog(int defaultIndex, QWidget* parent) : QDialog(parent) {
+AboutDialog::AboutDialog(int defaultIndex, QWidget* parent)
+ : GeneralDialog(typeid(AboutDialog).name(), parent) {
this->setWindowTitle(QString(_("About")) + " " + qApp->applicationName());
- auto* tabWidget = new QTabWidget;
- auto* infoTab = new InfoTab();
- auto* translatorsTab = new TranslatorsTab();
+ auto* tab_widget = new QTabWidget;
+ auto* info_tab = new InfoTab();
+ auto* gnupg_tab = new GnupgTab();
+ auto* translators_tab = new TranslatorsTab();
update_tab_ = new UpdateTab();
- tabWidget->addTab(infoTab, _("About Software"));
- tabWidget->addTab(translatorsTab, _("Translators"));
- tabWidget->addTab(update_tab_, _("Update"));
+ tab_widget->addTab(info_tab, _("About GpgFrontend"));
+ tab_widget->addTab(gnupg_tab, _("GnuPG"));
+ tab_widget->addTab(translators_tab, _("Translators"));
+ tab_widget->addTab(update_tab_, _("Update"));
- connect(tabWidget, &QTabWidget::currentChanged, this,
+ connect(tab_widget, &QTabWidget::currentChanged, this,
[&](int index) { LOG(INFO) << "Current Index" << index; });
- if (defaultIndex < tabWidget->count() && defaultIndex >= 0) {
- tabWidget->setCurrentIndex(defaultIndex);
+ if (defaultIndex < tab_widget->count() && defaultIndex >= 0) {
+ tab_widget->setCurrentIndex(defaultIndex);
}
auto* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
connect(buttonBox, &QDialogButtonBox::accepted, this, &AboutDialog::close);
auto* mainLayout = new QVBoxLayout;
- mainLayout->addWidget(tabWidget);
+ mainLayout->addWidget(tab_widget);
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
diff --git a/src/ui/help/AboutDialog.h b/src/ui/dialog/help/AboutDialog.h
index 40d93f3e..09a63734 100644
--- a/src/ui/help/AboutDialog.h
+++ b/src/ui/dialog/help/AboutDialog.h
@@ -31,6 +31,7 @@
#include "core/GpgContext.h"
#include "ui/GpgFrontendUI.h"
+#include "ui/dialog/GeneralDialog.h"
#include "ui/struct/SoftwareVersion.h"
namespace GpgFrontend::UI {
@@ -116,7 +117,7 @@ class UpdateTab : public QWidget {
* @brief Class for handling the about dialog
*
*/
-class AboutDialog : public QDialog {
+class AboutDialog : public GeneralDialog {
Q_OBJECT
public:
diff --git a/src/ui/dialog/help/GnupgTab.cpp b/src/ui/dialog/help/GnupgTab.cpp
new file mode 100644
index 00000000..48787987
--- /dev/null
+++ b/src/ui/dialog/help/GnupgTab.cpp
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2022. 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
+ */
+
+//
+// Created by eric on 2022/7/23.
+//
+
+#include "GnupgTab.h"
+
+GpgFrontend::UI::GnupgTab::GnupgTab(QWidget* parent) : QWidget(parent) {
+ GpgContext& ctx = GpgContext::GetInstance();
+ auto info = ctx.GetInfo();
+
+ auto* pixmap = new QPixmap(":gnupg.png");
+ auto* text = new QString(
+ "<center><h2>" + QString(_("GnuPG")) + "</h2></center>" + "<center><b>" +
+ QString(_("GnuPG Version")) + ": " +
+ QString::fromStdString(info.GnupgVersion) + "</b></center>" +
+ "<center><b>" + +"</b></center>" + "<center>" +
+ QString(_("GpgME Version")) + ": " +
+ QString::fromStdString(info.GpgMEVersion) + "</center><br /><hr />" +
+ "<h3>" + QString(_("PATHs")) + "</h3>" + QString(_("GpgConf")) + ": " +
+ QString::fromStdString(info.GpgConfPath) + "<br />" +
+ QString(_("GnuPG")) + ": " + QString::fromStdString(info.AppPath) +
+ "<br />" + QString(_("CMS")) + ": " +
+ QString::fromStdString(info.CMSPath) + "<br />");
+
+ auto* layout = new QGridLayout();
+ auto* pixmapLabel = new QLabel();
+ pixmapLabel->setPixmap(*pixmap);
+ layout->addWidget(pixmapLabel, 0, 0, 1, -1, Qt::AlignCenter);
+ auto* aboutLabel = new QLabel();
+ aboutLabel->setText(*text);
+ aboutLabel->setWordWrap(true);
+ aboutLabel->setOpenExternalLinks(true);
+ layout->addWidget(aboutLabel, 1, 0, 1, -1);
+ layout->addItem(
+ new QSpacerItem(20, 10, QSizePolicy::Minimum, QSizePolicy::Fixed), 2, 1,
+ 1, 1);
+
+ setLayout(layout);
+}
diff --git a/src/ui/dialog/help/GnupgTab.h b/src/ui/dialog/help/GnupgTab.h
new file mode 100644
index 00000000..4fc7ff22
--- /dev/null
+++ b/src/ui/dialog/help/GnupgTab.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2022. 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
+ */
+
+//
+// Created by eric on 2022/7/23.
+//
+
+#ifndef GPGFRONTEND_GNUPGTAB_H
+#define GPGFRONTEND_GNUPGTAB_H
+
+#include "core/GpgContext.h"
+#include "ui/GpgFrontendUI.h"
+
+namespace GpgFrontend::UI{
+class GnupgTab: public QWidget {
+ Q_OBJECT
+ public:
+ /**
+ * @brief Construct a new Info Tab object
+ *
+ * @param parent
+ */
+ explicit GnupgTab(QWidget* parent = nullptr);
+};
+}
+
+
+
+#endif // GPGFRONTEND_GNUPGTAB_H
diff --git a/src/ui/import_export/ExportKeyPackageDialog.cpp b/src/ui/dialog/import_export/ExportKeyPackageDialog.cpp
index d6f303f6..312cd946 100644
--- a/src/ui/import_export/ExportKeyPackageDialog.cpp
+++ b/src/ui/dialog/import_export/ExportKeyPackageDialog.cpp
@@ -30,13 +30,13 @@
#include <boost/format.hpp>
-#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/KeyPackageOperator.h"
+#include "core/function/gpg/GpgKeyGetter.h"
#include "ui_ExportKeyPackageDialog.h"
GpgFrontend::UI::ExportKeyPackageDialog::ExportKeyPackageDialog(
KeyIdArgsListPtr key_ids, QWidget* parent)
- : QDialog(parent),
+ : GeneralDialog(typeid(ExportKeyPackageDialog).name(), parent),
ui_(std::make_shared<Ui_exportKeyPackageDialog>()),
key_ids_(std::move(key_ids)) {
ui_->setupUi(this);
@@ -141,5 +141,5 @@ GpgFrontend::UI::ExportKeyPackageDialog::ExportKeyPackageDialog(
_("Exclude keys that do not have a private key"));
setAttribute(Qt::WA_DeleteOnClose);
- setWindowTitle(_("exportKeyPackageDialog"));
+ setWindowTitle(_("Export As Key Package"));
}
diff --git a/src/ui/import_export/ExportKeyPackageDialog.h b/src/ui/dialog/import_export/ExportKeyPackageDialog.h
index ecf13b1d..c5f9a2b1 100644
--- a/src/ui/import_export/ExportKeyPackageDialog.h
+++ b/src/ui/dialog/import_export/ExportKeyPackageDialog.h
@@ -30,6 +30,7 @@
#define GPGFRONTEND_EXPORTKEYPACKAGEDIALOG_H
#include "GpgFrontendUI.h"
+#include "ui/dialog/GeneralDialog.h"
class Ui_exportKeyPackageDialog;
@@ -39,7 +40,7 @@ namespace GpgFrontend::UI {
* @brief
*
*/
-class ExportKeyPackageDialog : public QDialog {
+class ExportKeyPackageDialog : public GeneralDialog {
Q_OBJECT
public:
diff --git a/src/ui/import_export/KeyImportDetailDialog.cpp b/src/ui/dialog/import_export/KeyImportDetailDialog.cpp
index 766d2d81..31183a34 100644
--- a/src/ui/import_export/KeyImportDetailDialog.cpp
+++ b/src/ui/dialog/import_export/KeyImportDetailDialog.cpp
@@ -33,7 +33,8 @@
namespace GpgFrontend::UI {
KeyImportDetailDialog::KeyImportDetailDialog(GpgImportInformation result,
bool automatic, QWidget* parent)
- : QDialog(parent), m_result_(std::move(result)) {
+ : GeneralDialog(typeid(KeyImportDetailDialog).name(), parent),
+ m_result_(std::move(result)) {
// If no key for import found, just show a message
if (m_result_.considered == 0) {
if (automatic)
@@ -197,6 +198,7 @@ QString KeyImportDetailDialog::get_status_string(int keyStatus) {
void KeyImportDetailDialog::create_button_box() {
button_box_ = new QDialogButtonBox(QDialogButtonBox::Ok);
- connect(button_box_, &QDialogButtonBox::accepted, this, &KeyImportDetailDialog::close);
+ connect(button_box_, &QDialogButtonBox::accepted, this,
+ &KeyImportDetailDialog::close);
}
} // namespace GpgFrontend::UI
diff --git a/src/ui/import_export/KeyImportDetailDialog.h b/src/ui/dialog/import_export/KeyImportDetailDialog.h
index a648f205..06f44e94 100644
--- a/src/ui/import_export/KeyImportDetailDialog.h
+++ b/src/ui/dialog/import_export/KeyImportDetailDialog.h
@@ -32,6 +32,7 @@
#include "core/GpgContext.h"
#include "core/function/gpg/GpgKeyImportExporter.h"
#include "ui/GpgFrontendUI.h"
+#include "ui/dialog/GeneralDialog.h"
namespace GpgFrontend::UI {
@@ -39,7 +40,7 @@ namespace GpgFrontend::UI {
* @brief
*
*/
-class KeyImportDetailDialog : public QDialog {
+class KeyImportDetailDialog : public GeneralDialog {
Q_OBJECT
public:
diff --git a/src/ui/import_export/KeyServerImportDialog.cpp b/src/ui/dialog/import_export/KeyServerImportDialog.cpp
index e359238c..6430a22e 100644
--- a/src/ui/import_export/KeyServerImportDialog.cpp
+++ b/src/ui/dialog/import_export/KeyServerImportDialog.cpp
@@ -28,17 +28,21 @@
#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 {
KeyServerImportDialog::KeyServerImportDialog(bool automatic, QWidget* parent)
- : QDialog(parent), m_automatic_(automatic) {
+ : GeneralDialog("key_server_import_dialog", parent),
+ m_automatic_(automatic) {
// Layout for messagebox
auto* message_layout = new QHBoxLayout();
@@ -115,36 +119,6 @@ KeyServerImportDialog::KeyServerImportDialog(bool automatic, QWidget* parent)
if (automatic) {
this->setFixedSize(240, 42);
- } else {
- auto pos = QPoint(150, 150);
- LOG(INFO) << "parent" << parent;
- if (parent) pos += parent->pos();
- LOG(INFO) << "pos default" << pos.x() << pos.y();
- auto size = QSize(800, 500);
-
- try {
- SettingsObject key_server_import_state("key_server_import_state");
- bool window_save = key_server_import_state.Check("window_save", true);
-
- // Restore window size & location
- if (window_save) {
- int x = key_server_import_state.Check("window_pos").Check("x", pos.x()),
- y = key_server_import_state.Check("window_pos").Check("y", pos.y());
-
- pos = QPoint(x, y);
- int width = key_server_import_state.Check("window_size")
- .Check("width", size.width()),
- height = key_server_import_state.Check("window_size")
- .Check("height", size.height());
-
- size = QSize(width, height);
- }
- } catch (...) {
- LOG(WARNING) << "cannot read pos or size from settings object";
- }
-
- this->resize(size);
- this->move(pos);
}
this->setModal(true);
@@ -152,10 +126,31 @@ KeyServerImportDialog::KeyServerImportDialog(bool automatic, QWidget* parent)
connect(this, &KeyServerImportDialog::SignalKeyImported,
SignalStation::GetInstance(),
&SignalStation::SignalKeyDatabaseRefresh);
+}
+
+KeyServerImportDialog::KeyServerImportDialog(QWidget* parent)
+ : GeneralDialog("key_server_import_dialog", parent), m_automatic_(true) {
+ setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
+
+ // Network Waiting
+ waiting_bar_ = new QProgressBar();
+ waiting_bar_->setVisible(false);
+ waiting_bar_->setRange(0, 0);
+ waiting_bar_->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
+ waiting_bar_->setTextVisible(false);
+
+ // Layout for messagebox
+ auto* layout = new QHBoxLayout();
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->setSpacing(0);
+ layout->addWidget(waiting_bar_);
- // save window pos and size to configure file
- connect(this, &KeyServerImportDialog::finished, this,
- &KeyServerImportDialog::slot_save_window_state);
+ key_server_combo_box_ = create_comboBox();
+
+ this->setLayout(layout);
+ this->setWindowTitle(_("Update Keys from Keyserver"));
+ this->setFixedSize(240, 42);
+ this->setModal(true);
}
QComboBox* KeyServerImportDialog::create_comboBox() {
@@ -174,6 +169,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 +225,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 +280,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 +322,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 +355,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 +403,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 +449,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 +491,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 +513,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 +524,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();
}
}
@@ -542,45 +547,4 @@ void KeyServerImportDialog::set_loading(bool status) {
}
}
-KeyServerImportDialog::KeyServerImportDialog(QWidget* parent)
- : QDialog(parent), m_automatic_(true) {
- setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
-
- // Network Waiting
- waiting_bar_ = new QProgressBar();
- waiting_bar_->setVisible(false);
- waiting_bar_->setRange(0, 0);
- waiting_bar_->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
- waiting_bar_->setTextVisible(false);
-
- // Layout for messagebox
- auto* layout = new QHBoxLayout();
- layout->setContentsMargins(0, 0, 0, 0);
- layout->setSpacing(0);
- layout->addWidget(waiting_bar_);
-
- key_server_combo_box_ = create_comboBox();
-
- this->setLayout(layout);
- this->setWindowTitle(_("Update Keys from Keyserver"));
- this->setFixedSize(240, 42);
- this->setModal(true);
-}
-
-void KeyServerImportDialog::slot_save_window_state() {
- LOG(INFO) << _("Called");
-
- if (m_automatic_) return;
-
- SettingsObject key_server_import_state("key_server_import_state");
-
- // window position and size
- key_server_import_state["window_pos"]["x"] = pos().x();
- key_server_import_state["window_pos"]["y"] = pos().y();
-
- key_server_import_state["window_size"]["width"] = size().width();
- key_server_import_state["window_size"]["height"] = size().height();
- key_server_import_state["window_save"] = true;
-}
-
} // namespace GpgFrontend::UI
diff --git a/src/ui/import_export/KeyServerImportDialog.h b/src/ui/dialog/import_export/KeyServerImportDialog.h
index 37362859..fd912bdd 100644
--- a/src/ui/import_export/KeyServerImportDialog.h
+++ b/src/ui/dialog/import_export/KeyServerImportDialog.h
@@ -29,9 +29,12 @@
#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"
+#include "ui/dialog/GeneralDialog.h"
#include "ui/widgets/KeyList.h"
namespace GpgFrontend::UI {
@@ -40,7 +43,7 @@ namespace GpgFrontend::UI {
* @brief
*
*/
-class KeyServerImportDialog : public QDialog {
+class KeyServerImportDialog : public GeneralDialog {
Q_OBJECT
public:
@@ -74,7 +77,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 +91,7 @@ class KeyServerImportDialog : public QDialog {
private slots:
/**
- * @brief
+ * @brief import key(s) for the key table selection
*
*/
void slot_import();
@@ -96,14 +100,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
@@ -111,12 +117,6 @@ class KeyServerImportDialog : public QDialog {
*/
void slot_search();
- /**
- * @brief
- *
- */
- void slot_save_window_state();
-
private:
/**
* @brief Create a keys table object
@@ -164,18 +164,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/import_export/KeyUploadDialog.cpp b/src/ui/dialog/import_export/KeyUploadDialog.cpp
index a0436a8e..055f2e1f 100644
--- a/src/ui/import_export/KeyUploadDialog.cpp
+++ b/src/ui/dialog/import_export/KeyUploadDialog.cpp
@@ -30,15 +30,16 @@
#include <algorithm>
+#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyImportExporter.h"
-#include "core/function/GlobalSettingStation.h"
namespace GpgFrontend::UI {
KeyUploadDialog::KeyUploadDialog(const KeyIdArgsListPtr& keys_ids,
QWidget* parent)
- : QDialog(parent), m_keys_(GpgKeyGetter::GetInstance().GetKeys(keys_ids)) {
+ : GeneralDialog(typeid(KeyUploadDialog).name(), parent),
+ m_keys_(GpgKeyGetter::GetInstance().GetKeys(keys_ids)) {
auto* pb = new QProgressBar();
pb->setRange(0, 0);
pb->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
@@ -109,7 +110,8 @@ void KeyUploadDialog::slot_upload_key_to_server(
// Send Post Data
QNetworkReply* reply = qnam->post(request, postData);
- connect(reply, &QNetworkReply::finished, this, &KeyUploadDialog::slot_upload_finished);
+ connect(reply, &QNetworkReply::finished, this,
+ &KeyUploadDialog::slot_upload_finished);
// Keep Waiting
while (reply->isRunning()) {
diff --git a/src/ui/import_export/KeyUploadDialog.h b/src/ui/dialog/import_export/KeyUploadDialog.h
index 05cba083..d621f33a 100644
--- a/src/ui/import_export/KeyUploadDialog.h
+++ b/src/ui/dialog/import_export/KeyUploadDialog.h
@@ -31,6 +31,7 @@
#include "core/GpgContext.h"
#include "ui/GpgFrontendUI.h"
+#include "ui/dialog/GeneralDialog.h"
namespace GpgFrontend::UI {
@@ -38,7 +39,7 @@ namespace GpgFrontend::UI {
* @brief
*
*/
-class KeyUploadDialog : public QDialog {
+class KeyUploadDialog : public GeneralDialog {
Q_OBJECT
public:
/**
diff --git a/src/ui/key_generate/KeygenDialog.cpp b/src/ui/dialog/key_generate/KeygenDialog.cpp
index d5ca801d..42160ec9 100644
--- a/src/ui/key_generate/KeygenDialog.cpp
+++ b/src/ui/dialog/key_generate/KeygenDialog.cpp
@@ -26,7 +26,7 @@
*
*/
-#include "ui/key_generate/KeygenDialog.h"
+#include "KeygenDialog.h"
#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgKeyOpera.h"
@@ -35,7 +35,8 @@
namespace GpgFrontend::UI {
-KeyGenDialog::KeyGenDialog(QWidget* parent) : QDialog(parent) {
+KeyGenDialog::KeyGenDialog(QWidget* parent)
+ : GeneralDialog(typeid(KeyGenDialog).name(), parent) {
button_box_ =
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
diff --git a/src/ui/key_generate/KeygenDialog.h b/src/ui/dialog/key_generate/KeygenDialog.h
index 751ebdd8..baf10dbf 100644
--- a/src/ui/key_generate/KeygenDialog.h
+++ b/src/ui/dialog/key_generate/KeygenDialog.h
@@ -30,6 +30,7 @@
#include "core/GpgContext.h"
#include "core/GpgGenKeyInfo.h"
#include "ui/GpgFrontendUI.h"
+#include "ui/dialog/GeneralDialog.h"
namespace GpgFrontend::UI {
@@ -37,7 +38,7 @@ namespace GpgFrontend::UI {
* @brief
*
*/
-class KeyGenDialog : public QDialog {
+class KeyGenDialog : public GeneralDialog {
Q_OBJECT
public:
diff --git a/src/ui/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
index 2b9e076d..806c0e50 100644
--- a/src/ui/key_generate/SubkeyGenerateDialog.cpp
+++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp
@@ -24,7 +24,7 @@
*
*/
-#include "ui/key_generate/SubkeyGenerateDialog.h"
+#include "SubkeyGenerateDialog.h"
#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgKeyGetter.h"
@@ -35,7 +35,8 @@
namespace GpgFrontend::UI {
SubkeyGenerateDialog::SubkeyGenerateDialog(const KeyId& key_id, QWidget* parent)
- : QDialog(parent), key_(GpgKeyGetter::GetInstance().GetKey(key_id)) {
+ : GeneralDialog(typeid(SubkeyGenerateDialog).name(), parent),
+ key_(GpgKeyGetter::GetInstance().GetKey(key_id)) {
auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
// max expire date time
diff --git a/src/ui/key_generate/SubkeyGenerateDialog.h b/src/ui/dialog/key_generate/SubkeyGenerateDialog.h
index 4ab90ad4..1e6608b2 100644
--- a/src/ui/key_generate/SubkeyGenerateDialog.h
+++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.h
@@ -30,13 +30,14 @@
#include "core/GpgContext.h"
#include "core/GpgGenKeyInfo.h"
#include "ui/GpgFrontendUI.h"
+#include "ui/dialog/GeneralDialog.h"
namespace GpgFrontend::UI {
/**
* @brief
*
*/
-class SubkeyGenerateDialog : public QDialog {
+class SubkeyGenerateDialog : public GeneralDialog {
Q_OBJECT
public:
diff --git a/src/ui/keypair_details/KeyDetailsDialog.cpp b/src/ui/dialog/keypair_details/KeyDetailsDialog.cpp
index 3b3e8818..9c2f8003 100644
--- a/src/ui/keypair_details/KeyDetailsDialog.cpp
+++ b/src/ui/dialog/keypair_details/KeyDetailsDialog.cpp
@@ -26,16 +26,16 @@
*
*/
-#include "ui/keypair_details/KeyDetailsDialog.h"
+#include "KeyDetailsDialog.h"
-#include "ui/keypair_details/KeyPairDetailTab.h"
-#include "ui/keypair_details/KeyPairOperaTab.h"
-#include "ui/keypair_details/KeyPairSubkeyTab.h"
-#include "ui/keypair_details/KeyPairUIDTab.h"
+#include "KeyPairDetailTab.h"
+#include "KeyPairOperaTab.h"
+#include "KeyPairSubkeyTab.h"
+#include "KeyPairUIDTab.h"
namespace GpgFrontend::UI {
KeyDetailsDialog::KeyDetailsDialog(const GpgKey& key, QWidget* parent)
- : QDialog(parent) {
+ : GeneralDialog(typeid(KeyDetailsDialog).name(), parent) {
tab_widget_ = new QTabWidget();
tab_widget_->addTab(new KeyPairDetailTab(key.GetId(), tab_widget_),
_("KeyPair"));
diff --git a/src/ui/keypair_details/KeyDetailsDialog.h b/src/ui/dialog/keypair_details/KeyDetailsDialog.h
index e6f4472c..1ddcda00 100644
--- a/src/ui/keypair_details/KeyDetailsDialog.h
+++ b/src/ui/dialog/keypair_details/KeyDetailsDialog.h
@@ -31,10 +31,11 @@
#include "core/GpgContext.h"
#include "ui/GpgFrontendUI.h"
+#include "ui/dialog/GeneralDialog.h"
namespace GpgFrontend::UI {
-class KeyDetailsDialog : public QDialog {
+class KeyDetailsDialog : public GeneralDialog {
Q_OBJECT
public:
diff --git a/src/ui/keypair_details/KeyNewUIDDialog.cpp b/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp
index 9ff73f9e..18dd1967 100644
--- a/src/ui/keypair_details/KeyNewUIDDialog.cpp
+++ b/src/ui/dialog/keypair_details/KeyNewUIDDialog.cpp
@@ -24,7 +24,7 @@
*
*/
-#include "ui/keypair_details/KeyNewUIDDialog.h"
+#include "KeyNewUIDDialog.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgUIDOperator.h"
@@ -32,7 +32,8 @@
namespace GpgFrontend::UI {
KeyNewUIDDialog::KeyNewUIDDialog(const KeyId& key_id, QWidget* parent)
- : QDialog(parent), m_key_(GpgKeyGetter::GetInstance().GetKey(key_id)) {
+ : GeneralDialog(typeid(KeyNewUIDDialog).name(), parent),
+ m_key_(GpgKeyGetter::GetInstance().GetKey(key_id)) {
name_ = new QLineEdit();
name_->setMinimumWidth(240);
email_ = new QLineEdit();
@@ -65,7 +66,8 @@ KeyNewUIDDialog::KeyNewUIDDialog(const KeyId& key_id, QWidget* parent)
this->setAttribute(Qt::WA_DeleteOnClose, true);
this->setModal(true);
- connect(this, &KeyNewUIDDialog::SignalUIDCreated, SignalStation::GetInstance(),
+ connect(this, &KeyNewUIDDialog::SignalUIDCreated,
+ SignalStation::GetInstance(),
&SignalStation::SignalKeyDatabaseRefresh);
}
@@ -84,9 +86,9 @@ void KeyNewUIDDialog::slot_create_new_uid() {
}
auto error_string = error_stream.str();
if (error_string.empty()) {
- if (GpgUIDOperator::GetInstance().AddUID(m_key_, name_->text().toStdString(),
- comment_->text().toStdString(),
- email_->text().toStdString())) {
+ if (GpgUIDOperator::GetInstance().AddUID(
+ m_key_, name_->text().toStdString(), comment_->text().toStdString(),
+ email_->text().toStdString())) {
emit finished(1);
emit SignalUIDCreated();
} else
diff --git a/src/ui/keypair_details/KeyNewUIDDialog.h b/src/ui/dialog/keypair_details/KeyNewUIDDialog.h
index 24f2c6b1..291b59c4 100644
--- a/src/ui/keypair_details/KeyNewUIDDialog.h
+++ b/src/ui/dialog/keypair_details/KeyNewUIDDialog.h
@@ -29,9 +29,10 @@
#include "core/GpgContext.h"
#include "ui/GpgFrontendUI.h"
+#include "ui/dialog/GeneralDialog.h"
namespace GpgFrontend::UI {
-class KeyNewUIDDialog : public QDialog {
+class KeyNewUIDDialog : public GeneralDialog {
Q_OBJECT
public:
diff --git a/src/ui/keypair_details/KeyPairDetailTab.cpp b/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp
index 76f316e9..4a6e4b52 100644
--- a/src/ui/keypair_details/KeyPairDetailTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp
@@ -24,7 +24,7 @@
*
*/
-#include "ui/keypair_details/KeyPairDetailTab.h"
+#include "KeyPairDetailTab.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyImportExporter.h"
diff --git a/src/ui/keypair_details/KeyPairDetailTab.h b/src/ui/dialog/keypair_details/KeyPairDetailTab.h
index 9d0d6560..91ccdab8 100644
--- a/src/ui/keypair_details/KeyPairDetailTab.h
+++ b/src/ui/dialog/keypair_details/KeyPairDetailTab.h
@@ -29,9 +29,9 @@
#include "KeySetExpireDateDialog.h"
#include "core/GpgContext.h"
-#include "import_export/KeyServerImportDialog.h"
-#include "import_export/KeyUploadDialog.h"
#include "ui/GpgFrontendUI.h"
+#include "ui/dialog/import_export/KeyServerImportDialog.h"
+#include "ui/dialog/import_export/KeyUploadDialog.h"
namespace GpgFrontend::UI {
@@ -60,19 +60,19 @@ class KeyPairDetailTab : public QWidget {
private:
GpgKey key_; ///<
- QGroupBox* owner_box_; ///< Groupbox containing owner information
- QGroupBox* key_box_; ///< Groupbox containing key information
- QGroupBox* fingerprint_box_; ///< Groupbox containing fingerprint information
+ QGroupBox* owner_box_; ///< Groupbox containing owner information
+ QGroupBox* key_box_; ///< Groupbox containing key information
+ QGroupBox* fingerprint_box_; ///< Groupbox containing fingerprint information
QGroupBox* additional_uid_box_; ///< Groupbox containing information about
///< additional uids
- QLabel* name_var_label_; ///< Label containing the keys name
- QLabel* email_var_label_; ///< Label containing the keys email
- QLabel* comment_var_label_; ///< Label containing the keys comment
- QLabel* key_size_var_label_; ///< Label containing the keys key size
- QLabel* expire_var_label_; ///< Label containing the keys expiration date
- QLabel* created_var_label_; ///< Label containing the keys creation date
- QLabel* last_update_var_label_; ///<
+ QLabel* name_var_label_; ///< Label containing the keys name
+ QLabel* email_var_label_; ///< Label containing the keys email
+ QLabel* comment_var_label_; ///< Label containing the keys comment
+ QLabel* key_size_var_label_; ///< Label containing the keys key size
+ QLabel* expire_var_label_; ///< Label containing the keys expiration date
+ QLabel* created_var_label_; ///< Label containing the keys creation date
+ QLabel* last_update_var_label_; ///<
QLabel* algorithm_var_label_; ///< Label containing the keys algorithm
QLabel* key_id_var_label; ///< Label containing the keys keyid
QLabel* fingerprint_var_label_; ///< Label containing the keys fingerprint
diff --git a/src/ui/keypair_details/KeyPairOperaTab.cpp b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp
index 4f7cd66f..77eba0bc 100644
--- a/src/ui/keypair_details/KeyPairOperaTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp
@@ -26,12 +26,12 @@
#include "KeyPairOperaTab.h"
+#include "KeySetExpireDateDialog.h"
#include "core/function/gpg/GpgKeyImportExporter.h"
#include "core/function/gpg/GpgKeyOpera.h"
-#include "import_export/KeyUploadDialog.h"
#include "ui/SignalStation.h"
#include "ui/UserInterfaceUtils.h"
-#include "ui/keypair_details/KeySetExpireDateDialog.h"
+#include "ui/dialog/import_export/KeyUploadDialog.h"
namespace GpgFrontend::UI {
diff --git a/src/ui/keypair_details/KeyPairOperaTab.h b/src/ui/dialog/keypair_details/KeyPairOperaTab.h
index af6b1eee..af6b1eee 100644
--- a/src/ui/keypair_details/KeyPairOperaTab.h
+++ b/src/ui/dialog/keypair_details/KeyPairOperaTab.h
diff --git a/src/ui/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp
index 46de550c..fe1d0798 100644
--- a/src/ui/keypair_details/KeyPairSubkeyTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp
@@ -26,7 +26,7 @@
*
*/
-#include "ui/keypair_details/KeyPairSubkeyTab.h"
+#include "KeyPairSubkeyTab.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "ui/SignalStation.h"
diff --git a/src/ui/keypair_details/KeyPairSubkeyTab.h b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.h
index a64d143c..a93ebca5 100644
--- a/src/ui/keypair_details/KeyPairSubkeyTab.h
+++ b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.h
@@ -32,7 +32,7 @@
#include "KeySetExpireDateDialog.h"
#include "core/GpgContext.h"
#include "ui/GpgFrontendUI.h"
-#include "ui/key_generate/SubkeyGenerateDialog.h"
+#include "ui/dialog/key_generate/SubkeyGenerateDialog.h"
namespace GpgFrontend::UI {
diff --git a/src/ui/keypair_details/KeyPairUIDTab.cpp b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp
index 4cc835a8..b923dbec 100644
--- a/src/ui/keypair_details/KeyPairUIDTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp
@@ -24,7 +24,7 @@
*
*/
-#include "ui/keypair_details/KeyPairUIDTab.h"
+#include "KeyPairUIDTab.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyManager.h"
diff --git a/src/ui/keypair_details/KeyPairUIDTab.h b/src/ui/dialog/keypair_details/KeyPairUIDTab.h
index fae8f9f2..fae8f9f2 100644
--- a/src/ui/keypair_details/KeyPairUIDTab.h
+++ b/src/ui/dialog/keypair_details/KeyPairUIDTab.h
diff --git a/src/ui/keypair_details/KeySetExpireDateDialog.cpp b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
index f2ccc240..2c10b895 100644
--- a/src/ui/keypair_details/KeySetExpireDateDialog.cpp
+++ b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
@@ -26,7 +26,7 @@
*
*/
-#include "ui/keypair_details/KeySetExpireDateDialog.h"
+#include "KeySetExpireDateDialog.h"
#include <utility>
@@ -40,7 +40,7 @@ namespace GpgFrontend::UI {
KeySetExpireDateDialog::KeySetExpireDateDialog(const KeyId& key_id,
QWidget* parent)
- : QDialog(parent),
+ : GeneralDialog(typeid(KeySetExpireDateDialog).name(), parent),
ui_(std::make_shared<Ui_ModifiedExpirationDateTime>()),
m_key_(GpgKeyGetter::GetInstance().GetKey(key_id)) {
init();
@@ -49,7 +49,7 @@ KeySetExpireDateDialog::KeySetExpireDateDialog(const KeyId& key_id,
KeySetExpireDateDialog::KeySetExpireDateDialog(const KeyId& key_id,
std::string subkey_fpr,
QWidget* parent)
- : QDialog(parent),
+ : GeneralDialog(typeid(KeySetExpireDateDialog).name(), parent),
ui_(std::make_shared<Ui_ModifiedExpirationDateTime>()),
m_key_(GpgKeyGetter::GetInstance().GetKey(key_id)),
m_subkey_(std::move(subkey_fpr)) {
diff --git a/src/ui/keypair_details/KeySetExpireDateDialog.h b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.h
index 3c0b62f7..3cd6cd01 100644
--- a/src/ui/keypair_details/KeySetExpireDateDialog.h
+++ b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.h
@@ -33,12 +33,13 @@
#include "core/model/GpgKey.h"
#include "core/model/GpgSubKey.h"
#include "ui/GpgFrontendUI.h"
+#include "ui/dialog/GeneralDialog.h"
class Ui_ModifiedExpirationDateTime;
namespace GpgFrontend::UI {
-class KeySetExpireDateDialog : public QDialog {
+class KeySetExpireDateDialog : public GeneralDialog {
Q_OBJECT
public:
/**
diff --git a/src/ui/keypair_details/KeyUIDSignDialog.cpp b/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp
index 2ed45512..0f7de587 100644
--- a/src/ui/keypair_details/KeyUIDSignDialog.cpp
+++ b/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp
@@ -24,7 +24,7 @@
*
*/
-#include "ui/keypair_details/KeyUIDSignDialog.h"
+#include "KeyUIDSignDialog.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyManager.h"
@@ -34,7 +34,9 @@ namespace GpgFrontend::UI {
KeyUIDSignDialog::KeyUIDSignDialog(const GpgKey& key, UIDArgsListPtr uid,
QWidget* parent)
- : QDialog(parent), m_uids_(std::move(uid)), m_key_(key) {
+ : GeneralDialog(typeid(KeyUIDSignDialog).name(), parent),
+ m_uids_(std::move(uid)),
+ m_key_(key) {
const auto key_id = m_key_.GetId();
m_key_list_ = new KeyList(KeyMenuAbility::NONE, this);
m_key_list_->AddListGroupTab(
diff --git a/src/ui/keypair_details/KeyUIDSignDialog.h b/src/ui/dialog/keypair_details/KeyUIDSignDialog.h
index 7c1cb58c..bfaff6d2 100644
--- a/src/ui/keypair_details/KeyUIDSignDialog.h
+++ b/src/ui/dialog/keypair_details/KeyUIDSignDialog.h
@@ -29,11 +29,12 @@
#include "core/GpgContext.h"
#include "ui/GpgFrontendUI.h"
+#include "ui/dialog/GeneralDialog.h"
#include "ui/widgets/KeyList.h"
namespace GpgFrontend::UI {
-class KeyUIDSignDialog : public QDialog {
+class KeyUIDSignDialog : public GeneralDialog {
Q_OBJECT
public:
diff --git a/src/ui/settings/SettingsAdvanced.cpp b/src/ui/dialog/settings/SettingsAdvanced.cpp
index 516d4d02..516d4d02 100644
--- a/src/ui/settings/SettingsAdvanced.cpp
+++ b/src/ui/dialog/settings/SettingsAdvanced.cpp
diff --git a/src/ui/settings/SettingsAdvanced.h b/src/ui/dialog/settings/SettingsAdvanced.h
index c1a3d5a6..c1a3d5a6 100644
--- a/src/ui/settings/SettingsAdvanced.h
+++ b/src/ui/dialog/settings/SettingsAdvanced.h
diff --git a/src/ui/settings/SettingsAppearance.cpp b/src/ui/dialog/settings/SettingsAppearance.cpp
index 7e54c9f8..17471a0d 100644
--- a/src/ui/settings/SettingsAppearance.cpp
+++ b/src/ui/dialog/settings/SettingsAppearance.cpp
@@ -114,11 +114,10 @@ AppearanceTab::AppearanceTab(QWidget* parent) : QWidget(parent) {
* appropriately
**********************************/
void AppearanceTab::SetSettings() {
+ SettingsObject general_settings_state("general_settings_state");
- SettingsObject main_windows_state("main_windows_state");
-
- int width = main_windows_state.Check("icon_size").Check("width", 24),
- height = main_windows_state.Check("icon_size").Check("height", 24);
+ int width = general_settings_state.Check("icon_size").Check("width", 24),
+ height = general_settings_state.Check("icon_size").Check("height", 24);
auto icon_size = QSize(width, height);
@@ -136,7 +135,7 @@ void AppearanceTab::SetSettings() {
// icon_style
int s_icon_style =
- main_windows_state.Check("icon_style", Qt::ToolButtonTextUnderIcon);
+ general_settings_state.Check("icon_style", Qt::ToolButtonTextUnderIcon);
auto icon_style = static_cast<Qt::ToolButtonStyle>(s_icon_style);
switch (icon_style) {
@@ -153,10 +152,10 @@ void AppearanceTab::SetSettings() {
break;
}
- bool window_save = main_windows_state.Check("window_save", true);
+ bool window_save = general_settings_state.Check("window_save", true);
if (window_save) window_size_check_box_->setCheckState(Qt::Checked);
- auto info_font_size = main_windows_state.Check("info_font_size", 10);
+ auto info_font_size = general_settings_state.Check("font_size", 10);
if (info_font_size < 9 || info_font_size > 18) info_font_size = 10;
info_board_font_size_spin_->setValue(info_font_size);
}
@@ -167,7 +166,7 @@ void AppearanceTab::SetSettings() {
*************************************/
void AppearanceTab::ApplySettings() {
- SettingsObject main_windows_state("main_windows_state");
+ SettingsObject general_settings_state("general_settings_state");
int icon_size = 24;
switch (icon_size_group_->checkedId()) {
@@ -182,8 +181,8 @@ void AppearanceTab::ApplySettings() {
break;
}
- main_windows_state["icon_size"]["width"] = icon_size;
- main_windows_state["icon_size"]["height"] = icon_size;
+ general_settings_state["icon_size"]["width"] = icon_size;
+ general_settings_state["icon_size"]["height"] = icon_size;
auto icon_style = Qt::ToolButtonTextUnderIcon;
switch (icon_style_group_->checkedId()) {
@@ -198,12 +197,11 @@ void AppearanceTab::ApplySettings() {
break;
}
- main_windows_state["icon_style"] = icon_style;
-
- main_windows_state["window_save"] = window_size_check_box_->isChecked();
+ general_settings_state["icon_style"] = icon_style;
- main_windows_state["info_font_size"] = info_board_font_size_spin_->value();
+ general_settings_state["window_save"] = window_size_check_box_->isChecked();
+ general_settings_state["info_font_size"] = info_board_font_size_spin_->value();
}
} // namespace GpgFrontend::UI
diff --git a/src/ui/settings/SettingsAppearance.h b/src/ui/dialog/settings/SettingsAppearance.h
index 7110d992..7110d992 100644
--- a/src/ui/settings/SettingsAppearance.h
+++ b/src/ui/dialog/settings/SettingsAppearance.h
diff --git a/src/ui/settings/SettingsDialog.cpp b/src/ui/dialog/settings/SettingsDialog.cpp
index eefdd3c7..e2677a0f 100644
--- a/src/ui/settings/SettingsDialog.cpp
+++ b/src/ui/dialog/settings/SettingsDialog.cpp
@@ -28,17 +28,18 @@
#include "SettingsDialog.h"
+#include "SettingsAdvanced.h"
+#include "SettingsAppearance.h"
+#include "SettingsGeneral.h"
+#include "SettingsKeyServer.h"
+#include "SettingsNetwork.h"
#include "core/function/GlobalSettingStation.h"
#include "ui/main_window/MainWindow.h"
-#include "ui/settings/SettingsAdvanced.h"
-#include "ui/settings/SettingsAppearance.h"
-#include "ui/settings/SettingsGeneral.h"
-#include "ui/settings/SettingsKeyServer.h"
-#include "ui/settings/SettingsNetwork.h"
namespace GpgFrontend::UI {
-SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent) {
+SettingsDialog::SettingsDialog(QWidget* parent)
+ : GeneralDialog(typeid(SettingsDialog).name(), parent) {
tab_widget_ = new QTabWidget();
general_tab_ = new GeneralTab();
appearance_tab_ = new AppearanceTab();
diff --git a/src/ui/settings/SettingsDialog.h b/src/ui/dialog/settings/SettingsDialog.h
index e123cc6c..172370d0 100755..100644
--- a/src/ui/settings/SettingsDialog.h
+++ b/src/ui/dialog/settings/SettingsDialog.h
@@ -30,6 +30,7 @@
#define __SETTINGSDIALOG_H__
#include "ui/GpgFrontendUI.h"
+#include "ui/dialog/GeneralDialog.h"
#include "ui/widgets/KeyList.h"
namespace GpgFrontend::UI {
@@ -43,7 +44,7 @@ class NetworkTab;
* @brief
*
*/
-class SettingsDialog : public QDialog {
+class SettingsDialog : public GeneralDialog {
Q_OBJECT
public:
@@ -54,7 +55,7 @@ class SettingsDialog : public QDialog {
*/
explicit SettingsDialog(QWidget* parent = nullptr);
- GeneralTab* general_tab_; ///<
+ GeneralTab* general_tab_; ///<
AppearanceTab* appearance_tab_; ///<
KeyserverTab* key_server_tab_; ///<
NetworkTab* network_tab_; ///<
diff --git a/src/ui/settings/SettingsGeneral.cpp b/src/ui/dialog/settings/SettingsGeneral.cpp
index 3c7bca32..3c7bca32 100644
--- a/src/ui/settings/SettingsGeneral.cpp
+++ b/src/ui/dialog/settings/SettingsGeneral.cpp
diff --git a/src/ui/settings/SettingsGeneral.h b/src/ui/dialog/settings/SettingsGeneral.h
index b3e7d904..b3e7d904 100644
--- a/src/ui/settings/SettingsGeneral.h
+++ b/src/ui/dialog/settings/SettingsGeneral.h
diff --git a/src/ui/settings/SettingsKeyServer.cpp b/src/ui/dialog/settings/SettingsKeyServer.cpp
index 94655871..2c09b66c 100644
--- a/src/ui/settings/SettingsKeyServer.cpp
+++ b/src/ui/dialog/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/settings/SettingsKeyServer.h b/src/ui/dialog/settings/SettingsKeyServer.h
index f983e69b..f983e69b 100644
--- a/src/ui/settings/SettingsKeyServer.h
+++ b/src/ui/dialog/settings/SettingsKeyServer.h
diff --git a/src/ui/settings/SettingsNetwork.cpp b/src/ui/dialog/settings/SettingsNetwork.cpp
index d4edae42..d4edae42 100644
--- a/src/ui/settings/SettingsNetwork.cpp
+++ b/src/ui/dialog/settings/SettingsNetwork.cpp
diff --git a/src/ui/settings/SettingsNetwork.h b/src/ui/dialog/settings/SettingsNetwork.h
index d4c0d00d..d4c0d00d 100644
--- a/src/ui/settings/SettingsNetwork.h
+++ b/src/ui/dialog/settings/SettingsNetwork.h
diff --git a/src/ui/main_window/GeneralMainWindow.cpp b/src/ui/main_window/GeneralMainWindow.cpp
new file mode 100644
index 00000000..7df73aba
--- /dev/null
+++ b/src/ui/main_window/GeneralMainWindow.cpp
@@ -0,0 +1,135 @@
+/**
+ * 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 "GeneralMainWindow.h"
+
+#include <utility>
+
+#include "ui/struct/SettingsObject.h"
+
+GpgFrontend::UI::GeneralMainWindow::GeneralMainWindow(std::string name,
+ QWidget* parent)
+ : name_(std::move(name)), QMainWindow(parent) {
+ slot_restore_settings();
+}
+
+GpgFrontend::UI::GeneralMainWindow::~GeneralMainWindow() = default;
+
+void GpgFrontend::UI::GeneralMainWindow::closeEvent(QCloseEvent* event) {
+ slot_save_settings();
+ QMainWindow::closeEvent(event);
+}
+
+void GpgFrontend::UI::GeneralMainWindow::slot_restore_settings() noexcept {
+ try {
+ LOG(INFO) << name_ << _("Called");
+
+ SettingsObject general_windows_state(name_ + "_state");
+
+ std::string window_state = general_windows_state.Check(
+ "window_state", saveState().toBase64().toStdString());
+
+ // state sets pos & size of dock-widgets
+ this->restoreState(
+ QByteArray::fromBase64(QByteArray::fromStdString(window_state)));
+
+ bool window_save = general_windows_state.Check("window_save", true);
+
+ // Restore window size & location
+ if (window_save) {
+ int x = general_windows_state.Check("window_pos").Check("x", 100),
+ y = general_windows_state.Check("window_pos").Check("y", 100);
+
+ this->move({x, y});
+ pos_ = {x, y};
+
+ int width =
+ general_windows_state.Check("window_size").Check("width", 800),
+ height =
+ general_windows_state.Check("window_size").Check("height", 450);
+
+ this->resize({width, height});
+ size_ = {width, height};
+ }
+
+
+ // appearance
+ SettingsObject general_settings_state("general_settings_state");
+
+ int width = general_settings_state.Check("icon_size").Check("width", 24),
+ height = general_settings_state.Check("icon_size").Check("height", 24);
+ LOG(INFO) << "icon_size" << width << height;
+
+ icon_size_ = {width, height};
+ font_size_ = general_settings_state.Check("font_size", 10);
+
+ this->setIconSize(icon_size_);
+
+ // icon_style
+ int s_icon_style =
+ general_settings_state.Check("icon_style", Qt::ToolButtonTextUnderIcon);
+ this->setToolButtonStyle(static_cast<Qt::ToolButtonStyle>(s_icon_style));
+ icon_style_ = toolButtonStyle();
+
+ } catch (...) {
+ LOG(ERROR) << name_ << "error";
+ }
+}
+
+void GpgFrontend::UI::GeneralMainWindow::slot_save_settings() noexcept {
+ try {
+ LOG(INFO) << name_ << _("Called");
+
+ SettingsObject general_windows_state(name_ + "_state");
+
+ // window position and size
+ general_windows_state["window_state"] =
+ saveState().toBase64().toStdString();
+ general_windows_state["window_pos"]["x"] = pos().x();
+ general_windows_state["window_pos"]["y"] = pos().y();
+
+ general_windows_state["window_size"]["width"] = size_.width();
+ general_windows_state["window_size"]["height"] = size_.height();
+ general_windows_state["window_save"] = true;
+
+ SettingsObject general_settings_state("general_settings_state");
+
+ // icon size
+ general_settings_state["icon_size"]["width"] = icon_size_.width();
+ general_settings_state["icon_size"]["height"] = icon_size_.height();
+
+ // font size
+ general_settings_state["font_size"] = font_size_;
+
+ // tool button style
+ general_settings_state["icon_style"] = this->toolButtonStyle();
+
+ } catch (...) {
+ LOG(ERROR) << name_ << "error";
+ }
+}
diff --git a/src/ui/main_window/GeneralMainWindow.h b/src/ui/main_window/GeneralMainWindow.h
new file mode 100644
index 00000000..71327100
--- /dev/null
+++ b/src/ui/main_window/GeneralMainWindow.h
@@ -0,0 +1,81 @@
+/**
+ * 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_GENERALMAINWINDOW_H
+#define GPGFRONTEND_GENERALMAINWINDOW_H
+
+#include "ui/GpgFrontendUI.h"
+
+namespace GpgFrontend::UI {
+
+/**
+ *
+ */
+class GeneralMainWindow : public QMainWindow {
+ public:
+ /**
+ *
+ * @param name
+ */
+ explicit GeneralMainWindow(std::string name, QWidget* parent = nullptr);
+
+ /**
+ *
+ */
+ ~GeneralMainWindow() override;
+
+ protected:
+ /**
+ *
+ * @param event
+ */
+ void closeEvent(QCloseEvent* event);
+
+ QSize icon_size_{}; ///<
+ int font_size_{}; ///<
+ Qt::ToolButtonStyle icon_style_; ///<
+
+ private slots:
+ /**
+ *
+ */
+ void slot_restore_settings() noexcept;
+
+ /**
+ *
+ */
+ void slot_save_settings() noexcept;
+
+ private:
+ std::string name_; ///<
+ QPoint pos_; ///<
+ QSize size_; ///<
+};
+} // namespace GpgFrontend::UI
+
+#endif // GPGFRONTEND_GENERALMAINWINDOW_H
diff --git a/src/ui/KeyMgmt.cpp b/src/ui/main_window/KeyMgmt.cpp
index 30bc8a1b..6dc2b14f 100755..100644
--- a/src/ui/KeyMgmt.cpp
+++ b/src/ui/main_window/KeyMgmt.cpp
@@ -26,24 +26,25 @@
*
*/
-#include "ui/KeyMgmt.h"
+#include "KeyMgmt.h"
#include <utility>
+#include "core/function/GlobalSettingStation.h"
+#include "core/function/KeyPackageOperator.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyImportExporter.h"
#include "core/function/gpg/GpgKeyOpera.h"
-#include "core/function/KeyPackageOperator.h"
#include "ui/SignalStation.h"
#include "ui/UserInterfaceUtils.h"
-#include "ui/import_export/ExportKeyPackageDialog.h"
-#include "ui/key_generate/SubkeyGenerateDialog.h"
+#include "ui/dialog/import_export/ExportKeyPackageDialog.h"
+#include "ui/dialog/key_generate/SubkeyGenerateDialog.h"
#include "ui/main_window/MainWindow.h"
-#include "core/function/GlobalSettingStation.h"
namespace GpgFrontend::UI {
-KeyMgmt::KeyMgmt(QWidget* parent) : QMainWindow(parent) {
+KeyMgmt::KeyMgmt(QWidget* parent)
+ : GeneralMainWindow("key_management", parent) {
/* the list of Keys available*/
key_list_ = new KeyList(KeyMenuAbility::ALL, this);
@@ -105,53 +106,6 @@ KeyMgmt::KeyMgmt(QWidget* parent) : QMainWindow(parent) {
auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
- try {
- int width = settings.lookup("window.icon_size.width");
- int height = settings.lookup("window.icon_size.height");
-
- this->setIconSize(QSize(width, height));
-
- } catch (...) {
- LOG(ERROR) << _("Setting Operation Error") << _("icon_size");
- }
-
- // icon_style
- try {
- int s_icon_style = settings.lookup("window.icon_style");
- auto icon_style = static_cast<Qt::ToolButtonStyle>(s_icon_style);
- this->setToolButtonStyle(icon_style);
- } catch (...) {
- LOG(ERROR) << _("Setting Operation Error") << _("icon_style");
- }
-
- auto pos = QPoint(50, 50);
- LOG(INFO) << "parent" << parent;
- if (parent) pos += parent->pos();
- LOG(INFO) << "pos default" << pos.x() << pos.y();
- auto size = QSize(900, 600);
-
- try {
- int x, y, width, height;
- x = settings.lookup("window.key_management.position.x");
- y = settings.lookup("window.key_management.position.y");
- width = settings.lookup("window.key_management.size.width");
- height = settings.lookup("window.key_management.size.height");
- pos = QPoint(x, y);
- size = QSize(width, height);
-
- std::string window_state =
- settings.lookup("window.key_management.window_state");
-
- // state sets pos & size of dock-widgets
- this->restoreState(
- QByteArray::fromBase64(QByteArray::fromStdString(window_state)));
-
- } catch (...) {
- LOG(WARNING) << "cannot read pos or size from settings";
- }
-
- this->resize(size);
- this->move(pos);
this->statusBar()->show();
setWindowTitle(_("KeyPair Management"));
@@ -296,7 +250,7 @@ void KeyMgmt::create_tool_bars() {
generateToolButton->setIcon(QIcon(":key_generate.png"));
generateToolButton->setText(_("Generate"));
generateToolButton->setToolTip(_("Generate A New Keypair or Subkey"));
- generateToolButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
+ generateToolButton->setToolButtonStyle(icon_style_);
keyToolBar->addWidget(generateToolButton);
// add button with popup menu for import
@@ -306,7 +260,7 @@ void KeyMgmt::create_tool_bars() {
toolButton->setIcon(QIcon(":key_import.png"));
toolButton->setToolTip(_("Import key"));
toolButton->setText(_("Import Key"));
- toolButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
+ toolButton->setToolButtonStyle(icon_style_);
keyToolBar->addWidget(toolButton);
keyToolBar->addSeparator();
@@ -406,11 +360,6 @@ void KeyMgmt::SlotGenerateKeyDialog() {
keyGenDialog->show();
}
-void KeyMgmt::closeEvent(QCloseEvent* event) {
- SlotSaveWindowState();
- QMainWindow::closeEvent(event);
-}
-
void KeyMgmt::SlotGenerateSubKey() {
auto keys_selected = key_list_->GetSelected();
if (keys_selected->empty()) {
@@ -434,52 +383,6 @@ void KeyMgmt::SlotGenerateSubKey() {
auto dialog = new SubkeyGenerateDialog(key.GetId(), this);
dialog->show();
}
-void KeyMgmt::SlotSaveWindowState() {
- auto& settings =
- GpgFrontend::GlobalSettingStation::GetInstance().GetUISettings();
-
- if (!settings.exists("window") ||
- settings.lookup("window").getType() != libconfig::Setting::TypeGroup)
- settings.add("window", libconfig::Setting::TypeGroup);
-
- auto& window = settings["window"];
-
- if (!window.exists("key_management") ||
- window.lookup("key_management").getType() !=
- libconfig::Setting::TypeGroup)
- window.add("key_management", libconfig::Setting::TypeGroup);
-
- auto& key_management = window["key_management"];
-
- if (!key_management.exists("position") ||
- key_management.lookup("position").getType() !=
- libconfig::Setting::TypeGroup) {
- auto& position =
- key_management.add("position", libconfig::Setting::TypeGroup);
- position.add("x", libconfig::Setting::TypeInt) = pos().x();
- position.add("y", libconfig::Setting::TypeInt) = pos().y();
- } else {
- key_management["position"]["x"] = pos().x();
- key_management["position"]["y"] = pos().y();
- }
-
- if (!key_management.exists("size") ||
- key_management.lookup("size").getType() !=
- libconfig::Setting::TypeGroup) {
- auto& size = key_management.add("size", libconfig::Setting::TypeGroup);
- size.add("width", libconfig::Setting::TypeInt) = QWidget::width();
- size.add("height", libconfig::Setting::TypeInt) = QWidget::height();
- } else {
- key_management["size"]["width"] = QWidget::width();
- key_management["size"]["height"] = QWidget::height();
- }
-
- if (!key_management.exists("window_state"))
- key_management.add("window_state", libconfig::Setting::TypeString) =
- saveState().toBase64().toStdString();
-
- GlobalSettingStation::GetInstance().SyncSettings();
-}
void KeyMgmt::SlotExportAsOpenSSHFormat() {
ByteArrayPtr key_export_data = nullptr;
@@ -527,7 +430,6 @@ void KeyMgmt::SlotExportAsOpenSSHFormat() {
}
void KeyMgmt::SlotImportKeyPackage() {
-
LOG(INFO) << "Importing key package...";
auto key_package_file_name = QFileDialog::getOpenFileName(
@@ -538,8 +440,7 @@ void KeyMgmt::SlotImportKeyPackage() {
this, _("Import Key Package Passphrase File"), {},
QString(_("Key Package Passphrase File")) + " (*.key);;All Files (*)");
- if(key_package_file_name.isEmpty() || key_file_name.isEmpty())
- return;
+ if (key_package_file_name.isEmpty() || key_file_name.isEmpty()) return;
GpgImportInformation info;
diff --git a/src/ui/KeyMgmt.h b/src/ui/main_window/KeyMgmt.h
index 25ee80c5..2073113a 100755..100644
--- a/src/ui/KeyMgmt.h
+++ b/src/ui/main_window/KeyMgmt.h
@@ -30,10 +30,11 @@
#define __KEYMGMT_H__
#include "ui/GpgFrontendUI.h"
-#include "ui/import_export/KeyImportDetailDialog.h"
-#include "ui/import_export/KeyServerImportDialog.h"
-#include "ui/key_generate/KeygenDialog.h"
-#include "ui/keypair_details/KeyDetailsDialog.h"
+#include "ui/dialog/import_export/KeyImportDetailDialog.h"
+#include "ui/dialog/import_export/KeyServerImportDialog.h"
+#include "ui/dialog/key_generate/KeygenDialog.h"
+#include "ui/dialog/keypair_details/KeyDetailsDialog.h"
+#include "ui/main_window/GeneralMainWindow.h"
#include "ui/widgets/KeyList.h"
namespace GpgFrontend::UI {
@@ -42,7 +43,7 @@ namespace GpgFrontend::UI {
* @brief
*
*/
-class KeyMgmt : public QMainWindow {
+class KeyMgmt : public GeneralMainWindow {
Q_OBJECT
public:
@@ -107,12 +108,6 @@ class KeyMgmt : public QMainWindow {
* @brief
*
*/
- void SlotSaveWindowState();
-
- /**
- * @brief
- *
- */
void SlotImportKeyPackage();
signals:
@@ -176,14 +171,6 @@ class KeyMgmt : public QMainWindow {
QAction* close_act_{}; ///<
QAction* show_key_details_act_{}; ///<
KeyServerImportDialog* import_dialog_{}; ///<
-
- protected:
- /**
- * @brief
- *
- * @param event
- */
- void closeEvent(QCloseEvent* event) override;
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp
index d04e3dbd..e3e4c0ab 100644
--- a/src/ui/main_window/MainWindow.cpp
+++ b/src/ui/main_window/MainWindow.cpp
@@ -36,7 +36,7 @@
namespace GpgFrontend::UI {
-MainWindow::MainWindow() {
+MainWindow::MainWindow() : GeneralMainWindow("main_window") {
this->setMinimumSize(1200, 700);
this->setWindowTitle(qApp->applicationName());
}
@@ -135,63 +135,14 @@ void MainWindow::restore_settings() {
LOG(INFO) << _("Called");
try {
- LOG(INFO) << "restore settings main_windows_state";
-
- SettingsObject main_windows_state("main_windows_state");
-
- std::string window_state = main_windows_state.Check(
- "window_state", saveState().toBase64().toStdString());
- // state sets pos & size of dock-widgets
- this->restoreState(
- QByteArray::fromBase64(QByteArray::fromStdString(window_state)));
-
- bool window_save = main_windows_state.Check("window_save", true);
-
- // Restore window size & location
- if (window_save) {
- int x = main_windows_state.Check("window_pos").Check("x", 100),
- y = main_windows_state.Check("window_pos").Check("y", 100);
-
- auto pos = QPoint(x, y);
-
- int width = main_windows_state.Check("window_size").Check("width", 800),
- height = main_windows_state.Check("window_size").Check("height", 450);
-
- auto size = QSize(width, height);
- this->resize(size);
- this->move(pos);
- } else {
- this->resize(QSize(800, 450));
- this->move(QPoint(100, 100));
- }
-
- int width = main_windows_state.Check("icon_size").Check("width", 24),
- height = main_windows_state.Check("icon_size").Check("height", 24);
- LOG(INFO) << "icon_size" << width << height;
-
- main_windows_state.Check("info_font_size", 10);
-
- // icon_style
- int s_icon_style =
- main_windows_state.Check("icon_style", Qt::ToolButtonTextUnderIcon);
- auto icon_style = static_cast<Qt::ToolButtonStyle>(s_icon_style);
- this->setToolButtonStyle(icon_style);
- import_button_->setToolButtonStyle(icon_style);
-
- // icons ize
- this->setIconSize(QSize(width, height));
- import_button_->setIconSize(QSize(width, height));
-
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;
}
@@ -216,6 +167,9 @@ void MainWindow::restore_settings() {
bool save_key_checked = true;
general.lookupValue("save_key_checked", save_key_checked);
+ // set appearance
+ import_button_->setToolButtonStyle(icon_style_);
+
try {
LOG(INFO) << "restore settings default_key_checked";
@@ -255,16 +209,6 @@ void MainWindow::save_settings() {
auto &settings = GlobalSettingStation::GetInstance().GetUISettings();
try {
- SettingsObject main_windows_state("main_windows_state");
-
- // window position and size
- main_windows_state["window_state"] = saveState().toBase64().toStdString();
- main_windows_state["window_pos"]["x"] = pos().x();
- main_windows_state["window_pos"]["y"] = pos().y();
-
- main_windows_state["window_size"]["width"] = size().width();
- main_windows_state["window_size"]["height"] = size().height();
-
bool save_key_checked = settings.lookup("general.save_key_checked");
// keyid-list of private checked keys
diff --git a/src/ui/main_window/MainWindow.h b/src/ui/main_window/MainWindow.h
index a0f1a5d4..b31e2fcb 100644
--- a/src/ui/main_window/MainWindow.h
+++ b/src/ui/main_window/MainWindow.h
@@ -29,17 +29,18 @@
#ifndef __GPGWIN_H__
#define __GPGWIN_H__
+#include "KeyMgmt.h"
#include "core/GpgConstants.h"
#include "core/function/result_analyse/GpgDecryptResultAnalyse.h"
#include "core/function/result_analyse/GpgEncryptResultAnalyse.h"
#include "core/function/result_analyse/GpgSignResultAnalyse.h"
#include "ui/GpgFrontendUI.h"
-#include "ui/KeyMgmt.h"
#include "ui/dialog/WaitingDialog.h"
#include "ui/dialog/Wizard.h"
-#include "ui/help/AboutDialog.h"
-#include "ui/import_export/KeyUploadDialog.h"
-#include "ui/settings/SettingsDialog.h"
+#include "ui/dialog/help/AboutDialog.h"
+#include "ui/dialog/import_export/KeyUploadDialog.h"
+#include "ui/dialog/settings/SettingsDialog.h"
+#include "ui/main_window/GeneralMainWindow.h"
#include "ui/widgets/FindWidget.h"
#include "ui/widgets/InfoBoardWidget.h"
#include "ui/widgets/TextEdit.h"
@@ -49,10 +50,13 @@ namespace GpgFrontend::UI {
* @brief
*
*/
-class MainWindow : public QMainWindow {
+class MainWindow : public GeneralMainWindow {
Q_OBJECT
public:
+ /**
+ *
+ */
struct CryptoMenu {
using OperationType = unsigned int;
@@ -383,6 +387,7 @@ class MainWindow : public QMainWindow {
QAction* about_act_{}; ///< Action to open about dialog
QAction* check_update_act_{}; ///< Action to open about dialog
QAction* translate_act_{}; ///< Action to open about dialog
+ QAction* gnupg_act_{}; ///< Action to open about dialog
QAction* open_settings_act_{}; ///< Action to open settings dialog
QAction* show_key_details_act_{}; ///< Action to open key-details dialog
QAction* start_wizard_act_{}; ///< Action to open the wizard
diff --git a/src/ui/main_window/MainWindowFileSlotFunction.cpp b/src/ui/main_window/MainWindowFileSlotFunction.cpp
index 4ab23a22..526c27c0 100644
--- a/src/ui/main_window/MainWindowFileSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowFileSlotFunction.cpp
@@ -32,8 +32,8 @@
#include "core/function/gpg/GpgFileOpera.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/thread/Task.h"
+#include "dialog/SignersPicker.h"
#include "ui/UserInterfaceUtils.h"
-#include "ui/widgets/SignersPicker.h"
namespace GpgFrontend::UI {
@@ -618,6 +618,9 @@ void MainWindow::SlotFileEncryptSign() {
connect(signersPicker, &SignersPicker::finished, &loop, &QEventLoop::quit);
loop.exec();
+ // return when canceled
+ if (!signersPicker->GetStatus()) return;
+
auto signer_key_ids = signersPicker->GetCheckedSigners();
auto p_signer_keys = GpgKeyGetter::GetInstance().GetKeys(signer_key_ids);
diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp
index 0ad52248..f715046c 100644
--- a/src/ui/main_window/MainWindowSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowSlotFunction.cpp
@@ -26,7 +26,6 @@
*
*/
-#include <cstddef>
#include <memory>
#include <string>
#include <utility>
@@ -34,15 +33,12 @@
#include "MainWindow.h"
#include "core/GpgConstants.h"
#include "core/GpgModel.h"
-#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgBasicOperator.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyImportExporter.h"
-#include "core/model/GpgKey.h"
-#include "core/thread/TaskRunner.h"
#include "ui/UserInterfaceUtils.h"
-#include "ui/help/AboutDialog.h"
-#include "ui/widgets/SignersPicker.h"
+#include "ui/dialog/help/AboutDialog.h"
+#include "dialog/SignersPicker.h"
namespace GpgFrontend::UI {
/**
@@ -427,6 +423,9 @@ void MainWindow::slot_encrypt_sign() {
connect(signersPicker, &SignersPicker::finished, &loop, &QEventLoop::quit);
loop.exec();
+ // return when canceled
+ if (!signersPicker->GetStatus()) return;
+
auto signer_key_ids = signersPicker->GetCheckedSigners();
auto signer_keys = GpgKeyGetter::GetInstance().GetKeys(signer_key_ids);
diff --git a/src/ui/main_window/MainWindowSlotUI.cpp b/src/ui/main_window/MainWindowSlotUI.cpp
index 9d81b11c..9061349e 100644
--- a/src/ui/main_window/MainWindowSlotUI.cpp
+++ b/src/ui/main_window/MainWindowSlotUI.cpp
@@ -105,17 +105,17 @@ void MainWindow::slot_open_settings_dialog() {
connect(dialog, &SettingsDialog::finished, this, [&]() -> void {
LOG(INFO) << "Setting Dialog Finished";
- SettingsObject main_windows_state("main_windows_state");
+ SettingsObject general_settings_state("general_settings_state");
- int width = main_windows_state.Check("icon_size").Check("width", 24),
- height = main_windows_state.Check("icon_size").Check("height", 24);
+ int width = general_settings_state.Check("icon_size").Check("width", 24),
+ height = general_settings_state.Check("icon_size").Check("height", 24);
LOG(INFO) << "icon_size" << width << height;
- main_windows_state.Check("info_font_size", 10);
+ general_settings_state.Check("info_font_size", 10);
// icon_style
int s_icon_style =
- main_windows_state.Check("icon_style", Qt::ToolButtonTextUnderIcon);
+ general_settings_state.Check("icon_style", Qt::ToolButtonTextUnderIcon);
auto icon_style = static_cast<Qt::ToolButtonStyle>(s_icon_style);
this->setToolButtonStyle(icon_style);
import_button_->setToolButtonStyle(icon_style);
diff --git a/src/ui/main_window/MainWindowUI.cpp b/src/ui/main_window/MainWindowUI.cpp
index 7d798c8b..1470b731 100644
--- a/src/ui/main_window/MainWindowUI.cpp
+++ b/src/ui/main_window/MainWindowUI.cpp
@@ -251,11 +251,17 @@ void MainWindow::create_actions() {
connect(about_act_, &QAction::triggered, this,
[=]() { new AboutDialog(0, this); });
+ gnupg_act_ = new QAction(_("GnuPG"), this);
+ gnupg_act_->setIcon(QIcon(":help.png"));
+ gnupg_act_->setToolTip(_("Information about Gnupg"));
+ connect(gnupg_act_, &QAction::triggered, this,
+ [=]() { new AboutDialog(1, this); });
+
translate_act_ = new QAction(_("Translate"), this);
translate_act_->setIcon(QIcon(":help.png"));
translate_act_->setToolTip(_("Information about translation"));
connect(translate_act_, &QAction::triggered, this,
- [=]() { new AboutDialog(1, this); });
+ [=]() { new AboutDialog(2, this); });
/*
* Check Update Menu
@@ -377,6 +383,7 @@ void MainWindow::create_menus() {
help_menu_->addSeparator();
help_menu_->addAction(check_update_act_);
help_menu_->addAction(translate_act_);
+ help_menu_->addAction(gnupg_act_);
help_menu_->addAction(about_act_);
}
diff --git a/src/ui/struct/SettingsObject.h b/src/ui/struct/SettingsObject.h
index 653a543f..d1e85be5 100644
--- a/src/ui/struct/SettingsObject.h
+++ b/src/ui/struct/SettingsObject.h
@@ -69,7 +69,8 @@ class SettingsObject : public nlohmann::json {
* @param default_value
* @return nlohmann::json&
*/
- nlohmann::json& Check(const std::string& key, const nlohmann::json& default_value);
+ nlohmann::json& Check(const std::string& key,
+ const nlohmann::json& default_value);
/**
* @brief
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..0090e79d
--- /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 {
/**
diff --git a/src/ui/widgets/FilePage.h b/src/ui/widgets/FilePage.h
index cff395a8..8e278de7 100644
--- a/src/ui/widgets/FilePage.h
+++ b/src/ui/widgets/FilePage.h
@@ -29,8 +29,6 @@
#ifndef GPGFRONTEND_FILEPAGE_H
#define GPGFRONTEND_FILEPAGE_H
-
-
#include "ui/GpgFrontendUI.h"
#include "ui/widgets/InfoBoardWidget.h"
diff --git a/src/ui/widgets/FindWidget.cpp b/src/ui/widgets/FindWidget.cpp
index defcf31c..598d8004 100644
--- a/src/ui/widgets/FindWidget.cpp
+++ b/src/ui/widgets/FindWidget.cpp
@@ -49,9 +49,11 @@ FindWidget::FindWidget(QWidget* parent, PlainTextEditorPage* edit)
this->setLayout(notificationWidgetLayout);
connect(find_edit_, &QLineEdit::textEdited, this, &FindWidget::slot_find);
- connect(find_edit_, &QLineEdit::returnPressed, this, &FindWidget::slot_find_next);
+ connect(find_edit_, &QLineEdit::returnPressed, this,
+ &FindWidget::slot_find_next);
connect(nextButton, &QPushButton::clicked, this, &FindWidget::slot_find_next);
- connect(previousButton, &QPushButton::clicked, this, &FindWidget::slot_find_previous);
+ connect(previousButton, &QPushButton::clicked, this,
+ &FindWidget::slot_find_previous);
connect(closeButton, &QPushButton::clicked, this, &FindWidget::slot_close);
// The timer is necessary for setting the focus
diff --git a/src/ui/widgets/InfoBoardWidget.cpp b/src/ui/widgets/InfoBoardWidget.cpp
index ec2971cc..264a67d1 100644
--- a/src/ui/widgets/InfoBoardWidget.cpp
+++ b/src/ui/widgets/InfoBoardWidget.cpp
@@ -28,10 +28,10 @@
#include "ui/widgets/InfoBoardWidget.h"
-#include "ui/SignalStation.h"
#include "core/function/GlobalSettingStation.h"
-#include "ui_InfoBoard.h"
+#include "ui/SignalStation.h"
#include "ui/struct/SettingsObject.h"
+#include "ui_InfoBoard.h"
namespace GpgFrontend::UI {
diff --git a/src/ui/widgets/InfoBoardWidget.h b/src/ui/widgets/InfoBoardWidget.h
index 7f456777..47740456 100644
--- a/src/ui/widgets/InfoBoardWidget.h
+++ b/src/ui/widgets/InfoBoardWidget.h
@@ -31,7 +31,7 @@
#include "PlainTextEditorPage.h"
#include "core/function/result_analyse/GpgVerifyResultAnalyse.h"
-#include "ui/details/VerifyDetailsDialog.h"
+#include "ui/dialog/details/VerifyDetailsDialog.h"
class Ui_InfoBoard;
diff --git a/src/ui/widgets/KeyList.h b/src/ui/widgets/KeyList.h
index 60449ad9..f1c88cc6 100644
--- a/src/ui/widgets/KeyList.h
+++ b/src/ui/widgets/KeyList.h
@@ -32,7 +32,7 @@
#include <utility>
#include "core/GpgContext.h"
-#include "ui/import_export/KeyImportDetailDialog.h"
+#include "ui/dialog/import_export/KeyImportDetailDialog.h"
class Ui_KeyList;
diff --git a/src/ui/widgets/VerifyKeyDetailBox.cpp b/src/ui/widgets/VerifyKeyDetailBox.cpp
index 4c936f4f..c6c4982c 100644
--- a/src/ui/widgets/VerifyKeyDetailBox.cpp
+++ b/src/ui/widgets/VerifyKeyDetailBox.cpp
@@ -41,7 +41,7 @@ VerifyKeyDetailBox::VerifyKeyDetailBox(const GpgSignature& signature,
case GPG_ERR_NO_PUBKEY: {
this->setTitle("A Error Signature");
auto* importButton = new QPushButton(_("Import from keyserver"));
- connect(importButton,&QPushButton::clicked, this,
+ connect(importButton, &QPushButton::clicked, this,
&VerifyKeyDetailBox::slot_import_form_key_server);
this->setTitle(QString(_("Key not present with id 0x")) + fpr_.c_str());
diff --git a/src/ui/widgets/VerifyKeyDetailBox.h b/src/ui/widgets/VerifyKeyDetailBox.h
index 57f133d5..6ed9fd52 100644
--- a/src/ui/widgets/VerifyKeyDetailBox.h
+++ b/src/ui/widgets/VerifyKeyDetailBox.h
@@ -29,7 +29,7 @@
#ifndef __VERIFYKEYDETAILBOX_H__
#define __VERIFYKEYDETAILBOX_H__
-#include "ui/import_export/KeyServerImportDialog.h"
+#include "ui/dialog/import_export/KeyServerImportDialog.h"
#include "ui/widgets/KeyList.h"
namespace GpgFrontend::UI {