[evolution-data-server] Provide e_util_get_source_full_name() to describe source with parents
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Provide e_util_get_source_full_name() to describe source with parents
- Date: Fri, 12 Jun 2015 10:01:24 +0000 (UTC)
commit 83bc48e6b3e8e785438b442b7743213dd7e2e3b5
Author: Milan Crha <mcrha redhat com>
Date: Fri Jun 12 12:00:24 2015 +0200
Provide e_util_get_source_full_name() to describe source with parents
docs/reference/eds/eds-sections.txt | 1 +
libedataserver/e-data-server-util.c | 78 +++++++++++++++++++++++++++++++++++
libedataserver/e-data-server-util.h | 5 ++
3 files changed, 84 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/eds/eds-sections.txt b/docs/reference/eds/eds-sections.txt
index 9139209..bc77cb6 100644
--- a/docs/reference/eds/eds-sections.txt
+++ b/docs/reference/eds/eds-sections.txt
@@ -2146,6 +2146,7 @@ e_data_server_util_set_dbus_call_timeout
e_binding_bind_property
e_binding_bind_property_full
e_binding_bind_property_with_closures
+e_util_get_source_full_name
ENamedParameters
EAsyncClosure
tm
diff --git a/libedataserver/e-data-server-util.c b/libedataserver/e-data-server-util.c
index 79a5cf2..528220c 100644
--- a/libedataserver/e-data-server-util.c
+++ b/libedataserver/e-data-server-util.c
@@ -32,7 +32,9 @@
#include <glib-object.h>
+#include "e-source.h"
#include "e-source-enumtypes.h"
+#include "e-source-registry.h"
#include "camel/camel.h"
#include "e-data-server-util.h"
@@ -2685,3 +2687,79 @@ e_type_traverse (GType parent_type,
g_free (children);
}
+
+/**
+ * e_util_get_source_full_name:
+ * @registry: an #ESourceRegistry
+ * @source: an #ESource
+ *
+ * Constructs a full name of the @source with all of its parents
+ * of the form: "<account-name> : <parent>/<source>" where
+ * the "<parent>/" part can be repeated zero or more times, depending
+ * on the deep level of the @source.
+ *
+ * Returns: (transfer full): Full name of the @source as a newly allocated
+ * string, which should be freed with g_free() when done with it.
+ *
+ * Since 3.18
+ **/
+gchar *
+e_util_get_source_full_name (ESourceRegistry *registry,
+ ESource *source)
+{
+ GString *fullname;
+ GSList *parts, *link;
+
+ g_return_val_if_fail (E_IS_SOURCE (source), NULL);
+
+ if (!registry)
+ return g_strdup (e_source_get_display_name (source));
+
+ parts = NULL;
+
+ parts = g_slist_prepend (parts, g_strdup (e_source_get_display_name (source)));
+
+ g_object_ref (source);
+ while (source) {
+ const gchar *parent_id;
+ ESource *parent;
+
+ parent_id = e_source_get_parent (source);
+ if (!parent_id || !*parent_id)
+ break;
+
+ parent = e_source_registry_ref_source (registry, parent_id);
+ g_object_unref (source);
+ source = parent;
+
+ if (source) {
+ const gchar *display_name = e_source_get_display_name (source);
+
+ if (!display_name || !*display_name)
+ break;
+
+ parts = g_slist_prepend (parts, g_strdup (display_name));
+ }
+ }
+
+ g_object_unref (source);
+
+ fullname = g_string_new ("");
+
+ for (link = parts; link; link = link->next) {
+ const gchar *part = link->data;
+
+ if (fullname->len) {
+ if (link == parts->next)
+ g_string_append (fullname, " : ");
+ else
+ g_string_append_c (fullname, '/');
+ }
+
+ g_string_append (fullname, part);
+ }
+
+ g_slist_free_full (parts, g_free);
+
+ return g_string_free (fullname, FALSE);
+}
diff --git a/libedataserver/e-data-server-util.h b/libedataserver/e-data-server-util.h
index 0d2aec7..ddcba0a 100644
--- a/libedataserver/e-data-server-util.h
+++ b/libedataserver/e-data-server-util.h
@@ -34,6 +34,8 @@
G_BEGIN_DECLS
struct tm;
+struct _ESource;
+struct _ESourceRegistry;
const gchar * e_get_user_cache_dir (void);
const gchar * e_get_user_config_dir (void);
@@ -266,6 +268,9 @@ void e_type_traverse (GType parent_type,
ETypeFunc func,
gpointer user_data);
+gchar * e_util_get_source_full_name (struct _ESourceRegistry *registry,
+ struct _ESource *source);
+
G_END_DECLS
#endif /* E_DATA_SERVER_UTIL_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]