summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Neumair <cneumair@gnome.org>2008-07-19 12:12:00 +0000
committerChristian Neumair <cneumair@src.gnome.org>2008-07-19 12:12:00 +0000
commit82887543d718e332791dc8df79c9b4e1e8620db4 (patch)
tree272acdf115c271716d6ab47414197458fa7833ac
parent8f974b3021b93504b22eb73ae322618f5a1bd403 (diff)
downloadnautilus-82887543d718e332791dc8df79c9b4e1e8620db4.tar.gz
Add nautilus_file_operations_mount_volume_full(), which will issue a
2008-07-19 Christian Neumair <cneumair@gnome.org> * libnautilus-private/nautilus-file-operations.c (mount_callback_data_notify), (volume_mount_cb), (nautilus_file_operations_mount_volume), (nautilus_file_operations_mount_volume_full): * libnautilus-private/nautilus-file-operations.h: Add nautilus_file_operations_mount_volume_full(), which will issue a callback with an optional user data object, if the object is still alive after mounting. * src/nautilus-places-sidebar.c (add_place), (clicked_eject_button), (volume_mounted_cb), (open_selected_bookmark), (nautilus_places_sidebar_init), (nautilus_places_sidebar_dispose): Open files after mounting them. svn path=/trunk/; revision=14373
-rw-r--r--ChangeLog17
-rw-r--r--libnautilus-private/nautilus-file-operations.c57
-rw-r--r--libnautilus-private/nautilus-file-operations.h8
-rw-r--r--src/nautilus-places-sidebar.c91
4 files changed, 160 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index ef299cb4e..d66556d33 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2008-07-19 Christian Neumair <cneumair@gnome.org>
+
+ * libnautilus-private/nautilus-file-operations.c
+ (mount_callback_data_notify), (volume_mount_cb),
+ (nautilus_file_operations_mount_volume),
+ (nautilus_file_operations_mount_volume_full):
+ * libnautilus-private/nautilus-file-operations.h:
+ Add nautilus_file_operations_mount_volume_full(), which
+ will issue a callback with an optional user data object,
+ if the object is still alive after mounting.
+
+ * src/nautilus-places-sidebar.c (add_place),
+ (clicked_eject_button), (volume_mounted_cb),
+ (open_selected_bookmark), (nautilus_places_sidebar_init),
+ (nautilus_places_sidebar_dispose):
+ Open files after mounting them.
+
2008-07-17 Christian Neumair <cneumair@gnome.org>
* libnautilus-private/nautilus-program-choosing.c
diff --git a/libnautilus-private/nautilus-file-operations.c b/libnautilus-private/nautilus-file-operations.c
index a28521558..80463c48e 100644
--- a/libnautilus-private/nautilus-file-operations.c
+++ b/libnautilus-private/nautilus-file-operations.c
@@ -2108,10 +2108,23 @@ nautilus_file_operations_unmount_mount (GtkWindow *parent_w
}
static void
+mount_callback_data_notify (gpointer data,
+ GObject *object)
+{
+ GMountOperation *mount_op;
+
+ mount_op = G_MOUNT_OPERATION (data);
+ g_object_set_data (G_OBJECT (mount_op), "mount-callback", NULL);
+ g_object_set_data (G_OBJECT (mount_op), "mount-callback-data", NULL);
+}
+
+static void
volume_mount_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
+ NautilusMountCallback mount_callback;
+ GObject *mount_callback_data_object;
GMountOperation *mount_op = user_data;
GError *error;
char *primary;
@@ -2132,6 +2145,22 @@ volume_mount_cb (GObject *source_object,
g_error_free (error);
}
+ mount_callback = (NautilusMountCallback)
+ g_object_get_data (G_OBJECT (mount_op), "mount-callback");
+ mount_callback_data_object =
+ g_object_get_data (G_OBJECT (mount_op), "mount-callback-data");
+
+ if (mount_callback != NULL) {
+ (* mount_callback) (G_VOLUME (source_object),
+ mount_callback_data_object);
+
+ if (mount_callback_data_object != NULL) {
+ g_object_weak_unref (mount_callback_data_object,
+ mount_callback_data_notify,
+ mount_op);
+ }
+ }
+
g_object_unref (mount_op);
}
@@ -2141,15 +2170,39 @@ nautilus_file_operations_mount_volume (GtkWindow *parent_window,
GVolume *volume,
gboolean allow_autorun)
{
+ nautilus_file_operations_mount_volume_full (parent_window, volume,
+ allow_autorun, NULL, NULL);
+}
+
+void
+nautilus_file_operations_mount_volume_full (GtkWindow *parent_window,
+ GVolume *volume,
+ gboolean allow_autorun,
+ NautilusMountCallback mount_callback,
+ GObject *mount_callback_data_object)
+{
GMountOperation *mount_op;
-
+
mount_op = eel_mount_operation_new (parent_window);
+ g_object_set_data (G_OBJECT (mount_op),
+ "mount-callback",
+ mount_callback);
+
+ if (mount_callback != NULL &&
+ mount_callback_data_object != NULL) {
+ g_object_weak_ref (mount_callback_data_object,
+ mount_callback_data_notify,
+ mount_op);
+ }
+ g_object_set_data (G_OBJECT (mount_op),
+ "mount-callback-data",
+ mount_callback_data_object);
+
if (allow_autorun)
nautilus_allow_autorun_for_volume (volume);
g_volume_mount (volume, 0, mount_op, NULL, volume_mount_cb, mount_op);
}
-
static void
report_count_progress (CommonJob *job,
SourceInfo *source_info)
diff --git a/libnautilus-private/nautilus-file-operations.h b/libnautilus-private/nautilus-file-operations.h
index d9cd17ead..fd0f18510 100644
--- a/libnautilus-private/nautilus-file-operations.h
+++ b/libnautilus-private/nautilus-file-operations.h
@@ -38,6 +38,8 @@ typedef void (* NautilusOpCallback) (gpointer callback_data);
typedef void (* NautilusDeleteCallback) (GHashTable *debuting_uris,
gboolean user_cancel,
gpointer callback_data);
+typedef void (* NautilusMountCallback) (GVolume *volume,
+ GObject *callback_data_object);
/* FIXME: int copy_action should be an enum */
@@ -93,7 +95,11 @@ void nautilus_file_operations_unmount_mount (GtkWindow *par
void nautilus_file_operations_mount_volume (GtkWindow *parent_window,
GVolume *volume,
gboolean allow_autorun);
-
+void nautilus_file_operations_mount_volume_full (GtkWindow *parent_window,
+ GVolume *volume,
+ gboolean allow_autorun,
+ NautilusMountCallback mount_callback,
+ GObject *mount_callback_data_object);
void nautilus_file_operations_copy (GList *files,
GArray *relative_item_points,
diff --git a/src/nautilus-places-sidebar.c b/src/nautilus-places-sidebar.c
index 0bdf71634..4f467c87c 100644
--- a/src/nautilus-places-sidebar.c
+++ b/src/nautilus-places-sidebar.c
@@ -54,6 +54,8 @@
#include "nautilus-places-sidebar.h"
#include "nautilus-window.h"
+#define EJECT_BUTTON_XPAD 6
+
#define NAUTILUS_PLACES_SIDEBAR_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_PLACES_SIDEBAR, NautilusPlacesSidebarClass))
#define NAUTILUS_IS_PLACES_SIDEBAR(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_PLACES_SIDEBAR))
#define NAUTILUS_IS_PLACES_SIDEBAR_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_PLACES_SIDEBAR))
@@ -85,6 +87,11 @@ typedef struct {
GtkWidget *popup_menu_rescan_item;
GtkWidget *popup_menu_format_item;
GtkWidget *popup_menu_empty_trash_item;
+
+ /* volume mounting - delayed open process */
+ gboolean mounting;
+ NautilusWindowSlotInfo *go_to_after_mount_slot;
+ NautilusWindowOpenFlags go_to_after_mount_flags;
} NautilusPlacesSidebar;
typedef struct {
@@ -253,8 +260,8 @@ add_place (NautilusPlacesSidebar *sidebar,
PLACES_SIDEBAR_COLUMN_ROW_TYPE, place_type,
PLACES_SIDEBAR_COLUMN_INDEX, index,
PLACES_SIDEBAR_COLUMN_EJECT, (show_unmount || show_eject),
- PLACES_SIDEBAR_COLUMN_ABOVE_SEPARATOR, place_type != PLACES_BOOKMARK,
- PLACES_SIDEBAR_COLUMN_BELOW_SEPARATOR, place_type == PLACES_BOOKMARK,
+ PLACES_SIDEBAR_COLUMN_ABOVE_SEPARATOR, (show_unmount || show_eject),
+ PLACES_SIDEBAR_COLUMN_BELOW_SEPARATOR, !(show_unmount || show_eject),
-1);
if (pixbuf != NULL) {
@@ -623,17 +630,26 @@ clicked_eject_button (NautilusPlacesSidebar *sidebar,
GdkEvent *event = gtk_get_current_event ();
GdkEventButton *button_event = (GdkEventButton *) event;
GtkTreeViewColumn *column;
- int x, pos, width;
+ GtkSettings *settings;
+ int pos, renderer_width, eject_button_size;
+ int renderer_x2;
*path = NULL;
if (event->type == GDK_BUTTON_PRESS &&
gtk_tree_view_get_path_at_pos (sidebar->tree_view,
button_event->x, button_event->y,
- path, &column, &x, NULL) &&
+ path, &column, NULL, NULL) &&
gtk_tree_view_column_cell_get_position (column, sidebar->eject_cell_renderer,
- &pos, &width)) {
- if (button_event->x > pos && button_event->x < pos + width) {
+ &pos, &renderer_width)) {
+ renderer_x2 = MIN (pos + renderer_width, GTK_WIDGET (sidebar)->allocation.width);
+
+ settings = gtk_widget_get_settings (GTK_WIDGET (sidebar));
+ gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
+ &eject_button_size, NULL);
+
+ if (button_event->x > renderer_x2 - (EJECT_BUTTON_XPAD + eject_button_size) &&
+ button_event->x < renderer_x2 - EJECT_BUTTON_XPAD) {
return TRUE;
}
}
@@ -1363,12 +1379,52 @@ bookmarks_selection_changed_cb (GtkTreeSelection *selection,
}
static void
+volume_mounted_cb (GVolume *volume,
+ GObject *user_data)
+{
+ GMount *mount;
+ NautilusPlacesSidebar *sidebar;
+ GFile *location;
+
+ sidebar = NAUTILUS_PLACES_SIDEBAR (user_data);
+
+ sidebar->mounting = FALSE;
+
+ mount = g_volume_get_mount (volume);
+ if (mount != NULL) {
+ location = g_mount_get_root (mount);
+
+ if (sidebar->go_to_after_mount_slot != NULL) {
+ if ((sidebar->go_to_after_mount_flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW) == 0) {
+ nautilus_window_slot_info_open_location (sidebar->go_to_after_mount_slot, location,
+ NAUTILUS_WINDOW_OPEN_ACCORDING_TO_MODE,
+ sidebar->go_to_after_mount_flags, NULL);
+ } else {
+ NautilusWindow *cur, *new;
+
+ cur = NAUTILUS_WINDOW (sidebar->window);
+ new = nautilus_application_create_navigation_window (cur->application,
+ NULL,
+ gtk_window_get_screen (GTK_WINDOW (cur)));
+ nautilus_window_go_to (new, location);
+ }
+ }
+
+ g_object_unref (G_OBJECT (location));
+ g_object_unref (G_OBJECT (mount));
+ }
+
+
+ eel_remove_weak_pointer (&(sidebar->go_to_after_mount_slot));
+}
+
+static void
open_selected_bookmark (NautilusPlacesSidebar *sidebar,
GtkTreeModel *model,
GtkTreePath *path,
NautilusWindowOpenFlags flags)
{
- NautilusWindowSlot *slot;
+ NautilusWindowSlotInfo *slot;
GtkTreeIter iter;
GFile *location;
char *uri;
@@ -1414,9 +1470,22 @@ open_selected_bookmark (NautilusPlacesSidebar *sidebar,
} else {
GVolume *volume;
+ NautilusWindowSlot *slot;
gtk_tree_model_get (model, &iter, PLACES_SIDEBAR_COLUMN_VOLUME, &volume, -1);
- if (volume != NULL) {
- nautilus_file_operations_mount_volume (NULL, volume, FALSE);
+ if (volume != NULL && !sidebar->mounting) {
+ sidebar->mounting = TRUE;
+
+ g_assert (sidebar->go_to_after_mount_slot == NULL);
+
+ slot = nautilus_window_info_get_active_slot (sidebar->window);
+ sidebar->go_to_after_mount_slot = slot;
+ eel_add_weak_pointer (&(sidebar->go_to_after_mount_slot));
+
+ sidebar->go_to_after_mount_flags = flags;
+
+ nautilus_file_operations_mount_volume_full (NULL, volume, FALSE,
+ volume_mounted_cb,
+ G_OBJECT (sidebar));
g_object_unref (volume);
}
}
@@ -2123,7 +2192,7 @@ nautilus_places_sidebar_init (NautilusPlacesSidebar *sidebar)
"icon-name", "media-eject",
"stock-size", GTK_ICON_SIZE_MENU,
"xalign", 1.0,
- "xpad", 6,
+ "xpad", EJECT_BUTTON_XPAD,
NULL);
gtk_tree_view_column_pack_end (col, cell, TRUE);
gtk_tree_view_column_set_attributes (col, cell,
@@ -2253,6 +2322,8 @@ nautilus_places_sidebar_dispose (GObject *object)
sidebar->volume_monitor = NULL;
}
+ eel_remove_weak_pointer (&(sidebar->go_to_after_mount_slot));
+
G_OBJECT_CLASS (nautilus_places_sidebar_parent_class)->dispose (object);
}