[gnome-flashback] desktop: move or copy droped uris to desktop



commit c1bd711219c555e4770cb4bc172b9e7019d32ca4
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Dec 1 20:59:25 2019 +0200

    desktop: move or copy droped uris to desktop

 gnome-flashback/libdesktop/gf-icon-view.c    |  76 +++++++++++++++
 gnome-flashback/libdesktop/gf-icon-view.h    |  10 ++
 gnome-flashback/libdesktop/gf-monitor-view.c | 141 +++++++++++++++++++++++++++
 3 files changed, 227 insertions(+)
---
diff --git a/gnome-flashback/libdesktop/gf-icon-view.c b/gnome-flashback/libdesktop/gf-icon-view.c
index 40944e5..32e70b9 100644
--- a/gnome-flashback/libdesktop/gf-icon-view.c
+++ b/gnome-flashback/libdesktop/gf-icon-view.c
@@ -555,6 +555,44 @@ rename_file_cb (GObject      *object,
     }
 }
 
+static void
+copy_uris_cb (GObject      *object,
+              GAsyncResult *res,
+              gpointer      user_data)
+{
+  GError *error;
+
+  error = NULL;
+  gf_nautilus_gen_call_copy_uris_finish (GF_NAUTILUS_GEN (object),
+                                         res, &error);
+
+  if (error != NULL)
+    {
+      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+        g_warning ("Error copying uris: %s", error->message);
+      g_error_free (error);
+    }
+}
+
+static void
+move_uris_cb (GObject      *object,
+              GAsyncResult *res,
+              gpointer      user_data)
+{
+  GError *error;
+
+  error = NULL;
+  gf_nautilus_gen_call_move_uris_finish (GF_NAUTILUS_GEN (object),
+                                         res, &error);
+
+  if (error != NULL)
+    {
+      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+        g_warning ("Error moving uris: %s", error->message);
+      g_error_free (error);
+    }
+}
+
 static GfIconInfo *
 create_icon_info (GfIconView *self,
                   GtkWidget  *icon)
@@ -2881,6 +2919,12 @@ gf_icon_view_get_file_attributes (GfIconView *self)
                                 NULL);
 }
 
+char *
+gf_icon_view_get_desktop_uri (GfIconView *self)
+{
+  return g_file_get_uri (self->desktop);
+}
+
 void
 gf_icon_view_set_representative_color (GfIconView *self,
                                        GdkRGBA    *color)
@@ -3086,3 +3130,35 @@ gf_icon_view_rename_file (GfIconView *self,
                                     rename_file_cb,
                                     NULL);
 }
+
+void
+gf_icon_view_copy_uris (GfIconView         *self,
+                        const char * const *uris,
+                        const char         *destination)
+{
+  if (self->nautilus == NULL)
+    return;
+
+  gf_nautilus_gen_call_copy_uris (self->nautilus,
+                                  uris,
+                                  destination,
+                                  self->cancellable,
+                                  copy_uris_cb,
+                                  NULL);
+}
+
+void
+gf_icon_view_move_uris (GfIconView         *self,
+                        const char * const *uris,
+                        const char         *destination)
+{
+  if (self->nautilus == NULL)
+    return;
+
+  gf_nautilus_gen_call_move_uris (self->nautilus,
+                                  uris,
+                                  destination,
+                                  self->cancellable,
+                                  move_uris_cb,
+                                  NULL);
+}
diff --git a/gnome-flashback/libdesktop/gf-icon-view.h b/gnome-flashback/libdesktop/gf-icon-view.h
index f1fd742..8d3be92 100644
--- a/gnome-flashback/libdesktop/gf-icon-view.h
+++ b/gnome-flashback/libdesktop/gf-icon-view.h
@@ -32,6 +32,8 @@ GfThumbnailFactory *gf_icon_view_get_thumbnail_factory    (GfIconView          *
 
 char               *gf_icon_view_get_file_attributes      (GfIconView          *self);
 
+char               *gf_icon_view_get_desktop_uri          (GfIconView          *self);
+
 void                gf_icon_view_set_representative_color (GfIconView          *self,
                                                            GdkRGBA             *color);
 
@@ -59,6 +61,14 @@ void                gf_icon_view_rename_file              (GfIconView          *
                                                            const char          *uri,
                                                            const char          *new_name);
 
+void                gf_icon_view_copy_uris                (GfIconView          *self,
+                                                           const char * const  *uris,
+                                                           const char          *destination);
+
+void                gf_icon_view_move_uris                (GfIconView          *self,
+                                                           const char * const  *uris,
+                                                           const char          *destination);
+
 G_END_DECLS
 
 #endif
diff --git a/gnome-flashback/libdesktop/gf-monitor-view.c b/gnome-flashback/libdesktop/gf-monitor-view.c
index eaf28b3..c9e3d87 100644
--- a/gnome-flashback/libdesktop/gf-monitor-view.c
+++ b/gnome-flashback/libdesktop/gf-monitor-view.c
@@ -396,6 +396,94 @@ add_drag_rectangles_from_gnome_icon_list (GfMonitorView *self,
   g_strfreev (list);
 }
 
+static char **
+get_uris_from_icon_list (GfMonitorView *self,
+                         GfIcon        *drag_icon)
+{
+  GPtrArray *uris;
+  GList *selected_icons;
+  GList *l;
+
+  uris = g_ptr_array_new ();
+  selected_icons = gf_icon_view_get_selected_icons (self->icon_view);
+
+  for (l = selected_icons; l != NULL; l = l->next)
+    {
+      GFile *file;
+
+      file = gf_icon_get_file (GF_ICON (l->data));
+      g_ptr_array_add (uris, g_file_get_uri (file));
+    }
+
+  g_ptr_array_add (uris, NULL);
+
+  return (char **) g_ptr_array_free (uris, FALSE);
+}
+
+static char **
+get_uris_from_gnome_icon_list (GfMonitorView *self,
+                               const guchar  *gnome_icon_list)
+{
+  GPtrArray *uris;
+  char **list;
+
+  uris = g_ptr_array_new ();
+  list = g_strsplit ((const char *) gnome_icon_list, "\r\n", -1);
+
+  if (list != NULL)
+    {
+      int i;
+
+      for (i = 0; list[i] != NULL; i++)
+        {
+          char **parts;
+
+          parts = g_strsplit (list[i], "\r", -1);
+          if (parts == NULL)
+            continue;
+
+          g_ptr_array_add (uris, g_strdup (parts[0]));
+          g_strfreev (parts);
+        }
+
+      g_strfreev (list);
+    }
+
+  g_ptr_array_add (uris, NULL);
+
+  return (char **) g_ptr_array_free (uris, FALSE);
+}
+
+static void
+copy_to_desktop (GfMonitorView  *self,
+                 char          **uris)
+{
+  char *desktop_uri;
+
+  desktop_uri = gf_icon_view_get_desktop_uri (self->icon_view);
+
+  gf_icon_view_copy_uris (self->icon_view,
+                          (const char * const *) uris,
+                          desktop_uri);
+
+  g_free (desktop_uri);
+}
+
+static void
+move_to_desktop (GfMonitorView  *self,
+                 char          **uris)
+{
+  char *desktop_uri;
+
+  desktop_uri = gf_icon_view_get_desktop_uri (self->icon_view);
+
+  gf_icon_view_move_uris (self->icon_view,
+                          (const char * const *) uris,
+                          desktop_uri);
+
+  g_free (desktop_uri);
+}
+
 static void
 drag_data_received_cb (GtkWidget        *widget,
                        GdkDragContext   *context,
@@ -478,27 +566,80 @@ drag_data_received_cb (GtkWidget        *widget,
 
       if (info == 100)
         {
+          GfIcon *icon;
+
+          icon = *(gpointer *) gtk_selection_data_get_data (data);
+
           if (action == GDK_ACTION_MOVE &&
               self->placement != GF_PLACEMENT_AUTO_ARRANGE_ICONS)
             {
             }
           else if (action == GDK_ACTION_COPY)
             {
+              if (self->placement == GF_PLACEMENT_AUTO_ARRANGE_ICONS)
+                {
+                  char **uris;
+
+                  uris = get_uris_from_icon_list (self, icon);
+
+                  copy_to_desktop (self, uris);
+                  g_strfreev (uris);
+
+                  success = TRUE;
+                }
             }
         }
       else if (info == 200)
         {
+          const guchar *selection_data;
+
+          selection_data = gtk_selection_data_get_data (data);
+
           if (action == GDK_ACTION_MOVE)
             {
+              if (self->placement == GF_PLACEMENT_AUTO_ARRANGE_ICONS)
+                {
+                  char **uris;
+
+                  uris = get_uris_from_gnome_icon_list (self, selection_data);
+
+                  move_to_desktop (self, uris);
+                  g_strfreev (uris);
+
+                  success = TRUE;
+                  delete = TRUE;
+                }
             }
           else if (action == GDK_ACTION_COPY)
             {
+              if (self->placement == GF_PLACEMENT_AUTO_ARRANGE_ICONS)
+                {
+                  char **uris;
+
+                  uris = get_uris_from_gnome_icon_list (self, selection_data);
+
+                  copy_to_desktop (self, uris);
+                  g_strfreev (uris);
+
+                  success = TRUE;
+                }
             }
         }
       else if (info == 300)
         {
           if (action == GDK_ACTION_COPY)
             {
+              if (self->placement == GF_PLACEMENT_AUTO_ARRANGE_ICONS)
+                {
+                  char **uris;
+
+                  uris = gtk_selection_data_get_uris (data);
+
+                  copy_to_desktop (self, uris);
+                  g_strfreev (uris);
+
+                  success = TRUE;
+                }
             }
         }
 


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