summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Tomas <den.t@gmx.de>2013-04-20 13:21:45 +0300
committerEric Koegel <eric.koegel@gmail.com>2013-04-20 13:35:24 +0300
commit7ff0477814096554ccd6c14a56c851bd1c32166b (patch)
tree349b18dfba9097127c3200a6b3a62a2427b1eb1f
parentc9ad3db47331b542f6a19de40b8c10238034e2ca (diff)
downloadxfdesktop-7ff0477814096554ccd6c14a56c851bd1c32166b.tar.gz
Fix HTTP URL performance issue / wrong action proposed
- only check "file" URLs for move/copy - adding an optional output parameter "suggested_action" to the icon's allowed_drop_actions() The suggested actions are: folder: move if writable else none volume: copy if writable else none file: copy (run) if executable else none trash: move Signed-off-by: Eric Koegel <eric.koegel@gmail.com>
-rw-r--r--src/xfdesktop-file-icon-manager.c32
-rw-r--r--src/xfdesktop-icon-view.c40
-rw-r--r--src/xfdesktop-icon.c12
-rw-r--r--src/xfdesktop-icon.h5
-rw-r--r--src/xfdesktop-regular-file-icon.c23
-rw-r--r--src/xfdesktop-special-file-icon.c15
-rw-r--r--src/xfdesktop-volume-icon.c16
7 files changed, 103 insertions, 40 deletions
diff --git a/src/xfdesktop-file-icon-manager.c b/src/xfdesktop-file-icon-manager.c
index 1f425ad2..d68ff735 100644
--- a/src/xfdesktop-file-icon-manager.c
+++ b/src/xfdesktop-file-icon-manager.c
@@ -3228,31 +3228,45 @@ xfdesktop_file_icon_manager_propose_drop_action(XfdesktopIconViewManager *manage
file_icon = XFDESKTOP_FILE_ICON(drop_icon);
tfile = xfdesktop_file_icon_peek_file(file_icon);
tinfo = xfdesktop_file_icon_peek_file_info(file_icon);
- }
- if(tfile && !g_file_has_uri_scheme(tfile, "file")) {
- return action;
+ /* if it's a volume, but we don't have |tinfo|, this just isn't
+ * going to work */
+ if(!tinfo && XFDESKTOP_IS_VOLUME_ICON(drop_icon)) {
+ return 0;
+ }
+
+ if(tfile && !g_file_has_uri_scheme(tfile, "file")) {
+ return action;
+ }
+
+ if(tinfo && g_file_info_get_file_type(tinfo) != G_FILE_TYPE_DIRECTORY) {
+ return action;
+ }
}
file_list = xfdesktop_file_utils_file_list_from_string((const gchar *)gtk_selection_data_get_data(data));
if(file_list) {
GFile *base_dest_file = NULL;
- gboolean dest_is_volume = (drop_icon
- && XFDESKTOP_IS_VOLUME_ICON(drop_icon));
- /* if it's a volume, but we don't have |tinfo|, this just isn't
- * going to work */
- if(!tinfo && dest_is_volume) {
+ /* source must be local file */
+ if(!g_file_has_uri_scheme(file_list->data, "file")) {
xfdesktop_file_utils_file_list_free(file_list);
return action;
}
- if(tinfo && g_file_info_get_file_type(tinfo) == G_FILE_TYPE_DIRECTORY) {
+ if(tinfo) {
base_dest_file = g_object_ref(tfile);
} else {
base_dest_file = g_object_ref(fmanager->priv->folder);
}
+ /* dropping on ourselves? */
+ if(g_strcmp0(g_file_get_uri(file_list->data), g_file_get_uri(base_dest_file)) == 0) {
+ g_object_unref(base_dest_file);
+ xfdesktop_file_utils_file_list_free(file_list);
+ return 0;
+ }
+
/* Determine if we should move/copy by checking if the files
* are on the same filesystem and are writable by the user.
*/
diff --git a/src/xfdesktop-icon-view.c b/src/xfdesktop-icon-view.c
index b2360cd5..cf034852 100644
--- a/src/xfdesktop-icon-view.c
+++ b/src/xfdesktop-icon-view.c
@@ -1387,7 +1387,7 @@ xfdesktop_icon_view_drag_motion(GtkWidget *widget,
icon_on_dest = xfdesktop_icon_view_icon_in_cell(icon_view, hover_row,
hover_col);
if(icon_on_dest) {
- if(!xfdesktop_icon_get_allowed_drop_actions(icon_on_dest))
+ if(!xfdesktop_icon_get_allowed_drop_actions(icon_on_dest, NULL))
return FALSE;
} else if(!xfdesktop_grid_is_free_position(icon_view, hover_row, hover_col))
return FALSE;
@@ -1407,7 +1407,7 @@ xfdesktop_icon_view_drag_motion(GtkWidget *widget,
else /* #3 */
our_action = gdk_drag_context_get_suggested_action(context);
} else {
- /* start with all available actions */
+ /* start with all available actions (may be filtered by modifier keys) */
GdkDragAction allowed_actions = context->actions;
if(is_local_drag) { /* #2 */
@@ -1426,18 +1426,30 @@ xfdesktop_icon_view_drag_motion(GtkWidget *widget,
}
allowed_actions &= xfdesktop_icon_get_allowed_drag_actions(icon_view->priv->cursor);
+
+ /* for local drags, let the dest icon decide */
+ allowed_actions &= xfdesktop_icon_get_allowed_drop_actions(icon_on_dest, &our_action);
+ } else { /* #4 */
+ allowed_actions &= xfdesktop_icon_get_allowed_drop_actions(icon_on_dest, NULL);
+
+ /* for foreign drags, take the action suggested by the source */
+ our_action = gdk_drag_context_get_suggested_action(context);
}
-
+
/* #2 or #4 */
- allowed_actions &= xfdesktop_icon_get_allowed_drop_actions(icon_on_dest);
-
- /* priority: move, copy, link */
- if(allowed_actions & GDK_ACTION_MOVE)
- our_action = GDK_ACTION_MOVE;
- else if(allowed_actions & GDK_ACTION_COPY)
- our_action = GDK_ACTION_COPY;
- else if(allowed_actions & GDK_ACTION_LINK)
- our_action = GDK_ACTION_LINK;
+
+ /* fallback actions if the suggested action is not allowed,
+ * priority: move, copy, link */
+ if(!(our_action & allowed_actions)) {
+ if(allowed_actions & GDK_ACTION_MOVE)
+ our_action = GDK_ACTION_MOVE;
+ else if(allowed_actions & GDK_ACTION_COPY)
+ our_action = GDK_ACTION_COPY;
+ else if(allowed_actions & GDK_ACTION_LINK)
+ our_action = GDK_ACTION_LINK;
+ else
+ our_action = 0;
+ }
}
/* allow the drag dest to override the selected action based on the drag data */
@@ -1445,6 +1457,8 @@ xfdesktop_icon_view_drag_motion(GtkWidget *widget,
icon_view->priv->hover_col = hover_col;
icon_view->priv->proposed_drop_action = our_action;
icon_view->priv->dropped = FALSE;
+ g_object_set_data(G_OBJECT(context), "--xfdesktop-icon-view-drop-icon",
+ icon_on_dest);
gtk_drag_get_data(widget, context, target, time_);
/* the actual call to gdk_drag_status() is deferred to
@@ -1626,7 +1640,7 @@ xfdesktop_icon_view_drag_data_received(GtkWidget *widget,
context, row, col, data,
info, time_);
} else {
- /* FIXME: cannot use x and y here, for they doen't seem to have any
+ /* FIXME: cannot use x and y here, for they don't seem to have any
* meaningful value */
GdkDragAction action = icon_view->priv->proposed_drop_action;
diff --git a/src/xfdesktop-icon.c b/src/xfdesktop-icon.c
index 38c15388..ffe3d2fa 100644
--- a/src/xfdesktop-icon.c
+++ b/src/xfdesktop-icon.c
@@ -221,7 +221,8 @@ xfdesktop_icon_get_allowed_drag_actions(XfdesktopIcon *icon)
/*< optional; drops aren't allowed if not provided >*/
GdkDragAction
-xfdesktop_icon_get_allowed_drop_actions(XfdesktopIcon *icon)
+xfdesktop_icon_get_allowed_drop_actions(XfdesktopIcon *icon,
+ GdkDragAction *suggested_action)
{
XfdesktopIconClass *klass;
@@ -229,10 +230,13 @@ xfdesktop_icon_get_allowed_drop_actions(XfdesktopIcon *icon)
klass = XFDESKTOP_ICON_GET_CLASS(icon);
- if(!klass->get_allowed_drop_actions)
+ if(!klass->get_allowed_drop_actions) {
+ if(suggested_action)
+ *suggested_action = 0;
return 0;
-
- return klass->get_allowed_drop_actions(icon);
+ }
+
+ return klass->get_allowed_drop_actions(icon, suggested_action);
}
/*< optional; required if get_allowed_drop_actions() can return nonzero >*/
diff --git a/src/xfdesktop-icon.h b/src/xfdesktop-icon.h
index e42261e8..5b750fd4 100644
--- a/src/xfdesktop-icon.h
+++ b/src/xfdesktop-icon.h
@@ -68,7 +68,7 @@ struct _XfdesktopIconClass
GdkDragAction (*get_allowed_drag_actions)(XfdesktopIcon *icon);
- GdkDragAction (*get_allowed_drop_actions)(XfdesktopIcon *icon);
+ GdkDragAction (*get_allowed_drop_actions)(XfdesktopIcon *icon, GdkDragAction *suggested_action);
gboolean (*do_drop_dest)(XfdesktopIcon *icon, XfdesktopIcon *src_icon, GdkDragAction action);
G_CONST_RETURN gchar *(*peek_tooltip)(XfdesktopIcon *icon);
@@ -98,7 +98,8 @@ gboolean xfdesktop_icon_get_position(XfdesktopIcon *icon,
GdkDragAction xfdesktop_icon_get_allowed_drag_actions(XfdesktopIcon *icon);
-GdkDragAction xfdesktop_icon_get_allowed_drop_actions(XfdesktopIcon *icon);
+GdkDragAction xfdesktop_icon_get_allowed_drop_actions(XfdesktopIcon *icon,
+ GdkDragAction *suggested_action);
gboolean xfdesktop_icon_do_drop_dest(XfdesktopIcon *icon,
XfdesktopIcon *src_icon,
GdkDragAction action);
diff --git a/src/xfdesktop-regular-file-icon.c b/src/xfdesktop-regular-file-icon.c
index 6e4b71d7..a247a43d 100644
--- a/src/xfdesktop-regular-file-icon.c
+++ b/src/xfdesktop-regular-file-icon.c
@@ -80,7 +80,8 @@ static GdkPixbuf *xfdesktop_regular_file_icon_peek_pixbuf(XfdesktopIcon *icon,
static G_CONST_RETURN gchar *xfdesktop_regular_file_icon_peek_label(XfdesktopIcon *icon);
static G_CONST_RETURN gchar *xfdesktop_regular_file_icon_peek_tooltip(XfdesktopIcon *icon);
static GdkDragAction xfdesktop_regular_file_icon_get_allowed_drag_actions(XfdesktopIcon *icon);
-static GdkDragAction xfdesktop_regular_file_icon_get_allowed_drop_actions(XfdesktopIcon *icon);
+static GdkDragAction xfdesktop_regular_file_icon_get_allowed_drop_actions(XfdesktopIcon *icon,
+ GdkDragAction *suggested_action);
static gboolean xfdesktop_regular_file_icon_do_drop_dest(XfdesktopIcon *icon,
XfdesktopIcon *src_icon,
GdkDragAction action);
@@ -411,24 +412,36 @@ xfdesktop_regular_file_icon_get_allowed_drag_actions(XfdesktopIcon *icon)
}
static GdkDragAction
-xfdesktop_regular_file_icon_get_allowed_drop_actions(XfdesktopIcon *icon)
+xfdesktop_regular_file_icon_get_allowed_drop_actions(XfdesktopIcon *icon,
+ GdkDragAction *suggested_action)
{
GFileInfo *info = xfdesktop_file_icon_peek_file_info(XFDESKTOP_FILE_ICON(icon));
- if(!info)
+ if(!info) {
+ if(suggested_action)
+ *suggested_action = 0;
return 0;
+ }
/* if it's executable we can 'copy'. if it's a folder we can do anything
* if it's writable. */
if(g_file_info_get_file_type(info) == G_FILE_TYPE_DIRECTORY) {
- if(g_file_info_get_attribute_boolean(info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
+ if(g_file_info_get_attribute_boolean(info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) {
+ if(suggested_action)
+ *suggested_action = GDK_ACTION_MOVE;
return GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK;
+ }
} else {
if(xfdesktop_file_utils_file_is_executable(info)) {
+ if(suggested_action)
+ *suggested_action = GDK_ACTION_COPY;
return GDK_ACTION_COPY;
}
}
+ if(suggested_action)
+ *suggested_action = 0;
+
return 0;
}
@@ -446,7 +459,7 @@ xfdesktop_regular_file_icon_do_drop_dest(XfdesktopIcon *icon,
DBG("entering");
g_return_val_if_fail(regular_file_icon && src_file_icon, FALSE);
- g_return_val_if_fail(xfdesktop_regular_file_icon_get_allowed_drop_actions(icon) != 0,
+ g_return_val_if_fail(xfdesktop_regular_file_icon_get_allowed_drop_actions(icon, NULL) != 0,
FALSE);
src_file = xfdesktop_file_icon_peek_file(src_file_icon);
diff --git a/src/xfdesktop-special-file-icon.c b/src/xfdesktop-special-file-icon.c
index db4b7bce..955263c1 100644
--- a/src/xfdesktop-special-file-icon.c
+++ b/src/xfdesktop-special-file-icon.c
@@ -75,7 +75,8 @@ static GdkPixbuf *xfdesktop_special_file_icon_peek_pixbuf(XfdesktopIcon *icon,
static G_CONST_RETURN gchar *xfdesktop_special_file_icon_peek_label(XfdesktopIcon *icon);
static G_CONST_RETURN gchar *xfdesktop_special_file_icon_peek_tooltip(XfdesktopIcon *icon);
static GdkDragAction xfdesktop_special_file_icon_get_allowed_drag_actions(XfdesktopIcon *icon);
-static GdkDragAction xfdesktop_special_file_icon_get_allowed_drop_actions(XfdesktopIcon *icon);
+static GdkDragAction xfdesktop_special_file_icon_get_allowed_drop_actions(XfdesktopIcon *icon,
+ GdkDragAction *suggested_action);
static gboolean xfdesktop_special_file_icon_do_drop_dest(XfdesktopIcon *icon,
XfdesktopIcon *src_icon,
GdkDragAction action);
@@ -305,7 +306,8 @@ xfdesktop_special_file_icon_get_allowed_drag_actions(XfdesktopIcon *icon)
}
static GdkDragAction
-xfdesktop_special_file_icon_get_allowed_drop_actions(XfdesktopIcon *icon)
+xfdesktop_special_file_icon_get_allowed_drop_actions(XfdesktopIcon *icon,
+ GdkDragAction *suggested_action)
{
XfdesktopSpecialFileIcon *special_file_icon = XFDESKTOP_SPECIAL_FILE_ICON(icon);
GFileInfo *info;
@@ -319,13 +321,20 @@ xfdesktop_special_file_icon_get_allowed_drop_actions(XfdesktopIcon *icon)
{
DBG("can move, copy and link");
actions = GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK;
+ if(suggested_action)
+ *suggested_action = GDK_ACTION_MOVE;
}
}
} else {
DBG("can move");
actions = GDK_ACTION_MOVE; /* everything else is just silly */
+ if(suggested_action)
+ *suggested_action = GDK_ACTION_MOVE;
}
+ if(suggested_action)
+ *suggested_action = 0;
+
return actions;
}
@@ -344,7 +353,7 @@ xfdesktop_special_file_icon_do_drop_dest(XfdesktopIcon *icon,
DBG("entering");
g_return_val_if_fail(special_file_icon && src_file_icon, FALSE);
- g_return_val_if_fail(xfdesktop_special_file_icon_get_allowed_drop_actions(icon),
+ g_return_val_if_fail(xfdesktop_special_file_icon_get_allowed_drop_actions(icon, NULL),
FALSE);
src_file = xfdesktop_file_icon_peek_file(src_file_icon);
diff --git a/src/xfdesktop-volume-icon.c b/src/xfdesktop-volume-icon.c
index 4f2154ed..d642f891 100644
--- a/src/xfdesktop-volume-icon.c
+++ b/src/xfdesktop-volume-icon.c
@@ -81,7 +81,8 @@ static GdkPixbuf *xfdesktop_volume_icon_peek_pixbuf(XfdesktopIcon *icon,
static G_CONST_RETURN gchar *xfdesktop_volume_icon_peek_label(XfdesktopIcon *icon);
static G_CONST_RETURN gchar *xfdesktop_volume_icon_peek_tooltip(XfdesktopIcon *icon);
static GdkDragAction xfdesktop_volume_icon_get_allowed_drag_actions(XfdesktopIcon *icon);
-static GdkDragAction xfdesktop_volume_icon_get_allowed_drop_actions(XfdesktopIcon *icon);
+static GdkDragAction xfdesktop_volume_icon_get_allowed_drop_actions(XfdesktopIcon *icon,
+ GdkDragAction *suggested_action);
static gboolean xfdesktop_volume_icon_do_drop_dest(XfdesktopIcon *icon,
XfdesktopIcon *src_icon,
GdkDragAction action);
@@ -328,7 +329,8 @@ xfdesktop_volume_icon_get_allowed_drag_actions(XfdesktopIcon *icon)
}
static GdkDragAction
-xfdesktop_volume_icon_get_allowed_drop_actions(XfdesktopIcon *icon)
+xfdesktop_volume_icon_get_allowed_drop_actions(XfdesktopIcon *icon,
+ GdkDragAction *suggested_action)
{
/* if not mounted, it doesn't really make sense to allow any operations
* here. if mounted, we should allow everything if it's writable. */
@@ -339,10 +341,16 @@ xfdesktop_volume_icon_get_allowed_drop_actions(XfdesktopIcon *icon)
if(xfdesktop_volume_icon_is_mounted(icon)) {
GFileInfo *info = xfdesktop_file_icon_peek_file_info(XFDESKTOP_FILE_ICON(icon));
if(info) {
- if(g_file_info_get_attribute_boolean(info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
+ if(g_file_info_get_attribute_boolean(info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) {
+ if(suggested_action)
+ *suggested_action = GDK_ACTION_COPY;
return GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK;
+ }
}
}
+
+ if(suggested_action)
+ *suggested_action = 0;
return 0;
}
@@ -362,7 +370,7 @@ xfdesktop_volume_icon_do_drop_dest(XfdesktopIcon *icon,
DBG("entering");
g_return_val_if_fail(volume_icon && src_file_icon, FALSE);
- g_return_val_if_fail(xfdesktop_volume_icon_get_allowed_drop_actions(icon),
+ g_return_val_if_fail(xfdesktop_volume_icon_get_allowed_drop_actions(icon, NULL),
FALSE);
src_file = xfdesktop_file_icon_peek_file(src_file_icon);