Exemplo n.º 1
0
static VALUE
rg_display(VALUE self)
{
#if GTK_CHECK_VERSION(2,2,0)
    return GOBJ2RVAL(gtk_clipboard_get_display(_SELF(self)));
#else
    return Qnil;
#endif
}
static void
xfdesktop_clipboard_manager_transfer_files (XfdesktopClipboardManager *manager,
                                            gboolean                copy,
                                            GList                  *files)
{
  XfdesktopFileIcon *file;
  GList      *lp;

  /* release any pending files */
  for (lp = manager->files; lp != NULL; lp = lp->next)
    {
      g_object_weak_unref(G_OBJECT (lp->data),
                          (GWeakNotify)xfdesktop_clipboard_manager_file_destroyed,
                          manager);
      g_object_unref (G_OBJECT (lp->data));
    }
  g_list_free (manager->files);

  /* remember the transfer operation */
  manager->files_cutted = !copy;

  /* setup the new file list */
  for (lp = files, manager->files = NULL; lp != NULL; lp = lp->next)
    {
      file = g_object_ref (G_OBJECT (lp->data));
      manager->files = g_list_prepend (manager->files, file);
      g_object_weak_ref(G_OBJECT(file), 
                        (GWeakNotify)xfdesktop_clipboard_manager_file_destroyed,
                        manager);
    }

  /* acquire the CLIPBOARD ownership */
  gtk_clipboard_set_with_owner (manager->clipboard, clipboard_targets,
                                G_N_ELEMENTS (clipboard_targets),
                                xfdesktop_clipboard_manager_get_callback,
                                xfdesktop_clipboard_manager_clear_callback,
                                G_OBJECT (manager));

  /* Need to fake a "owner-change" event here if the Xserver doesn't support clipboard notification */
  if (!gdk_display_supports_selection_notification (gtk_clipboard_get_display (manager->clipboard)))
    {
      xfdesktop_clipboard_manager_owner_changed (manager->clipboard, NULL, manager);
    }
}
static void
xfdesktop_clipboard_manager_contents_received (GtkClipboard     *clipboard,
                                            GtkSelectionData *selection_data,
                                            gpointer          user_data)
{
  XfdesktopClipboardPasteRequest *request = user_data;
  XfdesktopClipboardManager      *manager = XFDESKTOP_CLIPBOARD_MANAGER (request->manager);
  GtkWindow                      *parent = GTK_WINDOW(gtk_widget_get_toplevel(request->widget));
  gboolean                        path_copy = TRUE;
  GList                          *path_list = NULL;
  GList                          *dest_file_list  = NULL;
  GList                          *l               = NULL;
  gchar                          *data;

  /* check whether the retrieval worked */
  if (G_LIKELY (gtk_selection_data_get_length(selection_data) > 0))
    {
      /* be sure the selection data is zero-terminated */
      data = (gchar *) gtk_selection_data_get_data(selection_data);
      data[gtk_selection_data_get_length(selection_data)] = '\0';

      /* check whether to copy or move */
      if (g_ascii_strncasecmp (data, "copy\n", 5) == 0)
        {
          path_copy = TRUE;
          data += 5;
        }
      else if (g_ascii_strncasecmp (data, "cut\n", 4) == 0)
        {
          path_copy = FALSE;
          data += 4;
        }

      /* determine the path list stored with the selection */
      path_list = xfdesktop_file_utils_file_list_from_string (data);
    }

  /* perform the action if possible */
  if (G_LIKELY (path_list != NULL))
    {
      for (l = path_list; l; l = l->next) {
        gchar *dest_basename = g_file_get_basename(l->data);

        if(dest_basename && *dest_basename != '\0') {
          /* If we copy a file, we need to use the new absolute filename
           * as the destination. If we move, we need to use the destination
           * directory. */
           if(path_copy) {
             GFile *dest_file = g_file_get_child(request->target_file, dest_basename);
             dest_file_list = g_list_prepend(dest_file_list, dest_file);
           } else {
             dest_file_list = g_list_prepend(dest_file_list, request->target_file);
           }
         }
         g_free(dest_basename);
      }

      dest_file_list = g_list_reverse(dest_file_list);

      if (G_LIKELY (path_copy))
      {
        xfdesktop_file_utils_transfer_files(GDK_ACTION_COPY,
                                            path_list,
                                            dest_file_list,
                                            gtk_widget_get_screen(GTK_WIDGET(parent)));
      } else {
        xfdesktop_file_utils_transfer_files(GDK_ACTION_MOVE,
                                            path_list,
                                            dest_file_list,
                                            gtk_widget_get_screen(GTK_WIDGET(parent)));
      }

      /* clear the clipboard if it contained "cutted data"
       * (gtk_clipboard_clear takes care of not clearing
       * the selection if we don't own it)
       */
      if (G_UNLIKELY (!path_copy))
        gtk_clipboard_clear (manager->clipboard);

      /* check the contents of the clipboard again
       * if either the Xserver or our GTK+ version
       * doesn't support the XFixes extension.
       */
      if (!gdk_display_supports_selection_notification (gtk_clipboard_get_display (manager->clipboard)))
        {
          xfdesktop_clipboard_manager_owner_changed (manager->clipboard, NULL, manager);
        }
    }

  /* free the request */
  if (G_LIKELY (request->widget != NULL))
    g_object_remove_weak_pointer (G_OBJECT (request->widget), (gpointer) &request->widget);
  if (G_LIKELY (request->new_files_closure != NULL))
    g_closure_unref (request->new_files_closure);
  g_object_unref (G_OBJECT (request->manager));

  g_list_free(dest_file_list);
  g_list_free(path_list);
}