[gnome-calendar/calendar-management] manager: implement GcalManager::get_origin method
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/calendar-management] manager: implement GcalManager::get_origin method
- Date: Tue, 3 Feb 2015 17:30:02 +0000 (UTC)
commit fd17907def51c59681e977c435db65f9a2d2843b
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Tue Feb 3 13:11:48 2015 -0200
manager: implement GcalManager::get_origin method
This method retrieves the ESource's origin information needed by the source management dialog.
src/gcal-manager.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++
src/gcal-manager.h | 3 ++
2 files changed, 74 insertions(+), 0 deletions(-)
---
diff --git a/src/gcal-manager.c b/src/gcal-manager.c
index 03d985e..87dee02 100644
--- a/src/gcal-manager.c
+++ b/src/gcal-manager.c
@@ -1066,3 +1066,74 @@ gcal_manager_get_events (GcalManager *manager,
return list;
}
+/**
+ * gcal_manager_get_origin:
+ * @manager: a { link GcalManager} instance.
+ * @source: the reference { link ESource}.
+ *
+ * Tries to find the origin of the given @source.
+ * It's achieved by looking though the @source's
+ * parents until it finds a matching one.
+ *
+ * Returns: a newly allocated { link GcalSourceOrigin}.
+ */
+GcalSourceOrigin*
+gcal_manager_get_origin (GcalManager *manager,
+ ESource *source)
+{
+ GcalManagerPrivate *priv = gcal_manager_get_instance_private (manager);
+ GcalSourceOrigin *origin;
+ ESource *parent;
+ gchar *old_uid;
+
+ old_uid = NULL;
+ origin = g_new0 (GcalSourceOrigin, 1);
+
+ origin->source = source;
+
+ while (TRUE)
+ {
+ const gchar *parent_uid;
+
+ parent_uid = e_source_get_parent (source);
+ parent = e_source_registry_ref_source (priv->source_registry, parent_uid);
+
+ if (g_strcmp0 (old_uid, parent_uid) == 0)
+ break;
+
+ /**
+ * If the source has a GOA extension,
+ * do simple checks to find out the
+ * origin.
+ */
+ if (e_source_has_extension (parent, E_SOURCE_EXTENSION_GOA))
+ {
+ /* Google */
+ if (g_str_has_suffix (parent_uid, "gmail.com"))
+ origin->name = "Google";
+
+ /**
+ * The only other source that supports
+ * calendars is ownCloud
+ */
+ else
+ origin->name = "ownCloud";
+
+ origin->account = e_source_get_display_name (parent);
+ }
+ else
+ {
+ origin->name = e_source_get_display_name (parent);
+ origin->account = NULL;
+ }
+
+ if (old_uid != NULL)
+ g_free (old_uid);
+
+ old_uid = g_strdup (parent_uid);
+
+ g_object_unref (parent);
+ }
+
+ return origin;
+}
diff --git a/src/gcal-manager.h b/src/gcal-manager.h
index ee130d9..ab00258 100644
--- a/src/gcal-manager.h
+++ b/src/gcal-manager.h
@@ -130,6 +130,9 @@ GList* gcal_manager_get_events (GcalManager *manager
icaltimetype *range_start,
icaltimetype *range_end);
+GcalSourceOrigin* gcal_manager_get_origin (GcalManager *manager,
+ ESource *source);
+
G_END_DECLS
#endif /* __GCAL_MANAGER_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]