aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2010-10-21 12:20:57 +0800
committerMatthew Barnes <mbarnes@redhat.com>2010-10-21 12:24:46 +0800
commit18447890ffbbcb3667056a554116f97b65d106b6 (patch)
treed54839b8d813b54996f2d3f196e1acf086b1bc89 /e-util
parent4a08257b83512cc32b73d732ccc53266a22b917c (diff)
downloadgsoc2013-evolution-18447890ffbbcb3667056a554116f97b65d106b6.tar
gsoc2013-evolution-18447890ffbbcb3667056a554116f97b65d106b6.tar.gz
gsoc2013-evolution-18447890ffbbcb3667056a554116f97b65d106b6.tar.bz2
gsoc2013-evolution-18447890ffbbcb3667056a554116f97b65d106b6.tar.lz
gsoc2013-evolution-18447890ffbbcb3667056a554116f97b65d106b6.tar.xz
gsoc2013-evolution-18447890ffbbcb3667056a554116f97b65d106b6.tar.zst
gsoc2013-evolution-18447890ffbbcb3667056a554116f97b65d106b6.zip
ESignatureList cleanups.
Diffstat (limited to 'e-util')
-rw-r--r--e-util/e-signature-list.c186
-rw-r--r--e-util/e-signature-list.h85
-rw-r--r--e-util/e-signature-utils.c14
3 files changed, 159 insertions, 126 deletions
diff --git a/e-util/e-signature-list.c b/e-util/e-signature-list.c
index bcc476bfc8..7a58e8fea4 100644
--- a/e-util/e-signature-list.c
+++ b/e-util/e-signature-list.c
@@ -21,15 +21,16 @@
*
*/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "e-signature-list.h"
+#include <config.h>
#include <string.h>
#include <libedataserver/e-uid.h>
-#include "e-signature-list.h"
+#define E_SIGNATURE_LIST_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_SIGNATURE_LIST, ESignatureListPrivate))
struct _ESignatureListPrivate {
GConfClient *gconf;
@@ -46,80 +47,73 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
-static void e_signature_list_finalize (GObject *object);
-static void e_signature_list_dispose (GObject *object);
-
G_DEFINE_TYPE (
ESignatureList,
e_signature_list,
E_TYPE_LIST)
static void
-e_signature_list_class_init (ESignatureListClass *klass)
-{
- GObjectClass *object_class = (GObjectClass *) klass;
-
- object_class->dispose = e_signature_list_dispose;
- object_class->finalize = e_signature_list_finalize;
-
- signals[SIGNATURE_ADDED] =
- g_signal_new ("signature-added",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (ESignatureListClass, signature_added),
- NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE, 1,
- E_TYPE_SIGNATURE);
- signals[SIGNATURE_CHANGED] =
- g_signal_new ("signature-changed",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (ESignatureListClass, signature_changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE, 1,
- E_TYPE_SIGNATURE);
- signals[SIGNATURE_REMOVED] =
- g_signal_new ("signature-removed",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (ESignatureListClass, signature_removed),
- NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE, 1,
- E_TYPE_SIGNATURE);
-}
-
-static void
-e_signature_list_init (ESignatureList *list)
-{
- list->priv = g_new0 (struct _ESignatureListPrivate, 1);
-}
-
-static void
e_signature_list_dispose (GObject *object)
{
ESignatureList *list = (ESignatureList *) object;
if (list->priv->gconf) {
if (list->priv->notify_id != 0)
- gconf_client_notify_remove (list->priv->gconf, list->priv->notify_id);
+ gconf_client_notify_remove (
+ list->priv->gconf, list->priv->notify_id);
g_object_unref (list->priv->gconf);
list->priv->gconf = NULL;
}
+ /* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (e_signature_list_parent_class)->dispose (object);
}
static void
-e_signature_list_finalize (GObject *object)
+e_signature_list_class_init (ESignatureListClass *class)
{
- ESignatureList *list = (ESignatureList *) object;
+ GObjectClass *object_class;
+
+ g_type_class_add_private (class, sizeof (ESignatureListPrivate));
- g_free (list->priv);
+ object_class = G_OBJECT_CLASS (class);
+ object_class->dispose = e_signature_list_dispose;
- G_OBJECT_CLASS (e_signature_list_parent_class)->finalize (object);
+ signals[SIGNATURE_ADDED] = g_signal_new (
+ "signature-added",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (ESignatureListClass, signature_added),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1,
+ E_TYPE_SIGNATURE);
+
+ signals[SIGNATURE_CHANGED] = g_signal_new (
+ "signature-changed",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (ESignatureListClass, signature_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1,
+ E_TYPE_SIGNATURE);
+
+ signals[SIGNATURE_REMOVED] = g_signal_new (
+ "signature-removed",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (ESignatureListClass, signature_removed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1,
+ E_TYPE_SIGNATURE);
+}
+
+static void
+e_signature_list_init (ESignatureList *signature_list)
+{
+ signature_list->priv = E_SIGNATURE_LIST_GET_PRIVATE (signature_list);
}
static GSList *
@@ -398,51 +392,83 @@ e_signature_list_remove (ESignatureList *signature_list, ESignature *signature)
}
/**
- * e_signature_list_find:
- * @signature_list: signature list
- * @type: Type of search.
- * @key: Search key.
+ * e_signature_list_find_by_name:
+ * @signature_list: an #ESignatureList
+ * @name: the signature name to find
*
- * Perform a search of the signature list on a single key.
+ * Searches @signature_list for the given signature name.
*
- * @type must be set from one of the following search types:
- * E_SIGNATURE_FIND_NAME - Find a signature by signature name.
- * E_SIGNATURE_FIND_UID - Find a signature based on UID
+ * Returns: the matching signature or %NULL if it doesn't exist
+ **/
+ESignature *
+e_signature_list_find_by_name (ESignatureList *signature_list,
+ const gchar *signature_name)
+{
+ ESignature *signature = NULL;
+ EIterator *it;
+
+ g_return_val_if_fail (E_IS_SIGNATURE_LIST (signature_list), NULL);
+
+ /* this could use a callback for more flexibility ...
+ ... but this makes the common cases easier */
+
+ if (signature_name == NULL)
+ return NULL;
+
+ for (it = e_list_get_iterator (E_LIST (signature_list));
+ e_iterator_is_valid (it);
+ e_iterator_next (it)) {
+ const gchar *value;
+
+ /* XXX EIterator misuses const. */
+ signature = (ESignature *) e_iterator_get (it);
+ value = e_signature_get_name (signature);
+
+ if (g_strcmp0 (value, signature_name) == 0)
+ break;
+
+ signature = NULL;
+ }
+
+ g_object_unref (it);
+
+ return signature;
+}
+
+/**
+ * e_signature_list_find_by_uid:
+ * @signature_list: an #ESignatureList
+ * @name: the signature UID to find
+ *
+ * Searches @signature_list for the given signature UID.
*
- * Return value: The signature or NULL if it doesn't exist.
+ * Returns: the matching signature or %NULL if it doesn't exist
**/
-const ESignature *
-e_signature_list_find (ESignatureList *signature_list,
- e_signature_find_t type,
- const gchar *key)
+ESignature *
+e_signature_list_find_by_uid (ESignatureList *signature_list,
+ const gchar *signature_uid)
{
ESignature *signature = NULL;
EIterator *it;
+ g_return_val_if_fail (E_IS_SIGNATURE_LIST (signature_list), NULL);
+
/* this could use a callback for more flexibility ...
... but this makes the common cases easier */
- if (!key)
+ if (signature_uid == NULL)
return NULL;
- for (it = e_list_get_iterator ((EList *) signature_list);
+ for (it = e_list_get_iterator (E_LIST (signature_list));
e_iterator_is_valid (it);
e_iterator_next (it)) {
const gchar *value = NULL;
/* XXX EIterator misuses const. */
signature = (ESignature *) e_iterator_get (it);
+ value = e_signature_get_uid (signature);
- switch (type) {
- case E_SIGNATURE_FIND_NAME:
- value = e_signature_get_name (signature);
- break;
- case E_SIGNATURE_FIND_UID:
- value = e_signature_get_uid (signature);
- break;
- }
-
- if (g_strcmp0 (value, key) == 0)
+ if (g_strcmp0 (value, signature_uid) == 0)
break;
signature = NULL;
diff --git a/e-util/e-signature-list.h b/e-util/e-signature-list.h
index b662272180..f2c9df7865 100644
--- a/e-util/e-signature-list.h
+++ b/e-util/e-signature-list.h
@@ -21,55 +21,72 @@
*
*/
-#ifndef __E_SIGNATURE_LIST__
-#define __E_SIGNATURE_LIST__
+#ifndef E_SIGNATURE_LIST_H
+#define E_SIGNATURE_LIST_H
#include <libedataserver/e-list.h>
#include <e-util/e-signature.h>
#include <gconf/gconf-client.h>
-#define E_TYPE_SIGNATURE_LIST (e_signature_list_get_type ())
-#define E_SIGNATURE_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_SIGNATURE_LIST, ESignatureList))
-#define E_SIGNATURE_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), E_TYPE_SIGNATURE_LIST, ESignatureListClass))
-#define E_IS_SIGNATURE_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_SIGNATURE_LIST))
-#define E_IS_SIGNATURE_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), E_TYPE_SIGNATURE_LIST))
+/* Standard GObject macros */
+#define E_TYPE_SIGNATURE_LIST \
+ (e_signature_list_get_type ())
+#define E_SIGNATURE_LIST(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), E_TYPE_SIGNATURE_LIST, ESignatureList))
+#define E_SIGNATURE_LIST_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_CAST \
+ ((cls), E_TYPE_SIGNATURE_LIST, ESignatureListClass))
+#define E_IS_SIGNATURE_LIST(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), E_TYPE_SIGNATURE_LIST))
+#define E_IS_SIGNATURE_LIST_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_TYPE \
+ ((cls), E_TYPE_SIGNATURE_LIST))
+#define E_SIGNATURE_LIST_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), E_TYPE_SIGNATURE_LIST, ESignatureListClass))
+
+G_BEGIN_DECLS
typedef struct _ESignatureList ESignatureList;
typedef struct _ESignatureListClass ESignatureListClass;
-
-/* search options for the find command */
-typedef enum {
- E_SIGNATURE_FIND_NAME,
- E_SIGNATURE_FIND_UID
-} e_signature_find_t;
+typedef struct _ESignatureListPrivate ESignatureListPrivate;
struct _ESignatureList {
- EList parent_object;
-
- struct _ESignatureListPrivate *priv;
+ EList parent;
+ ESignatureListPrivate *priv;
};
struct _ESignatureListClass {
EListClass parent_class;
- /* signals */
- void (* signature_added) (ESignatureList *, ESignature *);
- void (* signature_changed) (ESignatureList *, ESignature *);
- void (* signature_removed) (ESignatureList *, ESignature *);
+ /* Signals */
+ void (*signature_added) (ESignatureList *signature_list,
+ ESignature *signature);
+ void (*signature_changed) (ESignatureList *signature_list,
+ ESignature *signature);
+ void (*signature_removed) (ESignatureList *signature_list,
+ ESignature *signature);
};
-GType e_signature_list_get_type (void);
-
-ESignatureList *e_signature_list_new (GConfClient *gconf);
-void e_signature_list_construct (ESignatureList *signature_list, GConfClient *gconf);
-
-void e_signature_list_save (ESignatureList *signature_list);
-
-void e_signature_list_add (ESignatureList *signature_list, ESignature *signature);
-void e_signature_list_change (ESignatureList *signature_list, ESignature *signature);
-void e_signature_list_remove (ESignatureList *signature_list, ESignature *signature);
-
-const ESignature *e_signature_list_find (ESignatureList *signature_list, e_signature_find_t type, const gchar *key);
-
-#endif /* __E_SIGNATURE_LIST__ */
+GType e_signature_list_get_type (void);
+ESignatureList *e_signature_list_new (GConfClient *client);
+void e_signature_list_construct (ESignatureList *signature_list,
+ GConfClient *client);
+void e_signature_list_save (ESignatureList *signature_list);
+void e_signature_list_add (ESignatureList *signature_list,
+ ESignature *signature);
+void e_signature_list_change (ESignatureList *signature_list,
+ ESignature *signature);
+void e_signature_list_remove (ESignatureList *signature_list,
+ ESignature *signature);
+ESignature * e_signature_list_find_by_name (ESignatureList *signature_list,
+ const gchar *signature_name);
+ESignature * e_signature_list_find_by_uid (ESignatureList *signature_list,
+ const gchar *signature_uid);
+
+G_END_DECLS
+
+#endif /* E_SIGNATURE_LIST_H */
diff --git a/e-util/e-signature-utils.c b/e-util/e-signature-utils.c
index d42d6f325d..8c190791d5 100644
--- a/e-util/e-signature-utils.c
+++ b/e-util/e-signature-utils.c
@@ -52,34 +52,24 @@ ESignature *
e_get_signature_by_name (const gchar *name)
{
ESignatureList *signature_list;
- const ESignature *signature;
- e_signature_find_t find;
g_return_val_if_fail (name != NULL, NULL);
- find = E_SIGNATURE_FIND_NAME;
signature_list = e_get_signature_list ();
- signature = e_signature_list_find (signature_list, find, name);
- /* XXX ESignatureList misuses const. */
- return (ESignature *) signature;
+ return e_signature_list_find_by_name (signature_list, name);
}
ESignature *
e_get_signature_by_uid (const gchar *uid)
{
ESignatureList *signature_list;
- const ESignature *signature;
- e_signature_find_t find;
g_return_val_if_fail (uid != NULL, NULL);
- find = E_SIGNATURE_FIND_UID;
signature_list = e_get_signature_list ();
- signature = e_signature_list_find (signature_list, find, uid);
- /* XXX ESignatureList misuses const. */
- return (ESignature *) signature;
+ return e_signature_list_find_by_uid (signature_list, uid);
}
gchar *