diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2011-04-27 06:22:29 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2011-04-27 06:22:29 +0800 |
commit | 81270ea009bdca0a9527737efa7ecb27a6260bff (patch) | |
tree | bdf75a062bf5d62ed071bea74ce88b6bef186e91 | |
parent | 1af7571c5c475ecf3f95d56a0fe7af78c7be3180 (diff) | |
download | gsoc2013-evolution-81270ea009bdca0a9527737efa7ecb27a6260bff.tar gsoc2013-evolution-81270ea009bdca0a9527737efa7ecb27a6260bff.tar.gz gsoc2013-evolution-81270ea009bdca0a9527737efa7ecb27a6260bff.tar.bz2 gsoc2013-evolution-81270ea009bdca0a9527737efa7ecb27a6260bff.tar.lz gsoc2013-evolution-81270ea009bdca0a9527737efa7ecb27a6260bff.tar.xz gsoc2013-evolution-81270ea009bdca0a9527737efa7ecb27a6260bff.tar.zst gsoc2013-evolution-81270ea009bdca0a9527737efa7ecb27a6260bff.zip |
Add itip_get_user_identities().
Convenience function returns a NULL-terminated array of name + address
strings based on registered mail identities.
-rw-r--r-- | calendar/gui/dialogs/event-page.c | 61 | ||||
-rw-r--r-- | calendar/gui/dialogs/memo-page.c | 62 | ||||
-rw-r--r-- | calendar/gui/dialogs/task-page.c | 61 | ||||
-rw-r--r-- | calendar/gui/itip-utils.c | 45 | ||||
-rw-r--r-- | calendar/gui/itip-utils.h | 1 |
5 files changed, 105 insertions, 125 deletions
diff --git a/calendar/gui/dialogs/event-page.c b/calendar/gui/dialogs/event-page.c index 6b9110bc86..a4856b1792 100644 --- a/calendar/gui/dialogs/event-page.c +++ b/calendar/gui/dialogs/event-page.c @@ -109,7 +109,7 @@ struct _EventPagePrivate { GtkWidget *location; GtkWidget *location_label; - GList *address_strings; + gchar **address_strings; EMeetingAttendee *ia; gchar *user_add; ECalComponent *comp; @@ -896,8 +896,7 @@ event_page_finalize (GObject *object) priv = EVENT_PAGE_GET_PRIVATE (object); - g_list_foreach (priv->address_strings, (GFunc) g_free, NULL); - g_list_free (priv->address_strings); + g_strfreev (priv->address_strings); g_ptr_array_foreach ( priv->deleted_attendees, (GFunc) g_object_unref, NULL); @@ -3186,7 +3185,6 @@ event_page_select_organizer (EventPage *epage, const gchar *backend_address) { EventPagePrivate *priv = epage->priv; CompEditor *editor; - GList *l; ECal *client; EAccount *def_account; gchar *def_address = NULL; @@ -3194,6 +3192,7 @@ event_page_select_organizer (EventPage *epage, const gchar *backend_address) gboolean subscribed_cal = FALSE; ESource *source = NULL; const gchar *user_addr = NULL; + gint ii; def_account = e_get_default_account (); if (def_account && def_account->enabled) @@ -3213,12 +3212,14 @@ event_page_select_organizer (EventPage *epage, const gchar *backend_address) user_addr = (backend_address && *backend_address) ? backend_address : NULL; default_address = NULL; - if (user_addr) - for (l = priv->address_strings; l != NULL; l = l->next) - if (g_strrstr ((gchar *) l->data, user_addr) != NULL) { - default_address = (const gchar *) l->data; + if (user_addr) { + for (ii = 0; priv->address_strings[ii] != NULL; ii++) { + if (g_strrstr (priv->address_strings[ii], user_addr) != NULL) { + default_address = priv->address_strings[ii]; break; } + } + } if (!default_address && def_address) default_address = def_address; @@ -3252,8 +3253,8 @@ event_page_construct (EventPage *epage, EMeetingStore *meeting_store) { EventPagePrivate *priv; - EAccountList *account_list; - EIterator *iterator; + GtkTreeModel *model; + gint ii; priv = epage->priv; priv->meeting_store = g_object_ref (meeting_store); @@ -3272,40 +3273,18 @@ event_page_construct (EventPage *epage, return NULL; } - account_list = e_get_account_list (); - iterator = e_list_get_iterator (E_LIST (account_list)); - - while (e_iterator_is_valid (iterator)) { - EAccount *account; + model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->organizer)); - /* XXX EIterator misuses const. */ - account = (EAccount *) e_iterator_get (iterator); + priv->address_strings = itip_get_user_identities (); + for (ii = 0; priv->address_strings[ii] != NULL; ii++) + e_dialog_append_list_store_text ( + model, 0, priv->address_strings[ii]); - if (account->enabled) - priv->address_strings = g_list_append ( - priv->address_strings, - g_strdup_printf ( - "%s <%s>", - account->id->name, - account->id->address)); + gtk_combo_box_set_active (GTK_COMBO_BOX (priv->organizer), 0); - e_iterator_next (iterator); - } - - g_object_unref (iterator); - - if (priv->address_strings) { - GList *l; - GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->organizer)); - - for (l = priv->address_strings; l; l = l->next) - e_dialog_append_list_store_text (model, 0, l->data); - - gtk_combo_box_set_active (GTK_COMBO_BOX (priv->organizer), 0); - - g_signal_connect (gtk_bin_get_child (GTK_BIN (priv->organizer)), "changed", (GCallback) organizer_changed_cb, epage); - } else - g_warning ("No potential organizers!"); + g_signal_connect ( + gtk_bin_get_child (GTK_BIN (priv->organizer)), "changed", + G_CALLBACK (organizer_changed_cb), epage); if (!init_widgets (epage)) { g_message ("event_page_construct(): " diff --git a/calendar/gui/dialogs/memo-page.c b/calendar/gui/dialogs/memo-page.c index 88d755efb6..54692894e3 100644 --- a/calendar/gui/dialogs/memo-page.c +++ b/calendar/gui/dialogs/memo-page.c @@ -92,7 +92,7 @@ struct _MemoPagePrivate { GtkWidget *source_selector; - GList *address_strings; + gchar **address_strings; ENameSelector *name_selector; }; @@ -187,8 +187,7 @@ memo_page_dispose (GObject *object) priv = MEMO_PAGE (object)->priv; - g_list_foreach (priv->address_strings, (GFunc) g_free, NULL); - g_list_free (priv->address_strings); + g_strfreev (priv->address_strings); /* Chain up to parent's dispose() method. */ G_OBJECT_CLASS (memo_page_parent_class)->dispose (object); @@ -1096,7 +1095,6 @@ memo_page_select_organizer (MemoPage *mpage, const gchar *backend_address) MemoPagePrivate *priv; CompEditor *editor; CompEditorFlags flags; - GList *l; ECal *client; EAccount *def_account; gchar *def_address = NULL; @@ -1104,6 +1102,7 @@ memo_page_select_organizer (MemoPage *mpage, const gchar *backend_address) gboolean subscribed_cal = FALSE; ESource *source = NULL; const gchar *user_addr = NULL; + gint ii; def_account = e_get_default_account (); if (def_account && def_account->enabled) @@ -1125,12 +1124,14 @@ memo_page_select_organizer (MemoPage *mpage, const gchar *backend_address) user_addr = (backend_address && *backend_address) ? backend_address : NULL; default_address = NULL; - if (user_addr) - for (l = priv->address_strings; l != NULL; l = l->next) - if (g_strrstr ((gchar *) l->data, user_addr) != NULL) { - default_address = (const gchar *) l->data; + if (user_addr) { + for (ii = 0; priv->address_strings[ii] != NULL; ii++) { + if (g_strrstr (priv->address_strings[ii], user_addr) != NULL) { + default_address = priv->address_strings[ii]; break; } + } + } if (!default_address && def_account) default_address = def_address; @@ -1158,10 +1159,12 @@ memo_page_select_organizer (MemoPage *mpage, const gchar *backend_address) MemoPage * memo_page_construct (MemoPage *mpage) { - MemoPagePrivate *priv = mpage->priv; + MemoPagePrivate *priv; CompEditor *editor; CompEditorFlags flags; + priv = mpage->priv; + editor = comp_editor_page_get_editor (COMP_EDITOR_PAGE (mpage)); flags = comp_editor_get_flags (editor); @@ -1175,41 +1178,16 @@ memo_page_construct (MemoPage *mpage) } if (flags & COMP_EDITOR_IS_SHARED) { - EAccountList *account_list; - EIterator *iterator; - - account_list = e_get_account_list (); - iterator = e_list_get_iterator (E_LIST (account_list)); - - while (e_iterator_is_valid (iterator)) { - EAccount *account; - - /* XXX EIterator misuses const. */ - account = (EAccount *) e_iterator_get (iterator); - - if (account->enabled) - priv->address_strings = g_list_append ( - priv->address_strings, - g_strdup_printf ( - "%s <%s>", - account->id->name, - account->id->address)); - - e_iterator_next (iterator); - } - - g_object_unref (iterator); - - if (priv->address_strings) { - GList *l; - GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->org_combo)); + GtkTreeModel *model; + gint ii; - for (l = priv->address_strings; l; l = l->next) - e_dialog_append_list_store_text (model, 0, l->data); + model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->org_combo)); + priv->address_strings = itip_get_user_identities (); + for (ii = 0; priv->address_strings[ii] != NULL; ii++) + e_dialog_append_list_store_text ( + model, 0, priv->address_strings[ii]); - gtk_combo_box_set_active (GTK_COMBO_BOX (priv->org_combo), 0); - } else - g_warning ("No potential organizers!"); + gtk_combo_box_set_active (GTK_COMBO_BOX (priv->org_combo), 0); gtk_widget_show (priv->org_label); gtk_widget_show (priv->org_combo); diff --git a/calendar/gui/dialogs/task-page.c b/calendar/gui/dialogs/task-page.c index 499e9e14ba..1120ccf263 100644 --- a/calendar/gui/dialogs/task-page.c +++ b/calendar/gui/dialogs/task-page.c @@ -65,7 +65,7 @@ struct _TaskPagePrivate { /* Widgets from the UI file */ GtkWidget *main; - GList *address_strings; + gchar **address_strings; EMeetingAttendee *ia; gchar *user_add; ECalComponent *comp; @@ -425,8 +425,7 @@ task_page_finalize (GObject *object) priv = TASK_PAGE_GET_PRIVATE (object); - g_list_foreach (priv->address_strings, (GFunc) g_free, NULL); - g_list_free (priv->address_strings); + g_strfreev (priv->address_strings); g_ptr_array_foreach ( priv->deleted_attendees, (GFunc) g_object_unref, NULL); @@ -2037,7 +2036,6 @@ task_page_select_organizer (TaskPage *tpage, const gchar *backend_address) { TaskPagePrivate *priv = tpage->priv; CompEditor *editor; - GList *l; EAccount *def_account; gchar *def_address = NULL; const gchar *default_address; @@ -2045,6 +2043,7 @@ task_page_select_organizer (TaskPage *tpage, const gchar *backend_address) ESource *source = NULL; ECal *client; const gchar *user_addr = NULL; + gint ii; editor = comp_editor_page_get_editor (COMP_EDITOR_PAGE (tpage)); client = comp_editor_get_client (editor); @@ -2064,12 +2063,14 @@ task_page_select_organizer (TaskPage *tpage, const gchar *backend_address) user_addr = (backend_address && *backend_address) ? backend_address : NULL; default_address = NULL; - if (user_addr) - for (l = priv->address_strings; l != NULL; l = l->next) - if (g_strrstr ((gchar *) l->data, user_addr) != NULL) { - default_address = (const gchar *) l->data; + if (user_addr) { + for (ii = 0; priv->address_strings[ii] != NULL; ii++) { + if (g_strrstr (priv->address_strings[ii], user_addr) != NULL) { + default_address = priv->address_strings[ii]; break; } + } + } if (!default_address && def_address) default_address = def_address; @@ -2104,8 +2105,8 @@ task_page_construct (TaskPage *tpage, ECal *client) { TaskPagePrivate *priv; - EAccountList *account_list; - EIterator *iterator; + GtkTreeModel *model; + gint ii; priv = tpage->priv; priv->meeting_store = g_object_ref (meeting_store); @@ -2126,40 +2127,18 @@ task_page_construct (TaskPage *tpage, return NULL; } - account_list = e_get_account_list (); - iterator = e_list_get_iterator (E_LIST (account_list)); - - while (e_iterator_is_valid (iterator)) { - EAccount *account; - - /* XXX EIterator misuses const. */ - account = (EAccount *) e_iterator_get (iterator); - - if (account->enabled) - priv->address_strings = g_list_append ( - priv->address_strings, - g_strdup_printf ( - "%s <%s>", - account->id->name, - account->id->address)); - - e_iterator_next (iterator); - } - - g_object_unref (iterator); - - if (priv->address_strings) { - GList *l; - GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->organizer)); + model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->organizer)); - for (l = priv->address_strings; l; l = l->next) - e_dialog_append_list_store_text (model, 0, l->data); + priv->address_strings = itip_get_user_identities (); + for (ii = 0; priv->address_strings[ii] != NULL; ii++) + e_dialog_append_list_store_text ( + model, 0, priv->address_strings[ii]); - gtk_combo_box_set_active (GTK_COMBO_BOX (priv->organizer), 0); + gtk_combo_box_set_active (GTK_COMBO_BOX (priv->organizer), 0); - g_signal_connect (gtk_bin_get_child (GTK_BIN (priv->organizer)), "changed", (GCallback) organizer_changed_cb, tpage); - } else - g_warning ("No potential organizers!"); + g_signal_connect ( + gtk_bin_get_child (GTK_BIN (priv->organizer)), "changed", + G_CALLBACK (organizer_changed_cb), tpage); if (!init_widgets (tpage)) { g_message ("task_page_construct(): " diff --git a/calendar/gui/itip-utils.c b/calendar/gui/itip-utils.c index d6b7893694..4ab53de115 100644 --- a/calendar/gui/itip-utils.c +++ b/calendar/gui/itip-utils.c @@ -62,6 +62,48 @@ static icalproperty_method itip_methods_enum[] = { }; /** + * itip_get_user_identities: + * + * Returns a %NULL-terminated array of name + address strings based on + * registered mail identities. Free the returned array with g_strfreev(). + * + * Returns: an %NULL-terminated array of mail identity strings + **/ +gchar ** +itip_get_user_identities (void) +{ + EAccountList *account_list; + EIterator *iterator; + gchar **identities; + gint length, ii = 0; + + account_list = e_get_account_list (); + length = e_list_length (E_LIST (account_list)); + iterator = e_list_get_iterator (E_LIST (account_list)); + + identities = g_new0 (gchar *, length + 1); + + while (e_iterator_is_valid (iterator)) { + EAccount *account; + + /* XXX EIterator misuses const. */ + account = (EAccount *) e_iterator_get (iterator); + + if (account->enabled) + identities[ii++] = g_strdup_printf ( + "%s <%s>", + account->id->name, + account->id->address); + + e_iterator_next (iterator); + } + + g_object_unref (iterator); + + return identities; +} + +/** * itip_address_is_user: * @address: an email address * @@ -79,7 +121,8 @@ itip_address_is_user (const gchar *address) account_list = e_get_account_list (); - account = e_account_list_find ( + /* XXX EAccountList misuses const. */ + account = (EAccount *) e_account_list_find ( account_list, E_ACCOUNT_FIND_ID_ADDRESS, address); return (account != NULL); diff --git a/calendar/gui/itip-utils.h b/calendar/gui/itip-utils.h index bf9f5417c8..720540e239 100644 --- a/calendar/gui/itip-utils.h +++ b/calendar/gui/itip-utils.h @@ -50,6 +50,7 @@ struct CalMimeAttach { guint length; }; +gchar ** itip_get_user_identities (void); gboolean itip_address_is_user (const gchar *address); gboolean itip_organizer_is_user (ECalComponent *comp, ECal *client); |