[gnome-shell] contact-system: Add helper method to get a (display) email



commit 503508af416ad7913c67d8100708f2f49b90f765
Author: Florian MÃllner <fmuellner gnome org>
Date:   Wed Oct 5 20:11:13 2011 +0200

    contact-system: Add helper method to get a (display) email
    
    Folks uses collection/set objects from libgee to store email addresses
    associated with an individual. Unfortunately to extract addresses, parts
    of libgee which are unusable from (introspected) bindings have to be
    used[0], so add a helper method.
    
    [0] in particular gee_iterator_get(), which is annotated as
        "return: (transfer full): gpointer"
    
    https://bugzilla.gnome.org/show_bug.cgi?id=660580

 src/shell-contact-system.c |   51 ++++++++++++++++++++++++++++++++++++++++++++
 src/shell-contact-system.h |    3 ++
 2 files changed, 54 insertions(+), 0 deletions(-)
---
diff --git a/src/shell-contact-system.c b/src/shell-contact-system.c
index bca4255..fae4898 100644
--- a/src/shell-contact-system.c
+++ b/src/shell-contact-system.c
@@ -316,6 +316,57 @@ shell_contact_system_get_individual (ShellContactSystem *self,
 }
 
 /**
+ * shell_contact_system_get_email_for_display:
+ * @self: A #ShellContactSystem
+ * @individual A #FolksIndividual
+ *
+ * Get an email address (either from IM addresses or email), which can be
+ * used to represent @individual.
+ *
+ * Return: (transfer full): a newly allocated string or %NULL if no address
+ *                          was found
+ */
+char *
+shell_contact_system_get_email_for_display (ShellContactSystem *self,
+                                            FolksIndividual    *individual)
+{
+  GeeMultiMap *im_addr_map = folks_im_details_get_im_addresses (FOLKS_IM_DETAILS (individual));
+  GeeCollection *im_addrs = gee_multi_map_get_values (im_addr_map);
+  GeeSet *email_addrs = folks_email_details_get_email_addresses (FOLKS_EMAIL_DETAILS (individual));
+  GeeIterator *addrs_iter;
+  char *email = NULL;
+
+  addrs_iter = gee_iterable_iterator (GEE_ITERABLE (im_addrs));
+  if (gee_iterator_first (addrs_iter))
+    {
+      FolksImFieldDetails *field = gee_iterator_get (addrs_iter);
+      email = g_strdup (folks_abstract_field_details_get_value ((FolksAbstractFieldDetails*)field));
+
+      g_object_unref (field);
+    }
+
+  g_object_unref (addrs_iter);
+  g_object_unref (im_addrs);
+
+  if (email != NULL)
+    return email;
+
+  addrs_iter = gee_iterable_iterator (GEE_ITERABLE (email_addrs));
+
+  if (gee_iterator_first (addrs_iter))
+    {
+      FolksEmailFieldDetails *field = gee_iterator_get (addrs_iter);
+      email = g_strdup (folks_abstract_field_details_get_value ((FolksAbstractFieldDetails*)field));
+
+      g_object_unref (field);
+    }
+
+  g_object_unref (addrs_iter);
+
+  return email;
+}
+
+/**
  * shell_contact_system_initial_search:
  * @shell: A #ShellContactSystem
  * @terms: (element-type utf8): List of terms, logical AND
diff --git a/src/shell-contact-system.h b/src/shell-contact-system.h
index def382d..bf87426 100644
--- a/src/shell-contact-system.h
+++ b/src/shell-contact-system.h
@@ -40,6 +40,9 @@ GeeMap *shell_contact_system_get_all (ShellContactSystem *self);
 FolksIndividual *shell_contact_system_get_individual (ShellContactSystem  *self,
                                                       gchar               *id);
 
+char * shell_contact_system_get_email_for_display (ShellContactSystem *self,
+                                                   FolksIndividual    *individual);
+
 GSList * shell_contact_system_initial_search (ShellContactSystem  *shell,
                                               GSList              *terms);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]