diff options
author | Rebecca Schulman <rebecka@eazel.com> | 2001-02-23 05:08:15 +0000 |
---|---|---|
committer | Rebecca Schulman <rebecka@src.gnome.org> | 2001-02-23 05:08:15 +0000 |
commit | f1209514471862cbb9ad8253ae2669bc6dc7ca3f (patch) | |
tree | a4a816d0ae135168b6589ede2182b8e57e8730ad /libnautilus-private | |
parent | b6fe6b3f4c68afcb88cd200fdf2fc29f0942b844 (diff) | |
download | nautilus-f1209514471862cbb9ad8253ae2669bc6dc7ca3f.tar.gz |
Fix bug 6058, that opening a file with a default application that cannot
2001-02-22 Rebecca Schulman <rebecka@eazel.com>
Fix bug 6058, that opening a file with a default
application that cannot access a location (in the specific
case of the bug, eazel-services) should explain the problem,
and offer another application, rather than simply failing.
reviewed by: John Sullivan <sullivan@eazel.com>
* libnautilus-extensions/nautilus-program-choosing.h:
* libnautilus-extensions/nautilus-program-choosing.c:
(nautilus_choose_application_for_file),
(application_can_handle_uri), (application_cannot_open_location),
(nautilus_launch_application),
(launch_application_callback),
(launch_parameters_new),
(launch_parameters_free), (launch_application_callback):
Change nautilus_launch_application to take a NautilusFile rather
than a uri, so that we can find out whether other applications
are available for the location, using the mime type as well
as uri scheme. Change the dialogs that come up when an application
is not available for a particular location to explain more of what
we know. If another application is available to open the uri,
open the program chooser dialog.
* src/file-manager/fm-directory-view.c:
(application_launch_parameters_new),
(application_launch_parameters_free),
(fm_directory_view_launch_application),
(fm_directory_view_chose_application_callback), (choose_program),
(bonobo_launch_application_callback),
(add_application_to_bonobo_menu), (reset_bonobo_open_with_menu),
(activate_callback):
Change the parameters sent to nautilus_launch_application, and
so change data sent to callbacks used to later call
nautilus_launch_application
* src/nautilus-sidebar.c: (command_button_callback),
(nautilus_sidebar_chose_application_callback):
Call nautilus_launch_application with the new arguments
Diffstat (limited to 'libnautilus-private')
-rw-r--r-- | libnautilus-private/nautilus-program-choosing.c | 190 | ||||
-rw-r--r-- | libnautilus-private/nautilus-program-choosing.h | 2 |
2 files changed, 174 insertions, 18 deletions
diff --git a/libnautilus-private/nautilus-program-choosing.c b/libnautilus-private/nautilus-program-choosing.c index 22ab25390..6713fc2a9 100644 --- a/libnautilus-private/nautilus-program-choosing.c +++ b/libnautilus-private/nautilus-program-choosing.c @@ -32,8 +32,10 @@ #include "nautilus-program-chooser.h" #include "nautilus-stock-dialogs.h" #include "nautilus-string.h" +#include <gtk/gtk.h> #include <libgnome/gnome-i18n.h> #include <libgnomeui/gnome-uidefs.h> +#include <libgnomevfs/gnome-vfs-mime-handlers.h> #include <libgnomevfs/gnome-vfs-utils.h> #include <stdlib.h> @@ -405,36 +407,190 @@ nautilus_choose_application_for_file (NautilusFile *file, g_list_free (attributes); } +static gboolean +application_can_handle_uri (gpointer application_data, + gpointer uri_scheme) +{ + GnomeVFSMimeApplication *application; + + g_assert (application_data != NULL); + + application = (GnomeVFSMimeApplication *) application_data; + + return g_list_find_custom (application->supported_uri_schemes, + uri_scheme, + nautilus_strcmp_compare_func) != NULL; + +} + +typedef struct { + NautilusFile *file; + GtkWindow *parent_window; +} LaunchParameters; + +static LaunchParameters * +launch_parameters_new (NautilusFile *file, + GtkWindow *parent_window) +{ + LaunchParameters *launch_parameters; + + launch_parameters = g_new0 (LaunchParameters, 1); + nautilus_file_ref (file); + launch_parameters->file = file; + gtk_widget_ref (GTK_WIDGET (parent_window)); + launch_parameters->parent_window = parent_window; + + return launch_parameters; +} + +static void +launch_parameters_free (LaunchParameters *launch_parameters) +{ + g_assert (launch_parameters != NULL); + + nautilus_file_unref (launch_parameters->file); + gtk_widget_unref (GTK_WIDGET (launch_parameters->parent_window)); + + g_free (launch_parameters); +} + +static void +launch_application_callback (GnomeVFSMimeApplication *application, + gpointer callback_data) +{ + LaunchParameters *launch_parameters; + + g_assert (callback_data != NULL); + + launch_parameters = (LaunchParameters *) callback_data; + + if (application != NULL) { + g_assert (NAUTILUS_IS_FILE (launch_parameters->file)); + + nautilus_launch_application (application, + launch_parameters->file, + launch_parameters->parent_window); + } + + launch_parameters_free (launch_parameters); + +} + +/** + * application_cannot_open_location + * + * Handle the case where an application has been selected to be launched, + * and it cannot handle the current uri scheme. This can happen + * because the default application for a file type may not be able + * to handle some kinds of locations. We want to tell users that their + * default application doesn't work here, rather than switching off to + * a different one without them noticing. + * + * @application: The application that was to be launched. + * @file: The file whose location was passed as a parameter to the application + * @parent_window: A window to use as the parent for any error dialogs. + * */ +static void +application_cannot_open_location (GnomeVFSMimeApplication *application, + NautilusFile *file, + const char *uri_scheme, + GtkWindow *parent_window) +{ + GList *available_applications, *available_applications_for_uri; + GList *other_applications; + GnomeDialog *message_dialog; + LaunchParameters *launch_parameters; + char *message; + char *file_name; + + available_applications = nautilus_mime_get_all_applications_for_file (file); + available_applications_for_uri = nautilus_g_list_partition (available_applications, + application_can_handle_uri, + (gpointer) uri_scheme, + &other_applications); + gnome_vfs_mime_application_list_free (other_applications); + + file_name = nautilus_file_get_name (file); + + if (available_applications_for_uri != NULL) { + message = g_strdup_printf (_("\"%s\" can't open \"%s\" because \"%s\" can't access files at \"%s\" " + "locations. Would you like to choose another application?"), + application->name, file_name, + application->name, uri_scheme); + message_dialog = nautilus_show_yes_no_dialog (message, + _("Can't Open Location"), + GNOME_STOCK_BUTTON_OK, + GNOME_STOCK_BUTTON_CANCEL, + parent_window); + if (gnome_dialog_run (message_dialog) == GNOME_OK) { + launch_parameters = launch_parameters_new (file, parent_window); + nautilus_choose_application_for_file + (file, + parent_window, + launch_application_callback, + launch_parameters); + + } + + } + else { + message = g_strdup_printf (_("\"%s\" can't open \"%s\" because \"%s\" can't access files at \"%s\" " + "locations. No other applications are available to view this file. " + "If you copy this file onto your computer, you will be able to open " + "it."), application->name, file_name, + application->name, uri_scheme); + nautilus_show_info_dialog (message, _("Can't Open Location"), parent_window); + } + + gnome_vfs_mime_application_list_free (available_applications_for_uri); + g_free (file_name); + g_free (message); +} + /** * nautilus_launch_application: * - * Fork off a process to launch an application with a given uri as - * a parameter. Provide a parent window for error dialogs. + * Fork off a process to launch an application with a given file as a + * parameter. Provide a parent window for error dialogs. * * @application: The application to be launched. - * @uri: Passed as a parameter to the application. + * @file: The file whose location should be passed as a parameter to the application * @parent_window: A window to use as the parent for any error dialogs. - * */ void nautilus_launch_application (GnomeVFSMimeApplication *application, - const char *uri, + NautilusFile *file, GtkWindow *parent_window) { - GnomeDialog *dialog; char *parameter; - char *prompt; + char *uri_scheme, *uri; + + uri_scheme = nautilus_file_get_uri_scheme (file); /* If the program can open URIs, always use a URI. This * prevents any possible ambiguity for cases where a path * would looks like a URI. */ if (application->expects_uris == GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS || - (application->expects_uris == GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS_FOR_NON_FILES && - !nautilus_istr_has_prefix (uri, "file:"))) { - parameter = g_strdup (uri); + ((application->expects_uris == GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS_FOR_NON_FILES) && + nautilus_strcasecmp (uri_scheme, "file:") != 0)) { + /* Check to be sure that the application also supports this particular URI scheme */ + if (g_list_find_custom (application->supported_uri_schemes, + uri_scheme, + nautilus_strcmp_compare_func) == NULL) { + application_cannot_open_location (application, + file, + uri_scheme, + parent_window); + g_free (uri_scheme); + return; + } + parameter = nautilus_file_get_uri (file); } else { + uri = nautilus_file_get_uri (file); parameter = gnome_vfs_get_local_path_from_uri (uri); + g_free (uri); + if (parameter == NULL) { /* This application can't deal with this URI, * because it can only handle local @@ -443,20 +599,20 @@ nautilus_launch_application (GnomeVFSMimeApplication *application, * where to put it, and who would delete it * when done. */ - prompt = g_strdup_printf (_("Sorry, %s can only open local files, and " - "\"%s\" is remote. If you want to open it " - "with %s, make a local copy first."), - application->name, uri, application->name); - dialog = nautilus_show_error_dialog (prompt, _("Can't open remote file"), parent_window); - g_free (prompt); + application_cannot_open_location (application, + file, + uri_scheme, + parent_window); + g_free (uri_scheme); return; } } + g_free (uri_scheme); nautilus_launch_application_from_command (application->command, parameter, application->requires_terminal); - + g_free (parameter); } diff --git a/libnautilus-private/nautilus-program-choosing.h b/libnautilus-private/nautilus-program-choosing.h index ab2f847fc..8d7c07904 100644 --- a/libnautilus-private/nautilus-program-choosing.h +++ b/libnautilus-private/nautilus-program-choosing.h @@ -51,7 +51,7 @@ void nautilus_cancel_choose_component_for_file (NautilusFile NautilusComponentChoiceCallback callback, gpointer callback_data); void nautilus_launch_application (GnomeVFSMimeApplication *application, - const char *uri, + NautilusFile *file, GtkWindow *parent_window); void nautilus_launch_application_from_command (const char *command_string, const char *parameter, |