[nautilus] file-dnd: move dnd handling to file



commit 487cec0491679c5602fa5f3dc2c852d1ebaa4cc3
Author: Carlos Soriano <csoriano gnome org>
Date:   Wed Mar 30 15:39:13 2016 +0200

    file-dnd: move dnd handling to file
    
    We are requiring file handling like special casing subclasses in the
    dnd handling.
    
    We are currently doing it outside of nautilus class... which makes
    overriding on subclasses impossible.
    
    This design goes against inheritance design, so there is no point on
    making it that way if it defeats this purpose.
    
    So merge the handling of file dnd inside the file class itself, and in
    upcoming patches we will override that handling in order to use
    inheritance instead of special casing in the parent.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=712620

 libnautilus-private/Makefile.am                    |    2 -
 libnautilus-private/nautilus-canvas-dnd.c          |    1 -
 libnautilus-private/nautilus-dnd.h                 |   20 ----
 libnautilus-private/nautilus-file.c                |  100 +++++++++++++++++++-
 libnautilus-private/nautilus-file.h                |   32 ++++++-
 libnautilus-private/nautilus-tree-view-drag-dest.c |    2 +-
 src/nautilus-canvas-view.c                         |    1 -
 src/nautilus-files-view.c                          |    1 -
 src/nautilus-list-view.c                           |    1 -
 9 files changed, 131 insertions(+), 29 deletions(-)
---
diff --git a/libnautilus-private/Makefile.am b/libnautilus-private/Makefile.am
index ea7315b..8c37d4d 100644
--- a/libnautilus-private/Makefile.am
+++ b/libnautilus-private/Makefile.am
@@ -106,8 +106,6 @@ libnautilus_private_la_SOURCES = \
        nautilus-file-changes-queue.h \
        nautilus-file-conflict-dialog.c \
        nautilus-file-conflict-dialog.h \
-       nautilus-file-dnd.c \
-       nautilus-file-dnd.h \
        nautilus-file-operations.c \
        nautilus-file-operations.h \
        nautilus-file-private.h \
diff --git a/libnautilus-private/nautilus-canvas-dnd.c b/libnautilus-private/nautilus-canvas-dnd.c
index 60ed964..c485c9a 100644
--- a/libnautilus-private/nautilus-canvas-dnd.c
+++ b/libnautilus-private/nautilus-canvas-dnd.c
@@ -35,7 +35,6 @@
 
 #include "nautilus-canvas-dnd.h"
 
-#include "nautilus-file-dnd.h"
 #include "nautilus-canvas-private.h"
 #include "nautilus-global-preferences.h"
 #include "nautilus-link.h"
diff --git a/libnautilus-private/nautilus-dnd.h b/libnautilus-private/nautilus-dnd.h
index b73d02e..35872ae 100644
--- a/libnautilus-private/nautilus-dnd.h
+++ b/libnautilus-private/nautilus-dnd.h
@@ -37,26 +37,6 @@
 #define NAUTILUS_ICON_DND_XDNDDIRECTSAVE_TYPE  "XdndDirectSave0" /* XDS Protocol Type */
 #define NAUTILUS_ICON_DND_RAW_TYPE     "application/octet-stream"
 
-/* Item of the drag selection list */
-typedef struct {
-       NautilusFile *file;
-       char *uri;
-       gboolean got_icon_position;
-       int icon_x, icon_y;
-       int icon_width, icon_height;
-} NautilusDragSelectionItem;
-
-/* Standard Drag & Drop types. */
-typedef enum {
-       NAUTILUS_ICON_DND_GNOME_ICON_LIST,
-       NAUTILUS_ICON_DND_URI_LIST,
-       NAUTILUS_ICON_DND_NETSCAPE_URL,
-       NAUTILUS_ICON_DND_TEXT,
-       NAUTILUS_ICON_DND_XDNDDIRECTSAVE,
-       NAUTILUS_ICON_DND_RAW,
-       NAUTILUS_ICON_DND_ROOTWINDOW_DROP
-} NautilusIconDndTargetType;
-
 /* drag&drop-related information. */
 typedef struct {
        GtkTargetList *target_list;
diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c
index cad5142..8066799 100644
--- a/libnautilus-private/nautilus-file.c
+++ b/libnautilus-private/nautilus-file.c
@@ -8122,7 +8122,105 @@ nautilus_file_info_providers_done (NautilusFile *file)
        nautilus_file_changed (file);
 }
 
-static void     
+/* DND */
+
+static gboolean
+nautilus_drag_can_accept_files (NautilusFile *drop_target_item)
+{
+       if (nautilus_file_is_directory (drop_target_item)) {
+               NautilusDirectory *directory;
+               gboolean res;
+
+               /* target is a directory, accept if editable */
+               directory = nautilus_directory_get_for_file (drop_target_item);
+               res = nautilus_directory_is_editable (directory) &&
+                       nautilus_file_can_write (drop_target_item);
+               nautilus_directory_unref (directory);
+               return res;
+       }
+
+       if (NAUTILUS_IS_DESKTOP_ICON_FILE (drop_target_item)) {
+               return TRUE;
+       }
+
+       /* Launchers are an acceptable drop target */
+       if (nautilus_file_is_launcher (drop_target_item)) {
+               return TRUE;
+       }
+
+       if (nautilus_is_file_roller_installed () &&
+           nautilus_file_is_archive (drop_target_item)) {
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
+gboolean
+nautilus_drag_can_accept_item (NautilusFile *drop_target_item,
+                               const char   *item_uri)
+{
+       if (nautilus_file_matches_uri (drop_target_item, item_uri)) {
+               /* can't accept itself */
+               return FALSE;
+       }
+
+       return nautilus_drag_can_accept_files (drop_target_item);
+}
+
+gboolean
+nautilus_drag_can_accept_items (NautilusFile *drop_target_item,
+                                const GList  *items)
+{
+       int max;
+
+       if (drop_target_item == NULL)
+               return FALSE;
+
+       g_assert (NAUTILUS_IS_FILE (drop_target_item));
+
+       /* Iterate through selection checking if item will get accepted by the
+        * drop target. If more than 100 items selected, return an over-optimisic
+        * result
+        */
+       for (max = 100; items != NULL && max >= 0; items = items->next, max--) {
+               if (!nautilus_drag_can_accept_item (drop_target_item,
+                       ((NautilusDragSelectionItem *)items->data)->uri)) {
+                       return FALSE;
+               }
+       }
+
+       return TRUE;
+}
+
+gboolean
+nautilus_drag_can_accept_info (NautilusFile              *drop_target_item,
+                               NautilusIconDndTargetType  drag_type,
+                               const GList               *items)
+{
+       switch (drag_type) {
+               case NAUTILUS_ICON_DND_GNOME_ICON_LIST:
+                       return nautilus_drag_can_accept_items (drop_target_item, items);
+
+               case NAUTILUS_ICON_DND_URI_LIST:
+               case NAUTILUS_ICON_DND_NETSCAPE_URL:
+               case NAUTILUS_ICON_DND_TEXT:
+                       return nautilus_drag_can_accept_files (drop_target_item);
+
+               case NAUTILUS_ICON_DND_XDNDDIRECTSAVE:
+               case NAUTILUS_ICON_DND_RAW:
+                       return nautilus_drag_can_accept_files (drop_target_item); /* Check if we can accept 
files at this location */
+
+               case NAUTILUS_ICON_DND_ROOTWINDOW_DROP:
+                       return FALSE;
+
+               default:
+                       g_assert_not_reached ();
+                       return FALSE;
+       }
+}
+
+static void
 nautilus_file_info_iface_init (NautilusFileInfoIface *iface)
 {
        iface->is_gone = nautilus_file_is_gone;
diff --git a/libnautilus-private/nautilus-file.h b/libnautilus-private/nautilus-file.h
index 40d060b..447eb72 100644
--- a/libnautilus-private/nautilus-file.h
+++ b/libnautilus-private/nautilus-file.h
@@ -82,7 +82,27 @@ typedef enum {
        NAUTILUS_FILE_ICON_FLAGS_USE_ONE_EMBLEM = (1<<7)
 } NautilusFileIconFlags;       
 
-/* Emblems sometimes displayed for NautilusFiles. Do not localize. */ 
+/* Standard Drag & Drop types. */
+typedef enum {
+       NAUTILUS_ICON_DND_GNOME_ICON_LIST,
+       NAUTILUS_ICON_DND_URI_LIST,
+       NAUTILUS_ICON_DND_NETSCAPE_URL,
+       NAUTILUS_ICON_DND_TEXT,
+       NAUTILUS_ICON_DND_XDNDDIRECTSAVE,
+       NAUTILUS_ICON_DND_RAW,
+       NAUTILUS_ICON_DND_ROOTWINDOW_DROP
+} NautilusIconDndTargetType;
+
+/* Item of the drag selection list */
+typedef struct {
+       NautilusFile *file;
+       char *uri;
+       gboolean got_icon_position;
+       int icon_x, icon_y;
+       int icon_width, icon_height;
+} NautilusDragSelectionItem;
+
+/* Emblems sometimes displayed for NautilusFiles. Do not localize. */
 #define NAUTILUS_FILE_EMBLEM_NAME_SYMBOLIC_LINK "symbolic-link"
 #define NAUTILUS_FILE_EMBLEM_NAME_CANT_READ "unreadable"
 #define NAUTILUS_FILE_EMBLEM_NAME_CANT_WRITE "readonly"
@@ -458,6 +478,16 @@ GList *                 nautilus_file_list_filter                       (GList
                                                                          GList                         
**failed,
                                                                          NautilusFileFilterFunc          
filter_function,
                                                                          gpointer                        
user_data);
+/* DND */
+gboolean                nautilus_drag_can_accept_item                   (NautilusFile                   
*drop_target_item,
+                                                                         const char                     
*item_uri);
+
+gboolean                nautilus_drag_can_accept_items                  (NautilusFile                   
*drop_target_item,
+                                                                         const GList                    
*items);
+
+gboolean                nautilus_drag_can_accept_info                   (NautilusFile                   
*drop_target_item,
+                                                                         NautilusIconDndTargetType       
drag_type,
+                                                                         const GList                    
*items);
 
 /* Debugging */
 void                    nautilus_file_dump                              (NautilusFile                   
*file);
diff --git a/libnautilus-private/nautilus-tree-view-drag-dest.c 
b/libnautilus-private/nautilus-tree-view-drag-dest.c
index 41d1666..5cadc32 100644
--- a/libnautilus-private/nautilus-tree-view-drag-dest.c
+++ b/libnautilus-private/nautilus-tree-view-drag-dest.c
@@ -29,7 +29,7 @@
 
 #include "nautilus-tree-view-drag-dest.h"
 
-#include "nautilus-file-dnd.h"
+#include "nautilus-dnd.h"
 #include "nautilus-file-changes-queue.h"
 #include "nautilus-global-preferences.h"
 #include "nautilus-link.h"
diff --git a/src/nautilus-canvas-view.c b/src/nautilus-canvas-view.c
index 1380d5e..db028c6 100644
--- a/src/nautilus-canvas-view.c
+++ b/src/nautilus-canvas-view.c
@@ -39,7 +39,6 @@
 #include <libnautilus-private/nautilus-clipboard-monitor.h>
 #include <libnautilus-private/nautilus-directory.h>
 #include <libnautilus-private/nautilus-dnd.h>
-#include <libnautilus-private/nautilus-file-dnd.h>
 #include <libnautilus-private/nautilus-file-utilities.h>
 #include <libnautilus-private/nautilus-ui-utilities.h>
 #include <libnautilus-private/nautilus-global-preferences.h>
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 9f186b9..4eb136e 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -73,7 +73,6 @@
 #include <libnautilus-private/nautilus-dnd.h>
 #include <libnautilus-private/nautilus-file-attributes.h>
 #include <libnautilus-private/nautilus-file-changes-queue.h>
-#include <libnautilus-private/nautilus-file-dnd.h>
 #include <libnautilus-private/nautilus-file-operations.h>
 #include <libnautilus-private/nautilus-file-utilities.h>
 #include <libnautilus-private/nautilus-file-private.h>
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index 6f89652..21b3ef2 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -48,7 +48,6 @@
 #include <libnautilus-private/nautilus-column-chooser.h>
 #include <libnautilus-private/nautilus-column-utilities.h>
 #include <libnautilus-private/nautilus-dnd.h>
-#include <libnautilus-private/nautilus-file-dnd.h>
 #include <libnautilus-private/nautilus-file-utilities.h>
 #include <libnautilus-private/nautilus-ui-utilities.h>
 #include <libnautilus-private/nautilus-global-preferences.h>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]