summaryrefslogtreecommitdiff
path: root/libnautilus-private
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2003-04-28 20:48:59 +0000
committerAlexander Larsson <alexl@src.gnome.org>2003-04-28 20:48:59 +0000
commit9de4bf44cf8cf1711bf493dbc4a20d0d17a78fa7 (patch)
treeec97d309725b71e365972e45ed3ae5ec5c880fb1 /libnautilus-private
parent6deb7d61ab68d2846dc0996a7bdd45b7f713127a (diff)
downloadnautilus-9de4bf44cf8cf1711bf493dbc4a20d0d17a78fa7.tar.gz
Based on a patch by Frank Worsley <fworsley@shaw.ca>
2003-04-28 Alexander Larsson <alexl@redhat.com> Based on a patch by Frank Worsley <fworsley@shaw.ca> * libnautilus-private/nautilus-program-chooser.[ch]: (nautilus_program_chooser_show_no_choices_message), (nautilus_program_chooser_show_invalid_message): Added the term 'action' to the dialogs when there is no default application or component. * libnautilus-private/nautilus-program-choosing.[ch]: (application_cannot_open_location), (nautilus_launch_show_file), (nautilus_launch_action), (nautilus_launch_application): Updated to use the new gnome-vfs functions and error codes. * src/file-manager/fm-directory-view.c: (fm_directory_view_launch_application), (activate_callback), (activate_activation_uri_ready_callback), (cancel_activate_callback), (fm_directory_view_activate_file): Cleaned up to properly support the new gnome-vfs functionality and an external component viewer. Also fixed to get activation uri for a file and then retrieve properties for the activation uri not the file that was clicked (fixes #42391).
Diffstat (limited to 'libnautilus-private')
-rw-r--r--libnautilus-private/nautilus-program-chooser.c58
-rw-r--r--libnautilus-private/nautilus-program-chooser.h4
-rw-r--r--libnautilus-private/nautilus-program-choosing.c265
-rw-r--r--libnautilus-private/nautilus-program-choosing.h7
4 files changed, 261 insertions, 73 deletions
diff --git a/libnautilus-private/nautilus-program-chooser.c b/libnautilus-private/nautilus-program-chooser.c
index 25a8b251e..b73107e2b 100644
--- a/libnautilus-private/nautilus-program-chooser.c
+++ b/libnautilus-private/nautilus-program-chooser.c
@@ -1597,11 +1597,13 @@ nautilus_program_chooser_show_no_choices_message (GnomeVFSMimeActionType action_
if (action_type == GNOME_VFS_MIME_ACTION_TYPE_COMPONENT) {
unavailable_message = g_strdup_printf (_("No viewers are available for \"%s\"."), file_name);
dialog_title = g_strdup (_("No Viewers Available"));
- } else {
- g_assert (action_type == GNOME_VFS_MIME_ACTION_TYPE_APPLICATION);
+ } else if (action_type == GNOME_VFS_MIME_ACTION_TYPE_APPLICATION) {
unavailable_message = g_strdup_printf (_("There is no application associated with \"%s\"."), file_name);
dialog_title = g_strdup (_("No Application Associated"));
- }
+ } else {
+ unavailable_message = g_strdup_printf (_("There is no action associated with \"%s\"."), file_name);
+ dialog_title = g_strdup (_("No Action Associated"));
+ }
/* Note: This might be misleading in the components case, since the
* user can't add components to the complete list even from the capplet.
@@ -1609,15 +1611,59 @@ nautilus_program_chooser_show_no_choices_message (GnomeVFSMimeActionType action_
*/
prompt = g_strdup_printf (_("%s\n\n"
"You can configure GNOME to associate applications "
- "with file types. Do you want to associate an "
+ "with file types. Do you want to associate an "
"application with this file type now?"),
unavailable_message);
+
dialog = eel_show_yes_no_dialog
(prompt, dialog_title, _("Associate Application"), GTK_STOCK_CANCEL, parent_window);
+
+ g_signal_connect_object (dialog, "response",
+ G_CALLBACK (launch_mime_capplet_on_ok),
+ file, 0);
+
+ g_free (unavailable_message);
+ g_free (file_name);
+ g_free (prompt);
+ g_free (dialog_title);
+}
+
+void
+nautilus_program_chooser_show_invalid_message (GnomeVFSMimeActionType action_type,
+ NautilusFile *file,
+ GtkWindow *parent_window)
+{
+ char *prompt;
+ char *unavailable_message;
+ char *file_name;
+ char *dialog_title;
+ GtkDialog *dialog;
+
+ file_name = get_file_name_for_display (file);
+ if (action_type == GNOME_VFS_MIME_ACTION_TYPE_COMPONENT) {
+ unavailable_message = g_strdup_printf (_("The viewer associated with \"%s\" is invalid."), file_name);
+ dialog_title = g_strdup (_("Invalid Viewer Associated"));
+ } else if (action_type == GNOME_VFS_MIME_ACTION_TYPE_APPLICATION) {
+ unavailable_message = g_strdup_printf (_("The application associated with \"%s\" is invalid."), file_name);
+ dialog_title = g_strdup (_("Invalid Application Associated"));
+ } else {
+ unavailable_message = g_strdup_printf (_("The action associated with \"%s\" is invalid."), file_name);
+ dialog_title = g_strdup (_("Invalid Action Associated"));
+ }
+
+ prompt = g_strdup_printf (_("%s\n\n"
+ "You can configure GNOME to associate a different application "
+ "or viewer with this file type. Do you want to associate an "
+ "application or viewer with this file type now?"),
+ unavailable_message);
+
+ dialog = eel_show_yes_no_dialog
+ (prompt, dialog_title, _("Associate Action"), GTK_STOCK_CANCEL, parent_window);
+
g_signal_connect_object (dialog, "response",
- G_CALLBACK (launch_mime_capplet_on_ok),
- file, 0);
+ G_CALLBACK (launch_mime_capplet_on_ok),
+ file, 0);
g_free (unavailable_message);
g_free (file_name);
diff --git a/libnautilus-private/nautilus-program-chooser.h b/libnautilus-private/nautilus-program-chooser.h
index 2e6b7bd08..ed98ad7bd 100644
--- a/libnautilus-private/nautilus-program-chooser.h
+++ b/libnautilus-private/nautilus-program-chooser.h
@@ -65,4 +65,8 @@ void nautilus_program_chooser_show_no_choices_message (GnomeVFSMimeActionType
NautilusFile *file,
GtkWindow *parent_window);
+void nautilus_program_chooser_show_invalid_message (GnomeVFSMimeActionType action_type,
+ NautilusFile *file,
+ GtkWindow *parent_window);
+
#endif /* NAUTILUS_PROGRAM_CHOOSER_H */
diff --git a/libnautilus-private/nautilus-program-choosing.c b/libnautilus-private/nautilus-program-choosing.c
index 1c837fb6f..03ed57b44 100644
--- a/libnautilus-private/nautilus-program-choosing.c
+++ b/libnautilus-private/nautilus-program-choosing.c
@@ -41,6 +41,7 @@
#include <libgnome/gnome-i18n.h>
#include <libgnome/gnome-util.h>
#include <libgnome/gnome-desktop-item.h>
+#include <libgnome/gnome-url.h>
#include <libgnomeui/gnome-uidefs.h>
#include <libgnomevfs/gnome-vfs-mime-handlers.h>
#include <libgnomevfs/gnome-vfs-utils.h>
@@ -490,10 +491,17 @@ application_cannot_open_location (GnomeVFSMimeApplication *application,
file_name = nautilus_file_get_display_name (file);
if (nautilus_mime_has_any_applications_for_file (file)) {
- 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);
+ if (application != 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);
+ } else {
+ message = g_strdup_printf (_("The default action can't open \"%s\" because it can't access files at \"%s\" "
+ "locations. Would you like to choose another action?"),
+ file_name, uri_scheme);
+ }
+
message_dialog = eel_show_yes_no_dialog (message,
_("Can't Open Location"),
GTK_STOCK_OK,
@@ -501,6 +509,7 @@ application_cannot_open_location (GnomeVFSMimeApplication *application,
parent_window);
response = gtk_dialog_run (message_dialog);
gtk_object_destroy (GTK_OBJECT (message_dialog));
+
if (response == GTK_RESPONSE_YES) {
launch_parameters = launch_parameters_new (file, parent_window);
nautilus_choose_application_for_file
@@ -510,21 +519,156 @@ application_cannot_open_location (GnomeVFSMimeApplication *application,
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 may be able to open "
- "it."), application->name, file_name,
- application->name, uri_scheme);
+
+ } else {
+ if (application != NULL) {
+ 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 may be able to open "
+ "it."), application->name, file_name,
+ application->name, uri_scheme);
+ } else {
+ message = g_strdup_printf (_("The default action can't open \"%s\" because it can't access files at \"%s\" "
+ "locations. No other actions are available to view this file. "
+ "If you copy this file onto your computer, you may be able to open "
+ "it."), file_name, uri_scheme);
+ }
+
eel_show_info_dialog (message, _("Can't Open Location"), parent_window);
- }
+ }
g_free (file_name);
g_free (message);
}
/**
+ * nautilus_launch_show_file:
+ *
+ * Shows a file using gnome_url_show.
+ *
+ * @file: the file whose uri will be shown.
+ * @parent_window: window to use as parent for error dialog.
+ */
+void nautilus_launch_show_file (NautilusFile *file,
+ GtkWindow *parent_window)
+{
+ GnomeVFSResult result;
+ GnomeVFSMimeActionType action;
+ GdkScreen *screen;
+ char **envp;
+ char *uri, *uri_scheme;
+
+ uri = NULL;
+ if (nautilus_file_is_nautilus_link (file)) {
+ uri = nautilus_file_get_activation_uri (file);
+ }
+
+ if (uri == NULL) {
+ uri = nautilus_file_get_uri (file);
+ }
+
+ action = nautilus_mime_get_default_action_type_for_file (file);
+ screen = gtk_window_get_screen (parent_window);
+ envp = egg_screen_exec_environment (screen);
+
+ result = gnome_vfs_url_show_with_env (uri, envp);
+
+ switch (result) {
+ case GNOME_VFS_OK:
+ break;
+
+ case GNOME_VFS_ERROR_NOT_SUPPORTED:
+ uri_scheme = nautilus_file_get_uri_scheme (file);
+ application_cannot_open_location (NULL,
+ file,
+ uri_scheme,
+ parent_window);
+ g_free (uri_scheme);
+ break;
+
+ case GNOME_VFS_ERROR_NO_DEFAULT:
+ case GNOME_VFS_ERROR_NO_HANDLER:
+ nautilus_program_chooser_show_no_choices_message
+ (action, file, parent_window);
+ break;
+
+ default:
+ nautilus_program_chooser_show_invalid_message
+ (action, file, parent_window);
+ }
+
+ g_strfreev (envp);
+ g_free (uri);
+}
+
+/**
+ * nautilus_launch_action:
+ *
+ * Forks off a process to launch the action with a given file
+ * as a parameter. Provide parent window for error dialogs.
+ *
+ * @action: the action to launch
+ * @file: the file whose location should be passed as a parameter.
+ * @parent_window: window to use as parent for error dialogs.
+ */
+void nautilus_launch_action (GnomeVFSMimeAction *action,
+ NautilusFile *file,
+ GtkWindow *parent_window)
+{
+ GdkScreen *screen;
+ GnomeVFSResult result;
+ GList uris;
+ char *uri;
+ char **envp;
+
+ switch (action->action_type) {
+ case GNOME_VFS_MIME_ACTION_TYPE_APPLICATION:
+
+ nautilus_launch_application (action->action.application, file, parent_window);
+
+ break;
+
+ case GNOME_VFS_MIME_ACTION_TYPE_COMPONENT:
+
+ uri = NULL;
+ if (nautilus_file_is_nautilus_link (file)) {
+ uri = nautilus_file_get_activation_uri (file);
+ }
+
+ if (uri == NULL) {
+ uri = nautilus_file_get_uri (file);
+ }
+
+ uris.next = NULL;
+ uris.prev = NULL;
+ uris.data = uri;
+
+ screen = gtk_window_get_screen (parent_window);
+ envp = egg_screen_exec_environment (screen);
+
+ result = gnome_vfs_mime_action_launch_with_env (action, &uris, envp);
+
+ switch (result) {
+ case GNOME_VFS_OK:
+ break;
+
+ default:
+ nautilus_program_chooser_show_invalid_message
+ (action->action_type, file, parent_window);
+ }
+
+ g_strfreev (envp);
+ g_free (uri);
+
+ break;
+
+ default:
+ nautilus_program_chooser_show_invalid_message
+ (action->action_type, file, parent_window);
+ }
+}
+
+/**
* nautilus_launch_application:
*
* Fork off a process to launch an application with a given file as a
@@ -539,67 +683,56 @@ nautilus_launch_application (GnomeVFSMimeApplication *application,
NautilusFile *file,
GtkWindow *parent_window)
{
- GdkScreen *screen;
- char *parameter;
- 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) &&
- eel_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,
- eel_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 {
+ GdkScreen *screen;
+ char *uri;
+ char *uri_scheme;
+ GList uris;
+ char **envp;
+ GnomeVFSResult result;
+
+ uri = NULL;
+ if (nautilus_file_is_nautilus_link (file)) {
+ uri = nautilus_file_get_activation_uri (file);
+ }
+
+ if (uri == NULL) {
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
- * files. Tell user. Some day we could offer
- * to copy it locally for the user, if we knew
- * where to put it, and who would delete it
- * when done.
- */
- application_cannot_open_location (application,
- file,
- uri_scheme,
- parent_window);
- g_free (uri_scheme);
- return;
- }
}
- g_free (uri_scheme);
+ uris.next = NULL;
+ uris.prev = NULL;
+ uris.data = uri;
+
screen = gtk_window_get_screen (parent_window);
+ envp = egg_screen_exec_environment (screen);
+
+ result = gnome_vfs_mime_application_launch_with_env (application, &uris, envp);
+
+ switch (result) {
+ case GNOME_VFS_OK:
+ break;
+
+ case GNOME_VFS_ERROR_NOT_SUPPORTED:
+ uri_scheme = nautilus_file_get_uri_scheme (file);
+ application_cannot_open_location (application,
+ file,
+ uri_scheme,
+ parent_window);
+ g_free (uri_scheme);
+
+ break;
- nautilus_launch_application_from_command (screen,
- application->name,
- application->command,
- parameter,
- application->requires_terminal);
-
- g_free (parameter);
+ default:
+ nautilus_program_chooser_show_invalid_message
+ (GNOME_VFS_MIME_ACTION_TYPE_APPLICATION, file, parent_window);
+
+ break;
+ }
+
+ g_free (uri);
+ g_strfreev (envp);
}
-
-
/**
* nautilus_launch_application_from_command:
*
diff --git a/libnautilus-private/nautilus-program-choosing.h b/libnautilus-private/nautilus-program-choosing.h
index 65c0bd333..84ef475f4 100644
--- a/libnautilus-private/nautilus-program-choosing.h
+++ b/libnautilus-private/nautilus-program-choosing.h
@@ -53,6 +53,9 @@ void nautilus_choose_component_for_file (NautilusFile
void nautilus_cancel_choose_component_for_file (NautilusFile *file,
NautilusComponentChoiceCallback callback,
gpointer callback_data);
+void nautilus_launch_action (GnomeVFSMimeAction *action,
+ NautilusFile *file,
+ GtkWindow *parent_window);
void nautilus_launch_application (GnomeVFSMimeApplication *application,
NautilusFile *file,
GtkWindow *parent_window);
@@ -65,5 +68,7 @@ void nautilus_launch_desktop_file (GdkScreen *screen,
const char *desktop_file_uri,
const GList *parameter_uris,
GtkWindow *parent_window);
-
+void nautilus_launch_show_file (NautilusFile *file,
+ GtkWindow *parent_window);
+
#endif /* NAUTILUS_PROGRAM_CHOOSING_H */