aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gpg/GpgConstants.h15
-rw-r--r--src/gpg/GpgGenKeyInfo.cpp21
-rw-r--r--src/gpg/GpgGenKeyInfo.h25
-rw-r--r--src/gpg/function/GpgKeyOpera.cpp67
-rw-r--r--src/main.cpp3
-rw-r--r--src/ui/SignalStation.cpp34
-rw-r--r--src/ui/SignalStation.h41
-rw-r--r--src/ui/keygen/KeygenDialog.cpp22
-rw-r--r--src/ui/keygen/KeygenDialog.h3
-rw-r--r--src/ui/keygen/SubkeyGenerateDialog.cpp22
-rw-r--r--src/ui/keygen/SubkeyGenerateDialog.h7
-rw-r--r--src/ui/keypair_details/KeyPairSubkeyTab.cpp30
-rw-r--r--src/ui/keypair_details/KeyPairSubkeyTab.h2
-rw-r--r--src/ui/main_window/MainWindowFileSlotFunction.cpp4
-rw-r--r--src/ui/widgets/KeyList.cpp40
15 files changed, 220 insertions, 116 deletions
diff --git a/src/gpg/GpgConstants.h b/src/gpg/GpgConstants.h
index 313e49bb..78a9a3b0 100644
--- a/src/gpg/GpgConstants.h
+++ b/src/gpg/GpgConstants.h
@@ -25,18 +25,18 @@
#ifndef GPG_CONSTANTS_H
#define GPG_CONSTANTS_H
-#include "GpgFrontend.h"
-
-#include <functional>
-
+#define ELPP_DEFAULT_LOGGING_FLAGS 8192
+#include <easyloggingpp/easylogging++.h>
#include <gpg-error.h>
#include <gpgme.h>
+
#include <cassert>
+#include <functional>
+#include <libconfig.h++>
#include <memory>
#include <string>
-#include <easyloggingpp/easylogging++.h>
-#include <libconfig.h++>
+#include "GpgFrontend.h"
const int RESTART_CODE = 1000;
@@ -73,8 +73,7 @@ using GpgVerifyResult =
GpgError check_gpg_error(GpgError err);
GpgError check_gpg_error(GpgError gpgmeError, const std::string& comment);
gpg_err_code_t check_gpg_error_2_err_code(
- gpgme_error_t err,
- gpgme_error_t predict = GPG_ERR_NO_ERROR);
+ gpgme_error_t err, gpgme_error_t predict = GPG_ERR_NO_ERROR);
// Fingerprint
std::string beautify_fingerprint(BypeArrayConstRef fingerprint);
diff --git a/src/gpg/GpgGenKeyInfo.cpp b/src/gpg/GpgGenKeyInfo.cpp
index e45f67c8..79d6617c 100644
--- a/src/gpg/GpgGenKeyInfo.cpp
+++ b/src/gpg/GpgGenKeyInfo.cpp
@@ -23,10 +23,12 @@
*/
#include "gpg/GpgGenKeyInfo.h"
+
+#include <easyloggingpp/easylogging++.h>
+
#include <boost/date_time/gregorian/greg_date.hpp>
#include <boost/date_time/gregorian/greg_duration.hpp>
#include <boost/date_time/gregorian/gregorian_types.hpp>
-#include <boost/date_time/posix_time/ptime.hpp>
#include <string>
#include <vector>
@@ -37,6 +39,7 @@ const std::vector<std::string> GpgFrontend::GenKeyInfo::SupportedSubkeyAlgo = {
"RSA", "DSA", "ED25519", "ELG"};
void GpgFrontend::GenKeyInfo::setAlgo(const std::string &m_algo) {
+ LOG(INFO) << "GpgFrontend::GenKeyInfo::setAlgo m_algo" << m_algo;
reset_options();
@@ -48,9 +51,10 @@ void GpgFrontend::GenKeyInfo::setAlgo(const std::string &m_algo) {
this->allowChangeCertification = false;
- std::string lower_algo;
- std::transform(m_algo.begin(), m_algo.end(), lower_algo.begin(),
- [](unsigned char c) { return std::tolower(c); });
+ std::string lower_algo = std::string(m_algo);
+ boost::algorithm::to_lower(lower_algo);
+
+ LOG(INFO) << "GpgFrontend::GenKeyInfo::setAlgo lower_algo" << lower_algo;
if (lower_algo == "rsa") {
/**
@@ -108,11 +112,10 @@ void GpgFrontend::GenKeyInfo::setAlgo(const std::string &m_algo) {
suggestSizeAdditionStep = 1024;
setKeySize(2048);
}
- GenKeyInfo::algo = lower_algo;
+ this->algo = lower_algo;
}
void GpgFrontend::GenKeyInfo::reset_options() {
-
allowChangeEncryption = true;
setAllowEncryption(true);
@@ -154,14 +157,12 @@ void GpgFrontend::GenKeyInfo::setExpired(
void GpgFrontend::GenKeyInfo::setNonExpired(bool m_non_expired) {
using namespace boost::posix_time;
- if (!m_non_expired)
- this->expired = from_time_t(0).date();
+ if (!m_non_expired) this->expired = from_time_t(0).date();
GenKeyInfo::nonExpired = m_non_expired;
}
void GpgFrontend::GenKeyInfo::setAllowEncryption(bool m_allow_encryption) {
- if (allowChangeEncryption)
- GenKeyInfo::allowEncryption = m_allow_encryption;
+ if (allowChangeEncryption) GenKeyInfo::allowEncryption = m_allow_encryption;
}
void GpgFrontend::GenKeyInfo::setAllowCertification(
diff --git a/src/gpg/GpgGenKeyInfo.h b/src/gpg/GpgGenKeyInfo.h
index d2ec8141..cb627555 100644
--- a/src/gpg/GpgGenKeyInfo.h
+++ b/src/gpg/GpgGenKeyInfo.h
@@ -22,19 +22,17 @@
*
*/
-#ifndef GPG4USB_GPGGENKEYINFO_H
-#define GPG4USB_GPGGENKEYINFO_H
+#ifndef GPGFRONTEND_GPGGENKEYINFO_H
+#define GPGFRONTEND_GPGGENKEYINFO_H
+#include <boost/date_time.hpp>
#include <boost/date_time/gregorian/greg_duration_types.hpp>
#include <string>
#include <vector>
-#include <boost/date_time.hpp>
-
namespace GpgFrontend {
class GenKeyInfo {
-
bool subKey = true;
std::string userid;
std::string algo;
@@ -46,13 +44,13 @@ class GenKeyInfo {
bool noPassPhrase = false;
bool allowNoPassPhrase = true;
- int suggestMaxKeySize = 1024;
+ int suggestMaxKeySize = 4096;
int suggestSizeAdditionStep = 1024;
- int suggestMinKeySize = 4096;
+ int suggestMinKeySize = 1024;
std::string passPhrase;
-public:
+ public:
static const std::vector<std::string> SupportedKeyAlgo;
static const std::vector<std::string> SupportedSubkeyAlgo;
@@ -96,8 +94,7 @@ public:
[[nodiscard]] bool isAllowNoPassPhrase() const { return allowNoPassPhrase; }
void setAllowSigning(bool m_allow_signing) {
- if (allowChangeSigning)
- GenKeyInfo::allowSigning = m_allow_signing;
+ if (allowChangeSigning) GenKeyInfo::allowSigning = m_allow_signing;
}
[[nodiscard]] bool isAllowEncryption() const { return allowEncryption; }
@@ -144,7 +141,7 @@ public:
return suggestSizeAdditionStep;
}
-private:
+ private:
bool allowEncryption = true;
bool allowChangeEncryption = true;
@@ -159,12 +156,12 @@ private:
void reset_options();
-public:
+ public:
explicit GenKeyInfo(bool m_is_sub_key = false) : subKey(m_is_sub_key) {
setAlgo("rsa");
}
};
-} // namespace GpgFrontend
+} // namespace GpgFrontend
-#endif // GPG4USB_GPGGENKEYINFO_H
+#endif // GPGFRONTEND_GPGGENKEYINFO_H
diff --git a/src/gpg/function/GpgKeyOpera.cpp b/src/gpg/function/GpgKeyOpera.cpp
index f61534c5..0a222c3f 100644
--- a/src/gpg/function/GpgKeyOpera.cpp
+++ b/src/gpg/function/GpgKeyOpera.cpp
@@ -23,19 +23,19 @@
*/
#include "gpg/function/GpgKeyOpera.h"
-#include "gpg/GpgConstants.h"
-#include "gpg/GpgGenKeyInfo.h"
-#include "gpg/function/GpgCommandExecutor.h"
-#include "gpg/function/GpgKeyGetter.h"
#include <boost/asio/read_until.hpp>
#include <boost/date_time/posix_time/conversion.hpp>
-
#include <boost/process/async_pipe.hpp>
#include <memory>
#include <string>
#include <vector>
+#include "gpg/GpgConstants.h"
+#include "gpg/GpgGenKeyInfo.h"
+#include "gpg/function/GpgCommandExecutor.h"
+#include "gpg/function/GpgKeyGetter.h"
+
/**
* Delete keys
* @param uidList key ids
@@ -62,8 +62,7 @@ void GpgFrontend::GpgKeyOpera::DeleteKeys(
* @return if successful
*/
void GpgFrontend::GpgKeyOpera::SetExpire(
- const GpgKey& key,
- const SubkeyId& subkey_id,
+ const GpgKey& key, const SubkeyId& subkey_id,
std::unique_ptr<boost::gregorian::date>& expires) {
unsigned long expires_time = 0;
if (expires != nullptr) {
@@ -88,8 +87,7 @@ void GpgFrontend::GpgKeyOpera::SetExpire(
* @return the process doing this job
*/
void GpgFrontend::GpgKeyOpera::GenerateRevokeCert(
- const GpgKey& key,
- const std::string& output_file_name) {
+ const GpgKey& key, const std::string& output_file_name) {
auto args = std::vector<std::string>{"--command-fd", "0",
"--status-fd", "1",
"-o", output_file_name.c_str(),
@@ -117,7 +115,11 @@ GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::GenerateKey(
const std::unique_ptr<GenKeyInfo>& params) {
auto userid_utf8 = params->getUserid();
const char* userid = userid_utf8.c_str();
- auto algo_utf8 = (params->getAlgo() + params->getKeySizeStr());
+ auto algo_utf8 = params->getAlgo() + params->getKeySizeStr();
+
+ LOG(INFO) << "GpgFrontend::GpgKeyOpera::GenerateKey Params"
+ << params->getAlgo() << params->getKeySizeStr();
+
const char* algo = algo_utf8.c_str();
unsigned long expires = 0;
{
@@ -127,18 +129,15 @@ GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::GenerateKey(
unsigned int flags = 0;
- if (!params->isSubKey())
- flags |= GPGME_CREATE_CERT;
- if (params->isAllowEncryption())
- flags |= GPGME_CREATE_ENCR;
- if (params->isAllowSigning())
- flags |= GPGME_CREATE_SIGN;
- if (params->isAllowAuthentication())
- flags |= GPGME_CREATE_AUTH;
- if (params->isNonExpired())
- flags |= GPGME_CREATE_NOEXPIRE;
- if (params->isNoPassPhrase())
- flags |= GPGME_CREATE_NOPASSWD;
+ if (!params->isSubKey()) flags |= GPGME_CREATE_CERT;
+ if (params->isAllowEncryption()) flags |= GPGME_CREATE_ENCR;
+ if (params->isAllowSigning()) flags |= GPGME_CREATE_SIGN;
+ if (params->isAllowAuthentication()) flags |= GPGME_CREATE_AUTH;
+ if (params->isNonExpired()) flags |= GPGME_CREATE_NOEXPIRE;
+ if (params->isNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD;
+
+ LOG(INFO) << "GpgFrontend::GpgKeyOpera::GenerateKey Args: " << userid << algo
+ << expires << flags;
auto err = gpgme_op_createkey(ctx, userid, algo, 0, expires, nullptr, flags);
return check_gpg_error(err);
@@ -151,10 +150,8 @@ GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::GenerateKey(
* @return error info
*/
GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::GenerateSubkey(
- const GpgKey& key,
- const std::unique_ptr<GenKeyInfo>& params) {
- if (!params->isSubKey())
- return GPG_ERR_CANCELED;
+ const GpgKey& key, const std::unique_ptr<GenKeyInfo>& params) {
+ if (!params->isSubKey()) return GPG_ERR_CANCELED;
auto algo_utf8 = (params->getAlgo() + params->getKeySizeStr());
const char* algo = algo_utf8.c_str();
@@ -165,19 +162,17 @@ GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::GenerateSubkey(
}
unsigned int flags = 0;
- if (!params->isSubKey())
- flags |= GPGME_CREATE_CERT;
- if (params->isAllowEncryption())
- flags |= GPGME_CREATE_ENCR;
- if (params->isAllowSigning())
- flags |= GPGME_CREATE_SIGN;
- if (params->isAllowAuthentication())
- flags |= GPGME_CREATE_AUTH;
- if (params->isNonExpired())
- flags |= GPGME_CREATE_NOEXPIRE;
+ if (!params->isSubKey()) flags |= GPGME_CREATE_CERT;
+ if (params->isAllowEncryption()) flags |= GPGME_CREATE_ENCR;
+ if (params->isAllowSigning()) flags |= GPGME_CREATE_SIGN;
+ if (params->isAllowAuthentication()) flags |= GPGME_CREATE_AUTH;
+ if (params->isNonExpired()) flags |= GPGME_CREATE_NOEXPIRE;
flags |= GPGME_CREATE_NOPASSWD;
+ LOG(INFO) << "GpgFrontend::GpgKeyOpera::GenerateSubkey Args: " << key.id()
+ << algo << expires << flags;
+
auto err =
gpgme_op_createsubkey(ctx, gpgme_key_t(key), algo, 0, expires, flags);
return check_gpg_error(err);
diff --git a/src/main.cpp b/src/main.cpp
index f44d7ad3..71e517da 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -29,6 +29,9 @@
INITIALIZE_EASYLOGGINGPP
int main(int argc, char* argv[]) {
+
+ el::Loggers::addFlag(el::LoggingFlag::AutoSpacing);
+
Q_INIT_RESOURCE(gpgfrontend);
QApplication app(argc, argv);
diff --git a/src/ui/SignalStation.cpp b/src/ui/SignalStation.cpp
new file mode 100644
index 00000000..ad5c0b53
--- /dev/null
+++ b/src/ui/SignalStation.cpp
@@ -0,0 +1,34 @@
+/**
+ * This file is part of GPGFrontend.
+ *
+ * GPGFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Foobar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from gpg4usb-team.
+ * Their source code version also complies with GNU General Public License.
+ *
+ * The source code version of this software was modified and released
+ * by Saturneric<[email protected]> starting on May 12, 2021.
+ *
+ */
+
+#include "SignalStation.h"
+
+std::unique_ptr<SignalStation> SignalStation::_instance = nullptr;
+
+SignalStation* SignalStation::GetInstance() {
+ if (_instance == nullptr) {
+ _instance = std::make_unique<SignalStation>();
+ }
+ return _instance.get();
+}
diff --git a/src/ui/SignalStation.h b/src/ui/SignalStation.h
new file mode 100644
index 00000000..92211aa2
--- /dev/null
+++ b/src/ui/SignalStation.h
@@ -0,0 +1,41 @@
+/**
+ * This file is part of GPGFrontend.
+ *
+ * GPGFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Foobar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from gpg4usb-team.
+ * Their source code version also complies with GNU General Public License.
+ *
+ * The source code version of this software was modified and released
+ * by Saturneric<[email protected]> starting on May 12, 2021.
+ *
+ */
+
+#ifndef GPGFRONTEND_SIGNALSTATION_H
+#define GPGFRONTEND_SIGNALSTATION_H
+
+#include "ui/GpgFrontendUI.h"
+
+class SignalStation : public QObject {
+ Q_OBJECT
+ static std::unique_ptr<SignalStation> _instance;
+
+ public:
+ static SignalStation* GetInstance();
+
+ signals:
+ void KeyDatabaseRefresh();
+};
+
+#endif // GPGFRONTEND_SIGNALSTATION_H
diff --git a/src/ui/keygen/KeygenDialog.cpp b/src/ui/keygen/KeygenDialog.cpp
index 0786d644..a8bc6935 100644
--- a/src/ui/keygen/KeygenDialog.cpp
+++ b/src/ui/keygen/KeygenDialog.cpp
@@ -23,7 +23,9 @@
*/
#include "ui/keygen/KeygenDialog.h"
+
#include "gpg/function/GpgKeyOpera.h"
+#include "ui/SignalStation.h"
#include "ui/WaitingDialog.h"
namespace GpgFrontend::UI {
@@ -34,6 +36,10 @@ KeyGenDialog::KeyGenDialog(QWidget* parent) : QDialog(parent) {
this->setWindowTitle(tr("Generate Key"));
this->setModal(true);
+
+ connect(this, SIGNAL(KeyGenerated()), SignalStation::GetInstance(),
+ SIGNAL(KeyDatabaseRefresh()));
+
generateKeyDialog();
}
@@ -86,7 +92,7 @@ void KeyGenDialog::slotKeyGenAccept() {
*/
genKeyInfo->setUserid(
- QString("%1 (%3) <%2>")
+ QString("%1(%3)<%2>")
.arg(nameEdit->text(), emailEdit->text(), commentEdit->text())
.toStdString());
@@ -115,11 +121,19 @@ void KeyGenDialog::slotKeyGenAccept() {
dialog->close();
if (gpgme_err_code(error) == GPG_ERR_NO_ERROR) {
- QMessageBox::information(this, tr("Success"),
- tr("The new key pair has been generated."));
+ auto* msg_box = new QMessageBox(nullptr);
+ msg_box->setAttribute(Qt::WA_DeleteOnClose);
+ msg_box->setStandardButtons(QMessageBox::Ok);
+ msg_box->setWindowTitle(tr("Success"));
+ msg_box->setText(tr("The new key pair has been generated."));
+ msg_box->setModal(false);
+ msg_box->open();
+
+ emit KeyGenerated();
this->close();
- } else
+ } else {
QMessageBox::critical(this, tr("Failure"), tr(gpgme_strerror(error)));
+ }
} else {
/**
diff --git a/src/ui/keygen/KeygenDialog.h b/src/ui/keygen/KeygenDialog.h
index 97846eb5..60a34a90 100644
--- a/src/ui/keygen/KeygenDialog.h
+++ b/src/ui/keygen/KeygenDialog.h
@@ -44,6 +44,9 @@ class KeyGenDialog : public QDialog {
*/
explicit KeyGenDialog(QWidget* parent = nullptr);
+ signals:
+ void KeyGenerated();
+
private:
QGroupBox* create_key_usage_group_box();
diff --git a/src/ui/keygen/SubkeyGenerateDialog.cpp b/src/ui/keygen/SubkeyGenerateDialog.cpp
index 1da37393..41bc36c9 100644
--- a/src/ui/keygen/SubkeyGenerateDialog.cpp
+++ b/src/ui/keygen/SubkeyGenerateDialog.cpp
@@ -26,6 +26,7 @@
#include "gpg/function/GpgKeyGetter.h"
#include "gpg/function/GpgKeyOpera.h"
+#include "ui/SignalStation.h"
#include "ui/WaitingDialog.h"
namespace GpgFrontend::UI {
@@ -50,10 +51,12 @@ SubkeyGenerateDialog::SubkeyGenerateDialog(const KeyId& key_id, QWidget* parent)
vbox2->addWidget(buttonBox);
this->setWindowTitle(tr("Generate New Subkey"));
-
this->setLayout(vbox2);
this->setModal(true);
+ connect(this, SIGNAL(SubKeyGenerated()), SignalStation::GetInstance(),
+ SIGNAL(KeyDatabaseRefresh()));
+
set_signal_slot();
refresh_widgets_state();
}
@@ -233,8 +236,9 @@ void SubkeyGenerateDialog::slotKeyGenAccept() {
.date());
}
- gpgme_error_t error = false;
+ GpgError error;
auto thread = QThread::create([&]() {
+ LOG(INFO) << "SubkeyGenerateDialog::slotKeyGenAccept() Thread Started";
error = GpgKeyOpera::GetInstance().GenerateSubkey(mKey, genKeyInfo);
});
thread->start();
@@ -245,12 +249,18 @@ void SubkeyGenerateDialog::slotKeyGenAccept() {
while (thread->isRunning()) {
QCoreApplication::processEvents();
}
-
dialog->close();
- if (gpgme_err_code(error) == GPG_ERR_NO_ERROR) {
- QMessageBox::information(nullptr, tr("Success"),
- tr("The new subkey has been generated."));
+ if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR) {
+ auto* msg_box = new QMessageBox(nullptr);
+ msg_box->setAttribute(Qt::WA_DeleteOnClose);
+ msg_box->setStandardButtons(QMessageBox::Ok);
+ msg_box->setWindowTitle(tr("Success"));
+ msg_box->setText(tr("The new subkey has been generated."));
+ msg_box->setModal(false);
+ msg_box->open();
+
+ emit SubKeyGenerated();
this->close();
} else
QMessageBox::critical(this, tr("Failure"), tr(gpgme_strerror(error)));
diff --git a/src/ui/keygen/SubkeyGenerateDialog.h b/src/ui/keygen/SubkeyGenerateDialog.h
index 1b4249b4..12f608d0 100644
--- a/src/ui/keygen/SubkeyGenerateDialog.h
+++ b/src/ui/keygen/SubkeyGenerateDialog.h
@@ -25,8 +25,8 @@
#ifndef GPGFRONTEND_SUBKEYGENERATEDIALOG_H
#define GPGFRONTEND_SUBKEYGENERATEDIALOG_H
-#include <gpg/GpgGenKeyInfo.h>
#include "gpg/GpgContext.h"
+#include "gpg/GpgGenKeyInfo.h"
#include "ui/GpgFrontendUI.h"
namespace GpgFrontend::UI {
@@ -37,10 +37,13 @@ class SubkeyGenerateDialog : public QDialog {
public:
explicit SubkeyGenerateDialog(const KeyId& key_id, QWidget* parent);
+ signals:
+ void SubKeyGenerated();
+
private:
GpgKey mKey;
- std::unique_ptr<GenKeyInfo> genKeyInfo = std::make_unique<GenKeyInfo>();
+ std::unique_ptr<GenKeyInfo> genKeyInfo = std::make_unique<GenKeyInfo>(true);
QGroupBox* keyUsageGroupBox{};
QDialogButtonBox* buttonBox; /** Box for standardbuttons */
diff --git a/src/ui/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/keypair_details/KeyPairSubkeyTab.cpp
index a56885d1..7703bbde 100644
--- a/src/ui/keypair_details/KeyPairSubkeyTab.cpp
+++ b/src/ui/keypair_details/KeyPairSubkeyTab.cpp
@@ -23,7 +23,9 @@
*/
#include "ui/keypair_details/KeyPairSubkeyTab.h"
+
#include "gpg/function/GpgKeyGetter.h"
+#include "ui/SignalStation.h"
namespace GpgFrontend::UI {
@@ -93,6 +95,12 @@ KeyPairSubkeyTab::KeyPairSubkeyTab(const std::string& key_id, QWidget* parent)
connect(subkeyList, SIGNAL(itemSelectionChanged()), this,
SLOT(slotRefreshSubkeyDetail()));
+ // key database refresh signal
+ connect(SignalStation::GetInstance(), SIGNAL(KeyDatabaseRefresh()), this,
+ SLOT(slotRefreshKeyInfo()));
+ connect(SignalStation::GetInstance(), SIGNAL(KeyDatabaseRefresh()), this,
+ SLOT(slotRefreshSubkeyList()));
+
baseLayout->setContentsMargins(0, 0, 0, 0);
setLayout(baseLayout);
@@ -128,6 +136,7 @@ void KeyPairSubkeyTab::createSubkeyList() {
}
void KeyPairSubkeyTab::slotRefreshSubkeyList() {
+ LOG(INFO) << "KeyPairSubkeyTab::slotRefreshSubkeyList Called";
int row = 0;
subkeyList->setSelectionMode(QAbstractItemView::SingleSelection);
@@ -135,8 +144,7 @@ void KeyPairSubkeyTab::slotRefreshSubkeyList() {
this->buffered_subkeys.clear();
auto sub_keys = mKey.subKeys();
for (auto& sub_key : *sub_keys) {
- if (sub_key.disabled() || sub_key.revoked())
- continue;
+ if (sub_key.disabled() || sub_key.revoked()) continue;
this->buffered_subkeys.push_back(std::move(sub_key));
}
@@ -213,14 +221,10 @@ void KeyPairSubkeyTab::slotRefreshSubkeyDetail() {
QString usage;
QTextStream usage_steam(&usage);
- if (subkey.can_certify())
- usage_steam << "Cert ";
- if (subkey.can_encrypt())
- usage_steam << "Encr ";
- if (subkey.can_sign())
- usage_steam << "Sign ";
- if (subkey.can_authenticate())
- usage_steam << "Auth ";
+ if (subkey.can_certify()) usage_steam << "Cert ";
+ if (subkey.can_encrypt()) usage_steam << "Encr ";
+ if (subkey.can_sign()) usage_steam << "Sign ";
+ if (subkey.can_authenticate()) usage_steam << "Auth ";
usageVarLabel->setText(usage);
@@ -269,12 +273,14 @@ const GpgSubKey& KeyPairSubkeyTab::getSelectedSubkey() {
int row = 0;
for (int i = 0; i < subkeyList->rowCount(); i++) {
- if (subkeyList->item(row, 0)->isSelected())
- break;
+ if (subkeyList->item(row, 0)->isSelected()) break;
row++;
}
return buffered_subkeys[row];
}
+void KeyPairSubkeyTab::slotRefreshKeyInfo() {
+ mKey = GpgKeyGetter::GetInstance().GetKey(mKey.id());
+}
} // namespace GpgFrontend::UI
diff --git a/src/ui/keypair_details/KeyPairSubkeyTab.h b/src/ui/keypair_details/KeyPairSubkeyTab.h
index 642d0cf4..6466d8b4 100644
--- a/src/ui/keypair_details/KeyPairSubkeyTab.h
+++ b/src/ui/keypair_details/KeyPairSubkeyTab.h
@@ -76,6 +76,8 @@ class KeyPairSubkeyTab : public QWidget {
void slotRevokeSubkey();
+ void slotRefreshKeyInfo();
+
protected:
void contextMenuEvent(QContextMenuEvent* event) override;
};
diff --git a/src/ui/main_window/MainWindowFileSlotFunction.cpp b/src/ui/main_window/MainWindowFileSlotFunction.cpp
index 933579b0..2590cdda 100644
--- a/src/ui/main_window/MainWindowFileSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowFileSlotFunction.cpp
@@ -83,10 +83,6 @@ bool file_pre_check(QWidget* parent, const QString& path) {
void process_operation(QWidget* parent, const std::string& waiting_title,
const std::function<void()>& func) {
- GpgEncrResult result = nullptr;
-
- gpgme_error_t error;
- bool if_error = false;
auto thread = QThread::create(func);
QApplication::connect(thread, SIGNAL(finished()), thread,
SLOT(deleteLater()));
diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp
index f340cafc..4cb30acf 100644
--- a/src/ui/widgets/KeyList.cpp
+++ b/src/ui/widgets/KeyList.cpp
@@ -23,15 +23,16 @@
*/
#include "ui/widgets/KeyList.h"
-#include "gpg/function/GpgKeyGetter.h"
#include <utility>
+#include "gpg/function/GpgKeyGetter.h"
+#include "ui/SignalStation.h"
+
namespace GpgFrontend::UI {
KeyList::KeyList(KeyListRow::KeyType selectType,
- KeyListColumn::InfoType infoType,
- QWidget* parent)
+ KeyListColumn::InfoType infoType, QWidget* parent)
: QWidget(parent),
appPath(qApp->applicationDirPath()),
settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
@@ -48,10 +49,10 @@ KeyList::KeyList(KeyListRow::KeyType selectType,
mKeyList->setSelectionBehavior(QAbstractItemView::SelectRows);
mKeyList->setSelectionMode(QAbstractItemView::SingleSelection);
- // tableitems not editable
+ // table items not editable
mKeyList->setEditTriggers(QAbstractItemView::NoEditTriggers);
- // no focus (rectangle around tableitems)
- // may be it should focus on whole row
+ // no focus (rectangle around table items)
+ // maybe it should focus on whole row
mKeyList->setFocusPolicy(Qt::NoFocus);
mKeyList->setAlternatingRowColors(true);
@@ -91,13 +92,20 @@ KeyList::KeyList(KeyListRow::KeyType selectType,
popupMenu = new QMenu(this);
+ // register key database refresh signal
+ connect(SignalStation::GetInstance(), SIGNAL(KeyDatabaseRefresh()), this,
+ SLOT(slotRefresh()));
connect(mKeyList, SIGNAL(doubleClicked(const QModelIndex&)), this,
SLOT(slotDoubleClicked(const QModelIndex&)));
+
setAcceptDrops(true);
slotRefresh();
}
void KeyList::slotRefresh() {
+
+ LOG(INFO) << "KeyList::slotRefresh Called";
+
auto keyList = getChecked();
// while filling the table, sort enabled causes errors
mKeyList->setSortingEnabled(false);
@@ -178,14 +186,10 @@ void KeyList::slotRefresh() {
QString usage;
QTextStream usage_steam(&usage);
- if (it->CanCertActual())
- usage_steam << "C";
- if (it->CanEncrActual())
- usage_steam << "E";
- if (it->CanSignActual())
- usage_steam << "S";
- if (it->CanAuthActual())
- usage_steam << "A";
+ if (it->CanCertActual()) usage_steam << "C";
+ if (it->CanEncrActual()) usage_steam << "E";
+ if (it->CanSignActual()) usage_steam << "S";
+ if (it->CanAuthActual()) usage_steam << "A";
auto* temp_usage = new QTableWidgetItem(usage);
temp_usage->setTextAlignment(Qt::AlignCenter);
@@ -291,13 +295,9 @@ void KeyList::contextMenuEvent(QContextMenuEvent* event) {
}
}
-void KeyList::addSeparator() {
- popupMenu->addSeparator();
-}
+void KeyList::addSeparator() { popupMenu->addSeparator(); }
-void KeyList::addMenuAction(QAction* act) {
- popupMenu->addAction(act);
-}
+void KeyList::addMenuAction(QAction* act) { popupMenu->addAction(act); }
void KeyList::dropEvent(QDropEvent* event) {
auto* dialog = new QDialog();