Skip to content

Commit

Permalink
feat: users can choose which crypto tool bar buttons are displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
saturneric committed Jan 26, 2025
1 parent 3aa7e32 commit 2572aba
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 27 deletions.
4 changes: 3 additions & 1 deletion gpgfrontend.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@
<file alias="export-email.png">resource/lfs/icons/export-email.png</file>
<file alias="warning-filling.png">resource/lfs/icons/warning-filling.png</file>
<file alias="upgrade.png">resource/lfs/icons/upgrade.png</file>
<file alias="batch.png">resource/lfs/icons/batch.png</file>
<file alias="batch.png">resource/lfs/icons/batch.png</file>
<file alias="encr-sign.png">resource/lfs/icons/encr-sign.png</file>
<file alias="decr-verify.png">resource/lfs/icons/decr-verify.png</file>
</qresource>
<qresource prefix="/test/key">
<file alias="pv1.key">resource/lfs/test/data/pv1.key</file>
Expand Down
Binary file added resource/lfs/icons/decr-verify.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/lfs/icons/encr-sign.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resource/lfs/icons/file-operator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 7 additions & 6 deletions src/core/typedef/GpgTypedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ using GpgOperationCallback = std::function<void(GpgError, DataObjectPtr)>;
using GpgOperationFuture = std::future<std::tuple<GpgError, DataObjectPtr>>;

enum GpgOperation {
kENCRYPT,
kDECRYPT,
kSIGN,
kVERIFY,
kENCRYPT_SIGN,
kDECRYPT_VERIFY
kNONE = 0,
kENCRYPT = 1 << 0,
kDECRYPT = 1 << 1,
kSIGN = 1 << 2,
kVERIFY = 1 << 3,
kENCRYPT_SIGN = 1 << 4,
kDECRYPT_VERIFY = 1 << 5,
};
} // namespace GpgFrontend
27 changes: 27 additions & 0 deletions src/ui/dialog/settings/SettingsAppearance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ void AppearanceTab::SetSettings() {
} else {
ui_->themeComboBox->setCurrentIndex(target_theme_index);
}

ui_->encrCheckBox->setChecked(
(appearance.tool_bar_crypto_operas_type & GpgOperation::kENCRYPT) != 0);
ui_->decrCheckBox->setChecked(
(appearance.tool_bar_crypto_operas_type & GpgOperation::kDECRYPT) != 0);
ui_->signCheckBox->setChecked(
(appearance.tool_bar_crypto_operas_type & GpgOperation::kSIGN) != 0);
ui_->verifyCheckBox->setChecked(
(appearance.tool_bar_crypto_operas_type & GpgOperation::kVERIFY) != 0);
ui_->encrSignCheckBox->setChecked((appearance.tool_bar_crypto_operas_type &
GpgOperation::kENCRYPT_SIGN) != 0);
ui_->decrVerifyCheckBox->setChecked((appearance.tool_bar_crypto_operas_type &
GpgOperation::kDECRYPT_VERIFY) != 0);
}

