Author: jannis Date: 2009-06-19 15:34:20 +0000 (Fri, 19 Jun 2009) New Revision: 30050
Modified: thunar/branches/migration-to-gio/ChangeLog thunar/branches/migration-to-gio/thunar/thunar-location-entry.c Log: * thunar/thunar-location-entry.c: Simplify the activate code by deriving from ThunarBrowser and using the poke functions to mount volumes or resolve files asynchronously and on demand. Modified: thunar/branches/migration-to-gio/ChangeLog =================================================================== --- thunar/branches/migration-to-gio/ChangeLog 2009-06-19 15:34:16 UTC (rev 30049) +++ thunar/branches/migration-to-gio/ChangeLog 2009-06-19 15:34:20 UTC (rev 30050) @@ -1,5 +1,11 @@ 2009-06-19 Jannis Pohlmann <jan...@xfce.org> + * thunar/thunar-location-entry.c: Simplify the activate code by + deriving from ThunarBrowser and using the poke functions to mount + volumes or resolve files asynchronously and on demand. + +2009-06-19 Jannis Pohlmann <jan...@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 Modified: thunar/branches/migration-to-gio/thunar/thunar-location-entry.c =================================================================== --- thunar/branches/migration-to-gio/thunar/thunar-location-entry.c 2009-06-19 15:34:16 UTC (rev 30049) +++ thunar/branches/migration-to-gio/thunar/thunar-location-entry.c 2009-06-19 15:34:20 UTC (rev 30050) @@ -24,6 +24,7 @@ #include <gdk/gdkkeysyms.h> +#include <thunar/thunar-browser.h> #include <thunar/thunar-dialogs.h> #include <thunar/thunar-gobject-extensions.h> #include <thunar/thunar-gtk-extensions.h> @@ -36,10 +37,6 @@ -typedef struct _ActivateData ActivateData; - - - /* Property identifiers */ enum { @@ -103,14 +100,8 @@ GtkWidget *path_entry; }; -struct _ActivateData -{ - ThunarLocationEntry *location_entry; - ThunarFile *file; -}; - static GObjectClass *thunar_location_entry_parent_class; @@ -136,6 +127,13 @@ NULL, }; + static const GInterfaceInfo browser_info = + { + NULL, + NULL, + NULL, + }; + static const GInterfaceInfo component_info = { (GInterfaceInitFunc) thunar_location_entry_component_init, @@ -158,6 +156,7 @@ }; type = g_type_register_static (GTK_TYPE_HBOX, I_("ThunarLocationEntry"), &info, 0); + g_type_add_interface_static (type, THUNAR_TYPE_BROWSER, &browser_info); g_type_add_interface_static (type, THUNAR_TYPE_NAVIGATOR, &navigator_info); g_type_add_interface_static (type, THUNAR_TYPE_COMPONENT, &component_info); g_type_add_interface_static (type, THUNAR_TYPE_LOCATION_BAR, &location_bar_info); @@ -458,58 +457,28 @@ static void -thunar_location_entry_activate_finish (GObject *object, - GAsyncResult *result, - gpointer user_data) +thunar_location_entry_poke_file_finish (ThunarBrowser *browser, + ThunarFile *file, + ThunarFile *target_file, + GError *error, + gpointer ignored) { - ActivateData *data = user_data; - GError *error = NULL; + _thunar_return_if_fail (THUNAR_IS_LOCATION_ENTRY (browser)); + _thunar_return_if_fail (THUNAR_IS_FILE (file)); - _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_LOCATION_ENTRY (data->location_entry)); - _thunar_return_if_fail (THUNAR_IS_FILE (data->file)); - - /* 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 unsupported 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 wasn't mounted before */ - if (!thunar_file_is_mounted (data->file)) - thunar_file_reload (data->file); - - /* we then try to open or launch it */ - thunar_location_entry_open_or_launch (data->location_entry, data->file); + /* try to open or launch the target file */ + thunar_location_entry_open_or_launch (THUNAR_LOCATION_ENTRY (browser), + target_file); } else { /* display an error explaining why we couldn't open/mount the file */ - thunar_dialogs_show_error (data->location_entry->path_entry, + thunar_dialogs_show_error (THUNAR_LOCATION_ENTRY (browser)->path_entry, error, _("Failed to open \"%s\""), - thunar_file_get_display_name (data->file)); - - /* free the error */ - g_error_free (error); + thunar_file_get_display_name (file)); } - - /* destroy the activate data */ - g_object_unref (data->file); - g_object_unref (data->location_entry); - _thunar_slice_free (ActivateData, data); } @@ -520,11 +489,7 @@ thunar_location_entry_activate (GtkWidget *path_entry, ThunarLocationEntry *location_entry) { - GMountOperation *mount_operation; - ActivateData *data; - ThunarFile *file; - GtkWidget *window; - GFile *location; + ThunarFile *file; _thunar_return_if_fail (THUNAR_IS_LOCATION_ENTRY (location_entry)); _thunar_return_if_fail (location_entry->path_entry == path_entry); @@ -533,38 +498,8 @@ file = thunar_path_entry_get_current_file (THUNAR_PATH_ENTRY (path_entry)); if (G_LIKELY (file != NULL)) { - /* check if the file is mounted */ - if (thunar_file_is_mounted (file)) - { - /* it is, we don't need to mount its volume first */ - thunar_location_entry_open_or_launch (location_entry, file); - } - else - { - /* get the GFile of the file */ - location = thunar_file_get_file (file); - - /* determine the toplevel window */ - window = gtk_widget_get_toplevel (path_entry); - - /* allocate a new activate data struct */ - data = _thunar_slice_new0 (ActivateData); - data->file = g_object_ref (file); - data->location_entry = g_object_ref (location_entry); - - /* create a GTK+ mount operation */ - mount_operation = gtk_mount_operation_new (GTK_WINDOW (window)); - - /* mount the volume enclosing the file asynchronously. Thunar will switch - * to the new directory or launch the activated file in the mount callback */ - g_file_mount_enclosing_volume (location, G_MOUNT_MOUNT_NONE, - mount_operation, NULL, - thunar_location_entry_activate_finish, - data); - - /* we no longer need the mount operation */ - g_object_unref (mount_operation); - } + thunar_browser_poke_file (THUNAR_BROWSER (location_entry), file, path_entry, + thunar_location_entry_poke_file_finish, NULL); } } _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits