diff options
author | Maciej Stachowiak <mstachow@src.gnome.org> | 2000-10-31 04:28:54 +0000 |
---|---|---|
committer | Maciej Stachowiak <mstachow@src.gnome.org> | 2000-10-31 04:28:54 +0000 |
commit | d81e04f3ca14d0e27b243751a78adf0d2bc9e6a0 (patch) | |
tree | f7c86263f5c03a701ab03d34e231a77a830c8391 /libnautilus-extensions/nautilus-mime-actions.c | |
parent | 4243b51975025c7af7f73445972bce407ee695a5 (diff) | |
download | nautilus-d81e04f3ca14d0e27b243751a78adf0d2bc9e6a0.tar.gz |
Portions of the fix for 2379 (the parts that don't make it crash).
* libnautilus-extensions/nautilus-mime-actions.c:
(nautilus_mime_actions_check_if_minimum_attributes_ready),
(nautilus_mime_actions_check_if_full_attributes_ready),
(nautilus_mime_actions_get_minimum_file_attributes),
(nautilus_mime_actions_get_full_file_attributes),
(nautilus_mime_actions_wait_for_full_file_attributes),
(nautilus_mime_get_default_action_type_for_file),
(nautilus_mime_get_default_action_for_file),
(nautilus_mime_get_default_application_for_file_internal),
(nautilus_mime_get_default_application_for_file),
(nautilus_mime_is_default_application_for_file_user_chosen),
(nautilus_mime_get_default_component_sort_conditions),
(nautilus_mime_get_default_component_for_file_internal),
(nautilus_mime_get_short_list_applications_for_file),
(nautilus_mime_get_short_list_components_for_file),
(nautilus_mime_get_short_list_methods_for_file),
(nautilus_mime_get_all_applications_for_file),
(nautilus_mime_get_all_components_for_file),
(nautilus_mime_set_default_application_for_file),
(nautilus_mime_set_default_component_for_file),
(nautilus_mime_set_short_list_applications_for_file),
(nautilus_mime_set_short_list_components_for_file),
(nautilus_mime_add_application_to_short_list_for_file),
(nautilus_mime_remove_application_from_short_list_for_file),
(nautilus_mime_add_component_to_short_list_for_file),
(nautilus_mime_remove_component_from_short_list_for_file),
(nautilus_mime_extend_all_applications_for_file),
(nautilus_mime_remove_from_all_applications_for_file),
(nautilus_do_component_query):
* libnautilus-extensions/nautilus-mime-actions.h:
* libnautilus-extensions/nautilus-program-chooser.c:
(repopulate_program_list), (is_component_default_for_file),
(program_file_pair_is_default_for_file),
(program_file_pair_is_in_short_list_for_file),
(add_to_short_list_for_file), (remove_from_short_list_for_file),
(remove_default_for_item), (set_default_for_item):
* libnautilus-extensions/nautilus-program-choosing.c:
(any_programs_available_for_file):
* src/file-manager/fm-directory-view.c: (switch_location_and_view),
(create_open_with_gtk_menu), (reset_bonobo_open_with_menu),
(activate_callback):
* src/nautilus-applicable-views.c: (nautilus_navigation_info_new):
* src/nautilus-sidebar.c: (nautilus_sidebar_update_all),
(nautilus_sidebar_set_uri):
* src/nautilus-window.c: (nautilus_window_load_content_view_menu):
* test/test-nautilus-mime-actions-set.c: (main):
* test/test-nautilus-mime-actions.c: (main): Portions of the fix
for 2379 (the parts that don't make it crash).
Diffstat (limited to 'libnautilus-extensions/nautilus-mime-actions.c')
-rw-r--r-- | libnautilus-extensions/nautilus-mime-actions.c | 265 |
1 files changed, 167 insertions, 98 deletions
diff --git a/libnautilus-extensions/nautilus-mime-actions.c b/libnautilus-extensions/nautilus-mime-actions.c index 375c5e0e1..b6c4fac46 100644 --- a/libnautilus-extensions/nautilus-mime-actions.c +++ b/libnautilus-extensions/nautilus-mime-actions.c @@ -70,7 +70,8 @@ static gboolean server_matches_content_requirements (OAF_ServerInfo GList *explicit_iids); static GList *nautilus_do_component_query (const char *mime_type, const char *uri_scheme, - GList *files, + GList *content_mime_types, + gboolean ignore_content_mime_types, GList *explicit_iids, char **extra_sort_criteria, char *extra_requirements, @@ -98,40 +99,64 @@ is_known_mime_type (const char *mime_type) static gboolean -nautilus_mime_actions_check_if_required_attributes_ready (NautilusFile *file) +nautilus_mime_actions_check_if_minimum_attributes_ready (NautilusFile *file) { GList *attributes; gboolean ready; - attributes = nautilus_mime_actions_get_required_file_attributes (); + attributes = nautilus_mime_actions_get_minimum_file_attributes (); ready = nautilus_file_check_if_ready (file, attributes); g_list_free (attributes); return ready; } +static gboolean +nautilus_mime_actions_check_if_full_attributes_ready (NautilusFile *file) +{ + GList *attributes; + gboolean ready; + + attributes = nautilus_mime_actions_get_full_file_attributes (); + ready = nautilus_file_check_if_ready (file, attributes); + g_list_free (attributes); + + return ready; +} GList * -nautilus_mime_actions_get_required_file_attributes () +nautilus_mime_actions_get_minimum_file_attributes () { GList *attributes; attributes = NULL; attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_METADATA); attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_MIME_TYPE); + + return attributes; +} + + +GList * +nautilus_mime_actions_get_full_file_attributes () +{ + GList *attributes; + + attributes = nautilus_mime_actions_get_minimum_file_attributes (); attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_MIME_TYPES); return attributes; } + void -nautilus_mime_actions_wait_for_required_file_attributes (NautilusFile *file) +nautilus_mime_actions_wait_for_full_file_attributes (NautilusFile *file) { GList *attributes; - attributes = nautilus_mime_actions_get_required_file_attributes (); + attributes = nautilus_mime_actions_get_full_file_attributes (); nautilus_file_wait_until_ready (file, attributes); @@ -146,7 +171,7 @@ nautilus_mime_get_default_action_type_for_file (NautilusFile *file) char *action_type_string; GnomeVFSMimeActionType action_type; - g_return_val_if_fail (nautilus_mime_actions_check_if_required_attributes_ready (file), + g_return_val_if_fail (nautilus_mime_actions_check_if_minimum_attributes_ready (file), GNOME_VFS_MIME_ACTION_TYPE_NONE); action_type_string = nautilus_file_get_metadata @@ -173,7 +198,7 @@ nautilus_mime_get_default_action_for_file (NautilusFile *file) { GnomeVFSMimeAction *action; - g_return_val_if_fail (nautilus_mime_actions_check_if_required_attributes_ready (file), + g_return_val_if_fail (nautilus_mime_actions_check_if_minimum_attributes_ready (file), NULL); action = g_new0 (GnomeVFSMimeAction, 1); @@ -209,15 +234,15 @@ nautilus_mime_get_default_action_for_file (NautilusFile *file) static GnomeVFSMimeApplication * -nautilus_mime_get_default_application_for_file_internal (NautilusFile *file, - gboolean *user_chosen) +nautilus_mime_get_default_application_for_file_internal (NautilusFile *file, + gboolean *user_chosen) { char *mime_type; GnomeVFSMimeApplication *result; char *default_application_string; gboolean used_user_chosen_info; - g_return_val_if_fail (nautilus_mime_actions_check_if_required_attributes_ready (file), + g_return_val_if_fail (nautilus_mime_actions_check_if_minimum_attributes_ready (file), NULL); used_user_chosen_info = TRUE; @@ -225,6 +250,8 @@ nautilus_mime_get_default_application_for_file_internal (NautilusFile *file default_application_string = nautilus_file_get_metadata (file, NAUTILUS_METADATA_KEY_DEFAULT_APPLICATION, NULL); + /* FIXME: should fall back to normal default if user-specified default is bogus */ + if (default_application_string == NULL) { mime_type = nautilus_file_get_mime_type (file); result = gnome_vfs_mime_get_default_application (mime_type); @@ -242,13 +269,13 @@ nautilus_mime_get_default_application_for_file_internal (NautilusFile *file } GnomeVFSMimeApplication * -nautilus_mime_get_default_application_for_file (NautilusFile *file) +nautilus_mime_get_default_application_for_file (NautilusFile *file) { return nautilus_mime_get_default_application_for_file_internal (file, NULL); } gboolean -nautilus_mime_is_default_application_for_file_user_chosen (NautilusFile *file) +nautilus_mime_is_default_application_for_file_user_chosen (NautilusFile *file) { GnomeVFSMimeApplication *application; gboolean user_chosen; @@ -268,60 +295,19 @@ nautilus_mime_is_default_application_for_file_user_chosen (NautilusFile *fi } -static OAF_ServerInfo * -nautilus_mime_get_default_component_for_file_internal (NautilusFile *file, - gboolean *user_chosen) +static char ** +nautilus_mime_get_default_component_sort_conditions (NautilusFile *file, char *default_component_string) { - GList *info_list; - OAF_ServerInfo *mime_default; - char *default_component_string; - char *mime_type; - char *uri_scheme; - GList *item_mime_types; - GList *explicit_iids; - CORBA_Environment ev; - OAF_ServerInfo *server; - char *sort_conditions[5]; + char **sort_conditions; char *supertype; - gboolean used_user_chosen_info; + char *mime_type; GList *short_list; GList *p; char *prev; - - g_return_val_if_fail (nautilus_mime_actions_check_if_required_attributes_ready (file), - NULL); - - used_user_chosen_info = TRUE; - - CORBA_exception_init (&ev); - - mime_type = nautilus_file_get_mime_type (file); - - uri_scheme = nautilus_file_get_uri_scheme (file); - - explicit_iids = get_explicit_content_view_iids_from_metafile (file); - nautilus_file_get_directory_item_mime_types (file, &item_mime_types); - - default_component_string = nautilus_file_get_metadata - (file, NAUTILUS_METADATA_KEY_DEFAULT_COMPONENT, NULL); - - if (default_component_string == NULL && is_known_mime_type (mime_type)) { - mime_default = gnome_vfs_mime_get_default_component (mime_type); - if (mime_default != NULL) { - default_component_string = g_strdup (mime_default->iid); - if (default_component_string != NULL) { - /* Default component chosen based only on type. */ - used_user_chosen_info = FALSE; - } - CORBA_free (mime_default); - } - } - /* FIXME bugzilla.eazel.com 1264: - * should return NULL for the following cases: - * - Known URI scheme pointing to nonexistent location - * - Syntactically invalid URI - */ + sort_conditions = g_new0 (char *, 5); + + mime_type = nautilus_file_get_mime_type (file); supertype = mime_type_get_supertype (mime_type); @@ -373,9 +359,93 @@ nautilus_mime_get_default_component_for_file_internal (NautilusFile *file, } sort_conditions[4] = NULL; + + g_free (mime_type); + g_free (supertype); + + return sort_conditions; +} + + + +static OAF_ServerInfo * +nautilus_mime_get_default_component_for_file_internal (NautilusFile *file, + gboolean *user_chosen) +{ + GList *info_list; + OAF_ServerInfo *mime_default; + char *default_component_string; + char *mime_type; + char *uri_scheme; + GList *item_mime_types; + GList *explicit_iids; + CORBA_Environment ev; + OAF_ServerInfo *server; + char **sort_conditions; + char *extra_requirements; + gboolean used_user_chosen_info; + gboolean metadata_default; + + g_return_val_if_fail (nautilus_mime_actions_check_if_minimum_attributes_ready (file), + NULL); + + used_user_chosen_info = TRUE; + + info_list = NULL; + + CORBA_exception_init (&ev); + + mime_type = nautilus_file_get_mime_type (file); + + uri_scheme = nautilus_file_get_uri_scheme (file); + + explicit_iids = get_explicit_content_view_iids_from_metafile (file); + + if (!nautilus_mime_actions_check_if_full_attributes_ready (file) || + !nautilus_file_get_directory_item_mime_types (file, &item_mime_types)) { + item_mime_types = NULL; + } + + default_component_string = nautilus_file_get_metadata + (file, NAUTILUS_METADATA_KEY_DEFAULT_COMPONENT, NULL); + + if (default_component_string == NULL && is_known_mime_type (mime_type)) { + metadata_default = FALSE; + mime_default = gnome_vfs_mime_get_default_component (mime_type); + if (mime_default != NULL) { + default_component_string = g_strdup (mime_default->iid); + if (default_component_string != NULL) { + /* Default component chosen based only on type. */ + used_user_chosen_info = FALSE; + } + CORBA_free (mime_default); + } + } else { + metadata_default = TRUE; + } + + /* FIXME bugzilla.eazel.com 1264: + * should return NULL for the following cases: + * - Known URI scheme pointing to nonexistent location + * - Syntactically invalid URI + */ - info_list = nautilus_do_component_query (mime_type, uri_scheme, item_mime_types, explicit_iids, - sort_conditions, NULL, &ev); + sort_conditions = nautilus_mime_get_default_component_sort_conditions (file, default_component_string); + + /* If the default is specified in the per-uri metadata, + respect the setting regardless of content type requirements */ + if (metadata_default) { + extra_requirements = g_strconcat ("iid = '", default_component_string, "'"); + + info_list = nautilus_do_component_query (mime_type, uri_scheme, item_mime_types, TRUE, + explicit_iids, sort_conditions, extra_requirements, &ev); + g_free (extra_requirements); + } + + if (info_list == NULL) { + info_list = nautilus_do_component_query (mime_type, uri_scheme, item_mime_types, FALSE, + explicit_iids, sort_conditions, NULL, &ev); + } if (ev._major == CORBA_NO_EXCEPTION && info_list != NULL) { server = OAF_ServerInfo_duplicate (info_list->data); @@ -390,11 +460,8 @@ nautilus_mime_get_default_component_for_file_internal (NautilusFile *file, return NULL; } - g_free (sort_conditions[0]); - g_free (sort_conditions[1]); - g_free (sort_conditions[2]); - g_free (sort_conditions[3]); - g_free (supertype); + g_strfreev (sort_conditions); + g_free (uri_scheme); g_free (mime_type); g_free (default_component_string); @@ -448,7 +515,7 @@ nautilus_mime_get_short_list_applications_for_file (NautilusFile *file) GnomeVFSMimeApplication *application; CORBA_Environment ev; - g_return_val_if_fail (nautilus_mime_actions_check_if_required_attributes_ready (file), + g_return_val_if_fail (nautilus_mime_actions_check_if_minimum_attributes_ready (file), NULL); CORBA_exception_init (&ev); @@ -510,7 +577,7 @@ nautilus_mime_get_short_list_components_for_file (NautilusFile *file) char *extra_requirements; char *prev; - g_return_val_if_fail (nautilus_mime_actions_check_if_required_attributes_ready (file), + g_return_val_if_fail (nautilus_mime_actions_check_if_minimum_attributes_ready (file), NULL); CORBA_exception_init (&ev); @@ -518,7 +585,11 @@ nautilus_mime_get_short_list_components_for_file (NautilusFile *file) uri_scheme = nautilus_file_get_uri_scheme (file); explicit_iids = get_explicit_content_view_iids_from_metafile (file); - nautilus_file_get_directory_item_mime_types (file, &item_mime_types); + + if (!nautilus_mime_actions_check_if_full_attributes_ready (file) || + !nautilus_file_get_directory_item_mime_types (file, &item_mime_types)) { + item_mime_types = NULL; + } metadata_component_add_ids = nautilus_file_get_metadata_list (file, @@ -574,7 +645,8 @@ nautilus_mime_get_short_list_components_for_file (NautilusFile *file) } - result = nautilus_do_component_query (mime_type, uri_scheme, item_mime_types, explicit_iids, NULL, extra_requirements, &ev); + result = nautilus_do_component_query (mime_type, uri_scheme, item_mime_types, FALSE, + explicit_iids, NULL, extra_requirements, &ev); g_free (extra_requirements); } @@ -594,7 +666,7 @@ nautilus_mime_get_short_list_methods_for_file (NautilusFile *file) char *mime_type; const char *method; - g_return_val_if_fail (nautilus_mime_actions_check_if_required_attributes_ready (file), + g_return_val_if_fail (nautilus_mime_actions_check_if_minimum_attributes_ready (file), NULL); mime_type = nautilus_file_get_mime_type (file); @@ -612,7 +684,7 @@ nautilus_mime_get_all_applications_for_file (NautilusFile *file) GList *p; GnomeVFSMimeApplication *application; - g_return_val_if_fail (nautilus_mime_actions_check_if_required_attributes_ready (file), + g_return_val_if_fail (nautilus_mime_actions_check_if_minimum_attributes_ready (file), NULL); metadata_application_ids = nautilus_file_get_metadata_list @@ -663,7 +735,7 @@ nautilus_mime_get_all_components_for_file (NautilusFile *file) GList *explicit_iids; CORBA_Environment ev; - g_return_val_if_fail (nautilus_mime_actions_check_if_required_attributes_ready (file), + g_return_val_if_fail (nautilus_mime_actions_check_if_minimum_attributes_ready (file), NULL); CORBA_exception_init (&ev); @@ -672,9 +744,14 @@ nautilus_mime_get_all_components_for_file (NautilusFile *file) mime_type = nautilus_file_get_mime_type (file); explicit_iids = get_explicit_content_view_iids_from_metafile (file); - nautilus_file_get_directory_item_mime_types (file, &item_mime_types); - info_list = nautilus_do_component_query (mime_type, uri_scheme, item_mime_types, explicit_iids, NULL, NULL, &ev); + if (!nautilus_mime_actions_check_if_full_attributes_ready (file) || + !nautilus_file_get_directory_item_mime_types (file, &item_mime_types)) { + item_mime_types = NULL; + } + + info_list = nautilus_do_component_query (mime_type, uri_scheme, item_mime_types, FALSE, + explicit_iids, NULL, NULL, &ev); g_free (uri_scheme); g_free (mime_type); @@ -724,7 +801,7 @@ GnomeVFSResult nautilus_mime_set_default_application_for_file (NautilusFile *file, const char *application_id) { - g_return_val_if_fail (nautilus_mime_actions_check_if_required_attributes_ready (file), + g_return_val_if_fail (nautilus_mime_actions_check_if_minimum_attributes_ready (file), GNOME_VFS_ERROR_GENERIC); nautilus_file_set_metadata @@ -743,7 +820,7 @@ GnomeVFSResult nautilus_mime_set_default_component_for_file (NautilusFile *file, const char *component_iid) { - g_return_val_if_fail (nautilus_mime_actions_check_if_required_attributes_ready (file), + g_return_val_if_fail (nautilus_mime_actions_check_if_minimum_attributes_ready (file), GNOME_VFS_ERROR_GENERIC); nautilus_file_set_metadata @@ -769,7 +846,7 @@ nautilus_mime_set_short_list_applications_for_file (NautilusFile *file, GList *p; char *mime_type; - g_return_val_if_fail (nautilus_mime_actions_check_if_required_attributes_ready (file), + g_return_val_if_fail (nautilus_mime_actions_check_if_minimum_attributes_ready (file), GNOME_VFS_ERROR_GENERIC); /* get per-mime short list */ @@ -817,7 +894,7 @@ nautilus_mime_set_short_list_components_for_file (NautilusFile *file, GList *p; char *mime_type; - g_return_val_if_fail (nautilus_mime_actions_check_if_required_attributes_ready (file), + g_return_val_if_fail (nautilus_mime_actions_check_if_minimum_attributes_ready (file), GNOME_VFS_ERROR_GENERIC); /* get per-mime short list */ @@ -860,7 +937,7 @@ nautilus_mime_add_application_to_short_list_for_file (NautilusFile *file, GList *old_list, *new_list; GnomeVFSResult result; - g_return_val_if_fail (nautilus_mime_actions_check_if_required_attributes_ready (file), + g_return_val_if_fail (nautilus_mime_actions_check_if_minimum_attributes_ready (file), GNOME_VFS_ERROR_GENERIC); result = GNOME_VFS_OK; @@ -887,7 +964,7 @@ nautilus_mime_remove_application_from_short_list_for_file (NautilusFile *fi gboolean was_in_list; GnomeVFSResult result; - g_return_val_if_fail (nautilus_mime_actions_check_if_required_attributes_ready (file), + g_return_val_if_fail (nautilus_mime_actions_check_if_minimum_attributes_ready (file), GNOME_VFS_ERROR_GENERIC); old_list = nautilus_mime_get_short_list_applications_for_file (file); @@ -914,7 +991,7 @@ nautilus_mime_add_component_to_short_list_for_file (NautilusFile *file, GList *old_list, *new_list; GnomeVFSResult result; - g_return_val_if_fail (nautilus_mime_actions_check_if_required_attributes_ready (file), + g_return_val_if_fail (nautilus_mime_actions_check_if_minimum_attributes_ready (file), GNOME_VFS_ERROR_GENERIC); old_list = nautilus_mime_get_short_list_components_for_file (file); @@ -941,7 +1018,7 @@ nautilus_mime_remove_component_from_short_list_for_file (NautilusFile *file, gboolean was_in_list; GnomeVFSResult result; - g_return_val_if_fail (nautilus_mime_actions_check_if_required_attributes_ready (file), + g_return_val_if_fail (nautilus_mime_actions_check_if_minimum_attributes_ready (file), GNOME_VFS_ERROR_GENERIC); old_list = nautilus_mime_get_short_list_components_for_file (file); @@ -969,7 +1046,7 @@ nautilus_mime_extend_all_applications_for_file (NautilusFile *file, GList *extras; GList *final_applications; - g_return_val_if_fail (nautilus_mime_actions_check_if_required_attributes_ready (file), + g_return_val_if_fail (nautilus_mime_actions_check_if_minimum_attributes_ready (file), GNOME_VFS_ERROR_GENERIC); metadata_application_ids = nautilus_file_get_metadata_list @@ -997,7 +1074,7 @@ nautilus_mime_remove_from_all_applications_for_file (NautilusFile *file, GList *metadata_application_ids; GList *final_applications; - g_return_val_if_fail (nautilus_mime_actions_check_if_required_attributes_ready (file), + g_return_val_if_fail (nautilus_mime_actions_check_if_minimum_attributes_ready (file), GNOME_VFS_ERROR_GENERIC); metadata_application_ids = nautilus_file_get_metadata_list @@ -1390,22 +1467,13 @@ static char *nautilus_sort_criteria[] = { "name", NULL}; -#if 0 - /* Prefer the industrial strengthe html viewer most */ - "iid == 'OAFIID:nautilus_mozilla_content_view:1ee70717-57bf-4079-aae5-922abdd576b1'", - /* Prefer the gtkhtml viewer next */ - "iid == 'OAFIID:ntl_web_browser:0ce1a736-c939-4ac7-b12c-19d72bf1510b'", - /* Prefer the icon view next */ - "iid == 'OAFIID:ntl_file_manager_icon_view:42681b21-d5ca-4837-87d2-394d88ecc058'", -#endif; - - static GList * nautilus_do_component_query (const char *mime_type, const char *uri_scheme, GList *item_mime_types, + gboolean ignore_content_mime_types, GList *explicit_iids, char **extra_sort_criteria, char *extra_requirements, @@ -1449,7 +1517,8 @@ nautilus_do_component_query (const char *mime_type, server = &oaf_result->_buffer[i]; - if (server_matches_content_requirements (server, content_types, explicit_iids)) { + if (ignore_content_mime_types || + server_matches_content_requirements (server, content_types, explicit_iids)) { retval = g_list_append (retval, OAF_ServerInfo_duplicate (server)); |