[Xfce4-commits] r29113 - in thunar/branches/port-to-gio: . thunar
Jannis Pohlmann
jannis at xfce.org
Wed Jan 7 04:00:03 CET 2009
Author: jannis
Date: 2009-01-07 03:00:03 +0000 (Wed, 07 Jan 2009)
New Revision: 29113
Modified:
thunar/branches/port-to-gio/ChangeLog
thunar/branches/port-to-gio/thunar/thunar-folder.c
thunar/branches/port-to-gio/thunar/thunar-preferences.c
thunar/branches/port-to-gio/thunar/thunar-window.c
Log:
* thunar/thunar-folder.c, thunar/thunar-preferences.c: Make
ThunarFolder and ThunarPreferences use GFileMonitor instead of
ThunarVfsMonitor.
* thunar/thunar-window.c: Remove code for GLib versions < 2.14 from
thunar_window_setup_user_dir_menu_entries() and
thunar_window_open_user_folder(). Implement more functions based on
GIO: thunar_window_action_open_home() and
thunar_window_action_open_trash().
Modified: thunar/branches/port-to-gio/ChangeLog
===================================================================
--- thunar/branches/port-to-gio/ChangeLog 2009-01-06 23:03:23 UTC (rev 29112)
+++ thunar/branches/port-to-gio/ChangeLog 2009-01-07 03:00:03 UTC (rev 29113)
@@ -1,3 +1,14 @@
+2009-01-07 Jannis Pohlmann <jannis at xfce.org>
+
+ * thunar/thunar-folder.c, thunar/thunar-preferences.c: Make
+ ThunarFolder and ThunarPreferences use GFileMonitor instead of
+ ThunarVfsMonitor.
+ * thunar/thunar-window.c: Remove code for GLib versions < 2.14 from
+ thunar_window_setup_user_dir_menu_entries() and
+ thunar_window_open_user_folder(). Implement more functions based on
+ GIO: thunar_window_action_open_home() and
+ thunar_window_action_open_trash().
+
2009-01-06 Jannis Pohlmann <jannis at xfce.org>
* thunar/Makefile.am, thunar-file.{c,h}, thunar-list-model.c,
Modified: thunar/branches/port-to-gio/thunar/thunar-folder.c
===================================================================
--- thunar/branches/port-to-gio/thunar/thunar-folder.c 2009-01-06 23:03:23 UTC (rev 29112)
+++ thunar/branches/port-to-gio/thunar/thunar-folder.c 2009-01-07 03:00:03 UTC (rev 29113)
@@ -67,11 +67,10 @@
static void thunar_folder_file_destroyed (ThunarFileMonitor *file_monitor,
ThunarFile *file,
ThunarFolder *folder);
-static void thunar_folder_monitor (ThunarVfsMonitor *monitor,
- ThunarVfsMonitorHandle *handle,
- ThunarVfsMonitorEvent event,
- ThunarVfsPath *handle_path,
- ThunarVfsPath *event_path,
+static void thunar_folder_monitor (GFileMonitor *monitor,
+ GFile *path,
+ GFile *other_path,
+ GFileMonitorEvent event_type,
gpointer user_data);
@@ -101,8 +100,7 @@
ThunarFileMonitor *file_monitor;
- ThunarVfsMonitor *monitor;
- ThunarVfsMonitorHandle *handle;
+ GFileMonitor *monitor;
};
@@ -223,13 +221,12 @@
static void
thunar_folder_init (ThunarFolder *folder)
{
+ folder->monitor = NULL;
+
/* connect to the ThunarFileMonitor instance */
folder->file_monitor = thunar_file_monitor_get_default ();
g_signal_connect (G_OBJECT (folder->file_monitor), "file-changed", G_CALLBACK (thunar_folder_file_changed), folder);
g_signal_connect (G_OBJECT (folder->file_monitor), "file-destroyed", G_CALLBACK (thunar_folder_file_destroyed), folder);
-
- /* connect to the file alteration monitor */
- folder->monitor = thunar_vfs_monitor_get_default ();
}
@@ -241,12 +238,14 @@
/* disconnect from the ThunarFileMonitor instance */
g_signal_handlers_disconnect_matched (G_OBJECT (folder->file_monitor), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, folder);
- g_object_unref (G_OBJECT (folder->file_monitor));
+ g_object_unref (folder->file_monitor);
/* disconnect from the file alteration monitor */
- if (G_LIKELY (folder->handle != NULL))
- thunar_vfs_monitor_remove (folder->monitor, folder->handle);
- g_object_unref (G_OBJECT (folder->monitor));
+ if (G_LIKELY (folder->monitor != NULL))
+ {
+ g_file_monitor_cancel (folder->monitor);
+ g_object_unref (folder->monitor);
+ }
/* cancel the pending job (if any) */
if (G_UNLIKELY (folder->job != NULL))
@@ -322,7 +321,6 @@
_thunar_return_val_if_fail (THUNAR_IS_FOLDER (folder), FALSE);
_thunar_return_val_if_fail (THUNAR_VFS_IS_JOB (job), FALSE);
- _thunar_return_val_if_fail (folder->handle == NULL, FALSE);
_thunar_return_val_if_fail (folder->job == job, FALSE);
/* turn the info list into a file list */
@@ -358,7 +356,6 @@
_thunar_return_if_fail (THUNAR_IS_FOLDER (folder));
_thunar_return_if_fail (THUNAR_VFS_IS_JOB (job));
_thunar_return_if_fail (THUNAR_IS_FILE (folder->corresponding_file));
- _thunar_return_if_fail (folder->handle == NULL);
_thunar_return_if_fail (folder->job == job);
/* check if we need to merge new files with existing files */
@@ -436,8 +433,10 @@
folder->job = NULL;
/* add us to the file alteration monitor */
- folder->handle = thunar_vfs_monitor_add_directory (folder->monitor, thunar_file_get_path (folder->corresponding_file),
- thunar_folder_monitor, folder);
+ folder->monitor = g_file_monitor_directory (thunar_file_get_gfile (folder->corresponding_file),
+ G_FILE_MONITOR_NONE, NULL, NULL);
+ g_object_add_weak_pointer (G_OBJECT (folder->monitor), (gpointer) &folder->monitor);
+ g_signal_connect (folder->monitor, "changed", G_CALLBACK (thunar_folder_monitor), folder);
/* tell the consumers that we have loaded the directory */
g_object_notify (G_OBJECT (folder), "loading");
@@ -504,37 +503,44 @@
static void
-thunar_folder_monitor (ThunarVfsMonitor *monitor,
- ThunarVfsMonitorHandle *handle,
- ThunarVfsMonitorEvent event,
- ThunarVfsPath *handle_path,
- ThunarVfsPath *event_path,
+thunar_folder_monitor (GFileMonitor *monitor,
+ GFile *path,
+ GFile *other_path,
+ GFileMonitorEvent event_type,
gpointer user_data)
{
ThunarFolder *folder = THUNAR_FOLDER (user_data);
ThunarFile *file;
GList *lp;
GList list;
+ gchar *uri;
- _thunar_return_if_fail (THUNAR_VFS_IS_MONITOR (monitor));
_thunar_return_if_fail (THUNAR_IS_FOLDER (folder));
- _thunar_return_if_fail (folder->monitor == monitor);
- _thunar_return_if_fail (folder->handle == handle);
_thunar_return_if_fail (folder->job == NULL);
- /* check on which file the event occurred */
- if (!thunar_vfs_path_equal (event_path, thunar_file_get_path (folder->corresponding_file)))
+ /* check if the directory itself has changed */
+ if (g_file_equal (path, thunar_file_get_gfile (folder->corresponding_file)))
{
+ if (event_type == G_FILE_MONITOR_EVENT_DELETED)
+ thunar_file_destroy (folder->corresponding_file);
+ else
+ thunar_file_reload (folder->corresponding_file);
+ }
+ else
+ {
/* check if we already ship the file */
- for (lp = folder->files; lp != NULL; lp = lp->next)
- if (thunar_vfs_path_equal (event_path, thunar_file_get_path (lp->data)))
+ for (lp = g_list_first (folder->files); lp != NULL; lp = g_list_next (lp))
+ if (g_file_equal (path, thunar_file_get_gfile (lp->data)))
break;
- /* if we don't have it, add it if the event is not an "deleted" event */
- if (G_UNLIKELY (lp == NULL && event != THUNAR_VFS_MONITOR_EVENT_DELETED))
+ /* if we don't have it, add it if the event is not a "deleted" event */
+ if (G_UNLIKELY (lp == NULL && event_type != G_FILE_MONITOR_EVENT_DELETED))
{
/* allocate a file for the path */
- file = thunar_file_get_for_path (event_path, NULL);
+ uri = g_file_get_uri (path);
+ file = thunar_file_get_for_uri (uri, NULL);
+ g_free (uri);
+
if (G_UNLIKELY (file == NULL))
return;
@@ -548,20 +554,13 @@
else if (lp != NULL)
{
/* update/destroy the file */
- if (event == THUNAR_VFS_MONITOR_EVENT_DELETED)
+ if (event_type == G_FILE_MONITOR_EVENT_DELETED)
thunar_file_destroy (lp->data);
else
thunar_file_reload (lp->data);
}
+
}
- else
- {
- /* update/destroy the corresponding file */
- if (event == THUNAR_VFS_MONITOR_EVENT_DELETED)
- thunar_file_destroy (folder->corresponding_file);
- else
- thunar_file_reload (folder->corresponding_file);
- }
}
@@ -699,10 +698,10 @@
}
/* disconnect from the file alteration monitor */
- if (G_UNLIKELY (folder->handle != NULL))
+ if (G_UNLIKELY (folder->monitor != NULL))
{
- thunar_vfs_monitor_remove (folder->monitor, folder->handle);
- folder->handle = NULL;
+ g_file_monitor_cancel (folder->monitor);
+ g_object_unref (folder->monitor);
}
/* reset the new_files list */
Modified: thunar/branches/port-to-gio/thunar/thunar-preferences.c
===================================================================
--- thunar/branches/port-to-gio/thunar/thunar-preferences.c 2009-01-06 23:03:23 UTC (rev 29112)
+++ thunar/branches/port-to-gio/thunar/thunar-preferences.c 2009-01-07 03:00:03 UTC (rev 29113)
@@ -37,8 +37,6 @@
#include <string.h>
#endif
-#include <thunar-vfs/thunar-vfs.h>
-
#include <thunar/thunar-enum-types.h>
#include <thunar/thunar-gobject-extensions.h>
#include <thunar/thunar-preferences.h>
@@ -102,11 +100,10 @@
GParamSpec *pspec);
static void thunar_preferences_resume_monitor (ThunarPreferences *preferences);
static void thunar_preferences_suspend_monitor (ThunarPreferences *preferences);
-static void thunar_preferences_monitor (ThunarVfsMonitor *monitor,
- ThunarVfsMonitorHandle *handle,
- ThunarVfsMonitorEvent event,
- ThunarVfsPath *handle_path,
- ThunarVfsPath *event_path,
+static void thunar_preferences_monitor (GFileMonitor *monitor,
+ GFile *path,
+ GFile *other_path,
+ GFileMonitorEvent event_type,
gpointer user_data);
static void thunar_preferences_queue_load (ThunarPreferences *preferences);
static void thunar_preferences_queue_store (ThunarPreferences *preferences);
@@ -126,15 +123,15 @@
{
GObject __parent__;
- ThunarVfsMonitorHandle *handle;
- ThunarVfsMonitor *monitor;
+ GFileMonitor *monitor;
+ GFile *monitor_file;
- GValue values[N_PROPERTIES];
+ GValue values[N_PROPERTIES];
- gboolean loading_in_progress;
+ gboolean loading_in_progress;
- gint load_idle_id;
- gint store_idle_id;
+ gint load_idle_id;
+ gint store_idle_id;
};
@@ -671,8 +668,8 @@
static void
thunar_preferences_init (ThunarPreferences *preferences)
{
- /* grab a reference on the VFS monitor */
- preferences->monitor = thunar_vfs_monitor_get_default ();
+ preferences->monitor = NULL;
+ preferences->monitor_file = NULL;
/* load the settings */
thunar_preferences_load_idle (preferences);
@@ -701,11 +698,7 @@
g_source_remove (preferences->load_idle_id);
/* stop the file monitor */
- if (G_LIKELY (preferences->monitor != NULL))
- {
- thunar_preferences_suspend_monitor (preferences);
- g_object_unref (G_OBJECT (preferences->monitor));
- }
+ thunar_preferences_suspend_monitor (preferences);
/* release the property values */
for (n = 1; n < N_PROPERTIES; ++n)
@@ -763,23 +756,26 @@
static void
thunar_preferences_resume_monitor (ThunarPreferences *preferences)
{
- ThunarVfsPath *path;
- gchar *filename;
+ gchar *filename;
/* verify that the monitor is suspended */
- if (G_LIKELY (preferences->handle == NULL))
+ if (G_LIKELY (preferences->monitor == NULL))
{
/* determine the save location for thunarrc to monitor */
filename = xfce_resource_save_location (XFCE_RESOURCE_CONFIG, "Thunar/thunarrc", TRUE);
if (G_LIKELY (filename != NULL))
{
- /* determine the VFS path for the filename */
- path = thunar_vfs_path_new (filename, NULL);
- if (G_LIKELY (path != NULL))
+ /* create a GFile for the filename */
+ preferences->monitor_file = g_file_new_for_path (filename);
+ if (G_LIKELY (preferences->monitor_file != NULL))
{
/* add the monitor handle for the file */
- preferences->handle = thunar_vfs_monitor_add_file (preferences->monitor, path, thunar_preferences_monitor, preferences);
- thunar_vfs_path_unref (path);
+ preferences->monitor = g_file_monitor_file (preferences->monitor_file,
+ G_FILE_MONITOR_NONE, NULL, NULL);
+ g_object_add_weak_pointer (G_OBJECT (preferences->monitor),
+ (gpointer) &preferences->monitor);
+ g_signal_connect (preferences->monitor, "changed",
+ G_CALLBACK (thunar_preferences_monitor), preferences);
}
/* release the filename */
@@ -794,33 +790,33 @@
thunar_preferences_suspend_monitor (ThunarPreferences *preferences)
{
/* verify that the monitor is active */
- if (G_LIKELY (preferences->handle != NULL))
+ if (G_LIKELY (preferences->monitor != NULL))
{
- /* disconnect the handle from the monitor */
- thunar_vfs_monitor_remove (preferences->monitor, preferences->handle);
- preferences->handle = NULL;
+ g_file_monitor_cancel (preferences->monitor);
+ g_object_unref (preferences->monitor);
+ g_object_unref (preferences->monitor_file);
}
}
static void
-thunar_preferences_monitor (ThunarVfsMonitor *monitor,
- ThunarVfsMonitorHandle *handle,
- ThunarVfsMonitorEvent event,
- ThunarVfsPath *handle_path,
- ThunarVfsPath *event_path,
- gpointer user_data)
+thunar_preferences_monitor (GFileMonitor *monitor,
+ GFile *path,
+ GFile *other_path,
+ GFileMonitorEvent event_type,
+ gpointer user_data)
{
ThunarPreferences *preferences = THUNAR_PREFERENCES (user_data);
_thunar_return_if_fail (THUNAR_IS_PREFERENCES (preferences));
- _thunar_return_if_fail (THUNAR_VFS_IS_MONITOR (monitor));
_thunar_return_if_fail (preferences->monitor == monitor);
- _thunar_return_if_fail (preferences->handle == handle);
+ if (G_UNLIKELY (!g_file_equal (path, preferences->monitor_file)))
+ return;
+
/* schedule a reload whenever the file is created/changed */
- if (event == THUNAR_VFS_MONITOR_EVENT_CHANGED || event == THUNAR_VFS_MONITOR_EVENT_CREATED)
+ if (event_type == G_FILE_MONITOR_EVENT_CHANGED || event_type == G_FILE_MONITOR_EVENT_CREATED)
thunar_preferences_queue_load (preferences);
}
Modified: thunar/branches/port-to-gio/thunar/thunar-window.c
===================================================================
--- thunar/branches/port-to-gio/thunar/thunar-window.c 2009-01-06 23:03:23 UTC (rev 29112)
+++ thunar/branches/port-to-gio/thunar/thunar-window.c 2009-01-07 03:00:03 UTC (rev 29113)
@@ -616,17 +616,6 @@
"open-pictures", "open-public", "open-templates", "open-videos"
};
-#if !GLIB_CHECK_VERSION(2, 14, 0)
-
- for (i = 0; i < G_N_ELEMENTS(callback_names); i++)
- {
- GtkAction *action = gtk_action_group_get_action (window->action_group,
- callback_names[i]);
- gtk_action_set_visible (GTK_ACTION (action), FALSE);
- }
-
-#else /* GLIB_CHECK_VERSION(2, 14, 0) */
-
gchar *old_locale = NULL;
gchar *locale = NULL;
gchar *translation = NULL;
@@ -650,10 +639,10 @@
for (i = 0; i < THUNAR_USER_N_DIRECTORIES; i++)
{
- gboolean visible = FALSE;
+ gboolean visible = FALSE;
GtkAction *action = gtk_action_group_get_action (window->action_group,
callback_names[i]);
- gchar *path = g_strdup (g_get_user_special_dir (i));
+ gchar *path = g_strdup (g_get_user_special_dir (i));
/* special case: got NULL for the templates dir. Force it to ~/Templates */
if (G_UNLIKELY (path == NULL && i == THUNAR_USER_DIRECTORY_TEMPLATES))
@@ -686,8 +675,6 @@
}
setlocale (LC_MESSAGES, old_locale);
-
-#endif /* GLIB_CHECK_VERSION(2,14,0) */
}
@@ -1878,18 +1865,14 @@
thunar_window_action_open_home (GtkAction *action,
ThunarWindow *window)
{
- ThunarVfsPath *home_path;
ThunarFile *home_file;
GError *error = NULL;
_thunar_return_if_fail (GTK_IS_ACTION (action));
_thunar_return_if_fail (THUNAR_IS_WINDOW (window));
- /* determine the path to the home directory */
- home_path = thunar_vfs_path_get_for_home ();
-
/* determine the file for the home directory */
- home_file = thunar_file_get_for_path (home_path, &error);
+ home_file = thunar_file_get_for_uri (xfce_get_homedir (), &error);
if (G_UNLIKELY (home_file == NULL))
{
/* display an error to the user */
@@ -1902,9 +1885,6 @@
thunar_window_set_current_directory (window, home_file);
g_object_unref (G_OBJECT (home_file));
}
-
- /* release our reference on the home path */
- thunar_vfs_path_unref (home_path);
}
gboolean
@@ -1914,22 +1894,20 @@
const gchar *default_name)
{
ThunarFile *user_file = NULL;
- GError *error = NULL;
- gchar *user_dir = NULL;
- gboolean result = FALSE;
+ GError *error = NULL;
+ gchar *user_dir;
+ gboolean result = FALSE;
-#if GLIB_CHECK_VERSION(2, 14, 0)
user_dir = g_strdup (g_get_user_special_dir (thunar_user_dir));
-#endif
if (G_UNLIKELY (user_dir == NULL))
- {
- user_dir = g_build_filename (G_DIR_SEPARATOR_S, xfce_get_homedir (),
- default_name, NULL);
- }
+ user_dir = g_build_filename (G_DIR_SEPARATOR_S, xfce_get_homedir (), default_name, NULL);
user_file = thunar_file_get_for_uri (user_dir, &error);
- if (G_UNLIKELY (user_file == NULL && error->domain == G_FILE_ERROR && error->code == G_FILE_ERROR_EXIST))
+
+ if (G_UNLIKELY (user_file == NULL &&
+ error->domain == G_FILE_ERROR &&
+ error->code == G_FILE_ERROR_EXIST))
{
g_error_free (error);
error = NULL;
@@ -2144,22 +2122,19 @@
thunar_window_action_open_trash (GtkAction *action,
ThunarWindow *window)
{
- ThunarVfsPath *trash_bin_path;
- ThunarFile *trash_bin;
- GError *error = NULL;
+ ThunarFile *trash_bin;
+ GError *error = NULL;
_thunar_return_if_fail (GTK_IS_ACTION (action));
_thunar_return_if_fail (THUNAR_IS_WINDOW (window));
- /* determine the path to the trash bin */
- trash_bin_path = thunar_vfs_path_get_for_trash ();
-
/* determine the file for the trash bin */
- trash_bin = thunar_file_get_for_path (trash_bin_path, &error);
+ trash_bin = thunar_file_get_for_uri ("trash:///", &error);
if (G_UNLIKELY (trash_bin == NULL))
{
/* display an error to the user */
- thunar_dialogs_show_error (GTK_WIDGET (window), error, _("Failed to display the contents of the trash can"));
+ thunar_dialogs_show_error (GTK_WIDGET (window), error,
+ _("Failed to display the contents of the trash can"));
g_error_free (error);
}
else
@@ -2168,9 +2143,6 @@
thunar_window_set_current_directory (window, trash_bin);
g_object_unref (G_OBJECT (trash_bin));
}
-
- /* release our reference on the trash bin path */
- thunar_vfs_path_unref (trash_bin_path);
}
More information about the Xfce4-commits
mailing list