diff options
-rw-r--r-- | doc/reference/evolution-util/evolution-util-sections.txt | 1 | ||||
-rw-r--r-- | e-util/e-source-selector.c | 114 | ||||
-rw-r--r-- | e-util/e-source-selector.h | 4 | ||||
-rw-r--r-- | e-util/test-source-selector.c | 29 | ||||
-rw-r--r-- | plugins/publish-calendar/url-editor-dialog.c | 20 |
5 files changed, 103 insertions, 65 deletions
diff --git a/doc/reference/evolution-util/evolution-util-sections.txt b/doc/reference/evolution-util/evolution-util-sections.txt index b1a59439fa..8ce000d21c 100644 --- a/doc/reference/evolution-util/evolution-util-sections.txt +++ b/doc/reference/evolution-util/evolution-util-sections.txt @@ -3214,7 +3214,6 @@ e_source_selector_unselect_source e_source_selector_select_exclusive e_source_selector_source_is_selected e_source_selector_get_selection -e_source_selector_free_selection e_source_selector_set_select_new e_source_selector_edit_primary_selection e_source_selector_ref_primary_selection diff --git a/e-util/e-source-selector.c b/e-util/e-source-selector.c index b4f82c2c5b..1e4435ea03 100644 --- a/e-util/e-source-selector.c +++ b/e-util/e-source-selector.c @@ -38,6 +38,12 @@ typedef struct _AsyncContext AsyncContext; struct _ESourceSelectorPrivate { ESourceRegistry *registry; + gulong source_added_handler_id; + gulong source_changed_handler_id; + gulong source_removed_handler_id; + gulong source_enabled_handler_id; + gulong source_disabled_handler_id; + GHashTable *source_index; gchar *extension_name; @@ -687,15 +693,43 @@ source_selector_dispose (GObject *object) priv = E_SOURCE_SELECTOR_GET_PRIVATE (object); - if (priv->registry != NULL) { - g_signal_handlers_disconnect_matched ( + if (priv->source_added_handler_id > 0) { + g_signal_handler_disconnect ( priv->registry, - G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, object); - g_object_unref (priv->registry); - priv->registry = NULL; + priv->source_added_handler_id); + priv->source_added_handler_id = 0; } + if (priv->source_changed_handler_id > 0) { + g_signal_handler_disconnect ( + priv->registry, + priv->source_changed_handler_id); + priv->source_changed_handler_id = 0; + } + + if (priv->source_removed_handler_id > 0) { + g_signal_handler_disconnect ( + priv->registry, + priv->source_removed_handler_id); + priv->source_removed_handler_id = 0; + } + + if (priv->source_enabled_handler_id > 0) { + g_signal_handler_disconnect ( + priv->registry, + priv->source_enabled_handler_id); + priv->source_enabled_handler_id = 0; + } + + if (priv->source_disabled_handler_id > 0) { + g_signal_handler_disconnect ( + priv->registry, + priv->source_disabled_handler_id); + priv->source_disabled_handler_id = 0; + } + + g_clear_object (&priv->registry); + g_hash_table_remove_all (priv->source_index); g_hash_table_remove_all (priv->pending_writes); @@ -729,29 +763,35 @@ source_selector_constructed (GObject *object) { ESourceRegistry *registry; ESourceSelector *selector; + gulong handler_id; selector = E_SOURCE_SELECTOR (object); registry = e_source_selector_get_registry (selector); - g_signal_connect ( + handler_id = g_signal_connect ( registry, "source-added", G_CALLBACK (source_selector_source_added_cb), selector); + selector->priv->source_added_handler_id = handler_id; - g_signal_connect ( + handler_id = g_signal_connect ( registry, "source-changed", G_CALLBACK (source_selector_source_changed_cb), selector); + selector->priv->source_changed_handler_id = handler_id; - g_signal_connect ( + handler_id = g_signal_connect ( registry, "source-removed", G_CALLBACK (source_selector_source_removed_cb), selector); + selector->priv->source_removed_handler_id = handler_id; - g_signal_connect ( + handler_id = g_signal_connect ( registry, "source-enabled", G_CALLBACK (source_selector_source_enabled_cb), selector); + selector->priv->source_enabled_handler_id = handler_id; - g_signal_connect ( + handler_id = g_signal_connect ( registry, "source-disabled", G_CALLBACK (source_selector_source_disabled_cb), selector); + selector->priv->source_disabled_handler_id = handler_id; source_selector_build_model (selector); @@ -1450,7 +1490,7 @@ e_source_selector_set_show_colors (ESourceSelector *selector, { g_return_if_fail (E_IS_SOURCE_SELECTOR (selector)); - if ((show_colors ? 1 : 0) == (selector->priv->show_colors ? 1 : 0)) + if (show_colors == selector->priv->show_colors) return; selector->priv->show_colors = show_colors; @@ -1493,7 +1533,7 @@ e_source_selector_set_show_toggles (ESourceSelector *selector, { g_return_if_fail (E_IS_SOURCE_SELECTOR (selector)); - if ((show_toggles ? 1 : 0) == (selector->priv->show_toggles ? 1 : 0)) + if (show_toggles == selector->priv->show_toggles) return; selector->priv->show_toggles = show_toggles; @@ -1514,15 +1554,15 @@ source_selector_check_selected (GtkTreeModel *model, struct { ESourceSelector *selector; - GSList *list; + GQueue queue; } *closure = user_data; gtk_tree_model_get (model, iter, COLUMN_SOURCE, &source, -1); if (e_source_selector_source_is_selected (closure->selector, source)) - closure->list = g_slist_prepend (closure->list, source); - else - g_object_unref (source); + g_queue_push_tail (&closure->queue, g_object_ref (source)); + + g_object_unref (source); return FALSE; } @@ -1531,45 +1571,41 @@ source_selector_check_selected (GtkTreeModel *model, * e_source_selector_get_selection: * @selector: an #ESourceSelector * - * Get the list of selected sources, i.e. those that were enabled through the - * corresponding checkboxes in the tree. + * Returns a list of selected sources, i.e. those that were enabled through + * the corresponding checkboxes in the tree. The sources are ordered as they + * appear in @selector. + * + * The sources returned in the list are referenced for thread-safety. + * They must each be unreferenced with g_object_unref() when finished + * with them. Free the returned list itself with g_list_free(). + * + * An easy way to free the list properly in one step is as follows: * - * Returns: A list of the ESources currently selected. The sources will - * be in the same order as they appear on the screen, and the list should be - * freed using e_source_selector_free_selection(). + * |[ + * g_list_free_full (list, g_object_unref); + * ]| + * + * Returns: a ordered list of selected sources **/ -GSList * +GList * e_source_selector_get_selection (ESourceSelector *selector) { struct { ESourceSelector *selector; - GSList *list; + GQueue queue; } closure; g_return_val_if_fail (E_IS_SOURCE_SELECTOR (selector), NULL); closure.selector = selector; - closure.list = NULL; + g_queue_init (&closure.queue); gtk_tree_model_foreach ( gtk_tree_view_get_model (GTK_TREE_VIEW (selector)), (GtkTreeModelForeachFunc) source_selector_check_selected, &closure); - return g_slist_reverse (closure.list); -} - -/** - * e_source_list_free_selection: - * @list: A selection list returned by e_source_selector_get_selection(). - * - * Free the selection list. - **/ -void -e_source_selector_free_selection (GSList *list) -{ - g_slist_foreach (list, (GFunc) g_object_unref, NULL); - g_slist_free (list); + return g_queue_peek_head_link (&closure.queue); } /** diff --git a/e-util/e-source-selector.h b/e-util/e-source-selector.h index 949c94bf33..f0e56573b5 100644 --- a/e-util/e-source-selector.h +++ b/e-util/e-source-selector.h @@ -117,9 +117,7 @@ void e_source_selector_select_exclusive gboolean e_source_selector_source_is_selected (ESourceSelector *selector, ESource *source); -GSList * e_source_selector_get_selection (ESourceSelector *selector); -void e_source_selector_free_selection - (GSList *list); +GList * e_source_selector_get_selection (ESourceSelector *selector); void e_source_selector_set_select_new (ESourceSelector *selector, gboolean state); diff --git a/e-util/test-source-selector.c b/e-util/test-source-selector.c index 8f44af3bb1..7a46fa5a07 100644 --- a/e-util/test-source-selector.c +++ b/e-util/test-source-selector.c @@ -28,29 +28,28 @@ static const gchar *extension_name; static void dump_selection (ESourceSelector *selector) { - GSList *selection = e_source_selector_get_selection (selector); + GList *list, *link; + + list = e_source_selector_get_selection (selector); g_print ("Current selection:\n"); - if (selection == NULL) { + + if (list == NULL) g_print ("\t(None)\n"); - } else { - GSList *p; - for (p = selection; p != NULL; p = p->next) { - ESource *source = E_SOURCE (p->data); - ESourceBackend *extension; + for (link = list; link != NULL; link = g_list_next (link->next)) { + ESource *source = E_SOURCE (link->data); + ESourceBackend *extension; - extension = e_source_get_extension ( - source, extension_name); + extension = e_source_get_extension (source, extension_name); - g_print ( - "\tSource %s (backend %s)\n", - e_source_get_display_name (source), - e_source_backend_get_backend_name (extension)); - } + g_print ( + "\tSource %s (backend %s)\n", + e_source_get_display_name (source), + e_source_backend_get_backend_name (extension)); } - e_source_selector_free_selection (selection); + g_list_free_full (list, (GDestroyNotify) g_object_unref); } static void diff --git a/plugins/publish-calendar/url-editor-dialog.c b/plugins/publish-calendar/url-editor-dialog.c index c672e94de3..04bbe5d9f9 100644 --- a/plugins/publish-calendar/url-editor-dialog.c +++ b/plugins/publish-calendar/url-editor-dialog.c @@ -110,7 +110,7 @@ static void check_input (UrlEditorDialog *dialog) { gint n = 0; - GSList *sources; + GList *sources; EPublishUri *uri; uri = dialog->uri; @@ -126,8 +126,10 @@ check_input (UrlEditorDialog *dialog) } if (gtk_widget_get_sensitive (dialog->events_selector)) { - sources = e_source_selector_get_selection (E_SOURCE_SELECTOR (dialog->events_selector)); - n += g_slist_length (sources); + sources = e_source_selector_get_selection ( + E_SOURCE_SELECTOR (dialog->events_selector)); + n += g_list_length (sources); + g_list_free_full (sources, (GDestroyNotify) g_object_unref); } if (n == 0) goto fail; @@ -586,7 +588,7 @@ url_editor_dialog_run (UrlEditorDialog *dialog) response = gtk_dialog_run (GTK_DIALOG (dialog)); if (response == GTK_RESPONSE_OK) { - GSList *l, *p; + GList *list, *link; if (dialog->uri->password) g_free (dialog->uri->password); @@ -606,16 +608,20 @@ url_editor_dialog_run (UrlEditorDialog *dialog) e_passwords_forget_password (dialog->uri->location); } - l = e_source_selector_get_selection (E_SOURCE_SELECTOR (dialog->events_selector)); - for (p = l; p; p = g_slist_next (p)) { + list = e_source_selector_get_selection ( + E_SOURCE_SELECTOR (dialog->events_selector)); + + for (link = list; link != NULL; link = g_list_next (link)) { ESource *source; const gchar *uid; - source = E_SOURCE (p->data); + source = E_SOURCE (link->data); uid = e_source_get_uid (source); dialog->uri->events = g_slist_append ( dialog->uri->events, g_strdup (uid)); } + + g_list_free_full (list, (GDestroyNotify) g_object_unref); } gtk_widget_hide (GTK_WIDGET (dialog)); |