[nautilus/wip/csoriano/destktop-split2: 42/47] file-dnd: move dnd handling to file



commit fec23ffde756db41482d6f33ddc8d94e85ff82bb
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.

 libnautilus-private/Makefile.am                    |    2 -
 libnautilus-private/nautilus-canvas-dnd.c          |    1 -
 libnautilus-private/nautilus-dnd.h                 |   20 ---
 libnautilus-private/nautilus-file-dnd.c            |  129 --------------------
 libnautilus-private/nautilus-file-dnd.h            |   41 ------
 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 -
 11 files changed, 131 insertions(+), 199 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 2b6d2a3..c6b0722 100644
--- a/libnautilus-private/nautilus-canvas-dnd.c
+++ b/libnautilus-private/nautilus-canvas-dnd.c
@@ -36,7 +36,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 b92a97f..e7df840 100644
--- a/libnautilus-private/nautilus-dnd.h
+++ b/libnautilus-private/nautilus-dnd.h
@@ -38,26 +38,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 48aa94e..da1d312 100644
--- a/libnautilus-private/nautilus-file.c
+++ b/libnautilus-private/nautilus-file.c
@@ -8123,7 +8123,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 02e449e..f786391 100644
--- a/libnautilus-private/nautilus-file.h
+++ b/libnautilus-private/nautilus-file.h
@@ -83,7 +83,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"
@@ -459,6 +479,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 dd63851..5b0813b 100644
--- a/libnautilus-private/nautilus-tree-view-drag-dest.c
+++ b/libnautilus-private/nautilus-tree-view-drag-dest.c
@@ -30,7 +30,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 23e2e7a..9159e1b 100644
--- a/src/nautilus-canvas-view.c
+++ b/src/nautilus-canvas-view.c
@@ -40,7 +40,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 8a22489..95b2d4c 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -76,7 +76,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 1c2f996..e1c6101 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -49,7 +49,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]