[evolution/gnome-3-8] ESelectNamesEditable cleanups.



commit ee951629214613c6b5108064410976c35541830a
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed Mar 27 20:50:34 2013 -0400

    ESelectNamesEditable cleanups.
    
    (cherry picked from commit a7cd179c901a620ea2f4e11589cccc960d8373fc)

 calendar/gui/e-select-names-editable.c |  168 ++++++++++++++++++++------------
 calendar/gui/e-select-names-editable.h |   73 ++++++++------
 calendar/gui/e-select-names-renderer.c |   11 ++-
 3 files changed, 155 insertions(+), 97 deletions(-)
---
diff --git a/calendar/gui/e-select-names-editable.c b/calendar/gui/e-select-names-editable.c
index b45f7eb..b9a2b1d 100644
--- a/calendar/gui/e-select-names-editable.c
+++ b/calendar/gui/e-select-names-editable.c
@@ -48,7 +48,7 @@ e_select_names_editable_init (ESelectNamesEditable *esne)
 {
 }
 
-ESelectNamesEditable *
+GtkWidget *
 e_select_names_editable_new (void)
 {
        EShell *shell;
@@ -68,20 +68,25 @@ gchar *
 e_select_names_editable_get_email (ESelectNamesEditable *esne)
 {
        EDestinationStore *destination_store;
-       GList *destinations;
-       EDestination *destination;
+       GList *list;
        gchar *result = NULL;
 
        g_return_val_if_fail (E_SELECT_NAMES_EDITABLE (esne), NULL);
 
-       destination_store = e_name_selector_entry_peek_destination_store (E_NAME_SELECTOR_ENTRY (esne));
-       destinations = e_destination_store_list_destinations (destination_store);
-       if (!destinations)
+       destination_store = e_name_selector_entry_peek_destination_store (
+               E_NAME_SELECTOR_ENTRY (esne));
+       list = e_destination_store_list_destinations (destination_store);
+       if (list == NULL)
                return NULL;
 
-       destination = destinations->data;
-       result = g_strdup (e_destination_get_email (destination));
-       g_list_free (destinations);
+       if (list != NULL) {
+               EDestination *destination;
+
+               destination = E_DESTINATION (list->data);
+               result = g_strdup (e_destination_get_email (destination));
+               g_list_free (list);
+       }
+
        return result;
 }
 
@@ -89,63 +94,85 @@ GList *
 e_select_names_editable_get_emails (ESelectNamesEditable *esne)
 {
        EDestinationStore *destination_store;
-       GList *destinations, *l;
-       EDestination *destination;
-       GList *result = NULL;
+       GQueue queue = G_QUEUE_INIT;
+       GList *list, *link;
 
        g_return_val_if_fail (E_SELECT_NAMES_EDITABLE (esne), NULL);
 
-       destination_store = e_name_selector_entry_peek_destination_store (E_NAME_SELECTOR_ENTRY (esne));
-       destinations = e_destination_store_list_destinations (destination_store);
-       if (!destinations)
-               return NULL;
+       destination_store = e_name_selector_entry_peek_destination_store (
+               E_NAME_SELECTOR_ENTRY (esne));
+       list = e_destination_store_list_destinations (destination_store);
+
+       for (link = list; link != NULL; link = g_list_next (link->next)) {
+               EDestination *destination;
+
+               destination = E_DESTINATION (link->data);
 
-       for (l = destinations; l != NULL; l = l->next) {
-               destination = l->data;
                if (e_destination_is_evolution_list (destination)) {
-                       const GList *list_dests, *l;
+                       const GList *list_dests;
 
                        list_dests = e_destination_list_get_dests (destination);
-                       for (l = list_dests; l != NULL; l = g_list_next (l)) {
-                               result = g_list_append (result, g_strdup (e_destination_get_email (l->data)));
+                       while (list_dests != NULL) {
+                               const gchar *email;
+
+                               destination = E_DESTINATION (list_dests->data);
+                               email = e_destination_get_email (destination);
+                               g_queue_push_tail (&queue, g_strdup (email));
+
+                               list_dests = g_list_next (list_dests);
                        }
+
                } else {
-                       /* check if the contact is contact list, it does not contain all the email ids  */
-                       /* we dont expand it currently, TODO do we need to expand it by getting it from 
addressbook*/
-                       if (e_destination_get_contact (destination) &&
-                           e_contact_get (e_destination_get_contact (destination), E_CONTACT_IS_LIST)) {
-                               /* If its a contact_list which is not expanded, it wont have a email id,
-                                * so we can use the name as the email id */
-
-                               result = g_list_append (result, g_strdup (e_destination_get_name 
(destination)));
-                       } else
-                               result = g_list_append (result, g_strdup (e_destination_get_email 
(destination)));
+                       EContact *contact;
+                       const gchar *name;
+                       const gchar *email;
+                       gboolean contact_is_list;
+
+                       contact = e_destination_get_contact (destination);
+                       name = e_destination_get_name (destination);
+                       email = e_destination_get_email (destination);
+
+                       contact_is_list =
+                               (contact != NULL) &&
+                               e_contact_get (contact, E_CONTACT_IS_LIST);
+
+                       if (contact_is_list) {
+                               /* If its a contact_list which is not expanded,
+                                * it won't have an email id, so we can use the
+                                * name as the email id. */
+                               g_queue_push_tail (&queue, g_strdup (name));
+                       } else {
+                               g_queue_push_tail (&queue, g_strdup (email));
+                       }
                }
        }
 
-       g_list_free (destinations);
+       g_list_free (list);
 
-       return result;
+       return queue.head;
 }
 
 gchar *
 e_select_names_editable_get_name (ESelectNamesEditable *esne)
 {
        EDestinationStore *destination_store;
-       GList *destinations;
-       EDestination *destination;
+       GList *list;
        gchar *result = NULL;
 
        g_return_val_if_fail (E_SELECT_NAMES_EDITABLE (esne), NULL);
 
-       destination_store = e_name_selector_entry_peek_destination_store (E_NAME_SELECTOR_ENTRY (esne));
-       destinations = e_destination_store_list_destinations (destination_store);
-       if (!destinations)
-               return NULL;
+       destination_store = e_name_selector_entry_peek_destination_store (
+               E_NAME_SELECTOR_ENTRY (esne));
+       list = e_destination_store_list_destinations (destination_store);
+
+       if (list != NULL) {
+               EDestination *destination;
+
+               destination = E_DESTINATION (list->data);
+               result = g_strdup (e_destination_get_name (destination));
+               g_list_free (list);
+       }
 
-       destination = destinations->data;
-       result = g_strdup (e_destination_get_name (destination));
-       g_list_free (destinations);
        return result;
 }
 
@@ -153,34 +180,44 @@ GList *
 e_select_names_editable_get_names (ESelectNamesEditable *esne)
 {
        EDestinationStore *destination_store;
-       GList *destinations, *l;
-       EDestination *destination;
-       GList *result = NULL;
+       GQueue queue = G_QUEUE_INIT;
+       GList *list, *link;
 
        g_return_val_if_fail (E_SELECT_NAMES_EDITABLE (esne), NULL);
 
-       destination_store = e_name_selector_entry_peek_destination_store (E_NAME_SELECTOR_ENTRY (esne));
-       destinations = e_destination_store_list_destinations (destination_store);
-       if (!destinations)
-               return NULL;
+       destination_store = e_name_selector_entry_peek_destination_store (
+               E_NAME_SELECTOR_ENTRY (esne));
+       list = e_destination_store_list_destinations (destination_store);
+
+       for (link = list; link != NULL; link = g_list_next (link)) {
+               EDestination *destination;
+
+               destination = E_DESTINATION (link->data);
 
-       for (l = destinations; l != NULL; l = l->next) {
-               destination = l->data;
                if (e_destination_is_evolution_list (destination)) {
-                       const GList *list_dests, *l;
+                       const GList *list_dests;
 
                        list_dests = e_destination_list_get_dests (destination);
-                       for (l = list_dests; l != NULL; l = g_list_next (l)) {
-                               result = g_list_append (result, g_strdup (e_destination_get_name (l->data)));
+                       while (list_dests != NULL) {
+                               const gchar *name;
+
+                               destination = E_DESTINATION (list_dests->data);
+                               name = e_destination_get_name (destination);
+                               g_queue_push_tail (&queue, g_strdup (name));
+
+                               list_dests = g_list_next (list_dests);
                        }
                } else {
-                       result = g_list_append (result, g_strdup (e_destination_get_name (destination)));
+                       const gchar *name;
+
+                       name = e_destination_get_name (destination);
+                       g_queue_push_tail (&queue, g_strdup (name));
                }
        }
 
-       g_list_free (destinations);
+       g_list_free (list);
 
-       return result;
+       return queue.head;
 }
 
 void
@@ -189,23 +226,26 @@ e_select_names_editable_set_address (ESelectNamesEditable *esne,
                                      const gchar *email)
 {
        EDestinationStore *destination_store;
-       GList *destinations;
+       GList *list;
        EDestination *destination;
 
        g_return_if_fail (E_IS_SELECT_NAMES_EDITABLE (esne));
 
-       destination_store = e_name_selector_entry_peek_destination_store (E_NAME_SELECTOR_ENTRY (esne));
-       destinations = e_destination_store_list_destinations (destination_store);
+       destination_store = e_name_selector_entry_peek_destination_store (
+               E_NAME_SELECTOR_ENTRY (esne));
+       list = e_destination_store_list_destinations (destination_store);
 
-       if (!destinations)
+       if (list == NULL)
                destination = e_destination_new ();
        else
-               destination = g_object_ref (destinations->data);
+               destination = g_object_ref (list->data);
 
        e_destination_set_name (destination, name);
        e_destination_set_email (destination, email);
 
-       if (!destinations)
-               e_destination_store_append_destination (destination_store, destination);
+       if (list == NULL)
+               e_destination_store_append_destination (
+                       destination_store, destination);
+
        g_object_unref (destination);
 }
diff --git a/calendar/gui/e-select-names-editable.h b/calendar/gui/e-select-names-editable.h
index 84732f7..84e499b 100644
--- a/calendar/gui/e-select-names-editable.h
+++ b/calendar/gui/e-select-names-editable.h
@@ -21,46 +21,61 @@
  *
  */
 
-#ifndef __E_SELECT_NAMES_EDITABLE_H__
-#define __E_SELECT_NAMES_EDITABLE_H__
+#ifndef E_SELECT_NAMES_EDITABLE_H
+#define E_SELECT_NAMES_EDITABLE_H
 
-G_BEGIN_DECLS
+#include <e-util/e-util.h>
+
+/* Standard GObject macros */
+#define E_TYPE_SELECT_NAMES_EDITABLE \
+       (e_select_names_editable_get_type ())
+#define E_SELECT_NAMES_EDITABLE(obj) \
+       (G_TYPE_CHECK_INSTANCE_CAST \
+       ((obj), E_TYPE_SELECT_NAMES_EDITABLE, ESelectNamesEditable))
+#define E_SELECT_NAMES_EDITABLE_CLASS(cls) \
+       (G_TYPE_CHECK_CLASS_CAST \
+       ((cls), E_TYPE_SELECT_NAMES_EDITABLE, ESelectNamesEditableClass))
+#define E_IS_SELECT_NAMES_EDITABLE(obj) \
+       (G_TYPE_CHECK_INSTANCE_TYPE \
+       ((obj), E_TYPE_SELECT_NAMES_EDITABLE))
+#define E_IS_SELECT_NAMES_EDITABLE_CLASS(cls) \
+       (G_TYPE_CHECK_CLASS_TYPE \
+       ((cls), E_TYPE_SELECT_NAMES_EDITABLE))
+#define E_SELECT_NAMES_EDITABLE_GET_CLASS(obj) \
+       (G_TYPE_INSTANCE_GET_CLASS \
+       ((obj), E_TYPE_SELECT_NAMES_EDITABLE, ESelectNamesEditableClass))
 
-#define E_TYPE_SELECT_NAMES_EDITABLE        (e_select_names_editable_get_type ())
-#define E_SELECT_NAMES_EDITABLE(o)          (G_TYPE_CHECK_INSTANCE_CAST ((o), E_TYPE_SELECT_NAMES_EDITABLE, 
ESelectNamesEditable))
-#define E_SELECT_NAMES_EDITABLE_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST ((k), E_TYPE_SELECT_NAMES_EDITABLE, 
ESelectNamesEditableClass))
-#define E_IS_SELECT_NAMES_EDITABLE(o)       (G_TYPE_CHECK_INSTANCE_TYPE ((o), E_TYPE_SELECT_NAMES_EDITABLE))
-#define E_IS_SELECT_NAMES_EDITABLE_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((o), E_TYPE_SELECT_NAMES_EDITABLE))
-#define E_SELECT_NAMES_EDITABLE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), E_TYPE_SELECT_NAMES_EDITABLE, 
ESelectNamesEditableClass))
+G_BEGIN_DECLS
 
