[Xfce4-commits] r30049 - in thunar/branches/migration-to-gio: . thunar
Jannis Pohlmann
jannis at xfce.org
Fri Jun 19 17:34:16 CEST 2009
Author: jannis
Date: 2009-06-19 15:34:16 +0000 (Fri, 19 Jun 2009)
New Revision: 30049
Modified:
thunar/branches/migration-to-gio/ChangeLog
thunar/branches/migration-to-gio/thunar/thunar-shortcuts-view.c
Log:
* thunar/thunar-shortcuts-view.c: Dramatically simplify the way
directories and volumes are mounted and opened by deriving from
ThunarBrowser and calling thunar_browser_poke_file() and
thunar_browser_poke_volume() to resolve directories and volumes
before opening them.
Modified: thunar/branches/migration-to-gio/ChangeLog
===================================================================
--- thunar/branches/migration-to-gio/ChangeLog 2009-06-19 15:34:11 UTC (rev 30048)
+++ thunar/branches/migration-to-gio/ChangeLog 2009-06-19 15:34:16 UTC (rev 30049)
@@ -1,5 +1,13 @@
2009-06-19 Jannis Pohlmann <jannis at xfce.org>
+ * thunar/thunar-shortcuts-view.c: Dramatically simplify the way
+ directories and volumes are mounted and opened by deriving from
+ ThunarBrowser and calling thunar_browser_poke_file() and
+ thunar_browser_poke_volume() to resolve directories and volumes
+ before opening them.
+
+2009-06-19 Jannis Pohlmann <jannis at xfce.org>
+
* thunar/thunar-browser.{c,h}: Add a new interface with two
convenience functions for browsing (possibly not yet mounted or
resolved) volumes and files. thunar_browser_poke_file() can be used
Modified: thunar/branches/migration-to-gio/thunar/thunar-shortcuts-view.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-shortcuts-view.c 2009-06-19 15:34:11 UTC (rev 30048)
+++ thunar/branches/migration-to-gio/thunar/thunar-shortcuts-view.c 2009-06-19 15:34:16 UTC (rev 30049)
@@ -33,6 +33,7 @@
#endif
#include <thunar/thunar-application.h>
+#include <thunar/thunar-browser.h>
#include <thunar/thunar-dialogs.h>
#include <thunar/thunar-dnd.h>
#include <thunar/thunar-gio-extensions.h>
@@ -45,10 +46,6 @@
-typedef struct _MountData MountData;
-
-
-
/* Identifiers for signals */
enum
{
@@ -65,8 +62,6 @@
-static void thunar_shortcuts_view_class_init (ThunarShortcutsViewClass *klass);
-static void thunar_shortcuts_view_init (ThunarShortcutsView *view);
static void thunar_shortcuts_view_finalize (GObject *object);
static gboolean thunar_shortcuts_view_button_press_event (GtkWidget *widget,
GdkEventButton *event);
@@ -125,12 +120,11 @@
GtkTreePath *dst_path);
static void thunar_shortcuts_view_open_clicked (ThunarShortcutsView *view);
static void thunar_shortcuts_view_open (ThunarShortcutsView *view,
- gboolean new_window,
- gboolean mount_only);
+ gboolean new_window);
static void thunar_shortcuts_view_open_in_new_window_clicked (ThunarShortcutsView *view);
static void thunar_shortcuts_view_empty_trash (ThunarShortcutsView *view);
static void thunar_shortcuts_view_eject (ThunarShortcutsView *view);
-static void thunar_shortcuts_view_mount_clicked (ThunarShortcutsView *view);
+static void thunar_shortcuts_view_mount (ThunarShortcutsView *view);
static gboolean thunar_shortcuts_view_separator_func (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer user_data);
@@ -167,17 +161,8 @@
gint queue_resize_signal_id;
};
-struct _MountData
-{
- ThunarShortcutsView *view;
- ThunarFile *file;
- GVolume *volume;
- guint new_window : 1;
- guint mount_only : 1;
-};
-
/* Target types for dragging from the shortcuts view */
static const GtkTargetEntry drag_targets[] = {
{ "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, GTK_TREE_MODEL_ROW },
@@ -191,40 +176,15 @@
-static GObjectClass *thunar_shortcuts_view_parent_class;
-static guint view_signals[LAST_SIGNAL];
+static guint view_signals[LAST_SIGNAL];
-GType
-thunar_shortcuts_view_get_type (void)
-{
- static GType type = G_TYPE_INVALID;
+G_DEFINE_TYPE_WITH_CODE (ThunarShortcutsView, thunar_shortcuts_view, GTK_TYPE_TREE_VIEW,
+ G_IMPLEMENT_INTERFACE (THUNAR_TYPE_BROWSER, NULL));
- if (G_UNLIKELY (type == G_TYPE_INVALID))
- {
- static const GTypeInfo info =
- {
- sizeof (ThunarShortcutsViewClass),
- NULL,
- NULL,
- (GClassInitFunc) thunar_shortcuts_view_class_init,
- NULL,
- NULL,
- sizeof (ThunarShortcutsView),
- 0,
- (GInstanceInitFunc) thunar_shortcuts_view_init,
- NULL,
- };
- type = g_type_register_static (GTK_TYPE_TREE_VIEW, I_("ThunarShortcutsView"), &info, 0);
- }
- return type;
-}
-
-
-
static void
thunar_shortcuts_view_class_init (ThunarShortcutsViewClass *klass)
{
@@ -232,9 +192,6 @@
GtkWidgetClass *gtkwidget_class;
GObjectClass *gobject_class;
- /* determine the parent type class */
- thunar_shortcuts_view_parent_class = g_type_class_peek_parent (klass);
-
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = thunar_shortcuts_view_finalize;
@@ -428,9 +385,9 @@
{
/* check if we should simply open or open in new window */
if (G_LIKELY (event->button == 1))
- thunar_shortcuts_view_open (view, FALSE, FALSE);
+ thunar_shortcuts_view_open (view, FALSE);
else if (G_UNLIKELY (event->button == 2))
- thunar_shortcuts_view_open (view, TRUE, FALSE);
+ thunar_shortcuts_view_open (view, TRUE);
}
/* reset the pressed button state */
@@ -787,7 +744,7 @@
(*GTK_TREE_VIEW_CLASS (thunar_shortcuts_view_parent_class)->row_activated) (tree_view, path, column);
/* open the selected shortcut */
- thunar_shortcuts_view_open (view, FALSE, FALSE);
+ thunar_shortcuts_view_open (view, FALSE);
}
@@ -852,7 +809,7 @@
/* append the "Mount Volume" menu action */
item = gtk_image_menu_item_new_with_mnemonic (_("_Mount Volume"));
gtk_widget_set_sensitive (item, !g_volume_is_mounted (volume));
- g_signal_connect_swapped (G_OBJECT (item), "activate", G_CALLBACK (thunar_shortcuts_view_mount_clicked), view);
+ g_signal_connect_swapped (G_OBJECT (item), "activate", G_CALLBACK (thunar_shortcuts_view_mount), view);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
gtk_widget_show (item);
@@ -1240,307 +1197,87 @@
thunar_shortcuts_view_open_clicked (ThunarShortcutsView *view)
{
_thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
- thunar_shortcuts_view_open (view, FALSE, FALSE);
+ thunar_shortcuts_view_open (view, FALSE);
}
static void
-thunar_shortcuts_view_mount_data_free (MountData *data)
+thunar_shortcuts_view_poke_file_finish (ThunarBrowser *browser,
+ ThunarFile *file,
+ ThunarFile *target_file,
+ GError *error,
+ gpointer user_data)
{
- _thunar_return_if_fail (data != NULL);
- _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (data->view));
-
- g_object_unref (data->view);
-
- if (data->file != NULL)
- g_object_unref (data->file);
-
- if (data->volume != NULL)
- g_object_unref (data->volume);
-
- _thunar_slice_free (MountData, data);
-}
-
-
-
-static void
-thunar_shortcuts_view_open_real (MountData *data)
-{
ThunarApplication *application;
- GError *error = NULL;
+ gboolean new_window = GPOINTER_TO_UINT (user_data);
- _thunar_return_if_fail (data != NULL);
- _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (data->view));
- _thunar_return_if_fail (THUNAR_IS_FILE (data->file));
+ _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (browser));
+ _thunar_return_if_fail (THUNAR_IS_FILE (file));
- if (thunar_file_is_mounted (data->file))
+ if (error == NULL)
{
- if (data->new_window)
+ if (new_window)
{
- /* open a new window for the shortcut target folder */
+ /* open a new window for the target folder */
application = thunar_application_get ();
- thunar_application_open_window (application, data->file,
- gtk_widget_get_screen (GTK_WIDGET (data->view)));
+ thunar_application_open_window (application, target_file,
+ gtk_widget_get_screen (GTK_WIDGET (browser)));
g_object_unref (application);
}
else
{
/* invoke the signal to change to that folder */
- g_signal_emit (data->view, view_signals[SHORTCUT_ACTIVATED], 0, data->file);
+ g_signal_emit (browser, view_signals[SHORTCUT_ACTIVATED], 0, target_file);
}
}
else
{
- g_set_error (&error, G_IO_ERROR, G_IO_ERROR_NOT_MOUNTED, _("Mounting failed"));
- thunar_dialogs_show_error (data->view, error, _("Failed to open \"%s\""),
- thunar_file_get_display_name (data->file));
- g_error_free (error);
+ thunar_dialogs_show_error (GTK_WIDGET (browser), error, _("Failed to open \"%s\""),
+ thunar_file_get_display_name (file));
}
}
static void
-thunar_shortcuts_view_open_async_finish (GObject *object,
- GAsyncResult *result,
- gpointer user_data)
+thunar_shortcuts_view_poke_volume_finish (ThunarBrowser *browser,
+ GVolume *volume,
+ ThunarFile *mount_point,
+ GError *error,
+ gpointer user_data)
{
- MountData *data = user_data;
- GError *error = NULL;
+ gboolean new_window = GPOINTER_TO_UINT (user_data);
+ gchar *volume_name;
- _thunar_return_if_fail (G_IS_FILE (object));
- _thunar_return_if_fail (G_IS_ASYNC_RESULT (result));
- _thunar_return_if_fail (data != NULL);
- _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (data->view));
- _thunar_return_if_fail (THUNAR_IS_FILE (data->file));
+ _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (browser));
+ _thunar_return_if_fail (G_IS_VOLUME (volume));
- /* finish mounting the volume */
- if (!g_file_mount_enclosing_volume_finish (G_FILE (object), result, &error))
- {
- if (error->domain == G_IO_ERROR)
- {
- /* ignore already mounted and not supported errors */
- if (error->code == G_IO_ERROR_ALREADY_MOUNTED
- || error->code == G_IO_ERROR_NOT_SUPPORTED)
- {
- g_clear_error (&error);
- }
- }
- }
-
- /* check if mounting succeeded */
if (error == NULL)
{
- /* reload the file if it couldn't be loaded before */
- if (!thunar_file_is_mounted (data->file))
- thunar_file_reload (data->file);
-
- /* now try to open the file */
- thunar_shortcuts_view_open_real (data);
+ thunar_browser_poke_file (browser, mount_point, GTK_WIDGET (browser),
+ thunar_shortcuts_view_poke_file_finish,
+ GUINT_TO_POINTER (new_window));
}
else
{
- /* show the error dialog */
- thunar_dialogs_show_error (data->view, error, _("Failed to open \"%s\""),
- thunar_file_get_display_name (data->file));
-
- /* free the error */
- g_error_free (error);
- }
-
- /* free the mount data struct */
- thunar_shortcuts_view_mount_data_free (data);
-}
-
-
-
-static void
-thunar_shortcuts_view_open_async (MountData *data)
-{
- GMountOperation *mount_operation;
- GtkWidget *window;
- GFile *location;
-
- _thunar_return_if_fail (data != NULL);
- _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (data->view));
- _thunar_return_if_fail (THUNAR_IS_FILE (data->file));
-
- /* check if the file is mounted */
- if (thunar_file_is_mounted (data->file))
- {
- /* it is, open it now */
- thunar_shortcuts_view_open_real (data);
-
- /* destroy the mount data */
- thunar_shortcuts_view_mount_data_free (data);
- }
- else
- {
- /* it is not, determine its location */
- location = thunar_file_get_file (data->file);
-
- /* allocate a GTK+ mount operation */
- window = gtk_widget_get_toplevel (GTK_WIDGET (data->view));
- mount_operation = gtk_mount_operation_new (GTK_WINDOW (window));
-
- /* mount the enclosing volume and open the file in the callback */
- g_file_mount_enclosing_volume (location, G_MOUNT_MOUNT_NONE,
- mount_operation, NULL,
- thunar_shortcuts_view_open_async_finish,
- data);
-
- /* release the mount operation */
- g_object_unref (mount_operation);
- }
-}
-
-
-
-static void
-thunar_shortcuts_view_mount_async_finish (GObject *object,
- GAsyncResult *result,
- gpointer user_data)
-{
- MountData *data = user_data;
- ThunarFile *file;
- GError *error = NULL;
- GMount *mount;
- GFile *location;
- gchar *volume_name;
-
- _thunar_return_if_fail (G_IS_VOLUME (object));
- _thunar_return_if_fail (G_IS_ASYNC_RESULT (result));
- _thunar_return_if_fail (data != NULL);
- _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (data->view));
- _thunar_return_if_fail (G_IS_VOLUME (data->volume));
-
- /* check if there was an error */
- if (!g_volume_mount_finish (G_VOLUME (object), result, &error))
- {
- if (error->domain == G_IO_ERROR)
- {
- /* ignore already handled and pending mount errors */
- if (error->code == G_IO_ERROR_FAILED_HANDLED
- || error->code == G_IO_ERROR_ALREADY_MOUNTED
- || error->code == G_IO_ERROR_PENDING)
- {
- g_clear_error (&error);
- }
- }
- }
-
- if (error == NULL)
- {
- if (data->mount_only)
- return;
-
- mount = g_volume_get_mount (data->volume);
-
- /* mounting succeeded, so if the mount still doesn't exist, that's a bug */
- _thunar_assert (G_IS_MOUNT (mount));
-
- location = g_mount_get_root (mount);
- file = thunar_file_get (location, NULL);
-
- /* mounting succeeded, so we should be able to load a file for the mount point */
- _thunar_assert (THUNAR_IS_FILE (file));
-
- g_object_ref (location);
- g_object_unref (mount);
-
- if (!thunar_file_is_mounted (file))
- thunar_file_reload (file);
-
- g_object_unref (data->volume);
- data->volume = NULL;
- data->file = file;
-
- thunar_shortcuts_view_open_real (data);
- }
-
- if (error != NULL)
- {
- /* display an error dialog to inform the user */
- volume_name = g_volume_get_name (data->volume);
- thunar_dialogs_show_error (data->view, error, _("Failed to mount \"%s\""),
- volume_name);
+ volume_name = g_volume_get_name (volume);
+ thunar_dialogs_show_error (GTK_WIDGET (browser), error,
+ _("Failed to mount \"%s\""), volume_name);
g_free (volume_name);
-
- /* free the error */
- g_error_free (error);
}
-
- /* free the mount data struct */
- thunar_shortcuts_view_mount_data_free (data);
}
static void
-thunar_shortcuts_view_mount_async (MountData *data)
-{
- GMountOperation *mount_operation;
- ThunarFile *file;
- GtkWidget *window;
- GMount *mount;
- GFile *location;
-
- _thunar_return_if_fail (data != NULL);
- _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (data->view));
- _thunar_return_if_fail (G_IS_VOLUME (data->volume));
-
- if (g_volume_is_mounted (data->volume))
- {
- if (data->mount_only)
- return;
-
- mount = g_volume_get_mount (data->volume);
-
- _thunar_assert (G_IS_MOUNT (mount));
-
- location = g_mount_get_root (mount);
- file = thunar_file_get (location, NULL);
-
- _thunar_assert (THUNAR_IS_FILE (file));
-
- g_object_unref (data->volume);
- data->volume = NULL;
- data->file = file;
-
- thunar_shortcuts_view_open_real (data);
-
- g_object_unref (location);
- g_object_unref (mount);
-
- thunar_shortcuts_view_mount_data_free (data);
- }
- else
- {
- window = gtk_widget_get_toplevel (GTK_WIDGET (data->view));
- mount_operation = gtk_mount_operation_new (GTK_WINDOW (window));
-
- g_volume_mount (data->volume, G_MOUNT_MOUNT_NONE,
- mount_operation, NULL,
- thunar_shortcuts_view_mount_async_finish,
- data);
-
- g_object_unref (mount_operation);
- }
-}
-
-
-
-static void
thunar_shortcuts_view_open (ThunarShortcutsView *view,
- gboolean new_window,
- gboolean mount_only)
+ gboolean new_window)
{
GtkTreeSelection *selection;
GtkTreeModel *model;
GtkTreeIter iter;
ThunarFile *file;
- MountData *mount_data;
GVolume *volume;
_thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
@@ -1562,32 +1299,22 @@
if (G_LIKELY (volume != NULL))
{
- mount_data = _thunar_slice_new0 (MountData);
- mount_data->view = g_object_ref (view);
- mount_data->new_window = new_window;
- mount_data->mount_only = mount_only;
- mount_data->volume = volume;
- mount_data->file = NULL;
-
- thunar_shortcuts_view_mount_async (mount_data);
-
- if (file != NULL)
- g_object_unref (file);
+ thunar_browser_poke_volume (THUNAR_BROWSER (view), volume, view,
+ thunar_shortcuts_view_poke_volume_finish,
+ GUINT_TO_POINTER (new_window));
}
else if (file != NULL)
{
- mount_data = _thunar_slice_new0 (MountData);
- mount_data->view = g_object_ref (view);
- mount_data->new_window = new_window;
- mount_data->mount_only = mount_only;
- mount_data->file = file;
- mount_data->volume = NULL;
+ thunar_browser_poke_file (THUNAR_BROWSER (view), file, view,
+ thunar_shortcuts_view_poke_file_finish,
+ GUINT_TO_POINTER (new_window));
+ }
- thunar_shortcuts_view_open_async (mount_data);
+ if (file != NULL)
+ g_object_unref (file);
- if (volume != NULL)
- g_object_unref (volume);
- }
+ if (volume != NULL)
+ g_object_unref (volume);
}
}
@@ -1597,7 +1324,7 @@
thunar_shortcuts_view_open_in_new_window_clicked (ThunarShortcutsView *view)
{
_thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
- thunar_shortcuts_view_open (view, TRUE, FALSE);
+ thunar_shortcuts_view_open (view, TRUE);
}
@@ -1743,10 +1470,61 @@
static void
-thunar_shortcuts_view_mount_clicked (ThunarShortcutsView *view)
+thunar_shortcuts_view_poke_volume_mount_finish (ThunarBrowser *browser,
+ GVolume *volume,
+ ThunarFile *mount_point,
+ GError *error,
+ gpointer ignored)
{
+ gchar *volume_name;
+
+ _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (browser));
+ _thunar_return_if_fail (G_IS_VOLUME (volume));
+
+ if (error != NULL)
+ {
+ volume_name = g_volume_get_name (volume);
+ thunar_dialogs_show_error (GTK_WIDGET (browser), error,
+ _("Failed to mount \"%s\""), volume_name);
+ g_free (volume_name);
+ }
+}
+
+
+
+
+static void
+thunar_shortcuts_view_mount (ThunarShortcutsView *view)
+{
+ GtkTreeSelection *selection;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ GVolume *volume;
+
_thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
- thunar_shortcuts_view_open (view, FALSE, TRUE);
+
+ /* determine the selected item */
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
+
+ /* avoid dealing with invalid selections */
+ if (!GTK_IS_TREE_SELECTION (selection))
+ return;
+
+ if (gtk_tree_selection_get_selected (selection, &model, &iter))
+ {
+ /* determine the file for the shortcut at the given tree iterator */
+ gtk_tree_model_get (model, &iter,
+ THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME, &volume,
+ -1);
+
+ if (G_LIKELY (volume != NULL))
+ {
+ thunar_browser_poke_volume (THUNAR_BROWSER (view), volume, view,
+ thunar_shortcuts_view_poke_volume_mount_finish,
+ NULL);
+ g_object_unref (volume);
+ }
+ }
}
More information about the Xfce4-commits
mailing list