aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/core/function/gpg/GpgKeyGetter.cpp8
-rw-r--r--src/core/function/gpg/GpgKeyOpera.cpp3
-rw-r--r--src/core/model/GpgKey.cpp24
-rw-r--r--src/core/model/GpgKey.h9
-rw-r--r--src/pinentry/pinentrydialog.cpp27
-rw-r--r--src/ui/UserInterfaceUtils.cpp2
-rw-r--r--src/ui/dialog/WaitingDialog.cpp5
-rw-r--r--src/ui/function/GenerateRevokeCertification.cpp1
-rw-r--r--src/ui/function/RaisePinentry.cpp15
-rw-r--r--src/ui/function/RaisePinentry.h10
10 files changed, 59 insertions, 45 deletions
diff --git a/src/core/function/gpg/GpgKeyGetter.cpp b/src/core/function/gpg/GpgKeyGetter.cpp
index 5215f34b..cad2d884 100644
--- a/src/core/function/gpg/GpgKeyGetter.cpp
+++ b/src/core/function/gpg/GpgKeyGetter.cpp
@@ -82,7 +82,7 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> {
auto keys_list = std::make_unique<GpgKeyLinkList>();
for (const auto& [key, value] : keys_cache_) {
- keys_list->push_back(value.Copy());
+ keys_list->push_back(value);
}
return keys_list;
}
@@ -140,7 +140,7 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> {
// get the lock
std::lock_guard<std::mutex> lock(ctx_mutex_);
auto keys_copy = std::make_unique<GpgKeyLinkList>();
- for (const auto& key : *keys) keys_copy->emplace_back(key.Copy());
+ for (const auto& key : *keys) keys_copy->emplace_back(key);
return keys_copy;
}
@@ -148,7 +148,7 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> {
// get the lock
std::lock_guard<std::mutex> lock(ctx_mutex_);
auto keys_copy = std::make_unique<KeyArgsList>();
- for (const auto& key : *keys) keys_copy->emplace_back(key.Copy());
+ for (const auto& key : *keys) keys_copy->emplace_back(key);
return keys_copy;
}
@@ -189,7 +189,7 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> {
if (keys_cache_.find(key_id) != keys_cache_.end()) {
std::lock_guard<std::mutex> lock(ctx_mutex_);
// return a copy of the key in cache
- return keys_cache_[key_id].Copy();
+ return keys_cache_[key_id];
}
// return a bad key
diff --git a/src/core/function/gpg/GpgKeyOpera.cpp b/src/core/function/gpg/GpgKeyOpera.cpp
index 1c4c78a5..b4aa85eb 100644
--- a/src/core/function/gpg/GpgKeyOpera.cpp
+++ b/src/core/function/gpg/GpgKeyOpera.cpp
@@ -216,8 +216,7 @@ void GpgKeyOpera::GenerateSubkey(const GpgKey& key,
const std::shared_ptr<GenKeyInfo>& params,
const GpgOperationCallback& callback) {
RunGpgOperaAsync(
- [key = key.Copy(), &ctx = ctx_,
- params](const DataObjectPtr&) -> GpgError {
+ [key, &ctx = ctx_, params](const DataObjectPtr&) -> GpgError {
if (!params->IsSubKey()) return GPG_ERR_CANCELED;
SPDLOG_DEBUG("generate subkey algo {} key size {}", params->GetAlgo(),
diff --git a/src/core/model/GpgKey.cpp b/src/core/model/GpgKey.cpp
index 8a7f5a6e..9e6df32b 100644
--- a/src/core/model/GpgKey.cpp
+++ b/src/core/model/GpgKey.cpp
@@ -41,13 +41,13 @@ auto GpgKey::operator=(GpgKey &&k) noexcept -> GpgKey & {
return *this;
}
-GpgKey::GpgKey(const GpgKey &key) noexcept {
+GpgKey::GpgKey(const GpgKey &key) {
+ auto *key_ref = key.key_ref_.get();
{
const std::lock_guard<std::mutex> guard(gpgme_key_opera_mutex_);
- gpgme_key_ref(key.key_ref_.get());
+ gpgme_key_ref(key_ref);
}
- auto *new_key_ref = key_ref_.get();
- this->key_ref_ = KeyRefHandler(std::move(new_key_ref));
+ this->key_ref_ = KeyRefHandler(key_ref);
}
auto GpgKey::operator=(const GpgKey &key) -> GpgKey & {
@@ -55,13 +55,12 @@ auto GpgKey::operator=(const GpgKey &key) -> GpgKey & {
return *this;
}
+ auto *key_ref = key.key_ref_.get();
{
const std::lock_guard<std::mutex> guard(gpgme_key_opera_mutex_);
- gpgme_key_ref(key.key_ref_.get());
+ gpgme_key_ref(key_ref);
}
- auto *new_key_ref = key_ref_.get();
- this->key_ref_ = KeyRefHandler(std::move(new_key_ref));
-
+ this->key_ref_ = KeyRefHandler(key_ref);
return *this;
}
@@ -248,15 +247,6 @@ auto GpgKey::IsHasActualEncryptionCapability() const -> bool {
});
}
-auto GpgKey::Copy() const -> GpgKey {
- {
- const std::lock_guard<std::mutex> guard(gpgme_key_opera_mutex_);
- gpgme_key_ref(key_ref_.get());
- }
- auto *new_key_ref = key_ref_.get();
- return GpgKey(std::move(new_key_ref));
-}
-
void GpgKey::KeyRefDeleter::operator()(gpgme_key_t _key) {
if (_key != nullptr) gpgme_key_unref(_key);
}
diff --git a/src/core/model/GpgKey.h b/src/core/model/GpgKey.h
index 5fc3961b..b45a2c2a 100644
--- a/src/core/model/GpgKey.h
+++ b/src/core/model/GpgKey.h
@@ -314,7 +314,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKey {
*
* @param k
*/
- GpgKey(const GpgKey&) noexcept;
+ GpgKey(const GpgKey&);
/**
* @brief
@@ -357,13 +357,6 @@ class GPGFRONTEND_CORE_EXPORT GpgKey {
*/
explicit operator gpgme_key_t() const;
- /**
- * @brief
- *
- * @return GpgKey
- */
- [[nodiscard]] auto Copy() const -> GpgKey;
-
private:
/**
* @brief
diff --git a/src/pinentry/pinentrydialog.cpp b/src/pinentry/pinentrydialog.cpp
index 366c9cf6..27d75c8b 100644
--- a/src/pinentry/pinentrydialog.cpp
+++ b/src/pinentry/pinentrydialog.cpp
@@ -107,11 +107,12 @@ PinEntryDialog::PinEntryDialog(QWidget *parent, const char *name, int timeout,
Q_UNUSED(name)
if (modal) {
+ setWindowModality(Qt::ApplicationModal);
setModal(true);
}
- QPalette redTextPalette;
- redTextPalette.setColor(QPalette::WindowText, Qt::red);
+ QPalette red_text_palette;
+ red_text_palette.setColor(QPalette::WindowText, Qt::red);
auto *const main_layout = new QVBoxLayout{this};
@@ -127,7 +128,7 @@ PinEntryDialog::PinEntryDialog(QWidget *parent, const char *name, int timeout,
_error = new QLabel{this};
_error->setTextFormat(Qt::PlainText);
_error->setTextInteractionFlags(Qt::TextSelectableByMouse);
- _error->setPalette(redTextPalette);
+ _error->setPalette(red_text_palette);
_error->hide();
grid->addWidget(_error, row, 1, 1, 2);
@@ -142,7 +143,7 @@ PinEntryDialog::PinEntryDialog(QWidget *parent, const char *name, int timeout,
mCapsLockHint = new QLabel{this};
mCapsLockHint->setTextFormat(Qt::PlainText);
mCapsLockHint->setTextInteractionFlags(Qt::TextSelectableByMouse);
- mCapsLockHint->setPalette(redTextPalette);
+ mCapsLockHint->setPalette(red_text_palette);
mCapsLockHint->setAlignment(Qt::AlignCenter);
mCapsLockHint->setVisible(false);
grid->addWidget(mCapsLockHint, row, 1, 1, 2);
@@ -210,23 +211,23 @@ PinEntryDialog::PinEntryDialog(QWidget *parent, const char *name, int timeout,
if (!repeatString.isNull()) {
row++;
- auto repeatLabel = new QLabel{this};
- repeatLabel->setTextFormat(Qt::PlainText);
- repeatLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
- repeatLabel->setText(repeatString);
- grid->addWidget(repeatLabel, row, 1);
+ auto *repeat_label = new QLabel{this};
+ repeat_label->setTextFormat(Qt::PlainText);
+ repeat_label->setTextInteractionFlags(Qt::TextSelectableByMouse);
+ repeat_label->setText(repeatString);
+ grid->addWidget(repeat_label, row, 1);
mRepeat = new PinLineEdit(this);
mRepeat->setMaxLength(256);
mRepeat->setEchoMode(QLineEdit::Password);
- repeatLabel->setBuddy(mRepeat);
+ repeat_label->setBuddy(mRepeat);
grid->addWidget(mRepeat, row, 2);
row++;
mRepeatError = new QLabel{this};
mRepeatError->setTextFormat(Qt::PlainText);
mRepeatError->setTextInteractionFlags(Qt::TextSelectableByMouse);
- mRepeatError->setPalette(redTextPalette);
+ mRepeatError->setPalette(red_text_palette);
mRepeatError->hide();
grid->addWidget(mRepeatError, row, 2);
}
@@ -248,7 +249,7 @@ PinEntryDialog::PinEntryDialog(QWidget *parent, const char *name, int timeout,
hbox->addLayout(grid, 1);
main_layout->addLayout(hbox);
- QDialogButtonBox *const buttons = new QDialogButtonBox(this);
+ auto *const buttons = new QDialogButtonBox(this);
buttons->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
_ok = buttons->button(QDialogButtonBox::Ok);
_cancel = buttons->button(QDialogButtonBox::Cancel);
@@ -314,6 +315,8 @@ PinEntryDialog::PinEntryDialog(QWidget *parent, const char *name, int timeout,
if (qApp->platformName() != QLatin1String("wayland")) {
setWindowState(Qt::WindowMinimized);
QTimer::singleShot(0, this, [this]() { raiseWindow(this); });
+ } else {
+ raiseWindow(this);
}
}
diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp
index 04c6feb3..a73f56d2 100644
--- a/src/ui/UserInterfaceUtils.cpp
+++ b/src/ui/UserInterfaceUtils.cpp
@@ -29,6 +29,7 @@
#include "UserInterfaceUtils.h"
#include <gpg-error.h>
+#include <qdialog.h>
#include <QtNetwork>
#include <string>
@@ -224,6 +225,7 @@ void CommonUtils::WaitForOpera(QWidget *parent,
QEventLoop looper;
auto *dialog = new WaitingDialog(_("Generating"), parent);
connect(dialog, &QDialog::finished, &looper, &QEventLoop::quit);
+ connect(dialog, &QDialog::finished, dialog, &QDialog::deleteLater);
opera([dialog]() { dialog->accept(); });
diff --git a/src/ui/dialog/WaitingDialog.cpp b/src/ui/dialog/WaitingDialog.cpp
index bfea0ee6..953622fc 100644
--- a/src/ui/dialog/WaitingDialog.cpp
+++ b/src/ui/dialog/WaitingDialog.cpp
@@ -28,7 +28,7 @@
#include "WaitingDialog.h"
-#include "dialog/GeneralDialog.h"
+#include "ui/dialog/GeneralDialog.h"
namespace GpgFrontend::UI {
@@ -53,6 +53,9 @@ WaitingDialog::WaitingDialog(const QString& title, QWidget* parent)
this->setAttribute(Qt::WA_DeleteOnClose);
this->setFixedSize(240, 42);
+ // move to a proper position
+ this->movePosition2CenterOfParent();
+
this->show();
}
diff --git a/src/ui/function/GenerateRevokeCertification.cpp b/src/ui/function/GenerateRevokeCertification.cpp
index 7d37e006..a1c99d95 100644
--- a/src/ui/function/GenerateRevokeCertification.cpp
+++ b/src/ui/function/GenerateRevokeCertification.cpp
@@ -83,6 +83,7 @@ auto GenerateRevokeCertification::Exec(const GpgKey& key,
}
}
}});
+ return 0;
}
} // namespace GpgFrontend::UI \ No newline at end of file
diff --git a/src/ui/function/RaisePinentry.cpp b/src/ui/function/RaisePinentry.cpp
index 65bae527..f47962f4 100644
--- a/src/ui/function/RaisePinentry.cpp
+++ b/src/ui/function/RaisePinentry.cpp
@@ -32,14 +32,27 @@
#include "core/function/CoreSignalStation.h"
#include "pinentry/pinentrydialog.h"
+#include "spdlog/spdlog.h"
namespace GpgFrontend::UI {
+auto FindTopMostWindow(QWidget* fallback) -> QWidget* {
+ QList<QWidget*> top_widgets = QApplication::topLevelWidgets();
+ foreach (QWidget* widget, top_widgets) {
+ if (widget->isActiveWindow()) {
+ SPDLOG_TRACE("find a topmost widget, address: {}",
+ static_cast<void*>(widget));
+ return widget;
+ }
+ }
+ return fallback;
+}
+
RaisePinentry::RaisePinentry(QWidget* parent) : QWidget(parent) {}
auto RaisePinentry::Exec() -> int {
auto* pinentry =
- new PinEntryDialog(this, 0, 0, true, false, QString(),
+ new PinEntryDialog(FindTopMostWindow(this), 0, 0, true, false, QString(),
QString::fromStdString(_("Show passphrase")),
QString::fromStdString(_("Hide passphrase")));
diff --git a/src/ui/function/RaisePinentry.h b/src/ui/function/RaisePinentry.h
index 7cb0c2a1..8c097c2a 100644
--- a/src/ui/function/RaisePinentry.h
+++ b/src/ui/function/RaisePinentry.h
@@ -35,8 +35,18 @@ namespace GpgFrontend::UI {
class RaisePinentry : public QWidget {
Q_OBJECT
public:
+ /**
+ * @brief Construct a new Raise Pinentry object
+ *
+ * @param parent
+ */
explicit RaisePinentry(QWidget *parent);
+ /**
+ * @brief
+ *
+ * @return int
+ */
auto Exec() -> int;
};