From 500770e8de18b07392ffa4435372525d5d03c688 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Tue, 12 Feb 2013 18:43:52 -0500 Subject: [PATCH] places-sidebar: add a Connect to Server sidebar item https://bugzilla.gnome.org/show_bug.cgi?id=686968 --- src/nautilus-application.c | 4 +- src/nautilus-application.h | 3 + src/nautilus-places-sidebar.c | 165 ++++++++++++++++++++++------------ 3 files changed, 112 insertions(+), 60 deletions(-) diff --git a/src/nautilus-application.c b/src/nautilus-application.c index a6b8ec95b..e0ebded15 100644 --- a/src/nautilus-application.c +++ b/src/nautilus-application.c @@ -750,7 +750,7 @@ on_connect_server_response (GtkDialog *dialog, gtk_widget_destroy (GTK_WIDGET (dialog)); } -static void +GtkWidget * nautilus_application_connect_server (NautilusApplication *application, NautilusWindow *window) { @@ -770,6 +770,8 @@ nautilus_application_connect_server (NautilusApplication *application, gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window)); gtk_window_set_screen (GTK_WINDOW (dialog), gtk_window_get_screen (GTK_WINDOW (window))); gtk_window_present (GTK_WINDOW (dialog)); + + return dialog; } static void diff --git a/src/nautilus-application.h b/src/nautilus-application.h index 68b17784a..9c9c0e5b7 100644 --- a/src/nautilus-application.h +++ b/src/nautilus-application.h @@ -78,4 +78,7 @@ NautilusBookmarkList * void nautilus_application_edit_bookmarks (NautilusApplication *application, NautilusWindow *window); +GtkWidget * nautilus_application_connect_server (NautilusApplication *application, + NautilusWindow *window); + #endif /* __NAUTILUS_APPLICATION_H__ */ diff --git a/src/nautilus-places-sidebar.c b/src/nautilus-places-sidebar.c index ffc25241d..ffba811db 100644 --- a/src/nautilus-places-sidebar.c +++ b/src/nautilus-places-sidebar.c @@ -144,6 +144,7 @@ typedef enum { PLACES_MOUNTED_VOLUME, PLACES_BOOKMARK, PLACES_HEADING, + PLACES_CONNECT_SERVER } PlaceType; typedef enum { @@ -782,6 +783,14 @@ update_places (NautilusPlacesSidebar *sidebar) _("Browse the contents of the network")); g_object_unref (icon); + icon = g_themed_icon_new (NAUTILUS_ICON_NETWORK_SERVER); + add_place (sidebar, PLACES_CONNECT_SERVER, + SECTION_NETWORK, + _("Connect to Server"), icon, NULL, + NULL, NULL, NULL, 0, + _("Connect to a network server address")); + g_object_unref (icon); + network_volumes = g_list_reverse (network_volumes); for (l = network_volumes; l != NULL; l = l->next) { volume = l->data; @@ -1783,80 +1792,115 @@ drive_start_from_bookmark_cb (GObject *source_object, } } +static void +open_selected_volume (NautilusPlacesSidebar *sidebar, + GtkTreeModel *model, + GtkTreeIter *iter, + NautilusWindowOpenFlags flags) +{ + GDrive *drive; + GVolume *volume; + NautilusWindowSlot *slot; + + gtk_tree_model_get (model, iter, + PLACES_SIDEBAR_COLUMN_DRIVE, &drive, + PLACES_SIDEBAR_COLUMN_VOLUME, &volume, + -1); + + if (volume != NULL && !sidebar->mounting) { + sidebar->mounting = TRUE; + + g_assert (sidebar->go_to_after_mount_slot == NULL); + + slot = nautilus_window_get_active_slot (sidebar->window); + sidebar->go_to_after_mount_slot = slot; + g_object_add_weak_pointer (G_OBJECT (sidebar->go_to_after_mount_slot), + (gpointer *) &sidebar->go_to_after_mount_slot); + + sidebar->go_to_after_mount_flags = flags; + + nautilus_file_operations_mount_volume_full (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (sidebar))), + volume, + volume_mounted_cb, + G_OBJECT (sidebar)); + } else if (volume == NULL && drive != NULL && + (g_drive_can_start (drive) || g_drive_can_start_degraded (drive))) { + GMountOperation *mount_op; + + mount_op = gtk_mount_operation_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (sidebar)))); + g_drive_start (drive, G_DRIVE_START_NONE, mount_op, NULL, drive_start_from_bookmark_cb, NULL); + g_object_unref (mount_op); + } + + if (drive != NULL) + g_object_unref (drive); + if (volume != NULL) + g_object_unref (volume); +} + +static void +open_selected_uri (NautilusPlacesSidebar *sidebar, + const gchar *uri, + NautilusWindowOpenFlags flags) +{ + NautilusWindowSlot *slot; + GFile *location; + + DEBUG ("Activating bookmark %s", uri); + + location = g_file_new_for_uri (uri); + + /* Navigate to the clicked location */ + if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW) == 0) { + slot = nautilus_window_get_active_slot (sidebar->window); + nautilus_window_slot_open_location (slot, location, flags); + } else { + NautilusWindow *cur, *new; + + cur = NAUTILUS_WINDOW (sidebar->window); + new = nautilus_application_create_window (NAUTILUS_APPLICATION (g_application_get_default ()), + gtk_window_get_screen (GTK_WINDOW (cur))); + nautilus_window_go_to (new, location); + } + + g_object_unref (location); +} + +static void +open_connect_to_server (NautilusPlacesSidebar *sidebar) +{ + NautilusApplication *application = NAUTILUS_APPLICATION (g_application_get_default ()); + GtkWidget *dialog; + + dialog = nautilus_application_connect_server (application, sidebar->window); + gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); +} + static void open_selected_bookmark (NautilusPlacesSidebar *sidebar, GtkTreeModel *model, GtkTreeIter *iter, NautilusWindowOpenFlags flags) { - NautilusWindowSlot *slot; - GFile *location; char *uri; + PlaceType row_type; if (!iter) { return; } - gtk_tree_model_get (model, iter, PLACES_SIDEBAR_COLUMN_URI, &uri, -1); + gtk_tree_model_get (model, iter, + PLACES_SIDEBAR_COLUMN_URI, &uri, + PLACES_SIDEBAR_COLUMN_ROW_TYPE, &row_type, + -1); if (uri != NULL) { - DEBUG ("Activating bookmark %s", uri); - - location = g_file_new_for_uri (uri); - /* Navigate to the clicked location */ - if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW) == 0) { - slot = nautilus_window_get_active_slot (sidebar->window); - nautilus_window_slot_open_location (slot, location, flags); - } else { - NautilusWindow *cur, *new; - - cur = NAUTILUS_WINDOW (sidebar->window); - new = nautilus_application_create_window (NAUTILUS_APPLICATION (g_application_get_default ()), - gtk_window_get_screen (GTK_WINDOW (cur))); - nautilus_window_go_to (new, location); - } - g_object_unref (location); + open_selected_uri (sidebar, uri, flags); g_free (uri); - + } else if (row_type == PLACES_CONNECT_SERVER) { + open_connect_to_server (sidebar); } else { - GDrive *drive; - GVolume *volume; - NautilusWindowSlot *slot; - - gtk_tree_model_get (model, iter, - PLACES_SIDEBAR_COLUMN_DRIVE, &drive, - PLACES_SIDEBAR_COLUMN_VOLUME, &volume, - -1); - - if (volume != NULL && !sidebar->mounting) { - sidebar->mounting = TRUE; - - g_assert (sidebar->go_to_after_mount_slot == NULL); - - slot = nautilus_window_get_active_slot (sidebar->window); - sidebar->go_to_after_mount_slot = slot; - g_object_add_weak_pointer (G_OBJECT (sidebar->go_to_after_mount_slot), - (gpointer *) &sidebar->go_to_after_mount_slot); - - sidebar->go_to_after_mount_flags = flags; - - nautilus_file_operations_mount_volume_full (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (sidebar))), - volume, - volume_mounted_cb, - G_OBJECT (sidebar)); - } else if (volume == NULL && drive != NULL && - (g_drive_can_start (drive) || g_drive_can_start_degraded (drive))) { - GMountOperation *mount_op; - - mount_op = gtk_mount_operation_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (sidebar)))); - g_drive_start (drive, G_DRIVE_START_NONE, mount_op, NULL, drive_start_from_bookmark_cb, NULL); - g_object_unref (mount_op); - } - - if (drive != NULL) - g_object_unref (drive); - if (volume != NULL) - g_object_unref (volume); + open_selected_volume (sidebar, model, iter, flags); } } @@ -2882,7 +2926,8 @@ bookmarks_button_release_event_cb (GtkWidget *widget, PLACES_SIDEBAR_COLUMN_ROW_TYPE, &row_type, -1); - if (row_type != PLACES_HEADING) { + if (row_type != PLACES_HEADING && + row_type != PLACES_CONNECT_SERVER) { bookmarks_popup_menu (sidebar, event); } } @@ -3101,6 +3146,8 @@ places_sidebar_sort_func (GtkTreeModel *model, g_free (name_a); g_free (name_b); + } else if (place_type_a == PLACES_CONNECT_SERVER) { + retval = 1; } return retval;