-typedef struct _ESelectNamesEditable      ESelectNamesEditable;
+typedef struct _ESelectNamesEditable ESelectNamesEditable;
 typedef struct _ESelectNamesEditableClass ESelectNamesEditableClass;
-typedef struct _ESelectNamesEditablePriv  ESelectNamesEditablePriv;
+typedef struct _ESelectNamesEditablePrivate ESelectNamesEditablePrivate;
 
-struct _ESelectNamesEditable
-{
+struct _ESelectNamesEditable {
        ENameSelectorEntry parent;
-
-       ESelectNamesEditablePriv *priv;
+       ESelectNamesEditablePrivate *priv;
 };
 
-struct _ESelectNamesEditableClass
-{
+struct _ESelectNamesEditableClass {
        ENameSelectorEntryClass parent_class;
 };
 
-GType      e_select_names_editable_get_type (void);
-
-ESelectNamesEditable *e_select_names_editable_new (void);
-
-gchar *e_select_names_editable_get_email (ESelectNamesEditable *esne);
-GList *e_select_names_editable_get_emails (ESelectNamesEditable *esne);
-
-gchar *e_select_names_editable_get_name (ESelectNamesEditable *esne);
-GList *e_select_names_editable_get_names (ESelectNamesEditable *esne);
-
-void   e_select_names_editable_set_address (ESelectNamesEditable *esne, const gchar *name, const gchar 
*email);
+GType          e_select_names_editable_get_type
+                                               (void) G_GNUC_CONST;
+GtkWidget *    e_select_names_editable_new     (void);
+gchar *                e_select_names_editable_get_email
+                                               (ESelectNamesEditable *esne);
+GList *                e_select_names_editable_get_emails
+                                               (ESelectNamesEditable *esne);
+gchar *                e_select_names_editable_get_name
+                                               (ESelectNamesEditable *esne);
+GList *                e_select_names_editable_get_names
+                                               (ESelectNamesEditable *esne);
+void           e_select_names_editable_set_address
+                                               (ESelectNamesEditable *esne,
+                                                const gchar *name,
+                                                const gchar *email);
 
 G_END_DECLS
 
-#endif /* __E_SELECT_NAMES_EDITABLE_H__ */
+#endif /* E_SELECT_NAMES_EDITABLE_H */
diff --git a/calendar/gui/e-select-names-renderer.c b/calendar/gui/e-select-names-renderer.c
index 311616d..02a21ac 100644
--- a/calendar/gui/e-select-names-renderer.c
+++ b/calendar/gui/e-select-names-renderer.c
@@ -119,7 +119,7 @@ e_select_names_renderer_start_editing (GtkCellRenderer *cell,
 {
        ESelectNamesRenderer *sn_cell = E_SELECT_NAMES_RENDERER (cell);
        GtkCellRendererText *text_cell = GTK_CELL_RENDERER_TEXT (cell);
-       ESelectNamesEditable *editable;
+       GtkWidget *editable;
        gboolean is_editable;
        gfloat xalign;
 
@@ -131,12 +131,15 @@ e_select_names_renderer_start_editing (GtkCellRenderer *cell,
        if (!is_editable)
                return NULL;
 
-       editable = E_SELECT_NAMES_EDITABLE (e_select_names_editable_new ());
+       editable = e_select_names_editable_new ();
        gtk_entry_set_has_frame (GTK_ENTRY (editable), FALSE);
        gtk_entry_set_alignment (GTK_ENTRY (editable), xalign);
        if (sn_cell->priv->email && *sn_cell->priv->email)
-               e_select_names_editable_set_address (editable, sn_cell->priv->name, sn_cell->priv->email);
-       gtk_widget_show (GTK_WIDGET (editable));
+               e_select_names_editable_set_address (
+                       E_SELECT_NAMES_EDITABLE (editable),
+                       sn_cell->priv->name,
+                       sn_cell->priv->email);
+       gtk_widget_show (editable);
 
        g_signal_connect (
                editable, "editing_done",


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