aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ui/dialog/keypair_details/KeyDetailsDialog.cpp21
-rw-r--r--src/ui/dialog/keypair_details/KeyPairPhotosTab.cpp132
-rw-r--r--src/ui/dialog/keypair_details/KeyPairPhotosTab.h58
-rw-r--r--src/ui/dialog/keypair_details/KeyPairUIDTab.cpp6
4 files changed, 215 insertions, 2 deletions
diff --git a/src/ui/dialog/keypair_details/KeyDetailsDialog.cpp b/src/ui/dialog/keypair_details/KeyDetailsDialog.cpp
index daa359d1..9dd54b67 100644
--- a/src/ui/dialog/keypair_details/KeyDetailsDialog.cpp
+++ b/src/ui/dialog/keypair_details/KeyDetailsDialog.cpp
@@ -28,13 +28,18 @@
#include "KeyDetailsDialog.h"
+#include "core/function/gpg/GpgAttributeHelper.h"
#include "ui/UISignalStation.h"
#include "ui/dialog/keypair_details/KeyPairDetailTab.h"
#include "ui/dialog/keypair_details/KeyPairOperaTab.h"
+#include "ui/dialog/keypair_details/KeyPairPhotosTab.h"
#include "ui/dialog/keypair_details/KeyPairSubkeyTab.h"
#include "ui/dialog/keypair_details/KeyPairUIDTab.h"
+namespace {} // namespace
+
namespace GpgFrontend::UI {
+
KeyDetailsDialog::KeyDetailsDialog(int channel, const GpgKeyPtr& key,
QWidget* parent)
: GeneralDialog(typeid(KeyDetailsDialog).name(), parent),
@@ -44,10 +49,26 @@ KeyDetailsDialog::KeyDetailsDialog(int channel, const GpgKeyPtr& key,
new KeyPairDetailTab(current_gpg_context_channel_, key, tab_widget_),
tr("KeyPair"));
+ auto attrs =
+ GpgAttributeHelper(current_gpg_context_channel_).GetAttributes(key->ID());
+
+ bool has_photos = false;
+ has_photos = std::any_of(
+ attrs.begin(), attrs.end(),
+ [](const GpgFrontend::GpgAttrInfo& info) { return info.ext == "jpg"; });
+
if (!key->IsRevoked()) {
tab_widget_->addTab(
new KeyPairUIDTab(current_gpg_context_channel_, key, tab_widget_),
tr("UIDs"));
+
+ // Add Photos tab if there are photo attributes
+ if (has_photos) {
+ tab_widget_->addTab(new KeyPairPhotosTab(current_gpg_context_channel_,
+ key, attrs, tab_widget_),
+ tr("Photo IDs"));
+ }
+
tab_widget_->addTab(
new KeyPairSubkeyTab(current_gpg_context_channel_, key, tab_widget_),
tr("Keychain"));
diff --git a/src/ui/dialog/keypair_details/KeyPairPhotosTab.cpp b/src/ui/dialog/keypair_details/KeyPairPhotosTab.cpp
new file mode 100644
index 00000000..f699a9c8
--- /dev/null
+++ b/src/ui/dialog/keypair_details/KeyPairPhotosTab.cpp
@@ -0,0 +1,132 @@
+/**
+ * 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 "KeyPairPhotosTab.h"
+
+#include "core/utils/FilesystemUtils.h"
+#include "ui_KeyPairPhotosTab.h"
+
+namespace GpgFrontend::UI {
+
+KeyPairPhotosTab::KeyPairPhotosTab(int channel, GpgKeyPtr key,
+ const QContainer<GpgAttrInfo>& infos,
+ QWidget* parent)
+ : QWidget(parent),
+ ui_(GpgFrontend::SecureCreateSharedObject<Ui_KeyPairPhotosTab>()),
+ current_gpg_context_channel_(channel),
+ key_(std::move(key)),
+ infos_(infos) {
+ ui_->setupUi(this);
+
+ auto* table_widget = ui_->tableWidget;
+ table_widget->setColumnCount(5);
+ table_widget->setHorizontalHeaderLabels(
+ {tr("Type"), tr("Flags"), tr("Date"), tr("Size"), tr("Thumbnail")});
+
+ int row_count = 0;
+ for (const auto& info : infos_) {
+ if (info.ext != "jpg") continue;
+ jpg_infos_.push_back(info);
+ row_count++;
+ }
+
+ table_widget->setRowCount(row_count);
+
+ int current_index = 0;
+ for (const auto& info : jpg_infos_) {
+ auto* item = new QTableWidgetItem(QString::number(info.type));
+ item->setTextAlignment(Qt::AlignCenter);
+ table_widget->setItem(current_index, 0, item);
+
+ item = new QTableWidgetItem(QString::number(info.flags));
+ item->setTextAlignment(Qt::AlignCenter);
+ table_widget->setItem(current_index, 1, item);
+
+ item = new QTableWidgetItem(QLocale().toString(
+ QDateTime::fromSecsSinceEpoch(info.ts), QLocale::ShortFormat));
+ item->setTextAlignment(Qt::AlignCenter);
+ table_widget->setItem(current_index, 2, item);
+
+ item = new QTableWidgetItem(
+ GpgFrontend::GetHumanFriendlyFileSize(info.payload.size()));
+ item->setTextAlignment(Qt::AlignCenter);
+ table_widget->setItem(current_index, 3, item);
+
+ // Thumbnail
+ item = new QTableWidgetItem();
+ QPixmap pixmap;
+ pixmap.loadFromData(info.payload, "JPG");
+ auto* label = new QLabel();
+ label->setAlignment(Qt::AlignCenter);
+ label->setPixmap(
+ pixmap.scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
+ table_widget->setCellWidget(current_index, 4, label);
+
+ current_index++;
+ }
+
+ table_widget->resizeColumnsToContents();
+
+ connect(table_widget, &QTableWidget::itemSelectionChanged, this,
+ &KeyPairPhotosTab::slot_view_photo);
+
+ ui_->listGroupBox->setTitle(
+ tr("List of Photo IDs (%1)").arg(QString::number(jpg_infos_.size())));
+ ui_->viewerGroupBox->setTitle(tr("Photo Viewer"));
+
+ setAttribute(Qt::WA_DeleteOnClose, true);
+}
+
+KeyPairPhotosTab::~KeyPairPhotosTab() = default;
+
+void KeyPairPhotosTab::slot_view_photo() {
+ auto* photo_label = ui_->photoLabel;
+ auto* table_widget = ui_->tableWidget;
+ const auto selected_items = table_widget->selectedItems();
+
+ if (selected_items.isEmpty()) {
+ photo_label->clear();
+ return;
+ }
+
+ const int selected_row = table_widget->row(selected_items.first());
+ if (selected_row < 0 || selected_row >= jpg_infos_.size()) {
+ photo_label->clear();
+ return;
+ }
+
+ auto info = jpg_infos_.at(selected_row);
+
+ QPixmap pixmap;
+ pixmap.loadFromData(info.payload, "JPG");
+
+ photo_label->setPixmap(pixmap.scaled(photo_label->size(), Qt::KeepAspectRatio,
+ Qt::SmoothTransformation));
+ photo_label->setAlignment(Qt::AlignCenter);
+}
+} // namespace GpgFrontend::UI \ No newline at end of file
diff --git a/src/ui/dialog/keypair_details/KeyPairPhotosTab.h b/src/ui/dialog/keypair_details/KeyPairPhotosTab.h
new file mode 100644
index 00000000..d22597ce
--- /dev/null
+++ b/src/ui/dialog/keypair_details/KeyPairPhotosTab.h
@@ -0,0 +1,58 @@
+/**
+ * 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/function/gpg/GpgAttributeHelper.h"
+#include "core/typedef/GpgTypedef.h"
+
+class Ui_KeyPairPhotosTab;
+
+namespace GpgFrontend::UI {
+class KeyPairPhotosTab : public QWidget {
+ Q_OBJECT
+
+ public:
+ explicit KeyPairPhotosTab(int channel, GpgKeyPtr key,
+ const QContainer<GpgAttrInfo>& infos,
+ QWidget* parent = nullptr);
+ ~KeyPairPhotosTab() override;
+
+ private slots:
+
+ void slot_view_photo();
+
+ private:
+ QSharedPointer<Ui_KeyPairPhotosTab> ui_;
+ int current_gpg_context_channel_;
+ GpgKeyPtr key_;
+ QContainer<GpgAttrInfo> infos_;
+ QContainer<GpgAttrInfo> jpg_infos_;
+};
+
+} // namespace GpgFrontend::UI \ No newline at end of file
diff --git a/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp
index 9e81fae6..ec78f736 100644
--- a/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp
+++ b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp
@@ -177,7 +177,8 @@ void KeyPairUIDTab::slot_refresh_uid_list() {
this->buffered_uids_.push_back(std::move(uid));
}
- uid_list_->setRowCount(buffered_uids_.size());
+ const int rows = static_cast<int>(buffered_uids_.size());
+ uid_list_->setRowCount(rows);
for (const auto& uid : buffered_uids_) {
auto* tmp0 = new QTableWidgetItem(uid.GetName());
@@ -266,7 +267,8 @@ void KeyPairUIDTab::slot_refresh_sig_list() {
buffered_signatures_.push_back(std::move(sig));
}
- sig_list_->setRowCount(buffered_signatures_.size());
+ const int rows = static_cast<int>(buffered_signatures_.size());
+ sig_list_->setRowCount(rows);
for (const auto& sig : buffered_signatures_) {
auto* tmp0 = new QTableWidgetItem(sig.GetKeyID());