aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main.cpp4
-rw-r--r--src/ui/KeyImportDetailDialog.cpp48
-rw-r--r--src/ui/KeyImportDetailDialog.h1
-rwxr-xr-xsrc/ui/KeyMgmt.cpp178
-rwxr-xr-xsrc/ui/KeyMgmt.h25
-rw-r--r--src/ui/KeyServerImportDialog.cpp291
-rw-r--r--src/ui/KeyServerImportDialog.h12
-rw-r--r--src/ui/MainWindow.cpp228
-rw-r--r--src/ui/MainWindow.h171
-rw-r--r--src/ui/UserInterfaceUtils.cpp46
-rw-r--r--src/ui/UserInterfaceUtils.h25
-rw-r--r--src/ui/WaitingDialog.cpp23
-rw-r--r--src/ui/Wizard.cpp4
-rw-r--r--src/ui/Wizard.h14
-rw-r--r--src/ui/keypair_details/KeyPairDetailTab.cpp18
-rw-r--r--src/ui/main_window/MainWindowSlotFunction.cpp2
-rw-r--r--src/ui/main_window/MainWindowSlotUI.cpp36
-rw-r--r--src/ui/main_window/MainWindowUI.cpp30
-rw-r--r--src/ui/settings/SettingsAppearance.cpp160
-rw-r--r--src/ui/settings/SettingsAppearance.h4
-rw-r--r--src/ui/settings/SettingsDialog.cpp97
-rwxr-xr-xsrc/ui/settings/SettingsDialog.h32
-rw-r--r--src/ui/settings/SettingsGeneral.cpp29
-rw-r--r--src/ui/settings/SettingsKeyServer.cpp62
-rw-r--r--src/ui/settings/SettingsKeyServer.h2
-rw-r--r--src/ui/widgets/InfoBoardWidget.cpp29
-rw-r--r--src/ui/widgets/InfoBoardWidget.h3
-rw-r--r--src/ui/widgets/VerifyKeyDetailBox.cpp2
28 files changed, 873 insertions, 703 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 7014ae05..e3506064 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -91,7 +91,9 @@ int main(int argc, char* argv[]) {
gpgme_set_locale(nullptr, LC_MESSAGES, setlocale(LC_MESSAGES, nullptr));
#endif
- GpgFrontend::UI::MainWindow window;
+ auto main_window = std::make_unique<GpgFrontend::UI::MainWindow>();
+ main_window->init();
+ main_window->show();
return_from_event_loop_code = QApplication::exec();
} while (return_from_event_loop_code == RESTART_CODE);
diff --git a/src/ui/KeyImportDetailDialog.cpp b/src/ui/KeyImportDetailDialog.cpp
index 321de3a6..48d1e9ee 100644
--- a/src/ui/KeyImportDetailDialog.cpp
+++ b/src/ui/KeyImportDetailDialog.cpp
@@ -33,34 +33,40 @@ KeyImportDetailDialog::KeyImportDetailDialog(GpgImportInformation result,
// If no key for import found, just show a message
if (mResult.considered == 0) {
if (automatic)
- QMessageBox::information(nullptr, _("Key Update Details"),
+ QMessageBox::information(parent, _("Key Update Details"),
_("No keys found"));
else
- QMessageBox::information(nullptr, _("Key Import Details"),
+ QMessageBox::information(parent, _("Key Import Details"),
_("No keys found to import"));
- return;
- }
-
- auto* mvbox = new QVBoxLayout();
-
- this->createGeneralInfoBox();
- mvbox->addWidget(generalInfoBox);
+ emit finished(0);
+ this->close();
+ this->deleteLater();
+ } else {
+ auto* mv_box = new QVBoxLayout();
- this->createKeysTable();
- mvbox->addWidget(keysTable);
+ this->createGeneralInfoBox();
+ mv_box->addWidget(generalInfoBox);
- this->createButtonBox();
- mvbox->addWidget(buttonBox);
+ this->createKeysTable();
+ mv_box->addWidget(keysTable);
- this->setLayout(mvbox);
- if (automatic)
- this->setWindowTitle(_("Key Update Details"));
- else
- this->setWindowTitle(_("Key Import Details"));
+ this->createButtonBox();
+ mv_box->addWidget(buttonBox);
- this->resize(QSize(600, 300));
- this->setModal(true);
- this->exec();
+ this->setLayout(mv_box);
+ if (automatic)
+ this->setWindowTitle(_("Key Update Details"));
+ else
+ this->setWindowTitle(_("Key Import Details"));
+
+ auto pos = QPoint(100, 100);
+ LOG(INFO) << "parent" << parent;
+ if (parent) pos += parent->pos();
+ this->move(pos);
+ this->resize(QSize(600, 300));
+ this->setModal(true);
+ this->show();
+ }
}
void KeyImportDetailDialog::createGeneralInfoBox() {
diff --git a/src/ui/KeyImportDetailDialog.h b/src/ui/KeyImportDetailDialog.h
index 0c7d6807..fe63baaa 100644
--- a/src/ui/KeyImportDetailDialog.h
+++ b/src/ui/KeyImportDetailDialog.h
@@ -45,7 +45,6 @@ class KeyImportDetailDialog : public QDialog {
static QString getStatusString(int keyStatus);
QTableWidget* keysTable{};
- GpgFrontend::GpgContext* mCtx;
QGroupBox* generalInfoBox{};
QGroupBox* keyInfoBox{};
QDialogButtonBox* buttonBox{};
diff --git a/src/ui/KeyMgmt.cpp b/src/ui/KeyMgmt.cpp
index 0c3d6a14..7459906d 100755
--- a/src/ui/KeyMgmt.cpp
+++ b/src/ui/KeyMgmt.cpp
@@ -30,13 +30,11 @@
#include "gpg/function/GpgKeyImportExportor.h"
#include "gpg/function/GpgKeyOpera.h"
#include "ui/SignalStation.h"
+#include "ui/UserInterfaceUtils.h"
+#include "ui/settings/GlobalSettingStation.h"
namespace GpgFrontend::UI {
-KeyMgmt::KeyMgmt(QWidget* parent)
- : QMainWindow(parent),
- appPath(qApp->applicationDirPath()),
- settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
- QSettings::IniFormat) {
+KeyMgmt::KeyMgmt(QWidget* parent) : QMainWindow(parent) {
/* the list of Keys available*/
mKeyList = new KeyList();
mKeyList->setColumnWidth(2, 250);
@@ -52,43 +50,57 @@ KeyMgmt::KeyMgmt(QWidget* parent)
connect(this, SIGNAL(signalStatusBarChanged(QString)), this->parent(),
SLOT(slotSetStatusBarText(QString)));
- /* Restore the iconstyle */
- this->settings.sync();
+ auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
- QSize iconSize = settings.value("toolbar/iconsize", QSize(24, 24)).toSize();
- settings.setValue("toolbar/iconsize", iconSize);
+ try {
+ int width = settings.lookup("window.icon_size.width");
+ int height = settings.lookup("window.icon_size.height");
- Qt::ToolButtonStyle buttonStyle = static_cast<Qt::ToolButtonStyle>(
- settings.value("toolbar/iconstyle", Qt::ToolButtonTextUnderIcon)
- .toUInt());
- this->setIconSize(iconSize);
- this->setToolButtonStyle(buttonStyle);
+ this->setIconSize(QSize(width, height));
- // state sets pos & size of dock-widgets
- this->restoreState(this->settings.value("keymgmt/windowState").toByteArray());
+ } catch (...) {
+ LOG(ERROR) << _("Setting Operation Error") << _("icon_size");
+ }
- qDebug() << "windows/windowSave"
- << this->settings.value("window/windowSave").toBool();
+ // 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");
+ }
- // Restore window size & location
- if (this->settings.value("keymgmt/setWindowSize").toBool()) {
- QPoint pos = settings.value("keymgmt/pos", QPoint(100, 100)).toPoint();
- QSize size = settings.value("keymgmt/size", QSize(900, 600)).toSize();
- qDebug() << "Settings size" << size << "pos" << pos;
- this->setMinimumSize(size);
- this->move(pos);
- } else {
- qDebug() << "Use default min windows size and pos";
- QPoint defaultPoint(100, 100);
- QSize defaultMinSize(900, 600);
- this->setMinimumSize(defaultMinSize);
- this->move(defaultPoint);
- this->settings.setValue("keymgmt/pos", defaultPoint);
- this->settings.setValue("keymgmt/size", defaultMinSize);
- this->settings.setValue("keymgmt/setWindowSize", true);
+ 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";
}
- setWindowTitle(_("Key Pair Management"));
+ this->resize(size);
+ this->move(pos);
+
+ setWindowTitle(_("KeyPair Management"));
mKeyList->addMenuAction(deleteSelectedKeysAct);
mKeyList->addMenuAction(showKeyDetailsAct);
@@ -100,8 +112,8 @@ void KeyMgmt::createActions() {
openKeyFileAct = new QAction(_("Open"), this);
openKeyFileAct->setShortcut(QKeySequence(_("Ctrl+O")));
openKeyFileAct->setToolTip(_("Open Key File"));
- connect(openKeyFileAct, SIGNAL(triggered()), this,
- SLOT(slotImportKeyFromFile()));
+ connect(importKeyFromFileAct, &QAction::triggered, this,
+ [&]() { CommonUtils::GetInstance()->slotImportKeyFromFile(this); });
closeAct = new QAction(_("Close"), this);
closeAct->setShortcut(QKeySequence(_("Ctrl+Q")));
@@ -126,20 +138,22 @@ void KeyMgmt::createActions() {
importKeyFromFileAct = new QAction(_("File"), this);
importKeyFromFileAct->setIcon(QIcon(":import_key_from_file.png"));
importKeyFromFileAct->setToolTip(_("Import New Key From File"));
- connect(importKeyFromFileAct, SIGNAL(triggered()), this,
- SLOT(slotImportKeyFromFile()));
+ connect(importKeyFromFileAct, &QAction::triggered, this,
+ [&]() { CommonUtils::GetInstance()->slotImportKeyFromFile(this); });
importKeyFromClipboardAct = new QAction(_("Clipboard"), this);
importKeyFromClipboardAct->setIcon(QIcon(":import_key_from_clipboard.png"));
importKeyFromClipboardAct->setToolTip(_("Import New Key From Clipboard"));
- connect(importKeyFromClipboardAct, SIGNAL(triggered()), this,
- SLOT(slotImportKeyFromClipboard()));
+ connect(importKeyFromClipboardAct, &QAction::triggered, this, [&]() {
+ CommonUtils::GetInstance()->slotImportKeyFromClipboard(this);
+ });
importKeyFromKeyServerAct = new QAction(_("Keyserver"), this);
importKeyFromKeyServerAct->setIcon(QIcon(":import_key_from_server.png"));
importKeyFromKeyServerAct->setToolTip(_("Import New Key From Keyserver"));
- connect(importKeyFromKeyServerAct, SIGNAL(triggered()), this,
- SLOT(slotImportKeyFromKeyServer()));
+ connect(importKeyFromKeyServerAct, &QAction::triggered, this, [&]() {
+ CommonUtils::GetInstance()->slotImportKeyFromKeyServer(this);
+ });
exportKeyToClipboardAct = new QAction(_("Export To Clipboard"), this);
exportKeyToClipboardAct->setIcon(QIcon(":export_key_to_clipboard.png"));
@@ -221,33 +235,6 @@ void KeyMgmt::createToolBars() {
keyToolBar->addAction(exportKeyToClipboardAct);
}
-void KeyMgmt::slotImportKeys(const std::string& in_buffer) {
- GpgImportInformation result = GpgKeyImportExportor::GetInstance().ImportKey(
- std::make_unique<ByteArray>(in_buffer));
- emit signalKeyStatusUpdated();
- new KeyImportDetailDialog(result, false, this);
-}
-
-void KeyMgmt::slotImportKeyFromFile() {
- QString file_name = QFileDialog::getOpenFileName(
- this, _("Open Key"), QString(),
- QString(_("Key Files")) + " (*.asc *.txt);;" + _("Keyring files") +
- " (*.gpg);;All Files (*)");
- if (!file_name.isNull()) {
- slotImportKeys(read_all_data_in_file(file_name.toStdString()));
- }
-}
-
-void KeyMgmt::slotImportKeyFromKeyServer() {
- importDialog = new KeyServerImportDialog(mKeyList, false, this);
- importDialog->show();
-}
-
-void KeyMgmt::slotImportKeyFromClipboard() {
- QClipboard* cb = QApplication::clipboard();
- slotImportKeys(cb->text(QClipboard::Clipboard).toUtf8().toStdString());
-}
-
void KeyMgmt::slotDeleteSelectedKeys() {
deleteKeysWithWarning(mKeyList->getSelected());
}
@@ -344,7 +331,10 @@ void KeyMgmt::slotGenerateKeyDialog() {
keyGenDialog->show();
}
-void KeyMgmt::closeEvent(QCloseEvent* event) { QMainWindow::closeEvent(event); }
+void KeyMgmt::closeEvent(QCloseEvent* event) {
+ slotSaveWindowState();
+ QMainWindow::closeEvent(event);
+}
void KeyMgmt::slotGenerateSubKey() {
auto keys_selected = mKeyList->getSelected();
@@ -369,5 +359,51 @@ void KeyMgmt::slotGenerateSubKey() {
auto dialog = new SubkeyGenerateDialog(key.id(), this);
dialog->show();
}
+void KeyMgmt::slotSaveWindowState() {
+ auto& settings =
+ GpgFrontend::UI::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().Sync();
+}
} // namespace GpgFrontend::UI
diff --git a/src/ui/KeyMgmt.h b/src/ui/KeyMgmt.h
index 1bf350f7..bf1c9b5a 100755
--- a/src/ui/KeyMgmt.h
+++ b/src/ui/KeyMgmt.h
@@ -40,25 +40,10 @@ class KeyMgmt : public QMainWindow {
public:
explicit KeyMgmt(QWidget* parent = nullptr);
- QAction* importKeyFromClipboardAct{};
- QAction* importKeyFromFileAct{};
- QAction* importKeyFromKeyServerAct{};
-
- QAction* generateKeyPairAct{};
- QAction* generateSubKeyAct{};
-
public slots:
void slotGenerateSubKey();
- void slotImportKeyFromFile();
-
- void slotImportKeyFromClipboard();
-
- void slotImportKeyFromKeyServer();
-
- void slotImportKeys(const std::string& in_buffer);
-
void slotExportKeyToFile();
void slotExportKeyToClipboard();
@@ -71,6 +56,8 @@ class KeyMgmt : public QMainWindow {
void slotShowKeyDetails();
+ void slotSaveWindowState();
+
signals:
void signalStatusBarChanged(QString);
@@ -86,9 +73,6 @@ class KeyMgmt : public QMainWindow {
void deleteKeysWithWarning(GpgFrontend::KeyIdArgsListPtr uidList);
- QString appPath;
- QSettings settings;
-
KeyList* mKeyList;
QMenu* fileMenu{};
QMenu* keyMenu{};
@@ -100,6 +84,11 @@ class KeyMgmt : public QMainWindow {
QAction* deleteCheckedKeysAct{};
QAction* deleteSelectedKeysAct{};
QAction* generateKeyDialogAct{};
+ QAction* generateKeyPairAct{};
+ QAction* generateSubKeyAct{};
+ QAction* importKeyFromClipboardAct{};
+ QAction* importKeyFromFileAct{};
+ QAction* importKeyFromKeyServerAct{};
QAction* closeAct{};
QAction* showKeyDetailsAct{};
KeyServerImportDialog* importDialog{};
diff --git a/src/ui/KeyServerImportDialog.cpp b/src/ui/KeyServerImportDialog.cpp
index 4f2c2d59..c7d9cd37 100644
--- a/src/ui/KeyServerImportDialog.cpp
+++ b/src/ui/KeyServerImportDialog.cpp
@@ -28,60 +28,50 @@
#include "gpg/function/GpgKeyImportExportor.h"
#include "ui/SignalStation.h"
+#include "ui/settings/GlobalSettingStation.h"
namespace GpgFrontend::UI {
-KeyServerImportDialog::KeyServerImportDialog(KeyList* keyList, bool automatic,
- QWidget* parent)
- : QDialog(parent),
- mAutomatic(automatic),
- appPath(qApp->applicationDirPath()),
- settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
- QSettings::IniFormat),
- mKeyList(keyList) {
+KeyServerImportDialog::KeyServerImportDialog(bool automatic, QWidget* parent)
+ : QDialog(parent), mAutomatic(automatic) {
+ // Layout for messagebox
+ auto* messageLayout = new QHBoxLayout;
+
if (automatic) {
setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
+ } else {
+ // Buttons
+ closeButton = createButton(_("Close"), SLOT(close()));
+ importButton = createButton(_("Import ALL"), SLOT(slotImport()));
+ importButton->setDisabled(true);
+ searchButton = createButton(_("Search"), SLOT(slotSearch()));
+
+ // Line edit for search string
+ searchLabel = new QLabel(QString(_("Search String")) + _(": "));
+ searchLineEdit = new QLineEdit();
+
+ // combobox for keyserverlist
+ keyServerLabel = new QLabel(QString(_("Key Server")) + _(": "));
+ keyServerComboBox = createComboBox();
+
+ // table containing the keys found
+ createKeysTable();
+ message = new QLabel;
+ message->setFixedHeight(24);
+ icon = new QLabel;
+ icon->setFixedHeight(24);
+
+ messageLayout->addWidget(icon);
+ messageLayout->addWidget(message);
+ messageLayout->addStretch();
}
- // Buttons
- closeButton = createButton(_("Close"), SLOT(close()));
- importButton = createButton(_("Import ALL"), SLOT(slotImport()));
- importButton->setDisabled(true);
- searchButton = createButton(_("Search"), SLOT(slotSearch()));
-
- // Line edit for search string
- searchLabel = new QLabel(QString(_("Search String")) + _(": "));
- searchLineEdit = new QLineEdit();
-
- // combobox for keyserverlist
- keyServerLabel = new QLabel(QString(_("Key Server")) + _(": "));
- keyServerComboBox = createComboBox();
-
- // table containing the keys found
- createKeysTable();
- message = new QLabel;
- message->setFixedHeight(24);
- icon = new QLabel;
- icon->setFixedHeight(24);
-
// Network Waiting
waitingBar = new QProgressBar();
waitingBar->setVisible(false);
waitingBar->setRange(0, 0);
waitingBar->setFixedWidth(200);
-
- // Layout for messagebox
- auto* messageLayout = new QHBoxLayout;
- messageLayout->addWidget(icon);
- messageLayout->addWidget(message);
messageLayout->addWidget(waitingBar);
- messageLayout->addStretch();
-
- // Layout for import and close button
- auto* buttonsLayout = new QHBoxLayout;
- buttonsLayout->addStretch();
- if (!automatic) buttonsLayout->addWidget(importButton);
- buttonsLayout->addWidget(closeButton);
auto* mainLayout = new QGridLayout;
@@ -96,6 +86,12 @@ KeyServerImportDialog::KeyServerImportDialog(KeyList* keyList, bool automatic,
mainLayout->addWidget(keyServerComboBox, 2, 1);
mainLayout->addWidget(keysTable, 3, 0, 1, 3);
mainLayout->addLayout(messageLayout, 4, 0, 1, 3);
+
+ // Layout for import and close button
+ auto* buttonsLayout = new QHBoxLayout;
+ buttonsLayout->addStretch();
+ buttonsLayout->addWidget(importButton);
+ buttonsLayout->addWidget(closeButton);
mainLayout->addLayout(buttonsLayout, 6, 0, 1, 3);
}
@@ -108,31 +104,38 @@ KeyServerImportDialog::KeyServerImportDialog(KeyList* keyList, bool automatic,
if (automatic) {
this->setFixedSize(240, 42);
} else {
- // Restore window size & location
- if (this->settings.value("ImportKeyFromServer/setWindowSize").toBool()) {
- QPoint pos =
- settings.value("ImportKeyFromServer/pos", QPoint(150, 150)).toPoint();
- QSize size =
- settings.value("ImportKeyFromServer/size", QSize(800, 500)).toSize();
- qDebug() << "Settings size" << size << "pos" << pos;
- this->setMinimumSize(size);
- this->move(pos);
- } else {
- qDebug() << "Use default min windows size and pos";
- QPoint defaultPoint(150, 150);
- QSize defaultMinSize(500, 300);
- this->setMinimumSize(defaultMinSize);
- this->move(defaultPoint);
- this->settings.setValue("ImportKeyFromServer/pos", defaultPoint);
- this->settings.setValue("ImportKeyFromServer/size", defaultMinSize);
- this->settings.setValue("ImportKeyFromServer/setWindowSize", true);
+ 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 {
+ auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+
+ int x, y, width, height;
+ x = settings.lookup("window.import_from_keyserver.position.x");
+ y = settings.lookup("window.import_from_keyserver.position.y");
+ width = settings.lookup("window.import_from_keyserver.size.width");
+ height = settings.lookup("window.import_from_keyserver.size.height");
+ pos = QPoint(x, y);
+ size = QSize(width, height);
+
+ } catch (...) {
+ LOG(WARNING) << "cannot read pos or size from settings";
}
+
+ this->resize(size);
+ this->move(pos);
}
this->setModal(true);
connect(this, SIGNAL(signalKeyImported()), SignalStation::GetInstance(),
SIGNAL(KeyDatabaseRefresh()));
+
+ // save window pos and size to configure file
+ connect(this, SIGNAL(finished(int)), this, SLOT(slotSaveWindowState()));
}
QPushButton* KeyServerImportDialog::createButton(const QString& text,
@@ -146,12 +149,26 @@ QComboBox* KeyServerImportDialog::createComboBox() {
auto* comboBox = new QComboBox;
comboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
- // Read keylist from ini-file and fill it into combobox
- comboBox->addItems(settings.value("keyserver/keyServerList").toStringList());
+ auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+
+ try {
+ auto& server_list = settings.lookup("keyserver.server_list");
+ const auto server_list_size = server_list.getLength();
+ for (int i = 0; i < server_list_size; i++) {
+ std::string server_url = server_list[i];
+ comboBox->addItem(server_url.c_str());
+ }
+ } catch (...) {
+ LOG(ERROR) << _("Setting Operation Error") << _("server_list");
+ }
// set default keyserver in combobox
- QString keyserver = settings.value("keyserver/defaultKeyServer").toString();
- comboBox->setCurrentIndex(comboBox->findText(keyserver));
+ try {
+ std::string default_server = settings.lookup("keyserver.default_server");
+ comboBox->setCurrentText(default_server.c_str());
+ } catch (...) {
+ LOG(ERROR) << _("Setting Operation Error") << _("default_server");
+ }
return comboBox;
}
@@ -367,8 +384,7 @@ void KeyServerImportDialog::slotSearchFinished() {
}
void KeyServerImportDialog::slotImport() {
- LOG(INFO) << "KeyServerImportDialog::slotImport currentRow"
- << keysTable->currentRow();
+ LOG(INFO) << _("Current Row") << keysTable->currentRow();
if (keysTable->currentRow() > -1) {
QString keyid = keysTable->item(keysTable->currentRow(), 2)->text();
slotImport(QStringList(keyid), keyServerComboBox->currentText());
@@ -376,58 +392,62 @@ void KeyServerImportDialog::slotImport() {
}
void KeyServerImportDialog::slotImport(const KeyIdArgsListPtr& keys) {
- QString keyserver = settings.value("keyserver/defaultKeyServer").toString();
- qDebug() << "Select Key Server" << keyserver;
- auto key_ids = QStringList();
- for (const auto& key_id : *keys) {
- key_ids.append(QString::fromStdString(key_id));
+ std::string target_keyserver;
+ if (keyServerComboBox != nullptr) {
+ target_keyserver = keyServerComboBox->currentText().toStdString();
+ }
+ if (target_keyserver.empty()) {
+ try {
+ auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+
+ target_keyserver = settings.lookup("keyserver.default_server").c_str();
+
+ LOG(INFO) << _("Set target Key Server to default Key Server")
+ << target_keyserver;
+ } catch (...) {
+ LOG(ERROR) << _("Cannot read default_keyserver From Settings");
+ QMessageBox::critical(
+ nullptr, _("Default Keyserver Not Found"),
+ _("Cannot read default keyserver from your settings, "
+ "please set a default keyserver first"));
+ return;
+ }
}
- slotImport(key_ids, QUrl(keyserver));
-}
-
-void KeyServerImportDialog::slotImportKey(const KeyIdArgsListPtr& keys) {
- QString keyserver = settings.value("keyserver/defaultKeyServer").toString();
- qDebug() << "Select Key Server" << keyserver;
auto key_ids = QStringList();
- for (const auto& key_id : *keys) {
+ for (const auto& key_id : *keys)
key_ids.append(QString::fromStdString(key_id));
- }
- slotImport(key_ids, QUrl(keyserver));
+ slotImport(key_ids, QUrl(target_keyserver.c_str()));
}
void KeyServerImportDialog::slotImport(const QStringList& keyIds,
const QUrl& keyServerUrl) {
for (const auto& keyId : keyIds) {
- QUrl reqUrl(keyServerUrl.scheme() + "://" + keyServerUrl.host() +
- "/pks/lookup?op=get&search=0x" + keyId + "&options=mr");
- qDebug() << "slotImport reqUrl" << reqUrl;
- auto pManager = new QNetworkAccessManager(this);
+ QUrl req_url(keyServerUrl.scheme() + "://" + keyServerUrl.host() +
+ "/pks/lookup?op=get&search=0x" + keyId + "&options=mr");
- QNetworkReply* reply = pManager->get(QNetworkRequest(reqUrl));
+ LOG(INFO) << "request url" << req_url.toString().toStdString();
+ auto manager = new QNetworkAccessManager(this);
+ QNetworkReply* reply = manager->get(QNetworkRequest(req_url));
connect(reply, SIGNAL(finished()), this, SLOT(slotImportFinished()));
-
+ LOG(INFO) << "loading start";
setLoading(true);
-
- while (reply->isRunning()) {
- QApplication::processEvents();
- }
-
+ while (reply->isRunning()) QApplication::processEvents();
setLoading(false);
+ LOG(INFO) << "loading done";
}
}
void KeyServerImportDialog::slotImportFinished() {
+ LOG(INFO) << _("Called");
+
auto* reply = qobject_cast<QNetworkReply*>(sender());
QByteArray key = reply->readAll();
- QVariant redirectionTarget =
- reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
-
auto error = reply->error();
if (error != QNetworkReply::NoError) {
- qDebug() << "Error From Reply" << reply->errorString();
+ LOG(ERROR) << "Error From Reply" << reply->errorString().toStdString();
switch (error) {
case QNetworkReply::ContentNotFoundError:
setMessage(_("Key Not Found"), true);
@@ -448,20 +468,11 @@ void KeyServerImportDialog::slotImportFinished() {
return;
}
- // Add keyserver to list in config-file, if it isn't contained
- QStringList keyServerList =
- settings.value("keyserver/keyServerList").toStringList();
- if (!keyServerList.contains(keyServerComboBox->currentText())) {
- keyServerList.append(keyServerComboBox->currentText());
- settings.setValue("keyserver/keyServerList", keyServerList);
- }
reply->deleteLater();
this->importKeys(std::make_unique<ByteArray>(key.constData(), key.length()));
- if (mAutomatic) {
- setMessage(QString("<h4>") + _("Key Updated") + "</h4>", false);
- } else {
+ if (!mAutomatic) {
setMessage(QString("<h4>") + _("Key Imported") + "</h4>", false);
}
}
@@ -471,31 +482,25 @@ void KeyServerImportDialog::importKeys(ByteArrayPtr in_data) {
GpgKeyImportExportor::GetInstance().ImportKey(std::move(in_data));
emit signalKeyImported();
if (mAutomatic) {
- new KeyImportDetailDialog(result, true, this);
+ auto dialog = new KeyImportDetailDialog(result, true, nullptr);
+ dialog->show();
this->accept();
} else {
- new KeyImportDetailDialog(result, false, this);
+ auto dialog = new KeyImportDetailDialog(result, false, this);
+ dialog->exec();
}
}
void KeyServerImportDialog::setLoading(bool status) {
- if (status) {
- waitingBar->setVisible(true);
- icon->setVisible(false);
- message->setVisible(false);
- } else {
- waitingBar->setVisible(false);
- icon->setVisible(true);
- message->setVisible(true);
+ waitingBar->setVisible(status);
+ if (!mAutomatic) {
+ icon->setVisible(!status);
+ message->setVisible(!status);
}
}
KeyServerImportDialog::KeyServerImportDialog(QWidget* parent)
- : QDialog(parent),
- mAutomatic(true),
- appPath(qApp->applicationDirPath()),
- settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
- QSettings::IniFormat) {
+ : QDialog(parent), mAutomatic(true) {
setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
message = new QLabel;
@@ -529,4 +534,52 @@ KeyServerImportDialog::KeyServerImportDialog(QWidget* parent)
this->setModal(true);
}
+void KeyServerImportDialog::slotSaveWindowState() {
+ LOG(INFO) << _("Called");
+
+ if (mAutomatic) return;
+
+ auto& settings =
+ GpgFrontend::UI::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("import_from_keyserver") ||
+ window.lookup("import_from_keyserver").getType() !=
+ libconfig::Setting::TypeGroup)
+ window.add("import_from_keyserver", libconfig::Setting::TypeGroup);
+
+ auto& import_from_keyserver = window["import_from_keyserver"];
+
+ if (!import_from_keyserver.exists("position") ||
+ import_from_keyserver.lookup("position").getType() !=
+ libconfig::Setting::TypeGroup) {
+ auto& position =
+ import_from_keyserver.add("position", libconfig::Setting::TypeGroup);
+ position.add("x", libconfig::Setting::TypeInt) = pos().x();
+ position.add("y", libconfig::Setting::TypeInt) = pos().y();
+ } else {
+ import_from_keyserver["position"]["x"] = pos().x();
+ import_from_keyserver["position"]["y"] = pos().y();
+ }
+
+ if (!import_from_keyserver.exists("size") ||
+ import_from_keyserver.lookup("size").getType() !=
+ libconfig::Setting::TypeGroup) {
+ auto& size =
+ import_from_keyserver.add("size", libconfig::Setting::TypeGroup);
+ size.add("width", libconfig::Setting::TypeInt) = QWidget::width();
+ size.add("height", libconfig::Setting::TypeInt) = QWidget::height();
+ } else {
+ import_from_keyserver["size"]["width"] = QWidget::width();
+ import_from_keyserver["size"]["height"] = QWidget::height();
+ }
+
+ GlobalSettingStation::GetInstance().Sync();
+}
+
} // namespace GpgFrontend::UI
diff --git a/src/ui/KeyServerImportDialog.h b/src/ui/KeyServerImportDialog.h
index 0fb7dbf1..d7f3364d 100644
--- a/src/ui/KeyServerImportDialog.h
+++ b/src/ui/KeyServerImportDialog.h
@@ -36,7 +36,7 @@ class KeyServerImportDialog : public QDialog {
Q_OBJECT
public:
- KeyServerImportDialog(KeyList* keyList, bool automatic, QWidget* parent);
+ KeyServerImportDialog(bool automatic, QWidget* parent);
KeyServerImportDialog(QWidget* parent);
@@ -44,8 +44,6 @@ class KeyServerImportDialog : public QDialog {
void slotImport(const QStringList& keyIds, const QUrl& keyserverUrl);
- void slotImportKey(const KeyIdArgsListPtr& keys);
-
signals:
void signalKeyImported();
@@ -59,6 +57,8 @@ class KeyServerImportDialog : public QDialog {
void slotSearch();
+ void slotSaveWindowState();
+
private:
void createKeysTable();
@@ -72,12 +72,8 @@ class KeyServerImportDialog : public QDialog {
QComboBox* createComboBox();
- bool mAutomatic;
-
- QString appPath;
- QSettings settings;
+ bool mAutomatic = false;
- KeyList* mKeyList{};
QLineEdit* searchLineEdit{};
QComboBox* keyServerComboBox{};
QProgressBar* waitingBar;
diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp
index cc04f246..b9251243 100644
--- a/src/ui/MainWindow.cpp
+++ b/src/ui/MainWindow.cpp
@@ -24,137 +24,137 @@
#include "MainWindow.h"
+#include "ui/UserInterfaceUtils.h"
+#ifdef RELEASE
#include "ui/help/VersionCheckThread.h"
+#endif
#include "ui/settings/GlobalSettingStation.h"
namespace GpgFrontend::UI {
MainWindow::MainWindow() {
- networkAccessManager = new QNetworkAccessManager(this);
-
- auto waitingDialog = new WaitingDialog(_("Loading Gnupg"), this);
-
- QString baseUrl =
- "https://api.github.com/repos/saturneric/gpgfrontend/releases/latest";
-
- QNetworkRequest request;
- request.setUrl(QUrl(baseUrl));
-
- QNetworkReply* replay = networkAccessManager->get(request);
-
-#ifdef RELEASE
- auto version_thread = new VersionCheckThread(replay);
-
- connect(version_thread, SIGNAL(finished()), version_thread,
- SLOT(deleteLater()));
- connect(version_thread,
- SIGNAL(upgradeVersion(const QString&, const QString&)), this,
- SLOT(slotVersionUpgrade(const QString&, const QString&)));
-
- version_thread->start();
-#endif
-
- // Check Context Status
- if (!GpgContext::GetInstance().good()) {
- QMessageBox::critical(
- nullptr, _("ENV Loading Failed"),
- _("Gnupg is not installed correctly, please follow the ReadME "
- "instructions to install gnupg and then open GpgFrontend."));
- QCoreApplication::quit();
- exit(0);
- }
+ this->setMinimumSize(1200, 700);
+ this->setWindowTitle(qApp->applicationName());
+}
- /* get path were app was started */
- setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
- setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
-
- edit = new TextEdit(this);
- setCentralWidget(edit);
-
- /* the list of Keys available*/
- mKeyList = new KeyList(KeyListRow::SECRET_OR_PUBLIC_KEY,
- KeyListColumn::TYPE | KeyListColumn::NAME |
- KeyListColumn::EmailAddress |
- KeyListColumn::Usage | KeyListColumn::Validity,
- this);
- mKeyList->setFilter([](const GpgKey& key) -> bool {
- if (key.revoked() || key.disabled() || key.expired())
- return false;
- else
- return true;
- });
- mKeyList->slotRefresh();
-
- infoBoard = new InfoBoardWidget(this, mKeyList);
-
- /* List of binary Attachments */
- attachmentDockCreated = false;
+void MainWindow::init() noexcept {
+ try {
+ // Check Context Status
+ if (!GpgContext::GetInstance().good()) {
+ QMessageBox::critical(
+ nullptr, _("ENV Loading Failed"),
+ _("Gnupg is not installed correctly, please follow the ReadME "
+ "instructions to install gnupg and then open GpgFrontend."));
+ QCoreApplication::quit();
+ exit(0);
+ }
- /* Variable containing if restart is needed */
- this->slotSetRestartNeeded(false);
-
- keyMgmt = new KeyMgmt(this);
- keyMgmt->hide();
- /* test attachmentdir for files alll 15s */
- auto* timer = new QTimer(this);
- // connect(timer, SIGNAL(timeout()), this,
- // SLOT(slotCheckAttachmentFolder()));
- timer->start(5000);
-
- createActions();
- createMenus();
- createToolBars();
- createStatusBar();
- createDockWindows();
-
- connect(edit->tabWidget, SIGNAL(currentChanged(int)), this,
- SLOT(slotDisableTabActions(int)));
-
- mKeyList->addMenuAction(appendSelectedKeysAct);
- mKeyList->addMenuAction(copyMailAddressToClipboardAct);
- mKeyList->addMenuAction(showKeyDetailsAct);
- mKeyList->addSeparator();
- mKeyList->addMenuAction(refreshKeysFromKeyserverAct);
- mKeyList->addMenuAction(uploadKeyToServerAct);
-
- restoreSettings();
-
- // open filename if provided as first command line parameter
- QStringList args = qApp->arguments();
- if (args.size() > 1) {
- if (!args[1].startsWith("-")) {
- if (QFile::exists(args[1])) edit->loadFile(args[1]);
+ networkAccessManager = new QNetworkAccessManager(this);
+
+ /* get path were app was started */
+ setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
+ setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
+
+ edit = new TextEdit(this);
+ setCentralWidget(edit);
+
+ /* the list of Keys available*/
+ mKeyList = new KeyList(KeyListRow::SECRET_OR_PUBLIC_KEY,
+ KeyListColumn::TYPE | KeyListColumn::NAME |
+ KeyListColumn::EmailAddress |
+ KeyListColumn::Usage | KeyListColumn::Validity,
+ this);
+ mKeyList->setFilter([](const GpgKey& key) -> bool {
+ if (key.revoked() || key.disabled() || key.expired())
+ return false;
+ else
+ return true;
+ });
+
+ mKeyList->slotRefresh();
+
+ infoBoard = new InfoBoardWidget(this, mKeyList);
+
+ /* List of binary Attachments */
+ attachmentDockCreated = false;
+
+ /* Variable containing if restart is needed */
+ this->slotSetRestartNeeded(false);
+
+ createActions();
+ createMenus();
+ createToolBars();
+ createStatusBar();
+ createDockWindows();
+
+ connect(edit->tabWidget, SIGNAL(currentChanged(int)), this,
+ SLOT(slotDisableTabActions(int)));
+
+ mKeyList->addMenuAction(appendSelectedKeysAct);
+ mKeyList->addMenuAction(copyMailAddressToClipboardAct);
+ mKeyList->addMenuAction(showKeyDetailsAct);
+ mKeyList->addSeparator();
+ mKeyList->addMenuAction(refreshKeysFromKeyserverAct);
+ mKeyList->addMenuAction(uploadKeyToServerAct);
+
+ restoreSettings();
+
+ // open filename if provided as first command line parameter
+ QStringList args = qApp->arguments();
+ if (args.size() > 1) {
+ if (!args[1].startsWith("-")) {
+ if (QFile::exists(args[1])) edit->loadFile(args[1]);
+ }
}
- }
- edit->curTextPage()->setFocus();
+ edit->curTextPage()->setFocus();
- waitingDialog->close();
+ auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
- this->setMinimumSize(1200, 700);
- this->setWindowTitle(qApp->applicationName());
- this->show();
+ if (!settings.exists("wizard") ||
+ settings.lookup("wizard").getType() != libconfig::Setting::TypeGroup)
+ settings.add("wizard", libconfig::Setting::TypeGroup);
- auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+ auto& wizard = settings["wizard"];
- if (!settings.exists("wizard") ||
- settings.lookup("wizard").getType() != libconfig::Setting::TypeGroup)
- settings.add("wizard", libconfig::Setting::TypeGroup);
+ // Show wizard, if the don't show wizard message box wasn't checked
+ // and keylist doesn't contain a private key
- auto& wizard = settings["wizard"];
+ if (!wizard.exists("show_wizard"))
+ wizard.add("show_wizard", libconfig::Setting::TypeBoolean) = true;
- // Show wizard, if the don't show wizard message box wasn't checked
- // and keylist doesn't contain a private key
+ bool show_wizard = true;
+ wizard.lookupValue("show_wizard", show_wizard);
- if (!wizard.exists("show_wizard"))
- wizard.add("show_wizard", libconfig::Setting::TypeBoolean) = true;
+ LOG(INFO) << "wizard show_wizard" << show_wizard;
- bool show_wizard = true;
- wizard.lookupValue("show_wizard", show_wizard);
+ if (show_wizard) {
+ slotStartWizard();
+ }
- LOG(INFO) << "wizard show_wizard" << show_wizard;
+ emit loaded();
- if (show_wizard) {
- slotStartWizard();
+#ifdef RELEASE
+ QString baseUrl =
+ "https://api.github.com/repos/saturneric/gpgfrontend/releases/latest";
+ QNetworkRequest request;
+ request.setUrl(QUrl(baseUrl));
+ auto* replay = networkAccessManager->get(request);
+ auto version_thread = new VersionCheckThread(replay);
+
+ connect(version_thread, SIGNAL(finished()), version_thread,
+ SLOT(deleteLater()));
+ connect(version_thread,
+ SIGNAL(upgradeVersion(const QString&, const QString&)), this,
+ SLOT(slotVersionUpgrade(const QString&, const QString&)));
+
+ version_thread->start();
+#endif
+ } catch (...) {
+ LOG(FATAL) << _("Critical error occur while loading GpgFrontend.");
+ QMessageBox::critical(nullptr, _("Loading Failed"),
+ _("Critical error occur while loading GpgFrontend."));
+ QCoreApplication::quit();
+ exit(0);
}
}
@@ -239,6 +239,10 @@ void MainWindow::restoreSettings() {
int width = icon_size["width"], height = icon_size["height"];
LOG(INFO) << "icon_size" << width << height;
+ // info board font size
+ if (!window.exists("info_font_size"))
+ window.add("info_font_size", libconfig::Setting::TypeInt) = 10;
+
// icons ize
this->setIconSize(QSize(width, height));
importButton->setIconSize(QSize(width, height));
diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h
index 82acee63..e0bf9f5a 100644
--- a/src/ui/MainWindow.h
+++ b/src/ui/MainWindow.h
@@ -56,6 +56,14 @@ class MainWindow : public QMainWindow {
*/
MainWindow();
+ /**
+ * ONLY Called from main()
+ */
+ void init() noexcept;
+
+ signals:
+ void loaded();
+
public slots:
void slotSetStatusBarText(const QString& text);
@@ -336,89 +344,92 @@ class MainWindow : public QMainWindow {
*/
[[nodiscard]] bool getRestartNeeded() const;
- TextEdit* edit; /** Tabwidget holding the edit-windows */
- QMenu* fileMenu; /** Submenu for file-operations*/
- QMenu* editMenu; /** Submenu for text-operations*/
- QMenu* cryptMenu; /** Submenu for crypt-operations */
- QMenu* fileEncMenu; /** Submenu for file crypt operations */
- QMenu* helpMenu; /** Submenu for help-operations */
- QMenu* keyMenu; /** Submenu for key-operations */
- QMenu* viewMenu; /** Submenu for view operations */
- QMenu* importKeyMenu; /** Sumenu for import operations */
- QMenu* steganoMenu; /** Submenu for steganographic operations*/
- QToolBar* cryptToolBar; /** Toolbar holding crypt actions */
- QToolBar* fileToolBar; /** Toolbar holding file actions */
- QToolBar* editToolBar; /** Toolbar holding edit actions */
- QToolBar* specialEditToolBar; /** Toolbar holding special edit actions */
- QToolBar* keyToolBar; /** Toolbar holding key operations */
+ TextEdit* edit{}; /** Tabwidget holding the edit-windows */
+ QMenu* fileMenu{}; /** Submenu for file-operations*/
+ QMenu* editMenu{}; /** Submenu for text-operations*/
+ QMenu* cryptMenu{}; /** Submenu for crypt-operations */
+ QMenu* fileEncMenu{}; /** Submenu for file crypt operations */
+ QMenu* helpMenu{}; /** Submenu for help-operations */
+ QMenu* keyMenu{}; /** Submenu for key-operations */
+ QMenu* viewMenu{}; /** Submenu for view operations */
+ QMenu* importKeyMenu{}; /** Sumenu for import operations */
+ QMenu* steganoMenu{}; /** Submenu for steganographic operations*/
+ QToolBar* cryptToolBar{}; /** Toolbar holding crypt actions */
+ QToolBar* fileToolBar{}; /** Toolbar holding file actions */
+ QToolBar* editToolBar{}; /** Toolbar holding edit actions */
+ QToolBar* specialEditToolBar{}; /** Toolbar holding special edit actions */
+ QToolBar* keyToolBar{}; /** Toolbar holding key operations */
QToolButton*
- importButton; /** Toolbutton for import dropdown menu in toolbar */
- QToolButton* fileEncButton; /** Toolbutton for file cryption dropdown menu in
- toolbar */
- QDockWidget* keyListDock; /** Encrypt Dock*/
- QDockWidget* attachmentDock; /** Attachment Dock */
- QDockWidget* infoBoardDock;
-
- QAction* newTabAct; /** Action to create new tab */
- QAction* switchTabUpAct; /** Action to switch tab up*/
- QAction* switchTabDownAct; /** Action to switch tab down */
- QAction* openAct; /** Action to open file */
- QAction* browserAct; /** Action to open file browser*/
- QAction* saveAct; /** Action to save file */
- QAction* saveAsAct; /** Action to save file as */
- QAction* printAct; /** Action to print */
- QAction* closeTabAct; /** Action to print */
- QAction* quitAct; /** Action to quit application */
- QAction* encryptAct; /** Action to encrypt text */
- QAction* encryptSignAct; /** Action to encrypt and sign text */
- QAction* decryptVerifyAct; /** Action to encrypt and sign text */
- QAction* decryptAct; /** Action to decrypt text */
- QAction* signAct; /** Action to sign text */
- QAction* verifyAct; /** Action to verify text */
- QAction* importKeyFromEditAct; /** Action to import key from edit */
- QAction* cleanDoubleLinebreaksAct; /** Action to remove double line breaks */
-
- QAction* appendSelectedKeysAct; /** Action to append selected keys to edit */
- QAction*
- copyMailAddressToClipboardAct; /** Action to copy mail to clipboard */
- QAction* openKeyManagementAct; /** Action to open key management */
- QAction* copyAct; /** Action to copy text */
- QAction* quoteAct; /** Action to quote text */
- QAction* cutAct; /** Action to cut text */
- QAction* pasteAct; /** Action to paste text */
- QAction* selectAllAct; /** Action to select whole text */
- QAction* findAct; /** Action to find text */
- QAction* undoAct; /** Action to undo last action */
- QAction* redoAct; /** Action to redo last action */
- QAction* zoomInAct; /** Action to zoom in */
- QAction* zoomOutAct; /** Action to zoom out */
- QAction* aboutAct; /** Action to open about dialog */
- QAction* checkUpdateAct; /** Action to open about dialog */
- QAction* fileEncryptAct; /** Action to open dialog for encrypting file */
- QAction* fileDecryptAct; /** Action to open dialog for decrypting file */
- QAction* fileSignAct; /** Action to open dialog for signing file */
- QAction* fileVerifyAct; /** Action to open dialog for verifying file */
- QAction* openSettingsAct; /** Action to open settings dialog */
- QAction* showKeyDetailsAct; /** Action to open key-details dialog */
+ importButton{}; /** Toolbutton for import dropdown menu in toolbar */
+ QToolButton* fileEncButton{}; /** Toolbutton for file cryption dropdown menu
+ in toolbar */
+ QDockWidget* keyListDock{}; /** Encrypt Dock*/
+ QDockWidget* attachmentDock{}; /** Attachment Dock */
+ QDockWidget* infoBoardDock{};
+
+ QAction* newTabAct{}; /** Action to create new tab */
+ QAction* switchTabUpAct{}; /** Action to switch tab up*/
+ QAction* switchTabDownAct{}; /** Action to switch tab down */
+ QAction* openAct{}; /** Action to open file */
+ QAction* browserAct{}; /** Action to open file browser*/
+ QAction* saveAct{}; /** Action to save file */
+ QAction* saveAsAct{}; /** Action to save file as */
+ QAction* printAct{}; /** Action to print */
+ QAction* closeTabAct{}; /** Action to print */
+ QAction* quitAct{}; /** Action to quit application */
+ QAction* encryptAct{}; /** Action to encrypt text */
+ QAction* encryptSignAct{}; /** Action to encrypt and sign text */
+ QAction* decryptVerifyAct{}; /** Action to encrypt and sign text */
+ QAction* decryptAct{}; /** Action to decrypt text */
+ QAction* signAct{}; /** Action to sign text */
+ QAction* verifyAct{}; /** Action to verify text */
+ QAction* importKeyFromEditAct{}; /** Action to import key from edit */
QAction*
- refreshKeysFromKeyserverAct; /** Action to refresh a key from keyserver */
- QAction* uploadKeyToServerAct; /** Action to append selected keys to edit */
- QAction* startWizardAct; /** Action to open the wizard */
- QAction* cutPgpHeaderAct; /** Action for cutting the PGP header */
- QAction* addPgpHeaderAct; /** Action for adding the PGP header */
-
- QLabel* statusBarIcon; /**< TODO */
+ cleanDoubleLinebreaksAct{}; /** Action to remove double line breaks */
- KeyList* mKeyList;
-
- InfoBoardWidget* infoBoard;
- KeyMgmt* keyMgmt;
- KeyServerImportDialog* importDialog; /**< TODO */
-
- QNetworkAccessManager* networkAccessManager;
-
- bool attachmentDockCreated;
- bool restartNeeded;
+ QAction*
+ appendSelectedKeysAct{}; /** Action to append selected keys to edit */
+ QAction*
+ copyMailAddressToClipboardAct{}; /** Action to copy mail to clipboard */
+ QAction* openKeyManagementAct{}; /** Action to open key management */
+ QAction* copyAct{}; /** Action to copy text */
+ QAction* quoteAct{}; /** Action to quote text */
+ QAction* cutAct{}; /** Action to cut text */
+ QAction* pasteAct{}; /** Action to paste text */
+ QAction* selectAllAct{}; /** Action to select whole text */
+ QAction* findAct{}; /** Action to find text */
+ QAction* undoAct{}; /** Action to undo last action */
+ QAction* redoAct{}; /** Action to redo last action */
+ QAction* zoomInAct{}; /** Action to zoom in */
+ QAction* zoomOutAct{}; /** Action to zoom out */
+ QAction* aboutAct{}; /** Action to open about dialog */
+ QAction* checkUpdateAct{}; /** Action to open about dialog */
+ QAction* fileEncryptAct{}; /** Action to open dialog for encrypting file */
+ QAction* fileDecryptAct{}; /** Action to open dialog for decrypting file */
+ QAction* fileSignAct{}; /** Action to open dialog for signing file */
+ QAction* fileVerifyAct{}; /** Action to open dialog for verifying file */
+ QAction* openSettingsAct{}; /** Action to open settings dialog */
+ QAction* showKeyDetailsAct{}; /** Action to open key-details dialog */
+ QAction* refreshKeysFromKeyserverAct{}; /** Action to refresh a key from
+ keyserver */
+ QAction* uploadKeyToServerAct{}; /** Action to append selected keys to edit */
+ QAction* startWizardAct{}; /** Action to open the wizard */
+ QAction* cutPgpHeaderAct{}; /** Action for cutting the PGP header */
+ QAction* addPgpHeaderAct{}; /** Action for adding the PGP header */
+
+ QAction* importKeyFromFileAct{};
+ QAction* importKeyFromClipboardAct{};
+ QAction* importKeyFromKeyServerAct{};
+
+ QLabel* statusBarIcon{}; /**< TODO */
+
+ KeyList* mKeyList{};
+ InfoBoardWidget* infoBoard{};
+
+ QNetworkAccessManager* networkAccessManager{};
+
+ bool attachmentDockCreated{};
+ bool restartNeeded{};
};
} // namespace GpgFrontend::UI
diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp
index f8658a78..395d292e 100644
--- a/src/ui/UserInterfaceUtils.cpp
+++ b/src/ui/UserInterfaceUtils.cpp
@@ -25,11 +25,16 @@
#include "UserInterfaceUtils.h"
#include "gpg/result_analyse/ResultAnalyse.h"
+#include "ui/SignalStation.h"
#include "ui/WaitingDialog.h"
#include "ui/widgets/InfoBoardWidget.h"
#include "ui/widgets/TextEdit.h"
namespace GpgFrontend::UI {
+
+std::unique_ptr<GpgFrontend::UI::CommonUtils>
+ GpgFrontend::UI::CommonUtils::_instance = nullptr;
+
void refresh_info_board(InfoBoardWidget* info_board, int status,
const std::string& report_text) {
if (status < 0)
@@ -79,4 +84,45 @@ void process_operation(QWidget* parent, const std::string& waiting_title,
dialog->close();
}
+CommonUtils* CommonUtils::GetInstance() {
+ if (_instance == nullptr) {
+ _instance = std::make_unique<CommonUtils>();
+ }
+ return _instance.get();
+}
+
+CommonUtils::CommonUtils() : QWidget(nullptr) {
+ connect(this, SIGNAL(signalKeyStatusUpdated()), SignalStation::GetInstance(),
+ SIGNAL(KeyDatabaseRefresh()));
+}
+
+void CommonUtils::slotImportKeys(QWidget* parent,
+ const std::string& in_buffer) {
+ GpgImportInformation result = GpgKeyImportExportor::GetInstance().ImportKey(
+ std::make_unique<ByteArray>(in_buffer));
+ emit signalKeyStatusUpdated();
+ new KeyImportDetailDialog(result, false, parent);
+}
+
+void CommonUtils::slotImportKeyFromFile(QWidget* parent) {
+ QString file_name = QFileDialog::getOpenFileName(
+ this, _("Open Key"), QString(),
+ QString(_("Key Files")) + " (*.asc *.txt);;" + _("Keyring files") +
+ " (*.gpg);;All Files (*)");
+ if (!file_name.isNull()) {
+ slotImportKeys(parent, read_all_data_in_file(file_name.toStdString()));
+ }
+}
+
+void CommonUtils::slotImportKeyFromKeyServer(QWidget* parent) {
+ auto dialog = new KeyServerImportDialog(false, parent);
+ dialog->show();
+}
+
+void CommonUtils::slotImportKeyFromClipboard(QWidget* parent) {
+ QClipboard* cb = QApplication::clipboard();
+ slotImportKeys(parent,
+ cb->text(QClipboard::Clipboard).toUtf8().toStdString());
+}
+
} // namespace GpgFrontend::UI \ No newline at end of file
diff --git a/src/ui/UserInterfaceUtils.h b/src/ui/UserInterfaceUtils.h
index ec439461..b5014f29 100644
--- a/src/ui/UserInterfaceUtils.h
+++ b/src/ui/UserInterfaceUtils.h
@@ -49,6 +49,31 @@ void process_result_analyse(TextEdit* edit, InfoBoardWidget* info_board,
void process_operation(QWidget* parent, const std::string& waiting_title,
const std::function<void()>& func);
+class CommonUtils : public QWidget {
+ Q_OBJECT
+ public:
+ static CommonUtils* GetInstance();
+
+ CommonUtils();
+
+ signals:
+ void signalKeyStatusUpdated();
+
+ public slots:
+
+ void slotImportKeys(QWidget* parent, const std::string& in_buffer);
+
+ void slotImportKeyFromFile(QWidget* parent);
+
+ void slotImportKeyFromKeyServer(QWidget* parent);
+
+ void slotImportKeyFromClipboard(QWidget* parent);
+
+ private:
+ static std::unique_ptr<CommonUtils> _instance;
+
+};
+
} // namespace GpgFrontend::UI
#endif // GPGFRONTEND_USER_INTERFACE_UTILS_H
diff --git a/src/ui/WaitingDialog.cpp b/src/ui/WaitingDialog.cpp
index d9aab23b..a83845ab 100644
--- a/src/ui/WaitingDialog.cpp
+++ b/src/ui/WaitingDialog.cpp
@@ -40,10 +40,33 @@ WaitingDialog::WaitingDialog(const QString& title, QWidget* parent)
this->setLayout(layout);
this->setModal(true);
+ this->raise();
this->setWindowFlags(Qt::Window | Qt::WindowTitleHint |
Qt::CustomizeWindowHint);
this->setWindowTitle(title);
+ this->setAttribute(Qt::WA_DeleteOnClose);
this->setFixedSize(240, 42);
+
+ if (parentWidget() == nullptr) {
+ auto* screen = QGuiApplication::primaryScreen();
+ QRect geo = screen->availableGeometry();
+ int screen_width = geo.width();
+ int screen_height = geo.height();
+
+ LOG(INFO) << "primary screen available geometry" << screen_width
+ << screen_height;
+
+ auto pos = QPoint((screen_width - QWidget::width()) / 2,
+ (screen_height - QWidget::height()) / 2);
+ this->move(pos);
+
+ } else {
+ auto pos = QPoint(parent->x() + (parent->width() - QWidget::width()) / 2,
+ parent->y() + (parent->height() - QWidget::height()) / 2);
+ LOG(INFO) << "pos" << pos.x() << pos.y();
+ this->move(pos);
+ }
+
this->show();
}
diff --git a/src/ui/Wizard.cpp b/src/ui/Wizard.cpp
index 996efa7e..67af385b 100644
--- a/src/ui/Wizard.cpp
+++ b/src/ui/Wizard.cpp
@@ -28,9 +28,7 @@
namespace GpgFrontend::UI {
-Wizard::Wizard(KeyMgmt* keyMgmt, QWidget* parent) : QWizard(parent) {
- mKeyMgmt = keyMgmt;
-
+Wizard::Wizard(QWidget* parent) : QWizard(parent) {
setPage(Page_Intro, new IntroPage(this));
setPage(Page_Choose, new ChoosePage(this));
setPage(Page_GenKey, new KeyGenPage(this));
diff --git a/src/ui/Wizard.h b/src/ui/Wizard.h
index 62fc1a41..5a66fb6e 100644
--- a/src/ui/Wizard.h
+++ b/src/ui/Wizard.h
@@ -38,19 +38,9 @@ class Wizard : public QWizard {
Q_ENUMS(WizardPages)
public:
- enum WizardPages {
- Page_Intro,
- Page_Choose,
- Page_ImportFromGpg4usb,
- Page_ImportFromGnupg,
- Page_GenKey,
- Page_Conclusion
- };
+ enum WizardPages { Page_Intro, Page_Choose, Page_GenKey, Page_Conclusion };
- Wizard(KeyMgmt* keyMgmt, QWidget* parent = nullptr);
-
- private:
- KeyMgmt* mKeyMgmt;
+ Wizard(QWidget* parent = nullptr);
private slots:
diff --git a/src/ui/keypair_details/KeyPairDetailTab.cpp b/src/ui/keypair_details/KeyPairDetailTab.cpp
index a7d082d1..53c2ee01 100644
--- a/src/ui/keypair_details/KeyPairDetailTab.cpp
+++ b/src/ui/keypair_details/KeyPairDetailTab.cpp
@@ -284,20 +284,20 @@ void KeyPairDetailTab::slotRefreshKeyInfo() {
QString usage;
QTextStream usage_steam(&usage);
- if (mKey.can_certify()) usage_steam << "Cert ";
- if (mKey.can_encrypt()) usage_steam << "Encr ";
- if (mKey.can_sign()) usage_steam << "Sign ";
- if (mKey.can_authenticate()) usage_steam << "Auth ";
+ if (mKey.can_certify()) usage_steam << _("Cert") << " ";
+ if (mKey.can_encrypt()) usage_steam << _("Encr") << " ";
+ if (mKey.can_sign()) usage_steam << _("Sign") << " ";
+ if (mKey.can_authenticate()) usage_steam << _("Auth") << " ";
usageVarLabel->setText(usage);
QString actualUsage;
QTextStream actual_usage_steam(&actualUsage);
- if (mKey.CanCertActual()) actual_usage_steam << "Cert ";
- if (mKey.CanEncrActual()) actual_usage_steam << "Encr ";
- if (mKey.CanSignActual()) actual_usage_steam << "Sign ";
- if (mKey.CanAuthActual()) actual_usage_steam << "Auth ";
+ if (mKey.CanCertActual()) actual_usage_steam << _("Cert") << " ";
+ if (mKey.CanEncrActual()) actual_usage_steam << _("Encr") << " ";
+ if (mKey.CanSignActual()) actual_usage_steam << _("Sign") << " ";
+ if (mKey.CanAuthActual()) actual_usage_steam << _("Auth") << " ";
actualUsageVarLabel->setText(actualUsage);
@@ -352,7 +352,7 @@ void KeyPairDetailTab::slotUpdateKeyToServer() {
keys->push_back(mKey.id());
auto* dialog = new KeyServerImportDialog(this);
dialog->show();
- dialog->slotImportKey(keys);
+ dialog->slotImport(keys);
}
void KeyPairDetailTab::slotGenRevokeCert() {
diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp
index 0f7bdb26..edfa1388 100644
--- a/src/ui/main_window/MainWindowSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowSlotFunction.cpp
@@ -518,7 +518,7 @@ void MainWindow::refreshKeysFromKeyserver() {
auto key_ids = mKeyList->getSelected();
if (key_ids->empty()) return;
- auto* dialog = new KeyServerImportDialog(mKeyList, true, this);
+ auto* dialog = new KeyServerImportDialog(true, this);
dialog->show();
dialog->slotImport(key_ids);
}
diff --git a/src/ui/main_window/MainWindowSlotUI.cpp b/src/ui/main_window/MainWindowSlotUI.cpp
index 312364e2..35eb74ac 100644
--- a/src/ui/main_window/MainWindowSlotUI.cpp
+++ b/src/ui/main_window/MainWindowSlotUI.cpp
@@ -23,6 +23,7 @@
*/
#include "MainWindow.h"
+#include "ui/UserInterfaceUtils.h"
#include "ui/settings/GlobalSettingStation.h"
namespace GpgFrontend::UI {
@@ -36,44 +37,21 @@ void MainWindow::slotSetStatusBarText(const QString& text) {
}
void MainWindow::slotStartWizard() {
- auto* wizard = new Wizard(keyMgmt, this);
+ auto* wizard = new Wizard(this);
wizard->show();
wizard->setModal(true);
}
-// void MainWindow::slotCheckAttachmentFolder() {
-// // TODO: always check?
-// if (!settings.value("mime/parseMime").toBool()) {
-// return;
-// }
-//
-// QString attachmentDir = qApp->applicationDirPath() + "/attachments/";
-// // filenum minus . and ..
-// uint filenum = QDir(attachmentDir).count() - 2;
-// if (filenum > 0) {
-// QString statusText;
-// if (filenum == 1) {
-// statusText = _("There is one unencrypted file in attachment folder");
-// } else {
-// statusText = _("There are ") + QString::number(filenum) +
-// _(" unencrypted files in attachment folder");
-// }
-// statusBarIcon->setStatusTip(statusText);
-// statusBarIcon->show();
-// } else {
-// statusBarIcon->hide();
-// }
-// }
-
void MainWindow::slotImportKeyFromEdit() {
if (edit->tabCount() == 0 || edit->slotCurPageTextEdit() == nullptr) return;
- keyMgmt->slotImportKeys(edit->curTextPage()->toPlainText().toStdString());
+ CommonUtils::GetInstance()->slotImportKeys(
+ this, edit->curTextPage()->toPlainText().toStdString());
}
void MainWindow::slotOpenKeyManagement() {
- keyMgmt->show();
- keyMgmt->raise();
- keyMgmt->activateWindow();
+ auto* dialog = new KeyMgmt(this);
+ dialog->show();
+ dialog->raise();
}
void MainWindow::slotOpenFileTab() { edit->slotNewFileTab(); }
diff --git a/src/ui/main_window/MainWindowUI.cpp b/src/ui/main_window/MainWindowUI.cpp
index 08a9e215..ee7a1bc0 100644
--- a/src/ui/main_window/MainWindowUI.cpp
+++ b/src/ui/main_window/MainWindowUI.cpp
@@ -23,6 +23,7 @@
*/
#include "MainWindow.h"
+#include "ui/UserInterfaceUtils.h"
namespace GpgFrontend::UI {
@@ -214,6 +215,26 @@ void MainWindow::createActions() {
/* Key Menu
*/
+ importKeyFromFileAct = new QAction(_("File"), this);
+ importKeyFromFileAct->setIcon(QIcon(":import_key_from_file.png"));
+ importKeyFromFileAct->setToolTip(_("Import New Key From File"));
+ connect(importKeyFromFileAct, &QAction::triggered, this,
+ [&]() { CommonUtils::GetInstance()->slotImportKeyFromFile(this); });
+
+ importKeyFromClipboardAct = new QAction(_("Clipboard"), this);
+ importKeyFromClipboardAct->setIcon(QIcon(":import_key_from_clipboard.png"));
+ importKeyFromClipboardAct->setToolTip(_("Import New Key From Clipboard"));
+ connect(importKeyFromClipboardAct, &QAction::triggered, this, [&]() {
+ CommonUtils::GetInstance()->slotImportKeyFromClipboard(this);
+ });
+
+ importKeyFromKeyServerAct = new QAction(_("Keyserver"), this);
+ importKeyFromKeyServerAct->setIcon(QIcon(":import_key_from_server.png"));
+ importKeyFromKeyServerAct->setToolTip(_("Import New Key From Keyserver"));
+ connect(importKeyFromKeyServerAct, &QAction::triggered, this, [&]() {
+ CommonUtils::GetInstance()->slotImportKeyFromKeyServer(this);
+ });
+
importKeyFromEditAct = new QAction(_("Editor"), this);
importKeyFromEditAct->setIcon(QIcon(":txt.png"));
importKeyFromEditAct->setToolTip(_("Import New Key From Editor"));
@@ -353,11 +374,10 @@ void MainWindow::createMenus() {
keyMenu = menuBar()->addMenu(_("Keys"));
importKeyMenu = keyMenu->addMenu(_("Import Key"));
importKeyMenu->setIcon(QIcon(":key_import.png"));
- importKeyMenu->addAction(keyMgmt->importKeyFromFileAct);
+ importKeyMenu->addAction(importKeyFromFileAct);
importKeyMenu->addAction(importKeyFromEditAct);
- importKeyMenu->addAction(keyMgmt->importKeyFromClipboardAct);
- importKeyMenu->addAction(keyMgmt->importKeyFromKeyServerAct);
- importKeyMenu->addAction(keyMgmt->importKeyFromKeyServerAct);
+ importKeyMenu->addAction(importKeyFromClipboardAct);
+ importKeyMenu->addAction(importKeyFromKeyServerAct);
keyMenu->addAction(openKeyManagementAct);
steganoMenu = menuBar()->addMenu(_("Steganography"));
@@ -455,7 +475,7 @@ void MainWindow::createStatusBar() {
}
void MainWindow::createDockWindows() {
- /* KeyList-Dockwindow
+ /* KeyList-Dock window
*/
keyListDock = new QDockWidget(_("Key ToolBox"), this);
keyListDock->setObjectName("EncryptDock");
diff --git a/src/ui/settings/SettingsAppearance.cpp b/src/ui/settings/SettingsAppearance.cpp
index 91bef9ef..49dc349c 100644
--- a/src/ui/settings/SettingsAppearance.cpp
+++ b/src/ui/settings/SettingsAppearance.cpp
@@ -24,13 +24,11 @@
#include "SettingsAppearance.h"
+#include "GlobalSettingStation.h"
+
namespace GpgFrontend::UI {
-AppearanceTab::AppearanceTab(QWidget* parent)
- : QWidget(parent),
- appPath(qApp->applicationDirPath()),
- settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
- QSettings::IniFormat) {
+AppearanceTab::AppearanceTab(QWidget* parent) : QWidget(parent) {
/*****************************************
* Icon-Size-Box
*****************************************/
@@ -91,7 +89,7 @@ AppearanceTab::AppearanceTab(QWidget* parent)
infoBoardFontSizeSpin->setRange(9, 18);
infoBoardFontSizeSpin->setValue(10);
infoBoardFontSizeSpin->setSingleStep(1);
- infoBoardLayout->addWidget(new QLabel(_("Front Size")));
+ infoBoardLayout->addWidget(new QLabel(_("Font Size in Information Board")));
infoBoardLayout->addWidget(infoBoardFontSizeSpin);
infoBoardBox->setLayout(infoBoardLayout);
@@ -111,46 +109,70 @@ AppearanceTab::AppearanceTab(QWidget* parent)
* appropriately
**********************************/
void AppearanceTab::setSettings() {
- // Iconsize
- QSize iconSize = settings.value("toolbar/iconsize", QSize(24, 24)).toSize();
- switch (iconSize.height()) {
- case 12:
- iconSizeSmall->setChecked(true);
- break;
- case 24:
- iconSizeMedium->setChecked(true);
- break;
- case 32:
- iconSizeLarge->setChecked(true);
- break;
+ auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+
+ try {
+ int width = settings.lookup("window.icon_size.width");
+ int height = settings.lookup("window.icon_size.height");
+
+ auto icon_size = QSize(width, height);
+
+ switch (icon_size.height()) {
+ case 12:
+ iconSizeSmall->setChecked(true);
+ break;
+ case 24:
+ iconSizeMedium->setChecked(true);
+ break;
+ case 32:
+ iconSizeLarge->setChecked(true);
+ break;
+ }
+
+ } catch (...) {
+ LOG(ERROR) << _("Setting Operation Error") << _("icon_size");
}
- // Iconstyle
- Qt::ToolButtonStyle iconStyle = static_cast<Qt::ToolButtonStyle>(
- settings.value("toolbar/iconstyle", Qt::ToolButtonTextUnderIcon)
- .toUInt());
- switch (iconStyle) {
- case Qt::ToolButtonTextOnly:
- iconTextButton->setChecked(true);
- break;
- case Qt::ToolButtonIconOnly:
- iconIconsButton->setChecked(true);
- break;
- case Qt::ToolButtonTextUnderIcon:
- iconAllButton->setChecked(true);
- break;
- default:
- break;
+
+ // icon_style
+ try {
+ int s_icon_style = settings.lookup("window.icon_style");
+ auto icon_style = static_cast<Qt::ToolButtonStyle>(s_icon_style);
+
+ switch (icon_style) {
+ case Qt::ToolButtonTextOnly:
+ iconTextButton->setChecked(true);
+ break;
+ case Qt::ToolButtonIconOnly:
+ iconIconsButton->setChecked(true);
+ break;
+ case Qt::ToolButtonTextUnderIcon:
+ iconAllButton->setChecked(true);
+ break;
+ default:
+ break;
+ }
+
+ } catch (...) {
+ LOG(ERROR) << _("Setting Operation Error") << _("icon_style");
}
// Window Save and Position
- if (settings.value("window/windowSave").toBool())
- windowSizeCheckBox->setCheckState(Qt::Checked);
-
- // infoBoardFontSize
- auto infoBoardFontSize =
- settings.value("informationBoard/fontSize", 10).toInt();
- if (infoBoardFontSize < 9 || infoBoardFontSize > 18) infoBoardFontSize = 10;
- infoBoardFontSizeSpin->setValue(infoBoardFontSize);
+ try {
+ bool window_save = settings.lookup("window.window_save");
+ if (window_save) windowSizeCheckBox->setCheckState(Qt::Checked);
+
+ } catch (...) {
+ LOG(ERROR) << _("Setting Operation Error") << _("window_save");
+ }
+
+ // info board font size
+ try {
+ int info_font_size = settings.lookup("window.info_font_size");
+ if (info_font_size < 9 || info_font_size > 18) info_font_size = 10;
+ infoBoardFontSizeSpin->setValue(info_font_size);
+ } catch (...) {
+ LOG(ERROR) << _("Setting Operation Error") << _("info_font_size");
+ }
}
/***********************************
@@ -158,34 +180,70 @@ void AppearanceTab::setSettings() {
* write them to settings-file
*************************************/
void AppearanceTab::applySettings() {
+ auto& settings =
+ GpgFrontend::UI::GlobalSettingStation::GetInstance().GetUISettings();
+
+ if (!settings.exists("window") ||
+ settings.lookup("window").getType() != libconfig::Setting::TypeGroup)
+ settings.add("window", libconfig::Setting::TypeGroup);
+
+ auto& window = settings["window"];
+
+ int icon_size = 24;
switch (iconSizeGroup->checkedId()) {
case 1:
- settings.setValue("toolbar/iconsize", QSize(12, 12));
+ icon_size = 12;
break;
case 2:
- settings.setValue("toolbar/iconsize", QSize(24, 24));
+ icon_size = 24;
break;
case 3:
- settings.setValue("toolbar/iconsize", QSize(32, 32));
+ icon_size = 32;
break;
}
+ if (!window.exists("icon_size")) {
+ auto& icon_size_settings =
+ window.add("icon_size", libconfig::Setting::TypeGroup);
+ icon_size_settings.add("width", libconfig::Setting::TypeInt) = icon_size;
+ icon_size_settings.add("height", libconfig::Setting::TypeInt) = icon_size;
+ } else {
+ window["icon_size"]["width"] = icon_size;
+ window["icon_size"]["height"] = icon_size;
+ }
+
+ auto icon_style = Qt::ToolButtonTextUnderIcon;
switch (iconStyleGroup->checkedId()) {
case 1:
- settings.setValue("toolbar/iconstyle", Qt::ToolButtonTextOnly);
+ icon_style = Qt::ToolButtonTextOnly;
break;
case 2:
- settings.setValue("toolbar/iconstyle", Qt::ToolButtonIconOnly);
+ icon_style = Qt::ToolButtonIconOnly;
break;
case 3:
- settings.setValue("toolbar/iconstyle", Qt::ToolButtonTextUnderIcon);
+ icon_style = Qt::ToolButtonTextUnderIcon;
break;
}
- settings.setValue("window/windowSave", windowSizeCheckBox->isChecked());
+ if (!window.exists("icon_style")) {
+ window.add("icon_style", libconfig::Setting::TypeInt) = icon_style;
+ } else {
+ window["icon_style"] = icon_style;
+ }
- settings.setValue("informationBoard/fontSize",
- infoBoardFontSizeSpin->value());
+ if (!window.exists("window_save")) {
+ window.add("window_save", libconfig::Setting::TypeBoolean) =
+ windowSizeCheckBox->isChecked();
+ } else {
+ window["window_save"] = windowSizeCheckBox->isChecked();
+ }
+
+ if (!window.exists("info_font_size")) {
+ window.add("info_font_size", libconfig::Setting::TypeBoolean) =
+ infoBoardFontSizeSpin->value();
+ } else {
+ window["info_font_size"] = infoBoardFontSizeSpin->value();
+ }
}
} // namespace GpgFrontend::UI
diff --git a/src/ui/settings/SettingsAppearance.h b/src/ui/settings/SettingsAppearance.h
index 284ecb1c..c0a0247b 100644
--- a/src/ui/settings/SettingsAppearance.h
+++ b/src/ui/settings/SettingsAppearance.h
@@ -33,7 +33,6 @@ class AppearanceTab : public QWidget {
Q_OBJECT
public:
- // void setSettings();
explicit AppearanceTab(QWidget* parent = nullptr);
void setSettings();
@@ -41,9 +40,6 @@ class AppearanceTab : public QWidget {
void applySettings();
private:
- QString appPath;
- QSettings settings;
-
QButtonGroup* iconStyleGroup;
QRadioButton* iconSizeSmall;
QRadioButton* iconSizeMedium;
diff --git a/src/ui/settings/SettingsDialog.cpp b/src/ui/settings/SettingsDialog.cpp
index f917a9b0..7fac5348 100644
--- a/src/ui/settings/SettingsDialog.cpp
+++ b/src/ui/settings/SettingsDialog.cpp
@@ -44,8 +44,9 @@ SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent) {
sendMailTab = new SendMailTab;
#endif
keyserverTab = new KeyserverTab;
+#ifdef ADVANCED_SUPPORT
advancedTab = new AdvancedTab;
- gpgPathsTab = new GpgPathsTab;
+#endif
tabWidget->addTab(generalTab, _("General"));
tabWidget->addTab(appearanceTab, _("Appearance"));
@@ -54,7 +55,9 @@ SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent) {
#endif
tabWidget->addTab(keyserverTab, _("Key Server"));
// tabWidget->addTab(gpgPathsTab, _("Gpg paths"));
+#ifdef ADVANCED_SUPPORT
tabWidget->addTab(advancedTab, _("Advanced"));
+#endif
buttonBox =
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
@@ -83,8 +86,10 @@ SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent) {
#endif
connect(keyserverTab, SIGNAL(signalRestartNeeded(bool)), this,
SLOT(slotSetRestartNeeded(bool)));
+#ifdef ADVANCED_SUPPORT
connect(advancedTab, SIGNAL(signalRestartNeeded(bool)), this,
SLOT(slotSetRestartNeeded(bool)));
+#endif
connect(this, SIGNAL(signalRestartNeeded(bool)), parent,
SLOT(slotSetRestartNeeded(bool)));
@@ -106,16 +111,19 @@ void SettingsDialog::slotAccept() {
#endif
appearanceTab->applySettings();
keyserverTab->applySettings();
+#ifdef ADVANCED_SUPPORT
advancedTab->applySettings();
- gpgPathsTab->applySettings();
+#endif
+
+ // write settings to filesystem
+ GlobalSettingStation::GetInstance().Sync();
+
if (getRestartNeeded()) {
emit signalRestartNeeded(true);
}
close();
}
-// http://www.informit.com/articles/article.aspx?p=1405555&seqNum=3
-// http://developer.qt.nokia.com/wiki/How_to_create_a_multi_language_application
QHash<QString, QString> SettingsDialog::listLanguages() {
QHash<QString, QString> languages;
@@ -146,85 +154,4 @@ QHash<QString, QString> SettingsDialog::listLanguages() {
return languages;
}
-GpgPathsTab::GpgPathsTab(QWidget* parent)
- : QWidget(parent),
- appPath(qApp->applicationDirPath()),
- settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
- QSettings::IniFormat) {
- setSettings();
-
- /*****************************************
- * Keydb Box
- *****************************************/
- auto* keydbBox = new QGroupBox(_("Relative path to Key Database"));
- auto* keydbBoxLayout = new QGridLayout();
-
- // Label containing the current keydbpath relative to default keydb path
- keydbLabel = new QLabel(accKeydbPath, this);
-
- auto* keydbButton = new QPushButton(_("Change Key Database path"), this);
- connect(keydbButton, SIGNAL(clicked()), this, SLOT(chooseKeydbDir()));
- auto* keydbDefaultButton =
- new QPushButton(_("Set Key Database to default path"), this);
- connect(keydbDefaultButton, SIGNAL(clicked()), this,
- SLOT(setKeydbPathToDefault()));
-
- keydbBox->setLayout(keydbBoxLayout);
- keydbBoxLayout->addWidget(
- new QLabel(QString(_("Current Key Database path")) + ": "), 1, 1);
- keydbBoxLayout->addWidget(keydbLabel, 1, 2);
- keydbBoxLayout->addWidget(keydbButton, 1, 3);
- keydbBoxLayout->addWidget(keydbDefaultButton, 2, 3);
- keydbBoxLayout->addWidget(
- new QLabel(QString("<b>") + _("NOTE") + ": </b> " +
- _("GpgFrontend will restart automatically if you change the "
- "Key Database path!")),
- 3, 1, 1, 3);
-
- auto* mainLayout = new QVBoxLayout;
- mainLayout->addWidget(keydbBox);
- mainLayout->addStretch(1);
- setLayout(mainLayout);
-}
-
-QString GpgPathsTab::getRelativePath(const QString& dir1, const QString& dir2) {
- QDir dir(dir1);
- QString s;
-
- s = dir.relativeFilePath(dir2);
- qDebug() << "relative path: " << s;
- if (s.isEmpty()) {
- s = ".";
- }
- return s;
-}
-
-void GpgPathsTab::setKeydbPathToDefault() {
- accKeydbPath = ".";
- keydbLabel->setText(".");
-}
-
-QString GpgPathsTab::chooseKeydbDir() {
- QString dir = QFileDialog::getExistingDirectory(
- this, _("Choose keydb directory"), accKeydbPath,
- QFileDialog::ShowDirsOnly);
-
- accKeydbPath = getRelativePath(defKeydbPath, dir);
- keydbLabel->setText(accKeydbPath);
- return {};
-}
-
-void GpgPathsTab::setSettings() {
- defKeydbPath = qApp->applicationDirPath() + "/keydb";
-
- accKeydbPath = settings.value("gpgpaths/keydbpath").toString();
- if (accKeydbPath.isEmpty()) {
- accKeydbPath = ".";
- }
-}
-
-void GpgPathsTab::applySettings() {
- settings.setValue("gpgpaths/keydbpath", accKeydbPath);
-}
-
} // namespace GpgFrontend::UI
diff --git a/src/ui/settings/SettingsDialog.h b/src/ui/settings/SettingsDialog.h
index 9f670cfd..b8277906 100755
--- a/src/ui/settings/SettingsDialog.h
+++ b/src/ui/settings/SettingsDialog.h
@@ -38,33 +38,10 @@ class SendMailTab;
class AppearanceTab;
class KeyserverTab;
-class AdvancedTab;
-
-class GpgPathsTab : public QWidget {
- Q_OBJECT
- public:
- explicit GpgPathsTab(QWidget* parent = nullptr);
-
- void applySettings();
-
- private:
- static QString getRelativePath(const QString& dir1, const QString& dir2);
-
- QString appPath;
- QSettings settings;
-
- QString defKeydbPath; /** The default keydb path used by gpg4usb */
- QString accKeydbPath; /** The currently used keydb path */
- QLabel* keydbLabel;
- void setSettings();
-
- private slots:
-
- QString chooseKeydbDir();
-
- void setKeydbPathToDefault();
-};
+#ifdef ADVANCED_SUPPORT
+class AdvancedTab;
+#endif
class SettingsDialog : public QDialog {
Q_OBJECT
@@ -78,8 +55,9 @@ class SettingsDialog : public QDialog {
#endif
AppearanceTab* appearanceTab;
KeyserverTab* keyserverTab;
+#ifdef ADVANCED_SUPPORT
AdvancedTab* advancedTab;
- GpgPathsTab* gpgPathsTab;
+#endif
static QHash<QString, QString> listLanguages();
diff --git a/src/ui/settings/SettingsGeneral.cpp b/src/ui/settings/SettingsGeneral.cpp
index a5ae124e..c0db08a5 100644
--- a/src/ui/settings/SettingsGeneral.cpp
+++ b/src/ui/settings/SettingsGeneral.cpp
@@ -204,8 +204,9 @@ void GeneralTab::setSettings() {
try {
std::string lang_key = settings.lookup("general.lang");
QString lang_value = lang.value(lang_key.c_str());
+ LOG(INFO) << "lang settings current" << lang_value.toStdString();
if (!lang.empty()) {
- langSelectBox->setCurrentIndex(langSelectBox->findText(lang_value));
+ langSelectBox->setCurrentIndex(langSelectBox->findText(lang_key.c_str()));
}
} catch (...) {
LOG(ERROR) << _("Setting Operation Error") << _("lang");
@@ -272,33 +273,29 @@ void GeneralTab::applySettings() {
#endif
#ifdef MULTI_LANG_SUPPORT
-
if (!general.exists("lang"))
general.add("lang", libconfig::Setting::TypeBoolean) =
langSelectBox->currentText().toStdString();
else {
general["lang"] = langSelectBox->currentText().toStdString();
- }
-
#endif
#ifdef SERVER_SUPPORT
- settings.setValue(
- "general/ownKeyId",
- QString::fromStdString(keyIdsList[ownKeySelectBox->currentIndex()]));
+ settings.setValue(
+ "general/ownKeyId",
+ QString::fromStdString(keyIdsList[ownKeySelectBox->currentIndex()]));
- settings.setValue("general/serviceToken",
- QString::fromStdString(serviceToken));
+ settings.setValue("general/serviceToken",
+ QString::fromStdString(serviceToken));
#endif
- if (!general.exists("confirm_import_keys"))
- general.add("confirm_import_keys", libconfig::Setting::TypeBoolean) =
- importConfirmationCheckBox->isChecked();
- else {
- general["confirm_import_keys"] = importConfirmationCheckBox->isChecked();
+ if (!general.exists("confirm_import_keys"))
+ general.add("confirm_import_keys", libconfig::Setting::TypeBoolean) =
+ importConfirmationCheckBox->isChecked();
+ else {
+ general["confirm_import_keys"] = importConfirmationCheckBox->isChecked();
+ }
}
-
- GlobalSettingStation::GetInstance().Sync();
}
#ifdef MULTI_LANG_SUPPORT
diff --git a/src/ui/settings/SettingsKeyServer.cpp b/src/ui/settings/SettingsKeyServer.cpp
index dc77491b..f05ad7fb 100644
--- a/src/ui/settings/SettingsKeyServer.cpp
+++ b/src/ui/settings/SettingsKeyServer.cpp
@@ -24,13 +24,11 @@
#include "SettingsKeyServer.h"
+#include "GlobalSettingStation.h"
+
namespace GpgFrontend::UI {
-KeyserverTab::KeyserverTab(QWidget* parent)
- : QWidget(parent),
- appPath(qApp->applicationDirPath()),
- settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
- QSettings::IniFormat) {
+KeyserverTab::KeyserverTab(QWidget* parent) : QWidget(parent) {
auto generalGroupBox = new QGroupBox(_("General"));
auto generalLayout = new QVBoxLayout();
@@ -95,15 +93,26 @@ KeyserverTab::KeyserverTab(QWidget* parent)
* appropriately
**********************************/
void KeyserverTab::setSettings() {
- keyServerStrList = settings.value("keyserver/keyServerList").toStringList();
-
- for (const auto& keyServer : keyServerStrList) {
- comboBox->addItem(keyServer);
- qDebug() << "KeyserverTab Get ListItemText" << keyServer;
+ auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+
+ try {
+ auto& server_list = settings.lookup("keyserver.server_list");
+ const auto server_list_size = server_list.getLength();
+ for (int i = 0; i < server_list_size; i++) {
+ std::string server_url = server_list[i];
+ comboBox->addItem(server_url.c_str());
+ keyServerStrList.append(server_url.c_str());
+ }
+ } catch (...) {
+ LOG(ERROR) << _("Setting Operation Error") << _("server_list");
}
- comboBox->setCurrentText(
- settings.value("keyserver/defaultKeyServer").toString());
+ try {
+ std::string default_server = settings.lookup("keyserver.default_server");
+ comboBox->setCurrentText(default_server.c_str());
+ } catch (...) {
+ LOG(ERROR) << _("Setting Operation Error") << _("default_server");
+ }
}
void KeyserverTab::addKeyServer() {
@@ -123,12 +132,35 @@ void KeyserverTab::addKeyServer() {
* write them to settings-file
*************************************/
void KeyserverTab::applySettings() {
- settings.setValue("keyserver/keyServerList", keyServerStrList);
- settings.setValue("keyserver/defaultKeyServer", comboBox->currentText());
+ auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+
+ if (!settings.exists("keyserver") ||
+ settings.lookup("keyserver").getType() != libconfig::Setting::TypeGroup)
+ settings.add("keyserver", libconfig::Setting::TypeGroup);
+
+ auto& keyserver = settings["keyserver"];
+
+ if (keyserver.exists("server_list"))
+ keyserver.remove("server_list");
+
+ keyserver.add("server_list", libconfig::Setting::TypeList);
+
+ auto& server_list = keyserver["server_list"];
+ for (const auto& key_server_url : keyServerStrList) {
+ server_list.add(libconfig::Setting::TypeString) =
+ key_server_url.toStdString();
+ }
+
+ if (!keyserver.exists("default_server")) {
+ keyserver.add("default_server", libconfig::Setting::TypeString) =
+ comboBox->currentText().toStdString();
+ } else {
+ keyserver["default_server"] = comboBox->currentText().toStdString();
+ }
}
void KeyserverTab::refreshTable() {
- qDebug() << "Start Refreshing Key Server Table";
+ LOG(INFO) << "Start Refreshing Key Server Table";
keyServerTable->setRowCount(keyServerStrList.size());
diff --git a/src/ui/settings/SettingsKeyServer.h b/src/ui/settings/SettingsKeyServer.h
index 23186702..5042aaa5 100644
--- a/src/ui/settings/SettingsKeyServer.h
+++ b/src/ui/settings/SettingsKeyServer.h
@@ -39,8 +39,6 @@ class KeyserverTab : public QWidget {
void applySettings();
private:
- QString appPath;
- QSettings settings;
QComboBox* comboBox;
QLineEdit* newKeyServerEdit;
QTableWidget* keyServerTable;
diff --git a/src/ui/widgets/InfoBoardWidget.cpp b/src/ui/widgets/InfoBoardWidget.cpp
index 7de99a2b..cd469422 100644
--- a/src/ui/widgets/InfoBoardWidget.cpp
+++ b/src/ui/widgets/InfoBoardWidget.cpp
@@ -24,14 +24,12 @@
#include "ui/widgets/InfoBoardWidget.h"
+#include "ui/settings/GlobalSettingStation.h"
+
namespace GpgFrontend::UI {
InfoBoardWidget::InfoBoardWidget(QWidget* parent, KeyList* keyList)
- : QWidget(parent),
- mKeyList(keyList),
- appPath(qApp->applicationDirPath()),
- settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
- QSettings::IniFormat) {
+ : QWidget(parent), mKeyList(keyList) {
infoBoard = new QTextEdit(this);
infoBoard->setReadOnly(true);
infoBoard->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
@@ -82,10 +80,14 @@ InfoBoardWidget::InfoBoardWidget(QWidget* parent, KeyList* keyList)
notificationWidgetLayout->setStretchFactor(line, 1);
notificationWidgetLayout->addStretch(0);
this->setLayout(notificationWidgetLayout);
+
+ // set default size
+ infoBoard->resize(480, 120);
+ resize(480, 120);
}
void InfoBoardWidget::slotImportFromKeyserver() {
- auto* importDialog = new KeyServerImportDialog(mKeyList, false, this);
+ auto* importDialog = new KeyServerImportDialog(false, this);
auto key_ids = std::make_unique<KeyIdArgsList>();
for (const auto& key_id : *keysNotInList) {
key_ids->push_back(key_id.toStdString());
@@ -116,9 +118,18 @@ void InfoBoardWidget::setInfoBoard(const QString& text,
QPalette status = infoBoard->palette();
status.setColor(QPalette::Text, color);
infoBoard->setPalette(status);
- auto infoBoardFontSize =
- settings.value("informationBoard/fontSize", 10).toInt();
- infoBoard->setFont(QFont("Times", infoBoardFontSize));
+
+ auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+
+ // info board font size
+ auto info_font_size = 10;
+ try {
+ info_font_size = settings.lookup("window.info_font_size");
+ if (info_font_size < 9 || info_font_size > 18) info_font_size = 10;
+ } catch (...) {
+ LOG(ERROR) << _("Setting Operation Error") << _("info_font_size");
+ }
+ infoBoard->setFont(QFont("Times", info_font_size));
}
void InfoBoardWidget::slotRefresh(const QString& text, InfoBoardStatus status) {
diff --git a/src/ui/widgets/InfoBoardWidget.h b/src/ui/widgets/InfoBoardWidget.h
index 858aa014..1a13e1a2 100644
--- a/src/ui/widgets/InfoBoardWidget.h
+++ b/src/ui/widgets/InfoBoardWidget.h
@@ -93,9 +93,6 @@ class InfoBoardWidget : public QWidget {
void slotRefresh(const QString& text, InfoBoardStatus status);
private:
- QString appPath;
- QSettings settings;
-
QMenu* detailMenu; /** Menu for te Button in verfiyNotification */
QAction* importFromKeyserverAct; /** Action for importing keys from keyserver
which are notin keylist */
diff --git a/src/ui/widgets/VerifyKeyDetailBox.cpp b/src/ui/widgets/VerifyKeyDetailBox.cpp
index 7c25d593..cd5b6641 100644
--- a/src/ui/widgets/VerifyKeyDetailBox.cpp
+++ b/src/ui/widgets/VerifyKeyDetailBox.cpp
@@ -153,7 +153,7 @@ VerifyKeyDetailBox::VerifyKeyDetailBox(QWidget* parent, KeyList* keyList,
}
void VerifyKeyDetailBox::slotImportFormKeyserver() {
- auto* importDialog = new KeyServerImportDialog(mKeyList, false, this);
+ auto* importDialog = new KeyServerImportDialog(false, this);
auto key_ids = std::make_unique<KeyIdArgsList>();
key_ids->push_back(fpr.toStdString());
importDialog->slotImport(key_ids);