diff options
author | Maciej Stachowiak <mstachow@src.gnome.org> | 2000-05-20 02:49:36 +0000 |
---|---|---|
committer | Maciej Stachowiak <mstachow@src.gnome.org> | 2000-05-20 02:49:36 +0000 |
commit | cf21c9eef131dc1a86c856866533631a8100078b (patch) | |
tree | 4ccce2ad32b705a4e4bdbef9f0cf902084ccdfa4 /libnautilus-private/nautilus-glib-extensions.c | |
parent | 7f1e84bb7a02c7ebc7bbb69a2ee6d26591d0c3ec (diff) | |
download | nautilus-cf21c9eef131dc1a86c856866533631a8100078b.tar.gz |
Fix bugzilla tasks #599 (hex number is bad default for meta view
names) and #631 (nead oaf query to determine metaviews).
* libnautilus-extensions/nautilus-view-identifier.h,
libnautilus-extensions/nautilus-view-identifier.c:
(nautilus_view_identifier_new, get_lang_list,
nautilus_view_identifier_new_from_oaf_server_info,
nautilus_view_identifier_free): Moved NautilusViewIdentifier code
here from ntl-uri-map.[ch].
(nautilus_view_identifier_new_from_content_view),
(nautilus_view_identifier_new_from_sidebar_panel),
(nautilus_view_identifier_free_callback),
(nautilus_view_identifier_free_list): New functions.
* libnautilus-extensions/Makefile.am: Add
nautilus-view-identifier.[ch] to build.
* src/ntl-types.h: Removed typedef for NautilusViewIdentifier.
* libnautilus-extensions/nautilus-glib-extensions.h:
* libnautilus-extensions/nautilus-glib-extensions.c
(nautilus_g_list_free_deep_custom): New function, like
`nautilus_g_list_free_deep' but lets you pass your own free
function.
(nautilus_g_list_free_deep): Use `nautilus_g_list_free_deep_custom'
(nautilus_g_list_partition): New function to destructively
partition a GList into two, depending on whether they satisfy the
provided predicate or not.
(nautilus_test_predicate), (nautilus_self_check_glib_extensions):
Added unit tests for `nautilus_g_list_partition' and for
`nautilus_g_list_equal' since the `nautilus_g_list_partition'
tests rely on it.
* libnautilus-extensions/nautilus-directory.c:
(nautilus_directory_notify_files_moved): Use
`nautilus_g_list_free_deep_custom'.
* libnautilus-extensions/nautilus-gdk-pixbuf-extensions.c
(nautilus_gdk_pixbuf_list_free): Likewise.
* libnautilus-extensions/nautilus-icon-factory.c
(nautilus_scalable_icon_list_free): Likewise.
* libnautilus-extensions/nautilus-string-list.c
(nautilus_string_list_clear): Likewise.
* nautilus-widgets/nautilus-preferences.c (pref_hash_node_free,
prefs_hash_lookup_with_implicit_registration): Likewise.
* libnautilus-extensions/nautilus-global-preferences.c,
libnautilus-extensions/nautilus-global-preferences.h
(global_preferences_create_dialog,
nautilus_global_preferences_get_sidebar_panel_view_identifiers,
nautilus_global_preferences_get_meta_view_iids,
nautilus_preferences_register_meta_view_preferences_for_ui,
global_preferences_register_for_ui): Change things around to
determine the set of sidebar panel prefs at run time, and to pass
around NautilusViewIdentifiers rather than just iid strings so we
can use the statically defined name in the oafinfo.
* src/ntl-uri-map.h, src/ntl-uri-map.c: (set_initial_content_iid,
got_file_info_callback, sidebar_panel_preference_is_on,
(add_sidebar_panel_identifiers, nautilus_navigation_info_free):
Changed things around to better handle sidebar panel (AKA meta
view) selection, and pass around both name and iid.
* src/ntl-window-msgs.c:
(nautilus_window_request_selection_change,
nautilus_window_has_really_changed,
nautilus_window_load_meta_view, nautilus_window_update_state,
nautilus_window_set_state_info): Fixed everything to pass around
ViewIdentifiers instead of iids for sidebar panels and set the
label approrpiately when activating; replaced a whole bunch of
GSList usage with GList (we can always optimize this stuff later).
* src/ntl-window.h, src/ntl-window.c: (nautilus_window_destroy,
nautilus_window_load_content_view_menu,
nautilus_window_set_content_view, nautilus_window_add_meta_view,
nautilus_window_remove_meta_view_real,
nautilus_window_remove_meta_view): Deal with the above changes
(mostly GSList -> GList changes).
* src/ntl-view-bonobo-control.c, src/ntl-view-bonobo-subdoc.c,
src/ntl-view-nautilus.c, src/ntl-view-private.h: Remove all
get_label related calls since we get that from the oafinfo now.
* libnautilus/nautilus-meta-view-frame.h,
libnautilus/nautilus-meta-view-frame.c:
(nautilus_meta_view_frame_initialize,
nautilus_meta_view_frame_new_from_bonobo_control,
nautilus_meta_view_frame_destroy): Remove
`nautilus_meta_view_frame_set_label' machinery and associated
machinery since we now get the label statically from the oafinfo.
* components/history/ntl-history-view.c: (make_obj): Don't call
`nautilus_meta_view_frame_set_label' any more, the label is now
statically determined from the oafinfo file.
* components/notes/ntl-notes.c: (make_notes_view): Likewise.
* components/websearch/ntl-web-search.c: (make_obj): Likewise.
* components/help/hyperbola-nav-index.c: Likewise.
(hyperbola_navigation_index_new): Likewise.
* components/help/hyperbola-nav-search.c: Likewise.
(hyperbola_navigation_search_new): Likewise.
* components/help/hyperbola-nav-tree.c: Likewise.
(hyperbola_navigation_tree_new): Likewise.
* src/ntl-meta-view.h, src/ntl-meta-view.c:
(nautilus_meta_view_set_label),
(nautilus_meta_view_get_label): Have an explicit value to set,
rather than trying to get it through CORBA. This is kind of a
hack, really we should pass around a label and a NautilusMetaView
separately and remove this stuff.
* components/help/hyperbola.oafinfo,
components/notes/ntl-notes.oafinfo,
components/websearch/ntl-web-search.oafinfo,
components/history/ntl-history-view.oafinfo: Updated to include
latest Nautilus attributes.
Diffstat (limited to 'libnautilus-private/nautilus-glib-extensions.c')
-rw-r--r-- | libnautilus-private/nautilus-glib-extensions.c | 175 |
1 files changed, 173 insertions, 2 deletions
diff --git a/libnautilus-private/nautilus-glib-extensions.c b/libnautilus-private/nautilus-glib-extensions.c index 06f791402..a34a8da88 100644 --- a/libnautilus-private/nautilus-glib-extensions.c +++ b/libnautilus-private/nautilus-glib-extensions.c @@ -196,6 +196,23 @@ nautilus_g_str_list_copy (GList *list) return result; } + +/** + * nautilus_g_list_free_deep_custom + * + * Frees the elements of a list and then the list, using a custom free function. + * + * @list: List of elements that can be freed with the provided free function. + * @element_free_func: function to call with the data pointer and user_data to free it. + * @user_data: User data to pass to element_free_func + **/ +void +nautilus_g_list_free_deep_custom (GList *list, GFunc element_free_func, gpointer user_data) +{ + g_list_foreach (list, element_free_func, user_data); + g_list_free (list); +} + /** * nautilus_g_list_free_deep * @@ -205,10 +222,10 @@ nautilus_g_str_list_copy (GList *list) void nautilus_g_list_free_deep (GList *list) { - g_list_foreach (list, (GFunc) g_free, NULL); - g_list_free (list); + nautilus_g_list_free_deep_custom (list, (GFunc) g_free, NULL); } + /** * nautilus_g_strv_find * @@ -258,6 +275,68 @@ nautilus_g_list_safe_for_each (GList *list, GFunc function, gpointer user_data) } /** + * nautilus_g_list_partition + * + * Parition a list into two parts depending on whether the data + * elements satisfy a provided predicate. Order is preserved in both + * of the resulting lists, and the original list is consumed. A list + * of the items that satisfy the predicate is returned, and the list + * of items not satisfying the predicate is returned via the failed + * out argument. + * + * @list: List to partition. + * @predicate: Function to call on each element. + * @user_data: Data to pass to function. + * @removed: The GList * variable pinted to by this argument will be + * set to the list of elements for which the predicate returned + * false. */ + +GList * +nautilus_g_list_partition (GList *list, + NautilusGPredicateFunc predicate, + gpointer user_data, + GList **failed) +{ + GList *predicate_true; + GList *predicate_false; + GList *reverse; + GList *p; + GList *next; + + predicate_true = NULL; + predicate_false = NULL; + + reverse = g_list_reverse (list); + + for (p = reverse; p != NULL; p = next) { + next = p->next; + + if (next != NULL) { + next->prev = NULL; + } + + if (predicate (p->data, user_data)) { + p->next = predicate_true; + if (predicate_true != NULL) { + predicate_true->prev = p; + } + predicate_true = p; + } else { + p->next = predicate_false; + if (predicate_false != NULL) { + predicate_false->prev = p; + } + predicate_false = p; + } + } + + *failed = predicate_false; + return predicate_true; +} + + + +/** * nautilus_g_ptr_array_new_from_list * * Copies (shallow) a list of pointers into an array of pointers. @@ -461,10 +540,32 @@ check_tm_to_g_date (time_t time) before_conversion->tm_year); } +static gboolean +nautilus_test_predicate (char *data, + char *user_data) +{ + if (g_strcasecmp (data, user_data) <= 0) { + return TRUE; + } else { + return FALSE; + } +} + void nautilus_self_check_glib_extensions (void) { char **strv; + GList *compare_list_1; + GList *compare_list_2; + GList *compare_list_3; + GList *compare_list_4; + GList *compare_list_5; + GList *list_to_partition; + GList *expected_passed; + GList *expected_failed; + GList *actual_passed; + GList *actual_failed; + check_tm_to_g_date (0); /* lower limit */ check_tm_to_g_date ((time_t) -1); /* upper limit */ @@ -483,6 +584,76 @@ nautilus_self_check_glib_extensions (void) NAUTILUS_CHECK_BOOLEAN_RESULT ((nautilus_get_system_time () - nautilus_get_system_time ()) < 0LL, TRUE); g_strfreev (strv); + + /* nautilus_g_str_list_equal */ + + /* We g_strdup because identical string constants can be shared. */ + + compare_list_1 = NULL; + compare_list_1 = g_list_append (list_to_partition, g_strdup ("Apple")); + compare_list_1 = g_list_append (list_to_partition, g_strdup ("zebra")); + compare_list_1 = g_list_append (list_to_partition, g_strdup ("!@#!@$#@$!")); + + compare_list_2 = NULL; + compare_list_2 = g_list_append (list_to_partition, g_strdup ("Apple")); + compare_list_2 = g_list_append (list_to_partition, g_strdup ("zebra")); + compare_list_2 = g_list_append (list_to_partition, g_strdup ("!@#!@$#@$!")); + + compare_list_3 = NULL; + compare_list_3 = g_list_append (list_to_partition, g_strdup ("Apple")); + compare_list_3 = g_list_append (list_to_partition, g_strdup ("zebra")); + + compare_list_4 = NULL; + compare_list_4 = g_list_append (list_to_partition, g_strdup ("Apple")); + compare_list_4 = g_list_append (list_to_partition, g_strdup ("zebra")); + compare_list_4 = g_list_append (list_to_partition, g_strdup ("!@#!@$#@$!")); + compare_list_4 = g_list_append (list_to_partition, g_strdup ("foobar")); + + compare_list_5 = NULL; + compare_list_5 = g_list_append (list_to_partition, g_strdup ("Apple")); + compare_list_5 = g_list_append (list_to_partition, g_strdup ("zzzzzebraaaaaa")); + compare_list_5 = g_list_append (list_to_partition, g_strdup ("!@#!@$#@$!")); + + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_g_str_list_equal (compare_list_1, compare_list_2), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_g_str_list_equal (compare_list_1, compare_list_3), FALSE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_g_str_list_equal (compare_list_1, compare_list_4), FALSE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_g_str_list_equal (compare_list_1, compare_list_5), FALSE); + + nautilus_g_list_free_deep (compare_list_1); + nautilus_g_list_free_deep (compare_list_2); + nautilus_g_list_free_deep (compare_list_3); + nautilus_g_list_free_deep (compare_list_4); + nautilus_g_list_free_deep (compare_list_5); + + + /* nautilus_g_list_partition */ + + list_to_partition = NULL; + list_to_partition = g_list_append (list_to_partition, "Cadillac"); + list_to_partition = g_list_append (list_to_partition, "Pontiac"); + list_to_partition = g_list_append (list_to_partition, "Ford"); + list_to_partition = g_list_append (list_to_partition, "Range Rover"); + + expected_passed = NULL; + expected_passed = g_list_append (list_to_partition, "Cadillac"); + expected_passed = g_list_append (list_to_partition, "Ford"); + + expected_failed = NULL; + expected_failed = g_list_append (list_to_partition, "Pontiac"); + expected_failed = g_list_append (list_to_partition, "Range Rover"); + + actual_passed = nautilus_g_list_partition (list_to_partition, + (NautilusGPredicateFunc) nautilus_test_predicate, + "m", + &actual_failed); + + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_g_str_list_equal (expected_passed, actual_passed), TRUE); + NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_g_str_list_equal (expected_failed, actual_failed), TRUE); + + nautilus_g_list_free_deep (expected_passed); + nautilus_g_list_free_deep (actual_passed); + nautilus_g_list_free_deep (expected_failed); + nautilus_g_list_free_deep (actual_failed); } #endif /* !NAUTILUS_OMIT_SELF_CHECK */ |