static GdkDragAction xfdesktop_regular_file_icon_get_allowed_drop_actions(XfdesktopIcon *icon, GdkDragAction *suggested_action) { GFileInfo *info = xfdesktop_file_icon_peek_file_info(XFDESKTOP_FILE_ICON(icon)); if(!info) { if(suggested_action) *suggested_action = 0; return 0; } /* if it's executable we can 'copy'. if it's a folder we can do anything * if it's writable. */ if(g_file_info_get_file_type(info) == G_FILE_TYPE_DIRECTORY) { if(g_file_info_get_attribute_boolean(info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) { if(suggested_action) *suggested_action = GDK_ACTION_MOVE; return GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK | GDK_ACTION_ASK; } } else { if(xfdesktop_file_utils_file_is_executable(info)) { if(suggested_action) *suggested_action = GDK_ACTION_COPY; return GDK_ACTION_COPY; } } if(suggested_action) *suggested_action = 0; return 0; }
static GdkDragAction xfdesktop_volume_icon_get_allowed_drop_actions(XfdesktopIcon *icon, GdkDragAction *suggested_action) { /* if not mounted, it doesn't really make sense to allow any operations * here. if mounted, we should allow everything if it's writable. */ /* FIXME: should i allow all actions if not mounted as well, and try to * mount and resolve on drop? */ if(xfdesktop_volume_icon_is_mounted(icon)) { GFileInfo *info = xfdesktop_file_icon_peek_file_info(XFDESKTOP_FILE_ICON(icon)); if(info) { if(g_file_info_get_attribute_boolean(info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) { if(suggested_action) *suggested_action = GDK_ACTION_COPY; return GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK; } } } if(suggested_action) *suggested_action = 0; return 0; }
static GdkDragAction xfdesktop_special_file_icon_get_allowed_drop_actions(XfdesktopIcon *icon, GdkDragAction *suggested_action) { XfdesktopSpecialFileIcon *special_file_icon = XFDESKTOP_SPECIAL_FILE_ICON(icon); GFileInfo *info; GdkDragAction actions = 0; if(special_file_icon->priv->type != XFDESKTOP_SPECIAL_FILE_ICON_TRASH) { info = xfdesktop_file_icon_peek_file_info(XFDESKTOP_FILE_ICON(icon)); if(info) { if(g_file_info_get_attribute_boolean(info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) { XF_DEBUG("can move, copy, link and ask"); actions = GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK | GDK_ACTION_ASK; if(suggested_action) *suggested_action = GDK_ACTION_MOVE; } } } else { XF_DEBUG("can move"); actions = GDK_ACTION_MOVE; /* everything else is just silly */ if(suggested_action) *suggested_action = GDK_ACTION_MOVE; } if(suggested_action) *suggested_action = 0; return actions; }
static const gchar * xfdesktop_special_file_icon_peek_tooltip(XfdesktopIcon *icon) { XfdesktopSpecialFileIcon *special_file_icon = XFDESKTOP_SPECIAL_FILE_ICON(icon); if(!special_file_icon->priv->tooltip) { GFileInfo *info = xfdesktop_file_icon_peek_file_info(XFDESKTOP_FILE_ICON(icon)); if(!info) return NULL; if(XFDESKTOP_SPECIAL_FILE_ICON_TRASH == special_file_icon->priv->type) { if(special_file_icon->priv->trash_item_count == 0) { special_file_icon->priv->tooltip = g_strdup(_("Trash is empty")); } else { special_file_icon->priv->tooltip = g_strdup_printf(g_dngettext(GETTEXT_PACKAGE, _("Trash contains one item"), _("Trash contains %d items"), special_file_icon->priv->trash_item_count), special_file_icon->priv->trash_item_count); } } else { const gchar *description; gchar *size_string, *time_string; guint64 size, mtime; if(special_file_icon->priv->type == XFDESKTOP_SPECIAL_FILE_ICON_FILESYSTEM) description = _("File System"); else if(special_file_icon->priv->type == XFDESKTOP_SPECIAL_FILE_ICON_HOME) description = _("Home"); else { description = g_file_info_get_attribute_string(info, G_FILE_ATTRIBUTE_STANDARD_DESCRIPTION); } size = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_STANDARD_SIZE); size_string = g_format_size(size); mtime = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_TIME_MODIFIED); time_string = xfdesktop_file_utils_format_time_for_display(mtime); special_file_icon->priv->tooltip = g_strdup_printf(_("%s\nSize: %s\nLast modified: %s"), description, size_string, time_string); g_free(size_string); g_free(time_string); } } return special_file_icon->priv->tooltip; }
static GdkDragAction xfdesktop_regular_file_icon_get_allowed_drag_actions(XfdesktopIcon *icon) { GFileInfo *info = xfdesktop_file_icon_peek_file_info(XFDESKTOP_FILE_ICON(icon)); GFile *file = xfdesktop_file_icon_peek_file(XFDESKTOP_FILE_ICON(icon)); GdkDragAction actions = GDK_ACTION_LINK; /* we can always link */ if(!info) return 0; if(g_file_info_get_attribute_boolean(info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ)) { GFileInfo *parent_info; GFile *parent_file; actions |= GDK_ACTION_COPY; /* we can only move if the parent is writable */ parent_file = g_file_get_parent(file); parent_info = g_file_query_info(parent_file, XFDESKTOP_FILE_INFO_NAMESPACE, G_FILE_QUERY_INFO_NONE, NULL, NULL); if(parent_info) { if(g_file_info_get_attribute_boolean(parent_info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) { actions |= GDK_ACTION_MOVE; } g_object_unref(parent_info); } g_object_unref(parent_file); } return actions; }
static GdkDragAction xfdesktop_volume_icon_get_allowed_drag_actions(XfdesktopIcon *icon) { /* volume icons more or less represent the volume's mount point, usually * (hopefully) a local path. so when it's mounted, we certainly can't move * the mount point, but copying and linking should be OK. when not mounted, * we should just disallow everything, since, even if its ThunarVfsInfo * is valid, we can't guarantee it won't change after mounting. */ /* FIXME: should i allow all actions if not mounted as well, and try to * mount and resolve on drop? */ if(xfdesktop_volume_icon_is_mounted(icon)) { GFileInfo *info = xfdesktop_file_icon_peek_file_info(XFDESKTOP_FILE_ICON(icon)); if(info) { if(g_file_info_get_attribute_boolean(info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ)) return GDK_ACTION_COPY | GDK_ACTION_LINK; else return GDK_ACTION_LINK; } } return 0; }
static const gchar * xfdesktop_regular_file_icon_peek_tooltip(XfdesktopIcon *icon) { XfdesktopRegularFileIcon *regular_file_icon = XFDESKTOP_REGULAR_FILE_ICON(icon); if(!regular_file_icon->priv->tooltip) { GFileInfo *info = xfdesktop_file_icon_peek_file_info(XFDESKTOP_FILE_ICON(icon)); const gchar *content_type, *comment = NULL; gchar *description, *size_string, *time_string; guint64 size, mtime; gboolean is_desktop_file = FALSE; if(!info) return NULL; if(g_content_type_equals(g_file_info_get_content_type(info), "application/x-desktop")) { is_desktop_file = TRUE; } else { gchar *uri = g_file_get_uri(regular_file_icon->priv->file); if(g_str_has_suffix(uri, ".desktop")) is_desktop_file = TRUE; g_free(uri); } content_type = g_file_info_get_content_type(info); description = g_content_type_get_description(content_type); size = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_STANDARD_SIZE); size_string = g_format_size(size); mtime = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_TIME_MODIFIED); time_string = xfdesktop_file_utils_format_time_for_display(mtime); regular_file_icon->priv->tooltip = g_strdup_printf(_("Type: %s\nSize: %s\nLast modified: %s"), description, size_string, time_string); /* Extract the Comment entry from the .desktop file */ if(is_desktop_file) { gchar *path = g_file_get_path(regular_file_icon->priv->file); XfceRc *rcfile = xfce_rc_simple_open(path, TRUE); g_free(path); if(rcfile) { xfce_rc_set_group(rcfile, "Desktop Entry"); comment = xfce_rc_read_entry(rcfile, "Comment", NULL); } /* Prepend the comment to the tooltip */ if(comment != NULL && *comment != '\0') { gchar *tooltip = regular_file_icon->priv->tooltip; regular_file_icon->priv->tooltip = g_strdup_printf("%s\n%s", comment, tooltip); g_free(tooltip); } xfce_rc_close(rcfile); } g_free(time_string); g_free(size_string); g_free(description); } return regular_file_icon->priv->tooltip; }
gboolean xfdesktop_regular_file_icon_do_drop_dest(XfdesktopIcon *icon, XfdesktopIcon *src_icon, GdkDragAction action) { XfdesktopRegularFileIcon *regular_file_icon = XFDESKTOP_REGULAR_FILE_ICON(icon); XfdesktopFileIcon *src_file_icon = XFDESKTOP_FILE_ICON(src_icon); GFileInfo *src_info; GFile *src_file; gboolean result = FALSE; TRACE("entering"); g_return_val_if_fail(regular_file_icon && src_file_icon, FALSE); g_return_val_if_fail(xfdesktop_regular_file_icon_get_allowed_drop_actions(icon, NULL) != 0, FALSE); src_file = xfdesktop_file_icon_peek_file(src_file_icon); src_info = xfdesktop_file_icon_peek_file_info(src_file_icon); if(!src_info) return FALSE; if(g_file_info_get_file_type(regular_file_icon->priv->file_info) != G_FILE_TYPE_DIRECTORY && xfdesktop_file_utils_file_is_executable(regular_file_icon->priv->file_info)) { GList files; files.data = src_file; files.prev = files.next = NULL; xfdesktop_file_utils_execute(NULL, regular_file_icon->priv->file, &files, regular_file_icon->priv->gscreen, NULL); result = TRUE; } else { GFile *parent, *dest_file = NULL; gchar *name; parent = g_file_get_parent(src_file); if(!parent) return FALSE; g_object_unref(parent); name = g_file_get_basename(src_file); if(!name) return FALSE; switch(action) { case GDK_ACTION_MOVE: dest_file = g_object_ref(regular_file_icon->priv->file); break; case GDK_ACTION_COPY: dest_file = g_file_get_child(regular_file_icon->priv->file, name); break; case GDK_ACTION_LINK: dest_file = g_object_ref(regular_file_icon->priv->file); break; default: g_warning("Unsupported drag action: %d", action); } if(dest_file) { xfdesktop_file_utils_transfer_file(action, src_file, dest_file, regular_file_icon->priv->gscreen); g_object_unref(dest_file); result = TRUE; } g_free(name); } return result; }
static gboolean xfdesktop_volume_icon_do_drop_dest(XfdesktopIcon *icon, XfdesktopIcon *src_icon, GdkDragAction action) { XfdesktopVolumeIcon *volume_icon = XFDESKTOP_VOLUME_ICON(icon); XfdesktopFileIcon *src_file_icon = XFDESKTOP_FILE_ICON(src_icon); GFileInfo *src_info; GFile *src_file, *parent, *dest_file = NULL; gboolean result = FALSE; gchar *name; DBG("entering"); g_return_val_if_fail(volume_icon && src_file_icon, FALSE); g_return_val_if_fail(xfdesktop_volume_icon_get_allowed_drop_actions(icon, NULL), FALSE); src_file = xfdesktop_file_icon_peek_file(src_file_icon); src_info = xfdesktop_file_icon_peek_file_info(src_file_icon); if(!src_info) return FALSE; if(!volume_icon->priv->file_info) return FALSE; parent = g_file_get_parent(src_file); if(!parent) return FALSE; g_object_unref(parent); name = g_file_get_basename(src_file); if(!name) return FALSE; switch(action) { case GDK_ACTION_MOVE: DBG("doing move"); dest_file = g_object_ref(volume_icon->priv->file); break; case GDK_ACTION_COPY: DBG("doing copy"); dest_file = g_file_get_child(volume_icon->priv->file, name); break; case GDK_ACTION_LINK: DBG("doing link"); dest_file = g_object_ref(volume_icon->priv->file); break; default: g_warning("Unsupported drag action: %d", action); } if(dest_file) { xfdesktop_file_utils_transfer_file(action, src_file, dest_file, volume_icon->priv->gscreen); g_object_unref(dest_file); result = TRUE; } g_free(name); return result; }
static gboolean xfdesktop_special_file_icon_do_drop_dest(XfdesktopIcon *icon, XfdesktopIcon *src_icon, GdkDragAction action) { XfdesktopSpecialFileIcon *special_file_icon = XFDESKTOP_SPECIAL_FILE_ICON(icon); XfdesktopFileIcon *src_file_icon = XFDESKTOP_FILE_ICON(src_icon); GFileInfo *src_info; GFile *src_file; GFile *dest_file = NULL; gboolean result = FALSE; TRACE("entering"); g_return_val_if_fail(special_file_icon && src_file_icon, FALSE); g_return_val_if_fail(xfdesktop_special_file_icon_get_allowed_drop_actions(icon, NULL), FALSE); src_file = xfdesktop_file_icon_peek_file(src_file_icon); src_info = xfdesktop_file_icon_peek_file_info(src_file_icon); if(!src_info) return FALSE; if(special_file_icon->priv->type == XFDESKTOP_SPECIAL_FILE_ICON_TRASH) { GList files; XF_DEBUG("doing trash"); /* fake a file list */ files.data = src_file; files.prev = files.next = NULL; /* let the trash service handle the trash operation */ xfdesktop_file_utils_trash_files(&files, special_file_icon->priv->gscreen, NULL); } else { gchar *name = g_file_get_basename(src_file); if(!name) return FALSE; switch(action) { case GDK_ACTION_MOVE: XF_DEBUG("doing move"); dest_file = g_object_ref(special_file_icon->priv->file); break; case GDK_ACTION_COPY: XF_DEBUG("doing copy"); dest_file = g_file_get_child(special_file_icon->priv->file, name); break; case GDK_ACTION_LINK: XF_DEBUG("doing link"); dest_file = g_object_ref(special_file_icon->priv->file); break; default: g_warning("Unsupported drag action: %d", action); } /* let the file manager service move/copy/link the file */ if(dest_file) { xfdesktop_file_utils_transfer_file(action, src_file, dest_file, special_file_icon->priv->gscreen); result = TRUE; } g_object_unref(dest_file); g_free(name); } return result; }