diff options
Diffstat (limited to 'src/ui')
29 files changed, 593 insertions, 224 deletions
diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp index 586d72ab..f2659e9d 100644 --- a/src/ui/UserInterfaceUtils.cpp +++ b/src/ui/UserInterfaceUtils.cpp @@ -53,7 +53,7 @@ void show_verify_details(QWidget *parent, InfoBoardWidget *info_board, GpgError error, const GpgVerifyResult &verify_result) { // take out result info_board->ResetOptionActionsMenu(); - info_board->AddOptionalAction("Show Verify Details", [=]() { + info_board->AddOptionalAction(_("Show Verify Details"), [=]() { VerifyDetailsDialog(parent, error, verify_result); }); } @@ -169,9 +169,10 @@ CommonUtils::CommonUtils() : QWidget(nullptr) { connect(this, &CommonUtils::SignalGnupgNotInstall, this, []() { QMessageBox::critical( nullptr, _("ENV Loading Failed"), - _("Gnupg(gpg) is not installed correctly, please follow the " - "ReadME " - "instructions in Github to install Gnupg and then open " + _("Gnupg(gpg) is not installed correctly, please follow " + "<a href='https://www.gpgfrontend.pub/#/" + "faq?id=how-to-deal-with-39env-loading-failed39'>this notes</a>" + " in FAQ to install Gnupg and then open " "GpgFrontend.")); QCoreApplication::quit(); }); diff --git a/src/ui/dialog/GeneralDialog.cpp b/src/ui/dialog/GeneralDialog.cpp index d07c2497..6fd2f32c 100644 --- a/src/ui/dialog/GeneralDialog.cpp +++ b/src/ui/dialog/GeneralDialog.cpp @@ -50,7 +50,6 @@ void GpgFrontend::UI::GeneralDialog::slot_restore_settings() noexcept { int x = general_windows_state.Check("window_pos").Check("x", 100), y = general_windows_state.Check("window_pos").Check("y", 100); - this->move({x, y}); pos_ = {x, y}; int width = @@ -58,9 +57,56 @@ void GpgFrontend::UI::GeneralDialog::slot_restore_settings() noexcept { height = general_windows_state.Check("window_size").Check("height", 247); - this->resize({width, height}); size_ = {width, height}; + if (this->parent() != nullptr) { + LOG(INFO) << "parent address" << this->parent(); + + QPoint parent_pos = {0, 0}; + QSize parent_size = {0, 0}; + + auto *parent_widget = qobject_cast<QWidget *>(this->parent()); + if (parent_widget != nullptr) { + parent_pos = parent_widget->pos(); + parent_size = parent_widget->size(); + } + + auto *parent_dialog = qobject_cast<QDialog *>(this->parent()); + if (parent_dialog != nullptr) { + parent_pos = parent_dialog->pos(); + parent_size = parent_dialog->size(); + } + + auto *parent_window = qobject_cast<QMainWindow *>(this->parent()); + if (parent_window != nullptr) { + parent_pos = parent_window->pos(); + parent_size = parent_window->size(); + } + + LOG(INFO) << "parent pos x:" << parent_pos.x() + << "y:" << parent_pos.y(); + + LOG(INFO) << "parent size width:" << parent_size.width() + << "height:" << parent_size.height(); + + LOG(INFO) << "this dialog size width:" << size_.width() + << "height:" << size_.height(); + + if (parent_pos != QPoint{0, 0}) { + QPoint parent_center{parent_pos.x() + parent_size.width() / 2, + parent_pos.y() + parent_size.height() / 2}; + + pos_ = {parent_center.x() - size_.width() / 2, + parent_center.y() - size_.height() / 2}; + + // record parent_pos_ + this->parent_pos_ = parent_pos; + this->parent_size_ = parent_size; + } + } + + this->move(pos_); + this->resize(size_); } } catch (...) { @@ -78,6 +124,9 @@ void GpgFrontend::UI::GeneralDialog::slot_save_settings() noexcept { general_windows_state["window_pos"]["x"] = pos().x(); general_windows_state["window_pos"]["y"] = pos().y(); + // update size of current dialog + size_ = this->size(); + general_windows_state["window_size"]["width"] = size_.width(); general_windows_state["window_size"]["height"] = size_.height(); general_windows_state["window_save"] = true; @@ -86,3 +135,41 @@ void GpgFrontend::UI::GeneralDialog::slot_save_settings() noexcept { LOG(ERROR) << name_ << "error"; } } + +void GpgFrontend::UI::GeneralDialog::setPosCenterOfScreen() { + 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; + + pos_ = QPoint((screen_width - QWidget::width()) / 2, + (screen_height - QWidget::height()) / 2); + this->move(pos_); +} + +/** + * @brief + * + */ +void GpgFrontend::UI::GeneralDialog::movePosition2CenterOfParent() { + LOG(INFO) << "parent pos x:" << parent_pos_.x() << "y:" << parent_pos_.y(); + + LOG(INFO) << "parent size width:" << parent_size_.width() + << "height:" << parent_size_.height(); + + if (parent_pos_ != QPoint{0, 0} && parent_size_ != QSize{0, 0}) { + LOG(INFO) << "update current dialog position now"; + QPoint parent_center{parent_pos_.x() + parent_size_.width() / 2, + parent_pos_.y() + parent_size_.height() / 2}; + + // update size of current dialog + size_ = this->size(); + + pos_ = {parent_center.x() - size_.width() / 2, + parent_center.y() - size_.height() / 2}; + this->move(pos_); + } +}
\ No newline at end of file diff --git a/src/ui/dialog/GeneralDialog.h b/src/ui/dialog/GeneralDialog.h index ca480c8b..41018105 100644 --- a/src/ui/dialog/GeneralDialog.h +++ b/src/ui/dialog/GeneralDialog.h @@ -45,6 +45,18 @@ class GeneralDialog : public QDialog { */ ~GeneralDialog() override; + protected: + /** + * + */ + void setPosCenterOfScreen(); + + /** + * @brief + * + */ + void movePosition2CenterOfParent(); + private slots: /** * @@ -60,6 +72,8 @@ class GeneralDialog : public QDialog { std::string name_; ///< QPoint pos_; ///< QSize size_; ///< + QPoint parent_pos_; + QSize parent_size_; }; } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/help/GnupgTab.cpp b/src/ui/dialog/help/GnupgTab.cpp index 48787987..9d783367 100644 --- a/src/ui/dialog/help/GnupgTab.cpp +++ b/src/ui/dialog/help/GnupgTab.cpp @@ -31,36 +31,103 @@ #include "GnupgTab.h" -GpgFrontend::UI::GnupgTab::GnupgTab(QWidget* parent) : QWidget(parent) { +#include "easylogging++.h" +#include "ui_GnuPGInfo.h" + +GpgFrontend::UI::GnupgTab::GnupgTab(QWidget* parent) + : QWidget(parent), + ui_(std::make_shared<Ui_GnuPGInfo>()), + gpgconf_process_(new QProcess(this)) { + GpgContext& ctx = GpgContext::GetInstance(); + auto info = ctx.GetInfo(); + + ui_->setupUi(this); + + QStringList column_titles; + column_titles << _("Name") << _("Description") << _("Version") << _("Path"); + + ui_->conponentDetailsTable->setColumnCount(column_titles.length()); + ui_->conponentDetailsTable->setHorizontalHeaderLabels(column_titles); + ui_->conponentDetailsTable->horizontalHeader()->setStretchLastSection(false); + ui_->conponentDetailsTable->setSelectionBehavior( + QAbstractItemView::SelectRows); + + // tableitems not editable + ui_->conponentDetailsTable->setEditTriggers( + QAbstractItemView::NoEditTriggers); + + // no focus (rectangle around tableitems) + // may be it should focus on whole row + ui_->conponentDetailsTable->setFocusPolicy(Qt::NoFocus); + ui_->conponentDetailsTable->setAlternatingRowColors(true); + + gpgconf_process_->start(QString::fromStdString(info.GpgConfPath), + QStringList() << "--list-components"); + + connect(gpgconf_process_, + qOverload<int, QProcess::ExitStatus>(&QProcess::finished), this, + &GnupgTab::process_components_info); +} + +void GpgFrontend::UI::GnupgTab::process_components_info( + int exit_code, QProcess::ExitStatus exit_status) { + LOG(INFO) << "called"; + GpgContext& ctx = GpgContext::GetInstance(); auto info = ctx.GetInfo(); - auto* pixmap = new QPixmap(":gnupg.png"); - auto* text = new QString( - "<center><h2>" + QString(_("GnuPG")) + "</h2></center>" + "<center><b>" + - QString(_("GnuPG Version")) + ": " + - QString::fromStdString(info.GnupgVersion) + "</b></center>" + - "<center><b>" + +"</b></center>" + "<center>" + - QString(_("GpgME Version")) + ": " + - QString::fromStdString(info.GpgMEVersion) + "</center><br /><hr />" + - "<h3>" + QString(_("PATHs")) + "</h3>" + QString(_("GpgConf")) + ": " + - QString::fromStdString(info.GpgConfPath) + "<br />" + - QString(_("GnuPG")) + ": " + QString::fromStdString(info.AppPath) + - "<br />" + QString(_("CMS")) + ": " + - QString::fromStdString(info.CMSPath) + "<br />"); - - auto* layout = new QGridLayout(); - auto* pixmapLabel = new QLabel(); - pixmapLabel->setPixmap(*pixmap); - layout->addWidget(pixmapLabel, 0, 0, 1, -1, Qt::AlignCenter); - auto* aboutLabel = new QLabel(); - aboutLabel->setText(*text); - aboutLabel->setWordWrap(true); - aboutLabel->setOpenExternalLinks(true); - layout->addWidget(aboutLabel, 1, 0, 1, -1); - layout->addItem( - new QSpacerItem(20, 10, QSizePolicy::Minimum, QSizePolicy::Fixed), 2, 1, - 1, 1); - - setLayout(layout); + std::vector<std::vector<std::string>> components_info = { + {"gpgme", "GPG Made Easy", info.GpgMEVersion, "/"}, + {"gpgconf", "GPG Configure", "/", info.GpgConfPath}, + + }; + + if (gpgconf_process_ != nullptr) { + QString data = gpgconf_process_->readAllStandardOutput(); + + std::vector<std::string> line_split_list; + boost::split(line_split_list, data.toStdString(), boost::is_any_of("\n")); + + for (const auto& line : line_split_list) { + std::vector<std::string> info_split_list; + boost::split(info_split_list, line, boost::is_any_of(":")); + LOG(INFO) << "gpgconf info line" << line << "info size" + << info_split_list.size(); + + if (info_split_list.size() != 3) continue; + + if (info_split_list[0] == "gpg") { + components_info.push_back({info_split_list[0], info_split_list[1], + info.GnupgVersion, info_split_list[2]}); + } else { + components_info.push_back( + {info_split_list[0], info_split_list[1], "/", info_split_list[2]}); + } + } + } + + ui_->conponentDetailsTable->setRowCount(components_info.size()); + + int row = 0; + for (const auto& info : components_info) { + if (info.size() != 4) continue; + + auto* tmp0 = new QTableWidgetItem(QString::fromStdString(info[0])); + tmp0->setTextAlignment(Qt::AlignCenter); + ui_->conponentDetailsTable->setItem(row, 0, tmp0); + + auto* tmp1 = new QTableWidgetItem(QString::fromStdString(info[1])); + tmp1->setTextAlignment(Qt::AlignCenter); + ui_->conponentDetailsTable->setItem(row, 1, tmp1); + + auto* tmp2 = new QTableWidgetItem(QString::fromStdString(info[2])); + tmp2->setTextAlignment(Qt::AlignCenter); + ui_->conponentDetailsTable->setItem(row, 2, tmp2); + + auto* tmp3 = new QTableWidgetItem(QString::fromStdString(info[3])); + tmp3->setTextAlignment(Qt::AlignLeft); + ui_->conponentDetailsTable->setItem(row, 3, tmp3); + + row++; + } } diff --git a/src/ui/dialog/help/GnupgTab.h b/src/ui/dialog/help/GnupgTab.h index 4fc7ff22..c143bae3 100644 --- a/src/ui/dialog/help/GnupgTab.h +++ b/src/ui/dialog/help/GnupgTab.h @@ -35,8 +35,9 @@ #include "core/GpgContext.h" #include "ui/GpgFrontendUI.h" -namespace GpgFrontend::UI{ -class GnupgTab: public QWidget { +class Ui_GnuPGInfo; +namespace GpgFrontend::UI { +class GnupgTab : public QWidget { Q_OBJECT public: /** @@ -45,9 +46,14 @@ class GnupgTab: public QWidget { * @param parent */ explicit GnupgTab(QWidget* parent = nullptr); -}; -} + private: + std::shared_ptr<Ui_GnuPGInfo> ui_; + QProcess* gpgconf_process_; + private slots: + void process_components_info(int, QProcess::ExitStatus); +}; +} // namespace GpgFrontend::UI #endif // GPGFRONTEND_GNUPGTAB_H diff --git a/src/ui/dialog/import_export/KeyUploadDialog.cpp b/src/ui/dialog/import_export/KeyUploadDialog.cpp index 055f2e1f..ad4be0cb 100644 --- a/src/ui/dialog/import_export/KeyUploadDialog.cpp +++ b/src/ui/dialog/import_export/KeyUploadDialog.cpp @@ -33,6 +33,7 @@ #include "core/function/GlobalSettingStation.h" #include "core/function/gpg/GpgKeyGetter.h" #include "core/function/gpg/GpgKeyImportExporter.h" +#include "ui/struct/SettingsObject.h" namespace GpgFrontend::UI { @@ -40,6 +41,7 @@ KeyUploadDialog::KeyUploadDialog(const KeyIdArgsListPtr& keys_ids, QWidget* parent) : GeneralDialog(typeid(KeyUploadDialog).name(), parent), m_keys_(GpgKeyGetter::GetInstance().GetKeys(keys_ids)) { + auto* pb = new QProgressBar(); pb->setRange(0, 0); pb->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); @@ -54,33 +56,47 @@ KeyUploadDialog::KeyUploadDialog(const KeyIdArgsListPtr& keys_ids, this->setModal(true); this->setWindowTitle(_("Uploading Public Key")); this->setFixedSize(240, 42); + this->setPosCenterOfScreen(); } void KeyUploadDialog::SlotUpload() { auto out_data = std::make_unique<ByteArray>(); GpgKeyImportExporter::GetInstance().ExportKeys(*m_keys_, out_data); slot_upload_key_to_server(*out_data); + + // Done + this->hide(); + this->close(); } void KeyUploadDialog::slot_upload_key_to_server( const GpgFrontend::ByteArray& keys_data) { + std::string target_keyserver; - 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; + + try { + SettingsObject key_server_json("key_server"); + + const auto key_server_list = + key_server_json.Check("server_list", nlohmann::json::array()); + + int default_key_server_index = key_server_json.Check("default_server", 0); + if (default_key_server_index >= key_server_list.size()) { + throw std::runtime_error("default_server index out of range"); } + + target_keyserver = + key_server_list[default_key_server_index].get<std::string>(); + + 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; } QUrl req_url(QString::fromStdString(target_keyserver + "/pks/add")); @@ -117,10 +133,6 @@ void KeyUploadDialog::slot_upload_key_to_server( while (reply->isRunning()) { QApplication::processEvents(); } - - // Done - this->hide(); - this->close(); } void KeyUploadDialog::slot_upload_finished() { diff --git a/src/ui/dialog/key_generate/KeygenDialog.cpp b/src/ui/dialog/key_generate/KeygenDialog.cpp index 42160ec9..b7ba6369 100644 --- a/src/ui/dialog/key_generate/KeygenDialog.cpp +++ b/src/ui/dialog/key_generate/KeygenDialog.cpp @@ -254,8 +254,9 @@ void KeyGenDialog::slot_authentication_box_changed(int state) { void KeyGenDialog::slot_activated_key_type(int index) { qDebug() << "key type index changed " << index; - gen_key_info_->SetAlgo( - this->key_type_combo_box_->itemText(index).toStdString()); + // check + assert(gen_key_info_->GetSupportedKeyAlgo().size() > index); + gen_key_info_->SetAlgo(gen_key_info_->GetSupportedKeyAlgo()[index]); refresh_widgets_state(); } @@ -357,7 +358,7 @@ QGroupBox* KeyGenDialog::create_basic_info_group_box() { key_type_combo_box_ = new QComboBox(this); for (auto& algo : GenKeyInfo::GetSupportedKeyAlgo()) { - key_type_combo_box_->addItem(QString::fromStdString(algo)); + key_type_combo_box_->addItem(QString::fromStdString(algo.first)); } if (!GenKeyInfo::GetSupportedKeyAlgo().empty()) { key_type_combo_box_->setCurrentIndex(0); diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp index 806c0e50..afa768f0 100644 --- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp +++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp @@ -26,6 +26,8 @@ #include "SubkeyGenerateDialog.h" +#include <cassert> + #include "core/function/GlobalSettingStation.h" #include "core/function/gpg/GpgKeyGetter.h" #include "core/function/gpg/GpgKeyOpera.h" @@ -120,10 +122,10 @@ QGroupBox* SubkeyGenerateDialog::create_basic_info_group_box() { key_size_spin_box_ = new QSpinBox(this); key_type_combo_box_ = new QComboBox(this); - for (auto& algo : GenKeyInfo::GetSupportedKeyAlgo()) { - key_type_combo_box_->addItem(QString::fromStdString(algo)); + for (auto& algo : GenKeyInfo::GetSupportedSubkeyAlgo()) { + key_type_combo_box_->addItem(QString::fromStdString(algo.first)); } - if (!GenKeyInfo::GetSupportedKeyAlgo().empty()) { + if (!GenKeyInfo::GetSupportedSubkeyAlgo().empty()) { key_type_combo_box_->setCurrentIndex(0); } @@ -188,7 +190,7 @@ void SubkeyGenerateDialog::slot_expire_box_changed() { } void SubkeyGenerateDialog::refresh_widgets_state() { - qDebug() << "refresh_widgets_state called"; + LOG(INFO) << "refresh_widgets_state called"; if (gen_key_info_->IsAllowEncryption()) key_usage_check_boxes_[0]->setCheckState(Qt::CheckState::Checked); @@ -266,13 +268,13 @@ void SubkeyGenerateDialog::slot_key_gen_accept() { }); thread->start(); - auto* dialog = new WaitingDialog(_("Generating"), this); - dialog->show(); + auto* waiting_dialog = new WaitingDialog(_("Generating"), this); + waiting_dialog->show(); while (thread->isRunning()) { QCoreApplication::processEvents(); } - dialog->close(); + waiting_dialog->close(); if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR) { auto* msg_box = new QMessageBox((QWidget*)this->parent()); @@ -285,8 +287,9 @@ void SubkeyGenerateDialog::slot_key_gen_accept() { emit SignalSubKeyGenerated(); this->close(); - } else + } else { QMessageBox::critical(this, _("Failure"), _("Failed to generate key.")); + } } else { /** @@ -336,8 +339,10 @@ void SubkeyGenerateDialog::slot_authentication_box_changed(int state) { void SubkeyGenerateDialog::slot_activated_key_type(int index) { qDebug() << "key type index changed " << index; - gen_key_info_->SetAlgo( - this->key_type_combo_box_->itemText(index).toStdString()); + + // check + assert(gen_key_info_->GetSupportedSubkeyAlgo().size() > index); + gen_key_info_->SetAlgo(gen_key_info_->GetSupportedSubkeyAlgo()[index]); refresh_widgets_state(); } diff --git a/src/ui/dialog/keypair_details/KeyDetailsDialog.cpp b/src/ui/dialog/keypair_details/KeyDetailsDialog.cpp index 9c2f8003..ed578aa7 100644 --- a/src/ui/dialog/keypair_details/KeyDetailsDialog.cpp +++ b/src/ui/dialog/keypair_details/KeyDetailsDialog.cpp @@ -55,8 +55,12 @@ KeyDetailsDialog::KeyDetailsDialog(const GpgKey& key, QWidget* parent) this->setLayout(mainLayout); this->setWindowTitle(_("Key Details")); this->setModal(true); - this->setMinimumSize({520, 600}); - this->resize(this->minimumSize()); + + // this->setMinimumSize({520, 600}); + + // move to center of the parent + this->movePosition2CenterOfParent(); + this->show(); } } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp b/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp index 4a6e4b52..b4d2d688 100644 --- a/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp +++ b/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp @@ -28,6 +28,7 @@ #include "core/function/gpg/GpgKeyGetter.h" #include "core/function/gpg/GpgKeyImportExporter.h" +#include "core/model/GpgKey.h" #include "dialog/WaitingDialog.h" #include "ui/SignalStation.h" @@ -268,8 +269,12 @@ void KeyPairDetailTab::slot_refresh_key_info() { } void KeyPairDetailTab::slot_refresh_key() { - LOG(INFO) << _("Called"); - this->key_ = GpgKeyGetter::GetInstance().GetKey(key_.GetId()); + LOG(INFO) << _("called"); + + // refresh the key + GpgKey refreshed_key = GpgKeyGetter::GetInstance().GetKey(key_.GetId()); + std::swap(this->key_, refreshed_key); + this->slot_refresh_key_info(); } diff --git a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp index fe1d0798..be67e5ca 100644 --- a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp +++ b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp @@ -165,7 +165,7 @@ void KeyPairSubkeyTab::create_subkey_list() { } void KeyPairSubkeyTab::slot_refresh_subkey_list() { - LOG(INFO) << "Called"; + LOG(INFO) << "called"; int row = 0; subkey_list_->setSelectionMode(QAbstractItemView::SingleSelection); @@ -177,6 +177,10 @@ void KeyPairSubkeyTab::slot_refresh_subkey_list() { this->buffered_subkeys_.push_back(std::move(sub_key)); } + LOG(INFO) << "buffered_subkeys_" + << "refreshed" + << "size" << this->buffered_subkeys_.size(); + subkey_list_->setRowCount(buffered_subkeys_.size()); for (const auto& subkeys : buffered_subkeys_) { @@ -212,12 +216,20 @@ void KeyPairSubkeyTab::slot_refresh_subkey_list() { } } + LOG(INFO) << "subkey_list_ item" << row << "refreshed"; + row++; } + LOG(INFO) << "subkey_list_" + << "refreshed"; + if (subkey_list_->rowCount() > 0) { subkey_list_->selectRow(0); } + + LOG(INFO) << "slot_refresh_subkey_list" + << "ended"; } void KeyPairSubkeyTab::slot_add_subkey() { @@ -332,6 +344,7 @@ const GpgSubKey& KeyPairSubkeyTab::get_selected_subkey() { return buffered_subkeys_[row]; } void KeyPairSubkeyTab::slot_refresh_key_info() { + LOG(INFO) << "called"; key_ = GpgKeyGetter::GetInstance().GetKey(key_.GetId()); } diff --git a/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp index b923dbec..caa4e3be 100644 --- a/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp +++ b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp @@ -574,7 +574,12 @@ void KeyPairUIDTab::slot_del_sign() { } } void KeyPairUIDTab::slot_refresh_key() { - this->m_key_ = GpgKeyGetter::GetInstance().GetKey(this->m_key_.GetId()); + LOG(INFO) << "called"; + + // refresh the key + GpgKey refreshed_key = GpgKeyGetter::GetInstance().GetKey(m_key_.GetId()); + std::swap(this->m_key_, refreshed_key); + this->slot_refresh_uid_list(); this->slot_refresh_tofu_info(); this->slot_refresh_sig_list(); diff --git a/src/ui/dialog/settings/SettingsAppearance.cpp b/src/ui/dialog/settings/SettingsAppearance.cpp index 17471a0d..b5fbc6a3 100644 --- a/src/ui/dialog/settings/SettingsAppearance.cpp +++ b/src/ui/dialog/settings/SettingsAppearance.cpp @@ -30,89 +30,48 @@ #include "core/function/GlobalSettingStation.h" #include "ui/struct/SettingsObject.h" +#include "ui_AppearanceSettings.h" namespace GpgFrontend::UI { -AppearanceTab::AppearanceTab(QWidget* parent) : QWidget(parent) { - /***************************************** - * Icon-Size-Box - *****************************************/ - auto* iconSizeBox = new QGroupBox(_("Icon Size")); - icon_size_group_ = new QButtonGroup(); - icon_size_small_ = new QRadioButton(_("small")); - icon_size_medium_ = new QRadioButton(_("medium")); - icon_size_large_ = new QRadioButton(_("large")); - - icon_size_group_->addButton(icon_size_small_, 1); - icon_size_group_->addButton(icon_size_medium_, 2); - icon_size_group_->addButton(icon_size_large_, 3); - - auto* iconSizeBoxLayout = new QHBoxLayout(); - iconSizeBoxLayout->addWidget(icon_size_small_); - iconSizeBoxLayout->addWidget(icon_size_medium_); - iconSizeBoxLayout->addWidget(icon_size_large_); - - iconSizeBox->setLayout(iconSizeBoxLayout); - - /***************************************** - * Icon-Style-Box - *****************************************/ - auto* iconStyleBox = new QGroupBox(_("Icon Style")); - icon_style_group_ = new QButtonGroup(); - icon_text_button_ = new QRadioButton(_("just text")); - icon_icons_button_ = new QRadioButton(_("just icons")); - icon_all_button_ = new QRadioButton(_("text and icons")); - - icon_style_group_->addButton(icon_text_button_, 1); - icon_style_group_->addButton(icon_icons_button_, 2); - icon_style_group_->addButton(icon_all_button_, 3); - - auto* iconStyleBoxLayout = new QHBoxLayout(); - iconStyleBoxLayout->addWidget(icon_text_button_); - iconStyleBoxLayout->addWidget(icon_icons_button_); - iconStyleBoxLayout->addWidget(icon_all_button_); - - iconStyleBox->setLayout(iconStyleBoxLayout); - - /***************************************** - * Window-Size-Box - *****************************************/ - auto* windowSizeBox = new QGroupBox(_("Window State")); - auto* windowSizeBoxLayout = new QHBoxLayout(); - window_size_check_box_ = - new QCheckBox(_("Save window size and position on exit."), this); - windowSizeBoxLayout->addWidget(window_size_check_box_); - windowSizeBox->setLayout(windowSizeBoxLayout); - - /***************************************** - * Info-Board-Font-Size-Box - *****************************************/ - - auto* infoBoardBox = new QGroupBox(_("Information Board")); - auto* infoBoardLayout = new QHBoxLayout(); - info_board_font_size_spin_ = new QSpinBox(); - info_board_font_size_spin_->setRange(9, 18); - info_board_font_size_spin_->setValue(10); - info_board_font_size_spin_->setSingleStep(1); - infoBoardLayout->addWidget(new QLabel(_("Font Size in Information Board"))); - infoBoardLayout->addWidget(info_board_font_size_spin_); - infoBoardBox->setLayout(infoBoardLayout); - - auto* mainLayout = new QVBoxLayout; - mainLayout->addWidget(iconSizeBox); - mainLayout->addWidget(iconStyleBox); - mainLayout->addWidget(windowSizeBox); - mainLayout->addWidget(infoBoardBox); - mainLayout->addStretch(1); +AppearanceTab::AppearanceTab(QWidget* parent) + : QWidget(parent), ui_(std::make_shared<Ui_AppearanceSettings>()) { + ui_->setupUi(this); + + ui_->iconSizeBox->setTitle(_("Icon Size")); + ui_->smallRadioButton->setText(_("small")); + ui_->mediumRadioButton->setText(_("medium")); + ui_->largeRadioButton->setText(_("large")); + + ui_->iconStyleBox->setTitle(_("Icon Style")); + ui_->justTextRadioButton->setText(_("just text")); + ui_->justIconRadioButton->setText(_("just icons")); + ui_->textAndIconsRadioButton->setText(_("text and icons")); + + ui_->windowStateBox->setTitle(_("Window State")); + ui_->windowStateCheckBox->setText( + _("Save window size and position on exit.")); + + ui_->textEditorBox->setTitle(_("Text Editor")); + ui_->fontSizeTextEditorLabel->setText(_("Font Size in Text Editor")); + + ui_->informationBoardBox->setTitle(_("Information Board")); + ui_->fontSizeInformationBoardLabel->setText( + _("Font Size in Information Board")); + + icon_size_group_ = new QButtonGroup(this); + icon_size_group_->addButton(ui_->smallRadioButton, 1); + icon_size_group_->addButton(ui_->mediumRadioButton, 2); + icon_size_group_->addButton(ui_->largeRadioButton, 3); + + icon_style_group_ = new QButtonGroup(this); + icon_style_group_->addButton(ui_->justTextRadioButton, 1); + icon_style_group_->addButton(ui_->justIconRadioButton, 2); + icon_style_group_->addButton(ui_->textAndIconsRadioButton, 3); + SetSettings(); - setLayout(mainLayout); } -/********************************** - * Read the settings from config - * and set the buttons and checkboxes - * appropriately - **********************************/ void AppearanceTab::SetSettings() { SettingsObject general_settings_state("general_settings_state"); @@ -123,13 +82,13 @@ void AppearanceTab::SetSettings() { switch (icon_size.width()) { case 12: - icon_size_small_->setChecked(true); + ui_->smallRadioButton->setChecked(true); break; case 24: - icon_size_medium_->setChecked(true); + ui_->mediumRadioButton->setChecked(true); break; case 32: - icon_size_large_->setChecked(true); + ui_->largeRadioButton->setChecked(true); break; } @@ -140,32 +99,35 @@ void AppearanceTab::SetSettings() { switch (icon_style) { case Qt::ToolButtonTextOnly: - icon_text_button_->setChecked(true); + ui_->justTextRadioButton->setChecked(true); break; case Qt::ToolButtonIconOnly: - icon_icons_button_->setChecked(true); + ui_->justIconRadioButton->setChecked(true); break; case Qt::ToolButtonTextUnderIcon: - icon_all_button_->setChecked(true); + ui_->textAndIconsRadioButton->setChecked(true); break; default: break; } bool window_save = general_settings_state.Check("window_save", true); - if (window_save) window_size_check_box_->setCheckState(Qt::Checked); - - auto info_font_size = general_settings_state.Check("font_size", 10); - if (info_font_size < 9 || info_font_size > 18) info_font_size = 10; - info_board_font_size_spin_->setValue(info_font_size); + if (window_save) ui_->windowStateCheckBox->setCheckState(Qt::Checked); + + auto info_board_info_font_size = + general_settings_state.Check("info_board").Check("font_size", 10); + if (info_board_info_font_size < 9 || info_board_info_font_size > 18) + info_board_info_font_size = 10; + ui_->fontSizeInformationBoardSpinBox->setValue(info_board_info_font_size); + + auto text_editor_info_font_size = + general_settings_state.Check("text_editor").Check("font_size", 10); + if (text_editor_info_font_size < 9 || text_editor_info_font_size > 18) + text_editor_info_font_size = 10; + ui_->fontSizeTextEditorLabelSpinBox->setValue(text_editor_info_font_size); } -/*********************************** - * get the values of the buttons and - * write them to settings-file - *************************************/ void AppearanceTab::ApplySettings() { - SettingsObject general_settings_state("general_settings_state"); int icon_size = 24; @@ -199,9 +161,13 @@ void AppearanceTab::ApplySettings() { general_settings_state["icon_style"] = icon_style; - general_settings_state["window_save"] = window_size_check_box_->isChecked(); + general_settings_state["window_save"] = ui_->windowStateCheckBox->isChecked(); + + general_settings_state["info_board"]["font_size"] = + ui_->fontSizeInformationBoardSpinBox->value(); - general_settings_state["info_font_size"] = info_board_font_size_spin_->value(); + general_settings_state["text_editor"]["font_size"] = + ui_->fontSizeTextEditorLabelSpinBox->value(); } } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/settings/SettingsAppearance.h b/src/ui/dialog/settings/SettingsAppearance.h index 7110d992..8a38c666 100644 --- a/src/ui/dialog/settings/SettingsAppearance.h +++ b/src/ui/dialog/settings/SettingsAppearance.h @@ -31,6 +31,8 @@ #include "ui/GpgFrontendUI.h" +class Ui_AppearanceSettings; + namespace GpgFrontend::UI { class AppearanceTab : public QWidget { @@ -57,16 +59,10 @@ class AppearanceTab : public QWidget { void ApplySettings(); private: + std::shared_ptr<Ui_AppearanceSettings> ui_; ///< + QButtonGroup* icon_style_group_; ///< - QRadioButton* icon_size_small_; ///< - QRadioButton* icon_size_medium_; ///< - QRadioButton* icon_size_large_; ///< - QButtonGroup* icon_size_group_; ///< - QRadioButton* icon_text_button_; ///< - QRadioButton* icon_icons_button_; ///< - QRadioButton* icon_all_button_; ///< - QSpinBox* info_board_font_size_spin_; ///< - QCheckBox* window_size_check_box_; ///< + QButtonGroup* icon_size_group_; signals: diff --git a/src/ui/dialog/settings/SettingsDialog.cpp b/src/ui/dialog/settings/SettingsDialog.cpp index e2677a0f..6737a512 100644 --- a/src/ui/dialog/settings/SettingsDialog.cpp +++ b/src/ui/dialog/settings/SettingsDialog.cpp @@ -33,6 +33,7 @@ #include "SettingsGeneral.h" #include "SettingsKeyServer.h" #include "SettingsNetwork.h" +#include "core/GpgConstants.h" #include "core/function/GlobalSettingStation.h" #include "ui/main_window/MainWindow.h" @@ -74,9 +75,24 @@ SettingsDialog::SettingsDialog(QWidget* parent) setLayout(mainLayout); // slots for handling the restart needed member - this->slot_set_restart_needed(false); + this->slot_set_restart_needed(0); + + // restart ui connect(general_tab_, &GeneralTab::SignalRestartNeeded, this, - &SettingsDialog::slot_set_restart_needed); + [=](bool needed) { + if (needed && restart_needed_ < RESTART_CODE) { + this->restart_needed_ = RESTART_CODE; + } + }); + + // restart core and ui + connect(general_tab_, &GeneralTab::SignalDeepRestartNeeded, this, + [=](bool needed) { + if (needed && restart_needed_ < DEEP_RESTART_CODE) + this->restart_needed_ = DEEP_RESTART_CODE; + }); + + // announce main window connect(this, &SettingsDialog::SignalRestartNeeded, qobject_cast<MainWindow*>(parent), &MainWindow::SlotSetRestartNeeded); @@ -85,12 +101,10 @@ SettingsDialog::SettingsDialog(QWidget* parent) this->show(); } -bool SettingsDialog::get_restart_needed() const { - return this->restart_needed_; -} +int SettingsDialog::get_restart_needed() const { return this->restart_needed_; } -void SettingsDialog::slot_set_restart_needed(bool needed) { - this->restart_needed_ = needed; +void SettingsDialog::slot_set_restart_needed(int mode) { + this->restart_needed_ = mode; } void SettingsDialog::SlotAccept() { @@ -108,7 +122,7 @@ void SettingsDialog::SlotAccept() { LOG(INFO) << "restart needed" << get_restart_needed(); if (get_restart_needed()) { - emit SignalRestartNeeded(true); + emit SignalRestartNeeded(get_restart_needed()); } close(); } diff --git a/src/ui/dialog/settings/SettingsDialog.h b/src/ui/dialog/settings/SettingsDialog.h index 172370d0..d28013f4 100644 --- a/src/ui/dialog/settings/SettingsDialog.h +++ b/src/ui/dialog/settings/SettingsDialog.h @@ -82,12 +82,12 @@ class SettingsDialog : public GeneralDialog { * * @param needed */ - void SignalRestartNeeded(bool needed); + void SignalRestartNeeded(int); private: QTabWidget* tab_widget_; ///< QDialogButtonBox* button_box_; ///< - bool restart_needed_{}; ///< + int restart_needed_{0}; ///< /** * @brief Get the Restart Needed object @@ -95,7 +95,7 @@ class SettingsDialog : public GeneralDialog { * @return true * @return false */ - bool get_restart_needed() const; + int get_restart_needed() const; private slots: @@ -104,7 +104,7 @@ class SettingsDialog : public GeneralDialog { * * @param needed */ - void slot_set_restart_needed(bool needed); + void slot_set_restart_needed(int); }; } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/settings/SettingsGeneral.cpp b/src/ui/dialog/settings/SettingsGeneral.cpp index 3c7bca32..680ed014 100644 --- a/src/ui/dialog/settings/SettingsGeneral.cpp +++ b/src/ui/dialog/settings/SettingsGeneral.cpp @@ -28,6 +28,8 @@ #include "SettingsGeneral.h" +#include "core/GpgContext.h" + #ifdef MULTI_LANG_SUPPORT #include "SettingsDialog.h" #endif @@ -70,6 +72,51 @@ GeneralTab::GeneralTab(QWidget* parent) this, &GeneralTab::slot_language_changed); #endif + connect(ui_->keyDatabseUseCustomCheckBox, &QCheckBox::stateChanged, this, + [=](int state) { + ui_->customKeyDatabasePathSelectButton->setDisabled( + state != Qt::CheckState::Checked); + // announce the restart + this->slot_key_databse_path_changed(); + }); + + connect(ui_->keyDatabseUseCustomCheckBox, &QCheckBox::stateChanged, this, + &GeneralTab::slot_update_custom_key_database_path_label); + + connect( + ui_->customKeyDatabasePathSelectButton, &QPushButton::clicked, this, + [=]() { + QString selected_custom_key_database_path = + QFileDialog::getExistingDirectory( + this, _("Open Directory"), {}, + QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + + LOG(INFO) << "key databse path selected" + << selected_custom_key_database_path.toStdString(); + + if (!selected_custom_key_database_path.isEmpty()) { + auto& settings = GlobalSettingStation::GetInstance().GetUISettings(); + auto& general = settings["general"]; + + // update settings + if (!general.exists("custom_key_database_path")) + general.add("custom_key_database_path", + libconfig::Setting::TypeString) = + selected_custom_key_database_path.toStdString(); + else { + general["custom_key_database_path"] = + selected_custom_key_database_path.toStdString(); + } + + // announce the restart + this->slot_key_databse_path_changed(); + + // update ui + this->slot_update_custom_key_database_path_label( + this->ui_->keyDatabseUseCustomCheckBox->checkState()); + } + }); + SetSettings(); } @@ -132,6 +179,19 @@ void GeneralTab::SetSettings() { } catch (...) { LOG(ERROR) << _("Setting Operation Error") << _("non_ascii_when_export"); } + + try { + bool use_custom_key_database_path = + settings.lookup("general.use_custom_key_database_path"); + if (use_custom_key_database_path) + ui_->keyDatabseUseCustomCheckBox->setCheckState(Qt::Checked); + } catch (...) { + LOG(ERROR) << _("Setting Operation Error") + << _("use_custom_key_database_path"); + } + + this->slot_update_custom_key_database_path_label( + ui_->keyDatabseUseCustomCheckBox->checkState()); } /*********************************** @@ -187,10 +247,60 @@ void GeneralTab::ApplySettings() { general["confirm_import_keys"] = ui_->importConfirmationCheckBox->isChecked(); } + + if (!general.exists("use_custom_key_database_path")) + general.add("use_custom_key_database_path", + libconfig::Setting::TypeBoolean) = + ui_->keyDatabseUseCustomCheckBox->isChecked(); + else { + general["use_custom_key_database_path"] = + ui_->keyDatabseUseCustomCheckBox->isChecked(); + } } #ifdef MULTI_LANG_SUPPORT void GeneralTab::slot_language_changed() { emit SignalRestartNeeded(true); } #endif +void GeneralTab::slot_update_custom_key_database_path_label(int state) { + if (state != Qt::CheckState::Checked) { + ui_->currentKeyDatabasePathLabel->setText(QString::fromStdString( + GpgContext::GetInstance().GetInfo().DatabasePath)); + + // hide label (not necessary to show the default path) + this->ui_->currentKeyDatabasePathLabel->setHidden(true); + } else { + // read from settings file + std::string custom_key_database_path; + try { + auto& settings = + GpgFrontend::GlobalSettingStation::GetInstance().GetUISettings(); + custom_key_database_path = static_cast<std::string>( + settings.lookup("general.custom_key_database_path")); + + } catch (...) { + LOG(ERROR) << _("Setting Operation Error") + << _("custom_key_database_path"); + } + + LOG(INFO) << "selected_custom_key_database_path from settings" + << custom_key_database_path; + + // set label value + if (!custom_key_database_path.empty()) { + ui_->currentKeyDatabasePathLabel->setText( + QString::fromStdString(custom_key_database_path)); + } else { + ui_->currentKeyDatabasePathLabel->setText( + _("None custom key database path.")); + } + + this->ui_->currentKeyDatabasePathLabel->setHidden(false); + } +} + +void GeneralTab::slot_key_databse_path_changed() { + emit SignalDeepRestartNeeded(true); +} + } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/settings/SettingsGeneral.h b/src/ui/dialog/settings/SettingsGeneral.h index b3e7d904..4543df7d 100644 --- a/src/ui/dialog/settings/SettingsGeneral.h +++ b/src/ui/dialog/settings/SettingsGeneral.h @@ -72,6 +72,13 @@ class GeneralTab : public QWidget { */ void SignalRestartNeeded(bool needed); + /** + * @brief + * + * @param needed + */ + void SignalDeepRestartNeeded(bool needed); + private: std::shared_ptr<Ui_GeneralSettings> ui_; ///< @@ -92,6 +99,18 @@ class GeneralTab : public QWidget { */ void slot_language_changed(); + /** + * @brief + * + */ + void slot_update_custom_key_database_path_label(int state); + + /** + * @brief + * + */ + void slot_key_databse_path_changed(); + #endif }; } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/settings/SettingsKeyServer.cpp b/src/ui/dialog/settings/SettingsKeyServer.cpp index 2c09b66c..365e19d4 100644 --- a/src/ui/dialog/settings/SettingsKeyServer.cpp +++ b/src/ui/dialog/settings/SettingsKeyServer.cpp @@ -114,11 +114,6 @@ KeyserverTab::KeyserverTab(QWidget* parent) slot_refresh_table(); } -/********************************** - * Read the settings from config - * and set the buttons and checkboxes - * appropriately - **********************************/ void KeyserverTab::SetSettings() { try { SettingsObject key_server_json("key_server"); diff --git a/src/ui/main_window/GeneralMainWindow.cpp b/src/ui/main_window/GeneralMainWindow.cpp index 7df73aba..fb42d71a 100644 --- a/src/ui/main_window/GeneralMainWindow.cpp +++ b/src/ui/main_window/GeneralMainWindow.cpp @@ -33,14 +33,14 @@ #include "ui/struct/SettingsObject.h" GpgFrontend::UI::GeneralMainWindow::GeneralMainWindow(std::string name, - QWidget* parent) + QWidget *parent) : name_(std::move(name)), QMainWindow(parent) { slot_restore_settings(); } GpgFrontend::UI::GeneralMainWindow::~GeneralMainWindow() = default; -void GpgFrontend::UI::GeneralMainWindow::closeEvent(QCloseEvent* event) { +void GpgFrontend::UI::GeneralMainWindow::closeEvent(QCloseEvent *event) { slot_save_settings(); QMainWindow::closeEvent(event); } @@ -65,7 +65,6 @@ void GpgFrontend::UI::GeneralMainWindow::slot_restore_settings() noexcept { int x = general_windows_state.Check("window_pos").Check("x", 100), y = general_windows_state.Check("window_pos").Check("y", 100); - this->move({x, y}); pos_ = {x, y}; int width = @@ -73,10 +72,44 @@ void GpgFrontend::UI::GeneralMainWindow::slot_restore_settings() noexcept { height = general_windows_state.Check("window_size").Check("height", 450); - this->resize({width, height}); size_ = {width, height}; - } + if (this->parent() != nullptr) { + LOG(INFO) << "parent address" << this->parent(); + + QPoint parent_pos = {0, 0}; + QSize parent_size = {0, 0}; + + auto *parent_dialog = qobject_cast<QDialog *>(this->parent()); + if (parent_dialog != nullptr) { + parent_pos = parent_dialog->pos(); + parent_size = parent_dialog->size(); + } + + auto *parent_window = qobject_cast<QMainWindow *>(this->parent()); + if (parent_window != nullptr) { + parent_pos = parent_window->pos(); + parent_size = parent_window->size(); + } + + LOG(INFO) << "parent pos x:" << parent_pos.x() + << "y:" << parent_pos.y(); + + LOG(INFO) << "parent size width:" << parent_size.width() + << "height:" << parent_size.height(); + + if (parent_pos != QPoint{0, 0}) { + QPoint parent_center{parent_pos.x() + parent_size.width() / 2, + parent_pos.y() + parent_size.height() / 2}; + + pos_ = {parent_center.x() - size_.width() / 2, + parent_center.y() - size_.height() / 2}; + } + } + + this->move(pos_); + this->resize(size_); + } // appearance SettingsObject general_settings_state("general_settings_state"); @@ -113,6 +146,9 @@ void GpgFrontend::UI::GeneralMainWindow::slot_save_settings() noexcept { general_windows_state["window_pos"]["x"] = pos().x(); general_windows_state["window_pos"]["y"] = pos().y(); + // update size of current dialog + size_ = this->size(); + general_windows_state["window_size"]["width"] = size_.width(); general_windows_state["window_size"]["height"] = size_.height(); general_windows_state["window_save"] = true; diff --git a/src/ui/main_window/GeneralMainWindow.h b/src/ui/main_window/GeneralMainWindow.h index 71327100..8995883a 100644 --- a/src/ui/main_window/GeneralMainWindow.h +++ b/src/ui/main_window/GeneralMainWindow.h @@ -54,7 +54,7 @@ class GeneralMainWindow : public QMainWindow { * * @param event */ - void closeEvent(QCloseEvent* event); + void closeEvent(QCloseEvent* event) override; QSize icon_size_{}; ///< int font_size_{}; ///< diff --git a/src/ui/main_window/KeyMgmt.cpp b/src/ui/main_window/KeyMgmt.cpp index 6dc2b14f..9df2b918 100644 --- a/src/ui/main_window/KeyMgmt.cpp +++ b/src/ui/main_window/KeyMgmt.cpp @@ -109,6 +109,7 @@ KeyMgmt::KeyMgmt(QWidget* parent) this->statusBar()->show(); setWindowTitle(_("KeyPair Management")); + key_list_->AddMenuAction(generate_subkey_act_); key_list_->AddMenuAction(delete_selected_keys_act_); key_list_->AddMenuAction(show_key_details_act_); diff --git a/src/ui/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp index e3e4c0ab..b0273d86 100644 --- a/src/ui/main_window/MainWindow.cpp +++ b/src/ui/main_window/MainWindow.cpp @@ -62,12 +62,18 @@ void MainWindow::Init() noexcept { /* Variable containing if restart is needed */ this->SlotSetRestartNeeded(false); + // init menu bar + this->setMenuBar(new QMenuBar()); + create_actions(); create_menus(); create_tool_bars(); create_status_bar(); create_dock_windows(); + // show menu bar + this->menuBar()->show(); + connect(edit_->tab_widget_, &QTabWidget::currentChanged, this, &MainWindow::slot_disable_tab_actions); connect(SignalStation::GetInstance(), diff --git a/src/ui/main_window/MainWindow.h b/src/ui/main_window/MainWindow.h index b31e2fcb..2e24cecd 100644 --- a/src/ui/main_window/MainWindow.h +++ b/src/ui/main_window/MainWindow.h @@ -148,7 +148,7 @@ class MainWindow : public GeneralMainWindow { * @details get value of member restartNeeded to needed. * @param needed true, if application has to be restarted */ - void SlotSetRestartNeeded(bool needed); + void SlotSetRestartNeeded(int); private slots: @@ -322,7 +322,7 @@ class MainWindow : public GeneralMainWindow { /** * @brief return true, if restart is needed */ - [[nodiscard]] bool get_restart_needed() const; + [[nodiscard]] int get_restart_needed() const; TextEdit* edit_{}; ///< Tabwidget holding the edit-windows QMenu* file_menu_{}; ///< Submenu for file-operations @@ -387,7 +387,7 @@ class MainWindow : public GeneralMainWindow { QAction* about_act_{}; ///< Action to open about dialog QAction* check_update_act_{}; ///< Action to open about dialog QAction* translate_act_{}; ///< Action to open about dialog - QAction* gnupg_act_{}; ///< Action to open about dialog + QAction* gnupg_act_{}; ///< Action to open about dialog QAction* open_settings_act_{}; ///< Action to open settings dialog QAction* show_key_details_act_{}; ///< Action to open key-details dialog QAction* start_wizard_act_{}; ///< Action to open the wizard @@ -403,7 +403,7 @@ class MainWindow : public GeneralMainWindow { InfoBoardWidget* info_board_{}; ///< bool attachment_dock_created_{}; ///< - bool restart_needed_{}; ///< + int restart_needed_{0}; ///< bool prohibit_update_checking_ = false; ///< }; diff --git a/src/ui/main_window/MainWindowSlotUI.cpp b/src/ui/main_window/MainWindowSlotUI.cpp index 9061349e..8961a33f 100644 --- a/src/ui/main_window/MainWindowSlotUI.cpp +++ b/src/ui/main_window/MainWindowSlotUI.cpp @@ -27,6 +27,7 @@ */ #include "MainWindow.h" +#include "core/GpgConstants.h" #include "core/function/GlobalSettingStation.h" #include "ui/UserInterfaceUtils.h" #include "ui/struct/SettingsObject.h" @@ -128,7 +129,7 @@ void MainWindow::slot_open_settings_dialog() { if (get_restart_needed()) { if (edit_->MaybeSaveAnyTab()) { save_settings(); - qApp->exit(RESTART_CODE); + qApp->exit(get_restart_needed()); } } }); @@ -182,11 +183,12 @@ void MainWindow::slot_cut_pgp_header() { edit_->SlotFillTextEditWithText(content.trimmed()); } -void MainWindow::SlotSetRestartNeeded(bool needed) { - this->restart_needed_ = needed; +void MainWindow::SlotSetRestartNeeded(int mode) { + LOG(INFO) << "restart mode" << mode; + this->restart_needed_ = mode; } -bool MainWindow::get_restart_needed() const { return this->restart_needed_; } +int MainWindow::get_restart_needed() const { return this->restart_needed_; } void MainWindow::SetCryptoMenuStatus( MainWindow::CryptoMenu::OperationType type) { diff --git a/src/ui/widgets/InfoBoardWidget.cpp b/src/ui/widgets/InfoBoardWidget.cpp index 264a67d1..74ead2ce 100644 --- a/src/ui/widgets/InfoBoardWidget.cpp +++ b/src/ui/widgets/InfoBoardWidget.cpp @@ -79,11 +79,13 @@ void InfoBoardWidget::SetInfoBoard(const QString& text, status.setColor(QPalette::Text, color); ui_->infoBoard->setPalette(status); - SettingsObject main_windows_state("main_windows_state"); + SettingsObject general_settings_state("general_settings_state"); // info board font size - auto info_font_size = main_windows_state.Check("info_font_size", 10); + auto info_font_size = + general_settings_state.Check("text_editor").Check("font_size", 10); ui_->infoBoard->setFont(QFont("Times", info_font_size)); + } void InfoBoardWidget::SlotRefresh(const QString& text, InfoBoardStatus status) { diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp index 0bd65f25..9150d580 100644 --- a/src/ui/widgets/KeyList.cpp +++ b/src/ui/widgets/KeyList.cpp @@ -158,7 +158,7 @@ void KeyList::AddListGroupTab( } void KeyList::SlotRefresh() { - LOG(INFO) << _("Called") << "address" << this; + LOG(INFO) << _("called") << "address" << this; ui_->refreshKeyListButton->setDisabled(true); ui_->syncButton->setDisabled(true); @@ -442,6 +442,8 @@ void KeyList::slot_sync_with_key_server() { } } + if (key_ids.empty()) return; + ui_->refreshKeyListButton->setDisabled(true); ui_->syncButton->setDisabled(true); @@ -496,7 +498,6 @@ void KeyList::check_all() { } KeyIdArgsListPtr& KeyTable::GetChecked() { - LOG(INFO) << "called"; if (checked_key_ids_ == nullptr) checked_key_ids_ = std::make_unique<KeyIdArgsList>(); auto& ret = checked_key_ids_; @@ -517,8 +518,6 @@ void KeyTable::SetChecked(KeyIdArgsListPtr key_ids) { } void KeyTable::Refresh(KeyLinkListPtr m_keys) { - LOG(INFO) << "called"; - auto& checked_key_list = GetChecked(); // while filling the table, sort enabled causes errors @@ -532,7 +531,6 @@ void KeyTable::Refresh(KeyLinkListPtr m_keys) { else keys = std::move(m_keys); - LOG(INFO) << "keys size: " << keys->size(); auto it = keys->begin(); int row_count = 0; @@ -553,7 +551,6 @@ void KeyTable::Refresh(KeyLinkListPtr m_keys) { it++; } - LOG(INFO) << "row_count: " << row_count; key_list_->setRowCount(row_count); int row_index = 0; @@ -645,8 +642,6 @@ void KeyTable::Refresh(KeyLinkListPtr m_keys) { } } } - - LOG(INFO) << "End"; } void KeyTable::UncheckALL() const { diff --git a/src/ui/widgets/PlainTextEditorPage.cpp b/src/ui/widgets/PlainTextEditorPage.cpp index 7eb682cc..10e19b8b 100644 --- a/src/ui/widgets/PlainTextEditorPage.cpp +++ b/src/ui/widgets/PlainTextEditorPage.cpp @@ -34,6 +34,7 @@ #include "core/thread/FileReadTask.h" #include "core/thread/Task.h" #include "core/thread/TaskRunnerGetter.h" +#include "ui/struct/SettingsObject.h" #include "ui_PlainTextEditor.h" namespace GpgFrontend::UI { @@ -48,7 +49,13 @@ PlainTextEditorPage::PlainTextEditorPage(QString file_path, QWidget *parent) ui_->loadingLabel->setHidden(true); // Front in same width - this->setFont({"Courier"}); + SettingsObject general_settings_state("general_settings_state"); + + // font size + auto editor_font_size = + general_settings_state.Check("text_editor").Check("font_size", 10); + ui_->textPage->setFont(QFont("Courier", editor_font_size)); + this->setAttribute(Qt::WA_DeleteOnClose); this->ui_->characterLabel->setText(_("0 character")); diff --git a/src/ui/widgets/PlainTextEditorPage.h b/src/ui/widgets/PlainTextEditorPage.h index e5c1c89d..ffa31762 100644 --- a/src/ui/widgets/PlainTextEditorPage.h +++ b/src/ui/widgets/PlainTextEditorPage.h @@ -129,7 +129,7 @@ class PlainTextEditorPage : public QWidget { size_t read_bytes_ = 0; ///< std::string charset_name_; ///< std::string language_name_; ///< - int32_t charset_confidence_; ///< + int32_t charset_confidence_{}; ///< bool is_crlf_ = false; ///< /** |