From 200964246efdc5a011aa188a0dae5b2915a8b7ac Mon Sep 17 00:00:00 2001 From: Quentin Rouland Date: Tue, 14 Jan 2025 12:20:55 +0100 Subject: [PATCH] Improve gpg key infos --- plugins/Pass/pass.cpp | 4 +- plugins/Pass/passkeymodel.h | 107 ++++++++++++++++++-------------- po/utpass.qrouland.pot | 31 +++++---- qml/pages/Info.qml | 1 - qml/pages/settings/InfoKeys.qml | 50 +++++++++++++-- 5 files changed, 126 insertions(+), 67 deletions(-) diff --git a/plugins/Pass/pass.cpp b/plugins/Pass/pass.cpp index dbddcdf..d515a85 100644 --- a/plugins/Pass/pass.cpp +++ b/plugins/Pass/pass.cpp @@ -58,7 +58,7 @@ bool Pass::importGPGKey(QUrl url) QVariant Pass::getAllGPGKeys() { qInfo() << "Getting all key form gpg "; - return QVariant::fromValue(PassKeyModel::keysToPassKeyQObjectList( - Gpg::instance()->getAllKeys().second)); + return QVariant::fromValue(PassKeyModel::keysToPassKey( + Gpg::instance()->getAllKeys().second)); // TODO Error handling } diff --git a/plugins/Pass/passkeymodel.h b/plugins/Pass/passkeymodel.h index af44eda..c739af3 100644 --- a/plugins/Pass/passkeymodel.h +++ b/plugins/Pass/passkeymodel.h @@ -6,69 +6,84 @@ using namespace GpgME; +class UserIdModel : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString uid READ uid MEMBER m_uid CONSTANT) + Q_PROPERTY(QString name READ name MEMBER m_name CONSTANT) + Q_PROPERTY(QString email READ email MEMBER m_email CONSTANT) + + UserID m_user_id; +public: + + + UserIdModel(UserID key): + m_user_id(key) + {}; + + QString uid() const + { + return QString::fromUtf8(m_user_id.id()); + }; + QString name() const + { + return QString::fromUtf8(m_user_id.name()); + }; + QString email() const + { + return QString::fromUtf8(m_user_id.email()); + }; +}; + class PassKeyModel : public QObject { Q_OBJECT - Q_PROPERTY(QString uid READ uid WRITE setUid NOTIFY uidChanged MEMBER m_uid) - Q_PROPERTY(bool secret READ secret WRITE setSecret NOTIFY secretChanged MEMBER m_secret) - Q_PROPERTY(bool expired READ expired WRITE setExpired NOTIFY expiredChanged MEMBER m_expired) - - QString m_uid; - bool m_secret; - bool m_expired; + Q_PROPERTY(QString uid READ uid MEMBER m_uid CONSTANT) + Q_PROPERTY(QList userIds READ userIds MEMBER m_user_ids CONSTANT) + Q_PROPERTY(bool isSecret READ isSecret MEMBER m_secret CONSTANT) + Q_PROPERTY(bool isExpired READ isExpired MEMBER m_expired CONSTANT) + Key m_key; public: - PassKeyModel(QString uid, bool secret, bool expired): - m_uid(uid), - m_secret(secret), - m_expired(expired) - {}; - PassKeyModel(Key key): - PassKeyModel(QString::fromUtf8(key.keyID()), key.hasSecret(), key.isExpired()) + m_key(key) {}; - static QList keysToPassKeyQObjectList(std::vector keys) + static QList keysToPassKey(std::vector keys) { - QList r; - std::for_each(keys.begin(), keys.end(), [&r](Key k) { - r.append(new PassKeyModel(k)); + QList ret; + std::for_each(keys.begin(), keys.end(), [&ret](Key k) { + ret.append(new PassKeyModel(k)); }); - return r; + return ret; }; QString uid() const { - return m_uid; - }; - bool secret() const - { - return m_secret; - }; - bool expired() const - { - return m_expired; + return QString::fromUtf8(m_key.keyID()); }; - void setUid(QString uid) + QList userIds() const { - m_uid = uid; - emit uidChanged(uid); - } - void setSecret(bool secret) - { - m_secret = secret; - emit secretChanged(secret); - } - void setExpired(bool expired) - { - m_expired = expired; - emit expiredChanged(expired); - } + auto user_ids = m_key.userIDs(); + QList ret; + std::for_each(user_ids.begin(), user_ids.end(), [&ret](UserID k) { + ret.append(new UserIdModel(k)); + }); + return ret; + }; -signals: - void uidChanged(QString); - void secretChanged(bool); - void expiredChanged(bool); + bool isSecret() const + { + return m_key.hasSecret(); + }; + + bool isExpired() const + { + return m_key.hasSecret(); + }; }; + + + #endif diff --git a/po/utpass.qrouland.pot b/po/utpass.qrouland.pot index ae0ef3f..5940020 100644 --- a/po/utpass.qrouland.pot +++ b/po/utpass.qrouland.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: utpass.qrouland\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-01-14 09:52+0100\n" +"POT-Creation-Date: 2025-01-14 12:17+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -67,19 +67,19 @@ msgstr "" msgid "Maintainer" msgstr "" -#: ../qml/pages/Info.qml:109 +#: ../qml/pages/Info.qml:108 msgid "Suggest improvement(s) or report a bug(s)" msgstr "" -#: ../qml/pages/Info.qml:114 +#: ../qml/pages/Info.qml:113 msgid "Access to the source code" msgstr "" -#: ../qml/pages/Info.qml:122 +#: ../qml/pages/Info.qml:121 msgid "Released under the terms of the GNU GPL v3" msgstr "" -#: ../qml/pages/Info.qml:131 ../qml/pages/headers/MainHeader.qml:33 +#: ../qml/pages/Info.qml:130 ../qml/pages/headers/MainHeader.qml:33 msgid "Info" msgstr "" @@ -125,7 +125,8 @@ msgid "" msgstr "" #: ../qml/pages/settings/ImportGitClone.qml:91 -#: ../qml/pages/settings/ImportZip.qml:62 ../qml/pages/settings/InfoKeys.qml:77 +#: ../qml/pages/settings/ImportZip.qml:62 +#: ../qml/pages/settings/InfoKeys.qml:117 msgid "Yes" msgstr "" @@ -167,27 +168,31 @@ msgstr "" msgid "Zip Password Store Import" msgstr "" -#: ../qml/pages/settings/InfoKeys.qml:41 -msgid "Key id : %1" +#: ../qml/pages/settings/InfoKeys.qml:39 +msgid "Key ID :" msgstr "" -#: ../qml/pages/settings/InfoKeys.qml:54 +#: ../qml/pages/settings/InfoKeys.qml:72 +msgid "Users IDs : " +msgstr "" + +#: ../qml/pages/settings/InfoKeys.qml:96 msgid "Delete this key" msgstr "" -#: ../qml/pages/settings/InfoKeys.qml:76 +#: ../qml/pages/settings/InfoKeys.qml:116 msgid "You're are about to delete
%1
Continue ?" msgstr "" -#: ../qml/pages/settings/InfoKeys.qml:94 +#: ../qml/pages/settings/InfoKeys.qml:134 msgid "Key removal failed !" msgstr "" -#: ../qml/pages/settings/InfoKeys.qml:103 +#: ../qml/pages/settings/InfoKeys.qml:143 msgid "Key successfully deleted !" msgstr "" -#: ../qml/pages/settings/InfoKeys.qml:114 +#: ../qml/pages/settings/InfoKeys.qml:154 msgid "Info Keys" msgstr "" diff --git a/qml/pages/Info.qml b/qml/pages/Info.qml index 35dd756..8e5e29f 100644 --- a/qml/pages/Info.qml +++ b/qml/pages/Info.qml @@ -95,7 +95,6 @@ Page { font.pixelSize: 72 color: theme.palette.normal.backgroundText } - } Flow { diff --git a/qml/pages/settings/InfoKeys.qml b/qml/pages/settings/InfoKeys.qml index 0d7031c..34fbcfa 100644 --- a/qml/pages/settings/InfoKeys.qml +++ b/qml/pages/settings/InfoKeys.qml @@ -33,15 +33,57 @@ Page { } Text { - id: uidKey - width: parent.width horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter - text: i18n.tr('Key id : %1').arg(model.modelData.uid) + text: i18n.tr('Key ID :') color: theme.palette.normal.backgroundText } + Text { + width: parent.width + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + text: model.modelData.uid + color: theme.palette.normal.backgroundText + } + + + Rectangle { + width: parent.width + height: units.gu(1) + color: theme.palette.normal.background + } + + ListModel { + id: userIdsModel + + Component.onCompleted: { + for(var i=0; i< model.modelData.userIds.length; ++i){ + userIdsModel.append({"model": model.modelData.userIds[i]}) + } + } + } + + Text { + width: parent.width + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + text: i18n.tr('Users IDs : ') + color: theme.palette.normal.backgroundText + } + + Repeater { + model: userIdsModel + Text { + width: parent.width + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + text: modelData.uid + color: theme.palette.normal.backgroundText + } + } + Rectangle { width: parent.width height: units.gu(1) @@ -64,9 +106,7 @@ Page { height: units.gu(1) color: theme.palette.normal.background } - } - } Component {