void AppearanceTab::ApplySettings() {
Expand Down Expand Up @@ -195,6 +208,20 @@ void AppearanceTab::ApplySettings() {
appearance.text_editor_font_size =
ui_->fontSizeTextEditorLabelSpinBox->value();

appearance.tool_bar_crypto_operas_type = 0;
appearance.tool_bar_crypto_operas_type |=
ui_->encrCheckBox->isChecked() ? kENCRYPT : kNONE;
appearance.tool_bar_crypto_operas_type |=
ui_->decrCheckBox->isChecked() ? kDECRYPT : kNONE;
appearance.tool_bar_crypto_operas_type |=
ui_->signCheckBox->isChecked() ? kSIGN : kNONE;
appearance.tool_bar_crypto_operas_type |=
ui_->verifyCheckBox->isChecked() ? kVERIFY : kNONE;
appearance.tool_bar_crypto_operas_type |=
ui_->encrSignCheckBox->isChecked() ? kENCRYPT_SIGN : kNONE;
appearance.tool_bar_crypto_operas_type |=
ui_->decrVerifyCheckBox->isChecked() ? kDECRYPT_VERIFY : kNONE;

general_settings_state.Store(appearance.ToJson());

auto settings = GlobalSettingStation::GetInstance().GetSettings();
Expand Down
38 changes: 36 additions & 2 deletions src/ui/main_window/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "core/function/GlobalSettingStation.h"
#include "core/model/SettingsObject.h"
#include "core/module/ModuleManager.h"
#include "struct/settings_object/AppearanceSO.h"
#include "ui/UISignalStation.h"
#include "ui/main_window/GeneralMainWindow.h"
#include "ui/struct/settings_object/KeyServerSO.h"
Expand Down Expand Up @@ -178,11 +179,44 @@ void MainWindow::restore_settings() {
settings.setValue("gnupg/non_ascii_at_file_operation", true);
}

prohibit_update_checking_ =
settings.value("network/prohibit_update_check").toBool();

// set appearance
AppearanceSO const appearance(SettingsObject("general_settings_state"));

crypt_tool_bar_->clear();

if ((appearance.tool_bar_crypto_operas_type & GpgOperation::kENCRYPT) != 0) {
crypt_tool_bar_->addAction(encrypt_act_);
}
if ((appearance.tool_bar_crypto_operas_type & GpgOperation::kDECRYPT) != 0) {
crypt_tool_bar_->addAction(decrypt_act_);
}
if ((appearance.tool_bar_crypto_operas_type & GpgOperation::kSIGN) != 0) {
crypt_tool_bar_->addAction(sign_act_);
}
if ((appearance.tool_bar_crypto_operas_type & GpgOperation::kVERIFY) != 0) {
crypt_tool_bar_->addAction(verify_act_);
}
if ((appearance.tool_bar_crypto_operas_type & GpgOperation::kENCRYPT_SIGN) !=
0) {
crypt_tool_bar_->addAction(encrypt_sign_act_);
}
if ((appearance.tool_bar_crypto_operas_type &
GpgOperation::kDECRYPT_VERIFY) != 0) {
crypt_tool_bar_->addAction(decrypt_verify_act_);
}

icon_style_ = appearance.tool_bar_button_style;
import_button_->setToolButtonStyle(icon_style_);
this->setToolButtonStyle(icon_style_);

prohibit_update_checking_ =
settings.value("network/prohibit_update_check").toBool();
// icons ize
this->setIconSize(
QSize(appearance.tool_bar_icon_width, appearance.tool_bar_icon_height));
import_button_->setIconSize(
QSize(appearance.tool_bar_icon_width, appearance.tool_bar_icon_height));
}

void MainWindow::recover_editor_unsaved_pages_from_cache() {
Expand Down
10 changes: 1 addition & 9 deletions src/ui/main_window/MainWindowSlotUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,7 @@ void MainWindow::slot_open_settings_dialog() {
connect(dialog, &SettingsDialog::finished, this, [&]() -> void {
AppearanceSO appearance(SettingsObject("general_settings_state"));

this->setToolButtonStyle(appearance.tool_bar_button_style);
import_button_->setToolButtonStyle(appearance.tool_bar_button_style);

// icons ize
this->setIconSize(
QSize(appearance.tool_bar_icon_width, appearance.tool_bar_icon_height));
import_button_->setIconSize(
QSize(appearance.tool_bar_icon_width, appearance.tool_bar_icon_height));

restore_settings();
// restart main window if necessary
if (restart_mode_ != kNonRestartCode) {
if (edit_->MaybeSaveAnyTab()) {
Expand Down
13 changes: 5 additions & 8 deletions src/ui/main_window/MainWindowUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@

#include "MainWindow.h"
#include "core/function/GlobalSettingStation.h"
#include "core/model/SettingsObject.h"
#include "core/module/ModuleManager.h"
#include "dialog/controller/ModuleControllerDialog.h"
#include "struct/settings_object/AppearanceSO.h"
#include "ui/UserInterfaceUtils.h"
#include "ui/dialog/controller/GnuPGControllerDialog.h"
#include "ui/dialog/help/AboutDialog.h"
Expand Down Expand Up @@ -148,7 +150,7 @@ void MainWindow::create_actions() {
&MainWindow::SlotGeneralEncrypt);

encrypt_sign_act_ =
create_action("encrypt_sign", tr("Encrypt Sign"), ":/icons/compress.png",
create_action("encrypt_sign", tr("Encrypt Sign"), ":/icons/encr-sign.png",
tr("Encrypt and Sign Message"),
{QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_E)});
connect(encrypt_sign_act_, &QAction::triggered, this,
Expand All @@ -162,7 +164,7 @@ void MainWindow::create_actions() {

decrypt_verify_act_ =
create_action("decrypt_verify", tr("Decrypt Verify"),
":/icons/expand.png", tr("Decrypt and Verify Message"),
":/icons/decr-verify.png", tr("Decrypt and Verify Message"),
{QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_D)});
connect(decrypt_verify_act_, &QAction::triggered, this,
&MainWindow::SlotGeneralDecryptVerify);
Expand Down Expand Up @@ -498,12 +500,7 @@ void MainWindow::create_tool_bars() {

crypt_tool_bar_ = addToolBar(tr("Operations"));
crypt_tool_bar_->setObjectName("cryptToolBar");
crypt_tool_bar_->addAction(encrypt_act_);
// crypt_tool_bar_->addAction(encrypt_sign_act_);
crypt_tool_bar_->addAction(decrypt_act_);
// crypt_tool_bar_->addAction(decrypt_verify_act_);
crypt_tool_bar_->addAction(sign_act_);
crypt_tool_bar_->addAction(verify_act_);

view_menu_->addAction(crypt_tool_bar_->toggleViewAction());

key_tool_bar_ = addToolBar(tr("Key"));
Expand Down
9 changes: 9 additions & 0 deletions src/ui/struct/settings_object/AppearanceSO.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#pragma once

#include "core/typedef/GpgTypedef.h"

namespace GpgFrontend::UI {

struct AppearanceSO {
Expand All @@ -36,6 +38,9 @@ struct AppearanceSO {
int tool_bar_icon_width = 24;
int tool_bar_icon_height = 24;
Qt::ToolButtonStyle tool_bar_button_style = Qt::ToolButtonTextUnderIcon;
int tool_bar_crypto_operas_type = GpgOperation::kENCRYPT |
GpgOperation::kDECRYPT |
GpgOperation::kSIGN | GpgOperation::kVERIFY;

bool save_window_state;

Expand All @@ -55,6 +60,9 @@ struct AppearanceSO {
if (const auto v = j["tool_bar_button_style"]; v.isDouble()) {
tool_bar_button_style = static_cast<Qt::ToolButtonStyle>(v.toInt());
}
if (const auto v = j["tool_bar_crypto_operas_type"]; v.isDouble()) {
tool_bar_crypto_operas_type = static_cast<int>(v.toInt());
}

if (const auto v = j["save_window_state"]; v.isBool()) {
save_window_state = v.toBool();
Expand All @@ -68,6 +76,7 @@ struct AppearanceSO {
j["tool_bar_icon_width"] = tool_bar_icon_width;
j["tool_bar_icon_height"] = tool_bar_icon_height;
j["tool_bar_button_style"] = tool_bar_button_style;
j["tool_bar_crypto_operas_type"] = tool_bar_crypto_operas_type;

j["save_window_state"] = save_window_state;
return j;
Expand Down
71 changes: 70 additions & 1 deletion ui/AppearanceSettings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,82 @@
</item>
</layout>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Crypto Operations</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop</set>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_3" rowstretch="0,0,0,0,0,0,0" columnstretch="0,0" rowminimumheight="0,0,0,0,0,0,0">
<property name="sizeConstraint">
<enum>QLayout::SizeConstraint::SetDefaultConstraint</enum>
</property>
<item row="3" column="1">
<widget class="QCheckBox" name="verifyCheckBox">
<property name="text">
<string>Verify</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="decrVerifyCheckBox">
<property name="text">
<string>Decrypt Verify</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="encrSignCheckBox">
<property name="text">
<string>Encrypt Sign</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="encrCheckBox">
<property name="text">
<string>Encrypt</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="signCheckBox">
<property name="text">
<string>Sign</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="decrCheckBox">
<property name="text">
<string>Decrypt</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down

0 comments on commit 2572aba

Please sign in to comment.