diff options
author | Philip Withnall <philip.withnall@collabora.co.uk> | 2014-03-28 17:14:23 +0800 |
---|---|---|
committer | Philip Withnall <philip.withnall@collabora.co.uk> | 2014-03-28 18:44:44 +0800 |
commit | 61b4bacf9a16bf69c26999dd9acac99695d23242 (patch) | |
tree | 01ec1df06524350dc665913445f14bbf8e0dad58 /e-util | |
parent | ed405f45a5b870b0374f8f714023e1647a1a6701 (diff) | |
download | gsoc2013-evolution-61b4bacf9a16bf69c26999dd9acac99695d23242.tar gsoc2013-evolution-61b4bacf9a16bf69c26999dd9acac99695d23242.tar.gz gsoc2013-evolution-61b4bacf9a16bf69c26999dd9acac99695d23242.tar.bz2 gsoc2013-evolution-61b4bacf9a16bf69c26999dd9acac99695d23242.tar.lz gsoc2013-evolution-61b4bacf9a16bf69c26999dd9acac99695d23242.tar.xz gsoc2013-evolution-61b4bacf9a16bf69c26999dd9acac99695d23242.tar.zst gsoc2013-evolution-61b4bacf9a16bf69c26999dd9acac99695d23242.zip |
e-util: Port to thread-safe ECategories API
This ports the following two function calls throughout Evolution:
• e_categories_get_list() to e_categories_dup_list()
• e_categories_get_icon_file_for() to e_categories_dup_icon_file_for()
It necessarily changes some internal e-util API:
• e_util_get_searchable_categories() to
e_util_dup_searchable_categories()
This bumps the EDS requirement to 3.13.1.
https://bugzilla.gnome.org/show_bug.cgi?id=727221
Diffstat (limited to 'e-util')
-rw-r--r-- | e-util/e-categories-config.c | 5 | ||||
-rw-r--r-- | e-util/e-categories-selector.c | 9 | ||||
-rw-r--r-- | e-util/e-category-completion.c | 9 | ||||
-rw-r--r-- | e-util/e-category-editor.c | 5 | ||||
-rw-r--r-- | e-util/e-misc-utils.c | 31 | ||||
-rw-r--r-- | e-util/e-misc-utils.h | 2 | ||||
-rw-r--r-- | e-util/e-name-selector-dialog.c | 4 |
7 files changed, 39 insertions, 26 deletions
diff --git a/e-util/e-categories-config.c b/e-util/e-categories-config.c index 7f65645572..226f6532fc 100644 --- a/e-util/e-categories-config.c +++ b/e-util/e-categories-config.c @@ -64,7 +64,7 @@ gboolean e_categories_config_get_icon_for (const gchar *category, GdkPixbuf **pixbuf) { - const gchar *icon_file; + gchar *icon_file; g_return_val_if_fail (pixbuf != NULL, FALSE); g_return_val_if_fail (category != NULL, FALSE); @@ -84,13 +84,14 @@ e_categories_config_get_icon_for (const gchar *category, } } - icon_file = e_categories_get_icon_file_for (category); + icon_file = e_categories_dup_icon_file_for (category); if (!icon_file) { *pixbuf = NULL; } else { /* load the icon in our list */ *pixbuf = gdk_pixbuf_new_from_file (icon_file, NULL); } + g_free (icon_file); g_hash_table_insert (pixbufs_cache, g_strdup (category), *pixbuf == NULL ? NULL : g_object_ref (*pixbuf)); diff --git a/e-util/e-categories-selector.c b/e-util/e-categories-selector.c index 454421c7a8..e014e7d8c5 100644 --- a/e-util/e-categories-selector.c +++ b/e-util/e-categories-selector.c @@ -71,10 +71,10 @@ categories_selector_build_model (ECategoriesSelector *selector) GTK_TREE_SORTABLE (store), COLUMN_CATEGORY, GTK_SORT_ASCENDING); - list = e_categories_get_list (); + list = e_categories_dup_list (); for (iter = list; iter != NULL; iter = iter->next) { const gchar *category_name = iter->data; - const gchar *filename; + gchar *filename; GdkPixbuf *pixbuf = NULL; GtkTreeIter iter; gboolean active; @@ -87,9 +87,10 @@ categories_selector_build_model (ECategoriesSelector *selector) selector->priv->selected_categories, category_name) != NULL); - filename = e_categories_get_icon_file_for (category_name); + filename = e_categories_dup_icon_file_for (category_name); if (filename != NULL) pixbuf = gdk_pixbuf_new_from_file (filename, NULL); + g_free (filename); gtk_list_store_append (store, &iter); @@ -111,7 +112,7 @@ categories_selector_build_model (ECategoriesSelector *selector) gtk_tree_view_set_search_column ( GTK_TREE_VIEW (selector), COLUMN_CATEGORY); - g_list_free (list); + g_list_free_full (list, g_free); g_object_unref (store); } diff --git a/e-util/e-category-completion.c b/e-util/e-category-completion.c index ac693836f6..cc8ed8936e 100644 --- a/e-util/e-category-completion.c +++ b/e-util/e-category-completion.c @@ -61,10 +61,10 @@ category_completion_build_model (GtkEntryCompletion *completion) store = gtk_list_store_new ( NUM_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING); - list = e_categories_get_list (); + list = e_categories_dup_list (); while (list != NULL) { const gchar *category = list->data; - const gchar *filename; + gchar *filename; gchar *normalized; gchar *casefolded; GdkPixbuf *pixbuf = NULL; @@ -72,13 +72,15 @@ category_completion_build_model (GtkEntryCompletion *completion) /* Only add user-visible categories. */ if (!e_categories_is_searchable (category)) { + g_free (list->data); list = g_list_delete_link (list, list); continue; } - filename = e_categories_get_icon_file_for (category); + filename = e_categories_dup_icon_file_for (category); if (filename != NULL && *filename != '\0') pixbuf = gdk_pixbuf_new_from_file (filename, NULL); + g_free (filename); normalized = g_utf8_normalize ( category, -1, G_NORMALIZE_DEFAULT); @@ -97,6 +99,7 @@ category_completion_build_model (GtkEntryCompletion *completion) if (pixbuf != NULL) g_object_unref (pixbuf); + g_free (list->data); list = g_list_delete_link (list, list); } diff --git a/e-util/e-category-editor.c b/e-util/e-category-editor.c index 7d4223d3e8..708ba5c890 100644 --- a/e-util/e-category-editor.c +++ b/e-util/e-category-editor.c @@ -304,7 +304,7 @@ e_category_editor_edit_category (ECategoryEditor *editor, const gchar *category) { GtkFileChooser *file_chooser; - const gchar *icon_file; + gchar *icon_file; g_return_val_if_fail (E_IS_CATEGORY_EDITOR (editor), FALSE); g_return_val_if_fail (category != NULL, FALSE); @@ -314,11 +314,12 @@ e_category_editor_edit_category (ECategoryEditor *editor, gtk_entry_set_text (GTK_ENTRY (editor->priv->category_name), category); gtk_widget_set_sensitive (editor->priv->category_name, FALSE); - icon_file = e_categories_get_icon_file_for (category); + icon_file = e_categories_dup_icon_file_for (category); if (icon_file) { gtk_file_chooser_set_filename (file_chooser, icon_file); update_preview (file_chooser, NULL); } + g_free (icon_file); if (gtk_dialog_run (GTK_DIALOG (editor)) == GTK_RESPONSE_OK) { gchar *category_icon; diff --git a/e-util/e-misc-utils.c b/e-util/e-misc-utils.c index cf6425f88e..f47dc19275 100644 --- a/e-util/e-misc-utils.c +++ b/e-util/e-misc-utils.c @@ -1910,7 +1910,7 @@ e_util_get_category_filter_options (void) GSList *res = NULL; GList *clist, *l; - clist = e_categories_get_list (); + clist = e_categories_dup_list (); for (l = clist; l; l = l->next) { const gchar *cname = l->data; struct _filter_option *fo; @@ -1925,33 +1925,40 @@ e_util_get_category_filter_options (void) res = g_slist_prepend (res, fo); } - g_list_free (clist); + g_list_free_full (clist, g_free); return g_slist_reverse (res); } /** - * e_util_get_searchable_categories: + * e_util_dup_searchable_categories: * - * Returns list of searchable categories only. The list should - * be freed with g_list_free() when done with it, but the items - * are internal strings, names of categories, which should not - * be touched in other than read-only way, in other words the same - * restrictions as for e_categories_get_list() applies here too. - **/ + * Returns a list of the searchable categories, with each item being a UTF-8 + * category name. The list should be freed with g_list_free() when done with it, + * and the items should be freed with g_free(). Everything can be freed at once + * using g_list_free_full(). + * + * Returns: (transfer full) (element-type utf8): a list of searchable category + * names; free with g_list_free_full() + */ GList * -e_util_get_searchable_categories (void) +e_util_dup_searchable_categories (void) { GList *res = NULL, *all_categories, *l; - all_categories = e_categories_get_list (); + all_categories = e_categories_dup_list (); for (l = all_categories; l; l = l->next) { - const gchar *cname = l->data; + gchar *cname = l->data; + /* Steal the string from e_categories_dup_list(). */ if (e_categories_is_searchable (cname)) res = g_list_prepend (res, (gpointer) cname); + else + g_free (cname); } + /* NOTE: Do *not* free the items. They have been freed or stolen + * above. */ g_list_free (all_categories); return g_list_reverse (res); diff --git a/e-util/e-misc-utils.h b/e-util/e-misc-utils.h index cb262c7f76..1a0e734dec 100644 --- a/e-util/e-misc-utils.h +++ b/e-util/e-misc-utils.h @@ -160,7 +160,7 @@ gchar * e_util_guess_mime_type (const gchar *filename, GSList * e_util_get_category_filter_options (void); -GList * e_util_get_searchable_categories (void); +GList * e_util_dup_searchable_categories (void); /* Useful GBinding transform functions */ gboolean e_binding_transform_color_to_string diff --git a/e-util/e-name-selector-dialog.c b/e-util/e-name-selector-dialog.c index 8bc9131594..c900d219f0 100644 --- a/e-util/e-name-selector-dialog.c +++ b/e-util/e-name-selector-dialog.c @@ -128,7 +128,7 @@ name_selector_dialog_populate_categories (ENameSelectorDialog *name_selector_dia gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 0); /* Categories are already sorted. */ - category_list = e_categories_get_list (); + category_list = e_categories_dup_list (); for (iter = category_list; iter != NULL; iter = iter->next) { /* Only add user-visible categories. */ if (!e_categories_is_searchable (iter->data)) @@ -138,7 +138,7 @@ name_selector_dialog_populate_categories (ENameSelectorDialog *name_selector_dia GTK_COMBO_BOX_TEXT (combo_box), iter->data); } - g_list_free (category_list); + g_list_free_full (category_list, g_free); g_signal_connect_swapped ( combo_box, "changed", |