[seahorse/object-list-bye: 1/4] pgp: Expose UID's signatures as GListModel
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seahorse/object-list-bye: 1/4] pgp: Expose UID's signatures as GListModel
- Date: Mon, 22 Feb 2021 17:34:46 +0000 (UTC)
commit 84007f71c44357639b186d2e40f4317cc52d4917
Author: Niels De Graef <nielsdegraef gmail com>
Date: Mon Feb 22 18:20:47 2021 +0100
pgp: Expose UID's signatures as GListModel
pgp/seahorse-gpgme-uid.c | 9 +++-----
pgp/seahorse-pgp-key-properties.c | 28 ++++++++++++++---------
pgp/seahorse-pgp-uid.c | 47 +++++++++++++++++++++++++++------------
pgp/seahorse-pgp-uid.h | 9 +++++---
4 files changed, 59 insertions(+), 34 deletions(-)
---
diff --git a/pgp/seahorse-gpgme-uid.c b/pgp/seahorse-gpgme-uid.c
index 8570513b..eac4c248 100644
--- a/pgp/seahorse-gpgme-uid.c
+++ b/pgp/seahorse-gpgme-uid.c
@@ -66,8 +66,6 @@ static void
realize_signatures (SeahorseGpgmeUid *self)
{
gpgme_key_sig_t gsig;
- SeahorsePgpSignature *sig;
- GList *sigs = NULL;
guint flags;
g_return_if_fail (self->pubkey);
@@ -78,6 +76,8 @@ realize_signatures (SeahorseGpgmeUid *self)
return;
for (gsig = self->userid->signatures; gsig; gsig = gsig->next) {
+ g_autoptr(SeahorsePgpSignature) sig = NULL;
+
sig = seahorse_pgp_signature_new (gsig->keyid);
/* Order of parsing these flags is important */
@@ -92,11 +92,8 @@ realize_signatures (SeahorseGpgmeUid *self)
flags |= SEAHORSE_FLAG_EXPORTABLE;
seahorse_pgp_signature_set_flags (sig, flags);
- sigs = g_list_prepend (sigs, sig);
+ seahorse_pgp_uid_add_signature (SEAHORSE_PGP_UID (self), sig);
}
-
- seahorse_pgp_uid_set_signatures (SEAHORSE_PGP_UID (self), sigs);
- seahorse_object_list_free (sigs);
}
static gboolean
diff --git a/pgp/seahorse-pgp-key-properties.c b/pgp/seahorse-pgp-key-properties.c
index 79ef8e1c..86765806 100644
--- a/pgp/seahorse-pgp-key-properties.c
+++ b/pgp/seahorse-pgp-key-properties.c
@@ -377,7 +377,6 @@ names_populate (SeahorsePgpKeyProperties *self, GtkTreeStore *store, SeahorsePgp
GtkTreeIter uiditer, sigiter;
GList *keys, *l;
GListModel *uids;
- GList *sigs, *s;
/* Insert all the fun-ness */
uids = seahorse_pgp_key_get_uids (pkey);
@@ -387,6 +386,7 @@ names_populate (SeahorsePgpKeyProperties *self, GtkTreeStore *store, SeahorsePgp
g_autoptr(GIcon) icon = NULL;
g_autoptr(GPtrArray) keyids = NULL;
g_autoptr(GCancellable) cancellable = NULL;
+ GListModel *sigs;
uid = g_list_model_get_item (uids, i);
icon = g_themed_icon_new ("avatar-default-symbolic");
@@ -401,11 +401,13 @@ names_populate (SeahorsePgpKeyProperties *self, GtkTreeStore *store, SeahorsePgp
/* Build a list of all the keyids */
sigs = seahorse_pgp_uid_get_signatures (uid);
- for (s = sigs; s; s = g_list_next (s)) {
+ for (guint j = 0; j < g_list_model_get_n_items (sigs); j++) {
+ g_autoptr(SeahorsePgpSignature) sig = g_list_model_get_item (sigs, j);
+
/* Never show self signatures, they're implied */
- if (seahorse_pgp_key_has_keyid (pkey, seahorse_pgp_signature_get_keyid (s->data)))
+ if (seahorse_pgp_key_has_keyid (pkey, seahorse_pgp_signature_get_keyid (sig)))
continue;
- g_ptr_array_add (keyids, (gpointer)seahorse_pgp_signature_get_keyid (s->data));
+ g_ptr_array_add (keyids, (void *) seahorse_pgp_signature_get_keyid (sig));
}
g_ptr_array_add (keyids, NULL);
@@ -1467,7 +1469,6 @@ signatures_populate_model (SeahorsePgpKeyProperties *self, SeahorseObjectModel *
gboolean have_sigs = FALSE;
g_autoptr(GPtrArray) rawids = NULL;
GListModel *uids;
- GList *sigs, *s;
GList *keys, *l;
if (self->signatures_tree == NULL)
@@ -1479,14 +1480,18 @@ signatures_populate_model (SeahorsePgpKeyProperties *self, SeahorseObjectModel *
/* Build a list of all the keyids */
for (guint i = 0; i < g_list_model_get_n_items (uids); i++) {
g_autoptr(SeahorsePgpUid) uid = g_list_model_get_item (uids, i);
+ GListModel *sigs;
+
sigs = seahorse_pgp_uid_get_signatures (uid);
- for (s = sigs; s; s = g_list_next (s)) {
+ for (guint j = 0; j < g_list_model_get_n_items (sigs); j++) {
+ g_autoptr(SeahorsePgpSignature) sig = g_list_model_get_item (sigs, j);
+
/* Never show self signatures, they're implied */
if (seahorse_pgp_key_has_keyid (self->key,
- seahorse_pgp_signature_get_keyid (s->data)))
+ seahorse_pgp_signature_get_keyid (sig)))
continue;
have_sigs = TRUE;
- g_ptr_array_add (rawids, (gchar *)seahorse_pgp_signature_get_keyid (s->data));
+ g_ptr_array_add (rawids, (char *) seahorse_pgp_signature_get_keyid (sig));
}
}
@@ -1560,11 +1565,12 @@ key_have_signatures (SeahorsePgpKey *pkey, guint types)
uids = seahorse_pgp_key_get_uids (pkey);
for (guint i = 0; i < g_list_model_get_n_items (uids); i++) {
g_autoptr(SeahorsePgpUid) uid = g_list_model_get_item (uids, i);
- GList *sigs;
+ GListModel *sigs;
sigs = seahorse_pgp_uid_get_signatures (uid);
- for (GList *s = sigs; s; s = g_list_next (s)) {
- if (seahorse_pgp_signature_get_sigtype (s->data) & types)
+ for (guint j = 0; j < g_list_model_get_n_items (sigs); j++) {
+ g_autoptr(SeahorsePgpSignature) sig = g_list_model_get_item (sigs, j);
+ if (seahorse_pgp_signature_get_sigtype (sig) & types)
return TRUE;
}
}
diff --git a/pgp/seahorse-pgp-uid.c b/pgp/seahorse-pgp-uid.c
index cc431f1f..ac8377e4 100644
--- a/pgp/seahorse-pgp-uid.c
+++ b/pgp/seahorse-pgp-uid.c
@@ -41,7 +41,7 @@ enum {
typedef struct _SeahorsePgpUidPrivate {
SeahorsePgpKey *parent;
- GList *signatures;
+ GListModel *signatures;
SeahorseValidity validity;
gboolean realized;
char *name;
@@ -217,6 +217,9 @@ seahorse_pgp_uid_realize (SeahorsePgpUid *self)
static void
seahorse_pgp_uid_init (SeahorsePgpUid *self)
{
+ SeahorsePgpUidPrivate *priv = seahorse_pgp_uid_get_instance_private (self);
+
+ priv->signatures = G_LIST_MODEL (g_list_store_new (SEAHORSE_PGP_TYPE_SIGNATURE));
g_object_set (self, "icon", NULL, "usage", SEAHORSE_USAGE_IDENTITY, NULL);
}
@@ -235,7 +238,7 @@ seahorse_pgp_uid_get_property (GObject *object, guint prop_id,
switch (prop_id) {
case PROP_SIGNATURES:
- g_value_set_boxed (value, seahorse_pgp_uid_get_signatures (self));
+ g_value_set_object (value, seahorse_pgp_uid_get_signatures (self));
break;
case PROP_PARENT:
g_value_set_object (value, seahorse_pgp_uid_get_parent (self));
@@ -263,9 +266,6 @@ seahorse_pgp_uid_set_property (GObject *object, guint prop_id, const GValue *val
SeahorsePgpUidPrivate *priv = seahorse_pgp_uid_get_instance_private (self);
switch (prop_id) {
- case PROP_SIGNATURES:
- seahorse_pgp_uid_set_signatures (self, g_value_get_boxed (value));
- break;
case PROP_PARENT:
g_return_if_fail (priv->parent == NULL);
priv->parent = g_value_get_object (value);
@@ -291,7 +291,7 @@ seahorse_pgp_uid_object_finalize (GObject *gobject)
SeahorsePgpUid *self = SEAHORSE_PGP_UID (gobject);
SeahorsePgpUidPrivate *priv = seahorse_pgp_uid_get_instance_private (self);
- g_clear_pointer (&priv->signatures, seahorse_object_list_free);
+ g_clear_object (&priv->signatures);
g_clear_pointer (&priv->name, g_free);
g_clear_pointer (&priv->email, g_free);
g_clear_pointer (&priv->comment, g_free);
@@ -332,9 +332,9 @@ seahorse_pgp_uid_class_init (SeahorsePgpUidClass *klass)
"", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_SIGNATURES,
- g_param_spec_boxed ("signatures", "Signatures", "Signatures on this UID",
- SEAHORSE_BOXED_OBJECT_LIST,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_param_spec_object ("signatures", "Signatures", "Signatures on this UID",
+ G_TYPE_LIST_MODEL,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
}
/* -----------------------------------------------------------------------------
@@ -369,7 +369,7 @@ seahorse_pgp_uid_get_parent (SeahorsePgpUid *self)
return priv->parent;
}
-GList*
+GListModel *
seahorse_pgp_uid_get_signatures (SeahorsePgpUid *self)
{
SeahorsePgpUidPrivate *priv = seahorse_pgp_uid_get_instance_private (self);
@@ -379,16 +379,35 @@ seahorse_pgp_uid_get_signatures (SeahorsePgpUid *self)
}
void
-seahorse_pgp_uid_set_signatures (SeahorsePgpUid *self, GList *signatures)
+seahorse_pgp_uid_add_signature (SeahorsePgpUid *self,
+ SeahorsePgpSignature *signature)
+{
+ SeahorsePgpUidPrivate *priv = seahorse_pgp_uid_get_instance_private (self);
+
+ g_return_if_fail (SEAHORSE_PGP_IS_UID (self));
+ g_return_if_fail (SEAHORSE_PGP_IS_SIGNATURE (signature));
+
+ g_list_store_append (G_LIST_STORE (priv->signatures), signature);
+}
+
+void
+seahorse_pgp_uid_remove_signature (SeahorsePgpUid *self,
+ SeahorsePgpSignature *signature)
{
SeahorsePgpUidPrivate *priv = seahorse_pgp_uid_get_instance_private (self);
g_return_if_fail (SEAHORSE_PGP_IS_UID (self));
+ g_return_if_fail (SEAHORSE_PGP_IS_SIGNATURE (signature));
- seahorse_object_list_free (priv->signatures);
- priv->signatures = seahorse_object_list_copy (signatures);
+ for (guint i = 0; i < g_list_model_get_n_items (priv->signatures); i++) {
+ g_autoptr(SeahorsePgpSignature) sig = NULL;
- g_object_notify (G_OBJECT (self), "signatures");
+ sig = g_list_model_get_item (priv->signatures, i);
+ if (signature == sig) {
+ g_list_store_remove (G_LIST_STORE (priv->signatures), i);
+ break;
+ }
+ }
}
SeahorseValidity
diff --git a/pgp/seahorse-pgp-uid.h b/pgp/seahorse-pgp-uid.h
index 9c03db45..efde122d 100644
--- a/pgp/seahorse-pgp-uid.h
+++ b/pgp/seahorse-pgp-uid.h
@@ -39,10 +39,13 @@ SeahorsePgpKey * seahorse_pgp_uid_get_parent (SeahorsePgpUid *self);
void seahorse_pgp_uid_realize (SeahorsePgpUid *self);
-GList* seahorse_pgp_uid_get_signatures (SeahorsePgpUid *self);
+GListModel * seahorse_pgp_uid_get_signatures (SeahorsePgpUid *self);
-void seahorse_pgp_uid_set_signatures (SeahorsePgpUid *self,
- GList *signatures);
+void seahorse_pgp_uid_add_signature (SeahorsePgpUid *self,
+ SeahorsePgpSignature *signature);
+
+void seahorse_pgp_uid_remove_signature (SeahorsePgpUid *self,
+ SeahorsePgpSignature *signature);
SeahorseValidity seahorse_pgp_uid_get_validity (SeahorsePgpUid *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]