[Xfce4-commits] <xfdesktop:master> Use Thunar's Launch() D-Bus method when an icon is activated.
Jannis Pohlmann
noreply at xfce.org
Tue Nov 2 01:14:16 CET 2010
Updating branch refs/heads/master
to b18fc4359e7d73f7222be454dbf84abfabf64894 (commit)
from 357e747c045ea07d6b5b14d9c3dfea58841cf62a (commit)
commit b18fc4359e7d73f7222be454dbf84abfabf64894
Author: Jannis Pohlmann <jannis at xfce.org>
Date: Tue Oct 19 15:07:46 2010 +0200
Use Thunar's Launch() D-Bus method when an icon is activated.
Alternatively, use xfdesktop_file_utils_open_folder() when the icon
refers to a directory.
src/xfdesktop-file-icon.c | 54 ++++----------------------------------
src/xfdesktop-file-utils.c | 62 ++++++++++++++++++++++++++++++++++++++++++++
src/xfdesktop-file-utils.h | 3 ++
3 files changed, 71 insertions(+), 48 deletions(-)
diff --git a/src/xfdesktop-file-icon.c b/src/xfdesktop-file-icon.c
index cc01713..78eb518 100644
--- a/src/xfdesktop-file-icon.c
+++ b/src/xfdesktop-file-icon.c
@@ -100,11 +100,10 @@ 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);
+ GFileInfo *info = xfdesktop_file_icon_peek_file_info(file_icon);
GFile *file = xfdesktop_file_icon_peek_file(file_icon);
GtkWidget *icon_view, *toplevel;
GdkScreen *gscreen;
- gboolean success = FALSE;
TRACE("entering");
@@ -114,54 +113,13 @@ xfdesktop_file_icon_activated(XfdesktopIcon *icon)
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) {
+
+ if(g_file_info_get_file_type(info) == G_FILE_TYPE_DIRECTORY)
xfdesktop_file_utils_open_folder(file, gscreen, GTK_WINDOW(toplevel));
- success = TRUE;
- } else {
- if(info->flags & THUNAR_VFS_FILE_FLAGS_EXECUTABLE) {
- success = thunar_vfs_info_execute(info, gscreen, NULL,
- xfce_get_homedir(), NULL);
- }
-
- 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);
- if(!success) {
- gchar *primary = g_markup_printf_escaped(_("Unable to launch \"%s\":"),
- info->display_name);
- 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);
- } else {
- success = xfdesktop_file_utils_launch_fallback(info,
- gscreen,
- GTK_WINDOW(toplevel));
- }
-
- g_object_unref(G_OBJECT(mime_database));
- }
- }
+ else
+ xfdesktop_file_utils_launch(file, gscreen, GTK_WINDOW(toplevel));
- return success;
+ return TRUE;
}
diff --git a/src/xfdesktop-file-utils.c b/src/xfdesktop-file-utils.c
index 7668d12..d7059eb 100644
--- a/src/xfdesktop-file-utils.c
+++ b/src/xfdesktop-file-utils.c
@@ -658,6 +658,68 @@ xfdesktop_file_utils_show_properties_dialog(GFile *file,
}
}
+static void
+xfdesktop_file_utils_launch_cb(DBusGProxy *proxy,
+ GError *error,
+ gpointer user_data)
+{
+ GtkWindow *parent = user_data;
+
+ if(error) {
+ xfce_message_dialog(parent,
+ _("Launch Error"), GTK_STOCK_DIALOG_ERROR,
+ _("The file could not be opened"),
+ _("This feature requires a file manager service to "
+ "be present (such as the one supplied by Thunar)."),
+ GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
+ }
+}
+
+void
+xfdesktop_file_utils_launch(GFile *file,
+ GdkScreen *screen,
+ GtkWindow *parent)
+{
+ DBusGProxy *fileman_proxy;
+
+ g_return_if_fail(G_IS_FILE(file));
+ g_return_if_fail(GDK_IS_SCREEN(screen) || GTK_IS_WINDOW(parent));
+
+ if(!screen)
+ screen = gtk_widget_get_screen(GTK_WIDGET(parent));
+
+ fileman_proxy = xfdesktop_file_utils_peek_filemanager_proxy();
+ if(fileman_proxy) {
+ gchar *uri = g_file_get_uri(file);
+ gchar *display_name = gdk_screen_make_display_name(screen);
+ gchar *startup_id = g_strdup_printf("_TIME%d", gtk_get_current_event_time());
+
+ if(!xfdesktop_file_manager_proxy_launch_async(fileman_proxy,
+ uri, display_name, startup_id,
+ xfdesktop_file_utils_launch_cb,
+ parent))
+ {
+ xfce_message_dialog(parent,
+ _("Launch Error"), GTK_STOCK_DIALOG_ERROR,
+ _("The file could not be opened"),
+ _("This feature requires a file manager service to "
+ "be present (such as the one supplied by Thunar)."),
+ GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
+ }
+
+ g_free(startup_id);
+ g_free(uri);
+ g_free(display_name);
+ } else {
+ xfce_message_dialog(parent,
+ _("Launch Error"), GTK_STOCK_DIALOG_ERROR,
+ _("The file could not be opened"),
+ _("This feature requires a file manager service to "
+ "be present (such as the one supplied by Thunar)."),
+ GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
+ }
+}
+
static gint dbus_ref_cnt = 0;
static DBusGConnection *dbus_gconn = NULL;
static DBusGProxy *dbus_trash_proxy = NULL;
diff --git a/src/xfdesktop-file-utils.h b/src/xfdesktop-file-utils.h
index 8b56756..d437635 100644
--- a/src/xfdesktop-file-utils.h
+++ b/src/xfdesktop-file-utils.h
@@ -90,6 +90,9 @@ void xfdesktop_file_utils_create_file(GFile *parent_folder,
void xfdesktop_file_utils_show_properties_dialog(GFile *file,
GdkScreen *screen,
GtkWindow *parent);
+void xfdesktop_file_utils_launch(GFile *file,
+ GdkScreen *screen,
+ GtkWindow *parent);
gboolean xfdesktop_file_utils_dbus_init(void);
More information about the Xfce4-commits
mailing list