[evolution-data-server] Add useful GBinding transform funcs from e-util.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Add useful GBinding transform funcs from e-util.
- Date: Tue, 15 Nov 2011 16:23:14 +0000 (UTC)
commit a8dcfca3229f7649e635ef996f2222c647039206
Author: Matthew Barnes <mbarnes redhat com>
Date: Tue Nov 15 11:03:07 2011 -0500
Add useful GBinding transform funcs from e-util.
e_binding_transform_enum_value_to_nick()
e_binding_transform_enum_nick_to_value()
.../libedataserver/libedataserver-sections.txt | 2 +
libedataserver/e-data-server-util.c | 78 ++++++++++++++++++++
libedataserver/e-data-server-util.h | 14 +++-
3 files changed, 93 insertions(+), 1 deletions(-)
---
diff --git a/docs/reference/libedataserver/libedataserver-sections.txt b/docs/reference/libedataserver/libedataserver-sections.txt
index 1bd5ada..0099fcf 100644
--- a/docs/reference/libedataserver/libedataserver-sections.txt
+++ b/docs/reference/libedataserver/libedataserver-sections.txt
@@ -549,6 +549,8 @@ e_util_copy_string_slist
e_util_copy_object_slist
e_util_free_string_slist
e_util_free_object_slist
+e_binding_transform_enum_value_to_nick
+e_binding_transform_enum_nick_to_value
e_util_get_prefix
e_util_get_cp_prefix
e_util_get_localedir
diff --git a/libedataserver/e-data-server-util.c b/libedataserver/e-data-server-util.c
index 5228d09..c7211a2 100644
--- a/libedataserver/e-data-server-util.c
+++ b/libedataserver/e-data-server-util.c
@@ -946,6 +946,84 @@ e_util_free_object_slist (GSList *objects)
g_slist_free_full (objects, (GDestroyNotify) g_object_unref);
}
+/**
+ * e_binding_transform_enum_value_to_nick:
+ * @binding: a #GBinding
+ * @source_value: a #GValue whose type is derived from #G_TYPE_ENUM
+ * @target_value: a #GValue of type #G_TYPE_STRING
+ * @not_used: not used
+ *
+ * Transforms an enumeration value to its corresponding nickname.
+ *
+ * Returns: %TRUE if the enum value has a corresponding nickname
+ *
+ * Since: 3.4
+ **/
+gboolean
+e_binding_transform_enum_value_to_nick (GBinding *binding,
+ const GValue *source_value,
+ GValue *target_value,
+ gpointer not_used)
+{
+ GEnumClass *enum_class;
+ GEnumValue *enum_value;
+ gint value;
+ gboolean success = FALSE;
+
+ g_return_val_if_fail (G_IS_BINDING (binding), FALSE);
+
+ enum_class = g_type_class_peek (G_VALUE_TYPE (source_value));
+ g_return_val_if_fail (G_IS_ENUM_CLASS (enum_class), FALSE);
+
+ value = g_value_get_enum (source_value);
+ enum_value = g_enum_get_value (enum_class, value);
+ if (enum_value != NULL) {
+ g_value_set_string (target_value, enum_value->value_nick);
+ success = TRUE;
+ }
+
+ return success;
+}
+
+/**
+ * e_binding_transform_enum_nick_to_value:
+ * @binding: a #GBinding
+ * @source_value: a #GValue of type #G_TYPE_STRING
+ * @target_value: a #GValue whose type is derived from #G_TYPE_ENUM
+ * @not_used: not used
+ *
+ * Transforms an enumeration nickname to its corresponding value.
+ *
+ * Returns: %TRUE if the enum nickname has a corresponding value
+ *
+ * Since: 3.4
+ **/
+gboolean
+e_binding_transform_enum_nick_to_value (GBinding *binding,
+ const GValue *source_value,
+ GValue *target_value,
+ gpointer not_used)
+{
+ GEnumClass *enum_class;
+ GEnumValue *enum_value;
+ const gchar *string;
+ gboolean success = FALSE;
+
+ g_return_val_if_fail (G_IS_BINDING (binding), FALSE);
+
+ enum_class = g_type_class_peek (G_VALUE_TYPE (target_value));
+ g_return_val_if_fail (G_IS_ENUM_CLASS (enum_class), FALSE);
+
+ string = g_value_get_string (source_value);
+ enum_value = g_enum_get_value_by_nick (enum_class, string);
+ if (enum_value != NULL) {
+ g_value_set_enum (target_value, enum_value->value);
+ success = TRUE;
+ }
+
+ return success;
+}
+
#ifdef G_OS_WIN32
#include <windows.h>
diff --git a/libedataserver/e-data-server-util.h b/libedataserver/e-data-server-util.h
index 8162b0c..8450c63 100644
--- a/libedataserver/e-data-server-util.h
+++ b/libedataserver/e-data-server-util.h
@@ -23,7 +23,7 @@
#define E_DATA_SERVER_UTIL_H
#include <sys/types.h>
-#include <glib.h>
+#include <glib-object.h>
G_BEGIN_DECLS
@@ -70,6 +70,18 @@ GSList * e_util_copy_object_slist (GSList *copy_to, const GSList *objects);
void e_util_free_string_slist (GSList *strings);
void e_util_free_object_slist (GSList *objects);
+/* Useful GBinding transform functions */
+gboolean e_binding_transform_enum_value_to_nick
+ (GBinding *binding,
+ const GValue *source_value,
+ GValue *target_value,
+ gpointer not_used);
+gboolean e_binding_transform_enum_nick_to_value
+ (GBinding *binding,
+ const GValue *source_value,
+ GValue *target_value,
+ gpointer not_used);
+
#ifdef G_OS_WIN32
const gchar * e_util_get_prefix (void) G_GNUC_CONST;
const gchar * e_util_get_cp_prefix (void) G_GNUC_CONST;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]