[seahorse/wip/nielsdg/remove-more-deprecated: 3/8] pgp: Uid: Don't use g_type_class_add_private()
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seahorse/wip/nielsdg/remove-more-deprecated: 3/8] pgp: Uid: Don't use g_type_class_add_private()
- Date: Tue, 19 Feb 2019 05:43:13 +0000 (UTC)
commit 6111da4b417808f2405bc39b6ae52b2ae0488fb1
Author: Niels De Graef <nielsdegraef gmail com>
Date: Tue Feb 19 05:47:39 2019 +0100
pgp: Uid: Don't use g_type_class_add_private()
It's been deprecated a while now in favor of `G_ADD_PRIVATE ()`
pgp/seahorse-pgp-uid.c | 653 +++++++++++++++++++++++++------------------------
pgp/seahorse-pgp-uid.h | 3 +-
2 files changed, 330 insertions(+), 326 deletions(-)
---
diff --git a/pgp/seahorse-pgp-uid.c b/pgp/seahorse-pgp-uid.c
index 210351df..ed5309c7 100644
--- a/pgp/seahorse-pgp-uid.c
+++ b/pgp/seahorse-pgp-uid.c
@@ -30,27 +30,27 @@
#include <glib/gi18n.h>
enum {
- PROP_0,
- PROP_PARENT,
- PROP_SIGNATURES,
- PROP_VALIDITY,
- PROP_NAME,
- PROP_EMAIL,
- PROP_COMMENT
+ PROP_0,
+ PROP_PARENT,
+ PROP_SIGNATURES,
+ PROP_VALIDITY,
+ PROP_NAME,
+ PROP_EMAIL,
+ PROP_COMMENT
};
-G_DEFINE_TYPE (SeahorsePgpUid, seahorse_pgp_uid, SEAHORSE_TYPE_OBJECT);
-
struct _SeahorsePgpUidPrivate {
- SeahorsePgpKey *parent;
- GList *signatures;
- SeahorseValidity validity;
- gboolean realized;
- gchar *name;
- gchar *email;
- gchar *comment;
+ SeahorsePgpKey *parent;
+ GList *signatures;
+ SeahorseValidity validity;
+ gboolean realized;
+ gchar *name;
+ gchar *email;
+ gchar *comment;
};
+G_DEFINE_TYPE_WITH_PRIVATE (SeahorsePgpUid, seahorse_pgp_uid, SEAHORSE_TYPE_OBJECT);
+
/* -----------------------------------------------------------------------------
* INTERNAL HELPERS
*/
@@ -58,14 +58,14 @@ struct _SeahorsePgpUidPrivate {
static gchar*
convert_string (const gchar *str)
{
- if (!str)
- return NULL;
-
- /* If not utf8 valid, assume latin 1 */
- if (!g_utf8_validate (str, -1, NULL))
- return g_convert (str, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
-
- return g_strdup (str);
+ if (!str)
+ return NULL;
+
+ /* If not utf8 valid, assume latin 1 */
+ if (!g_utf8_validate (str, -1, NULL))
+ return g_convert (str, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
+
+ return g_strdup (str);
}
#ifndef HAVE_STRSEP
@@ -86,7 +86,7 @@ strsep (char **stringp, const char *delim)
char ch = delim[0];
if (ch == '\0')
- end = NULL;
+ end = NULL;
else {
if (*begin == ch)
end = begin;
@@ -115,455 +115,458 @@ strsep (char **stringp, const char *delim)
static void
parse_user_id (const gchar *uid, gchar **name, gchar **email, gchar **comment)
{
- gchar *src, *tail, *x;
+ gchar *src, *tail;
+ g_autofree gchar *x = NULL;
int in_name = 0;
int in_email = 0;
int in_comment = 0;
x = tail = src = g_strdup (uid);
-
+
while (*src) {
if (in_email) {
- if (*src == '<')
- /* Not legal but anyway. */
- in_email++;
- else if (*src == '>') {
- if (!--in_email && !*email) {
- *email = tail;
+ if (*src == '<')
+ /* Not legal but anyway. */
+ in_email++;
+ else if (*src == '>') {
+ if (!--in_email && !*email) {
+ *email = tail;
*src = 0;
tail = src + 1;
- }
- }
- } else if (in_comment) {
- if (*src == '(')
- in_comment++;
- else if (*src == ')') {
- if (!--in_comment && !*comment) {
- *comment = tail;
+ }
+ }
+ } else if (in_comment) {
+ if (*src == '(')
+ in_comment++;
+ else if (*src == ')') {
+ if (!--in_comment && !*comment) {
+ *comment = tail;
*src = 0;
tail = src + 1;
- }
- }
- } else if (*src == '<') {
- if (in_name) {
- if (!*name) {
- *name = tail;
+ }
+ }
+ } else if (*src == '<') {
+ if (in_name) {
+ if (!*name) {
+ *name = tail;
*src = 0;
tail = src + 1;
- }
- in_name = 0;
- } else
- tail = src + 1;
-
- in_email = 1;
- } else if (*src == '(') {
- if (in_name) {
- if (!*name) {
- *name = tail;
+ }
+ in_name = 0;
+ } else
+ tail = src + 1;
+
+ in_email = 1;
+ } else if (*src == '(') {
+ if (in_name) {
+ if (!*name) {
+ *name = tail;
*src = 0;
tail = src + 1;
- }
- in_name = 0;
- }
- in_comment = 1;
- } else if (!in_name && *src != ' ' && *src != '\t') {
- in_name = 1;
- }
+ }
+ in_name = 0;
+ }
+ in_comment = 1;
+ } else if (!in_name && *src != ' ' && *src != '\t') {
+ in_name = 1;
+ }
src++;
}
-
+
if (in_name) {
if (!*name) {
- *name = tail;
+ *name = tail;
*src = 0;
tail = src + 1;
- }
+ }
}
-
+
/* Let unused parts point to an EOS. */
*name = g_strdup (*name ? *name : "");
*email = g_strdup (*email ? *email : "");
*comment = g_strdup (*comment ? *comment : "");
-
+
g_strstrip (*name);
g_strstrip (*email);
g_strstrip (*comment);
-
- g_free (x);
}
/* -----------------------------------------------------------------------------
- * OBJECT
+ * OBJECT
*/
void
seahorse_pgp_uid_realize (SeahorsePgpUid *self)
{
- gchar *markup;
- gchar *label;
+ SeahorsePgpUidPrivate *priv = seahorse_pgp_uid_get_instance_private (self);
+ g_autofree gchar *markup = NULL;
+ g_autofree gchar *label = NULL;
- /* Don't realize if no name present */
- if (!self->pv->name)
- return;
+ /* Don't realize if no name present */
+ if (!priv->name)
+ return;
- self->pv->realized = TRUE;
+ priv->realized = TRUE;
- label = seahorse_pgp_uid_calc_label (self->pv->name, self->pv->email, self->pv->comment);
- markup = seahorse_pgp_uid_calc_markup (self->pv->name, self->pv->email, self->pv->comment, 0);
- g_object_set (self, "markup", markup, "label", label, NULL);
- g_free (markup);
- g_free (label);
+ label = seahorse_pgp_uid_calc_label (priv->name, priv->email, priv->comment);
+ markup = seahorse_pgp_uid_calc_markup (priv->name, priv->email, priv->comment, 0);
+ g_object_set (self, "markup", markup, "label", label, NULL);
}
static void
seahorse_pgp_uid_init (SeahorsePgpUid *self)
{
- self->pv = G_TYPE_INSTANCE_GET_PRIVATE (self, SEAHORSE_PGP_TYPE_UID, SeahorsePgpUidPrivate);
- g_object_set (self, "icon", NULL, "usage", SEAHORSE_USAGE_IDENTITY, NULL);
+ g_object_set (self, "icon", NULL, "usage", SEAHORSE_USAGE_IDENTITY, NULL);
}
static void
seahorse_pgp_uid_constructed (GObject *object)
{
- G_OBJECT_CLASS (seahorse_pgp_uid_parent_class)->constructed (object);
- seahorse_pgp_uid_realize (SEAHORSE_PGP_UID (object));
+ G_OBJECT_CLASS (seahorse_pgp_uid_parent_class)->constructed (object);
+ seahorse_pgp_uid_realize (SEAHORSE_PGP_UID (object));
}
static void
seahorse_pgp_uid_get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
- SeahorsePgpUid *self = SEAHORSE_PGP_UID (object);
-
- switch (prop_id) {
- case PROP_SIGNATURES:
- g_value_set_boxed (value, seahorse_pgp_uid_get_signatures (self));
- break;
- case PROP_PARENT:
- g_value_set_object (value, seahorse_pgp_uid_get_parent (self));
- break;
- case PROP_VALIDITY:
- g_value_set_uint (value, seahorse_pgp_uid_get_validity (self));
- break;
- case PROP_NAME:
- g_value_set_string (value, seahorse_pgp_uid_get_name (self));
- break;
- case PROP_EMAIL:
- g_value_set_string (value, seahorse_pgp_uid_get_email (self));
- break;
- case PROP_COMMENT:
- g_value_set_string (value, seahorse_pgp_uid_get_comment (self));
- break;
- }
+ SeahorsePgpUid *self = SEAHORSE_PGP_UID (object);
+
+ switch (prop_id) {
+ case PROP_SIGNATURES:
+ g_value_set_boxed (value, seahorse_pgp_uid_get_signatures (self));
+ break;
+ case PROP_PARENT:
+ g_value_set_object (value, seahorse_pgp_uid_get_parent (self));
+ break;
+ case PROP_VALIDITY:
+ g_value_set_uint (value, seahorse_pgp_uid_get_validity (self));
+ break;
+ case PROP_NAME:
+ g_value_set_string (value, seahorse_pgp_uid_get_name (self));
+ break;
+ case PROP_EMAIL:
+ g_value_set_string (value, seahorse_pgp_uid_get_email (self));
+ break;
+ case PROP_COMMENT:
+ g_value_set_string (value, seahorse_pgp_uid_get_comment (self));
+ break;
+ }
}
static void
-seahorse_pgp_uid_set_property (GObject *object, guint prop_id, const GValue *value,
+seahorse_pgp_uid_set_property (GObject *object, guint prop_id, const GValue *value,
GParamSpec *pspec)
{
- SeahorsePgpUid *self = SEAHORSE_PGP_UID (object);
-
- 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 (self->pv->parent == NULL);
- self->pv->parent = g_value_get_object (value);
- break;
- case PROP_VALIDITY:
- seahorse_pgp_uid_set_validity (self, g_value_get_uint (value));
- break;
- case PROP_NAME:
- seahorse_pgp_uid_set_name (self, g_value_get_string (value));
- break;
- case PROP_EMAIL:
- seahorse_pgp_uid_set_email (self, g_value_get_string (value));
- break;
- case PROP_COMMENT:
- seahorse_pgp_uid_set_comment (self, g_value_get_string (value));
- break;
- }
+ SeahorsePgpUid *self = SEAHORSE_PGP_UID (object);
+ 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);
+ break;
+ case PROP_VALIDITY:
+ seahorse_pgp_uid_set_validity (self, g_value_get_uint (value));
+ break;
+ case PROP_NAME:
+ seahorse_pgp_uid_set_name (self, g_value_get_string (value));
+ break;
+ case PROP_EMAIL:
+ seahorse_pgp_uid_set_email (self, g_value_get_string (value));
+ break;
+ case PROP_COMMENT:
+ seahorse_pgp_uid_set_comment (self, g_value_get_string (value));
+ break;
+ }
}
static void
seahorse_pgp_uid_object_finalize (GObject *gobject)
{
- SeahorsePgpUid *self = SEAHORSE_PGP_UID (gobject);
-
- seahorse_object_list_free (self->pv->signatures);
- self->pv->signatures = NULL;
-
- g_free (self->pv->name);
- self->pv->name = NULL;
-
- g_free (self->pv->email);
- self->pv->email = NULL;
-
- g_free (self->pv->comment);
- self->pv->comment = NULL;
-
- G_OBJECT_CLASS (seahorse_pgp_uid_parent_class)->finalize (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_pointer (&priv->name, g_free);
+ g_clear_pointer (&priv->email, g_free);
+ g_clear_pointer (&priv->comment, g_free);
+
+ G_OBJECT_CLASS (seahorse_pgp_uid_parent_class)->finalize (gobject);
}
static void
seahorse_pgp_uid_class_init (SeahorsePgpUidClass *klass)
{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-
- seahorse_pgp_uid_parent_class = g_type_class_peek_parent (klass);
- g_type_class_add_private (klass, sizeof (SeahorsePgpUidPrivate));
-
- gobject_class->constructed = seahorse_pgp_uid_constructed;
- gobject_class->finalize = seahorse_pgp_uid_object_finalize;
- gobject_class->set_property = seahorse_pgp_uid_set_property;
- gobject_class->get_property = seahorse_pgp_uid_get_property;
-
- g_object_class_install_property (gobject_class, PROP_VALIDITY,
- g_param_spec_uint ("validity", "Validity", "Validity of this identity",
- 0, G_MAXUINT, 0, G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_PARENT,
- g_param_spec_object ("parent", "Parent Key", "Parent Key",
- SEAHORSE_PGP_TYPE_KEY, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
- g_object_class_install_property (gobject_class, PROP_NAME,
- g_param_spec_string ("name", "Name", "User ID name",
- "", G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_EMAIL,
- g_param_spec_string ("email", "Email", "User ID email",
- "", G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_COMMENT,
- g_param_spec_string ("comment", "Comment", "User ID comment",
- "", G_PARAM_READWRITE));
-
- 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));
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->constructed = seahorse_pgp_uid_constructed;
+ gobject_class->finalize = seahorse_pgp_uid_object_finalize;
+ gobject_class->set_property = seahorse_pgp_uid_set_property;
+ gobject_class->get_property = seahorse_pgp_uid_get_property;
+
+ g_object_class_install_property (gobject_class, PROP_VALIDITY,
+ g_param_spec_uint ("validity", "Validity", "Validity of this identity",
+ 0, G_MAXUINT, 0,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (gobject_class, PROP_PARENT,
+ g_param_spec_object ("parent", "Parent Key", "Parent Key",
+ SEAHORSE_PGP_TYPE_KEY,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY));
+
+ g_object_class_install_property (gobject_class, PROP_NAME,
+ g_param_spec_string ("name", "Name", "User ID name",
+ "", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (gobject_class, PROP_EMAIL,
+ g_param_spec_string ("email", "Email", "User ID email",
+ "", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (gobject_class, PROP_COMMENT,
+ g_param_spec_string ("comment", "Comment", "User ID comment",
+ "", 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));
}
/* -----------------------------------------------------------------------------
- * PUBLIC
+ * PUBLIC
*/
SeahorsePgpUid *
seahorse_pgp_uid_new (SeahorsePgpKey *parent,
const gchar *uid_string)
{
- SeahorsePgpUid *uid;
- gchar *name = NULL;
- gchar *email = NULL;
- gchar *comment = NULL;
-
- if (uid_string)
- parse_user_id (uid_string, &name, &email, &comment);
-
- uid = g_object_new (SEAHORSE_PGP_TYPE_UID,
- "parent", parent,
- "name", name,
- "email", email,
- "comment", comment,
- NULL);
-
- g_free (name);
- g_free (comment);
- g_free (email);
-
- return uid;
+ g_autofree gchar *name = NULL;
+ g_autofree gchar *email = NULL;
+ g_autofree gchar *comment = NULL;
+
+ if (uid_string)
+ parse_user_id (uid_string, &name, &email, &comment);
+
+ return g_object_new (SEAHORSE_PGP_TYPE_UID,
+ "parent", parent,
+ "name", name,
+ "email", email,
+ "comment", comment,
+ NULL);
}
SeahorsePgpKey *
seahorse_pgp_uid_get_parent (SeahorsePgpUid *self)
{
- g_return_val_if_fail (SEAHORSE_PGP_IS_UID (self), NULL);
- return self->pv->parent;
+ SeahorsePgpUidPrivate *priv = seahorse_pgp_uid_get_instance_private (self);
+
+ g_return_val_if_fail (SEAHORSE_PGP_IS_UID (self), NULL);
+ return priv->parent;
}
GList*
seahorse_pgp_uid_get_signatures (SeahorsePgpUid *self)
{
- g_return_val_if_fail (SEAHORSE_PGP_IS_UID (self), NULL);
- return self->pv->signatures;
+ SeahorsePgpUidPrivate *priv = seahorse_pgp_uid_get_instance_private (self);
+
+ g_return_val_if_fail (SEAHORSE_PGP_IS_UID (self), NULL);
+ return priv->signatures;
}
void
seahorse_pgp_uid_set_signatures (SeahorsePgpUid *self, GList *signatures)
{
- g_return_if_fail (SEAHORSE_PGP_IS_UID (self));
-
- seahorse_object_list_free (self->pv->signatures);
- self->pv->signatures = seahorse_object_list_copy (signatures);
-
- g_object_notify (G_OBJECT (self), "signatures");
+ SeahorsePgpUidPrivate *priv = seahorse_pgp_uid_get_instance_private (self);
+
+ g_return_if_fail (SEAHORSE_PGP_IS_UID (self));
+
+ seahorse_object_list_free (priv->signatures);
+ priv->signatures = seahorse_object_list_copy (signatures);
+
+ g_object_notify (G_OBJECT (self), "signatures");
}
SeahorseValidity
seahorse_pgp_uid_get_validity (SeahorsePgpUid *self)
{
- g_return_val_if_fail (SEAHORSE_PGP_IS_UID (self), SEAHORSE_VALIDITY_UNKNOWN);
- return self->pv->validity;
+ SeahorsePgpUidPrivate *priv = seahorse_pgp_uid_get_instance_private (self);
+
+ g_return_val_if_fail (SEAHORSE_PGP_IS_UID (self), SEAHORSE_VALIDITY_UNKNOWN);
+ return priv->validity;
}
void
seahorse_pgp_uid_set_validity (SeahorsePgpUid *self, SeahorseValidity validity)
{
- g_return_if_fail (SEAHORSE_PGP_IS_UID (self));
- self->pv->validity = validity;
- g_object_notify (G_OBJECT (self), "validity");
+ SeahorsePgpUidPrivate *priv = seahorse_pgp_uid_get_instance_private (self);
+
+ g_return_if_fail (SEAHORSE_PGP_IS_UID (self));
+ priv->validity = validity;
+ g_object_notify (G_OBJECT (self), "validity");
}
const gchar*
seahorse_pgp_uid_get_name (SeahorsePgpUid *self)
{
- g_return_val_if_fail (SEAHORSE_PGP_IS_UID (self), NULL);
- if (!self->pv->name)
- self->pv->name = g_strdup ("");
- return self->pv->name;
+ SeahorsePgpUidPrivate *priv = seahorse_pgp_uid_get_instance_private (self);
+
+ g_return_val_if_fail (SEAHORSE_PGP_IS_UID (self), NULL);
+ if (!priv->name)
+ priv->name = g_strdup ("");
+ return priv->name;
}
void
seahorse_pgp_uid_set_name (SeahorsePgpUid *self, const gchar *name)
{
- GObject *obj;
-
- g_return_if_fail (SEAHORSE_PGP_IS_UID (self));
-
- g_free (self->pv->name);
- self->pv->name = convert_string (name);
-
- obj = G_OBJECT (self);
- g_object_freeze_notify (obj);
- if (!self->pv->realized)
- seahorse_pgp_uid_realize (self);
- g_object_notify (obj, "name");
- g_object_thaw_notify (obj);
+ SeahorsePgpUidPrivate *priv = seahorse_pgp_uid_get_instance_private (self);
+ GObject *obj;
+
+ g_return_if_fail (SEAHORSE_PGP_IS_UID (self));
+
+ g_free (priv->name);
+ priv->name = convert_string (name);
+
+ obj = G_OBJECT (self);
+ g_object_freeze_notify (obj);
+ if (!priv->realized)
+ seahorse_pgp_uid_realize (self);
+ g_object_notify (obj, "name");
+ g_object_thaw_notify (obj);
}
const gchar*
seahorse_pgp_uid_get_email (SeahorsePgpUid *self)
{
- g_return_val_if_fail (SEAHORSE_PGP_IS_UID (self), NULL);
- if (!self->pv->email)
- self->pv->email = g_strdup ("");
- return self->pv->email;
+ SeahorsePgpUidPrivate *priv = seahorse_pgp_uid_get_instance_private (self);
+
+ g_return_val_if_fail (SEAHORSE_PGP_IS_UID (self), NULL);
+ if (!priv->email)
+ priv->email = g_strdup ("");
+ return priv->email;
}
void
seahorse_pgp_uid_set_email (SeahorsePgpUid *self, const gchar *email)
{
- GObject *obj;
-
- g_return_if_fail (SEAHORSE_PGP_IS_UID (self));
-
- g_free (self->pv->email);
- self->pv->email = convert_string (email);
-
- obj = G_OBJECT (self);
- g_object_freeze_notify (obj);
- if (!self->pv->realized)
- seahorse_pgp_uid_realize (self);
- g_object_notify (obj, "email");
- g_object_thaw_notify (obj);
+ SeahorsePgpUidPrivate *priv = seahorse_pgp_uid_get_instance_private (self);
+ GObject *obj;
+
+ g_return_if_fail (SEAHORSE_PGP_IS_UID (self));
+
+ g_free (priv->email);
+ priv->email = convert_string (email);
+
+ obj = G_OBJECT (self);
+ g_object_freeze_notify (obj);
+ if (!priv->realized)
+ seahorse_pgp_uid_realize (self);
+ g_object_notify (obj, "email");
+ g_object_thaw_notify (obj);
}
const gchar*
seahorse_pgp_uid_get_comment (SeahorsePgpUid *self)
{
- g_return_val_if_fail (SEAHORSE_PGP_IS_UID (self), NULL);
- if (!self->pv->comment)
- self->pv->comment = g_strdup ("");
- return self->pv->comment;
+ SeahorsePgpUidPrivate *priv = seahorse_pgp_uid_get_instance_private (self);
+
+ g_return_val_if_fail (SEAHORSE_PGP_IS_UID (self), NULL);
+ if (!priv->comment)
+ priv->comment = g_strdup ("");
+ return priv->comment;
}
void
seahorse_pgp_uid_set_comment (SeahorsePgpUid *self, const gchar *comment)
{
- GObject *obj;
-
- g_return_if_fail (SEAHORSE_PGP_IS_UID (self));
-
- g_free (self->pv->comment);
- self->pv->comment = convert_string (comment);
-
- obj = G_OBJECT (self);
- g_object_freeze_notify (obj);
- if (!self->pv->realized)
- seahorse_pgp_uid_realize (self);
- g_object_notify (obj, "comment");
- g_object_thaw_notify (obj);
+ SeahorsePgpUidPrivate *priv = seahorse_pgp_uid_get_instance_private (self);
+ GObject *obj;
+
+ g_return_if_fail (SEAHORSE_PGP_IS_UID (self));
+
+ g_free (priv->comment);
+ priv->comment = convert_string (comment);
+
+ obj = G_OBJECT (self);
+ g_object_freeze_notify (obj);
+ if (!priv->realized)
+ seahorse_pgp_uid_realize (self);
+ g_object_notify (obj, "comment");
+ g_object_thaw_notify (obj);
}
gchar*
-seahorse_pgp_uid_calc_label (const gchar *name, const gchar *email,
+seahorse_pgp_uid_calc_label (const gchar *name, const gchar *email,
const gchar *comment)
{
- GString *string;
-
- g_return_val_if_fail (name, NULL);
-
- string = g_string_new ("");
- g_string_append (string, name);
-
- if (email && email[0]) {
- g_string_append (string, " <");
- g_string_append (string, email);
- g_string_append (string, ">");
- }
-
- if (comment && comment[0]) {
- g_string_append (string, " (");
- g_string_append (string, comment);
- g_string_append (string, ")");
- }
-
- return g_string_free (string, FALSE);
+ GString *string;
+
+ g_return_val_if_fail (name, NULL);
+
+ string = g_string_new ("");
+ g_string_append (string, name);
+
+ if (email && email[0]) {
+ g_string_append (string, " <");
+ g_string_append (string, email);
+ g_string_append (string, ">");
+ }
+
+ if (comment && comment[0]) {
+ g_string_append (string, " (");
+ g_string_append (string, comment);
+ g_string_append (string, ")");
+ }
+
+ return g_string_free (string, FALSE);
}
gchar*
-seahorse_pgp_uid_calc_markup (const gchar *name, const gchar *email,
+seahorse_pgp_uid_calc_markup (const gchar *name, const gchar *email,
const gchar *comment, guint flags)
{
- const gchar *format;
- gboolean strike = FALSE;
- gboolean grayed = FALSE;
-
- g_return_val_if_fail (name, NULL);
-
- if (flags & SEAHORSE_FLAG_EXPIRED || flags & SEAHORSE_FLAG_REVOKED ||
- flags & SEAHORSE_FLAG_DISABLED)
- strike = TRUE;
- if (!(flags & SEAHORSE_FLAG_TRUSTED))
- grayed = TRUE;
-
- if (strike && grayed)
- format = "<span strikethrough='true' foreground='#555555'>%s<span size='small'
rise='0'>%s%s%s%s%s</span></span>";
- else if (grayed)
- format = "<span foreground='#555555'>%s<span size='small' rise='0'>%s%s%s%s%s</span></span>";
- else if (strike)
- format = "<span strikethrough='true'>%s<span foreground='#555555' size='small'
rise='0'>%s%s%s%s%s</span></span>";
- else
- format = "%s<span foreground='#555555' size='small' rise='0'>%s%s%s%s%s</span>";
-
- return g_markup_printf_escaped (format, name,
- email && email[0] ? " " : "",
- email && email[0] ? email : "",
- comment && comment[0] ? " '" : "",
- comment && comment[0] ? comment : "",
- comment && comment[0] ? "'" : "");
+ const gchar *format;
+ gboolean strike = FALSE;
+ gboolean grayed = FALSE;
+
+ g_return_val_if_fail (name, NULL);
+
+ if (flags & SEAHORSE_FLAG_EXPIRED || flags & SEAHORSE_FLAG_REVOKED ||
+ flags & SEAHORSE_FLAG_DISABLED)
+ strike = TRUE;
+ if (!(flags & SEAHORSE_FLAG_TRUSTED))
+ grayed = TRUE;
+
+ if (strike && grayed)
+ format = "<span strikethrough='true' foreground='#555555'>%s<span size='small'
rise='0'>%s%s%s%s%s</span></span>";
+ else if (grayed)
+ format = "<span foreground='#555555'>%s<span size='small' rise='0'>%s%s%s%s%s</span></span>";
+ else if (strike)
+ format = "<span strikethrough='true'>%s<span foreground='#555555' size='small'
rise='0'>%s%s%s%s%s</span></span>";
+ else
+ format = "%s<span foreground='#555555' size='small' rise='0'>%s%s%s%s%s</span>";
+
+ return g_markup_printf_escaped (format, name,
+ email && email[0] ? " " : "",
+ email && email[0] ? email : "",
+ comment && comment[0] ? " '" : "",
+ comment && comment[0] ? comment : "",
+ comment && comment[0] ? "'" : "");
}
GQuark
seahorse_pgp_uid_calc_id (GQuark key_id, guint index)
{
- gchar *str = NULL;
- GQuark id = 0;
-
- str = g_strdup_printf ("%s:%u", g_quark_to_string (key_id), index + 1);
- id = g_quark_from_string (str);
- g_free (str);
-
- return id;
+ g_autofree gchar *str = NULL;
+ GQuark id = 0;
+
+ str = g_strdup_printf ("%s:%u", g_quark_to_string (key_id), index + 1);
+ id = g_quark_from_string (str);
+
+ return id;
}
diff --git a/pgp/seahorse-pgp-uid.h b/pgp/seahorse-pgp-uid.h
index 3346bdf2..b3a31de9 100644
--- a/pgp/seahorse-pgp-uid.h
+++ b/pgp/seahorse-pgp-uid.h
@@ -39,13 +39,14 @@ typedef struct _SeahorsePgpUidPrivate SeahorsePgpUidPrivate;
struct _SeahorsePgpUid {
SeahorseObject parent;
- SeahorsePgpUidPrivate *pv;
};
struct _SeahorsePgpUidClass {
SeahorseObjectClass parent_class;
};
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (SeahorsePgpUid, g_object_unref)
+
GType seahorse_pgp_uid_get_type (void);
SeahorsePgpUid* seahorse_pgp_uid_new (SeahorsePgpKey *parent,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]