[Nautilus-list] RH merge, DnD
- From: Alex Larsson <alexl redhat com>
- To: <nautilus-list lists eazel com>
- Cc: <darin bentspoon com>
- Subject: [Nautilus-list] RH merge, DnD
- Date: Tue, 4 Sep 2001 16:01:36 -0400 (EDT)
Here is a DnD patch that makes drag and drop from the panel to the desktop
and nautilus windows to work.
According to jrb (who wrote it) it is sort of hackish, but is better that
we currently have.
/ Alex
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/nautilus/ChangeLog,v
retrieving revision 1.4749
diff -u -p -r1.4749 ChangeLog
--- ChangeLog 2001/09/04 15:37:01 1.4749
+++ ChangeLog 2001/09/04 19:59:46
@@ -1,3 +1,19 @@
+2001-09-04 Alex Larsson <alexl redhat com>
+
+ Merge some stuff from the redhat-outstanding-patches branch
+
+ * libnautilus-private/nautilus-icon-container.c:
+ * libnautilus-private/nautilus-icon-dnd.c:
+ Change signature of the "handle_uri_list" callback to include the
+ drag action.
+
+ * src/file-manager/fm-icon-view.c (icon_view_handle_uri_list):
+ Handle uri's more gracefully.
+
+ * src/file-manager/fm-desktop-icon-view.c:
+ (icon_view_handle_uri_list): Remove. Now handled in the
+ parent class.
+
2001-09-03 Alex Larsson <alexl redhat com>
Merge some stuff from the redhat-outstanding-patches branch
Index: libnautilus-private/nautilus-icon-container.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-container.c,v
retrieving revision 1.217
diff -u -p -r1.217 nautilus-icon-container.c
--- libnautilus-private/nautilus-icon-container.c 2001/09/04 15:37:08 1.217
+++ libnautilus-private/nautilus-icon-container.c 2001/09/04 19:59:47
@@ -3224,9 +3224,10 @@ nautilus_icon_container_initialize_class
object_class->type,
GTK_SIGNAL_OFFSET (NautilusIconContainerClass,
handle_uri_list),
- gtk_marshal_NONE__POINTER_INT_INT,
- GTK_TYPE_NONE, 3,
+ eel_gtk_marshal_NONE__POINTER_INT_INT_INT,
+ GTK_TYPE_NONE, 4,
GTK_TYPE_POINTER,
+ GTK_TYPE_INT,
GTK_TYPE_INT,
GTK_TYPE_INT);
Index: libnautilus-private/nautilus-icon-dnd.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-dnd.c,v
retrieving revision 1.91
diff -u -p -r1.91 nautilus-icon-dnd.c
--- libnautilus-private/nautilus-icon-dnd.c 2001/07/20 17:36:33 1.91
+++ libnautilus-private/nautilus-icon-dnd.c 2001/09/04 19:59:47
@@ -82,8 +82,9 @@ static void receive_dropped_keyword
char* keyword,
int x,
int y);
-static void receive_dropped_uri_list (NautilusIconContainer *container,
+static void receive_dropped_uri_list (NautilusIconContainer *container,
char* keyword,
+ GdkDragAction action,
int x,
int y);
static void nautilus_icon_container_free_drag_data (NautilusIconContainer *container);
@@ -461,7 +462,7 @@ drag_data_received_callback (GtkWidget *
case EEL_ICON_DND_URL:
receive_dropped_uri_list
(NAUTILUS_ICON_CONTAINER (widget),
- (char*) data->data, x, y);
+ (char*) data->data, context->action, x, y);
gtk_drag_finish (context, TRUE, FALSE, time);
break;
@@ -660,7 +661,7 @@ receive_dropped_keyword (NautilusIconCon
/* handle dropped uri list */
static void
-receive_dropped_uri_list (NautilusIconContainer *container, char *uri_list, int x, int y)
+receive_dropped_uri_list (NautilusIconContainer *container, char *uri_list, GdkDragAction action, int x, int y)
{
if (uri_list == NULL) {
return;
@@ -668,6 +669,7 @@ receive_dropped_uri_list (NautilusIconCo
gtk_signal_emit_by_name (GTK_OBJECT (container), "handle_uri_list",
uri_list,
+ action,
x, y);
}
Index: src/file-manager/fm-desktop-icon-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-desktop-icon-view.c,v
retrieving revision 1.142
diff -u -p -r1.142 fm-desktop-icon-view.c
--- src/file-manager/fm-desktop-icon-view.c 2001/08/15 21:04:01 1.142
+++ src/file-manager/fm-desktop-icon-view.c 2001/09/04 19:59:47
@@ -109,11 +109,6 @@ static void volume_mounted_callback
static void volume_unmounted_callback (NautilusVolumeMonitor *monitor,
NautilusVolume *volume,
FMDesktopIconView *icon_view);
-static void icon_view_handle_uri_list (NautilusIconContainer *container,
- const char *item_uris,
- int x,
- int y,
- FMDirectoryView *view);
static int desktop_icons_compare_callback (NautilusIconContainer *container,
NautilusFile *file_a,
NautilusFile *file_b,
@@ -651,11 +646,6 @@ fm_desktop_icon_view_initialize (FMDeskt
desktop_icon_view,
GTK_OBJECT (desktop_icon_view));
- gtk_signal_connect (GTK_OBJECT (icon_container),
- "handle_uri_list",
- GTK_SIGNAL_FUNC (icon_view_handle_uri_list),
- desktop_icon_view);
-
eel_preferences_add_callback (NAUTILUS_PREFERENCES_HOME_URI,
home_uri_changed,
desktop_icon_view);
@@ -863,70 +853,6 @@ volume_unmounted_callback (NautilusVolum
g_free (volume_name);
g_free (link_path);
-}
-
-static void
-icon_view_handle_uri_list (NautilusIconContainer *container, const char *item_uris,
- int x, int y, FMDirectoryView *view)
-{
- GList *uri_list, *node;
- GnomeDesktopEntry *entry;
- GdkPoint point;
- char *uri, *local_path;
- char *stripped_uri;
- const char *last_slash, *link_name;
-
- if (item_uris == NULL) {
- return;
- }
-
- point.x = x;
- point.y = y;
-
- uri_list = gnome_uri_list_extract_uris (item_uris);
-
- for (node = uri_list; node != NULL; node = node->next) {
- /* Most of what comes in here is not really URIs, but
- * rather paths that have a file: prefix in them.
- */
- uri = eel_make_uri_from_half_baked_uri (node->data);
-
- /* Make a link using the desktop file contents? */
- local_path = gnome_vfs_get_local_path_from_uri (uri);
- if (local_path != NULL) {
- entry = gnome_desktop_entry_load (local_path);
- if (entry != NULL) {
- /* FIXME: Handle name conflicts? */
- nautilus_link_local_create_from_gnome_entry (entry, desktop_directory, &point);
- gnome_desktop_entry_free (entry);
- }
- g_free (local_path);
- if (entry != NULL) {
- continue;
- }
- }
-
- /* Make a link from the URI alone. Generate the file
- * name by extracting the basename of the URI.
- */
- /* FIXME: This should be using eel_uri_get_basename
- * instead of a "roll our own" solution.
- */
- stripped_uri = eel_str_strip_trailing_chr (uri, '/');
- last_slash = strrchr (stripped_uri, '/');
- link_name = last_slash == NULL ? NULL : last_slash + 1;
-
- if (!eel_str_is_empty (link_name)) {
- /* FIXME: Handle name conflicts? */
- nautilus_link_local_create (desktop_directory, link_name,
- "gnome-http-url", uri,
- &point, NAUTILUS_LINK_GENERIC);
- }
-
- g_free (stripped_uri);
- }
-
- gnome_uri_list_free_strings (uri_list);
}
/* update_link_and_delete_copies
Index: src/file-manager/fm-icon-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-icon-view.c,v
retrieving revision 1.209
diff -u -p -r1.209 fm-icon-view.c
--- src/file-manager/fm-icon-view.c 2001/07/26 09:16:37 1.209
+++ src/file-manager/fm-icon-view.c 2001/09/04 19:59:47
@@ -33,7 +33,10 @@
#include <eel/eel-glib-extensions.h>
#include <eel/eel-gtk-extensions.h>
#include <eel/eel-gtk-macros.h>
+#include <eel/eel-stock-dialogs.h>
+#include <eel/eel-dnd.h>
#include <eel/eel-string.h>
+#include <eel/eel-vfs-extensions.h>
#include <errno.h>
#include <fcntl.h>
#include <gtk/gtkmain.h>
@@ -45,10 +48,12 @@
#include <libgnome/gnome-i18n.h>
#include <libgnome/gnome-config.h>
#include <libgnome/gnome-metadata.h>
+#include <libgnome/gnome-mime.h>
#include <libgnomevfs/gnome-vfs-async-ops.h>
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libgnomevfs/gnome-vfs-utils.h>
#include <libgnomevfs/gnome-vfs-xfer.h>
+#include <libgnomevfs/gnome-vfs-mime.h>
#include <libnautilus-private/nautilus-audio-player.h>
#include <libnautilus-private/nautilus-bonobo-extensions.h>
#include <libnautilus-private/nautilus-directory-background.h>
@@ -115,49 +120,56 @@ typedef enum {
} MenuItemType;
/* forward declarations */
-static void create_icon_container (FMIconView *icon_view);
-static void fm_icon_view_initialize (FMIconView *icon_view);
-static void fm_icon_view_initialize_class (FMIconViewClass *klass);
-static gboolean fm_icon_view_is_empty (FMDirectoryView *view);
-static void fm_icon_view_set_directory_sort_by (FMIconView *icon_view,
- NautilusFile *file,
- const char *sort_by);
-static void fm_icon_view_set_zoom_level (FMIconView *view,
- NautilusZoomLevel new_level,
- gboolean always_set_level);
-gboolean fm_icon_view_supports_auto_layout (FMIconView *view);
-static void fm_icon_view_update_icon_container_fonts (FMIconView *icon_view);
-static void fm_icon_view_update_icon_container_smooth_font (FMIconView *icon_view);
-static void fm_icon_view_update_icon_container_font_size_table (FMIconView *icon_view);
-static void fm_icon_view_update_click_mode (FMIconView *icon_view);
-static void fm_icon_view_update_smooth_graphics_mode (FMIconView *icon_view);
-static gboolean fm_icon_view_using_tighter_layout (FMIconView *icon_view);
-static gboolean fm_icon_view_get_directory_tighter_layout (FMIconView *icon_view,
- NautilusFile *file);
-static void fm_icon_view_set_directory_tighter_layout (FMIconView *icon_view,
- NautilusFile *file,
- gboolean tighter_layout);
-static gboolean real_supports_auto_layout (FMIconView *view);
-static const SortCriterion *get_sort_criterion_by_id (const char *id);
-static const SortCriterion *get_sort_criterion_by_sort_type (NautilusFileSortType sort_type);
-static void set_sort_criterion_by_id (FMIconView *icon_view,
- const char *id);
-static gboolean set_sort_reversed (FMIconView *icon_view,
- gboolean new_value);
-static void switch_to_manual_layout (FMIconView *view);
-static void preview_audio (FMIconView *icon_view,
- NautilusFile *file,
- gboolean start_flag);
-static void update_layout_menus (FMIconView *view);
-static void default_sort_in_reverse_order_changed_callback (gpointer callback_data);
-static void default_sort_order_changed_callback (gpointer callback_data);
-static void default_use_tighter_layout_changed_callback (gpointer callback_data);
-static void default_use_manual_layout_changed_callback (gpointer callback_data);
-static void default_zoom_level_changed_callback (gpointer callback_data);
-static void default_zoom_level_font_size_changed_callback (gpointer callback_data);
-static void font_changed_callback (gpointer callback_data);
-static void smooth_font_changed_callback (gpointer callback_data);
+static void create_icon_container (FMIconView *icon_view);
+static void fm_icon_view_initialize (FMIconView *icon_view);
+static void fm_icon_view_initialize_class (FMIconViewClass *klass);
+static gboolean fm_icon_view_is_empty (FMDirectoryView *view);
+static void fm_icon_view_set_directory_sort_by (FMIconView *icon_view,
+ NautilusFile *file,
+ const char *sort_by);
+static void fm_icon_view_set_zoom_level (FMIconView *view,
+ NautilusZoomLevel new_level,
+ gboolean always_set_level);
+gboolean fm_icon_view_supports_auto_layout (FMIconView *view);
+static void fm_icon_view_update_icon_container_fonts (FMIconView *icon_view);
+static void fm_icon_view_update_icon_container_smooth_font (FMIconView *icon_view);
+static void fm_icon_view_update_icon_container_font_size_table (FMIconView *icon_view);
+static void fm_icon_view_update_click_mode (FMIconView *icon_view);
+static void fm_icon_view_update_smooth_graphics_mode (FMIconView *icon_view);
+static gboolean fm_icon_view_using_tighter_layout (FMIconView *icon_view);
+static gboolean fm_icon_view_get_directory_tighter_layout (FMIconView *icon_view,
+ NautilusFile *file);
+static void fm_icon_view_set_directory_tighter_layout (FMIconView *icon_view,
+ NautilusFile *file,
+ gboolean tighter_layout);
+static gboolean real_supports_auto_layout (FMIconView *view);
+static const SortCriterion *get_sort_criterion_by_id (const char *id);
+static const SortCriterion *get_sort_criterion_by_sort_type (NautilusFileSortType sort_type);
+static void set_sort_criterion_by_id (FMIconView *icon_view,
+ const char *id);
+static gboolean set_sort_reversed (FMIconView *icon_view,
+ gboolean new_value);
+static void switch_to_manual_layout (FMIconView *view);
+static void preview_audio (FMIconView *icon_view,
+ NautilusFile *file,
+ gboolean start_flag);
+static void update_layout_menus (FMIconView *view);
+static void default_sort_in_reverse_order_changed_callback (gpointer callback_data);
+static void default_sort_order_changed_callback (gpointer callback_data);
+static void default_use_tighter_layout_changed_callback (gpointer callback_data);
+static void default_use_manual_layout_changed_callback (gpointer callback_data);
+static void default_zoom_level_changed_callback (gpointer callback_data);
+static void default_zoom_level_font_size_changed_callback (gpointer callback_data);
+static void font_changed_callback (gpointer callback_data);
+static void smooth_font_changed_callback (gpointer callback_data);
+static void icon_view_handle_uri_list (NautilusIconContainer *container,
+ const char *item_uris,
+ GdkDragAction action,
+ int x,
+ int y,
+ FMIconView *view);
+
static int preview_sound_auto_value;
EEL_DEFINE_CLASS_BOILERPLATE (FMIconView,
@@ -2321,6 +2333,8 @@ fm_icon_view_initialize_class (FMIconVie
static void
fm_icon_view_initialize (FMIconView *icon_view)
{
+ NautilusIconContainer *icon_container;
+
g_return_if_fail (GTK_BIN (icon_view)->child == NULL);
icon_view->details = g_new0 (FMIconViewDetails, 1);
@@ -2329,6 +2343,7 @@ fm_icon_view_initialize (FMIconView *ico
icon_view->details->timeout = -1;
icon_view->details->audio_preview_file = NULL;
create_icon_container (icon_view);
+ icon_container = get_icon_container (icon_view);
eel_preferences_add_callback_while_alive (NAUTILUS_PREFERENCES_ICON_VIEW_FONT,
font_changed_callback,
@@ -2362,6 +2377,12 @@ fm_icon_view_initialize (FMIconView *ico
default_zoom_level_changed_callback,
icon_view,
GTK_OBJECT (icon_view));
+
+ gtk_signal_connect (GTK_OBJECT (icon_container),
+ "handle_uri_list",
+ GTK_SIGNAL_FUNC (icon_view_handle_uri_list),
+ icon_view);
+
}
static gboolean
@@ -2650,4 +2671,148 @@ create_icon_container (FMIconView *icon_
fm_icon_view_update_smooth_graphics_mode (icon_view);
gtk_widget_show (GTK_WIDGET (icon_container));
+}
+
+static void
+icon_view_handle_uri_list (NautilusIconContainer *container, const char *item_uris,
+ GdkDragAction action, int x, int y, FMIconView *view)
+{
+
+ GList *uri_list, *node, *real_uri_list = NULL;
+ GnomeVFSURI *container_uri;
+ GnomeDesktopEntry *entry;
+ GdkPoint point;
+ char *local_path;
+ char *stripped_uri;
+ char *container_uri_string;
+ const char *last_slash, *link_name;
+ int n_uris;
+ gboolean all_local;
+ GArray *points;
+
+ if (item_uris == NULL) {
+ return;
+ }
+
+ container_uri_string = fm_directory_view_get_uri (FM_DIRECTORY_VIEW (view));
+ container_uri = gnome_vfs_uri_new (container_uri_string);
+ g_return_if_fail (container_uri != NULL);
+
+ if (gnome_vfs_uri_is_local (container_uri) == FALSE) {
+ eel_show_warning_dialog (_("Drag and drop is only supported to local file systems."),
+ _("Drag and Drop error"),
+ fm_directory_view_get_containing_window (FM_DIRECTORY_VIEW (view)));
+ gnome_vfs_uri_unref (container_uri);
+ g_free (container_uri_string);
+ return;
+ }
+
+ if (action == GDK_ACTION_ASK) {
+ action = eel_drag_drop_action_ask
+ (GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK);
+ }
+
+ /* We don't support GDK_ACTION_ASK or GDK_ACTION_PRIVATE
+ * and we don't support combinations either. */
+ if ((action != GDK_ACTION_DEFAULT) &&
+ (action != GDK_ACTION_COPY) &&
+ (action != GDK_ACTION_MOVE) &&
+ (action != GDK_ACTION_LINK)) {
+ eel_show_warning_dialog (_("An invalid drag type was used."),
+ _("Drag and Drop error"),
+ fm_directory_view_get_containing_window (FM_DIRECTORY_VIEW (view)));
+ g_free (container_uri);
+ gnome_vfs_uri_unref (container_uri);
+ return;
+ }
+
+ point.x = x;
+ point.y = y;
+
+ /* Most of what comes in here is not really URIs, but rather paths that
+ * have a file: prefix in them. We try to sanitize the uri list as a
+ * result. Additionally, if they are all local files, then we can copy
+ * them. Otherwise, we just make links.
+ */
+ all_local = TRUE;
+ n_uris = 0;
+ uri_list = gnome_uri_list_extract_uris (item_uris);
+ for (node = uri_list; node != NULL; node = node->next) {
+ gchar *sanitized_uri;
+
+ sanitized_uri = eel_make_uri_from_half_baked_uri (node->data);
+ if (sanitized_uri == NULL)
+ continue;
+ real_uri_list = g_list_append (real_uri_list, sanitized_uri);
+ if (strncmp (sanitized_uri, "file", 4) != 0)
+ all_local = FALSE;
+ n_uris++;
+ }
+ gnome_uri_list_free_strings (uri_list);
+
+ if (all_local == TRUE &&
+ (action == GDK_ACTION_COPY ||
+ action == GDK_ACTION_MOVE)) {
+ /* Copying files */
+ if (n_uris == 1) {
+ GdkPoint tmp_point = { 0, 0 };
+
+ /* pass in a 1-item array of icon positions, relative to x, y */
+ points = g_array_new (FALSE, TRUE, sizeof (GdkPoint));
+ g_array_append_val (points, tmp_point);
+ } else {
+ points = NULL;
+ }
+ fm_directory_view_move_copy_items (real_uri_list, points,
+ container_uri_string,
+ action, x, y, FM_DIRECTORY_VIEW (view));
+
+ if (points)
+ g_array_free (points, TRUE);
+ } else {
+ for (node = real_uri_list; node != NULL; node = node->next) {
+ /* Make a link using the desktop file contents? */
+ local_path = gnome_vfs_get_local_path_from_uri (node->data);
+ if (local_path != NULL) {
+ entry = gnome_desktop_entry_load (local_path);
+ if (entry != NULL) {
+
+ /* FIXME: Handle name conflicts? */
+ nautilus_link_local_create_from_gnome_entry (entry, container_uri_string, &point);
+ gnome_desktop_entry_free (entry);
+ }
+ g_free (local_path);
+ if (entry != NULL) {
+ continue;
+ }
+ }
+
+ /* Make a link from the URI alone. Generate the file
+ * name by extracting the basename of the URI.
+ */
+ /* FIXME: This should be using eel_uri_get_basename
+ * instead of a "roll our own" solution.
+ */
+ stripped_uri = eel_str_strip_trailing_chr ((char *)node->data, '/');
+ g_print ("local_path:%s\nstripped_uri:%s\n", (char *)node->data, stripped_uri);
+ last_slash = strrchr (stripped_uri, '/');
+ link_name = last_slash == NULL ? NULL : last_slash + 1;
+
+ if (!eel_str_is_empty (link_name)) {
+ /* FIXME: Handle name conflicts? */
+ nautilus_link_local_create (container_uri_string, link_name,
+ "gnome-http-url", local_path,
+ &point, NAUTILUS_LINK_GENERIC);
+ }
+
+ g_free (stripped_uri);
+
+ break;
+ }
+ }
+
+ gnome_uri_list_free_strings (real_uri_list);
+ gnome_vfs_uri_unref (container_uri);
+ g_free (container_uri_string);
+
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]