[Xfce4-commits] <xfdesktop:danielm/port-to-gio> - src/xfdesktop-file-icon.c: - src/xfdesktop-file-icon.h: * Droped peek_info(), added GFile and GFileInfo members to class, this will make the things a bit easier. - src/xfdesktop-file-utils.c: - src/xfdesktop-file-utils.h: * Ported all functions. * Added some usefull functions to use later: - xfdesktop_file_utils_get_file_info() - xfdesktop_file_utils_get_file_size() - xfdesktop_file_utils_get_file_date() - xfdesktop_file_utils_is_directory() - xfdesktop_file_utils_is_symlink() - xfdesktop_file_utils_is_executable() - xfdesktop_file_utils_is_writable() - xfdesktop_file_utils_is_readable() - xfdesktop_file_utils_is_desktop_file() - xfdesktop_file_utils_can_rename() - xfdesktop_file_utils_can_delete() - xfdesktop_f ile_utils_is_hidden() - xfdesktop_file_utils_is_root() * Some functions changed some args (dropping ThunarVFS Info): - xfdesktop_file_utils_handle_fileop_error() - xfdesktop_file_utils_launch_fallback() - xfdesktop_file_utils_open_folder() * Implemented thunarx-2 changes: - Dropped: xfdesktop_thunarx_file_info_get_vfs_info() - New functions: * xfdesktop_thunarx_file_info_get_file_info() * xfdesktop_thunarx_file_info_get_filesystem_info() * xfdesktop_thunarx_file_info_get_location()
Jannis Pohlmann
noreply at xfce.org
Sun Aug 29 21:14:05 CEST 2010
Updating branch refs/heads/danielm/port-to-gio
to 5b8b29e890b0041ed7182b2cab4dac075a50bfa6 (commit)
from ca5252f0adf83357e0676aaf00da40fdc29c9598 (commit)
commit 5b8b29e890b0041ed7182b2cab4dac075a50bfa6
Author: Daniel Morales <daniel at daniel.com.uy>
Date: Tue Feb 16 12:45:19 2010 -0200
- src/xfdesktop-file-icon.c:
- src/xfdesktop-file-icon.h:
* Droped peek_info(), added GFile and GFileInfo members to class,
this will make the things a bit easier.
- src/xfdesktop-file-utils.c:
- src/xfdesktop-file-utils.h:
* Ported all functions.
* Added some usefull functions to use later:
- xfdesktop_file_utils_get_file_info()
- xfdesktop_file_utils_get_file_size()
- xfdesktop_file_utils_get_file_date()
- xfdesktop_file_utils_is_directory()
- xfdesktop_file_utils_is_symlink()
- xfdesktop_file_utils_is_executable()
- xfdesktop_file_utils_is_writable()
- xfdesktop_file_utils_is_readable()
- xfdesktop_file_utils_is_desktop_file()
- xfdesktop_file_utils_can_rename()
- xfdesktop_file_utils_can_delete()
- xfdesktop_file_utils_is_hidden()
- xfdesktop_file_utils_is_root()
* Some functions changed some args (dropping ThunarVFS Info):
- xfdesktop_file_utils_handle_fileop_error()
- xfdesktop_file_utils_launch_fallback()
- xfdesktop_file_utils_open_folder()
* Implemented thunarx-2 changes:
- Dropped: xfdesktop_thunarx_file_info_get_vfs_info()
- New functions:
* xfdesktop_thunarx_file_info_get_file_info()
* xfdesktop_thunarx_file_info_get_filesystem_info()
* xfdesktop_thunarx_file_info_get_location()
src/xfdesktop-file-icon.c | 107 +++++------
src/xfdesktop-file-icon.h | 20 +-
src/xfdesktop-file-utils.c | 474 +++++++++++++++++++++++++++++++++-----------
src/xfdesktop-file-utils.h | 49 ++++-
4 files changed, 454 insertions(+), 196 deletions(-)
diff --git a/src/xfdesktop-file-icon.c b/src/xfdesktop-file-icon.c
index 4c97463..536fb54 100644
--- a/src/xfdesktop-file-icon.c
+++ b/src/xfdesktop-file-icon.c
@@ -24,10 +24,13 @@
#include <glib-object.h>
+#include <gio/gio.h>
+
#include <libxfce4ui/libxfce4ui.h>
#include "xfdesktop-file-utils.h"
#include "xfdesktop-file-icon.h"
+#include "xfdesktop-job.h"
struct _XfdesktopFileIconPrivate
{
@@ -67,14 +70,20 @@ static void
xfdesktop_file_icon_finalize(GObject *obj)
{
XfdesktopFileIcon *icon = XFDESKTOP_FILE_ICON(obj);
-
+
+ if(icon->info)
+ g_object_unref(icon->info);
+
+ if(icon->gfile)
+ g_object_unref(icon->gfile);
+
if(icon->priv->active_jobs) {
GList *l;
- ThunarVfsJob *job;
+ XfdesktopJob *job;
GCallback cb;
for(l = icon->priv->active_jobs; l; l = l->next) {
- job = THUNAR_VFS_JOB(l->data);
+ job = XFDESKTOP_JOB(l->data);
cb = g_object_get_data(G_OBJECT(job),
"--xfdesktop-file-icon-callback");
if(cb) {
@@ -86,7 +95,7 @@ xfdesktop_file_icon_finalize(GObject *obj)
g_object_set_data(G_OBJECT(job),
"--xfdesktop-file-icon-callback", NULL);
}
- thunar_vfs_job_cancel(job);
+ xfdesktop_job_cancel(job);
g_object_unref(G_OBJECT(job));
}
g_list_free(icon->priv->active_jobs);
@@ -99,88 +108,72 @@ static gboolean
xfdesktop_file_icon_activated(XfdesktopIcon *icon)
{
XfdesktopFileIcon *file_icon = XFDESKTOP_FILE_ICON(icon);
- const ThunarVfsInfo *info = xfdesktop_file_icon_peek_info(file_icon);
GtkWidget *icon_view, *toplevel;
GdkScreen *gscreen;
gboolean success = FALSE;
TRACE("entering");
-
- if(!info)
- return FALSE;
+
+ g_return_val_if_fail(G_IS_FILE(file_icon->gfile), FALSE);
+ g_return_val_if_fail(G_IS_FILE_INFO(file_icon->gfile), FALSE);
icon_view = xfdesktop_icon_peek_icon_view(icon);
toplevel = gtk_widget_get_toplevel(icon_view);
gscreen = gtk_widget_get_screen(icon_view);
-
- if(info->type == THUNAR_VFS_FILE_TYPE_DIRECTORY) {
- xfdesktop_file_utils_open_folder(info, gscreen, GTK_WINDOW(toplevel));
+
+ if(xfdesktop_file_utils_is_directory(file_icon)) {
+ xfdesktop_file_utils_open_folder(file_icon, gscreen, GTK_WINDOW(toplevel));
success = TRUE;
} else {
- if(info->flags & THUNAR_VFS_FILE_FLAGS_EXECUTABLE) {
+
+ if(xfdesktop_file_utils_is_executable(file_icon)) {
+#if 0
success = thunar_vfs_info_execute(info, gscreen, NULL,
xfce_get_homedir(), NULL);
+#endif
}
-
+
if(!success) {
- ThunarVfsMimeDatabase *mime_database;
- ThunarVfsMimeApplication *mime_app;
-
- mime_database = thunar_vfs_mime_database_get_default();
-
- mime_app = thunar_vfs_mime_database_get_default_application(mime_database,
- info->mime_info);
- if(mime_app) {
- GList *path_list = g_list_prepend(NULL, info->path);
-
- DBG("executing");
-
- success = thunar_vfs_mime_handler_exec(THUNAR_VFS_MIME_HANDLER(mime_app),
- gscreen, path_list, NULL);
+ GAppInfo *app_info;
+ GdkAppLaunchContext *context;
+
+ app_info = g_file_query_default_handler(file_icon->gfile, NULL, NULL);
+
+ if(app_info != NULL) {
+ GList *file_list = g_list_prepend(NULL, file_icon->gfile);
+
+ context = gdk_app_launch_context_new();
+ gdk_app_launch_context_set_screen(context, gscreen);
+
+ /* We're not showing the GError message.. at the moment */
+ success = g_app_info_launch(app_info, file_list, G_APP_LAUNCH_CONTEXT(context), NULL);
if(!success) {
gchar *primary = g_markup_printf_escaped(_("Unable to launch \"%s\":"),
- info->display_name);
+ g_file_info_get_display_name(file_icon->info));
xfce_message_dialog(GTK_WINDOW(toplevel), _("Launch Error"),
GTK_STOCK_DIALOG_ERROR, primary,
_("The associated application could not be found or executed."),
GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
g_free(primary);
}
-
- g_object_unref(G_OBJECT(mime_app));
- g_list_free(path_list);
+
+ g_object_unref(context);
+ g_object_unref(app_info);
+ g_list_free(file_list);
} else {
- success = xfdesktop_file_utils_launch_fallback(info,
+ success = xfdesktop_file_utils_launch_fallback(file_icon,
gscreen,
GTK_WINDOW(toplevel));
}
-
- g_object_unref(G_OBJECT(mime_database));
}
}
-
- return success;
-}
-
-G_CONST_RETURN ThunarVfsInfo *
-xfdesktop_file_icon_peek_info(XfdesktopFileIcon *icon)
-{
- XfdesktopFileIconClass *klass;
-
- g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), NULL);
-
- klass = XFDESKTOP_FILE_ICON_GET_CLASS(icon);
-
- if(klass->peek_info)
- return klass->peek_info(icon);
- else
- return NULL;
+ return success;
}
void
-xfdesktop_file_icon_update_info(XfdesktopFileIcon *icon,
- ThunarVfsInfo *info)
+xfdesktop_file_icon_update_gfile(XfdesktopFileIcon *icon,
+ GFile *gfile)
{
XfdesktopFileIconClass *klass;
@@ -188,8 +181,8 @@ xfdesktop_file_icon_update_info(XfdesktopFileIcon *icon,
klass = XFDESKTOP_FILE_ICON_GET_CLASS(icon);
- if(klass->update_info)
- klass->update_info(icon, info);
+ if(klass->update_gfile)
+ klass->update_gfile(icon, gfile);
}
gboolean
@@ -257,7 +250,7 @@ xfdesktop_file_icon_delete_file(XfdesktopFileIcon *icon)
void
xfdesktop_file_icon_add_active_job(XfdesktopFileIcon *icon,
- ThunarVfsJob *job)
+ XfdesktopJob *job)
{
g_return_if_fail(XFDESKTOP_IS_FILE_ICON(icon) && job);
@@ -267,7 +260,7 @@ xfdesktop_file_icon_add_active_job(XfdesktopFileIcon *icon,
gboolean
xfdesktop_file_icon_remove_active_job(XfdesktopFileIcon *icon,
- ThunarVfsJob *job)
+ XfdesktopJob *job)
{
if(g_list_find(icon->priv->active_jobs, job)) {
icon->priv->active_jobs = g_list_remove(icon->priv->active_jobs, job);
diff --git a/src/xfdesktop-file-icon.h b/src/xfdesktop-file-icon.h
index 050a160..419e981 100644
--- a/src/xfdesktop-file-icon.h
+++ b/src/xfdesktop-file-icon.h
@@ -23,9 +23,10 @@
#include <gtk/gtk.h>
-#include <thunar-vfs/thunar-vfs.h>
+#include <gio/gio.h>
#include "xfdesktop-icon.h"
+#include "xfdesktop-job.h"
G_BEGIN_DECLS
@@ -44,6 +45,9 @@ struct _XfdesktopFileIcon
/*< private >*/
XfdesktopFileIconPrivate *priv;
+
+ GFileInfo *info;
+ GFile *gfile;
};
struct _XfdesktopFileIconClass
@@ -51,9 +55,8 @@ struct _XfdesktopFileIconClass
XfdesktopIconClass parent;
/*< virtual functions >*/
- G_CONST_RETURN ThunarVfsInfo *(*peek_info)(XfdesktopFileIcon *icon);
- void (*update_info)(XfdesktopFileIcon *icon, ThunarVfsInfo *info);
-
+ void (*update_gfile)(XfdesktopFileIcon *icon, GFile *gfile);
+
gboolean (*can_rename_file)(XfdesktopFileIcon *icon);
gboolean (*rename_file)(XfdesktopFileIcon *icon, const gchar *new_name);
@@ -63,9 +66,8 @@ struct _XfdesktopFileIconClass
GType xfdesktop_file_icon_get_type(void) G_GNUC_CONST;
-G_CONST_RETURN ThunarVfsInfo *xfdesktop_file_icon_peek_info(XfdesktopFileIcon *icon);
-void xfdesktop_file_icon_update_info(XfdesktopFileIcon *icon,
- ThunarVfsInfo *info);
+void xfdesktop_file_icon_update_gfile(XfdesktopFileIcon *icon,
+ GFile *gfile);
gboolean xfdesktop_file_icon_can_rename_file(XfdesktopFileIcon *icon);
gboolean xfdesktop_file_icon_rename_file(XfdesktopFileIcon *icon,
@@ -75,9 +77,9 @@ gboolean xfdesktop_file_icon_can_delete_file(XfdesktopFileIcon *icon);
gboolean xfdesktop_file_icon_delete_file(XfdesktopFileIcon *icon);
void xfdesktop_file_icon_add_active_job(XfdesktopFileIcon *icon,
- ThunarVfsJob *job);
+ XfdesktopJob *job);
gboolean xfdesktop_file_icon_remove_active_job(XfdesktopFileIcon *icon,
- ThunarVfsJob *job);
+ XfdesktopJob *job);
G_END_DECLS
diff --git a/src/xfdesktop-file-utils.c b/src/xfdesktop-file-utils.c
index 498e547..b5bc273 100644
--- a/src/xfdesktop-file-utils.c
+++ b/src/xfdesktop-file-utils.c
@@ -26,13 +26,17 @@
#include <string.h>
#endif
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
+
#include <gtk/gtk.h>
#include <libxfce4ui/libxfce4ui.h>
#include <exo/exo.h>
-#include <thunar-vfs/thunar-vfs.h>
+#include <gio/gio.h>
#include <dbus/dbus-glib-lowlevel.h>
@@ -44,11 +48,15 @@
#include "xfdesktop-file-icon.h"
#include "xfdesktop-common.h"
#include "xfdesktop-file-utils.h"
+#include "xfdesktop-job.h"
+
+/* File information to query using: xfdesktop_file_utils_get_file_info() */
+#define XFDESKTOP_QUERY_FILE_INFO "standard::*,access::*,unix::*,id::*,time::*"
-ThunarVfsInteractiveJobResponse
+XfdesktopJobResponse
xfdesktop_file_utils_interactive_job_ask(GtkWindow *parent,
const gchar *message,
- ThunarVfsInteractiveJobResponse choices)
+ XfdesktopJobResponse choices)
{
GtkWidget *dlg, *btn;
gint resp;
@@ -57,48 +65,53 @@ xfdesktop_file_utils_interactive_job_ask(GtkWindow *parent,
GTK_STOCK_DIALOG_QUESTION, NULL, message,
NULL, NULL);
- if(choices & THUNAR_VFS_INTERACTIVE_JOB_RESPONSE_CANCEL) {
+ if(choices & XFDESKTOP_JOB_RESPONSE_CANCEL) {
btn = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
gtk_widget_show(btn);
gtk_dialog_add_action_widget(GTK_DIALOG(dlg), btn,
- THUNAR_VFS_INTERACTIVE_JOB_RESPONSE_CANCEL);
+ XFDESKTOP_JOB_RESPONSE_CANCEL);
}
- if(choices & THUNAR_VFS_INTERACTIVE_JOB_RESPONSE_NO) {
+ if(choices & XFDESKTOP_JOB_RESPONSE_NO) {
btn = gtk_button_new_from_stock(GTK_STOCK_NO);
gtk_widget_show(btn);
gtk_dialog_add_action_widget(GTK_DIALOG(dlg), btn,
- THUNAR_VFS_INTERACTIVE_JOB_RESPONSE_NO);
+ XFDESKTOP_JOB_RESPONSE_NO);
}
- if(choices & THUNAR_VFS_INTERACTIVE_JOB_RESPONSE_YES_ALL) {
+ if(choices & XFDESKTOP_JOB_RESPONSE_YES_ALL) {
btn = gtk_button_new_with_mnemonic(_("Yes to _all"));
gtk_widget_show(btn);
gtk_dialog_add_action_widget(GTK_DIALOG(dlg), btn,
- THUNAR_VFS_INTERACTIVE_JOB_RESPONSE_YES_ALL);
+ XFDESKTOP_JOB_RESPONSE_YES_ALL);
}
- if(choices & THUNAR_VFS_INTERACTIVE_JOB_RESPONSE_YES) {
+ if(choices & XFDESKTOP_JOB_RESPONSE_YES) {
btn = gtk_button_new_from_stock(GTK_STOCK_YES);
gtk_widget_show(btn);
gtk_dialog_add_action_widget(GTK_DIALOG(dlg), btn,
- THUNAR_VFS_INTERACTIVE_JOB_RESPONSE_YES);
+ XFDESKTOP_JOB_RESPONSE_YES);
}
resp = gtk_dialog_run(GTK_DIALOG(dlg));
gtk_widget_destroy(dlg);
- return (ThunarVfsInteractiveJobResponse)resp;
+ return (XfdesktopJobResponse)resp;
}
void
xfdesktop_file_utils_handle_fileop_error(GtkWindow *parent,
- const ThunarVfsInfo *src_info,
- const ThunarVfsInfo *dest_info,
+ const XfdesktopFileIcon *src_icon,
+ const XfdesktopFileIcon *dest_icon,
XfdesktopFileUtilsFileop fileop,
GError *error)
{
+ g_return_if_fail(XFDESKTOP_IS_FILE_ICON(src_icon)
+ && G_IS_FILE_INFO(src_icon->info));
+ g_return_if_fail(XFDESKTOP_IS_FILE_ICON(dest_icon)
+ && G_IS_FILE_INFO(dest_icon->info));
+
if(error) {
gchar *primary_fmt, *primary;
@@ -117,8 +130,8 @@ xfdesktop_file_utils_handle_fileop_error(GtkWindow *parent,
}
primary = g_strdup_printf(primary_fmt,
- src_info->display_name,
- dest_info->display_name);
+ g_file_info_get_display_name(src_icon->info),
+ g_file_info_get_display_name(dest_icon->info));
xfce_message_dialog(parent, _("File Error"), GTK_STOCK_DIALOG_ERROR,
primary, error->message,
GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
@@ -127,24 +140,29 @@ xfdesktop_file_utils_handle_fileop_error(GtkWindow *parent,
}
gchar *
-xfdesktop_file_utils_get_file_kind(const ThunarVfsInfo *info,
+xfdesktop_file_utils_get_file_kind(const XfdesktopFileIcon *icon,
gboolean *is_link)
{
gchar *str = NULL;
+ const gchar *content_type;
+
+ g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), NULL);
+ g_return_val_if_fail(G_IS_FILE_INFO(icon->info), NULL);
- if(!strcmp(thunar_vfs_mime_info_get_name(info->mime_info),
- "inode/symlink"))
+ content_type = g_file_info_get_content_type(icon->info);
+
+ if (g_content_type_equals(content_type, "inode/symlink"))
{
str = g_strdup(_("broken link"));
if(is_link)
*is_link = TRUE;
- } else if(info->flags & THUNAR_VFS_FILE_FLAGS_SYMLINK) {
+ } else if(g_file_info_get_is_symlink(icon->info)) {
str = g_strdup_printf(_("link to %s"),
- thunar_vfs_mime_info_get_comment(info->mime_info));
+ g_file_info_get_symlink_target(icon->info));
if(is_link)
*is_link = TRUE;
} else {
- str = g_strdup(thunar_vfs_mime_info_get_comment(info->mime_info));
+ str = g_strdup(g_content_type_get_description(content_type));
if(is_link)
*is_link = FALSE;
}
@@ -153,19 +171,228 @@ xfdesktop_file_utils_get_file_kind(const ThunarVfsInfo *info,
}
+GFileInfo *
+xfdesktop_file_utils_get_file_info(GFile *gfile,
+ GCancellable *cancellable)
+{
+ GFileInfo *info;
+ GError *err = NULL;
+
+ g_return_val_if_fail(G_IS_FILE(gfile), NULL);
+
+ info = g_file_query_info(gfile,
+ XFDESKTOP_QUERY_FILE_INFO,
+ G_FILE_QUERY_INFO_NONE,
+ cancellable, &err);
+ if(err != NULL) {
+ g_warning("Failed to query the file info: %s", err->message);
+ g_error_free(err);
+
+ return NULL;
+ }
+
+ return info;
+}
+
+
+guint64
+xfdesktop_file_utils_get_file_size(const XfdesktopFileIcon *icon,
+ gchar **humanized_size)
+{
+ goffset fSize;
+
+ g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), 0);
+ g_return_val_if_fail(G_IS_FILE_INFO(icon->info), 0);
+
+ fSize = g_file_info_get_size(icon->info);
+
+ if(humanized_size != NULL){
+ *humanized_size = g_format_size_for_display(fSize);
+ }
+
+ return (guint64)fSize;
+}
+
+
+gchar *
+xfdesktop_file_utils_get_file_date(const XfdesktopFileIcon *icon,
+ const gchar *attr)
+{
+ time_t ftime;
+ struct tm *tfile;
+ gchar buffer[64];
+ guint64 iDate;
+
+ g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), NULL);
+ g_return_val_if_fail(G_IS_FILE_INFO(icon->info), NULL);
+
+ iDate = g_file_info_get_attribute_uint64(icon->info, attr);
+
+ if(iDate == 0)
+ return NULL;
+
+ ftime = (time_t)iDate;
+ tfile = localtime(&ftime);
+
+ strftime(buffer, 64, "%Y-%m-%d %H:%M:%S", tfile);
+
+ return g_strdup(buffer);
+}
+
+
+gboolean
+xfdesktop_file_utils_is_directory(const XfdesktopFileIcon *icon)
+{
+ g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), FALSE);
+ g_return_val_if_fail(G_IS_FILE_INFO(icon->info), FALSE);
+
+ return (g_file_info_get_file_type(icon->info) == G_FILE_TYPE_DIRECTORY);
+}
+
+
+gboolean
+xfdesktop_file_utils_is_symlink(const XfdesktopFileIcon *icon)
+{
+ g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), FALSE);
+ g_return_val_if_fail(G_IS_FILE_INFO(icon->info), FALSE);
+
+ return g_file_info_get_is_symlink(icon->info);
+}
+
+
+gboolean
+xfdesktop_file_utils_is_desktop_file(const XfdesktopFileIcon *icon)
+{
+ const gchar *content_type;
+ gboolean is_desktop = FALSE;
+ gchar *basename;
+
+ g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), FALSE);
+ g_return_val_if_fail(G_IS_FILE_INFO(icon->info), FALSE);
+
+ content_type = g_file_info_get_content_type(icon->info);
+
+ if(content_type == NULL)
+ return FALSE;
+
+ is_desktop = g_content_type_equals(content_type, "application/x-desktop");
+ basename = g_file_get_basename(icon->gfile);
+
+ is_desktop = is_desktop && !g_str_has_suffix(basename, ".directory");
+
+ g_free(basename);
+ return is_desktop;
+}
+
+
+gboolean
+xfdesktop_file_utils_is_executable(const XfdesktopFileIcon *icon)
+{
+ gboolean is_executable = FALSE;
+ const gchar *content_type;
+
+ g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), FALSE);
+ g_return_val_if_fail(G_IS_FILE_INFO(icon->info), FALSE);
+
+ content_type = g_file_info_get_content_type(icon->info);
+ if(g_file_info_get_attribute_boolean(icon->info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE))
+ {
+ is_executable = g_content_type_can_be_executable(content_type)
+ && !g_content_type_is_a(content_type, "text/plain");
+ }
+
+ /* Maybe is a desktop file */
+ if(!is_executable)
+ is_executable = xfdesktop_file_utils_is_desktop_file(icon);
+
+ return is_executable;
+}
+
+
+gboolean
+xfdesktop_file_utils_is_readable(const XfdesktopFileIcon *icon)
+{
+ g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), FALSE);
+ g_return_val_if_fail(G_IS_FILE_INFO(icon->info), FALSE);
+
+ if (!g_file_info_has_attribute(icon->info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ))
+ return TRUE;
+
+ return g_file_info_get_attribute_boolean(icon->info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ);
+}
+
+
+gboolean
+xfdesktop_file_utils_is_writable(const XfdesktopFileIcon *icon)
+{
+ g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), FALSE);
+ g_return_val_if_fail(G_IS_FILE_INFO(icon->info), FALSE);
+
+ if (!g_file_info_has_attribute(icon->info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
+ return TRUE;
+
+ return g_file_info_get_attribute_boolean(icon->info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
+}
+
+gboolean
+xfdesktop_file_utils_is_hidden(const XfdesktopFileIcon *icon)
+{
+ g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), FALSE);
+ g_return_val_if_fail(G_IS_FILE_INFO(icon->info), FALSE);
+
+ return g_file_info_get_is_hidden(icon->info);
+}
+
+gboolean
+xfdesktop_file_utils_is_root(const XfdesktopFileIcon *icon)
+{
+ gboolean is_root = TRUE;
+ GFile *parent;
+
+ g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), FALSE);
+ g_return_val_if_fail(G_IS_FILE(icon->gfile), FALSE);
+
+ parent = g_file_get_parent(icon->gfile);
+ if (parent != NULL)
+ {
+ is_root = FALSE;
+ g_object_unref(parent);
+ }
+
+ return is_root;
+}
+
+gboolean
+xfdesktop_file_utils_can_delete(const XfdesktopFileIcon *icon)
+{
+ g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), FALSE);
+ g_return_val_if_fail(G_IS_FILE_INFO(icon->info), FALSE);
+
+ return g_file_info_get_attribute_boolean(icon->info, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE);
+}
+
+
+gboolean
+xfdesktop_file_utils_can_rename(const XfdesktopFileIcon *icon)
+{
+ g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), FALSE);
+ g_return_val_if_fail(G_IS_FILE_INFO(icon->info), FALSE);
+
+ return g_file_info_get_attribute_boolean(icon->info, G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME);
+}
+
+
GList *
xfdesktop_file_utils_file_icon_list_to_path_list(GList *icon_list)
{
GList *path_list = NULL, *l;
XfdesktopFileIcon *icon;
- const ThunarVfsInfo *info;
for(l = icon_list; l; l = l->next) {
icon = XFDESKTOP_FILE_ICON(l->data);
- info = xfdesktop_file_icon_peek_info(icon);
- if(info) {
+ if(G_IS_FILE(icon->gfile)) {
path_list = g_list_prepend(path_list,
- thunar_vfs_path_ref(info->path));
+ g_file_get_path(icon->gfile));
}
}
@@ -218,35 +445,45 @@ xfdesktop_file_utils_get_fallback_icon(gint size)
GdkPixbuf *
xfdesktop_file_utils_get_file_icon(const gchar *custom_icon_name,
- ThunarVfsInfo *info,
+ const XfdesktopFileIcon *icon,
gint size,
const GdkPixbuf *emblem,
guint opacity)
{
GtkIconTheme *itheme = gtk_icon_theme_get_default();
GdkPixbuf *pix_theme = NULL, *pix = NULL;
- const gchar *icon_name;
-
+
+ g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), NULL);
+ g_return_val_if_fail(G_IS_FILE_INFO(icon->info), NULL);
+
if(custom_icon_name) {
pix_theme = gtk_icon_theme_load_icon(itheme, custom_icon_name, size,
ITHEME_FLAGS, NULL);
}
-
- if(!pix_theme && info) {
- icon_name = thunar_vfs_info_get_custom_icon(info);
- if(icon_name) {
- pix_theme = gtk_icon_theme_load_icon(itheme, icon_name, size,
- ITHEME_FLAGS, NULL);
- }
- }
- if(!pix_theme && info && info->mime_info) {
- icon_name = thunar_vfs_mime_info_lookup_icon_name(info->mime_info,
- gtk_icon_theme_get_default());
- DBG("got mime info icon name: %s", icon_name);
- if(icon_name) {
- pix_theme = gtk_icon_theme_load_icon(itheme, icon_name, size,
- ITHEME_FLAGS, NULL);
+ if(!pix_theme) {
+ GIcon *gicon;
+
+ gicon = g_file_info_get_icon(icon->info);
+
+ if(gicon != NULL) {
+ if(G_IS_THEMED_ICON(gicon)) {
+ GtkIconInfo *gicon_info = gtk_icon_theme_lookup_by_gicon(itheme,
+ gicon, size,
+ GTK_ICON_LOOKUP_USE_BUILTIN);
+ if(gicon_info!= NULL) {
+ pix_theme = gtk_icon_info_load_icon(gicon_info, NULL);
+ gtk_icon_info_free(gicon_info);
+ }
+ } else if(G_IS_LOADABLE_ICON(gicon)) {
+ GInputStream *istream = g_loadable_icon_load(G_LOADABLE_ICON(gicon),
+ size, NULL, NULL, NULL);
+ if(istream != NULL) {
+ pix_theme = gdk_pixbuf_new_from_stream(istream, NULL, NULL);
+ g_object_unref(istream);
+ }
+ }
+ g_object_unref (gicon);
}
}
@@ -304,7 +541,7 @@ xfdesktop_file_utils_get_file_icon(const gchar *custom_icon_name,
pix = tmp;
}
#endif
-
+
return pix;
}
@@ -325,14 +562,16 @@ xfdesktop_file_utils_set_window_cursor(GtkWindow *window,
}
gboolean
-xfdesktop_file_utils_launch_fallback(const ThunarVfsInfo *info,
+xfdesktop_file_utils_launch_fallback(const XfdesktopFileIcon *icon,
GdkScreen *screen,
GtkWindow *parent)
{
gboolean ret = FALSE;
gchar *file_manager_app;
- g_return_val_if_fail(info, FALSE);
+ g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), FALSE);
+ g_return_val_if_fail(G_IS_FILE_INFO(icon->info), FALSE);
+ g_return_val_if_fail(G_IS_FILE(icon->gfile), FALSE);
file_manager_app = g_find_program_in_path(FILE_MANAGER_FALLBACK);
if(file_manager_app) {
@@ -344,7 +583,7 @@ xfdesktop_file_utils_launch_fallback(const ThunarVfsInfo *info,
screen = gdk_display_get_default_screen(gdk_display_get_default());
display_name = gdk_screen_make_display_name(screen);
- uri = thunar_vfs_path_dup_uri(info->path);
+ uri = g_file_get_uri(icon->gfile);
commandline = g_strconcat("\"", file_manager_app, "\" \"",
uri, "\"", NULL);
@@ -361,7 +600,7 @@ xfdesktop_file_utils_launch_fallback(const ThunarVfsInfo *info,
if(!ret) {
gchar *primary = g_markup_printf_escaped(_("Unable to launch \"%s\":"),
- info->display_name);
+ g_file_info_get_display_name(icon->info));
xfce_message_dialog(GTK_WINDOW(parent),
_("Launch Error"), GTK_STOCK_DIALOG_ERROR,
primary,
@@ -375,7 +614,7 @@ xfdesktop_file_utils_launch_fallback(const ThunarVfsInfo *info,
typedef struct
{
- const ThunarVfsInfo *info;
+ const XfdesktopFileIcon *icon;
GdkScreen *screen;
GtkWindow *parent;
} XfdesktopDisplayFolderData;
@@ -392,7 +631,7 @@ xfdesktop_file_utils_display_folder_cb(DBusGProxy *proxy,
xfdesktop_file_utils_set_window_cursor(dfdata->parent, GDK_LEFT_PTR);
if(error) {
- xfdesktop_file_utils_launch_fallback(dfdata->info, dfdata->screen,
+ xfdesktop_file_utils_launch_fallback(dfdata->icon, dfdata->screen,
dfdata->parent);
}
@@ -400,13 +639,14 @@ xfdesktop_file_utils_display_folder_cb(DBusGProxy *proxy,
}
void
-xfdesktop_file_utils_open_folder(const ThunarVfsInfo *info,
+xfdesktop_file_utils_open_folder(const XfdesktopFileIcon *icon,
GdkScreen *screen,
GtkWindow *parent)
{
DBusGProxy *fileman_proxy;
- g_return_if_fail(info && (screen || parent));
+ g_return_if_fail(XFDESKTOP_IS_FILE_ICON(icon) && (screen || parent));
+ g_return_if_fail(G_IS_FILE(icon->gfile));
if(!screen)
screen = gtk_widget_get_screen(GTK_WIDGET(parent));
@@ -414,10 +654,10 @@ xfdesktop_file_utils_open_folder(const ThunarVfsInfo *info,
fileman_proxy = xfdesktop_file_utils_peek_filemanager_proxy();
if(fileman_proxy) {
XfdesktopDisplayFolderData *dfdata = g_new(XfdesktopDisplayFolderData, 1);
- gchar *uri = thunar_vfs_path_dup_uri(info->path);
+ gchar *uri = g_file_get_uri(icon->gfile);
gchar *display_name = gdk_screen_make_display_name(screen);
- dfdata->info = info;
+ dfdata->icon = icon;
dfdata->screen = screen;
dfdata->parent = parent;
if(!org_xfce_FileManager_display_folder_async(fileman_proxy,
@@ -425,7 +665,7 @@ xfdesktop_file_utils_open_folder(const ThunarVfsInfo *info,
xfdesktop_file_utils_display_folder_cb,
dfdata))
{
- xfdesktop_file_utils_launch_fallback(info, screen, parent);
+ xfdesktop_file_utils_launch_fallback(icon, screen, parent);
g_free(dfdata);
} else
xfdesktop_file_utils_set_window_cursor(parent, GDK_WATCH);
@@ -433,7 +673,7 @@ xfdesktop_file_utils_open_folder(const ThunarVfsInfo *info,
g_free(uri);
g_free(display_name);
} else
- xfdesktop_file_utils_launch_fallback(info, screen, parent);
+ xfdesktop_file_utils_launch_fallback(icon, screen, parent);
}
@@ -517,10 +757,9 @@ gchar *
xfdesktop_thunarx_file_info_get_name(ThunarxFileInfo *file_info)
{
XfdesktopFileIcon *icon = XFDESKTOP_FILE_ICON(file_info);
- const ThunarVfsInfo *info = xfdesktop_file_icon_peek_info(icon);
- if(info)
- return g_strdup(thunar_vfs_path_get_name(info->path));
+ if(G_IS_FILE(icon->gfile))
+ return g_file_get_basename(icon->gfile);
else
return NULL;
}
@@ -529,38 +768,31 @@ gchar *
xfdesktop_thunarx_file_info_get_uri(ThunarxFileInfo *file_info)
{
XfdesktopFileIcon *icon = XFDESKTOP_FILE_ICON(file_info);
- const ThunarVfsInfo *info = xfdesktop_file_icon_peek_info(icon);
- gchar buf[PATH_MAX];
- if(!info)
- return NULL;
-
- if(thunar_vfs_path_to_uri(info->path, buf, PATH_MAX, NULL) <= 0)
+ if(G_IS_FILE(icon->gfile))
+ return g_file_get_uri(icon->gfile);
+ else
return NULL;
-
- return g_strdup(buf);
}
gchar *
xfdesktop_thunarx_file_info_get_parent_uri(ThunarxFileInfo *file_info)
{
XfdesktopFileIcon *icon = XFDESKTOP_FILE_ICON(file_info);
- const ThunarVfsInfo *info = xfdesktop_file_icon_peek_info(icon);
- ThunarVfsPath *parent;
- gchar buf[PATH_MAX];
-
- if(!info)
- return NULL;
-
- parent = thunar_vfs_path_get_parent(info->path);
-
- if(G_UNLIKELY(!parent))
- return NULL;
-
- if(thunar_vfs_path_to_uri(parent, buf, PATH_MAX, NULL) <= 0)
- return NULL;
-
- return g_strdup(buf);
+ GFile *parent;
+ gchar *uri = NULL;
+
+ g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), NULL);
+ g_return_val_if_fail(G_IS_FILE(icon->gfile), NULL);
+
+ parent = g_file_get_parent(icon->gfile);
+ if (parent != NULL)
+ {
+ uri = g_file_get_uri(parent);
+ g_object_unref(parent);
+ }
+
+ return uri;
}
gchar *
@@ -573,12 +805,11 @@ gchar *
xfdesktop_thunarx_file_info_get_mime_type(ThunarxFileInfo *file_info)
{
XfdesktopFileIcon *icon = XFDESKTOP_FILE_ICON(file_info);
- const ThunarVfsInfo *info = xfdesktop_file_icon_peek_info(icon);
- if(!info || !info->mime_info)
- return NULL;
+ g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), NULL);
+ g_return_val_if_fail(G_IS_FILE_INFO(icon->info), NULL);
- return g_strdup(thunar_vfs_mime_info_get_name(info->mime_info));
+ return g_strdup(g_file_info_get_content_type(icon->info));
}
gboolean
@@ -586,47 +817,52 @@ xfdesktop_thunarx_file_info_has_mime_type(ThunarxFileInfo *file_info,
const gchar *mime_type)
{
XfdesktopFileIcon *icon = XFDESKTOP_FILE_ICON(file_info);
- const ThunarVfsInfo *info = xfdesktop_file_icon_peek_info(icon);
- ThunarVfsMimeDatabase *mime_db;
- GList *mime_infos, *l;
- ThunarVfsMimeInfo *minfo;
- gboolean has_type = FALSE;
-
- if(!info || !info->mime_info)
- return FALSE;
-
- mime_db = thunar_vfs_mime_database_get_default();
-
- mime_infos = thunar_vfs_mime_database_get_infos_for_info(mime_db,
- info->mime_info);
- for(l = mime_infos; l; l = l->next) {
- minfo = (ThunarVfsMimeInfo *)l->data;
- if(!g_ascii_strcasecmp(mime_type, thunar_vfs_mime_info_get_name(minfo))) {
- has_type = TRUE;
- break;
- }
- }
- thunar_vfs_mime_info_list_free(mime_infos);
-
- g_object_unref(G_OBJECT(mime_db));
-
- return has_type;
+
+ g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), FALSE);
+ g_return_val_if_fail(G_IS_FILE_INFO(icon->info), FALSE);
+
+ return g_content_type_is_a(g_file_info_get_content_type(icon->info), mime_type);
}
gboolean
xfdesktop_thunarx_file_info_is_directory(ThunarxFileInfo *file_info)
{
+ return xfdesktop_file_utils_is_directory(XFDESKTOP_FILE_ICON(file_info));
+}
+
+GFileInfo *
+xfdesktop_thunarx_file_info_get_file_info(ThunarxFileInfo *file_info)
+{
XfdesktopFileIcon *icon = XFDESKTOP_FILE_ICON(file_info);
- const ThunarVfsInfo *info = xfdesktop_file_icon_peek_info(icon);
- return (info && info->type == THUNAR_VFS_FILE_TYPE_DIRECTORY);
+
+ g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), NULL);
+ g_return_val_if_fail(G_IS_FILE_INFO(icon->info), NULL);
+
+ return g_object_ref(icon->info);
+}
+
+GFileInfo *
+xfdesktop_thunarx_file_info_get_filesystem_info(ThunarxFileInfo*file_info)
+{
+ XfdesktopFileIcon *icon = XFDESKTOP_FILE_ICON(file_info);
+
+ g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), NULL);
+ g_return_val_if_fail(G_IS_FILE(icon->gfile), NULL);
+
+ return g_file_query_filesystem_info(icon->gfile,
+ "filesystem::*",
+ NULL, NULL);
}
-ThunarVfsInfo *
-xfdesktop_thunarx_file_info_get_vfs_info(ThunarxFileInfo *file_info)
+GFile *
+xfdesktop_thunarx_file_info_get_location(ThunarxFileInfo *file_info)
{
XfdesktopFileIcon *icon = XFDESKTOP_FILE_ICON(file_info);
- const ThunarVfsInfo *info = xfdesktop_file_icon_peek_info(icon);
- return info ? thunar_vfs_info_copy(info) : NULL;
+
+ g_return_val_if_fail(XFDESKTOP_IS_FILE_ICON(icon), NULL);
+ g_return_val_if_fail(G_IS_FILE(icon->gfile), NULL);
+
+ return g_object_ref(icon->gfile);
}
#endif /* HAVE_THUNARX */
diff --git a/src/xfdesktop-file-utils.h b/src/xfdesktop-file-utils.h
index d88c299..c325139 100644
--- a/src/xfdesktop-file-utils.h
+++ b/src/xfdesktop-file-utils.h
@@ -21,7 +21,7 @@
#ifndef __XFDESKTOP_FILE_UTILS_H__
#define __XFDESKTOP_FILE_UTILS_H__
-#include <thunar-vfs/thunar-vfs.h>
+#include <gio/gio.h>
#include <dbus/dbus-glib.h>
#ifdef HAVE_THUNARX
@@ -29,10 +29,11 @@
#endif
#include "xfdesktop-file-icon.h"
+#include "xfdesktop-job.h"
-ThunarVfsInteractiveJobResponse xfdesktop_file_utils_interactive_job_ask(GtkWindow *parent,
- const gchar *message,
- ThunarVfsInteractiveJobResponse choices);
+XfdesktopJobResponse xfdesktop_file_utils_interactive_job_ask(GtkWindow *parent,
+ const gchar *message,
+ XfdesktopJobResponse choices);
typedef enum
{
@@ -42,19 +43,43 @@ typedef enum
} XfdesktopFileUtilsFileop;
void xfdesktop_file_utils_handle_fileop_error(GtkWindow *parent,
- const ThunarVfsInfo *src_info,
- const ThunarVfsInfo *dest_info,
+ const XfdesktopFileIcon *src_icon,
+ const XfdesktopFileIcon *dest_icon,
XfdesktopFileUtilsFileop fileop,
GError *error);
+#if 0
+/* The implementation of both functions are already commented on "master" */
void xfdesktop_file_utils_copy_into(GtkWindow *parent,
GList *path_list,
ThunarVfsPath *dest_path);
void xfdesktop_file_utils_move_into(GtkWindow *parent,
GList *path_list,
ThunarVfsPath *dest_path);
+#endif
+
+GFileInfo *xfdesktop_file_utils_get_file_info(GFile *gfile,
+ GCancellable *cancellable);
+
+gchar *xfdesktop_file_utils_get_file_date(const XfdesktopFileIcon *icon,
+ const gchar *attr);
+
+guint64 xfdesktop_file_utils_get_file_size(const XfdesktopFileIcon *icon,
+ gchar **humanized_size);
+
+gboolean xfdesktop_file_utils_is_directory(const XfdesktopFileIcon *icon);
+gboolean xfdesktop_file_utils_is_symlink(const XfdesktopFileIcon *icon);
+gboolean xfdesktop_file_utils_is_executable(const XfdesktopFileIcon *icon);
+gboolean xfdesktop_file_utils_is_readable(const XfdesktopFileIcon *icon);
+gboolean xfdesktop_file_utils_is_writable(const XfdesktopFileIcon *icon);
+gboolean xfdesktop_file_utils_is_desktop_file(const XfdesktopFileIcon *icon);
+gboolean xfdesktop_file_utils_is_root(const XfdesktopFileIcon *icon);
+gboolean xfdesktop_file_utils_is_hidden(const XfdesktopFileIcon *icon);
+
+gboolean xfdesktop_file_utils_can_rename(const XfdesktopFileIcon *icon);
+gboolean xfdesktop_file_utils_can_delete(const XfdesktopFileIcon *icon);
-gchar *xfdesktop_file_utils_get_file_kind(const ThunarVfsInfo *info,
+gchar *xfdesktop_file_utils_get_file_kind(const XfdesktopFileIcon *icon,
gboolean *is_link);
GList *xfdesktop_file_utils_file_icon_list_to_path_list(GList *icon_list);
@@ -62,7 +87,7 @@ GList *xfdesktop_file_utils_file_icon_list_to_path_list(GList *icon_list);
GdkPixbuf *xfdesktop_file_utils_get_fallback_icon(gint size);
GdkPixbuf *xfdesktop_file_utils_get_file_icon(const gchar *custom_icon_name,
- ThunarVfsInfo *info,
+ const XfdesktopFileIcon *icon,
gint size,
const GdkPixbuf *emblem,
guint opacity);
@@ -70,11 +95,11 @@ GdkPixbuf *xfdesktop_file_utils_get_file_icon(const gchar *custom_icon_name,
void xfdesktop_file_utils_set_window_cursor(GtkWindow *window,
GdkCursorType cursor_type);
-gboolean xfdesktop_file_utils_launch_fallback(const ThunarVfsInfo *info,
+gboolean xfdesktop_file_utils_launch_fallback(const XfdesktopFileIcon *icon,
GdkScreen *screen,
GtkWindow *parent);
-void xfdesktop_file_utils_open_folder(const ThunarVfsInfo *info,
+void xfdesktop_file_utils_open_folder(const XfdesktopFileIcon *icon,
GdkScreen *screen,
GtkWindow *parent);
@@ -95,7 +120,9 @@ gchar *xfdesktop_thunarx_file_info_get_mime_type(ThunarxFileInfo *file_info);
gboolean xfdesktop_thunarx_file_info_has_mime_type(ThunarxFileInfo *file_info,
const gchar *mime_type);
gboolean xfdesktop_thunarx_file_info_is_directory(ThunarxFileInfo *file_info);
-ThunarVfsInfo *xfdesktop_thunarx_file_info_get_vfs_info(ThunarxFileInfo *file_info);
+GFileInfo *xfdesktop_thunarx_file_info_get_file_info(ThunarxFileInfo *file_info);
+GFileInfo *xfdesktop_thunarx_file_info_get_filesystem_info(ThunarxFileInfo*file_info);
+GFile *xfdesktop_thunarx_file_info_get_location(ThunarxFileInfo *file_info);
#endif
#endif
More information about the Xfce4-commits
mailing list