[tracker/evo-new-api] Evolution: Add demo code for listing available CamelStores.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/evo-new-api] Evolution: Add demo code for listing available CamelStores.
- Date: Thu, 5 Jul 2012 21:15:04 +0000 (UTC)
commit 5c90bd39a4d86ad85aa0976a55422bc5aea43509
Author: Matthew Barnes <mbarnes redhat com>
Date: Thu Jul 5 17:10:04 2012 -0400
Evolution: Add demo code for listing available CamelStores.
src/plugins/evolution/tracker-evolution-plugin.c | 73 ++++++++++++++++++++++
1 files changed, 73 insertions(+), 0 deletions(-)
---
diff --git a/src/plugins/evolution/tracker-evolution-plugin.c b/src/plugins/evolution/tracker-evolution-plugin.c
index 4991a58..cb3c820 100644
--- a/src/plugins/evolution/tracker-evolution-plugin.c
+++ b/src/plugins/evolution/tracker-evolution-plugin.c
@@ -102,6 +102,70 @@ tracker_miner_evolution_set_mail_session (TrackerMinerEvolution *miner,
g_weak_ref_set (&miner->priv->mail_session, mail_session);
}
+static GList *
+tracker_miner_evolution_list_mail_stores (TrackerMinerEvolution *miner)
+{
+ EMailSession *mail_session;
+ ESourceRegistry *registry;
+ GList *list, *link;
+ GList *stores = NULL;
+ const gchar *extension_name;
+
+ /* XXX This is just demonstration code showing how to build
+ * a list of available CamelStores with the new EDS API. */
+
+ mail_session = tracker_miner_evolution_ref_mail_session (miner);
+
+ /* XXX You'll probably also want to listen for "source-added"
+ * and "source-removed" signals from the ESourceRegistry. */
+ registry = e_mail_session_get_registry (mail_session);
+
+ /* List all ESources having a [Mail Account] extension. */
+ extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
+ list = e_source_registry_list_sources (registry, extension_name);
+
+ for (link = list; link != NULL; link = g_list_next (link)) {
+ ESource *source = E_SOURCE (link->data);
+ CamelService *service;
+ const gchar *uid;
+
+ uid = e_source_get_uid (source);
+
+ /* Skip Search Folders. */
+ if (g_strcmp0 (uid, E_MAIL_SESSION_VFOLDER_UID) == 0)
+ continue;
+
+ /* CamelServices share the same UID as the corresponding
+ * ESource, so we can just query the CamelSession by the
+ * mail account ESource UID. */
+ service = camel_session_get_service (CAMEL_SESSION (mail_session), uid);
+
+ /* The service returned should be a CamelStore. */
+ if (!CAMEL_IS_STORE (service)) {
+ g_warning (
+ "%s: Expected a CamelStore for UID "
+ "'%s' but instead got %s", G_STRFUNC,
+ uid, (service == NULL) ? "bupkis!" :
+ G_OBJECT_TYPE_NAME (service));
+ continue;
+ }
+
+ /* Reference the service so it doesn't disappear on us. */
+ stores = g_list_prepend (stores, g_object_ref (service));
+
+ g_debug (
+ "%s: Found %s (\"%s\")",
+ G_STRFUNC, G_OBJECT_TYPE_NAME (service),
+ camel_service_get_display_name (service));
+ }
+
+ g_list_free_full (list, (GDestroyNotify) g_object_unref);
+
+ g_object_unref (mail_session);
+
+ return stores;
+}
+
static void
miner_evolution_initable_iface_init (GInitableIface *iface)
{
@@ -186,6 +250,14 @@ tracker_miner_evolution_finalize (GObject *plugin)
}
static void
+tracker_miner_evolution_constructed (GObject *object)
+{
+ G_OBJECT_CLASS (tracker_miner_evolution_parent_class)->constructed (object);
+
+ tracker_miner_evolution_list_mail_stores (TRACKER_MINER_EVOLUTION (object));
+}
+
+static void
tracker_miner_evolution_class_init (TrackerMinerEvolutionClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -201,6 +273,7 @@ tracker_miner_evolution_class_init (TrackerMinerEvolutionClass *klass)
object_class->set_property = tracker_miner_evolution_set_property;
object_class->get_property = tracker_miner_evolution_get_property;
object_class->finalize = tracker_miner_evolution_finalize;
+ object_class->constructed = tracker_miner_evolution_constructed;
g_type_class_add_private (object_class, sizeof (TrackerMinerEvolutionPrivate));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]