aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp')
-rw-r--r--src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp101
1 files changed, 48 insertions, 53 deletions
diff --git a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
index 89d2ce74..22d1db2a 100644
--- a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
+++ b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2021 Saturneric
+ * Copyright (C) 2021 Saturneric <[email protected]>
*
* This file is part of GpgFrontend.
*
@@ -20,7 +20,7 @@
* the gpg4usb project, which is under GPL-3.0-or-later.
*
* All the source code of GpgFrontend was modified and released by
- * Saturneric<[email protected]> starting on May 12, 2021.
+ * Saturneric <[email protected]> starting on May 12, 2021.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
@@ -28,12 +28,11 @@
#include "KeySetExpireDateDialog.h"
-#include <utility>
-
#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyOpera.h"
-#include "ui/SignalStation.h"
+#include "core/utils/GpgUtils.h"
+#include "ui/UISignalStation.h"
#include "ui_ModifiedExpirationDateTime.h"
namespace GpgFrontend::UI {
@@ -41,49 +40,46 @@ namespace GpgFrontend::UI {
KeySetExpireDateDialog::KeySetExpireDateDialog(const KeyId& key_id,
QWidget* parent)
: GeneralDialog(typeid(KeySetExpireDateDialog).name(), parent),
- ui_(std::make_shared<Ui_ModifiedExpirationDateTime>()),
+ ui_(GpgFrontend::SecureCreateSharedObject<
+ Ui_ModifiedExpirationDateTime>()),
m_key_(GpgKeyGetter::GetInstance().GetKey(key_id)) {
init();
}
KeySetExpireDateDialog::KeySetExpireDateDialog(const KeyId& key_id,
- std::string subkey_fpr,
+ QString subkey_fpr,
QWidget* parent)
: GeneralDialog(typeid(KeySetExpireDateDialog).name(), parent),
- ui_(std::make_shared<Ui_ModifiedExpirationDateTime>()),
+ ui_(GpgFrontend::SecureCreateSharedObject<
+ Ui_ModifiedExpirationDateTime>()),
m_key_(GpgKeyGetter::GetInstance().GetKey(key_id)),
m_subkey_(std::move(subkey_fpr)) {
init();
}
void KeySetExpireDateDialog::slot_confirm() {
- SPDLOG_DEBUG("called: {} {}", ui_->dateEdit->date().toString().toStdString(),
- ui_->timeEdit->time().toString().toStdString());
+ GF_UI_LOG_DEBUG("called: {} {}",
+ ui_->dateEdit->date().toString().toStdString(),
+ ui_->timeEdit->time().toString().toStdString());
auto datetime = QDateTime(ui_->dateEdit->date(), ui_->timeEdit->time());
- std::unique_ptr<boost::posix_time::ptime> expires = nullptr;
+ std::unique_ptr<QDateTime> expires = nullptr;
if (ui_->noExpirationCheckBox->checkState() == Qt::Unchecked) {
-#ifdef GPGFRONTEND_GUI_QT6
- expires = std::make_unique<boost::posix_time::ptime>(
- boost::posix_time::from_time_t(
- datetime.toLocalTime().toSecsSinceEpoch()));
-#else
- expires = std::make_unique<boost::posix_time::ptime>(
- boost::posix_time::from_time_t(datetime.toLocalTime().toTime_t()));
-#endif
- SPDLOG_DEBUG("keyid: {}", m_key_.GetId(), m_subkey_,
- to_iso_string(*expires));
+ expires = std::make_unique<QDateTime>(datetime.toLocalTime());
+
+ GF_UI_LOG_DEBUG("keyid: {}", m_key_.GetId(), m_subkey_,
+ expires->toSecsSinceEpoch());
} else {
- SPDLOG_DEBUG("keyid: {}", m_key_.GetId(), m_subkey_, "Non Expired");
+ GF_UI_LOG_DEBUG("keyid: {}", m_key_.GetId(), m_subkey_, "Non Expired");
}
auto err = GpgKeyOpera::GetInstance().SetExpire(m_key_, m_subkey_, expires);
- if (check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR) {
+ if (CheckGpgError(err) == GPG_ERR_NO_ERROR) {
auto* msg_box = new QMessageBox(qobject_cast<QWidget*>(this->parent()));
msg_box->setAttribute(Qt::WA_DeleteOnClose);
msg_box->setStandardButtons(QMessageBox::Ok);
- msg_box->setWindowTitle(_("Success"));
- msg_box->setText(_("The expire date of the key pair has been updated."));
+ msg_box->setWindowTitle(tr("Success"));
+ msg_box->setText(tr("The expire date of the key pair has been updated."));
msg_box->setModal(true);
msg_box->open();
@@ -92,24 +88,19 @@ void KeySetExpireDateDialog::slot_confirm() {
this->close();
} else {
QMessageBox::critical(
- this, _("Failure"),
- _("Failed to update the expire date of the key pair."));
+ this, tr("Failure"),
+ tr("Failed to update the expire date of the key pair."));
}
}
void KeySetExpireDateDialog::init() {
ui_->setupUi(this);
- auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
+ auto settings =
+ GpgFrontend::GlobalSettingStation::GetInstance().GetSettings();
- bool longer_expiration_date = false;
- try {
- longer_expiration_date = settings.lookup("general.longer_expiration_date");
- SPDLOG_DEBUG("longer_expiration_date: {}", longer_expiration_date);
-
- } catch (...) {
- SPDLOG_ERROR("setting operation error: longer_expiration_date");
- }
+ bool longer_expiration_date = longer_expiration_date =
+ settings.value("basic/longer_expiration_date").toBool();
auto max_date_time =
longer_expiration_date
@@ -122,13 +113,8 @@ void KeySetExpireDateDialog::init() {
ui_->dateEdit->setMinimumDateTime(min_date_time);
// set default date time to expire date time
-#ifdef GPGFRONTEND_GUI_QT6
- auto current_expire_time =
- QDateTime::fromSecsSinceEpoch(to_time_t(m_key_.GetExpireTime()));
-#else
- auto current_expire_time =
- QDateTime::fromTime_t(to_time_t(m_key_.GetExpireTime()));
-#endif
+ auto current_expire_time = m_key_.GetExpireTime();
+
ui_->dateEdit->setDateTime(current_expire_time);
ui_->timeEdit->setDateTime(current_expire_time);
@@ -137,16 +123,25 @@ void KeySetExpireDateDialog::init() {
connect(ui_->button_box_, &QDialogButtonBox::accepted, this,
&KeySetExpireDateDialog::slot_confirm);
connect(this, &KeySetExpireDateDialog::SignalKeyExpireDateUpdated,
- SignalStation::GetInstance(),
- &SignalStation::SignalKeyDatabaseRefresh);
-
- ui_->titleLabel->setText(_("Modified Expiration Date (Local Time)"));
- ui_->label->setText(
- _("Tips: For the sake of security, the key is valid for up to two years. "
- "If you are an expert user, please unlock it for a longer time in the "
- "settings."));
- ui_->noExpirationCheckBox->setText(_("No Expiration"));
- this->setWindowTitle(_("Modified Expiration Date"));
+ UISignalStation::GetInstance(),
+ &UISignalStation::SignalKeyDatabaseRefresh);
+
+ if (m_key_.GetExpireTime().toSecsSinceEpoch() == 0) {
+ ui_->noExpirationCheckBox->setCheckState(Qt::Checked);
+ } else {
+ ui_->dateEdit->setDateTime(m_key_.GetExpireTime());
+ ui_->timeEdit->setDateTime(m_key_.GetExpireTime());
+ }
+
+ ui_->titleLabel->setText(tr("Modified Expiration Date (Local Time)"));
+ ui_->label->setText(tr(
+ "Tips: For the sake of security, the key is valid for up to two years. "
+ "If you are an expert user, please unlock it for a longer time in the "
+ "settings."));
+ ui_->noExpirationCheckBox->setText(tr("No Expiration"));
+ this->setWindowTitle(tr("Modified Expiration Date"));
+ this->setAttribute(Qt::WA_DeleteOnClose);
+ this->setModal(true);
}
void KeySetExpireDateDialog::slot_non_expired_checked(int state) {