Commit 454b224e authored by Alexander Larsson's avatar Alexander Larsson Committed by Alexander Larsson

Add nautilus_file_is_launcher()

2008-02-13  Alexander Larsson  <alexl@redhat.com>

        * libnautilus-private/nautilus-file.[ch]:
        * libnautilus-private/nautilus-file-private.h:
	Add nautilus_file_is_launcher()
	
        * libnautilus-private/nautilus-directory-async.c:
        * libnautilus-private/nautilus-dnd.c:
        * libnautilus-private/nautilus-link.[ch]
        * libnautilus-private/nautilus-mime-actions.c:
        * libnautilus-private/nautilus-program-choosing.[ch]:
        * src/file-manager/fm-directory-view.c:
        * src/file-manager/fm-tree-view.c:
	Remove weird desktop-file: and command: hacks, and
	replace with usage and implementation of
	nautilus_file_is_launcher().
	This fixes some problems where the old desktop-file uri
	was interpreted as an actual file.


svn path=/trunk/; revision=13734
parent 13b72557
2008-02-13 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-file.[ch]:
* libnautilus-private/nautilus-file-private.h:
Add nautilus_file_is_launcher()
* libnautilus-private/nautilus-directory-async.c:
* libnautilus-private/nautilus-dnd.c:
* libnautilus-private/nautilus-link.[ch]
* libnautilus-private/nautilus-mime-actions.c:
* libnautilus-private/nautilus-program-choosing.[ch]:
* src/file-manager/fm-directory-view.c:
* src/file-manager/fm-tree-view.c:
Remove weird desktop-file: and command: hacks, and
replace with usage and implementation of
nautilus_file_is_launcher().
This fixes some problems where the old desktop-file uri
was interpreted as an actual file.
2008-02-13 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-file-operations.c (verify_destination):
......
......@@ -191,7 +191,8 @@ static void link_info_done (NautilusDirectory
NautilusFile *file,
const char *uri,
const char *name,
const char *icon);
const char *icon,
gboolean is_launcher);
static void move_file_to_low_priority_queue (NautilusDirectory *directory,
NautilusFile *file);
static void move_file_to_extension_queue (NautilusDirectory *directory,
......@@ -1687,7 +1688,7 @@ lacks_link_info (NautilusFile *file)
if (nautilus_file_is_nautilus_link (file)) {
return TRUE;
} else {
link_info_done (file->details->directory, file, NULL, NULL, NULL);
link_info_done (file->details->directory, file, NULL, NULL, NULL, FALSE);
return FALSE;
}
} else {
......@@ -3469,7 +3470,8 @@ link_info_done (NautilusDirectory *directory,
NautilusFile *file,
const char *uri,
const char *name,
const char *icon)
const char *icon,
gboolean is_launcher)
{
file->details->link_info_is_up_to_date = TRUE;
......@@ -3486,6 +3488,7 @@ link_info_done (NautilusDirectory *directory,
file->details->activation_location = g_file_new_for_uri (uri);
}
file->details->custom_icon = g_strdup (icon);
file->details->is_launcher = is_launcher;
nautilus_directory_async_state_changed (directory);
}
......@@ -3531,23 +3534,25 @@ link_info_got_data (NautilusDirectory *directory,
char *file_contents)
{
char *uri, *name, *icon;
gboolean is_launcher;
nautilus_directory_ref (directory);
uri = NULL;
name = NULL;
icon = NULL;
is_launcher = FALSE;
/* Handle the case where we read the Nautilus link. */
if (result) {
nautilus_link_get_link_info_given_file_contents (file_contents, bytes_read,
&uri, &name, &icon);
&uri, &name, &icon, &is_launcher);
} else {
/* FIXME bugzilla.gnome.org 42433: We should report this error to the user. */
}
nautilus_file_ref (file);
link_info_done (directory, file, uri, name, icon);
link_info_done (directory, file, uri, name, icon, is_launcher);
nautilus_file_changed (file);
nautilus_file_unref (file);
......@@ -3633,7 +3638,7 @@ link_info_start (NautilusDirectory *directory,
/* If it's not a link we are done. If it is, we need to read it. */
if (!nautilus_style_link) {
link_info_done (directory, file, NULL, NULL, NULL);
link_info_done (directory, file, NULL, NULL, NULL, FALSE);
} else if (should_read_link_info_sync (file)) {
result = g_file_load_contents (location, NULL, &file_contents, &file_size, NULL, NULL);
link_info_got_data (directory, file, result, file_size, file_contents);
......
......@@ -368,6 +368,7 @@ nautilus_drag_default_drop_action_for_icons (GdkDragContext *context,
const char *dropped_uri;
GFile *target, *dropped;
GdkDragAction actions;
NautilusFile *target_file;
if (target_uri_string == NULL) {
*action = 0;
......@@ -388,6 +389,7 @@ nautilus_drag_default_drop_action_for_icons (GdkDragContext *context,
}
dropped_uri = ((NautilusDragSelectionItem *)items->data)->uri;
target_file = nautilus_file_get_existing_by_uri (dropped_uri);
/*
* Check for trash URI. We do a find_directory for any Trash directory.
......@@ -400,13 +402,14 @@ nautilus_drag_default_drop_action_for_icons (GdkDragContext *context,
*action = GDK_ACTION_MOVE;
}
nautilus_file_unref (target_file);
return;
} else if (g_str_has_prefix (target_uri_string, NAUTILUS_COMMAND_SPECIFIER) ||
g_str_has_prefix (target_uri_string, NAUTILUS_DESKTOP_COMMAND_SPECIFIER) ) {
} else if (target_file != NULL && nautilus_file_is_launcher (target_file)) {
if (actions & GDK_ACTION_MOVE) {
*action = GDK_ACTION_MOVE;
}
nautilus_file_unref (target_file);
return;
} else if (eel_uri_is_desktop (target_uri_string)) {
target = nautilus_get_desktop_location ();
......@@ -416,12 +419,15 @@ nautilus_drag_default_drop_action_for_icons (GdkDragContext *context,
*action = GDK_ACTION_MOVE;
}
nautilus_file_unref (target_file);
return;
}
} else {
target = g_file_new_for_uri (target_uri_string);
}
nautilus_file_unref (target_file);
/* Compare the first dropped uri with the target uri for same fs match. */
dropped = g_file_new_for_uri (dropped_uri);
same_fs = check_same_fs (target, dropped);
......
......@@ -189,6 +189,7 @@ struct NautilusFileDetails
/* TRUE if the file is open in a spatial window */
eel_boolean_bit has_open_window : 1;
eel_boolean_bit is_launcher : 1;
eel_boolean_bit is_symlink : 1;
eel_boolean_bit is_mountpoint : 1;
eel_boolean_bit is_hidden : 1;
......
......@@ -322,6 +322,7 @@ nautilus_file_clear_info (NautilusFile *file)
file->details->thumbnail_path = NULL;
file->details->thumbnailing_failed = FALSE;
file->details->is_launcher = FALSE;
file->details->is_symlink = FALSE;
file->details->is_hidden = FALSE;
file->details->is_backup = FALSE;
......@@ -3030,6 +3031,12 @@ nautilus_file_monitor_remove (NautilusFile *file,
monitor_remove, (file, client));
}
gboolean
nautilus_file_is_launcher (NautilusFile *file)
{
return file->details->is_launcher;
}
gboolean
nautilus_file_has_activation_uri (NautilusFile *file)
{
......
......@@ -376,6 +376,7 @@ GList *nautilus_file_list_filter_hidden_and_backup (GList
/* Get the URI that's used when activating the file.
* Getting this can require reading the contents of the file.
*/
gboolean nautilus_file_is_launcher (NautilusFile *file);
gboolean nautilus_file_has_activation_uri (NautilusFile *file);
char * nautilus_file_get_activation_uri (NautilusFile *file);
GFile * nautilus_file_get_activation_location (NautilusFile *file);
......
......@@ -298,7 +298,6 @@ nautilus_link_local_get_additional_text (const char *path)
static char *
nautilus_link_get_link_uri_from_desktop (GnomeDesktopItem *desktop_file)
{
const char *launch_string;
const char *type;
char *retval;
......@@ -309,15 +308,7 @@ nautilus_link_get_link_uri_from_desktop (GnomeDesktopItem *desktop_file)
return NULL;
}
if (strcmp (type, "Application") == 0) {
launch_string = gnome_desktop_item_get_string (desktop_file, "Exec");
if (launch_string == NULL) {
return NULL;
}
launch_string = gnome_desktop_item_get_location (desktop_file);
retval = g_strconcat (NAUTILUS_DESKTOP_COMMAND_SPECIFIER, launch_string, NULL);
} else if (strcmp (type, "URL") == 0) {
if (strcmp (type, "URL") == 0) {
/* Some old broken desktop files use this nonstandard feature, we need handle it though */
retval = g_strdup (gnome_desktop_item_get_string (desktop_file, "Exec"));
} else if ((strcmp (type, NAUTILUS_LINK_GENERIC_TAG) == 0) ||
......@@ -405,9 +396,11 @@ nautilus_link_get_link_info_given_file_contents (const char *file_contents,
int link_file_size,
char **uri,
char **name,
char **icon)
char **icon,
gboolean *is_launcher)
{
GnomeDesktopItem *desktop_file;
const char *type;
if (!is_link_data (file_contents, link_file_size)) {
return;
......@@ -422,6 +415,14 @@ nautilus_link_get_link_info_given_file_contents (const char *file_contents,
*name = nautilus_link_get_link_name_from_desktop (desktop_file);
*icon = nautilus_link_get_link_icon_from_desktop (desktop_file);
*is_launcher = FALSE;
type = gnome_desktop_item_get_string (desktop_file, "Type");
if (type != NULL &&
strcmp (type, "Application") == 0 &&
gnome_desktop_item_get_string (desktop_file, "Exec") != NULL) {
*is_launcher = TRUE;
}
gnome_desktop_item_unref (desktop_file);
}
......
......@@ -45,7 +45,8 @@ void nautilus_link_get_link_info_given_file_contents (const char
int link_file_size,
char **uri,
char **name,
char **icon);
char **icon,
gboolean *is_launcher);
void nautilus_link_local_create_from_gnome_entry (GnomeDesktopItem *entry,
const char *dest_uri,
const GdkPoint *position,
......
......@@ -45,7 +45,6 @@
typedef enum {
ACTIVATION_ACTION_LAUNCH_DESKTOP_FILE,
ACTIVATION_ACTION_LAUNCH_APPLICATION_FROM_COMMAND,
ACTIVATION_ACTION_ASK,
ACTIVATION_ACTION_LAUNCH,
ACTIVATION_ACTION_LAUNCH_IN_TERMINAL,
......@@ -736,6 +735,10 @@ get_activation_action (NautilusFile *file)
{
ActivationAction action;
char *activation_uri;
if (nautilus_file_is_launcher (file)) {
return ACTIVATION_ACTION_LAUNCH_DESKTOP_FILE;
}
activation_uri = nautilus_file_get_activation_uri (file);
if (activation_uri == NULL) {
......@@ -743,12 +746,7 @@ get_activation_action (NautilusFile *file)
}
action = ACTIVATION_ACTION_DO_NOTHING;
if (eel_str_has_prefix (activation_uri, NAUTILUS_DESKTOP_COMMAND_SPECIFIER)) {
action = ACTIVATION_ACTION_LAUNCH_DESKTOP_FILE;
} else if (eel_str_has_prefix (activation_uri, NAUTILUS_COMMAND_SPECIFIER)) {
action = ACTIVATION_ACTION_LAUNCH_APPLICATION_FROM_COMMAND;
} else if (nautilus_file_is_launchable (file)) {
if (nautilus_file_is_launchable (file)) {
char *executable_path;
action = ACTIVATION_ACTION_LAUNCH;
......@@ -1004,7 +1002,6 @@ activate_files (ActivateParameters *parameters)
{
NautilusFile *file;
GList *launch_desktop_files;
GList *launch_from_command_files;
GList *launch_files;
GList *launch_in_terminal_files;
GList *open_in_app_files;
......@@ -1023,7 +1020,6 @@ activate_files (ActivateParameters *parameters)
screen = gtk_widget_get_screen (GTK_WIDGET (parameters->parent_window));
launch_desktop_files = NULL;
launch_from_command_files = NULL;
launch_files = NULL;
launch_in_terminal_files = NULL;
open_in_app_files = NULL;
......@@ -1048,9 +1044,6 @@ activate_files (ActivateParameters *parameters)
case ACTIVATION_ACTION_LAUNCH_DESKTOP_FILE :
launch_desktop_files = g_list_prepend (launch_desktop_files, file);
break;
case ACTIVATION_ACTION_LAUNCH_APPLICATION_FROM_COMMAND :
launch_from_command_files = g_list_prepend (launch_from_command_files, file);
break;
case ACTIVATION_ACTION_LAUNCH :
launch_files = g_list_prepend (launch_files, file);
break;
......@@ -1084,22 +1077,6 @@ activate_files (ActivateParameters *parameters)
g_free (uri);
}
launch_from_command_files = g_list_reverse (launch_from_command_files);
for (l = launch_from_command_files; l != NULL; l = l->next) {
file = NAUTILUS_FILE (l->data);
uri = nautilus_file_get_activation_uri (file);
nautilus_debug_log (FALSE, NAUTILUS_DEBUG_LOG_DOMAIN_USER,
"directory view activate_callback launch_application_from_command window=%p: %s",
parameters->parent_window, uri);
nautilus_launch_application_from_command (
screen, NULL, uri + strlen (NAUTILUS_COMMAND_SPECIFIER),
NULL, FALSE);
g_free (uri);
}
old_working_dir = NULL;
if (parameters->activation_directory &&
(launch_files != NULL || launch_in_terminal_files != NULL)) {
......@@ -1240,7 +1217,6 @@ activate_files (ActivateParameters *parameters)
}
g_list_free (launch_desktop_files);
g_list_free (launch_from_command_files);
g_list_free (launch_files);
g_list_free (launch_in_terminal_files);
g_list_free (open_in_view_files);
......@@ -1407,9 +1383,7 @@ activate_activation_uris_ready_callback (GList *files_ignore,
* about the attributes for that, not for the original file.
*/
uri = nautilus_file_get_activation_uri (file);
if (uri != NULL &&
!(g_str_has_prefix (uri, NAUTILUS_DESKTOP_COMMAND_SPECIFIER) ||
g_str_has_prefix (uri, NAUTILUS_COMMAND_SPECIFIER))) {
if (uri != NULL) {
NautilusFile *actual_file;
actual_file = nautilus_file_get_by_uri (uri);
......
......@@ -369,11 +369,6 @@ nautilus_launch_desktop_file (GdkScreen *screen,
GFile *file;
Time timestamp;
/* strip the leading command specifier */
if (eel_str_has_prefix (desktop_file_uri, NAUTILUS_DESKTOP_COMMAND_SPECIFIER)) {
desktop_file_uri += strlen (NAUTILUS_DESKTOP_COMMAND_SPECIFIER);
}
/* Don't allow command execution from remote locations where the
* uri scheme isn't file:// (This is because files on for example
* nfs are treated as remote) to partially mitigate the security
......
......@@ -30,9 +30,6 @@
#include <gio/gio.h>
#include <libnautilus-private/nautilus-file.h>
#define NAUTILUS_COMMAND_SPECIFIER "command:"
#define NAUTILUS_DESKTOP_COMMAND_SPECIFIER "desktop-file:"
typedef void (*NautilusApplicationChoiceCallback) (GAppInfo *application,
gpointer callback_data);
......
......@@ -6623,11 +6623,13 @@ file_list_all_are_folders (GList *file_list)
file = NAUTILUS_FILE (l->data);
if (nautilus_file_is_nautilus_link (file) &&
!NAUTILUS_IS_DESKTOP_ICON_FILE (file)) {
if (nautilus_file_is_launcher (file)) {
return FALSE;
}
activation_uri = nautilus_file_get_activation_uri (file);
if (activation_uri == NULL ||
eel_str_has_prefix (activation_uri, NAUTILUS_DESKTOP_COMMAND_SPECIFIER) ||
eel_str_has_prefix (activation_uri, NAUTILUS_COMMAND_SPECIFIER)) {
if (activation_uri == NULL) {
g_free (activation_uri);
return FALSE;
}
......@@ -8176,8 +8178,7 @@ fm_directory_view_move_copy_items (const GList *item_uris,
int x, int y,
FMDirectoryView *view)
{
char *parameters, *temp;
GList *p;
NautilusFile *target_file;
g_assert (relative_item_points == NULL
|| relative_item_points->len == 0
......@@ -8186,32 +8187,17 @@ fm_directory_view_move_copy_items (const GList *item_uris,
/* add the drop location to the icon offsets */
offset_drop_points (relative_item_points, x, y);
target_file = nautilus_file_get_existing_by_uri (target_uri);
/* special-case "command:" here instead of starting a move/copy */
if (eel_str_has_prefix (target_uri, NAUTILUS_DESKTOP_COMMAND_SPECIFIER)) {
if (target_file != NULL && nautilus_file_is_launcher (target_file)) {
nautilus_file_unref (target_file);
nautilus_launch_desktop_file (
gtk_widget_get_screen (GTK_WIDGET (view)),
target_uri, item_uris,
fm_directory_view_get_containing_window (view));
return;
} else if (eel_str_has_prefix (target_uri, NAUTILUS_COMMAND_SPECIFIER)) {
parameters = NULL;
for (p = (GList *) item_uris; p != NULL; p = p->next) {
temp = g_strconcat ((char *) p->data, " ", parameters, NULL);
if (parameters != NULL) {
g_free (parameters);
}
parameters = temp;
}
target_uri += strlen (NAUTILUS_COMMAND_SPECIFIER);
nautilus_launch_application_from_command (
gtk_widget_get_screen (GTK_WIDGET (view)),
NULL, target_uri, parameters, FALSE);
g_free (parameters);
return;
}
nautilus_file_unref (target_file);
nautilus_file_operations_copy_move
(item_uris, relative_item_points,
......
......@@ -344,28 +344,14 @@ got_activation_uri_callback (NautilusFile *file, gpointer callback_data)
mode = view->details->activation_in_new_window ? NAUTILUS_WINDOW_OPEN_IN_NAVIGATION : NAUTILUS_WINDOW_OPEN_ACCORDING_TO_MODE;
/* FIXME: reenable && !eel_uris_match_ignore_fragments (view->details->current_main_view_uri, uri) */
uri = nautilus_file_get_activation_uri (file);
if (uri != NULL
&& g_str_has_prefix (uri, NAUTILUS_COMMAND_SPECIFIER)) {
uri += strlen (NAUTILUS_COMMAND_SPECIFIER);
nautilus_debug_log (FALSE, NAUTILUS_DEBUG_LOG_DOMAIN_USER,
"tree view launch_application_from_command window=%p: %s",
view->details->window, uri);
nautilus_launch_application_from_command (screen, NULL, uri, NULL, FALSE);
} else if (uri != NULL
&& g_str_has_prefix (uri, NAUTILUS_DESKTOP_COMMAND_SPECIFIER)) {
if (nautilus_file_is_launcher (file)) {
file_uri = nautilus_file_get_uri (file);
nautilus_debug_log (FALSE, NAUTILUS_DEBUG_LOG_DOMAIN_USER,
"tree view launch_desktop_file window=%p: %s",
view->details->window, file_uri);
nautilus_launch_desktop_file (screen, file_uri, NULL, NULL);
g_free (file_uri);
} else if (uri != NULL
&& nautilus_file_is_executable (file)
&& nautilus_file_can_execute (file)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment