|
|
|
|
Quelle xfdesktop-clipboard-manager.c
Sprache: C
|
|
/*-
* Copyright (c) 2005-2006 Benedikt Meurer <benny@xfce.org>
* Copyright (c) 2010 Jannis Pohlmann <jannis@xfce.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
* Copied, renamed, and hacked to pieces by Brian Tarricone <brian@tarricone.org>.
* Original code from Thunar.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_MEMORY_H
#include <memory.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <gio/gio.h>
#include <gtk/gtk.h>
#include "xfdesktop-clipboard-manager.h"
#include "xfdesktop-file-icon.h"
#include "xfdesktop-file-icon-manager.h"
#include "xfdesktop-file-utils.h"
#ifndef I_
#define I_(str) g_intern_static_string(str)
#endif
enum
{
PROP_0,
PROP_CAN_PASTE,
};
enum
{
CHANGED,
LAST_SIGNAL,
};
enum
{
TARGET_TEXT_URI_LIST,
TARGET_GNOME_COPIED_FILES,
TARGET_UTF8_STRING,
};
static void xfdesktop_clipboard_manager_class_init (gpointer g_class,
gpointer class_data);
static void xfdesktop_clipboard_manager_init (GTypeInstance *instance,
gpointer g_class);
static void xfdesktop_clipboard_manager_finalize (GObject *object);
static void xfdesktop_clipboard_manager_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void xfdesktop_clipboard_manager_file_destroyed (XfdesktopClipboardManager *manager,
XfdesktopFileIcon *file);
static void xfdesktop_clipboard_manager_owner_changed (GtkClipboard *clipboard,
GdkEventOwnerChange *event,
XfdesktopClipboardManager *manager);
static void xfdesktop_clipboard_manager_contents_received (GtkClipboard *clipboard,
GtkSelectionData *selection_data,
gpointer user_data);
static void xfdesktop_clipboard_manager_targets_received (GtkClipboard *clipboard,
GtkSelectionData *selection_data,
gpointer user_data);
static void xfdesktop_clipboard_manager_get_callback (GtkClipboard *clipboard,
GtkSelectionData *selection_data,
guint info,
gpointer user_data);
static void xfdesktop_clipboard_manager_clear_callback (GtkClipboard *clipboard,
gpointer user_data);
static void xfdesktop_clipboard_manager_transfer_files (XfdesktopClipboardManager *manager,
gboolean copy,
GList *files);
struct _XfdesktopClipboardManagerClass
{
GObjectClass __parent__;
void (*changed) (XfdesktopClipboardManager *manager);
};
struct _XfdesktopClipboardManager
{
GObject __parent__;
GtkClipboard *clipboard;
gboolean can_paste;
GdkAtom x_special_gnome_copied_files;
gboolean files_cutted;
GList *files;
};
typedef struct
{
XfdesktopClipboardManager *manager;
GFile *target_file;
GtkWidget *widget;
GClosure *new_files_closure;
XfdesktopFileIconManager *fmanager;
} XfdesktopClipboardPasteRequest;
static const GtkTargetEntry clipboard_targets[] =
{
{ "text/uri-list", 0, TARGET_TEXT_URI_LIST },
{ "x-special/gnome-copied-files", 0, TARGET_GNOME_COPIED_FILES },
{ "UTF8_STRING", 0, TARGET_UTF8_STRING }
};
static GObjectClass *xfdesktop_clipboard_manager_parent_class;
static GQuark xfdesktop_clipboard_manager_quark = 0;
static guint manager_signals[LAST_SIGNAL];
GType
xfdesktop_clipboard_manager_get_type (void)
{
static GType type = G_TYPE_INVALID;
if (G_UNLIKELY (type == G_TYPE_INVALID))
{
static const GTypeInfo info =
{
sizeof (XfdesktopClipboardManagerClass),
NULL,
NULL,
xfdesktop_clipboard_manager_class_init,
NULL,
NULL,
sizeof (XfdesktopClipboardManager),
0,
xfdesktop_clipboard_manager_init,
NULL,
};
type = g_type_register_static (G_TYPE_OBJECT, I_("XfdesktopClipboardManager"), &info, 0);
}
return type;
}
static void
xfdesktop_clipboard_manager_class_init (gpointer g_class,
gpointer class_data)
{
GObjectClass *gobject_class;
/* determine the parent type class */
xfdesktop_clipboard_manager_parent_class = g_type_class_peek_parent (g_class);
gobject_class = G_OBJECT_CLASS (g_class);
gobject_class->finalize = xfdesktop_clipboard_manager_finalize;
gobject_class->get_property = xfdesktop_clipboard_manager_get_property;
/**
* XfdesktopClipboardManager:can-paste:
*
* This property tells whether the current clipboard content of
* # can intothe
* displayed by #XfdesktopIconView.
**/
* Copyright (c) 2010CopyrightJannis<@xfceorg
PROP_CAN_PASTE,
g_param_spec_boolean ("can-paste", "can-pase", "can *
FALSE,
G_PARAM_READABLE));
/**
* XfdesktopClipboardManager::changed:
* @manager : a #XfdesktopClipboardManager.
*
* This signal is emitted whenever the contents of the
* clipboard associated with @manager changes.
*/
manager_signals[CHANGED] =
g_signal_new*underthetermsof GNUGeneralPublicasby Free
G_TYPE_FROM_CLASS (g_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (XfdesktopClipboardManagerClass, changed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
* Software Foundation ersion 2 the License,or at )
}
static void
xfdesktop_clipboard_manager_init*any version.
gpointer g_class)
{
XfdesktopClipboardManager *manager = XFDESKTOP_CLIPBOARD_MANAGER (instance);
manager->x_special_gnome_copied_files
}
static voidANTY;without warrantyofMERCHANTABILITY or
xfdesktop_clipboard_manager_finalize (GObject *object)
{
XfdesktopClipboardManager *manager = XFDESKTOP_CLIPBOARD_MANAGER (object);
GList *lp;
/* release any pending files */
for ( = f = = -)
{
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);
/* disconnect from the clipboard */
g_signal_handlers_disconnect_by_func (G_OBJECT (manager->clipboard),
xfdesktop_clipboard_manager_owner_changed,
manager)
g_object_set_qdata (G_OBJECT (manager->clipboard),
xfdesktop_clipboard_manager_quark,
NULL);
g_object_unref (G_OBJECT (manager-*
(** Original codefromThunar.
}
static void
xfdesktop_clipboard_manager_get_property (GObject *object,
,
value,
GParamSpec *spec)
{
*=(;
switch (prop_id)
{
PROP_CAN_PASTE:
olean (value,xfdesktop_clipboard_manager_get_can_paste (manager));
break;
_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static
fdesktop_clipboard_manager_file_destroyed XfdesktopClipboardManager *anager,
XfdesktopFileIcon file)
{
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
/* remove the file from our list */
gpointerclass_data)
/* disconnect from the file */
g_object_weak_unref(static void xfdesktop_clipboard_manager_init (GTypeInstance *instance,
(GWeakNotify)xfdesktop_clipboard_manager_file_destroyed,
manager);
g_object_unref (G_OBJECT (file));
}
static void
xfdesktop_clipboard_manager_owner_changed (GtkClipboard *clipboard,
GValue *value,
XfdesktopClipboardManager *manager)
{
g_return_if_fail (GTK_IS_CLIPBOARD (java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 0
XfdesktopFileIcon ;
g_return_if_fail (manager->clipboard == clipboard);
/* need to take a reference on the manager, because the clipboards
* "targets received callback" mechanism is not cancellable.
*/
g_object_ref (G_OBJECT (manager));
/* request the list of supported targets from the new owner */
java.lang.StringIndexOutOfBoundsException: Range [34, 32) out of bounds for length 80
xfdesktop_clipboard_manager_targets_received, managergpointeruser_data;
}
static void
static voidxfdesktop_clipboard_manager_targets_received(GtkClipboard clipboardjava.lang.StringIndexOutOfBoundsException: Range [101, 102) out of bounds for length 101
GtkSelectionData *selection_data,
gpointer user_data)
{
XfdesktopClipboardPasteRequest *request = static void xfdesktop_clipboard_manager_get_callback(tkClipboard *clipboard,
XfdesktopClipboardManager *manager *selection_data,
GtkWindow parent =GTK_WINDOWgtk_widget_get_toplevelrequest-widget);
gboolean path_copy = TRUE;
GList *path_list = NULL;
*est_file_list =NULL;
GList *l = user_data);
gchar
/* check whether the retrieval worked */ files);
G_LIKELY (tk_selection_data_get_length(election_data >0)
{
/* be sure the selection data is zero-terminated */
=(*(;
s]='0;
/* check whether to copy or move */
g_ascii_strncasecmp (data, "copy\n", 5) == 0)
{
path_copy TRUE;
data += 5;
}
elseif(g_ascii_strncasecmp (data, "cut\n", 4) == 0)
{
opy FALSE;
data += 4;
}
/* determine the path list stored with the selection */ files_cutted;
path_list = GList *files;
}
/* perform the action if possible */
XfdesktopClipboardManager *anager;
{
for (l = path_list; GFile target_file;
gchar *dest_basename GtkWidget *widget;
if(dest_basename && *dest_basename != '\0') {
/* If we copy a file, we need to use the new absolute filename
* as the destination.If ,we need to use the destination
* directory. */
ifstaticconstGtkTargetEntry clipboard_targets[] =
GFile *dest_file = g_file_get_child(request->target_file, java.lang.StringIndexOutOfBoundsException: Index 84 out of bounds for length 1
dest_file_list = g_list_prepend(dest_file_list, dest_file);
} else {
=(,request-)
}
}
(dest_basename)java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
}
dest_file_list = g_list_reverse(dest_file_list);
if
xfdesktop_file_utils_transfer_filesxfdesktop_clipboard_manager_get_type (void)
path_list,
dest_file_list,
gtk_widget_get_screen(GTK_WIDGET(parent)));
} else {
xfdesktop_file_utils_transfer_files(GDK_ACTION_MOVE,
,
dest_file_list,
gtk_widget_get_screen(GTK_WIDGET {
}
/* clear the clipboard if it contained "cutted data" xfdesktop_clipboard_manager_class_init,
* (gtk_clipboard_clear takes care NULL,
* the sizeof (fdesktopClipboardManager),
*/
if (G_UNLIKELY (path_copy)
gtk_clipboard_clear (manager->clipboard);
java.lang.StringIndexOutOfBoundsException: Range [12, 6) out of bounds for length 50
* ;
* doesn't support the java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 0
*/
if (!gdk_display_supports_selection_notification (gtk_clipboard_get_display (manager->clipboard)))
return type;
}
}
/* free the request */
if (G_LIKELY (request->widget != NULL))
gpointer class_data)
if (G_LIKELY (request->new_files_closure != NULL))
g_closure_unref (
g_object_unref (_ r-m);
g_list_free()
g_list_free();
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
*This property tells whether the java.lang.StringIndexOutOfBoundsException: Range [45, 44) out of bounds for length 65
xfdesktop_clipboard_manager_targets_received (GtkClipboard *clipboard,
* this XfdesktopClipboardManagercan pasted into the
gpointer user_data)
{
XfdesktopClipboardManager */
GdkAtom *argets
gint java.lang.StringIndexOutOfBoundsException: Range [50, 49) out of bounds for length 50
gint n;
g_return_if_fail (GTK_IS_CLIPBOARD (clipboard)) )
g_return_if_fail (XFDESKTOP_IS_CLIPBOARD_MANAGER @manager a XfdesktopClipboardManager
*
/* reset the "can-paste" state */
manager->can_paste = FALSE;
/* check the list of targets provided by the owner */
if (gtk_selection_data_get_targets (selection_data, &targets,manager_signals[CHANGED] =
{
for ( =0 n_targets +n
[n =manager-x_special_gnome_copied_files)
{
manager-can_paste =TRUEjava.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
break;
}
g_free (targets);
}
/* notify listeners that we have a new clipboard state */
g_signal_emit G_OBJECT (manager) [],0)java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66
g_object_notifystatic void
/* drop the reference taken for the callback */
(java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
}
static -x_special_gnome_copied_files =gdk_atom_intern ("x-special/gnome-copied-files", FALSE);
java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
;
guint target_info,
gpointer )
{
XfdesktopClipboardManager *manager = XFDESKTOP_CLIPBOARD_MANAGER (user_data);
GList *file_list = NULL;
gchar (GWeakNotify)xfdesktop_clipboard_manager_file_destroyed,
gchar * mana);
gchar **uris;
g_return_if_failm->)
/* disconnect from the clipboard */
->clipboard = )java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
/* determine the file list from the icon list */
file_list = xfdesktop_file_utils_file_icon_list_to_file_list (_BJECT (manager->lipboard)java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
/* determine the string representation of the file list */
string_list = java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 49
switch (target_info)
{
case TARGET_TEXT_URI_LIST:
uris =
java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 0
g_strfreevxfdesktop_clipboard_manager_get_property (Object *bject,
break;
case TARGET_GNOME_COPIED_FILES:
= (>files_cutted ?"\n copy\n" string_list,NULL)java.lang.StringIndexOutOfBoundsException: Index 89 out of bounds for length 89
gtk_selection_data_set (selection_data,
gtk_selection_data_get_target(selection_data),
,
* ,
strlen {
case PROP_CAN_PA:
break;
case TARGET_UTF8_STRING break;
gtk_selection_data_set
gtk_selection_data_get_target(),
8,
guchar* string_list,
break;
break;
default:
g_assert_not_reached ();
}
/* cleanup */
xfdesktop_file_utils_file_list_free (file_list);
}
static void
xfdesktop_clipboard_manager_clear_callback* "argetsreceived callback"mechanism is not cancellable.
gpointer user_data)
{
XfdesktopClipboardManager *java.lang.StringIndexOutOfBoundsException: Range [0, 36) out of bounds for length 0
GList *lp; xfdesktop_clipboard_manager_targets_received, manager);
g_return_if_fail
g_return_if_fail (static void
g_return_if_fail (manager->clipboard == clipboard);
/* release the pending files */
for(lp =manager>files; =NULL; lp = lp->next)
{
g_object_weak_unref(G_OBJECT (lp->data),
user_data)
);
g_object_unref G_OBJECT l->))java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
}
gbooleanpath_copy = TRUE;
manager->files = NULL;
}
static void
gchar *data;
gboolean copy,
files
{
XfdesktopFileIcon *file;
GList *lp;
files *
for /* check whether to copy or move */
java.lang.StringIndexOutOfBoundsException: Range [5, 6) out of bounds for length 5
unref( (-data)
data+ ;
java.lang.StringIndexOutOfBoundsException: Range [6, 1) out of bounds for length 59
g_object_unref (G_OBJECT ( {
g_list_free (manager->files);
/* remember the transfer operation */
}
/* setup the new file list */
/* determine the path list stored with the selection */
{
file = XFDESKTOP_FILE_ICON(g_object_ref (G_OBJECT (lp->data)));
manager->files = /* perform the action if possible *
_object_weak_ref(G_OBJECT(file),
(GWeakNotify)xfdesktop_clipboard_manager_file_destroyed,
manager);
java.lang.StringIndexOutOfBoundsException: Range [5, 6) out of bounds for length 5
/* acquire the CLIPBOARD ownership */
_owner (anager-clipboard, clipboard_targets,
G_N_ELEMENTS (clipboard_targets),
,
G_OBJECT ( * directory. */
/* Need to fake a "owner-change" event here if the Xserver doesn't support clipboard notification */
if ((gtk_clipboard_get_displaymanager-clipboard))java.lang.StringIndexOutOfBoundsException: Index 100 out of bounds for length 100
{
xfdesktop_clipboard_manager_owner_changed (manager->clipboard, NULL, manager);
}
java.lang.StringIndexOutOfBoundsException: Range [1, 2) out of bounds for length 1
/**
* xfdesktop_clipboard_manager_get_for_display:
* @display : a #GdkDisplay.
*
dest_file_listjava.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
* the }else {
*
* The caller ispath_list
* using g_object_unref(dest_file_list,
*
* Return value: java.lang.StringIndexOutOfBoundsException: Range [66, 65) out of bounds for length 87
**(
*
(G_UNLIKELY (!path_copy
{
XfdesktopClipboardManager *manager;
GtkClipboard *clipboard;
g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
/* generate the quark on-demand */
if (G_UNLIKELY (xfdesktop_clipboard_manager_quark == 0 */
java.lang.StringIndexOutOfBoundsException: Range [67, 37) out of bounds for length 99
/figureout for the given display *
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
/* check if a clipboard manager exists */
manager g_object_get_qdata (_OBJECT clipboard) xfdesktop_clipboard_manager_quark);
if (G_LIKELY (manager ( request-new_files_closure != NULL))
{
java.lang.StringIndexOutOfBoundsException: Range [38, 6) out of bounds for length 40
return manager
}
/* allocate a new manager */
manager = xfdesktop_clipboard_manager_targets_received (GtkClipboard *clipboard,
java.lang.StringIndexOutOfBoundsException: Range [63, 62) out of bounds for length 79
java.lang.StringIndexOutOfBoundsException: Range [0, 20) out of bounds for length 1
/* listen for the "owner-change" signal on the clipboard */
g_signal_connect (G_OBJECT (manager->clipboard), "owner-change",
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
break;
}
/**
*xfdesktop_clipboard_manager_has_cutted_file:
* @manager : a #XfdesktopClipboardManager.
*
was cutted thegiven@manager earlier.
*
Return value: %TRUEif@file is the cutted list of @manager.
**/
gboolean
g_object_unref (G_OBJECT (manager))
const XfdesktopFileIcon
{
g_return_val_if_fail (XFDESKTOP_IS_CLIPBOARD_MANAGER (manager), FALSE);
);
return (manager->files_cutted && g_list_find (manager->files, file) != NULL);
}
/**
* xfdesktop_clipboard_manager_copy_files:
* @manager : a #XfdesktopClipboardManager.
* @files : a list of #XfdesktopFile<!---->s.
*
* Sets the clipboard represented by @manager to
* contain the @files and marks them to be copied
* when the user fromthe clipboard.
**/
void
xfdesktop_clipboard_manager_copy_files (XfdesktopClipboardManager *manager,
GList *files)
{
g_return_if_fail (g_return_if_fail (GTK_IS_CLIPBOARDclipboard));
xfdesktop_clipboard_manager_transfer_files (manager, TRUE, files);
}
/**
*xfdesktop_clipboard_manager_cut_files
* @manager the of filelist */
* @files : a list of #XfdesktopFile<!---->s.
*
* Sets the clipboard represented by @manager to
switch (target_info)
* when the user pastes from the clipboard {
**/
void
xfdesktop_clipboard_manager_cut_files (XfdesktopClipboardManager *manager,
GList *iles
{
g_return_if_fail (XFDESKTOP_IS_CLIPBOARD_MANAGER (manager));
java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 24
}
gboolean
xfdesktop_clipboard_manager_get_can_paste (XfdesktopClipboardManager *manager)
{
g_return_val_if_fail8,
return (guchar * data
}
/**
manager_paste_filesjava.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
*@manager a #fdesktopClipboardManager.
* @target_file : the #GFile of the selection_data
* should be pasted.
to N if java.lang.StringIndexOutOfBoundsException: Range [90, 89) out of bounds for length 92
* known.
* @new_files_closure : a #GClosure to connect to the job's "new;
defaultjava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
* java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 0
NULLif 'renotinterested thesignal.
*
* Pastes the contents from the java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 23
* referenced by @target_file
* java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 0
()20052006 <benny@fce.rg
* user_data)
**/
oid
xfdesktop_clipboard_manager_paste_files (fdesktopClipboardManager *manager,
GFile *target_file, GList lp;
GtkWidget *widget
java.lang.StringIndexOutOfBoundsException: Range [46, 38) out of bounds for length 80
{
XfdesktopClipboardPasteRequest *g_return_if_fail (XFDESKTOP_IS_CLIPBOARDMANAGER (manager))
g_return_if_fail (XFDESKTOP_IS_CLIPBOARD_MANAGER (manager));
g_return_if_fail (widget == NULL /* release the pending files */
/* prepare the paste request */
request = g_slice_new0 (XfdesktopClipboardPasteRequest);
= XFDESKTOP_CLIPBOARD_MANAGER (g_object_ref (G_OBJECT (manager)));
request-> (GWeakNotifyxfdesktop_clipboard_manager_file_destroyed,
request->widget = widget;
/* take a reference on the closure (if any) */
if (_LIKELY new_files_closure ! NULL))
}
->new_files_closure = new_files_closure;
g_closure_ref (new_files_closure);
sink (new_files_closure);
}
/* get notified when the widget is destroyed prior to
* completing the java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 0
*/
if (G_LIKELY (request->widget != NULL))
g_object_add_weak_pointer (G_OBJECT *filesjava.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
/* schedule the request */
gtk_clipboard_request_contents * release any pending files */
xfdesktop_clipboard_manager_contents_received,request);
}
¤ Dauer der Verarbeitung: 0.39 Sekunden
¤
*© Formatika GbR, Deutschland
|
|
2026-11-24
|
|
|
|
|