[Xfce4-commits] <thunar-archive-plugin:master> Port the plugin to thunarx-2 (bug #6093).
Jannis Pohlmann
noreply at xfce.org
Sun Jan 23 14:44:02 CET 2011
Updating branch refs/heads/master
to 9db1286acb8c2f82457ebec14f4ab2d9332edf8a (commit)
from d1d69622f1398979bdd176a1b908a3343293e5b6 (commit)
commit 9db1286acb8c2f82457ebec14f4ab2d9332edf8a
Author: Jannis Pohlmann <jannis at xfce.org>
Date: Sun Jan 23 14:40:04 2011 +0100
Port the plugin to thunarx-2 (bug #6093).
This was a joint effort by Peter de Ridder, Samuli Suominen and Romain
Bouvier. A new release will follow shortly.
configure.in.in | 6 +-
thunar-archive-plugin/Makefile.am | 5 +-
thunar-archive-plugin/tap-backend.c | 158 ++++++++++++++++-----------------
thunar-archive-plugin/tap-provider.c | 83 ++++++------------
4 files changed, 113 insertions(+), 139 deletions(-)
diff --git a/configure.in.in b/configure.in.in
index 3fd2fcc..0a1a6a8 100644
--- a/configure.in.in
+++ b/configure.in.in
@@ -68,8 +68,10 @@ XDT_I18N([@LINGUAS@])
dnl ***********************************
dnl *** Check for required packages ***
dnl ***********************************
-XDT_CHECK_PACKAGE([THUNARX], [thunarx-1], [0.4.0])
-XDT_CHECK_PACKAGE([THUNAR_VFS], [thunar-vfs-1], [0.4.0])
+XDT_CHECK_PACKAGE([THUNARX], [thunarx-2], [0.4.0])
+XDT_CHECK_PACKAGE([EXO], [exo-1], [0.5.0])
+XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.6.0])
+dnl XDT_CHECK_PACKAGE([THUNAR_VFS], [thunar-vfs-1], [0.4.0])
dnl ***********************************
dnl *** Check for debugging support ***
diff --git a/thunar-archive-plugin/Makefile.am b/thunar-archive-plugin/Makefile.am
index 59afdd1..4cbfefa 100644
--- a/thunar-archive-plugin/Makefile.am
+++ b/thunar-archive-plugin/Makefile.am
@@ -9,7 +9,7 @@ INCLUDES = \
-DPACKAGE_LOCALE_DIR=\"$(localedir)\" \
$(PLATFORM_CPPFLAGS)
-extensionsdir = $(libdir)/thunarx-1
+extensionsdir = $(libdir)/thunarx-2
extensions_LTLIBRARIES = \
thunar-archive-plugin.la
@@ -23,7 +23,8 @@ thunar_archive_plugin_la_SOURCES = \
thunar_archive_plugin_la_CFLAGS = \
$(PLATFORM_CFLAGS) \
$(THUNARX_CFLAGS) \
- $(THUNAR_VFS_CFLAGS)
+ $(EXO_CFLAGS) \
+ $(LIBXFCE4UTIL_CFLAGS)
thunar_archive_plugin_la_LDFLAGS = \
-avoid-version \
diff --git a/thunar-archive-plugin/tap-backend.c b/thunar-archive-plugin/tap-backend.c
index 883a953..e457c64 100644
--- a/thunar-archive-plugin/tap-backend.c
+++ b/thunar-archive-plugin/tap-backend.c
@@ -29,36 +29,36 @@
#include <string.h>
#endif
-#include <thunar-vfs/thunar-vfs.h>
-
+#include <exo/exo.h>
#include <thunar-archive-plugin/tap-backend.h>
-static ThunarVfsMimeApplication *tap_backend_mime_ask (GList *mime_applications,
- GtkWidget *parent);
-static GList *tap_backend_mime_applications (ThunarVfsMimeDatabase *mime_database,
- GList *mime_infos);
-static ThunarVfsMimeApplication *tap_backend_mime_application (GList *mime_infos,
- GtkWidget *window,
- GError **error);
-static gchar *tap_backend_mime_wrapper (ThunarVfsMimeApplication *mime_application) G_GNUC_MALLOC;
-static GPid tap_backend_run (const gchar *action,
- const gchar *folder,
- GList *files,
- GList *mime_infos,
- GtkWidget *window,
- GError **error);
+static GAppInfo *tap_backend_mime_ask (GList *mime_applications,
+ GtkWidget *parent);
+static gint tap_backend_mime_application_compare (GAppInfo *a,
+ GAppInfo *b);
+static GList *tap_backend_mime_applications (GList *content_types);
+static GAppInfo *tap_backend_mime_application (GList *content_types,
+ GtkWidget *window,
+ GError **error);
+static gchar *tap_backend_mime_wrapper (GAppInfo *mime_application) G_GNUC_MALLOC;
+static GPid tap_backend_run (const gchar *action,
+ const gchar *folder,
+ GList *files,
+ GList *content_types,
+ GtkWidget *window,
+ GError **error);
-static ThunarVfsMimeApplication*
+static GAppInfo*
tap_backend_mime_ask (GList *mime_applications,
GtkWidget *parent)
{
- ThunarVfsMimeApplication *mime_application = NULL;
+ GAppInfo *mime_application = NULL;
GtkIconTheme *icon_theme;
- const gchar *icon_name;
+ GIcon *icon;
GtkTooltips *tooltips;
GtkWidget *button;
GtkWidget *dialog;
@@ -78,7 +78,7 @@ tap_backend_mime_ask (GList *mime_applications,
/* allocate tooltips */
tooltips = gtk_tooltips_new ();
- exo_gtk_object_ref_sink (GTK_OBJECT (tooltips));
+ g_object_ref_sink (tooltips);
/* prepare the dialog to query the preferred archiver for the user */
dialog = gtk_dialog_new_with_buttons (_("Select an archive manager"),
@@ -127,7 +127,7 @@ tap_backend_mime_ask (GList *mime_applications,
gtk_widget_show (button);
/* set the command as tooltip, as some archive manager's names are not very useful */
- command = g_strdup (thunar_vfs_mime_handler_get_command (THUNAR_VFS_MIME_HANDLER (mp->data)));
+ command = g_strdup (g_app_info_get_executable (mp->data));
space = strchr (command, ' ');
if (G_LIKELY (space != NULL))
*space = '\0';
@@ -140,17 +140,17 @@ tap_backend_mime_ask (GList *mime_applications,
gtk_widget_show (hbox);
/* check if we have an icon for the application */
- icon_name = thunar_vfs_mime_handler_lookup_icon_name (THUNAR_VFS_MIME_HANDLER (mp->data), icon_theme);
- if (G_LIKELY (icon_name != NULL))
+ icon = g_app_info_get_icon (mp->data);
+ if (G_LIKELY (icon != NULL))
{
/* add an image */
- image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
+ image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU);
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
gtk_widget_show (image);
}
/* add the label for the application */
- label = gtk_label_new (thunar_vfs_mime_application_get_name (mp->data));
+ label = gtk_label_new (g_app_info_get_name (mp->data));
gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f);
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
gtk_widget_show (label);
@@ -178,9 +178,17 @@ tap_backend_mime_ask (GList *mime_applications,
+static gint
+tap_backend_mime_application_compare (GAppInfo *a,
+ GAppInfo *b)
+{
+ return g_app_info_equal (a, b)?0:1;
+}
+
+
+
static GList*
-tap_backend_mime_applications (ThunarVfsMimeDatabase *mime_database,
- GList *mime_infos)
+tap_backend_mime_applications (GList *content_types)
{
GList *mime_applications = NULL;
GList *list;
@@ -190,14 +198,14 @@ tap_backend_mime_applications (ThunarVfsMimeDatabase *mime_database,
gchar *s;
/* determine the set of applications that can handle all mime types */
- for (lp = mime_infos; lp != NULL; lp = lp->next)
+ for (lp = content_types; lp != NULL; lp = lp->next)
{
/* no need to check anything if this is the same mime type as the previous one */
if (lp->prev != NULL && lp->prev->data == lp->data)
continue;
/* determine the list of applications that can handle this mime type */
- list = thunar_vfs_mime_database_get_applications (mime_database, lp->data);
+ list = g_app_info_get_all_for_type (lp->data);
if (G_UNLIKELY (mime_applications == NULL))
{
/* first file, so just use the applications list */
@@ -212,7 +220,7 @@ tap_backend_mime_applications (ThunarVfsMimeDatabase *mime_database,
next = ap->next;
/* check if the application is present in list */
- if (g_list_find (list, ap->data) == NULL)
+ if (g_list_find_custom (list, ap->data, (GCompareFunc) tap_backend_mime_application_compare) == NULL)
{
/* drop our reference on the application */
g_object_unref (G_OBJECT (ap->data));
@@ -256,24 +264,19 @@ tap_backend_mime_applications (ThunarVfsMimeDatabase *mime_database,
-static ThunarVfsMimeApplication*
-tap_backend_mime_application (GList *mime_infos,
+static GAppInfo*
+tap_backend_mime_application (GList *content_types,
GtkWidget *window,
GError **error)
{
- ThunarVfsMimeApplication *mime_application = NULL;
- ThunarVfsMimeDatabase *mime_database;
- const gchar * const *mime_types;
- ThunarVfsMimeInfo *mime_info;
+ GAppInfo *mime_application = NULL;
+ GAppInfo *app_info;
GError *err = NULL;
GList *mime_applications;
- guint n;
-
- /* grab a reference on the mime database */
- mime_database = thunar_vfs_mime_database_get_default ();
+ GList *lp;
/* determine the mime applications that can handle the mime types */
- mime_applications = tap_backend_mime_applications (mime_database, mime_infos);
+ mime_applications = tap_backend_mime_applications (content_types);
if (G_UNLIKELY (mime_applications == NULL))
{
/* tell the user that we cannot handle the specified mime types */
@@ -290,28 +293,29 @@ tap_backend_mime_application (GList *mime_infos,
/* more than one supported archive manager, check if the first
* available is the default for all its supported mime types.
*/
- mime_types = thunar_vfs_mime_application_get_mime_types (mime_applications->data);
- for (n = 0; mime_types[n] != NULL; ++n)
+ for (lp = content_types; lp != NULL; lp = lp->next)
{
/* determine the default application for this mime type */
- mime_info = thunar_vfs_mime_database_get_info (mime_database, mime_types[n]);
- mime_application = thunar_vfs_mime_database_get_default_application (mime_database, mime_info);
- thunar_vfs_mime_info_unref (mime_info);
+ app_info = g_app_info_get_default_for_type (lp->data, FALSE);
+
+ /* no default applications for this mime type */
+ if (app_info == NULL)
+ break;
/* check if our expected default application is also the default here */
- if (mime_applications->data != mime_application)
+ if (!g_app_info_equal (app_info, mime_applications->data))
{
/* no, have to ask the user */
- g_object_unref (G_OBJECT (mime_application));
+ g_object_unref (app_info);
break;
}
/* yep, next one please... */
- g_object_unref (G_OBJECT (mime_application));
+ g_object_unref (app_info);
}
/* check if we have found a suitable one */
- if (G_LIKELY (mime_types[n] == NULL))
+ if (G_LIKELY (lp == NULL))
{
/* use the first available archive manager */
mime_application = g_object_ref (G_OBJECT (mime_applications->data));
@@ -325,20 +329,17 @@ tap_backend_mime_application (GList *mime_infos,
/* make the selected application the default for all its
* supported mime types, so we don't need to ask once again.
*/
- mime_types = thunar_vfs_mime_application_get_mime_types (mime_application);
- for (n = 0; mime_types[n] != NULL; ++n)
+ for (lp = content_types; lp != NULL; lp = lp->next)
{
/* set the default application */
- mime_info = thunar_vfs_mime_database_get_info (mime_database, mime_types[n]);
- if (!thunar_vfs_mime_database_set_default_application (mime_database, mime_info, mime_application, &err))
+ if (!g_app_info_set_as_default_for_type (mime_application, lp->data, &err))
{
/* not critical, still we should tell the user that we failed */
g_warning ("Failed to make \"%s\" the default application for %s: %s",
- thunar_vfs_mime_application_get_name (mime_application),
- thunar_vfs_mime_info_get_name (mime_info), err->message);
+ g_app_info_get_name (mime_application),
+ (char*) lp->data, err->message);
g_clear_error (&err);
}
- thunar_vfs_mime_info_unref (mime_info);
}
}
}
@@ -348,16 +349,13 @@ tap_backend_mime_application (GList *mime_infos,
g_list_free (mime_applications);
}
- /* release our reference on the mime database */
- g_object_unref (G_OBJECT (mime_database));
-
return mime_application;
}
static gchar*
-tap_backend_mime_wrapper (ThunarVfsMimeApplication *mime_application)
+tap_backend_mime_wrapper (GAppInfo *mime_application)
{
const gchar *desktop_id;
gchar *basename;
@@ -365,7 +363,7 @@ tap_backend_mime_wrapper (ThunarVfsMimeApplication *mime_application)
gchar *dot;
/* determine the basename of the .desktop file */
- desktop_id = thunar_vfs_mime_application_get_desktop_id (mime_application);
+ desktop_id = g_app_info_get_id (mime_application);
basename = g_path_get_basename (desktop_id);
dot = strrchr (basename, '.');
if (G_LIKELY (dot != NULL))
@@ -394,12 +392,12 @@ static GPid
tap_backend_run (const gchar *action,
const gchar *folder,
GList *files,
- GList *mime_infos,
+ GList *content_types,
GtkWidget *window,
GError **error)
{
- ThunarVfsMimeApplication *mime_application;
- ThunarVfsInfo *info;
+ GAppInfo *mime_application;
+ gchar *mime_type;
GdkScreen *screen;
gchar *wrapper;
gchar **argv;
@@ -409,19 +407,19 @@ tap_backend_run (const gchar *action,
gint n;
/* determine the mime infos on-demand */
- if (G_LIKELY (mime_infos == NULL))
+ if (G_LIKELY (content_types == NULL))
{
/* determine the mime infos from the files */
for (lp = files; lp != NULL; lp = lp->next)
{
- info = thunarx_file_info_get_vfs_info (THUNARX_FILE_INFO (lp->data));
- mime_infos = g_list_append (mime_infos, thunar_vfs_mime_info_ref (info->mime_info));
- thunar_vfs_info_unref (info);
+ mime_type = thunarx_file_info_get_mime_type (THUNARX_FILE_INFO (lp->data));
+ content_types = g_list_append (content_types, g_content_type_from_mime_type (mime_type));
+ g_free (mime_type);
}
}
/* determine the mime application to use */
- mime_application = tap_backend_mime_application (mime_infos, window, error);
+ mime_application = tap_backend_mime_application (content_types, window, error);
if (G_LIKELY (mime_application != NULL))
{
/* determine the wrapper script for the application */
@@ -463,7 +461,8 @@ tap_backend_run (const gchar *action,
}
/* cleanup */
- thunar_vfs_mime_info_list_free (mime_infos);
+ g_list_foreach (content_types, (GFunc) g_free, NULL);
+ g_list_free (content_types);
return pid;
}
@@ -493,24 +492,21 @@ tap_backend_create_archive (const gchar *folder,
GtkWidget *window,
GError **error)
{
- ThunarVfsMimeDatabase *mime_database;
- GList *mime_infos = NULL;
+ GList *content_types = NULL;
g_return_val_if_fail (files != NULL, -1);
g_return_val_if_fail (GTK_IS_WINDOW (window), -1);
g_return_val_if_fail (g_path_is_absolute (folder), -1);
g_return_val_if_fail (error == NULL || *error == NULL, -1);
- /* determine the mime infos for zip and tar files (all supported archives must be able to handle them) */
- mime_database = thunar_vfs_mime_database_get_default ();
- mime_infos = g_list_append (mime_infos, thunar_vfs_mime_database_get_info (mime_database, "application/x-compressed-tar"));
- mime_infos = g_list_append (mime_infos, thunar_vfs_mime_database_get_info (mime_database, "application/x-tar"));
- mime_infos = g_list_append (mime_infos, thunar_vfs_mime_database_get_info (mime_database, "application/x-zip"));
- mime_infos = g_list_append (mime_infos, thunar_vfs_mime_database_get_info (mime_database, "application/zip"));
- g_object_unref (G_OBJECT (mime_database));
+ /* determine the content types for zip and tar files (all supported archives must be able to handle them) */
+ content_types = g_list_append (content_types, g_content_type_from_mime_type ("application/x-compressed-tar"));
+ content_types = g_list_append (content_types, g_content_type_from_mime_type ("application/x-tar"));
+ content_types = g_list_append (content_types, g_content_type_from_mime_type ("application/x-zip"));
+ content_types = g_list_append (content_types, g_content_type_from_mime_type ("application/zip"));
/* run the action, the mime infos will be freed by the _run() method */
- return tap_backend_run ("create", folder, files, mime_infos, window, error);
+ return tap_backend_run ("create", folder, files, content_types, window, error);
}
diff --git a/thunar-archive-plugin/tap-provider.c b/thunar-archive-plugin/tap-provider.c
index f298f8d..8cd2a44 100644
--- a/thunar-archive-plugin/tap-provider.c
+++ b/thunar-archive-plugin/tap-provider.c
@@ -26,7 +26,7 @@
#include <unistd.h>
#endif
-#include <thunar-vfs/thunar-vfs.h>
+#include <libxfce4util/libxfce4util.h>
#include <thunar-archive-plugin/tap-backend.h>
#include <thunar-archive-plugin/tap-provider.h>
@@ -85,12 +85,11 @@ struct _TapProvider
GtkIconFactory *icon_factory;
#endif
- /* child watch support for the last spawn command,
- * which allows us to refresh the folder contents
- * after the command terminates (i.e. the archive
- * is created).
+ /* child watch support for the last spawn command, which allowed us to refresh
+ * the folder contents after the command had terminated with ThunarVFS (i.e.
+ * when the archive had been created). This no longer works with GIO but
+ * we still use the watch to close the PID properly.
*/
- gchar *child_watch_path;
gint child_watch_id;
};
@@ -221,7 +220,6 @@ tap_provider_finalize (GObject *object)
{
/* reset the callback function to g_spawn_close_pid() so the plugin can be
* safely unloaded and the child will still not become a zombie afterwards.
- * This also resets the child_watch_id and child_watch_path properties.
*/
source = g_main_context_find_source_by_id (NULL, tap_provider->child_watch_id);
g_source_set_callback (source, (GSourceFunc) g_spawn_close_pid, NULL, NULL);
@@ -420,8 +418,7 @@ tap_provider_get_file_actions (ThunarxMenuProvider *menu_provider,
GtkWidget *window,
GList *files)
{
- ThunarVfsPathScheme scheme;
- ThunarVfsInfo *info;
+ gchar *scheme;
TapProvider *tap_provider = TAP_PROVIDER (menu_provider);
GtkAction *action;
GClosure *closure;
@@ -435,13 +432,15 @@ tap_provider_get_file_actions (ThunarxMenuProvider *menu_provider,
for (lp = files; lp != NULL; lp = lp->next, ++n_files)
{
/* check if the file is a local file */
- info = thunarx_file_info_get_vfs_info (lp->data);
- scheme = thunar_vfs_path_get_scheme (info->path);
- thunar_vfs_info_unref (info);
+ scheme = thunarx_file_info_get_uri_scheme (lp->data);
/* unable to handle non-local files */
- if (G_UNLIKELY (scheme != THUNAR_VFS_PATH_SCHEME_FILE))
- return NULL;
+ if (G_UNLIKELY (strcmp (scheme, "file")))
+ {
+ g_free (scheme);
+ return NULL;
+ }
+ g_free (scheme);
/* check if this file is a supported archive */
if (all_archives && !tap_is_archive (lp->data))
@@ -548,8 +547,7 @@ tap_provider_get_dnd_actions (ThunarxMenuProvider *menu_provider,
ThunarxFileInfo *folder,
GList *files)
{
- ThunarVfsPathScheme scheme;
- ThunarVfsInfo *info;
+ gchar *scheme;
TapProvider *tap_provider = TAP_PROVIDER (menu_provider);
GtkAction *action;
GClosure *closure;
@@ -557,25 +555,29 @@ tap_provider_get_dnd_actions (ThunarxMenuProvider *menu_provider,
gint n_files = 0;
/* check if the folder is a local folder */
- info = thunarx_file_info_get_vfs_info (folder);
- scheme = thunar_vfs_path_get_scheme (info->path);
- thunar_vfs_info_unref (info);
+ scheme = thunarx_file_info_get_uri_scheme (folder);
/* unable to extract to non-local folders */
- if (G_UNLIKELY (scheme != THUNAR_VFS_PATH_SCHEME_FILE))
- return NULL;
+ if (G_UNLIKELY (strcmp (scheme, "file")))
+ {
+ g_free (scheme);
+ return NULL;
+ }
+ g_free (scheme);
/* check all supplied files */
for (lp = files; lp != NULL; lp = lp->next, ++n_files)
{
/* check if the file is a local file */
- info = thunarx_file_info_get_vfs_info (lp->data);
- scheme = thunar_vfs_path_get_scheme (info->path);
- thunar_vfs_info_unref (info);
+ scheme = thunarx_file_info_get_uri_scheme (lp->data);
/* unable to handle non-local files */
- if (G_UNLIKELY (scheme != THUNAR_VFS_PATH_SCHEME_FILE))
- return NULL;
+ if (G_UNLIKELY (strcmp (scheme, "file")))
+ {
+ g_free (scheme);
+ return NULL;
+ }
+ g_free (scheme);
/* check if this file is a supported archive */
if (G_LIKELY (!tap_is_archive (lp->data)))
@@ -649,10 +651,6 @@ tap_provider_execute (TapProvider *tap_provider,
/* schedule the new child watch */
tap_provider->child_watch_id = g_child_watch_add_full (G_PRIORITY_LOW, pid, tap_provider_child_watch,
tap_provider, tap_provider_child_watch_destroy);
-
-
- /* remember the working directory for the child watch */
- tap_provider->child_watch_path = g_strdup (folder);
}
else if (error != NULL)
{
@@ -677,29 +675,8 @@ tap_provider_child_watch (GPid pid,
gint status,
gpointer user_data)
{
- ThunarVfsMonitor *monitor;
- ThunarVfsPath *path;
- TapProvider *tap_provider = TAP_PROVIDER (user_data);
-
GDK_THREADS_ENTER ();
- /* verify that we still have a valid child_watch_path */
- if (G_LIKELY (tap_provider->child_watch_path != NULL))
- {
- /* determine the corresponding ThunarVfsPath */
- path = thunar_vfs_path_new (tap_provider->child_watch_path, NULL);
- if (G_LIKELY (path != NULL))
- {
- /* schedule a changed notification on the path */
- monitor = thunar_vfs_monitor_get_default ();
- thunar_vfs_monitor_feed (monitor, THUNAR_VFS_MONITOR_EVENT_CHANGED, path);
- g_object_unref (G_OBJECT (monitor));
-
- /* release the ThunarVfsPath */
- thunar_vfs_path_unref (path);
- }
- }
-
/* need to cleanup */
g_spawn_close_pid (pid);
@@ -713,9 +690,7 @@ tap_provider_child_watch_destroy (gpointer user_data)
{
TapProvider *tap_provider = TAP_PROVIDER (user_data);
- /* reset child watch id and path */
- g_free (tap_provider->child_watch_path);
- tap_provider->child_watch_path = NULL;
+ /* reset child watch id */
tap_provider->child_watch_id = 0;
}
More information about the Xfce4-commits
mailing list