aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/model
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/model')
-rw-r--r--src/core/model/DataObject.h4
-rw-r--r--src/core/model/GpgAbstractKey.h17
-rw-r--r--src/core/model/GpgKey.cpp4
-rw-r--r--src/core/model/GpgKey.h11
-rw-r--r--src/core/model/GpgKeyGroup.cpp120
-rw-r--r--src/core/model/GpgKeyGroup.h263
-rw-r--r--src/core/model/GpgKeySignature.h3
-rw-r--r--src/core/model/GpgKeyTableModel.cpp264
-rw-r--r--src/core/model/GpgKeyTableModel.h51
-rw-r--r--src/core/model/GpgKeyTreeModel.cpp11
-rw-r--r--src/core/model/GpgKeyTreeModel.h7
-rw-r--r--src/core/model/GpgSubKey.cpp11
-rw-r--r--src/core/model/GpgSubKey.h23
-rw-r--r--src/core/model/GpgUID.h3
-rw-r--r--src/core/model/GpgVerifyResult.h2
15 files changed, 657 insertions, 137 deletions
diff --git a/src/core/model/DataObject.h b/src/core/model/DataObject.h
index a2b19413..efd75c16 100644
--- a/src/core/model/DataObject.h
+++ b/src/core/model/DataObject.h
@@ -95,4 +95,8 @@ auto ExtractParams(const std::shared_ptr<DataObject>& d_o, int index) -> T {
void swap(DataObject& a, DataObject& b) noexcept;
+using DataObjectPtr = std::shared_ptr<DataObject>; ///<
+using OperaRunnable = std::function<GFError(DataObjectPtr)>;
+using OperationCallback = std::function<void(GFError, DataObjectPtr)>;
+
} // namespace GpgFrontend \ No newline at end of file
diff --git a/src/core/model/GpgAbstractKey.h b/src/core/model/GpgAbstractKey.h
index 854297bc..2789fa39 100644
--- a/src/core/model/GpgAbstractKey.h
+++ b/src/core/model/GpgAbstractKey.h
@@ -30,11 +30,22 @@
namespace GpgFrontend {
+enum class GpgAbstractKeyType : unsigned int {
+ kNONE = 0,
+ kGPG_KEY,
+ kGPG_SUBKEY,
+ kGPG_KEYGROUP,
+};
+
class GpgAbstractKey {
public:
[[nodiscard]] virtual auto ID() const -> QString = 0;
[[nodiscard]] virtual auto Fingerprint() const -> QString = 0;
- [[nodiscard]] virtual auto IsSubKey() const -> bool = 0;
+ [[nodiscard]] virtual auto KeyType() const -> GpgAbstractKeyType = 0;
+
+ [[nodiscard]] virtual auto Name() const -> QString = 0;
+ [[nodiscard]] virtual auto Email() const -> QString = 0;
+ [[nodiscard]] virtual auto Comment() const -> QString = 0;
[[nodiscard]] virtual auto IsPrivateKey() const -> bool = 0;
[[nodiscard]] virtual auto IsHasEncrCap() const -> bool = 0;
@@ -54,6 +65,10 @@ class GpgAbstractKey {
[[nodiscard]] auto IsPrimaryKey() const -> bool { return IsHasCertCap(); }
+ [[nodiscard]] virtual auto UID() const -> QString {
+ return QString("%1(%2)<%3>").arg(Name()).arg(Comment()).arg(Email());
+ };
+
auto operator==(const GpgAbstractKey& o) const -> bool {
return ID() == o.ID();
}
diff --git a/src/core/model/GpgKey.cpp b/src/core/model/GpgKey.cpp
index 3efb53fc..1a7b7961 100644
--- a/src/core/model/GpgKey.cpp
+++ b/src/core/model/GpgKey.cpp
@@ -220,6 +220,8 @@ auto GpgKey::PrimaryKey() const -> GpgSubKey {
return GpgSubKey(key_ref_, key_ref_->subkeys);
}
-auto GpgKey::IsSubKey() const -> bool { return false; }
+auto GpgKey::KeyType() const -> GpgAbstractKeyType {
+ return GpgAbstractKeyType::kGPG_KEY;
+}
} // namespace GpgFrontend \ No newline at end of file
diff --git a/src/core/model/GpgKey.h b/src/core/model/GpgKey.h
index de2e8370..43410acd 100644
--- a/src/core/model/GpgKey.h
+++ b/src/core/model/GpgKey.h
@@ -28,12 +28,9 @@
#pragma once
-#include <utility>
-
#include "core/model/GpgAbstractKey.h"
#include "core/model/GpgSubKey.h"
#include "core/model/GpgUID.h"
-
namespace GpgFrontend {
/**
@@ -98,7 +95,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKey : public GpgAbstractKey {
* @return true
* @return false
*/
- [[nodiscard]] auto IsSubKey() const -> bool override;
+ [[nodiscard]] auto KeyType() const -> GpgAbstractKeyType override;
/**
* @brief
@@ -120,21 +117,21 @@ class GPGFRONTEND_CORE_EXPORT GpgKey : public GpgAbstractKey {
*
* @return QString
*/
- [[nodiscard]] auto Name() const -> QString;
+ [[nodiscard]] auto Name() const -> QString override;
/**
* @brief
*
* @return QString
*/
- [[nodiscard]] auto Email() const -> QString;
+ [[nodiscard]] auto Email() const -> QString override;
/**
* @brief
*
* @return QString
*/
- [[nodiscard]] auto Comment() const -> QString;
+ [[nodiscard]] auto Comment() const -> QString override;
/**
* @brief
diff --git a/src/core/model/GpgKeyGroup.cpp b/src/core/model/GpgKeyGroup.cpp
new file mode 100644
index 00000000..b572deac
--- /dev/null
+++ b/src/core/model/GpgKeyGroup.cpp
@@ -0,0 +1,120 @@
+/**
+ * Copyright (C) 2021-2024 Saturneric <[email protected]>
+ *
+ * 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.
+ *
+ * GpgFrontend 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 GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from
+ * 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.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#include "core/model/GpgKeyGroup.h"
+
+#include <utility>
+
+namespace GpgFrontend {
+
+GpgKeyGroup::GpgKeyGroup() = default;
+
+GpgKeyGroup::GpgKeyGroup(const GpgKeyGroup &) = default;
+
+GpgKeyGroup::~GpgKeyGroup() = default;
+
+auto GpgKeyGroup::operator=(const GpgKeyGroup &) -> GpgKeyGroup & = default;
+
+auto GpgKeyGroup::IsGood() const -> bool { return true; }
+
+auto GpgKeyGroup::ID() const -> QString { return id_; }
+
+auto GpgKeyGroup::Name() const -> QString { return name_; };
+
+auto GpgKeyGroup::Email() const -> QString { return email_; }
+
+auto GpgKeyGroup::Comment() const -> QString { return comment_; }
+
+auto GpgKeyGroup::Fingerprint() const -> QString { return {}; }
+
+auto GpgKeyGroup::PublicKeyAlgo() const -> QString { return {}; }
+
+auto GpgKeyGroup::Algo() const -> QString { return {}; }
+
+auto GpgKeyGroup::ExpirationTime() const -> QDateTime { return {}; };
+
+auto GpgKeyGroup::CreationTime() const -> QDateTime { return creation_time_; };
+
+auto GpgKeyGroup::IsHasEncrCap() const -> bool { return true; }
+
+auto GpgKeyGroup::IsHasSignCap() const -> bool { return false; }
+
+auto GpgKeyGroup::IsHasCertCap() const -> bool { return false; }
+
+auto GpgKeyGroup::IsHasAuthCap() const -> bool { return false; }
+
+auto GpgKeyGroup::IsPrivateKey() const -> bool { return false; }
+
+auto GpgKeyGroup::IsExpired() const -> bool { return false; }
+
+auto GpgKeyGroup::IsRevoked() const -> bool { return false; }
+
+auto GpgKeyGroup::IsDisabled() const -> bool {
+ return key_ids_.isEmpty() || disabled_;
+}
+
+auto GpgKeyGroup::KeyType() const -> GpgAbstractKeyType {
+ return GpgAbstractKeyType::kGPG_KEYGROUP;
+}
+
+GpgKeyGroup::GpgKeyGroup(QString name, QString email, QString comment,
+ QStringList key_ids)
+ : id_("#&" + QUuid::createUuid().toRfc4122().toHex().left(14).toUpper()),
+ name_(std::move(name)),
+ email_(std::move(email)),
+ comment_(std::move(comment)),
+ key_ids_(std::move(key_ids)),
+ creation_time_(QDateTime::currentDateTime()) {}
+
+GpgKeyGroup::GpgKeyGroup(const KeyGroupCO &kg_co)
+ : id_(kg_co.id),
+ name_(kg_co.name),
+ email_(kg_co.email),
+ comment_(kg_co.comment),
+ key_ids_(kg_co.key_ids),
+ creation_time_(kg_co.creation_time) {}
+
+auto GpgKeyGroup::ToCacheObject() const -> KeyGroupCO {
+ KeyGroupCO co;
+ co.id = id_;
+ co.name = name_;
+ co.email = email_;
+ co.comment = comment_;
+ co.key_ids = key_ids_;
+ co.creation_time = creation_time_;
+ return co;
+}
+
+auto GpgKeyGroup::KeyIds() const -> QStringList { return key_ids_; }
+
+void GpgKeyGroup::SetKeyIds(QStringList key_ids) {
+ key_ids_ = std::move(key_ids);
+}
+
+void GpgKeyGroup::SetDisabled(bool disabled) { disabled_ = disabled; }
+} // namespace GpgFrontend \ No newline at end of file
diff --git a/src/core/model/GpgKeyGroup.h b/src/core/model/GpgKeyGroup.h
new file mode 100644
index 00000000..d3ae8e03
--- /dev/null
+++ b/src/core/model/GpgKeyGroup.h
@@ -0,0 +1,263 @@
+/**
+ * Copyright (C) 2021-2024 Saturneric <[email protected]>
+ *
+ * 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.
+ *
+ * GpgFrontend 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 GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from
+ * 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.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#pragma once
+
+#include "core/model/GpgAbstractKey.h"
+#include "core/struct/cache_object/KeyGroupCO.h"
+
+namespace GpgFrontend {
+
+/**
+ * @brief
+ *
+ */
+class GPGFRONTEND_CORE_EXPORT GpgKeyGroup : public GpgAbstractKey {
+ public:
+ /**
+ * @brief Construct a new Gpg Key object
+ *
+ */
+ GpgKeyGroup();
+
+ /**
+ * @brief Construct a new Gpg Key object
+ *
+ * @param key
+ */
+ GpgKeyGroup(QString name, QString email, QString comment,
+ QStringList key_ids);
+
+ /**
+ * @brief Construct a new Gpg Key Group object
+ *
+ * @param kg_co
+ */
+ explicit GpgKeyGroup(const KeyGroupCO& kg_co);
+
+ /**
+ * @brief Construct a new Gpg Key object
+ *
+ * @param k
+ */
+ GpgKeyGroup(const GpgKeyGroup&);
+
+ /**
+ * @brief Destroy the Gpg Key objects
+ *
+ */
+ virtual ~GpgKeyGroup() override;
+
+ /**
+ * @brief
+ *
+ * @param k
+ * @return GpgKey&
+ */
+ auto operator=(const GpgKeyGroup&) -> GpgKeyGroup&;
+
+ /**
+ * @brief
+ *
+ * @return true
+ * @return false
+ */
+ [[nodiscard]] auto KeyType() const -> GpgAbstractKeyType override;
+
+ /**
+ * @brief
+ *
+ * @return true
+ * @return false
+ */
+ [[nodiscard]] auto IsGood() const -> bool override;
+
+ /**
+ * @brief
+ *
+ * @return QString
+ */
+ [[nodiscard]] auto ID() const -> QString override;
+
+ /**
+ * @brief
+ *
+ * @return QString
+ */
+ [[nodiscard]] auto Name() const -> QString override;
+
+ /**
+ * @brief
+ *
+ * @return QString
+ */
+ [[nodiscard]] auto Email() const -> QString override;
+
+ /**
+ * @brief
+ *
+ * @return QString
+ */
+ [[nodiscard]] auto Comment() const -> QString override;
+
+ /**
+ * @brief
+ *
+ * @return QString
+ */
+ [[nodiscard]] auto Fingerprint() const -> QString override;
+
+ /**
+ * @brief
+ *
+ * @return QString
+ */
+ [[nodiscard]] auto PublicKeyAlgo() const -> QString override;
+
+ /**
+ * @brief
+ *
+ * @return QString
+ */
+ [[nodiscard]] auto Algo() const -> QString override;
+
+ /**
+ * @brief
+ *
+ * @return QDateTime
+ */
+ [[nodiscard]] auto ExpirationTime() const -> QDateTime override;
+
+ /**
+ * @brief Create a time object
+ *
+ * @return QDateTime
+ */
+ [[nodiscard]] auto CreationTime() const -> QDateTime override;
+
+ /**
+ * @brief
+ *
+ * @return true
+ * @return false
+ */
+ [[nodiscard]] auto IsHasEncrCap() const -> bool override;
+
+ /**
+ * @brief
+ *
+ * @return true
+ * @return false
+ */
+ [[nodiscard]] auto IsHasSignCap() const -> bool override;
+
+ /**
+ * @brief
+ *
+ * @return true
+ * @return false
+ */
+ [[nodiscard]] auto IsHasCertCap() const -> bool override;
+
+ /**
+ * @brief
+ *
+ * @return true
+ * @return false
+ */
+ [[nodiscard]] auto IsHasAuthCap() const -> bool override;
+
+ /**
+ * @brief
+ *
+ * @return true
+ * @return false
+ */
+ [[nodiscard]] auto IsPrivateKey() const -> bool override;
+
+ /**
+ * @brief
+ *
+ * @return true
+ * @return false
+ */
+ [[nodiscard]] auto IsExpired() const -> bool override;
+
+ /**
+ * @brief
+ *
+ * @return true
+ * @return false
+ */
+ [[nodiscard]] auto IsRevoked() const -> bool override;
+
+ /**
+ * @brief
+ *
+ * @return true
+ * @return false
+ */
+ [[nodiscard]] auto IsDisabled() const -> bool override;
+
+ /**
+ * @brief
+ *
+ * @return KeyGroupCO
+ */
+ [[nodiscard]] auto ToCacheObject() const -> KeyGroupCO;
+
+ /**
+ * @brief
+ *
+ * @return KeyGroupCO
+ */
+ [[nodiscard]] auto KeyIds() const -> QStringList;
+
+ /**
+ * @brief Set the Key Ids object
+ *
+ */
+ void SetKeyIds(QStringList);
+
+ /**
+ * @brief Set the Disabled object
+ *
+ */
+ void SetDisabled(bool);
+
+ private:
+ QString id_;
+ QString name_;
+ QString email_;
+ QString comment_;
+ QStringList key_ids_;
+ QDateTime creation_time_;
+ bool disabled_;
+};
+
+} // namespace GpgFrontend
diff --git a/src/core/model/GpgKeySignature.h b/src/core/model/GpgKeySignature.h
index 5f190fa2..94870e0f 100644
--- a/src/core/model/GpgKeySignature.h
+++ b/src/core/model/GpgKeySignature.h
@@ -28,12 +28,11 @@
#pragma once
-#include "core/typedef/GpgTypedef.h"
-
/**
* @brief
*
*/
+#include "core/typedef/GpgErrorTypedef.h"
namespace GpgFrontend {
/**
diff --git a/src/core/model/GpgKeyTableModel.cpp b/src/core/model/GpgKeyTableModel.cpp
index 858ebd75..db456431 100644
--- a/src/core/model/GpgKeyTableModel.cpp
+++ b/src/core/model/GpgKeyTableModel.cpp
@@ -28,12 +28,16 @@
#include "GpgKeyTableModel.h"
+#include <QColor>
+
#include "core/model/GpgKey.h"
+#include "core/model/GpgKeyGroup.h"
#include "core/utils/GpgUtils.h"
namespace GpgFrontend {
-GpgKeyTableModel::GpgKeyTableModel(int channel, GpgKeyList keys,
+GpgKeyTableModel::GpgKeyTableModel(int channel,
+ const GpgAbstractKeyPtrList &keys,
QObject *parent)
: QAbstractTableModel(parent),
column_headers_({tr("Select"), tr("Type"), tr("Name"),
@@ -61,6 +65,123 @@ auto GpgKeyTableModel::columnCount(const QModelIndex & /*parent*/) const
return 11;
}
+auto GpgKeyTableModel::table_data_by_gpg_key(const QModelIndex &index,
+ const GpgKey *key) -> QVariant {
+ switch (index.column()) {
+ case 0: {
+ return index.row();
+ }
+ case 1: {
+ QString type_sym;
+ type_sym += key->IsPrivateKey() ? "pub/sec" : "pub";
+ if (key->IsPrivateKey() && !key->IsHasMasterKey()) type_sym += "#";
+ if (key->IsHasCardKey()) type_sym += "^";
+ return type_sym;
+ }
+ case 2: {
+ return key->Name();
+ }
+ case 3: {
+ return key->Email();
+ }
+ case 4: {
+ return GetUsagesByAbstractKey(key);
+ }
+ case 5: {
+ return key->OwnerTrust();
+ }
+ case 6: {
+ return key->ID();
+ }
+ case 7: {
+ return QLocale().toString(key->CreationTime(), "yyyy-MM-dd");
+ }
+ case 8: {
+ return key->Algo();
+ }
+ case 9: {
+ return static_cast<int>(key->SubKeys().size());
+ }
+ case 10: {
+ return key->Comment();
+ }
+ default:
+ return {};
+ }
+}
+
+auto GpgKeyTableModel::table_data_by_gpg_key_group(
+ const QModelIndex &index, const GpgKeyGroup *kg) -> QVariant {
+ switch (index.column()) {
+ case 0: {
+ return index.row();
+ }
+ case 1: {
+ return "group";
+ }
+ case 2: {
+ return kg->Name();
+ }
+ case 3: {
+ return kg->Email();
+ }
+ case 4: {
+ return GetUsagesByAbstractKey(kg);
+ }
+ case 5: {
+ return "/";
+ }
+ case 6: {
+ return kg->ID();
+ }
+ case 7: {
+ return QLocale().toString(kg->CreationTime(), "yyyy-MM-dd");
+ }
+ case 8: {
+ return kg->Algo();
+ }
+ case 9: {
+ return static_cast<int>(kg->KeyIds().size());
+ }
+ case 10: {
+ return kg->Comment();
+ }
+ default:
+ return {};
+ }
+}
+
+auto GpgKeyTableModel::table_tooltip_by_gpg_key(
+ const QModelIndex & /*index*/, const GpgKey *key) const -> QVariant {
+ QStringList tooltip_lines;
+ tooltip_lines << tr("ID: %1").arg(key->ID());
+ tooltip_lines << tr("Algo: %1").arg(key->Algo());
+ tooltip_lines << tr("Usage: %1").arg(GetUsagesByAbstractKey(key));
+ tooltip_lines << tr("Trust: %1").arg(key->OwnerTrust());
+ tooltip_lines << tr("Comment: %1")
+ .arg(key->Comment().isEmpty()
+ ? "<" + tr("No Comment") + ">"
+ : key->Comment());
+
+ const auto s_keys = key->SubKeys();
+ if (!s_keys.empty()) {
+ tooltip_lines << "";
+ tooltip_lines << tr("SubKeys (up to 8):");
+
+ int count = 0;
+ for (const auto &s_key : s_keys) {
+ if (count++ >= 8) break;
+ const auto usages = GetUsagesByAbstractKey(&s_key);
+ tooltip_lines << tr(" - ID: %1 | Algo: %2 | Usage: %3")
+ .arg(s_key.ID())
+ .arg(s_key.Algo())
+ .arg(usages.trimmed());
+ }
+ }
+
+ return tooltip_lines.join("\n");
+}
+
auto GpgKeyTableModel::data(const QModelIndex &index,
int role) const -> QVariant {
if (!index.isValid() || cached_items_.empty()) return {};
@@ -77,47 +198,16 @@ auto GpgKeyTableModel::data(const QModelIndex &index,
}
if (role == Qt::DisplayRole) {
- const auto key = i->Key();
+ auto *key = i->Key();
+ switch (key->KeyType()) {
+ case GpgAbstractKeyType::kGPG_KEY:
+ return table_data_by_gpg_key(index, dynamic_cast<GpgKey *>(key));
+ case GpgAbstractKeyType::kGPG_KEYGROUP:
+ return table_data_by_gpg_key_group(index,
+ dynamic_cast<GpgKeyGroup *>(key));
+ case GpgAbstractKeyType::kNONE:
+ case GpgAbstractKeyType::kGPG_SUBKEY:
- switch (index.column()) {
- case 0: {
- return index.row();
- }
- case 1: {
- QString type_sym;
- type_sym += key.IsPrivateKey() ? "pub/sec" : "pub";
- if (key.IsPrivateKey() && !key.IsHasMasterKey()) type_sym += "#";
- if (key.IsHasCardKey()) type_sym += "^";
- return type_sym;
- }
- case 2: {
- return key.Name();
- }
- case 3: {
- return key.Email();
- }
- case 4: {
- return GetUsagesByKey(key);
- }
- case 5: {
- return key.OwnerTrust();
- }
- case 6: {
- return key.ID();
- }
- case 7: {
- return QLocale().toString(key.CreationTime(), "yyyy-MM-dd");
- }
- case 8: {
- return key.Algo();
- }
- case 9: {
- return static_cast<int>(key.SubKeys().size());
- }
- case 10: {
- return key.Comment();
- }
- default:
return {};
}
}
@@ -138,35 +228,24 @@ auto GpgKeyTableModel::data(const QModelIndex &index,
}
if (role == Qt::ToolTipRole) {
- const auto key = i->Key();
-
- QStringList tooltip_lines;
- tooltip_lines << tr("ID: %1").arg(key.ID());
- tooltip_lines << tr("Algo: %1").arg(key.Algo());
- tooltip_lines << tr("Usage: %1").arg(GetUsagesByKey(key));
- tooltip_lines << tr("Trust: %1").arg(key.OwnerTrust());
- tooltip_lines << tr("Comment: %1")
- .arg(key.Comment().isEmpty()
- ? "<" + tr("No Comment") + ">"
- : key.Comment());
-
- const auto s_keys = key.SubKeys();
- if (!s_keys.empty()) {
- tooltip_lines << "";
- tooltip_lines << tr("SubKeys (up to 8):");
-
- int count = 0;
- for (const auto &s_key : s_keys) {
- if (count++ >= 8) break;
- const auto usages = GetUsagesBySubkey(s_key);
- tooltip_lines << tr(" - ID: %1 | Algo: %2 | Usage: %3")
- .arg(s_key.ID())
- .arg(s_key.Algo())
- .arg(usages.trimmed());
- }
- }
-
- return tooltip_lines.join("\n");
+ auto *const key = i->Key();
+ switch (key->KeyType()) {
+ case GpgAbstractKeyType::kGPG_KEY:
+ return table_tooltip_by_gpg_key(index, dynamic_cast<GpgKey *>(key));
+ case GpgAbstractKeyType::kNONE:
+ case GpgAbstractKeyType::kGPG_SUBKEY:
+ case GpgAbstractKeyType::kGPG_KEYGROUP:
+ return {};
+ }
+ }
+
+ if (role == Qt::BackgroundRole) {
+ auto *const key = i->Key();
+ if (key->IsDisabled()) return QColorConstants::DarkRed;
+ if (key->IsExpired() || key->IsRevoked()) {
+ return QColorConstants::DarkYellow;
+ }
+ return {};
}
return {};
@@ -194,50 +273,41 @@ auto GpgKeyTableModel::flags(const QModelIndex &index) const -> Qt::ItemFlags {
auto GpgKeyTableModel::setData(const QModelIndex &index, const QVariant &value,
int role) -> bool {
- if (!index.isValid()) return false;
+ if (!index.isValid() || index.column() != 0 || role != Qt::CheckStateRole) {
+ return false;
+ }
- auto *i = index.isValid()
- ? static_cast<GpgKeyTableItem *>(index.internalPointer())
- : nullptr;
+ auto *i = static_cast<GpgKeyTableItem *>(index.internalPointer());
if (i == nullptr) return false;
- if (index.column() == 0 && role == Qt::CheckStateRole) {
- i->SetChecked(value == Qt::Checked);
- emit dataChanged(index, index);
- return true;
- }
+ const bool state = (value.toInt() == Qt::Checked);
+ if (i->Checked() == state) return false;
+ i->SetChecked(state);
- return false;
+ emit dataChanged(index, index, {Qt::CheckStateRole});
+ return true;
}
-auto GpgKeyTableModel::GetAllKeyIds() -> KeyIdArgsList {
- KeyIdArgsList keys;
- for (auto &i : cached_items_) {
- keys.push_back(i.Key().ID());
+auto GpgKeyTableModel::GetAllKeys() const -> GpgAbstractKeyPtrList {
+ GpgAbstractKeyPtrList keys;
+ for (const auto &i : cached_items_) {
+ keys.push_back(i.SharedKey());
}
return keys;
}
-auto GpgKeyTableModel::GetKeyIDByRow(int row) const -> QString {
- if (cached_items_.size() <= row) return {};
-
- return cached_items_[row].Key().ID();
-}
-
-auto GpgKeyTableModel::IsPrivateKeyByRow(int row) const -> bool {
- if (cached_items_.size() <= row) return false;
- return cached_items_[row].Key().IsPrivateKey();
-}
-
auto GpgKeyTableModel::GetGpgContextChannel() const -> int {
return gpg_context_channel_;
}
-GpgKeyTableItem::GpgKeyTableItem(const GpgKey &key) : key_(key) {}
+GpgKeyTableItem::GpgKeyTableItem(GpgAbstractKeyPtr key)
+ : key_(std::move(key)) {}
GpgKeyTableItem::GpgKeyTableItem(const GpgKeyTableItem &) = default;
-auto GpgKeyTableItem::Key() const -> GpgKey { return key_; }
+auto GpgKeyTableItem::Key() const -> GpgAbstractKey * { return key_.get(); }
+
+auto GpgKeyTableItem::SharedKey() const -> GpgAbstractKeyPtr { return key_; }
void GpgKeyTableItem::SetChecked(bool checked) { checked_ = checked; }
diff --git a/src/core/model/GpgKeyTableModel.h b/src/core/model/GpgKeyTableModel.h
index 69118f56..d5cecf14 100644
--- a/src/core/model/GpgKeyTableModel.h
+++ b/src/core/model/GpgKeyTableModel.h
@@ -32,11 +32,13 @@
* @brief
*
*/
-#include "core/model/GpgKey.h"
#include "core/typedef/GpgTypedef.h"
namespace GpgFrontend {
+class GpgKey;
+class GpgKeyGroup;
+
enum class GpgKeyTableColumn : unsigned int {
kNONE = 0,
kTYPE = 1 << 0,
@@ -114,11 +116,23 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyTableItem {
public:
GpgKeyTableItem() = default;
- explicit GpgKeyTableItem(const GpgKey &key);
+ explicit GpgKeyTableItem(GpgAbstractKeyPtr key);
GpgKeyTableItem(const GpgKeyTableItem &);
- [[nodiscard]] auto Key() const -> GpgKey;
+ /**
+ * @brief
+ *
+ * @return GpgAbstractKey*
+ */
+ [[nodiscard]] auto Key() const -> GpgAbstractKey *;
+
+ /**
+ * @brief
+ *
+ * @return GpgAbstractKeyPtr
+ */
+ [[nodiscard]] auto SharedKey() const -> GpgAbstractKeyPtr;
/**
* @brief
@@ -136,7 +150,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyTableItem {
void SetChecked(bool);
private:
- GpgKey key_;
+ GpgAbstractKeyPtr key_;
bool checked_;
};
@@ -149,7 +163,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyTableModel : public QAbstractTableModel {
* @param keys
* @param parent
*/
- explicit GpgKeyTableModel(int channel, GpgKeyList keys,
+ explicit GpgKeyTableModel(int channel, const GpgAbstractKeyPtrList &keys,
QObject *parent = nullptr);
/**
@@ -227,23 +241,7 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyTableModel : public QAbstractTableModel {
*
* @return auto
*/
- auto GetAllKeyIds() -> KeyIdArgsList;
-
- /**
- * @brief Get the Key ID By Row object
- *
- * @return QString
- */
- [[nodiscard]] auto GetKeyIDByRow(int row) const -> QString;
-
- /**
- * @brief
- *
- * @param row
- * @return true
- * @return false
- */
- [[nodiscard]] auto IsPrivateKeyByRow(int row) const -> bool;
+ [[nodiscard]] auto GetAllKeys() const -> GpgAbstractKeyPtrList;
/**
* @brief
@@ -256,6 +254,15 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyTableModel : public QAbstractTableModel {
QStringList column_headers_;
int gpg_context_channel_;
+ auto table_tooltip_by_gpg_key(const QModelIndex &index,
+ const GpgKey *key) const -> QVariant;
+
+ static auto table_data_by_gpg_key(const QModelIndex &index,
+ const GpgKey *key) -> QVariant;
+
+ static auto table_data_by_gpg_key_group(const QModelIndex &index,
+ const GpgKeyGroup *kg) -> QVariant;
+
QContainer<GpgKeyTableItem> cached_items_;
};
diff --git a/src/core/model/GpgKeyTreeModel.cpp b/src/core/model/GpgKeyTreeModel.cpp
index bbe5d00b..a62878c9 100644
--- a/src/core/model/GpgKeyTreeModel.cpp
+++ b/src/core/model/GpgKeyTreeModel.cpp
@@ -211,7 +211,7 @@ auto GpgKeyTreeModel::create_gpg_key_tree_items(const GpgKey &key)
columns << key.UIDs().front().GetUID();
columns << key.ID();
- columns << GetUsagesByKey(key);
+ columns << GetUsagesByAbstractKey(&key);
columns << key.PublicKeyAlgo();
columns << key.Algo();
columns << QLocale().toString(key.CreationTime(), "yyyy-MM-dd");
@@ -228,7 +228,7 @@ auto GpgKeyTreeModel::create_gpg_key_tree_items(const GpgKey &key)
columns << (s_key.IsHasCertCap() ? "primary" : "sub");
columns << key.UIDs().front().GetUID();
columns << s_key.ID();
- columns << GetUsagesBySubkey(s_key);
+ columns << GetUsagesByAbstractKey(&s_key);
columns << s_key.PublicKeyAlgo();
columns << s_key.Algo();
columns << QLocale().toString(s_key.CreationTime(), "yyyy-MM-dd");
@@ -247,7 +247,10 @@ auto GpgKeyTreeModel::create_gpg_key_tree_items(const GpgKey &key)
auto GpgKeyTreeModel::GetAllCheckedSubKey() -> QContainer<GpgSubKey> {
QContainer<GpgSubKey> ret;
for (const auto &i : cached_items_) {
- if (!i->Key()->IsSubKey() || !i->Checkable() || !i->Checked()) continue;
+ if (i->Key()->KeyType() != GpgAbstractKeyType::kGPG_SUBKEY ||
+ !i->Checkable() || !i->Checked()) {
+ continue;
+ }
auto *s_key = dynamic_cast<GpgSubKey *>(i->Key());
if (s_key == nullptr) continue;
@@ -315,6 +318,8 @@ void GpgKeyTreeItem::SetCheckable(bool checkable) { checkable_ = checkable; }
auto GpgKeyTreeItem::Key() const -> GpgAbstractKey * { return key_.get(); }
+auto GpgKeyTreeItem::SharedKey() const -> GpgAbstractKeyPtr { return key_; }
+
auto GpgKeyTreeItem::Enable() const -> bool { return enable_; }
void GpgKeyTreeItem::SetEnable(bool enable) { enable_ = enable; }
diff --git a/src/core/model/GpgKeyTreeModel.h b/src/core/model/GpgKeyTreeModel.h
index 9e91037d..20b63e01 100644
--- a/src/core/model/GpgKeyTreeModel.h
+++ b/src/core/model/GpgKeyTreeModel.h
@@ -222,6 +222,13 @@ class GPGFRONTEND_CORE_EXPORT GpgKeyTreeItem {
*/
[[nodiscard]] auto Key() const -> GpgAbstractKey *;
+ /**
+ * @brief
+ *
+ * @return GpgAbstractKeyPtr
+ */
+ [[nodiscard]] auto SharedKey() const -> GpgAbstractKeyPtr;
+
private:
QContainer<QSharedPointer<GpgKeyTreeItem>> children_;
QVariantList data_;
diff --git a/src/core/model/GpgSubKey.cpp b/src/core/model/GpgSubKey.cpp
index a4e6582f..38710ead 100644
--- a/src/core/model/GpgSubKey.cpp
+++ b/src/core/model/GpgSubKey.cpp
@@ -95,11 +95,20 @@ auto GpgSubKey::SmartCardSerialNumber() const -> QString {
return QString::fromLatin1(s_key_ref_->card_number);
}
-auto GpgSubKey::IsSubKey() const -> bool { return true; }
+auto GpgSubKey::KeyType() const -> GpgAbstractKeyType {
+ return GpgAbstractKeyType::kGPG_SUBKEY;
+}
auto GpgSubKey::IsGood() const -> bool { return s_key_ref_ != nullptr; }
auto GpgSubKey::Convert2GpgKey() const -> QSharedPointer<GpgKey> {
return QSharedPointer<GpgKey>::create(key_ref_);
}
+
+auto GpgSubKey::Name() const -> QString { return key_ref_->uids->name; }
+
+auto GpgSubKey::Email() const -> QString { return key_ref_->uids->email; }
+
+auto GpgSubKey::Comment() const -> QString { return key_ref_->uids->comment; }
+
} // namespace GpgFrontend
diff --git a/src/core/model/GpgSubKey.h b/src/core/model/GpgSubKey.h
index c947b8af..920f42e8 100644
--- a/src/core/model/GpgSubKey.h
+++ b/src/core/model/GpgSubKey.h
@@ -96,7 +96,7 @@ class GPGFRONTEND_CORE_EXPORT GpgSubKey : public GpgAbstractKey {
* @return true
* @return false
*/
- [[nodiscard]] auto IsSubKey() const -> bool override;
+ [[nodiscard]] auto KeyType() const -> GpgAbstractKeyType override;
/**
* @brief
@@ -111,6 +111,27 @@ class GPGFRONTEND_CORE_EXPORT GpgSubKey : public GpgAbstractKey {
*
* @return QString
*/
+ [[nodiscard]] auto Name() const -> QString override;
+
+ /**
+ * @brief
+ *
+ * @return QString
+ */
+ [[nodiscard]] auto Email() const -> QString override;
+
+ /**
+ * @brief
+ *
+ * @return QString
+ */
+ [[nodiscard]] auto Comment() const -> QString override;
+
+ /**
+ * @brief
+ *
+ * @return QString
+ */
[[nodiscard]] auto PublicKeyAlgo() const -> QString override;
/**
diff --git a/src/core/model/GpgUID.h b/src/core/model/GpgUID.h
index 49ddd4c4..6cc44b57 100644
--- a/src/core/model/GpgUID.h
+++ b/src/core/model/GpgUID.h
@@ -28,8 +28,9 @@
#pragma once
-#include "GpgKeySignature.h"
#include "GpgTOFUInfo.h"
+#include "core/model/GpgKeySignature.h"
+#include "core/typedef/CoreTypedef.h"
namespace GpgFrontend {
/**
diff --git a/src/core/model/GpgVerifyResult.h b/src/core/model/GpgVerifyResult.h
index c150d633..6e61497e 100644
--- a/src/core/model/GpgVerifyResult.h
+++ b/src/core/model/GpgVerifyResult.h
@@ -29,7 +29,7 @@
#pragma once
#include "core/GpgFrontendCoreExport.h"
-#include "core/typedef/GpgTypedef.h"
+#include "core/model/GpgSignature.h"
namespace GpgFrontend {