diff options
author | António Fernandes <antoniof@gnome.org> | 2021-12-17 16:32:50 +0000 |
---|---|---|
committer | António Fernandes <antoniof@gnome.org> | 2022-01-05 12:55:14 +0000 |
commit | f59d1fb228052f047ad0c15cb107292d7394fe0e (patch) | |
tree | f88427f191ea91921daf271bf952b69128bc221e | |
parent | a52412f9ecff4605fd3d5491eb426c6545965145 (diff) | |
download | nautilus-f59d1fb228052f047ad0c15cb107292d7394fe0e.tar.gz |
general: Update copy-pasted GTK code
And update other code for the API changes.
REGRESSION: Populating the sidebar context menu is disabled.
-rwxr-xr-x | src/gtk/gtk-code-generator.sh | 43 | ||||
-rw-r--r-- | src/gtk/nautilusgtkbookmarksmanager.c | 125 | ||||
-rw-r--r-- | src/gtk/nautilusgtkbookmarksmanagerprivate.h (renamed from src/gtk/nautilusgtkbookmarksmanager.h) | 15 | ||||
-rw-r--r-- | src/gtk/nautilusgtkplacessidebar.c | 2623 | ||||
-rw-r--r-- | src/gtk/nautilusgtkplacessidebar.h | 159 | ||||
-rw-r--r-- | src/gtk/nautilusgtkplacessidebarprivate.h | 138 | ||||
-rw-r--r-- | src/gtk/nautilusgtkplacesview.c | 1510 | ||||
-rw-r--r-- | src/gtk/nautilusgtkplacesview.ui | 342 | ||||
-rw-r--r-- | src/gtk/nautilusgtkplacesviewprivate.h | 35 | ||||
-rw-r--r-- | src/gtk/nautilusgtkplacesviewrow.c | 47 | ||||
-rw-r--r-- | src/gtk/nautilusgtkplacesviewrow.ui | 137 | ||||
-rw-r--r-- | src/gtk/nautilusgtkplacesviewrowprivate.h | 2 | ||||
-rw-r--r-- | src/gtk/nautilusgtksidebarrow.c | 102 | ||||
-rw-r--r-- | src/gtk/nautilusgtksidebarrow.ui | 122 | ||||
-rw-r--r-- | src/gtk/nautilusgtksidebarrowprivate.h | 3 | ||||
-rw-r--r-- | src/meson.build | 4 | ||||
-rw-r--r-- | src/nautilus-places-view.c | 8 | ||||
-rw-r--r-- | src/nautilus-window.c | 7 |
18 files changed, 2225 insertions, 3197 deletions
diff --git a/src/gtk/gtk-code-generator.sh b/src/gtk/gtk-code-generator.sh index e6f2ac0d0..4effdc33d 100755 --- a/src/gtk/gtk-code-generator.sh +++ b/src/gtk/gtk-code-generator.sh @@ -5,9 +5,9 @@ # action. # Also remove/add the neccesary bits to make it work inside nautilus -URL=https://gitlab.gnome.org/GNOME/gtk/raw/gtk-3-24/gtk/ -URLUI=https://gitlab.gnome.org/GNOME/gtk/raw/gtk-3-24/gtk/ui/ -SUFIX=?h=gtk-3-24 +URL=https://gitlab.gnome.org/GNOME/gtk/raw/master/gtk/ +URLUI=https://gitlab.gnome.org/GNOME/gtk/raw/master/gtk/ui/ +SUFIX=?h=master # Since comments are not allowed inside the sed line, this is what it will do # by order: @@ -24,27 +24,22 @@ SUFIX=?h=gtk-3-24 # use local sidebar header instead of private gtk one # in-line replace private gtkfilesystem.h helper function # ignore shadowed variable which we would treat as compile error +# use local header instead of private gtk one +# replace private macros with their expansion +# replace private enum type with our own equivalent update_file () { _source="$1" _dest="$2" curl "${_source}" | sed \ - -e 's/gtkplacesview/nautilusgtkplacesview/g' \ - -e 's/gtk_places_view/nautilus_gtk_places_view/g' \ - -e 's/GtkPlacesView/NautilusGtkPlacesView/g' \ - -e 's/GTK_PLACES_VIEW/NAUTILUS_GTK_PLACES_VIEW/g' \ - -e 's/GTK_TYPE_PLACES_VIEW/NAUTILUS_TYPE_GTK_PLACES_VIEW/g' \ - -e 's/GTK_IS_PLACES_VIEW/NAUTILUS_IS_GTK_PLACES_VIEW/g' \ + -e 's/gtkplaces/nautilusgtkplaces/g' \ + -e 's/gtk_places_/nautilus_gtk_places_/g' \ + -e 's/GtkPlaces/NautilusGtkPlaces/g' \ + -e 's/GTK_PLACES_/NAUTILUS_GTK_PLACES_/g' \ + -e 's/GTK_TYPE_PLACES_/NAUTILUS_TYPE_GTK_PLACES_/g' \ + -e 's/GTK_IS_PLACES_/NAUTILUS_IS_GTK_PLACES_/g' \ -e 's/G_DECLARE_FINAL_TYPE (NautilusGtkPlacesViewRow, nautilus_gtk_places_view_row, GTK, PLACES_VIEW_ROW, GtkListBoxRow/ G_DECLARE_FINAL_TYPE (NautilusGtkPlacesViewRow, nautilus_gtk_places_view_row, NAUTILUS, GTK_PLACES_VIEW_ROW, GtkListBoxRow/g' \ - -e 's/gtkplacessidebar/nautilusgtkplacessidebar/g' \ - -e 's/gtk_places_sidebar/nautilus_gtk_places_sidebar/g' \ - -e 's/GtkPlacesSidebar/NautilusGtkPlacesSidebar/g' \ - -e 's/GTK_PLACES_SIDEBAR/NAUTILUS_GTK_PLACES_SIDEBAR/g' \ - -e 's/GTK_TYPE_PLACES_SIDEBAR/NAUTILUS_TYPE_GTK_PLACES_SIDEBAR/g' \ - -e 's/GTK_IS_PLACES_SIDEBAR/NAUTILUS_IS_GTK_PLACES_SIDEBAR/g' \ - -e 's/GtkPlacesOpen/NautilusGtkPlacesOpen/g' \ - -e 's/GTK_PLACES_OPEN/NAUTILUS_GTK_PLACES_OPEN/g' \ -e 's/gtkbookmarksmanager/nautilusgtkbookmarksmanager/g' \ -e 's/gtk_bookmarks_manager/nautilus_gtk_bookmarks_manager/g' \ -e 's/GtkBookmarksManager/NautilusGtkBookmarksManager/g' \ @@ -75,6 +70,8 @@ update_file () { -e "s/P_(\(.*\))/\1/" \ -e "s/I_(\(.*\))/\1/" \ -e '/"config.h"/a #include <gtk\/gtk.h>' \ + -e 's/<gtk\/gtkwidget.h>/<gtk\/gtk.h>/g' \ + -e '/gtkenums.h/d' \ -e '/gtktypebuiltins.h/d' \ -e '/gtkintl.h/d' \ -e '/<gtk\/gtkbox.h>/d' \ @@ -88,7 +85,9 @@ update_file () { -e '/"gtki\(.*\).h"/d' \ -e '/"gtkl\(.*\).h"/d' \ -e '/"gtkm\(.*\).h"/d' \ + -e '/"gtkn\(.*\).h"/d' \ -e '/"gtkpo\(.*\).h"/d' \ + -e '/"gtkpr\(.*\).h"/d' \ -e '/"gtkr\(.*\).h"/d' \ -e '/"gtksc\(.*\).h"/d' \ -e '/"gtkse\(.*\).h"/d' \ @@ -99,9 +98,14 @@ update_file () { -e '/"gtkw\(.*\).h"/d' \ -e '/#error/d' \ -e 's/gtk\/libgtk/gnome\/nautilus\/gtk/g' \ - -e 's/<gtk\/nautilusgtkplacessidebar.h>/"nautilusgtkplacessidebar.h"'/g \ + -e 's/<gtk\/nautilusgtkplacessidebarprivate.h>/"nautilusgtkplacessidebarprivate.h"'/g \ -e 's/_gtk_file_info_consider_as_directory (info)/(g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY || g_file_info_get_file_type (info) == G_FILE_TYPE_MOUNTABLE || g_file_info_get_file_type (info) == G_FILE_TYPE_SHORTCUT)/g' \ -e '/#include "nautilus-trash-monitor.h"/a #pragma GCC diagnostic ignored "-Wshadow"' \ + -e 's/gtk_drag_check_threshold_double/gtk_drag_check_threshold/g' \ + -e 's/NAUTILUS_TYPE_GTK_PLACES_OPEN_FLAGS/NAUTILUS_TYPE_OPEN_FLAGS/g' \ + -e '/"config.h"/a #include "nautilus-enum-types.h"' \ + -e 's/GTK_PARAM_READABLE/G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB/g' \ + -e 's/GTK_PARAM_READWRITE/G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB/g' \ > "${_dest}" } @@ -110,9 +114,8 @@ update_file "${URL}/gtkplacesviewprivate.h${SUFIX}" "nautilusgtkplacesviewprivat update_file "${URLUI}/gtkplacesview.ui${SUFIX}" "nautilusgtkplacesview.ui" update_file "${URL}/gtkplacessidebar.c${SUFIX}" "nautilusgtkplacessidebar.c" update_file "${URL}/gtkplacessidebarprivate.h${SUFIX}" "nautilusgtkplacessidebarprivate.h" -update_file "${URL}/gtkplacessidebar.h${SUFIX}" "nautilusgtkplacessidebar.h" update_file "${URL}/gtkbookmarksmanager.c${SUFIX}" "nautilusgtkbookmarksmanager.c" -update_file "${URL}/gtkbookmarksmanager.h${SUFIX}" "nautilusgtkbookmarksmanager.h" +update_file "${URL}/gtkbookmarksmanagerprivate.h${SUFIX}" "nautilusgtkbookmarksmanagerprivate.h" update_file "${URL}/gtkplacesviewrow.c${SUFIX}" "nautilusgtkplacesviewrow.c" update_file "${URL}/gtkplacesviewrowprivate.h${SUFIX}" "nautilusgtkplacesviewrowprivate.h" update_file "${URLUI}/gtkplacesviewrow.ui${SUFIX}" "nautilusgtkplacesviewrow.ui" diff --git a/src/gtk/nautilusgtkbookmarksmanager.c b/src/gtk/nautilusgtkbookmarksmanager.c index 385d58635..3563fc2f1 100644 --- a/src/gtk/nautilusgtkbookmarksmanager.c +++ b/src/gtk/nautilusgtkbookmarksmanager.c @@ -24,12 +24,13 @@ #include "config.h" #include <glib/gi18n.h> #include <gtk/gtk.h> +#include "nautilus-enum-types.h" #include <string.h> #include <glib/gi18n-lib.h> -#include "nautilusgtkbookmarksmanager.h" +#include "nautilusgtkbookmarksmanagerprivate.h" static void _gtk_bookmark_free (gpointer data) @@ -44,7 +45,7 @@ _gtk_bookmark_free (gpointer data) static void set_error_bookmark_doesnt_exist (GFile *file, GError **error) { - gchar *uri = g_file_get_uri (file); + char *uri = g_file_get_uri (file); g_set_error (error, GTK_FILE_CHOOSER_ERROR, @@ -59,7 +60,7 @@ static GFile * get_legacy_bookmarks_file (void) { GFile *file; - gchar *filename; + char *filename; filename = g_build_filename (g_get_home_dir (), ".gtk-bookmarks", NULL); file = g_file_new_for_path (filename); @@ -72,8 +73,12 @@ static GFile * get_bookmarks_file (void) { GFile *file; - gchar *filename; + char *filename; + /* Use gtk-3.0's bookmarks file as the format didn't change. + * Add the 3.0 file format to get_legacy_bookmarks_file() when + * the format does change. + */ filename = g_build_filename (g_get_user_config_dir (), "gtk-3.0", "bookmarks", NULL); file = g_file_new_for_path (filename); g_free (filename); @@ -82,16 +87,11 @@ get_bookmarks_file (void) } static GSList * -read_bookmarks (GFile *file) +parse_bookmarks (const char *contents) { - gchar *contents; - gchar **lines, *space; + char **lines, *space; GSList *bookmarks = NULL; - gint i; - - if (!g_file_load_contents (file, NULL, &contents, - NULL, NULL, NULL)) - return NULL; + int i; lines = g_strsplit (contents, "\n", -1); @@ -119,12 +119,61 @@ read_bookmarks (GFile *file) bookmarks = g_slist_reverse (bookmarks); g_strfreev (lines); + + return bookmarks; +} + +static GSList * +read_bookmarks (GFile *file) +{ + char *contents; + GSList *bookmarks = NULL; + + if (!g_file_load_contents (file, NULL, &contents, + NULL, NULL, NULL)) + return NULL; + + bookmarks = parse_bookmarks (contents); + g_free (contents); return bookmarks; } static void +notify_changed (NautilusGtkBookmarksManager *manager) +{ + if (manager->changed_func) + manager->changed_func (manager->changed_func_data); +} + +static void +read_bookmarks_finish (GObject *source, + GAsyncResult *result, + gpointer data) +{ + GFile *file = G_FILE (source); + NautilusGtkBookmarksManager *manager = data; + char *contents = NULL; + GError *error = NULL; + + if (!g_file_load_contents_finish (file, result, &contents, NULL, NULL, &error)) + { + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning ("Failed to load '%s': %s", g_file_peek_path (file), error->message); + g_error_free (error); + return; + } + + g_slist_free_full (manager->bookmarks, _gtk_bookmark_free); + manager->bookmarks = parse_bookmarks (contents); + + g_free (contents); + + notify_changed (manager); +} + +static void save_bookmarks (GFile *bookmarks_file, GSList *bookmarks) { @@ -138,7 +187,7 @@ save_bookmarks (GFile *bookmarks_file, for (l = bookmarks; l; l = l->next) { GtkBookmark *bookmark = l->data; - gchar *uri; + char *uri; uri = g_file_get_uri (bookmark->file); if (!uri) @@ -179,13 +228,6 @@ save_bookmarks (GFile *bookmarks_file, } static void -notify_changed (NautilusGtkBookmarksManager *manager) -{ - if (manager->changed_func) - manager->changed_func (manager->changed_func_data); -} - -static void bookmarks_file_changed (GFileMonitor *monitor, GFile *file, GFile *other_file, @@ -199,15 +241,17 @@ bookmarks_file_changed (GFileMonitor *monitor, case G_FILE_MONITOR_EVENT_CHANGED: case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT: case G_FILE_MONITOR_EVENT_CREATED: - case G_FILE_MONITOR_EVENT_DELETED: - g_slist_free_full (manager->bookmarks, _gtk_bookmark_free); - manager->bookmarks = read_bookmarks (file); - - gdk_threads_enter (); - notify_changed (manager); - gdk_threads_leave (); + g_file_load_contents_async (file, manager->cancellable, read_bookmarks_finish, manager); break; + case G_FILE_MONITOR_EVENT_DELETED: + case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED: + case G_FILE_MONITOR_EVENT_PRE_UNMOUNT: + case G_FILE_MONITOR_EVENT_UNMOUNTED: + case G_FILE_MONITOR_EVENT_MOVED: + case G_FILE_MONITOR_EVENT_RENAMED: + case G_FILE_MONITOR_EVENT_MOVED_IN: + case G_FILE_MONITOR_EVENT_MOVED_OUT: default: /* ignore at the moment */ break; @@ -226,9 +270,10 @@ _nautilus_gtk_bookmarks_manager_new (GtkBookmarksChangedFunc changed_func, gpoin manager->changed_func = changed_func; manager->changed_func_data = changed_func_data; + manager->cancellable = g_cancellable_new (); + bookmarks_file = get_bookmarks_file (); - manager->bookmarks = read_bookmarks (bookmarks_file); - if (!manager->bookmarks) + if (!g_file_query_exists (bookmarks_file, NULL)) { GFile *legacy_bookmarks_file; @@ -240,6 +285,8 @@ _nautilus_gtk_bookmarks_manager_new (GtkBookmarksChangedFunc changed_func, gpoin g_object_unref (legacy_bookmarks_file); } + else + g_file_load_contents_async (bookmarks_file, manager->cancellable, read_bookmarks_finish, manager); error = NULL; manager->bookmarks_monitor = g_file_monitor_file (bookmarks_file, @@ -254,6 +301,7 @@ _nautilus_gtk_bookmarks_manager_new (GtkBookmarksChangedFunc changed_func, gpoin manager->bookmarks_monitor_changed_id = g_signal_connect (manager->bookmarks_monitor, "changed", G_CALLBACK (bookmarks_file_changed), manager); + g_object_unref (bookmarks_file); return manager; @@ -264,6 +312,9 @@ _nautilus_gtk_bookmarks_manager_free (NautilusGtkBookmarksManager *manager) { g_return_if_fail (manager != NULL); + g_cancellable_cancel (manager->cancellable); + g_object_unref (manager->cancellable); + if (manager->bookmarks_monitor) { g_file_monitor_cancel (manager->bookmarks_monitor); @@ -339,7 +390,7 @@ _nautilus_gtk_bookmarks_manager_has_bookmark (NautilusGtkBookmarksManager *manag gboolean _nautilus_gtk_bookmarks_manager_insert_bookmark (NautilusGtkBookmarksManager *manager, GFile *file, - gint position, + int position, GError **error) { GSList *link; @@ -353,7 +404,7 @@ _nautilus_gtk_bookmarks_manager_insert_bookmark (NautilusGtkBookmarksManager *ma if (link) { - gchar *uri; + char *uri; bookmark = link->data; uri = g_file_get_uri (bookmark->file); @@ -423,7 +474,7 @@ _nautilus_gtk_bookmarks_manager_remove_bookmark (NautilusGtkBookmarksManager *ma gboolean _nautilus_gtk_bookmarks_manager_reorder_bookmark (NautilusGtkBookmarksManager *manager, GFile *file, - gint new_position, + int new_position, GError **error) { GSList *link; @@ -468,12 +519,12 @@ _nautilus_gtk_bookmarks_manager_reorder_bookmark (NautilusGtkBookmarksManager *m return TRUE; } -gchar * +char * _nautilus_gtk_bookmarks_manager_get_bookmark_label (NautilusGtkBookmarksManager *manager, GFile *file) { GSList *bookmarks; - gchar *label = NULL; + char *label = NULL; g_return_val_if_fail (manager != NULL, NULL); g_return_val_if_fail (file != NULL, NULL); @@ -500,7 +551,7 @@ _nautilus_gtk_bookmarks_manager_get_bookmark_label (NautilusGtkBookmarksManager gboolean _nautilus_gtk_bookmarks_manager_set_bookmark_label (NautilusGtkBookmarksManager *manager, GFile *file, - const gchar *label, + const char *label, GError **error) { GFile *bookmarks_file; @@ -532,7 +583,7 @@ _nautilus_gtk_bookmarks_manager_set_bookmark_label (NautilusGtkBookmarksManager return TRUE; } -gboolean +static gboolean _nautilus_gtk_bookmarks_manager_get_xdg_type (NautilusGtkBookmarksManager *manager, GFile *file, GUserDirectory *directory) @@ -540,7 +591,7 @@ _nautilus_gtk_bookmarks_manager_get_xdg_type (NautilusGtkBookmarksManager *manag GSList *link; gboolean match; GFile *location; - const gchar *path; + const char *path; GUserDirectory dir; GtkBookmark *bookmark; diff --git a/src/gtk/nautilusgtkbookmarksmanager.h b/src/gtk/nautilusgtkbookmarksmanagerprivate.h index 229c61370..99890a331 100644 --- a/src/gtk/nautilusgtkbookmarksmanager.h +++ b/src/gtk/nautilusgtkbookmarksmanagerprivate.h @@ -38,12 +38,14 @@ typedef struct gpointer changed_func_data; GtkBookmarksChangedFunc changed_func; + + GCancellable *cancellable; } NautilusGtkBookmarksManager; typedef struct { GFile *file; - gchar *label; + char *label; } GtkBookmark; NautilusGtkBookmarksManager *_nautilus_gtk_bookmarks_manager_new (GtkBookmarksChangedFunc changed_func, @@ -56,7 +58,7 @@ GSList *_nautilus_gtk_bookmarks_manager_list_bookmarks (NautilusGtkBookmarksMana gboolean _nautilus_gtk_bookmarks_manager_insert_bookmark (NautilusGtkBookmarksManager *manager, GFile *file, - gint position, + int position, GError **error); gboolean _nautilus_gtk_bookmarks_manager_remove_bookmark (NautilusGtkBookmarksManager *manager, @@ -65,23 +67,20 @@ gboolean _nautilus_gtk_bookmarks_manager_remove_bookmark (NautilusGtkBookmarksMa gboolean _nautilus_gtk_bookmarks_manager_reorder_bookmark (NautilusGtkBookmarksManager *manager, GFile *file, - gint new_position, + int new_position, GError **error); gboolean _nautilus_gtk_bookmarks_manager_has_bookmark (NautilusGtkBookmarksManager *manager, GFile *file); -gchar * _nautilus_gtk_bookmarks_manager_get_bookmark_label (NautilusGtkBookmarksManager *manager, +char * _nautilus_gtk_bookmarks_manager_get_bookmark_label (NautilusGtkBookmarksManager *manager, GFile *file); gboolean _nautilus_gtk_bookmarks_manager_set_bookmark_label (NautilusGtkBookmarksManager *manager, GFile *file, - const gchar *label, + const char *label, GError **error); -gboolean _nautilus_gtk_bookmarks_manager_get_xdg_type (NautilusGtkBookmarksManager *manager, - GFile *file, - GUserDirectory *directory); gboolean _nautilus_gtk_bookmarks_manager_get_is_builtin (NautilusGtkBookmarksManager *manager, GFile *file); diff --git a/src/gtk/nautilusgtkplacessidebar.c b/src/gtk/nautilusgtkplacessidebar.c index 71c320d7d..254bfe93e 100644 --- a/src/gtk/nautilusgtkplacessidebar.c +++ b/src/gtk/nautilusgtkplacessidebar.c @@ -24,31 +24,26 @@ #include "config.h" #include <glib/gi18n.h> #include <gtk/gtk.h> +#include "nautilus-enum-types.h" #include <gio/gio.h> #ifdef HAVE_CLOUDPROVIDERS -#include <cloudproviders/cloudproviderscollector.h> -#include <cloudproviders/cloudprovidersaccount.h> -#include <cloudproviders/cloudprovidersprovider.h> +#include <cloudproviders.h> #endif #include "nautilusgtkplacessidebarprivate.h" #include "nautilusgtksidebarrowprivate.h" #include "gdk/gdkkeysyms.h" -#include "nautilusgtkbookmarksmanager.h" -#include "nautilusgtkplacessidebar.h" +#include "nautilusgtkbookmarksmanagerprivate.h" #include "nautilus-trash-monitor.h" #pragma GCC diagnostic ignored "-Wshadow" -/** - * SECTION:nautilusgtkplacessidebar - * @Short_description: Sidebar that displays frequently-used places in the file system - * @Title: NautilusGtkPlacesSidebar - * @See_also: #GtkFileChooser +/*< private > + * NautilusGtkPlacesSidebar: * - * #NautilusGtkPlacesSidebar is a widget that displays a list of frequently-used places in the + * NautilusGtkPlacesSidebar is a widget that displays a list of frequently-used places in the * file system: the user’s home directory, the user’s bookmarks, and volumes and drives. - * This widget is used as a sidebar in #GtkFileChooser and may be used by file managers + * This widget is used as a sidebar in GtkFileChooser and may be used by file managers * and similar programs. * * The places sidebar displays drives and volumes, and will automatically mount @@ -64,7 +59,7 @@ * for a Clipart folder. You can do this with nautilus_gtk_places_sidebar_add_shortcut(). * * To make use of the places sidebar, an application at least needs to connect - * to the #NautilusGtkPlacesSidebar::open-location signal. This is emitted when the + * to the NautilusGtkPlacesSidebar::open-location signal. This is emitted when the * user selects in the sidebar a location to open. The application should also * call nautilus_gtk_places_sidebar_set_location() when it changes the currently-viewed * location. @@ -95,13 +90,16 @@ typedef enum { } DropState; struct _NautilusGtkPlacesSidebar { - GtkScrolledWindow parent; + GtkWidget parent; + GtkWidget *swin; GtkWidget *list_box; GtkWidget *new_bookmark_row; NautilusGtkBookmarksManager *bookmarks_manager; + GActionGroup *row_actions; + #ifdef HAVE_CLOUDPROVIDERS CloudProvidersCollector *cloud_manager; GList *unready_accounts; @@ -116,25 +114,19 @@ struct _NautilusGtkPlacesSidebar { GtkWidget *rename_entry; GtkWidget *rename_button; GtkWidget *rename_error; - gchar *rename_uri; + char *rename_uri; gulong trash_monitor_changed_id; GtkWidget *trash_row; /* DND */ - GList *drag_list; /* list of GFile */ - gint drag_data_info; gboolean dragging_over; - GtkTargetList *source_targets; GtkWidget *drag_row; - gint drag_row_height; - gint drag_row_x; - gint drag_row_y; - gint drag_root_x; - gint drag_root_y; + int drag_row_height; + int drag_row_x; + int drag_row_y; GtkWidget *row_placeholder; DropState drop_state; - GtkGesture *long_press_gesture; /* volume mounting - delayed open process */ NautilusGtkPlacesOpenFlags go_to_after_mount_open_flags; @@ -142,50 +134,37 @@ struct _NautilusGtkPlacesSidebar { GtkWidget *popover; NautilusGtkSidebarRow *context_row; - GSList *shortcuts; + GListStore *shortcuts; GDBusProxy *hostnamed_proxy; GCancellable *hostnamed_cancellable; - gchar *hostname; + char *hostname; NautilusGtkPlacesOpenFlags open_flags; - GActionGroup *action_group; - guint mounting : 1; - guint drag_data_received : 1; - guint drop_occurred : 1; guint show_recent_set : 1; guint show_recent : 1; guint show_desktop_set : 1; guint show_desktop : 1; - guint show_connect_to_server : 1; guint show_enter_location : 1; guint show_other_locations : 1; guint show_trash : 1; guint show_starred_location : 1; - guint local_only : 1; - guint populate_all : 1; }; struct _NautilusGtkPlacesSidebarClass { - GtkScrolledWindowClass parent; + GtkWidgetClass parent_class; void (* open_location) (NautilusGtkPlacesSidebar *sidebar, GFile *location, NautilusGtkPlacesOpenFlags open_flags); - void (* populate_popup) (NautilusGtkPlacesSidebar *sidebar, - GtkMenu *menu, - GFile *selected_item, - GVolume *selected_volume); void (* show_error_message) (NautilusGtkPlacesSidebar *sidebar, - const gchar *primary, - const gchar *secondary); - void (* show_connect_to_server) (NautilusGtkPlacesSidebar *sidebar); + const char *primary, + const char *secondary); GdkDragAction (* drag_action_requested) (NautilusGtkPlacesSidebar *sidebar, - GdkDragContext *context, GFile *dest_file, - GList *source_file_list); + GSList *source_file_list); GdkDragAction (* drag_action_ask) (NautilusGtkPlacesSidebar *sidebar, GdkDragAction actions); void (* drag_perform_drop) (NautilusGtkPlacesSidebar *sidebar, @@ -194,8 +173,6 @@ struct _NautilusGtkPlacesSidebarClass { GdkDragAction action); void (* show_enter_location) (NautilusGtkPlacesSidebar *sidebar); - void (* show_other_locations) (NautilusGtkPlacesSidebar *sidebar); - void (* show_other_locations_with_flags) (NautilusGtkPlacesSidebar *sidebar, NautilusGtkPlacesOpenFlags open_flags); @@ -209,14 +186,11 @@ struct _NautilusGtkPlacesSidebarClass { enum { OPEN_LOCATION, - POPULATE_POPUP, SHOW_ERROR_MESSAGE, - SHOW_CONNECT_TO_SERVER, SHOW_ENTER_LOCATION, DRAG_ACTION_REQUESTED, DRAG_ACTION_ASK, DRAG_PERFORM_DROP, - SHOW_OTHER_LOCATIONS, SHOW_OTHER_LOCATIONS_WITH_FLAGS, SHOW_STARRED_LOCATION, MOUNT, @@ -229,13 +203,10 @@ enum { PROP_OPEN_FLAGS, PROP_SHOW_RECENT, PROP_SHOW_DESKTOP, - PROP_SHOW_CONNECT_TO_SERVER, PROP_SHOW_ENTER_LOCATION, PROP_SHOW_TRASH, PROP_SHOW_STARRED_LOCATION, - PROP_LOCAL_ONLY, PROP_SHOW_OTHER_LOCATIONS, - PROP_POPULATE_ALL, NUM_PROPERTIES }; @@ -270,40 +241,32 @@ static void check_unmount_and_eject (GMount *mount, GDrive *drive, gboolean *show_unmount, gboolean *show_eject); -static gboolean on_button_press_event (GtkWidget *widget, - GdkEventButton *event, - NautilusGtkSidebarRow *sidebar); -static gboolean on_button_release_event (GtkWidget *widget, - GdkEventButton *event, - NautilusGtkSidebarRow *sidebar); +static void on_row_pressed (GtkGestureClick *gesture, + int n_press, + double x, + double y, + NautilusGtkSidebarRow *row); +static void on_row_released (GtkGestureClick *gesture, + int n_press, + double x, + double y, + NautilusGtkSidebarRow *row); +static void on_row_dragged (GtkGestureDrag *gesture, + double x, + double y, + NautilusGtkSidebarRow *row); + static void popup_menu_cb (NautilusGtkSidebarRow *row); static void long_press_cb (GtkGesture *gesture, - gdouble x, - gdouble y, + double x, + double y, NautilusGtkPlacesSidebar *sidebar); static void stop_drop_feedback (NautilusGtkPlacesSidebar *sidebar); static GMountOperation * get_mount_operation (NautilusGtkPlacesSidebar *sidebar); static GMountOperation * get_unmount_operation (NautilusGtkPlacesSidebar *sidebar); -/* Identifiers for target types */ -enum { - DND_UNKNOWN, - DND_NAUTILUS_GTK_SIDEBAR_ROW, - DND_TEXT_URI_LIST -}; - -/* Target types for dragging from the shortcuts list */ -static const GtkTargetEntry dnd_source_targets[] = { - { "DND_NAUTILUS_GTK_SIDEBAR_ROW", GTK_TARGET_SAME_WIDGET, DND_NAUTILUS_GTK_SIDEBAR_ROW } -}; - -/* Target types for dropping into the shortcuts list */ -static const GtkTargetEntry dnd_drop_targets [] = { - { "DND_NAUTILUS_GTK_SIDEBAR_ROW", GTK_TARGET_SAME_WIDGET, DND_NAUTILUS_GTK_SIDEBAR_ROW } -}; - -G_DEFINE_TYPE (NautilusGtkPlacesSidebar, nautilus_gtk_places_sidebar, GTK_TYPE_SCROLLED_WINDOW); +G_DEFINE_TYPE (NautilusGtkPlacesSidebar, nautilus_gtk_places_sidebar, GTK_TYPE_WIDGET); static void emit_open_location (NautilusGtkPlacesSidebar *sidebar, @@ -319,32 +282,20 @@ emit_open_location (NautilusGtkPlacesSidebar *sidebar, static void emit_show_error_message (NautilusGtkPlacesSidebar *sidebar, - const gchar *primary, - const gchar *secondary) + const char *primary, + const char *secondary) { g_signal_emit (sidebar, places_sidebar_signals[SHOW_ERROR_MESSAGE], 0, primary, secondary); } static void -emit_show_connect_to_server (NautilusGtkPlacesSidebar *sidebar) -{ - g_signal_emit (sidebar, places_sidebar_signals[SHOW_CONNECT_TO_SERVER], 0); -} - -static void emit_show_enter_location (NautilusGtkPlacesSidebar *sidebar) { g_signal_emit (sidebar, places_sidebar_signals[SHOW_ENTER_LOCATION], 0); } static void -emit_show_other_locations (NautilusGtkPlacesSidebar *sidebar) -{ - g_signal_emit (sidebar, places_sidebar_signals[SHOW_OTHER_LOCATIONS], 0); -} - -static void emit_show_other_locations_with_flags (NautilusGtkPlacesSidebar *sidebar, NautilusGtkPlacesOpenFlags open_flags) { @@ -377,26 +328,13 @@ emit_unmount_operation (NautilusGtkPlacesSidebar *sidebar, static GdkDragAction emit_drag_action_requested (NautilusGtkPlacesSidebar *sidebar, - GdkDragContext *context, GFile *dest_file, - GList *source_file_list) + GSList *source_file_list) { GdkDragAction ret_action = 0; g_signal_emit (sidebar, places_sidebar_signals[DRAG_ACTION_REQUESTED], 0, - context, dest_file, source_file_list, &ret_action); - - return ret_action; -} - -static GdkDragAction -emit_drag_action_ask (NautilusGtkPlacesSidebar *sidebar, - GdkDragAction actions) -{ - GdkDragAction ret_action = 0; - - g_signal_emit (sidebar, places_sidebar_signals[DRAG_ACTION_ASK], 0, - actions, &ret_action); + dest_file, source_file_list, &ret_action); return ret_action; } @@ -404,7 +342,7 @@ emit_drag_action_ask (NautilusGtkPlacesSidebar *sidebar, static void emit_drag_perform_drop (NautilusGtkPlacesSidebar *sidebar, GFile *dest_file, - GList *source_file_list, + GSList *source_file_list, GdkDragAction action) { g_signal_emit (sidebar, places_sidebar_signals[DRAG_PERFORM_DROP], 0, @@ -415,8 +353,8 @@ list_box_header_func (GtkListBoxRow *row, GtkListBoxRow *before, gpointer user_data) { - NautilusGtkPlacesSidebarSectionType row_section_type; - NautilusGtkPlacesSidebarSectionType before_section_type; + NautilusGtkPlacesSectionType row_section_type; + NautilusGtkPlacesSectionType before_section_type; GtkWidget *separator; gtk_list_box_row_set_header (row, NULL); @@ -428,27 +366,24 @@ list_box_header_func (GtkListBoxRow *row, } else { - before_section_type = SECTION_INVALID; - gtk_widget_set_margin_top (GTK_WIDGET (row), 4); + before_section_type = NAUTILUS_GTK_PLACES_SECTION_INVALID; } if (before && before_section_type != row_section_type) { separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL); - gtk_widget_set_margin_top (separator, 4); - gtk_widget_set_margin_bottom (separator, 4); gtk_list_box_row_set_header (row, separator); } } static GtkWidget* add_place (NautilusGtkPlacesSidebar *sidebar, - NautilusGtkPlacesSidebarPlaceType place_type, - NautilusGtkPlacesSidebarSectionType section_type, - const gchar *name, + NautilusGtkPlacesPlaceType place_type, + NautilusGtkPlacesSectionType section_type, + const char *name, GIcon *start_icon, GIcon *end_icon, - const gchar *uri, + const char *uri, GDrive *drive, GVolume *volume, GMount *mount, @@ -457,20 +392,20 @@ add_place (NautilusGtkPlacesSidebar *sidebar, #else gpointer *cloud_provider_account, #endif - const gint index, - const gchar *tooltip) + const int index, + const char *tooltip) { gboolean show_eject, show_unmount; gboolean show_eject_button; GtkWidget *row; GtkWidget *eject_button; - GtkWidget *event_box; + GtkGesture *gesture; check_unmount_and_eject (mount, volume, drive, &show_unmount, &show_eject); if (show_unmount || show_eject) - g_assert (place_type != PLACES_BOOKMARK); + g_assert (place_type != NAUTILUS_GTK_PLACES_BOOKMARK); show_eject_button = (show_unmount || show_eject); @@ -494,17 +429,24 @@ add_place (NautilusGtkPlacesSidebar *sidebar, NULL); eject_button = nautilus_gtk_sidebar_row_get_eject_button (NAUTILUS_GTK_SIDEBAR_ROW (row)); - event_box = nautilus_gtk_sidebar_row_get_event_box (NAUTILUS_GTK_SIDEBAR_ROW (row)); g_signal_connect_swapped (eject_button, "clicked", G_CALLBACK (eject_or_unmount_bookmark), row); - g_signal_connect (event_box, "button-press-event", - G_CALLBACK (on_button_press_event), row); - g_signal_connect (event_box, "button-release-event", - G_CALLBACK (on_button_release_event), row); - gtk_container_add (GTK_CONTAINER (sidebar->list_box), GTK_WIDGET (row)); - gtk_widget_show_all (row); + gesture = gtk_gesture_click_new (); + gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0); + g_signal_connect (gesture, "pressed", + G_CALLBACK (on_row_pressed), row); + g_signal_connect (gesture, "released", + G_CALLBACK (on_row_released), row); + gtk_widget_add_controller (row, GTK_EVENT_CONTROLLER (gesture)); + + gesture = gtk_gesture_drag_new (); + g_signal_connect (gesture, "drag-update", + G_CALLBACK (on_row_dragged), row); + gtk_widget_add_controller (row, GTK_EVENT_CONTROLLER (gesture)); + + gtk_list_box_insert (GTK_LIST_BOX (sidebar->list_box), GTK_WIDGET (row), -1); return row; } @@ -528,6 +470,7 @@ special_directory_get_gicon (GUserDirectory directory) ICON_CASE (TEMPLATES); ICON_CASE (VIDEOS); + case G_USER_N_DIRECTORIES: default: return g_themed_icon_new_with_default_fallbacks (ICON_NAME_FOLDER); } @@ -550,7 +493,7 @@ recent_files_setting_is_enabled (NautilusGtkPlacesSidebar *sidebar) static gboolean recent_scheme_is_supported (void) { - const gchar * const *supported; + const char * const *supported; supported = g_vfs_get_supported_uri_schemes (g_vfs_get_default ()); if (supported != NULL) @@ -568,11 +511,11 @@ should_show_recent (NautilusGtkPlacesSidebar *sidebar) } static gboolean -path_is_home_dir (const gchar *path) +path_is_home_dir (const char *path) { GFile *home_dir; GFile *location; - const gchar *home_path; + const char *home_path; gboolean res; home_path = g_get_home_dir (); @@ -592,7 +535,7 @@ path_is_home_dir (const gchar *path) static void open_home (NautilusGtkPlacesSidebar *sidebar) { - const gchar *home_path; + const char *home_path; GFile *home_dir; home_path = g_get_home_dir (); @@ -609,17 +552,17 @@ static void add_special_dirs (NautilusGtkPlacesSidebar *sidebar) { GList *dirs; - gint index; + int index; dirs = NULL; for (index = 0; index < G_USER_N_DIRECTORIES; index++) { - const gchar *path; + const char *path; GFile *root; GIcon *start_icon; - gchar *name; - gchar *mount_uri; - gchar *tooltip; + char *name; + char *mount_uri; + char *tooltip; if (!_nautilus_gtk_bookmarks_manager_get_is_xdg_dir_builtin (index)) continue; @@ -645,8 +588,8 @@ add_special_dirs (NautilusGtkPlacesSidebar *sidebar) mount_uri = g_file_get_uri (root); tooltip = g_file_get_parse_name (root); - add_place (sidebar, PLACES_XDG_DIR, - SECTION_COMPUTER, + add_place (sidebar, NAUTILUS_GTK_PLACES_XDG_DIR, + NAUTILUS_GTK_PLACES_SECTION_COMPUTER, name, start_icon, NULL, mount_uri, NULL, NULL, NULL, NULL, 0, tooltip); @@ -656,16 +599,16 @@ add_special_dirs (NautilusGtkPlacesSidebar *sidebar) g_free (mount_uri); g_free (tooltip); - dirs = g_list_prepend (dirs, (gchar *)path); + dirs = g_list_prepend (dirs, (char *)path); } g_list_free (dirs); } -static gchar * +static char * get_home_directory_uri (void) { - const gchar *home; + const char *home; home = g_get_home_dir (); if (!home) @@ -674,10 +617,10 @@ get_home_directory_uri (void) return g_filename_to_uri (home, NULL, NULL); } -static gchar * +static char * get_desktop_directory_uri (void) { - const gchar *name; + const char *name; name = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP); @@ -691,38 +634,21 @@ get_desktop_directory_uri (void) } static gboolean -should_show_file (NautilusGtkPlacesSidebar *sidebar, - GFile *file) -{ - gchar *path; - - if (!sidebar->local_only) - return TRUE; - - path = g_file_get_path (file); - if (path) - { - g_free (path); - return TRUE; - } - - return FALSE; -} - -static gboolean file_is_shown (NautilusGtkPlacesSidebar *sidebar, GFile *file) { - gchar *uri; - GList *rows; - GList *l; + char *uri; + GtkWidget *row; gboolean found = FALSE; - rows = gtk_container_get_children (GTK_CONTAINER (sidebar->list_box)); - l = rows; - while (l != NULL && !found) + for (row = gtk_widget_get_first_child (GTK_WIDGET (sidebar->list_box)); + row != NULL && !found; + row = gtk_widget_get_next_sibling (row)) { - g_object_get (l->data, "uri", &uri, NULL); + if (!GTK_IS_LIST_BOX_ROW (row)) + continue; + + g_object_get (row, "uri", &uri, NULL); if (uri) { GFile *other; @@ -731,47 +657,46 @@ file_is_shown (NautilusGtkPlacesSidebar *sidebar, g_object_unref (other); g_free (uri); } - l = l->next; } - g_list_free (rows); - return found; } +typedef struct +{ + NautilusGtkPlacesSidebar *sidebar; + guint position; +} ShortcutData; + static void on_app_shortcuts_query_complete (GObject *source, GAsyncResult *result, gpointer data) { - NautilusGtkPlacesSidebar *sidebar = data; + ShortcutData *sdata = data; + NautilusGtkPlacesSidebar *sidebar = sdata->sidebar; + guint pos = sdata->position; GFile *file = G_FILE (source); GFileInfo *info; + g_free (sdata); + info = g_file_query_info_finish (file, result, NULL); if (info) { - gchar *uri; - gchar *tooltip; - const gchar *name; + char *uri; + char *tooltip; + const char *name; GIcon *start_icon; - int pos = 0; name = g_file_info_get_display_name (info); start_icon = g_file_info_get_symbolic_icon (info); uri = g_file_get_uri (file); tooltip = g_file_get_parse_name (file); - /* XXX: we could avoid this by using an ancillary closure - * with the index coming from add_application_shortcuts(), - * but in terms of algorithmic overhead, the application - * shortcuts is not going to be really big - */ - pos = g_slist_index (sidebar->shortcuts, file); - - add_place (sidebar, PLACES_BUILT_IN, - SECTION_COMPUTER, + add_place (sidebar, NAUTILUS_GTK_PLACES_BUILT_IN, + NAUTILUS_GTK_PLACES_SECTION_COMPUTER, name, start_icon, NULL, uri, NULL, NULL, NULL, NULL, pos, @@ -787,25 +712,29 @@ on_app_shortcuts_query_complete (GObject *source, static void add_application_shortcuts (NautilusGtkPlacesSidebar *sidebar) { - GSList *l; + guint i, n; - for (l = sidebar->shortcuts; l; l = l->next) + n = g_list_model_get_n_items (G_LIST_MODEL (sidebar->shortcuts)); + for (i = 0; i < n; i++) { - GFile *file = l->data; + GFile *file = g_list_model_get_item (G_LIST_MODEL (sidebar->shortcuts), i); + ShortcutData *data; - if (!should_show_file (sidebar, file)) - continue; + g_object_unref (file); if (file_is_shown (sidebar, file)) continue; + data = g_new (ShortcutData, 1); + data->sidebar = sidebar; + data->position = i; g_file_query_info_async (file, "standard::display-name,standard::symbolic-icon", G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, sidebar->cancellable, on_app_shortcuts_query_complete, - sidebar); + data); } } @@ -825,9 +754,9 @@ on_bookmark_query_info_complete (GObject *source, GFile *root = G_FILE (source); GError *error = NULL; GFileInfo *info; - gchar *bookmark_name; - gchar *mount_uri; - gchar *tooltip; + char *bookmark_name; + char *mount_uri; + char *tooltip; GIcon *start_icon; info = g_file_query_info_finish (root, result, &error); @@ -841,6 +770,9 @@ on_bookmark_query_info_complete (GObject *source, { /* Don't add non-UTF-8 bookmarks */ bookmark_name = g_file_get_basename (root); + if (bookmark_name == NULL) + goto out; + if (!g_utf8_validate (bookmark_name, -1, NULL)) { g_free (bookmark_name); @@ -856,8 +788,8 @@ on_bookmark_query_info_complete (GObject *source, mount_uri = g_file_get_uri (root); tooltip = g_file_get_parse_name (root); - add_place (sidebar, PLACES_BOOKMARK, - SECTION_BOOKMARKS, + add_place (sidebar, NAUTILUS_GTK_PLACES_BOOKMARK, + NAUTILUS_GTK_PLACES_SECTION_BOOKMARKS, bookmark_name, start_icon, NULL, mount_uri, NULL, NULL, NULL, NULL, clos->index, tooltip); @@ -878,7 +810,7 @@ is_external_volume (GVolume *volume) { gboolean is_external; GDrive *drive; - gchar *id; + char *id; drive = g_volume_get_drive (volume); id = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_CLASS); @@ -918,19 +850,20 @@ create_cloud_provider_account_row (NautilusGtkPlacesSidebar *sidebar, { GIcon *end_icon; GIcon *start_icon; - gchar *mount_uri; - gchar *name; - gchar *tooltip; + const char *mount_path; + const char *name; + char *mount_uri; + char *tooltip; guint provider_account_status; start_icon = cloud_providers_account_get_icon (account); name = cloud_providers_account_get_name (account); provider_account_status = cloud_providers_account_get_status (account); - mount_uri = cloud_providers_account_get_path (account); + mount_path = cloud_providers_account_get_path (account); if (start_icon != NULL && name != NULL && provider_account_status != CLOUD_PROVIDERS_ACCOUNT_STATUS_INVALID - && mount_uri != NULL) + && mount_path != NULL) { switch (provider_account_status) { @@ -950,17 +883,20 @@ create_cloud_provider_account_row (NautilusGtkPlacesSidebar *sidebar, return FALSE; } - mount_uri = g_strconcat ("file://", mount_uri, NULL); + mount_uri = g_strconcat ("file://", mount_path, NULL); /* translators: %s is the name of a cloud provider for files */ tooltip = g_strdup_printf (_("Open %s"), name); - add_place (sidebar, PLACES_BUILT_IN, - SECTION_CLOUD, + add_place (sidebar, NAUTILUS_GTK_PLACES_BUILT_IN, + NAUTILUS_GTK_PLACES_SECTION_CLOUD, name, start_icon, end_icon, mount_uri, NULL, NULL, NULL, account, 0, tooltip); + g_free (tooltip); + g_free (mount_uri); + g_object_unref (end_icon); return TRUE; } else @@ -997,22 +933,22 @@ update_places (NautilusGtkPlacesSidebar *sidebar) GList *volumes; GVolume *volume; GSList *bookmarks, *sl; - gint index; - gchar *original_uri, *mount_uri, *name, *identifier; + int index; + char *original_uri, *name, *identifier; GtkListBoxRow *selected; - gchar *home_uri; + char *home_uri; GIcon *start_icon; GFile *root; - gchar *tooltip; + char *tooltip; GList *network_mounts, *network_volumes; GIcon *new_bookmark_icon; + GtkWidget *child; #ifdef HAVE_CLOUDPROVIDERS GList *cloud_providers; GList *cloud_providers_accounts; CloudProvidersAccount *cloud_provider_account; CloudProvidersProvider *cloud_provider; #endif - GtkStyleContext *context; /* save original selection */ selected = gtk_list_box_get_selected_row (GTK_LIST_BOX (sidebar->list_box)); @@ -1029,20 +965,18 @@ update_places (NautilusGtkPlacesSidebar *sidebar) /* Reset drag state, just in case we update the places while dragging or * ending a drag */ stop_drop_feedback (sidebar); - gtk_container_foreach (GTK_CONTAINER (sidebar->list_box), - (GtkCallback) gtk_widget_destroy, - NULL); + while ((child = gtk_widget_get_first_child (GTK_WIDGET (sidebar->list_box)))) + gtk_list_box_remove (GTK_LIST_BOX (sidebar->list_box), child); network_mounts = network_volumes = NULL; /* add built-in places */ if (should_show_recent (sidebar)) { - mount_uri = "recent:///"; start_icon = g_themed_icon_new_with_default_fallbacks ("document-open-recent-symbolic"); - add_place (sidebar, PLACES_BUILT_IN, - SECTION_COMPUTER, - _("Recent"), start_icon, NULL, mount_uri, + add_place (sidebar, NAUTILUS_GTK_PLACES_BUILT_IN, + NAUTILUS_GTK_PLACES_SECTION_COMPUTER, + _("Recent"), start_icon, NULL, "recent:///", NULL, NULL, NULL, NULL, 0, _("Recent files")); g_object_unref (start_icon); @@ -1050,22 +984,20 @@ update_places (NautilusGtkPlacesSidebar *sidebar) if (sidebar->show_starred_location) { - mount_uri = "starred:///"; start_icon = g_themed_icon_new_with_default_fallbacks ("starred-symbolic"); - add_place (sidebar, PLACES_STARRED_LOCATION, - SECTION_COMPUTER, - _("Starred"), start_icon, NULL, mount_uri, + add_place (sidebar, NAUTILUS_GTK_PLACES_STARRED_LOCATION, + NAUTILUS_GTK_PLACES_SECTION_COMPUTER, + _("Starred"), start_icon, NULL, "starred:///", NULL, NULL, NULL, NULL, 0, - /* TODO: Rename to 'Starred files' */ - _("Favorite files")); + _("Starred files")); g_object_unref (start_icon); } /* home folder */ home_uri = get_home_directory_uri (); start_icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_HOME); - add_place (sidebar, PLACES_BUILT_IN, - SECTION_COMPUTER, + add_place (sidebar, NAUTILUS_GTK_PLACES_BUILT_IN, + NAUTILUS_GTK_PLACES_SECTION_COMPUTER, _("Home"), start_icon, NULL, home_uri, NULL, NULL, NULL, NULL, 0, _("Open your personal folder")); @@ -1075,12 +1007,12 @@ update_places (NautilusGtkPlacesSidebar *sidebar) /* desktop */ if (sidebar->show_desktop) { - mount_uri = get_desktop_directory_uri (); + char *mount_uri = get_desktop_directory_uri (); if (mount_uri) { start_icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_DESKTOP); - add_place (sidebar, PLACES_BUILT_IN, - SECTION_COMPUTER, + add_place (sidebar, NAUTILUS_GTK_PLACES_BUILT_IN, + NAUTILUS_GTK_PLACES_SECTION_COMPUTER, _("Desktop"), start_icon, NULL, mount_uri, NULL, NULL, NULL, NULL, 0, _("Open the contents of your desktop in a folder")); @@ -1095,8 +1027,8 @@ update_places (NautilusGtkPlacesSidebar *sidebar) if (sidebar->show_enter_location) { start_icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_NETWORK_SERVER); - add_place (sidebar, PLACES_ENTER_LOCATION, - SECTION_COMPUTER, + add_place (sidebar, NAUTILUS_GTK_PLACES_ENTER_LOCATION, + NAUTILUS_GTK_PLACES_SECTION_COMPUTER, _("Enter Location"), start_icon, NULL, NULL, NULL, NULL, NULL, NULL, 0, _("Manually enter a location")); @@ -1104,11 +1036,11 @@ update_places (NautilusGtkPlacesSidebar *sidebar) } /* Trash */ - if (!sidebar->local_only && sidebar->show_trash) + if (sidebar->show_trash) { start_icon = nautilus_trash_monitor_get_symbolic_icon (); - sidebar->trash_row = add_place (sidebar, PLACES_BUILT_IN, - SECTION_COMPUTER, + sidebar->trash_row = add_place (sidebar, NAUTILUS_GTK_PLACES_BUILT_IN, + NAUTILUS_GTK_PLACES_SECTION_COMPUTER, _("Trash"), start_icon, NULL, "trash:///", NULL, NULL, NULL, NULL, 0, _("Open the trash")); @@ -1190,6 +1122,8 @@ update_places (NautilusGtkPlacesSidebar *sidebar) mount = g_volume_get_mount (volume); if (mount != NULL) { + char *mount_uri; + /* Show mounted volume in the sidebar */ start_icon = g_mount_get_symbolic_icon (mount); root = g_mount_get_default_location (mount); @@ -1197,8 +1131,8 @@ update_places (NautilusGtkPlacesSidebar *sidebar) name = g_mount_get_name (mount); tooltip = g_file_get_parse_name (root); - add_place (sidebar, PLACES_MOUNTED_VOLUME, - SECTION_MOUNTS, + add_place (sidebar, NAUTILUS_GTK_PLACES_MOUNTED_VOLUME, + NAUTILUS_GTK_PLACES_SECTION_MOUNTS, name, start_icon, NULL, mount_uri, drive, volume, mount, NULL, 0, tooltip); g_object_unref (root); @@ -1222,8 +1156,8 @@ update_places (NautilusGtkPlacesSidebar *sidebar) name = g_volume_get_name (volume); tooltip = g_strdup_printf (_("Mount and open “%s”"), name); - add_place (sidebar, PLACES_MOUNTED_VOLUME, - SECTION_MOUNTS, + add_place (sidebar, NAUTILUS_GTK_PLACES_MOUNTED_VOLUME, + NAUTILUS_GTK_PLACES_SECTION_MOUNTS, name, start_icon, NULL, NULL, drive, volume, NULL, NULL, 0, tooltip); g_object_unref (start_icon); @@ -1250,8 +1184,8 @@ update_places (NautilusGtkPlacesSidebar *sidebar) name = g_drive_get_name (drive); tooltip = g_strdup_printf (_("Mount and open “%s”"), name); - add_place (sidebar, PLACES_BUILT_IN, - SECTION_MOUNTS, + add_place (sidebar, NAUTILUS_GTK_PLACES_BUILT_IN, + NAUTILUS_GTK_PLACES_SECTION_MOUNTS, name, start_icon, NULL, NULL, drive, NULL, NULL, NULL, 0, tooltip); g_object_unref (start_icon); @@ -1302,13 +1236,14 @@ update_places (NautilusGtkPlacesSidebar *sidebar) if (mount != NULL) { char *mount_uri; + start_icon = g_mount_get_symbolic_icon (mount); root = g_mount_get_default_location (mount); mount_uri = g_file_get_uri (root); tooltip = g_file_get_parse_name (root); name = g_mount_get_name (mount); - add_place (sidebar, PLACES_MOUNTED_VOLUME, - SECTION_MOUNTS, + add_place (sidebar, NAUTILUS_GTK_PLACES_MOUNTED_VOLUME, + NAUTILUS_GTK_PLACES_SECTION_MOUNTS, name, start_icon, NULL, mount_uri, NULL, volume, mount, NULL, 0, tooltip); g_object_unref (mount); @@ -1323,8 +1258,8 @@ update_places (NautilusGtkPlacesSidebar *sidebar) /* see comment above in why we add an icon for an unmounted mountable volume */ start_icon = g_volume_get_symbolic_icon (volume); name = g_volume_get_name (volume); - add_place (sidebar, PLACES_MOUNTED_VOLUME, - SECTION_MOUNTS, + add_place (sidebar, NAUTILUS_GTK_PLACES_MOUNTED_VOLUME, + NAUTILUS_GTK_PLACES_SECTION_MOUNTS, name, start_icon, NULL, NULL, NULL, volume, NULL, NULL, 0, name); g_object_unref (start_icon); @@ -1337,11 +1272,10 @@ update_places (NautilusGtkPlacesSidebar *sidebar) /* file system root */ if (!sidebar->show_other_locations) { - mount_uri = "file:///"; /* No need to strdup */ start_icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_FILESYSTEM); - add_place (sidebar, PLACES_BUILT_IN, - SECTION_MOUNTS, - sidebar->hostname, start_icon, NULL, mount_uri, + add_place (sidebar, NAUTILUS_GTK_PLACES_BUILT_IN, + NAUTILUS_GTK_PLACES_SECTION_MOUNTS, + sidebar->hostname, start_icon, NULL, "file:///", NULL, NULL, NULL, NULL, 0, _("Open the contents of the file system")); g_object_unref (start_icon); @@ -1352,6 +1286,8 @@ update_places (NautilusGtkPlacesSidebar *sidebar) for (l = mounts; l != NULL; l = l->next) { + char *mount_uri; + mount = l->data; if (g_mount_is_shadowed (mount)) { @@ -1378,8 +1314,8 @@ update_places (NautilusGtkPlacesSidebar *sidebar) mount_uri = g_file_get_uri (root); name = g_mount_get_name (mount); tooltip = g_file_get_parse_name (root); - add_place (sidebar, PLACES_MOUNTED_VOLUME, - SECTION_COMPUTER, + add_place (sidebar, NAUTILUS_GTK_PLACES_MOUNTED_VOLUME, + NAUTILUS_GTK_PLACES_SECTION_COMPUTER, name, start_icon, NULL, mount_uri, NULL, NULL, mount, NULL, 0, tooltip); g_object_unref (root); @@ -1405,9 +1341,6 @@ update_places (NautilusGtkPlacesSidebar *sidebar) if (_nautilus_gtk_bookmarks_manager_get_is_builtin (sidebar->bookmarks_manager, root)) continue; - if (sidebar->local_only && !is_native) - continue; - clos = g_slice_new (BookmarkQueryClosure); clos->sidebar = sidebar; clos->index = index; @@ -1425,77 +1358,65 @@ update_places (NautilusGtkPlacesSidebar *sidebar) /* Add new bookmark row */ new_bookmark_icon = g_themed_icon_new ("bookmark-new-symbolic"); - sidebar->new_bookmark_row = add_place (sidebar, PLACES_DROP_FEEDBACK, - SECTION_BOOKMARKS, + sidebar->new_bookmark_row = add_place (sidebar, NAUTILUS_GTK_PLACES_DROP_FEEDBACK, + NAUTILUS_GTK_PLACES_SECTION_BOOKMARKS, _("New bookmark"), new_bookmark_icon, NULL, NULL, NULL, NULL, NULL, NULL, 0, _("Add a new bookmark")); - context = gtk_widget_get_style_context (sidebar->new_bookmark_row); - gtk_style_context_add_class (context, "sidebar-new-bookmark-row"); + gtk_widget_add_css_class (sidebar->new_bookmark_row, "sidebar-new-bookmark-row"); g_object_unref (new_bookmark_icon); /* network */ - if (!sidebar->local_only) + network_volumes = g_list_reverse (network_volumes); + for (l = network_volumes; l != NULL; l = l->next) { - if (sidebar->show_connect_to_server) - { - start_icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_NETWORK_SERVER); - add_place (sidebar, PLACES_CONNECT_TO_SERVER, - SECTION_MOUNTS, - _("Connect to Server"), start_icon, NULL, - NULL, NULL, NULL, NULL, NULL, 0, - _("Connect to a network server address")); - g_object_unref (start_icon); - } + volume = l->data; + mount = g_volume_get_mount (volume); - network_volumes = g_list_reverse (network_volumes); - for (l = network_volumes; l != NULL; l = l->next) + if (mount != NULL) { - volume = l->data; - mount = g_volume_get_mount (volume); - - if (mount != NULL) - { - network_mounts = g_list_prepend (network_mounts, mount); - continue; - } - else - { - start_icon = g_volume_get_symbolic_icon (volume); - name = g_volume_get_name (volume); - tooltip = g_strdup_printf (_("Mount and open “%s”"), name); - - add_place (sidebar, PLACES_MOUNTED_VOLUME, - SECTION_MOUNTS, - name, start_icon, NULL, NULL, - NULL, volume, NULL, NULL, 0, tooltip); - g_object_unref (start_icon); - g_free (name); - g_free (tooltip); - } + network_mounts = g_list_prepend (network_mounts, mount); + continue; } - - network_mounts = g_list_reverse (network_mounts); - for (l = network_mounts; l != NULL; l = l->next) + else { - mount = l->data; - root = g_mount_get_default_location (mount); - start_icon = g_mount_get_symbolic_icon (mount); - mount_uri = g_file_get_uri (root); - name = g_mount_get_name (mount); - tooltip = g_file_get_parse_name (root); - add_place (sidebar, PLACES_MOUNTED_VOLUME, - SECTION_MOUNTS, - name, start_icon, NULL, mount_uri, - NULL, NULL, mount, NULL, 0, tooltip); - g_object_unref (root); + start_icon = g_volume_get_symbolic_icon (volume); + name = g_volume_get_name (volume); + tooltip = g_strdup_printf (_("Mount and open “%s”"), name); + + add_place (sidebar, NAUTILUS_GTK_PLACES_MOUNTED_VOLUME, + NAUTILUS_GTK_PLACES_SECTION_MOUNTS, + name, start_icon, NULL, NULL, + NULL, volume, NULL, NULL, 0, tooltip); g_object_unref (start_icon); g_free (name); - g_free (mount_uri); g_free (tooltip); } } + network_mounts = g_list_reverse (network_mounts); + for (l = network_mounts; l != NULL; l = l->next) + { + char *mount_uri; + + mount = l->data; + root = g_mount_get_default_location (mount); + start_icon = g_mount_get_symbolic_icon (mount); + mount_uri = g_file_get_uri (root); + name = g_mount_get_name (mount); + tooltip = g_file_get_parse_name (root); + add_place (sidebar, NAUTILUS_GTK_PLACES_MOUNTED_VOLUME, + NAUTILUS_GTK_PLACES_SECTION_MOUNTS, + name, start_icon, NULL, mount_uri, + NULL, NULL, mount, NULL, 0, tooltip); + g_object_unref (root); + g_object_unref (start_icon); + g_free (name); + g_free (mount_uri); + g_free (tooltip); + } + + g_list_free_full (network_volumes, g_object_unref); g_list_free_full (network_mounts, g_object_unref); @@ -1504,15 +1425,15 @@ update_places (NautilusGtkPlacesSidebar *sidebar) { start_icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_OTHER_LOCATIONS); - add_place (sidebar, PLACES_OTHER_LOCATIONS, - SECTION_OTHER_LOCATIONS, + add_place (sidebar, NAUTILUS_GTK_PLACES_OTHER_LOCATIONS, + NAUTILUS_GTK_PLACES_SECTION_OTHER_LOCATIONS, _("Other Locations"), start_icon, NULL, "other-locations:///", NULL, NULL, NULL, NULL, 0, _("Show other locations")); g_object_unref (start_icon); } - gtk_widget_show_all (GTK_WIDGET (sidebar)); + gtk_widget_show (GTK_WIDGET (sidebar)); /* We want this hidden by default, but need to do it after the show_all call */ nautilus_gtk_sidebar_row_hide (NAUTILUS_GTK_SIDEBAR_ROW (sidebar->new_bookmark_row), TRUE); @@ -1531,14 +1452,16 @@ update_places (NautilusGtkPlacesSidebar *sidebar) static gboolean check_valid_drop_target (NautilusGtkPlacesSidebar *sidebar, NautilusGtkSidebarRow *row, - GdkDragContext *context) + const GValue *value) { - NautilusGtkPlacesSidebarPlaceType place_type; - NautilusGtkPlacesSidebarSectionType section_type; + NautilusGtkPlacesPlaceType place_type; + NautilusGtkPlacesSectionType section_type; gboolean valid = FALSE; - gchar *uri; + char *uri; GFile *dest_file; - gint drag_action; + int drag_action; + + g_return_val_if_fail (value != NULL, TRUE); if (row == NULL) return FALSE; @@ -1549,26 +1472,26 @@ check_valid_drop_target (NautilusGtkPlacesSidebar *sidebar, "uri", &uri, NULL); - if (place_type == PLACES_STARRED_LOCATION) + if (place_type == NAUTILUS_GTK_PLACES_STARRED_LOCATION) { g_free (uri); return FALSE; } - if (place_type == PLACES_CONNECT_TO_SERVER) + if (place_type == NAUTILUS_GTK_PLACES_CONNECT_TO_SERVER) { g_free (uri); return FALSE; } - if (place_type == PLACES_DROP_FEEDBACK) + if (place_type == NAUTILUS_GTK_PLACES_DROP_FEEDBACK) { g_free (uri); return TRUE; } /* Disallow drops on recent:/// */ - if (place_type == PLACES_BUILT_IN) + if (place_type == NAUTILUS_GTK_PLACES_BUILT_IN) { if (g_strcmp0 (uri, "recent:///") == 0) { @@ -1578,40 +1501,32 @@ check_valid_drop_target (NautilusGtkPlacesSidebar *sidebar, } /* Dragging a bookmark? */ - if (sidebar->drag_data_received && - sidebar->drag_data_info == DND_NAUTILUS_GTK_SIDEBAR_ROW) + if (G_VALUE_HOLDS (value, NAUTILUS_TYPE_GTK_SIDEBAR_ROW)) { /* Don't allow reordering bookmarks into non-bookmark areas */ - valid = section_type == SECTION_BOOKMARKS; + valid = section_type == NAUTILUS_GTK_PLACES_SECTION_BOOKMARKS; } - else + else if (G_VALUE_HOLDS (value, GDK_TYPE_FILE_LIST)) { /* Dragging a file */ - if (context) + if (uri != NULL) { - if (uri != NULL) - { - dest_file = g_file_new_for_uri (uri); - drag_action = emit_drag_action_requested (sidebar, context, dest_file, sidebar->drag_list); - valid = drag_action > 0; + dest_file = g_file_new_for_uri (uri); + drag_action = emit_drag_action_requested (sidebar, dest_file, g_value_get_boxed (value)); + valid = drag_action > 0; - g_object_unref (dest_file); - } - else - { - valid = FALSE; - } + g_object_unref (dest_file); } else { - /* We cannot discern if it is valid or not because there is not drag - * context available to ask the client. - * Simply make insensitive the drop targets we know are not valid for - * files, that are the ones remaining. - */ - valid = TRUE; + valid = FALSE; } } + else + { + g_assert_not_reached (); + valid = TRUE; + } g_free (uri); return valid; @@ -1619,60 +1534,30 @@ check_valid_drop_target (NautilusGtkPlacesSidebar *sidebar, static void update_possible_drop_targets (NautilusGtkPlacesSidebar *sidebar, - gboolean dragging, - GdkDragContext *context) + const GValue *value) { - GList *rows; - GList *l; - gboolean sensitive; - - rows = gtk_container_get_children (GTK_CONTAINER (sidebar->list_box)); + GtkWidget *row; - for (l = rows; l != NULL; l = l->next) + for (row = gtk_widget_get_first_child (GTK_WIDGET (sidebar->list_box)); + row != NULL; + row = gtk_widget_get_next_sibling (row)) { - sensitive = !dragging || check_valid_drop_target (sidebar, NAUTILUS_GTK_SIDEBAR_ROW (l->data), context); - gtk_widget_set_sensitive (GTK_WIDGET (l->data), sensitive); - } - - g_list_free (rows); -} - -static gboolean -get_drag_data (GtkWidget *list_box, - GdkDragContext *context, - guint time) -{ - GdkAtom target; - - target = gtk_drag_dest_find_target (list_box, context, NULL); - - if (target == GDK_NONE) - return FALSE; + gboolean sensitive; - gtk_drag_get_data (list_box, context, target, time); - - return TRUE; -} - -static void -free_drag_data (NautilusGtkPlacesSidebar *sidebar) -{ - sidebar->drag_data_received = FALSE; + if (!GTK_IS_LIST_BOX_ROW (row)) + continue; - if (sidebar->drag_list) - { - g_list_free_full (sidebar->drag_list, g_object_unref); - sidebar->drag_list = NULL; + sensitive = value == NULL || + check_valid_drop_target (sidebar, NAUTILUS_GTK_SIDEBAR_ROW (row), value); + gtk_widget_set_sensitive (row, sensitive); } - } static void start_drop_feedback (NautilusGtkPlacesSidebar *sidebar, - NautilusGtkSidebarRow *row, - GdkDragContext *context) + const GValue *value) { - if (sidebar->drag_data_info != DND_NAUTILUS_GTK_SIDEBAR_ROW) + if (value && !G_VALUE_HOLDS (value, NAUTILUS_TYPE_GTK_SIDEBAR_ROW)) { nautilus_gtk_sidebar_row_reveal (NAUTILUS_GTK_SIDEBAR_ROW (sidebar->new_bookmark_row)); /* If the state is permanent, don't change it. The application controls it. */ @@ -1680,15 +1565,13 @@ start_drop_feedback (NautilusGtkPlacesSidebar *sidebar, sidebar->drop_state = DROP_STATE_NEW_BOOKMARK_ARMED; } - update_possible_drop_targets (sidebar, TRUE, context); + update_possible_drop_targets (sidebar, value); } static void stop_drop_feedback (NautilusGtkPlacesSidebar *sidebar) { - update_possible_drop_targets (sidebar, FALSE, NULL); - - free_drag_data (sidebar); + update_possible_drop_targets (sidebar, NULL); if (sidebar->drop_state != DROP_STATE_NEW_BOOKMARK_ARMED_PERMANENT && sidebar->new_bookmark_row != NULL) @@ -1705,92 +1588,33 @@ stop_drop_feedback (NautilusGtkPlacesSidebar *sidebar) if (sidebar->row_placeholder != NULL) { - gtk_widget_destroy (sidebar->row_placeholder); + if (gtk_widget_get_parent (sidebar->row_placeholder) != NULL) + gtk_list_box_remove (GTK_LIST_BOX (sidebar->list_box), sidebar->row_placeholder); sidebar->row_placeholder = NULL; } sidebar->dragging_over = FALSE; - sidebar->drag_data_info = DND_UNKNOWN; -} - -static gboolean -on_motion_notify_event (GtkWidget *widget, - GdkEventMotion *event, - gpointer user_data) -{ - NautilusGtkPlacesSidebar *sidebar = NAUTILUS_GTK_PLACES_SIDEBAR (user_data); - - if (sidebar->drag_row == NULL || sidebar->dragging_over) - return FALSE; - - if (!(event->state & GDK_BUTTON1_MASK)) - return FALSE; - - if (gtk_drag_check_threshold (widget, - sidebar->drag_root_x, sidebar->drag_root_y, - event->x_root, event->y_root)) - { - sidebar->dragging_over = TRUE; - - gtk_drag_begin_with_coordinates (widget, sidebar->source_targets, GDK_ACTION_MOVE, - GDK_BUTTON_PRIMARY, (GdkEvent*)event, - -1, -1); - } - - return FALSE; -} - -static void -drag_begin_callback (GtkWidget *widget, - GdkDragContext *context, - gpointer user_data) -{ - NautilusGtkPlacesSidebar *sidebar = NAUTILUS_GTK_PLACES_SIDEBAR (user_data); - GtkAllocation allocation; - GtkWidget *drag_widget; - GtkWidget *window; - - gtk_widget_get_allocation (sidebar->drag_row, &allocation); - gtk_widget_hide (sidebar->drag_row); - - drag_widget = GTK_WIDGET (nautilus_gtk_sidebar_row_clone (NAUTILUS_GTK_SIDEBAR_ROW (sidebar->drag_row))); - window = gtk_window_new (GTK_WINDOW_POPUP); - sidebar->drag_row_height = allocation.height; - gtk_widget_set_size_request (window, allocation.width, allocation.height); - - gtk_container_add (GTK_CONTAINER (window), drag_widget); - gtk_widget_show_all (window); - gtk_widget_set_opacity (window, 0.8); - - gtk_drag_set_icon_widget (context, - window, - sidebar->drag_row_x, - sidebar->drag_row_y); } static GtkWidget * create_placeholder_row (NautilusGtkPlacesSidebar *sidebar) { - return g_object_new (NAUTILUS_TYPE_GTK_SIDEBAR_ROW, - "placeholder", TRUE, - NULL); + return g_object_new (NAUTILUS_TYPE_GTK_SIDEBAR_ROW, "placeholder", TRUE, NULL); } -static gboolean -drag_motion_callback (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - gpointer user_data) -{ - gint action; +static GdkDragAction +drag_motion_callback (GtkDropTarget *target, + double x, + double y, + NautilusGtkPlacesSidebar *sidebar) +{ + GdkDragAction action; GtkListBoxRow *row; - NautilusGtkPlacesSidebar *sidebar = NAUTILUS_GTK_PLACES_SIDEBAR (user_data); - NautilusGtkPlacesSidebarPlaceType place_type; - gchar *drop_target_uri = NULL; - gint row_index; - gint row_placeholder_index; + NautilusGtkPlacesPlaceType place_type; + char *drop_target_uri = NULL; + int row_index; + int row_placeholder_index; + const GValue *value; sidebar->dragging_over = TRUE; action = 0; @@ -1798,24 +1622,22 @@ drag_motion_callback (GtkWidget *widget, gtk_list_box_drag_unhighlight_row (GTK_LIST_BOX (sidebar->list_box)); - /* Nothing to do if no drag data */ - if (!sidebar->drag_data_received && - !get_drag_data (sidebar->list_box, context, time)) + /* Nothing to do if no value yet */ + value = gtk_drop_target_get_value (target); + if (value == NULL) goto out; /* Nothing to do if the target is not valid drop destination */ - if (!check_valid_drop_target (sidebar, NAUTILUS_GTK_SIDEBAR_ROW (row), context)) + if (!check_valid_drop_target (sidebar, NAUTILUS_GTK_SIDEBAR_ROW (row), value)) goto out; - if (sidebar->drag_data_received && - sidebar->drag_data_info == DND_NAUTILUS_GTK_SIDEBAR_ROW) + if (G_VALUE_HOLDS (value, NAUTILUS_TYPE_GTK_SIDEBAR_ROW)) { /* Dragging bookmarks always moves them to another position in the bookmarks list */ action = GDK_ACTION_MOVE; if (sidebar->row_placeholder == NULL) { sidebar->row_placeholder = create_placeholder_row (sidebar); - gtk_widget_show (sidebar->row_placeholder); g_object_ref_sink (sidebar->row_placeholder); } else if (GTK_WIDGET (row) == sidebar->row_placeholder) @@ -1824,15 +1646,10 @@ drag_motion_callback (GtkWidget *widget, } if (gtk_widget_get_parent (sidebar->row_placeholder) != NULL) - { - gtk_container_remove (GTK_CONTAINER (sidebar->list_box), - sidebar->row_placeholder); - } + gtk_list_box_remove (GTK_LIST_BOX (sidebar->list_box), sidebar->row_placeholder); if (row != NULL) { - gint dest_y, dest_x; - g_object_get (row, "order-index", &row_index, NULL); g_object_get (sidebar->row_placeholder, "order-index", &row_placeholder_index, NULL); /* We order the bookmarks sections based on the bookmark index that we @@ -1846,11 +1663,11 @@ drag_motion_callback (GtkWidget *widget, * of the row, we need to increase the order-index. */ row_placeholder_index = row_index; - gtk_widget_translate_coordinates (widget, GTK_WIDGET (row), + gtk_widget_translate_coordinates (GTK_WIDGET (sidebar), GTK_WIDGET (row), x, y, - &dest_x, &dest_y); + &x, &y); - if (dest_y > sidebar->drag_row_height / 2 && row_index > 0) + if (y > sidebar->drag_row_height / 2 && row_index > 0) row_placeholder_index++; } else @@ -1866,7 +1683,7 @@ drag_motion_callback (GtkWidget *widget, gtk_list_box_prepend (GTK_LIST_BOX (sidebar->list_box), sidebar->row_placeholder); } - else + else if (G_VALUE_HOLDS (value, GDK_TYPE_FILE_LIST)) { gtk_list_box_drag_highlight_row (GTK_LIST_BOX (sidebar->list_box), row); @@ -1878,65 +1695,42 @@ drag_motion_callback (GtkWidget *widget, * file move/copy operation itself, or if we should only try to * create bookmarks out of the dragged URIs. */ - if (sidebar->drag_list != NULL) + if (place_type == NAUTILUS_GTK_PLACES_DROP_FEEDBACK) { - if (place_type == PLACES_DROP_FEEDBACK) - { - action = GDK_ACTION_COPY; - } - else + action = GDK_ACTION_COPY; + } + else + { + /* uri may be NULL for unmounted volumes, for example, so we don't allow drops there */ + if (drop_target_uri != NULL) { - /* uri may be NULL for unmounted volumes, for example, so we don't allow drops there */ - if (drop_target_uri != NULL) - { - GFile *dest_file = g_file_new_for_uri (drop_target_uri); + GFile *dest_file = g_file_new_for_uri (drop_target_uri); - action = emit_drag_action_requested (sidebar, context, dest_file, sidebar->drag_list); + action = emit_drag_action_requested (sidebar, dest_file, g_value_get_boxed (value)); - g_object_unref (dest_file); - } + g_object_unref (dest_file); } } g_free (drop_target_uri); } - - out: - start_drop_feedback (sidebar, NAUTILUS_GTK_SIDEBAR_ROW (row), context); - - g_signal_stop_emission_by_name (sidebar->list_box, "drag-motion"); - - gdk_drag_status (context, action, time); - - return TRUE; -} - -/* Takes an array of URIs and turns it into a list of GFile */ -static GList * -build_file_list_from_uris (const gchar **uris) -{ - GList *result; - gint i; - - result = NULL; - for (i = 0; uris && uris[i]; i++) + else { - GFile *file; - - file = g_file_new_for_uri (uris[i]); - result = g_list_prepend (result, file); + g_assert_not_reached (); } - return g_list_reverse (result); + out: + start_drop_feedback (sidebar, value); + return action; } /* Reorders the bookmark to the specified position */ static void reorder_bookmarks (NautilusGtkPlacesSidebar *sidebar, NautilusGtkSidebarRow *row, - gint new_position) + int new_position) { - gchar *uri; + char *uri; GFile *file; g_object_get (row, "uri", &uri, NULL); @@ -1950,10 +1744,10 @@ reorder_bookmarks (NautilusGtkPlacesSidebar *sidebar, /* Creates bookmarks for the specified files at the given position in the bookmarks list */ static void drop_files_as_bookmarks (NautilusGtkPlacesSidebar *sidebar, - GList *files, - gint position) + GSList *files, + int position) { - GList *l; + GSList *l; for (l = files; l; l = l->next) { @@ -1974,76 +1768,26 @@ drop_files_as_bookmarks (NautilusGtkPlacesSidebar *sidebar, } } -static void -drag_data_get_callback (GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *data, - guint info, - guint time, - gpointer user_data) +static gboolean +drag_drop_callback (GtkDropTarget *target, + const GValue *value, + double x, + double y, + NautilusGtkPlacesSidebar *sidebar) { - NautilusGtkPlacesSidebar *sidebar = NAUTILUS_GTK_PLACES_SIDEBAR (user_data); - GdkAtom target = gtk_selection_data_get_target (data); - - if (target == gdk_atom_intern_static_string ("DND_NAUTILUS_GTK_SIDEBAR_ROW")) - { - gtk_selection_data_set (data, - target, - 8, - (void*)&sidebar->drag_row, - sizeof (gpointer)); - } -} - -static void -drag_data_received_callback (GtkWidget *list_box, - GdkDragContext *context, - int x, - int y, - GtkSelectionData *selection_data, - guint info, - guint time, - gpointer user_data) -{ - gint target_order_index; - NautilusGtkPlacesSidebarPlaceType target_place_type; - NautilusGtkPlacesSidebarSectionType target_section_type; - gchar *target_uri; - gboolean success; - NautilusGtkPlacesSidebar *sidebar = NAUTILUS_GTK_PLACES_SIDEBAR (user_data); + int target_order_index; + NautilusGtkPlacesPlaceType target_place_type; + NautilusGtkPlacesSectionType target_section_type; + char *target_uri; GtkListBoxRow *target_row; - - if (!sidebar->drag_data_received) - { - if (gtk_selection_data_get_target (selection_data) != GDK_NONE && - info == DND_TEXT_URI_LIST) - { - gchar **uris; - - uris = gtk_selection_data_get_uris (selection_data); - /* Free spurious drag data from previous drags if present */ - if (sidebar->drag_list != NULL) - g_list_free_full (sidebar->drag_list, g_object_unref); - sidebar->drag_list = build_file_list_from_uris ((const char **) uris); - g_strfreev (uris); - } - else - { - sidebar->drag_list = NULL; - } - sidebar->drag_data_received = TRUE; - sidebar->drag_data_info = info; - } - - g_signal_stop_emission_by_name (list_box, "drag-data-received"); - - if (!sidebar->drop_occurred) - return; + gboolean result; target_row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (sidebar->list_box), y); - if (target_row == NULL) - return; + return FALSE; + + if (!check_valid_drop_target (sidebar, NAUTILUS_GTK_SIDEBAR_ROW (target_row), value)) + return FALSE; g_object_get (target_row, "place-type", &target_place_type, @@ -2051,79 +1795,67 @@ drag_data_received_callback (GtkWidget *list_box, "order-index", &target_order_index, "uri", &target_uri, NULL); + result = FALSE; - success = FALSE; - - if (!check_valid_drop_target (sidebar, NAUTILUS_GTK_SIDEBAR_ROW (target_row), context)) - goto out; - - if (sidebar->drag_data_info == DND_NAUTILUS_GTK_SIDEBAR_ROW) + if (G_VALUE_HOLDS (value, NAUTILUS_TYPE_GTK_SIDEBAR_ROW)) { - GtkWidget **source_row; + GtkWidget *source_row; /* A bookmark got reordered */ - if (target_section_type != SECTION_BOOKMARKS) + if (target_section_type != NAUTILUS_GTK_PLACES_SECTION_BOOKMARKS) goto out; - source_row = (void*) gtk_selection_data_get_data (selection_data); + source_row = g_value_get_object (value); if (sidebar->row_placeholder != NULL) g_object_get (sidebar->row_placeholder, "order-index", &target_order_index, NULL); - reorder_bookmarks (sidebar, NAUTILUS_GTK_SIDEBAR_ROW (*source_row), target_order_index); - success = TRUE; + reorder_bookmarks (sidebar, NAUTILUS_GTK_SIDEBAR_ROW (source_row), target_order_index); + result = TRUE; } - else + else if (G_VALUE_HOLDS (value, GDK_TYPE_FILE_LIST)) { /* Dropping URIs! */ - GdkDragAction real_action; - gchar **uris; - GList *source_file_list; - - /* file transfer requested */ - real_action = gdk_drag_context_get_selected_action (context); - - if (real_action == GDK_ACTION_ASK) - real_action = emit_drag_action_ask (sidebar, gdk_drag_context_get_actions (context)); - - if (real_action > 0) + if (target_place_type == NAUTILUS_GTK_PLACES_DROP_FEEDBACK) { - GFile *dest_file; - - uris = gtk_selection_data_get_uris (selection_data); - source_file_list = build_file_list_from_uris ((const gchar **) uris); - - if (target_place_type == PLACES_DROP_FEEDBACK) - { - drop_files_as_bookmarks (sidebar, source_file_list, target_order_index); - } - else - { - dest_file = g_file_new_for_uri (target_uri); - - emit_drag_perform_drop (sidebar, dest_file, source_file_list, real_action); - - g_object_unref (dest_file); - } - - success = TRUE; - g_list_free_full (source_file_list, g_object_unref); - g_strfreev (uris); + drop_files_as_bookmarks (sidebar, g_value_get_boxed (value), target_order_index); + } + else + { + GFile *dest_file = g_file_new_for_uri (target_uri); + + emit_drag_perform_drop (sidebar, + dest_file, + g_value_get_boxed (value), + gdk_drop_get_actions (gtk_drop_target_get_current_drop (target))); + + g_object_unref (dest_file); } + result = TRUE; + } + else + { + g_assert_not_reached (); } out: - sidebar->drop_occurred = FALSE; - gtk_drag_finish (context, success, FALSE, time); stop_drop_feedback (sidebar); g_free (target_uri); + return result; } static void -drag_end_callback (GtkWidget *widget, - GdkDragContext *context, - gpointer user_data) +dnd_finished_cb (GdkDrag *drag, + NautilusGtkPlacesSidebar *sidebar) { - stop_drop_feedback (NAUTILUS_GTK_PLACES_SIDEBAR (user_data)); + stop_drop_feedback (sidebar); +} + +static void +dnd_cancel_cb (GdkDrag *drag, + GdkDragCancelReason reason, + NautilusGtkPlacesSidebar *sidebar) +{ + stop_drop_feedback (sidebar); } /* This functions is called every time the drag source leaves @@ -2136,50 +1868,28 @@ drag_end_callback (GtkWidget *widget, * but that's not true, because this function is called also before drag_drop, * which needs the data from the drag so we cannot free the drag data here. * So now one could think we could just do nothing here, and wait for - * drag-end or drag-failed signals and just stop_drop_feedback there. But that - * is also not true, since when the drag comes from a diferent widget than the + * drag-end or drag-cancel signals and just stop_drop_feedback there. But that + * is also not true, since when the drag comes from a different widget than the * sidebar, when the drag stops the last drag signal we receive is drag-leave. * So here what we will do is restore the state of the sidebar as if no drag - * is being done (and if the application didnt request for permanent hints with + * is being done (and if the application didn't request for permanent hints with * nautilus_gtk_places_sidebar_show_drop_hints) and we will free the drag data next time * we build new drag data in drag_data_received. */ static void -drag_leave_callback (GtkWidget *widget, - GdkDragContext *context, - guint time, - gpointer user_data) +drag_leave_callback (GtkDropTarget *dest, + gpointer user_data) { NautilusGtkPlacesSidebar *sidebar = NAUTILUS_GTK_PLACES_SIDEBAR (user_data); if (sidebar->drop_state != DROP_STATE_NEW_BOOKMARK_ARMED_PERMANENT) { - update_possible_drop_targets (sidebar, FALSE, context); + update_possible_drop_targets (sidebar, FALSE); nautilus_gtk_sidebar_row_hide (NAUTILUS_GTK_SIDEBAR_ROW (sidebar->new_bookmark_row), FALSE); sidebar->drop_state = DROP_STATE_NORMAL; } - sidebar->drag_data_received = FALSE; sidebar->dragging_over = FALSE; - sidebar->drag_data_info = DND_UNKNOWN; -} - -static gboolean -drag_drop_callback (GtkWidget *list_box, - GdkDragContext *context, - gint x, - gint y, - guint time, - gpointer user_data) -{ - gboolean retval = FALSE; - NautilusGtkPlacesSidebar *sidebar = NAUTILUS_GTK_PLACES_SIDEBAR (user_data); - - sidebar->drop_occurred = TRUE; - retval = get_drag_data (sidebar->list_box, context, time); - g_signal_stop_emission_by_name (sidebar->list_box, "drag-drop"); - - return retval; } static void @@ -2206,160 +1916,14 @@ check_unmount_and_eject (GMount *mount, } static void -check_visibility (GMount *mount, - GVolume *volume, - GDrive *drive, - gboolean *show_mount, - gboolean *show_unmount, - gboolean *show_eject, - gboolean *show_rescan, - gboolean *show_start, - gboolean *show_stop) -{ - *show_mount = FALSE; - *show_rescan = FALSE; - *show_start = FALSE; - *show_stop = FALSE; - - check_unmount_and_eject (mount, volume, drive, show_unmount, show_eject); - - if (drive != NULL) - { - if (g_drive_is_media_removable (drive) && - !g_drive_is_media_check_automatic (drive) && - g_drive_can_poll_for_media (drive)) - *show_rescan = TRUE; - - *show_start = g_drive_can_start (drive) || g_drive_can_start_degraded (drive); - *show_stop = g_drive_can_stop (drive); - - if (*show_stop) - *show_unmount = FALSE; - } - - if (volume != NULL) - { - if (mount == NULL) - *show_mount = g_volume_can_mount (volume); - } -} - -typedef struct { - GtkWidget *add_shortcut_item; - GtkWidget *remove_item; - GtkWidget *rename_item; - GtkWidget *separator_item; - GtkWidget *mount_item; - GtkWidget *unmount_item; - GtkWidget *eject_item; - GtkWidget *rescan_item; - GtkWidget *start_item; - GtkWidget *stop_item; -} PopoverData; - -static void -check_popover_sensitivity (NautilusGtkSidebarRow *row, - PopoverData *data) -{ - gboolean show_mount; - gboolean show_unmount; - gboolean show_eject; - gboolean show_rescan; - gboolean show_start; - gboolean show_stop; - NautilusGtkPlacesSidebarPlaceType type; - GDrive *drive; - GVolume *volume; - GMount *mount; - GtkWidget *sidebar; - GActionGroup *actions; - GAction *action; - - g_object_get (row, - "sidebar", &sidebar, - "place-type", &type, - "drive", &drive, - "volume", &volume, - "mount", &mount, - NULL); - - gtk_widget_set_visible (data->add_shortcut_item, (type == PLACES_MOUNTED_VOLUME)); - - actions = gtk_widget_get_action_group (sidebar, "row"); - action = g_action_map_lookup_action (G_ACTION_MAP (actions), "remove"); - g_simple_action_set_enabled (G_SIMPLE_ACTION (action), (type == PLACES_BOOKMARK)); - action = g_action_map_lookup_action (G_ACTION_MAP (actions), "rename"); - g_simple_action_set_enabled (G_SIMPLE_ACTION (action), (type == PLACES_BOOKMARK || - type == PLACES_XDG_DIR)); - action = g_action_map_lookup_action (G_ACTION_MAP (actions), "open"); - g_simple_action_set_enabled (G_SIMPLE_ACTION (action), !gtk_list_box_row_is_selected (GTK_LIST_BOX_ROW (row))); - - check_visibility (mount, volume, drive, - &show_mount, &show_unmount, &show_eject, &show_rescan, &show_start, &show_stop); - - gtk_widget_set_visible (data->separator_item, show_mount || show_unmount || show_eject); - gtk_widget_set_visible (data->mount_item, show_mount); - gtk_widget_set_visible (data->unmount_item, show_unmount); - gtk_widget_set_visible (data->eject_item, show_eject); - gtk_widget_set_visible (data->rescan_item, show_rescan); - gtk_widget_set_visible (data->start_item, show_start); - gtk_widget_set_visible (data->stop_item, show_stop); - - /* Adjust start/stop items to reflect the type of the drive */ - g_object_set (data->start_item, "text", _("_Start"), NULL); - g_object_set (data->stop_item, "text", _("_Stop"), NULL); - if ((show_start || show_stop) && drive != NULL) - { - switch (g_drive_get_start_stop_type (drive)) - { - case G_DRIVE_START_STOP_TYPE_SHUTDOWN: - /* start() for type G_DRIVE_START_STOP_TYPE_SHUTDOWN is normally not used */ - g_object_set (data->start_item, "text", _("_Power On"), NULL); - g_object_set (data->stop_item, "text", _("_Safely Remove Drive"), NULL); - break; - - case G_DRIVE_START_STOP_TYPE_NETWORK: - g_object_set (data->start_item, "text", _("_Connect Drive"), NULL); - g_object_set (data->stop_item, "text", _("_Disconnect Drive"), NULL); - break; - - case G_DRIVE_START_STOP_TYPE_MULTIDISK: - g_object_set (data->start_item, "text", _("_Start Multi-disk Device"), NULL); - g_object_set (data->stop_item, "text", _("_Stop Multi-disk Device"), NULL); - break; - - case G_DRIVE_START_STOP_TYPE_PASSWORD: - /* stop() for type G_DRIVE_START_STOP_TYPE_PASSWORD is normally not used */ - g_object_set (data->start_item, "text", _("_Unlock Device"), NULL); - g_object_set (data->stop_item, "text", _("_Lock Device"), NULL); - break; - - default: - case G_DRIVE_START_STOP_TYPE_UNKNOWN: - /* uses defaults set above */ - break; - } - } - - if (drive) - g_object_unref (drive); - if (volume) - g_object_unref (volume); - if (mount) - g_object_unref (mount); - - g_object_unref (sidebar); -} - -static void drive_start_from_bookmark_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { NautilusGtkPlacesSidebar *sidebar; GError *error; - gchar *primary; - gchar *name; + char *primary; + char *name; sidebar = NAUTILUS_GTK_PLACES_SIDEBAR (user_data); @@ -2387,8 +1951,8 @@ volume_mount_cb (GObject *source_object, NautilusGtkPlacesSidebar *sidebar; GVolume *volume; GError *error; - gchar *primary; - gchar *name; + char *primary; + char *name; GMount *mount; volume = G_VOLUME (source_object); @@ -2402,6 +1966,9 @@ volume_mount_cb (GObject *source_object, { name = g_volume_get_name (G_VOLUME (source_object)); if (g_str_has_prefix (error->message, "Error unlocking")) + /* Translators: This means that unlocking an encrypted storage + * device failed. %s is the name of the device. + */ primary = g_strdup_printf (_("Error unlocking “%s”"), name); else primary = g_strdup_printf (_("Unable to access “%s”"), name); @@ -2489,7 +2056,7 @@ open_volume (NautilusGtkSidebarRow *row, static void open_uri (NautilusGtkPlacesSidebar *sidebar, - const gchar *uri, + const char *uri, NautilusGtkPlacesOpenFlags open_flags) { GFile *location; @@ -2503,10 +2070,10 @@ static void open_row (NautilusGtkSidebarRow *row, NautilusGtkPlacesOpenFlags open_flags) { - gchar *uri; + char *uri; GDrive *drive; GVolume *volume; - NautilusGtkPlacesSidebarPlaceType place_type; + NautilusGtkPlacesPlaceType place_type; NautilusGtkPlacesSidebar *sidebar; g_object_get (row, @@ -2517,12 +2084,11 @@ open_row (NautilusGtkSidebarRow *row, "volume", &volume, NULL); - if (place_type == PLACES_OTHER_LOCATIONS) + if (place_type == NAUTILUS_GTK_PLACES_OTHER_LOCATIONS) { - emit_show_other_locations (sidebar); emit_show_other_locations_with_flags (sidebar, open_flags); } - else if (place_type == PLACES_STARRED_LOCATION) + else if (place_type == NAUTILUS_GTK_PLACES_STARRED_LOCATION) { emit_show_starred_location (sidebar, open_flags); } @@ -2530,11 +2096,7 @@ open_row (NautilusGtkSidebarRow *row, { open_uri (sidebar, uri, open_flags); } - else if (place_type == PLACES_CONNECT_TO_SERVER) - { - emit_show_connect_to_server (sidebar); - } - else if (place_type == PLACES_ENTER_LOCATION) + else if (place_type == NAUTILUS_GTK_PLACES_ENTER_LOCATION) { emit_show_enter_location (sidebar); } @@ -2575,8 +2137,8 @@ add_shortcut_cb (GSimpleAction *action, gpointer data) { NautilusGtkPlacesSidebar *sidebar = data; - gchar *uri; - gchar *name; + char *uri; + char *name; GFile *location; g_object_get (sidebar->context_row, @@ -2600,15 +2162,14 @@ static void rename_entry_changed (GtkEntry *entry, NautilusGtkPlacesSidebar *sidebar) { - NautilusGtkPlacesSidebarPlaceType type; - gchar *name; - gchar *uri; - const gchar *new_name; + NautilusGtkPlacesPlaceType type; + char *name; + char *uri; + const char *new_name; gboolean found = FALSE; - GList *rows; - GList *l; + GtkWidget *row; - new_name = gtk_entry_get_text (GTK_ENTRY (sidebar->rename_entry)); + new_name = gtk_editable_get_text (GTK_EDITABLE (sidebar->rename_entry)); if (strcmp (new_name, "") == 0) { @@ -2617,16 +2178,20 @@ rename_entry_changed (GtkEntry *entry, return; } - rows = gtk_container_get_children (GTK_CONTAINER (sidebar->list_box)); - for (l = rows; l && !found; l = l->next) + for (row = gtk_widget_get_first_child (GTK_WIDGET (sidebar->list_box)); + row != NULL && !found; + row = gtk_widget_get_next_sibling (row)) { - g_object_get (l->data, + if (!GTK_IS_LIST_BOX_ROW (row)) + continue; + + g_object_get (row, "place-type", &type, "uri", &uri, "label", &name, NULL); - if ((type == PLACES_XDG_DIR || type == PLACES_BOOKMARK) && + if ((type == NAUTILUS_GTK_PLACES_XDG_DIR || type == NAUTILUS_GTK_PLACES_BOOKMARK) && strcmp (uri, sidebar->rename_uri) != 0 && strcmp (new_name, name) == 0) found = TRUE; @@ -2634,7 +2199,6 @@ rename_entry_changed (GtkEntry *entry, g_free (uri); g_free (name); } - g_list_free (rows); gtk_widget_set_sensitive (sidebar->rename_button, !found); gtk_label_set_label (GTK_LABEL (sidebar->rename_error), @@ -2645,10 +2209,10 @@ static void do_rename (GtkButton *button, NautilusGtkPlacesSidebar *sidebar) { - gchar *new_text; + char *new_text; GFile *file; - new_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (sidebar->rename_entry))); + new_text = g_strdup (gtk_editable_get_text (GTK_EDITABLE (sidebar->rename_entry))); file = g_file_new_for_uri (sidebar->rename_uri); if (!_nautilus_gtk_bookmarks_manager_has_bookmark (sidebar->bookmarks_manager, file)) @@ -2687,20 +2251,24 @@ create_rename_popover (NautilusGtkPlacesSidebar *sidebar) GtkWidget *entry; GtkWidget *button; GtkWidget *error; - gchar *str; + char *str; if (sidebar->rename_popover) return; - popover = gtk_popover_new (GTK_WIDGET (sidebar)); + popover = gtk_popover_new (); + gtk_widget_set_parent (popover, GTK_WIDGET (sidebar)); /* Clean sidebar pointer when its destroyed, most of the times due to its * relative_to associated row being destroyed */ g_signal_connect (popover, "destroy", G_CALLBACK (on_rename_popover_destroy), sidebar); gtk_popover_set_position (GTK_POPOVER (popover), GTK_POS_RIGHT); grid = gtk_grid_new (); - gtk_container_add (GTK_CONTAINER (popover), grid); + gtk_popover_set_child (GTK_POPOVER (popover), grid); g_object_set (grid, - "margin", 10, + "margin-start", 10, + "margin-end", 10, + "margin-top", 10, + "margin-bottom", 10, "row-spacing", 6, "column-spacing", 6, NULL); @@ -2714,8 +2282,7 @@ create_rename_popover (NautilusGtkPlacesSidebar *sidebar) gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry); g_free (str); button = gtk_button_new_with_mnemonic (_("_Rename")); - gtk_widget_set_can_default (button, TRUE); - gtk_style_context_add_class (gtk_widget_get_style_context (button), "suggested-action"); + gtk_widget_add_css_class (button, "suggested-action"); g_signal_connect (button, "clicked", G_CALLBACK (do_rename), sidebar); error = gtk_label_new (""); gtk_widget_set_halign (error, GTK_ALIGN_START); @@ -2723,7 +2290,6 @@ create_rename_popover (NautilusGtkPlacesSidebar *sidebar) gtk_grid_attach (GTK_GRID (grid), entry, 0, 1, 1, 1); gtk_grid_attach (GTK_GRID (grid), button,1, 1, 1, 1); gtk_grid_attach (GTK_GRID (grid), error, 0, 2, 2, 1); - gtk_widget_show_all (grid); gtk_popover_set_default_widget (GTK_POPOVER (popover), button); sidebar->rename_popover = popover; @@ -2746,30 +2312,28 @@ static void update_popover_shadowing (GtkWidget *row, gboolean shown) { - GtkStyleContext *context; - gint count; + int count; count = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row), "popover-count")); count = shown ? count + 1 : count - 1; g_object_set_data (G_OBJECT (row), "popover-count", GINT_TO_POINTER (count)); - context = gtk_widget_get_style_context (row); if (count > 0) - gtk_style_context_add_class (context, "has-open-popup"); + gtk_widget_add_css_class (row, "has-open-popup"); else - gtk_style_context_remove_class (context, "has-open-popup"); + gtk_widget_remove_css_class (row, "has-open-popup"); } static void set_prelight (GtkPopover *popover) { - update_popover_shadowing (gtk_popover_get_relative_to (popover), TRUE); + update_popover_shadowing (gtk_widget_get_parent (GTK_WIDGET (popover)), TRUE); } static void unset_prelight (GtkPopover *popover) { - update_popover_shadowing (gtk_popover_get_relative_to (popover), FALSE); + update_popover_shadowing (gtk_widget_get_parent (GTK_WIDGET (popover)), FALSE); } static void @@ -2782,8 +2346,8 @@ setup_popover_shadowing (GtkWidget *popover) static void show_rename_popover (NautilusGtkSidebarRow *row) { - gchar *name; - gchar *uri; + char *name; + char *uri; NautilusGtkPlacesSidebar *sidebar; g_object_get (row, @@ -2798,8 +2362,12 @@ show_rename_popover (NautilusGtkSidebarRow *row) g_free (sidebar->rename_uri); sidebar->rename_uri = g_strdup (uri); - gtk_entry_set_text (GTK_ENTRY (sidebar->rename_entry), name); - gtk_popover_set_relative_to (GTK_POPOVER (sidebar->rename_popover), GTK_WIDGET (row)); + gtk_editable_set_text (GTK_EDITABLE (sidebar->rename_entry), name); + g_object_ref (sidebar->rename_popover); + gtk_widget_unparent (sidebar->rename_popover); + gtk_widget_set_parent (sidebar->rename_popover, GTK_WIDGET (row)); + g_object_unref (sidebar->rename_popover); + setup_popover_shadowing (sidebar->rename_popover); gtk_popover_popup (GTK_POPOVER (sidebar->rename_popover)); @@ -2813,11 +2381,11 @@ show_rename_popover (NautilusGtkSidebarRow *row) static void rename_bookmark (NautilusGtkSidebarRow *row) { - NautilusGtkPlacesSidebarPlaceType type; + NautilusGtkPlacesPlaceType type; g_object_get (row, "place-type", &type, NULL); - if (type != PLACES_BOOKMARK && type != PLACES_XDG_DIR) + if (type != NAUTILUS_GTK_PLACES_BOOKMARK && type != NAUTILUS_GTK_PLACES_XDG_DIR) return; show_rename_popover (row); @@ -2836,8 +2404,8 @@ rename_shortcut_cb (GSimpleAction *action, static void remove_bookmark (NautilusGtkSidebarRow *row) { - NautilusGtkPlacesSidebarPlaceType type; - gchar *uri; + NautilusGtkPlacesPlaceType type; + char *uri; GFile *file; NautilusGtkPlacesSidebar *sidebar; @@ -2847,7 +2415,7 @@ remove_bookmark (NautilusGtkSidebarRow *row) "uri", &uri, NULL); - if (type == PLACES_BOOKMARK) + if (type == NAUTILUS_GTK_PLACES_BOOKMARK) { file = g_file_new_for_uri (uri); _nautilus_gtk_bookmarks_manager_remove_bookmark (sidebar->bookmarks_manager, file, NULL); @@ -2903,8 +2471,8 @@ unmount_mount_cb (GObject *source_object, { if (error->code != G_IO_ERROR_FAILED_HANDLED) { - gchar *name; - gchar *primary; + char *name; + char *primary; name = g_mount_get_name (mount); primary = g_strdup_printf (_("Unable to unmount “%s”"), name); @@ -2924,7 +2492,7 @@ get_mount_operation (NautilusGtkPlacesSidebar *sidebar) { GMountOperation *mount_op; - mount_op = gtk_mount_operation_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (sidebar)))); + mount_op = gtk_mount_operation_new (GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (sidebar)))); emit_mount_operation (sidebar, mount_op); @@ -2936,7 +2504,7 @@ get_unmount_operation (NautilusGtkPlacesSidebar *sidebar) { GMountOperation *mount_op; - mount_op = gtk_mount_operation_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (sidebar)))); + mount_op = gtk_mount_operation_new (GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (sidebar)))); emit_unmount_operation (sidebar, mount_op); @@ -3072,8 +2640,8 @@ drive_stop_cb (GObject *source_object, { NautilusGtkPlacesSidebar *sidebar; GError *error; - gchar *primary; - gchar *name; + char *primary; + char *name; sidebar = user_data; @@ -3101,8 +2669,8 @@ drive_eject_cb (GObject *source_object, { NautilusGtkPlacesSidebar *sidebar; GError *error; - gchar *primary; - gchar *name; + char *primary; + char *name; sidebar = user_data; @@ -3130,8 +2698,8 @@ volume_eject_cb (GObject *source_object, { NautilusGtkPlacesSidebar *sidebar; GError *error; - gchar *primary; - gchar *name; + char *primary; + char *name; sidebar = user_data; @@ -3159,8 +2727,8 @@ mount_eject_cb (GObject *source_object, { NautilusGtkPlacesSidebar *sidebar; GError *error; - gchar *primary; - gchar *name; + char *primary; + char *name; sidebar = user_data; @@ -3307,8 +2875,8 @@ drive_poll_for_media_cb (GObject *source_object, { NautilusGtkPlacesSidebar *sidebar; GError *error; - gchar *primary; - gchar *name; + char *primary; + char *name; sidebar = NAUTILUS_GTK_PLACES_SIDEBAR (user_data); @@ -3355,8 +2923,8 @@ drive_start_cb (GObject *source_object, { NautilusGtkPlacesSidebar *sidebar; GError *error; - gchar *primary; - gchar *name; + char *primary; + char *name; sidebar = NAUTILUS_GTK_PLACES_SIDEBAR (user_data); @@ -3428,64 +2996,62 @@ stop_shortcut_cb (GSimpleAction *action, } static gboolean -on_key_press_event (GtkWidget *widget, - GdkEventKey *event, - NautilusGtkPlacesSidebar *sidebar) +on_key_pressed (GtkEventControllerKey *controller, + guint keyval, + guint keycode, + GdkModifierType state, + NautilusGtkPlacesSidebar *sidebar) { guint modifiers; GtkListBoxRow *row; - if (event) + row = gtk_list_box_get_selected_row (GTK_LIST_BOX (sidebar->list_box)); + if (row) { - row = gtk_list_box_get_selected_row (GTK_LIST_BOX (sidebar->list_box)); - if (row) - { - modifiers = gtk_accelerator_get_default_mod_mask (); - - if (event->keyval == GDK_KEY_Return || - event->keyval == GDK_KEY_KP_Enter || - event->keyval == GDK_KEY_ISO_Enter || - event->keyval == GDK_KEY_space) - { - NautilusGtkPlacesOpenFlags open_flags = NAUTILUS_GTK_PLACES_OPEN_NORMAL; + modifiers = gtk_accelerator_get_default_mod_mask (); - if ((event->state & modifiers) == GDK_SHIFT_MASK) - open_flags = NAUTILUS_GTK_PLACES_OPEN_NEW_TAB; - else if ((event->state & modifiers) == GDK_CONTROL_MASK) - open_flags = NAUTILUS_GTK_PLACES_OPEN_NEW_WINDOW; + if (keyval == GDK_KEY_Return || + keyval == GDK_KEY_KP_Enter || + keyval == GDK_KEY_ISO_Enter || + keyval == GDK_KEY_space) + { + NautilusGtkPlacesOpenFlags open_flags = NAUTILUS_GTK_PLACES_OPEN_NORMAL; - open_row (NAUTILUS_GTK_SIDEBAR_ROW (row), open_flags); + if ((state & modifiers) == GDK_SHIFT_MASK) + open_flags = NAUTILUS_GTK_PLACES_OPEN_NEW_TAB; + else if ((state & modifiers) == GDK_CONTROL_MASK) + open_flags = NAUTILUS_GTK_PLACES_OPEN_NEW_WINDOW; - return TRUE; - } + open_row (NAUTILUS_GTK_SIDEBAR_ROW (row), open_flags); - if (event->keyval == GDK_KEY_Down && - (event->state & modifiers) == GDK_MOD1_MASK) - return eject_or_unmount_selection (sidebar); + return TRUE; + } - if ((event->keyval == GDK_KEY_Delete || - event->keyval == GDK_KEY_KP_Delete) && - (event->state & modifiers) == 0) - { - remove_bookmark (NAUTILUS_GTK_SIDEBAR_ROW (row)); - return TRUE; - } + if (keyval == GDK_KEY_Down && + (state & modifiers) == GDK_ALT_MASK) + return eject_or_unmount_selection (sidebar); - if ((event->keyval == GDK_KEY_F2) && - (event->state & modifiers) == 0) - { - rename_bookmark (NAUTILUS_GTK_SIDEBAR_ROW (row)); - return TRUE; - } + if ((keyval == GDK_KEY_Delete || + keyval == GDK_KEY_KP_Delete) && + (state & modifiers) == 0) + { + remove_bookmark (NAUTILUS_GTK_SIDEBAR_ROW (row)); + return TRUE; + } - if ((event->keyval == GDK_KEY_Menu) || - ((event->keyval == GDK_KEY_F10) && - (event->state & modifiers) == GDK_SHIFT_MASK)) + if ((keyval == GDK_KEY_F2) && + (state & modifiers) == 0) + { + rename_bookmark (NAUTILUS_GTK_SIDEBAR_ROW (row)); + return TRUE; + } - { - popup_menu_cb (NAUTILUS_GTK_SIDEBAR_ROW (row)); - return TRUE; - } + if ((keyval == GDK_KEY_Menu) || + ((keyval == GDK_KEY_F10) && + (state & modifiers) == GDK_SHIFT_MASK)) + { + popup_menu_cb (NAUTILUS_GTK_SIDEBAR_ROW (row)); + return TRUE; } } @@ -3507,70 +3073,6 @@ static GActionEntry entries[] = { }; static void -add_actions (NautilusGtkPlacesSidebar *sidebar) -{ - GActionGroup *actions; - - actions = G_ACTION_GROUP (g_simple_action_group_new ()); - g_action_map_add_action_entries (G_ACTION_MAP (actions), - entries, G_N_ELEMENTS (entries), - sidebar); - gtk_widget_insert_action_group (GTK_WIDGET (sidebar), "row", actions); - g_object_unref (actions); -} - -static GtkWidget * -append_separator (GtkWidget *box) -{ - GtkWidget *separator; - - separator = g_object_new (GTK_TYPE_SEPARATOR, - "orientation", GTK_ORIENTATION_HORIZONTAL, - "visible", TRUE, - "margin-top", 6, - "margin-bottom", 6, - NULL); - gtk_container_add (GTK_CONTAINER (box), separator); - - return separator; -} - -static GtkWidget * -add_button (GtkWidget *box, - const gchar *label, - const gchar *action) -{ - GtkWidget *item; - - item = g_object_new (GTK_TYPE_MODEL_BUTTON, - "visible", TRUE, - "action-name", action, - "text", label, - NULL); - gtk_container_add (GTK_CONTAINER (box), item); - - return item; -} - -static GtkWidget * -add_open_button (GtkWidget *box, - const gchar *label, - NautilusGtkPlacesOpenFlags flags) -{ - GtkWidget *item; - - item = g_object_new (GTK_TYPE_MODEL_BUTTON, - "visible", TRUE, - "action-name", flags == NAUTILUS_GTK_PLACES_OPEN_NORMAL ? "row.open" : "row.open-other", - "action-target", g_variant_new_int32 (flags), - "text", label, - NULL); - gtk_container_add (GTK_CONTAINER (box), item); - - return item; -} - -static void on_row_popover_destroy (GtkWidget *row_popover, NautilusGtkPlacesSidebar *sidebar) { @@ -3598,7 +3100,8 @@ build_popup_menu_using_gmenu (NautilusGtkSidebarRow *row) GMenu *menu = g_menu_new (); GMenuItem *item; item = g_menu_item_new (_("_Open"), "row.open"); - g_menu_item_set_action_and_target_value (item, "row.open", g_variant_new_int32(NAUTILUS_GTK_PLACES_OPEN_NORMAL)); + g_menu_item_set_action_and_target_value (item, "row.open", + g_variant_new_int32 (NAUTILUS_GTK_PLACES_OPEN_NORMAL)); g_menu_append_item (menu, item); if (sidebar->open_flags & NAUTILUS_GTK_PLACES_OPEN_NEW_TAB) { @@ -3621,12 +3124,11 @@ build_popup_menu_using_gmenu (NautilusGtkSidebarRow *row) "cloudprovider", G_ACTION_GROUP (cloud_provider_action_group)); } - add_actions (sidebar); if (sidebar->popover) - gtk_widget_destroy (sidebar->popover); + gtk_widget_unparent (sidebar->popover); - sidebar->popover = gtk_popover_new_from_model (GTK_WIDGET (sidebar), - G_MENU_MODEL (menu)); + sidebar->popover = gtk_popover_menu_new_from_model (G_MENU_MODEL (menu)); + gtk_widget_set_parent (sidebar->popover, GTK_WIDGET (sidebar)); g_signal_connect (sidebar->popover, "destroy", G_CALLBACK (on_row_popover_destroy), sidebar); g_object_unref (sidebar); @@ -3640,8 +3142,24 @@ static void create_row_popover (NautilusGtkPlacesSidebar *sidebar, NautilusGtkSidebarRow *row) { - PopoverData data; - GtkWidget *box; + NautilusGtkPlacesPlaceType type; + GMenu *menu, *section; + GMenuItem *item; + GMount *mount; + GVolume *volume; + GDrive *drive; + GAction *action; + gboolean show_unmount, show_eject; + gboolean show_stop; + + g_object_get (row, + "place-type", &type, + "drive", &drive, + "volume", &volume, + "mount", &mount, + NULL); + + check_unmount_and_eject (mount, volume, drive, &show_unmount, &show_eject); #ifdef HAVE_CLOUDPROVIDERS CloudProvidersAccount *cloud_provider_account; @@ -3651,72 +3169,139 @@ create_row_popover (NautilusGtkPlacesSidebar *sidebar, if (cloud_provider_account) { build_popup_menu_using_gmenu (row); - return; + return; } #endif - sidebar->popover = gtk_popover_new (GTK_WIDGET (sidebar)); - /* Clean sidebar pointer when its destroyed, most of the times due to its - * relative_to associated row being destroyed */ - g_signal_connect (sidebar->popover, "destroy", G_CALLBACK (on_row_popover_destroy), sidebar); - setup_popover_shadowing (sidebar->popover); - box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - g_object_set (box, "margin", 10, NULL); - gtk_widget_show (box); - gtk_container_add (GTK_CONTAINER (sidebar->popover), box); + action = g_action_map_lookup_action (G_ACTION_MAP (sidebar->row_actions), "remove"); + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), (type == NAUTILUS_GTK_PLACES_BOOKMARK)); + action = g_action_map_lookup_action (G_ACTION_MAP (sidebar->row_actions), "rename"); + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), (type == NAUTILUS_GTK_PLACES_BOOKMARK || + type == NAUTILUS_GTK_PLACES_XDG_DIR)); + action = g_action_map_lookup_action (G_ACTION_MAP (sidebar->row_actions), "open"); + g_simple_action_set_enabled (G_SIMPLE_ACTION (action), !gtk_list_box_row_is_selected (GTK_LIST_BOX_ROW (row))); + + menu = g_menu_new (); + section = g_menu_new (); - add_open_button (box, _("_Open"), NAUTILUS_GTK_PLACES_OPEN_NORMAL); + item = g_menu_item_new (_("_Open"), "row.open"); + g_menu_item_set_action_and_target_value (item, "row.open", + g_variant_new_int32 (NAUTILUS_GTK_PLACES_OPEN_NORMAL)); + g_menu_append_item (section, item); + g_object_unref (item); if (sidebar->open_flags & NAUTILUS_GTK_PLACES_OPEN_NEW_TAB) - add_open_button (box, _("Open in New _Tab"), NAUTILUS_GTK_PLACES_OPEN_NEW_TAB); + { + item = g_menu_item_new (_("Open in New _Tab"), "row.open"); + g_menu_item_set_action_and_target_value (item, "row.open", + g_variant_new_int32 (NAUTILUS_GTK_PLACES_OPEN_NEW_TAB)); + g_menu_append_item (section, item); + g_object_unref (item); + } if (sidebar->open_flags & NAUTILUS_GTK_PLACES_OPEN_NEW_WINDOW) - add_open_button (box, _("Open in New _Window"), NAUTILUS_GTK_PLACES_OPEN_NEW_WINDOW); + { + item = g_menu_item_new (_("Open in New _Window"), "row.open"); + g_menu_item_set_action_and_target_value (item, "row.open", + g_variant_new_int32 (NAUTILUS_GTK_PLACES_OPEN_NEW_WINDOW)); + g_menu_append_item (section, item); + g_object_unref (item); + } + + g_menu_append_section (menu, NULL, G_MENU_MODEL (section)); + g_object_unref (section); - append_separator (box); + section = g_menu_new (); + item = g_menu_item_new (_("_Add Bookmark"), "row.add-bookmark"); + g_menu_append_item (section, item); + g_object_unref (item); - data.add_shortcut_item = add_button (box, _("_Add Bookmark"), "row.bookmark"); - data.remove_item = add_button (box, _("_Remove"), "row.remove"); - data.rename_item = add_button (box, _("Rename…"), "row.rename"); + item = g_menu_item_new (_("_Remove"), "row.remove"); + g_menu_append_item (section, item); + g_object_unref (item); - data.separator_item = append_separator (box); + item = g_menu_item_new (_("_Rename"), "row.rename"); + g_menu_append_item (section, item); + g_object_unref (item); - data.mount_item = add_button (box, _("_Mount"), "row.mount"); - data.unmount_item = add_button (box, _("_Unmount"), "row.unmount"); - data.eject_item = add_button (box, _("_Eject"), "row.eject"); - data.rescan_item = add_button (box, _("_Detect Media"), "row.rescan"); - data.start_item = add_button (box, _("_Start"), "row.start"); - data.stop_item = add_button (box, _("_Stop"), "row.stop"); + g_menu_append_section (menu, NULL, G_MENU_MODEL (section)); + g_object_unref (section); - /* Update everything! */ - check_popover_sensitivity (row, &data); + section = g_menu_new (); - if (sidebar->populate_all) + if (volume != NULL && mount == NULL && + g_volume_can_mount (volume)) { - gchar *uri; - GVolume *volume; - GFile *file; + item = g_menu_item_new (_("_Mount"), "row.mount"); + g_menu_append_item (section, item); + g_object_unref (item); + } - g_object_get (row, - "uri", &uri, - "volume", &volume, - NULL); + show_stop = (drive != NULL && g_drive_can_stop (drive)); - if (uri) - file = g_file_new_for_uri (uri); - else - file = NULL; + if (show_unmount && !show_stop) + { + item = g_menu_item_new (_("_Unmount"), "row.unmount"); + g_menu_append_item (section, item); + g_object_unref (item); + } - g_signal_emit (sidebar, places_sidebar_signals[POPULATE_POPUP], 0, - box, file, volume); + if (show_eject) + { + item = g_menu_item_new (_("_Eject"), "row.eject"); + g_menu_append_item (section, item); + g_object_unref (item); + } - if (file) - g_object_unref (file); + if (drive != NULL && + g_drive_is_media_removable (drive) && + !g_drive_is_media_check_automatic (drive) && + g_drive_can_poll_for_media (drive)) + { + item = g_menu_item_new (_("_Detect Media"), "row.rescan"); + g_menu_append_item (section, item); + g_object_unref (item); + } - g_free (uri); - if (volume) - g_object_unref (volume); + if (drive != NULL && + (g_drive_can_start (drive) || g_drive_can_start_degraded (drive))) + { + const guint ss_type = g_drive_get_start_stop_type (drive); + const char *start_label = _("_Start"); + + if (ss_type == G_DRIVE_START_STOP_TYPE_SHUTDOWN) start_label = _("_Power On"); + else if (ss_type == G_DRIVE_START_STOP_TYPE_NETWORK) start_label = _("_Connect Drive"); + else if (ss_type == G_DRIVE_START_STOP_TYPE_MULTIDISK) start_label = _("_Start Multi-disk Device"); + else if (ss_type == G_DRIVE_START_STOP_TYPE_PASSWORD) start_label = _("_Unlock Device"); + + item = g_menu_item_new (start_label, "row.start"); + g_menu_append_item (section, item); + g_object_unref (item); + } + + if (show_stop && !show_unmount) + { + const guint ss_type = g_drive_get_start_stop_type (drive); + const char *stop_label = _("_Stop"); + + if (ss_type == G_DRIVE_START_STOP_TYPE_SHUTDOWN) stop_label = _("_Safely Remove Drive"); + else if (ss_type == G_DRIVE_START_STOP_TYPE_NETWORK) stop_label = _("_Disconnect Drive"); + else if (ss_type == G_DRIVE_START_STOP_TYPE_MULTIDISK) stop_label = _("_Stop Multi-disk Device"); + else if (ss_type == G_DRIVE_START_STOP_TYPE_PASSWORD) stop_label = _("_Lock Device"); + + item = g_menu_item_new (stop_label, "row.stop"); + g_menu_append_item (section, item); + g_object_unref (item); } + + g_menu_append_section (menu, NULL, G_MENU_MODEL (section)); + g_object_unref (section); + + sidebar->popover = gtk_popover_menu_new_from_model (G_MENU_MODEL (menu)); + g_object_unref (menu); + g_signal_connect (sidebar->popover, "destroy", G_CALLBACK (on_row_popover_destroy), sidebar); + + setup_popover_shadowing (sidebar->popover); } static void @@ -3726,12 +3311,11 @@ show_row_popover (NautilusGtkSidebarRow *row) g_object_get (row, "sidebar", &sidebar, NULL); - if (sidebar->popover) - gtk_widget_destroy (sidebar->popover); + g_clear_pointer (&sidebar->popover, gtk_widget_unparent); create_row_popover (sidebar, row); - gtk_popover_set_relative_to (GTK_POPOVER (sidebar->popover), GTK_WIDGET (row)); + gtk_widget_set_parent (sidebar->popover, GTK_WIDGET (row)); sidebar->context_row = row; gtk_popover_popup (GTK_POPOVER (sidebar->popover)); @@ -3757,84 +3341,154 @@ on_row_activated (GtkListBox *list_box, open_row (selected_row, 0); } -static gboolean -on_button_press_event (GtkWidget *widget, - GdkEventButton *event, - NautilusGtkSidebarRow *row) +static void +on_row_pressed (GtkGestureClick *gesture, + int n_press, + double x, + double y, + NautilusGtkSidebarRow *row) { NautilusGtkPlacesSidebar *sidebar; - NautilusGtkPlacesSidebarSectionType section_type; + NautilusGtkPlacesSectionType section_type; + NautilusGtkPlacesPlaceType row_type; - g_object_get (NAUTILUS_GTK_SIDEBAR_ROW (row), + g_object_get (row, "sidebar", &sidebar, "section_type", §ion_type, + "place-type", &row_type, NULL); - if (section_type == SECTION_BOOKMARKS) + if (section_type == NAUTILUS_GTK_PLACES_SECTION_BOOKMARKS) { sidebar->drag_row = GTK_WIDGET (row); - sidebar->drag_row_x = (gint)event->x; - sidebar->drag_row_y = (gint)event->y; - - sidebar->drag_root_x = event->x_root; - sidebar->drag_root_y = event->y_root; + sidebar->drag_row_x = (int)x; + sidebar->drag_row_y = (int)y; } g_object_unref (sidebar); - - return FALSE; } -static gboolean -on_button_release_event (GtkWidget *widget, - GdkEventButton *event, - NautilusGtkSidebarRow *row) +static void +on_row_released (GtkGestureClick *gesture, + int n_press, + double x, + double y, + NautilusGtkSidebarRow *row) { - gboolean ret = FALSE; - NautilusGtkPlacesSidebarPlaceType row_type; + NautilusGtkPlacesSidebar *sidebar; + NautilusGtkPlacesSectionType section_type; + NautilusGtkPlacesPlaceType row_type; + guint button, state; - if (event && row) - { - g_object_get (row, "place-type", &row_type, NULL); + g_object_get (row, + "sidebar", &sidebar, + "section_type", §ion_type, + "place-type", &row_type, + NULL); - if (event->button == 1) - ret = FALSE; - else if (event->button == 2) + button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture)); + state = gtk_event_controller_get_current_event_state (GTK_EVENT_CONTROLLER (gesture)); + + if (row) + { + if (button == 2) { NautilusGtkPlacesOpenFlags open_flags = NAUTILUS_GTK_PLACES_OPEN_NORMAL; - open_flags = (event->state & GDK_CONTROL_MASK) ? - NAUTILUS_GTK_PLACES_OPEN_NEW_WINDOW : - NAUTILUS_GTK_PLACES_OPEN_NEW_TAB; + open_flags = (state & GDK_CONTROL_MASK) ? + NAUTILUS_GTK_PLACES_OPEN_NEW_WINDOW : + NAUTILUS_GTK_PLACES_OPEN_NEW_TAB; open_row (NAUTILUS_GTK_SIDEBAR_ROW (row), open_flags); - ret = TRUE; + gtk_gesture_set_state (GTK_GESTURE (gesture), + GTK_EVENT_SEQUENCE_CLAIMED); } - else if (event->button == 3) + else if (button == 3) { - if (row_type != PLACES_CONNECT_TO_SERVER) + if (row_type != NAUTILUS_GTK_PLACES_CONNECT_TO_SERVER) show_row_popover (NAUTILUS_GTK_SIDEBAR_ROW (row)); } } +} - return ret; +static void +on_row_dragged (GtkGestureDrag *gesture, + double x, + double y, + NautilusGtkSidebarRow *row) +{ + NautilusGtkPlacesSidebar *sidebar; + + g_object_get (row, "sidebar", &sidebar, NULL); + + if (sidebar->drag_row == NULL || sidebar->dragging_over) + { + g_object_unref (sidebar); + return; + } + + if (gtk_drag_check_threshold (GTK_WIDGET (row), 0, 0, x, y)) + { + double start_x, start_y; + double drag_x, drag_y; + GdkContentProvider *content; + GdkSurface *surface; + GdkDevice *device; + GtkAllocation allocation; + GtkWidget *drag_widget; + GdkDrag *drag; + + gtk_gesture_drag_get_start_point (gesture, &start_x, &start_y); + gtk_widget_translate_coordinates (GTK_WIDGET (row), + GTK_WIDGET (sidebar), + start_x, start_y, + &drag_x, &drag_y); + + sidebar->dragging_over = TRUE; + + content = gdk_content_provider_new_typed (NAUTILUS_TYPE_GTK_SIDEBAR_ROW, sidebar->drag_row); + + surface = gtk_native_get_surface (gtk_widget_get_native (GTK_WIDGET (sidebar))); + device = gtk_gesture_get_device (GTK_GESTURE (gesture)); + + drag = gdk_drag_begin (surface, device, content, GDK_ACTION_MOVE, drag_x, drag_y); + + g_object_unref (content); + + g_signal_connect (drag, "dnd-finished", G_CALLBACK (dnd_finished_cb), sidebar); + g_signal_connect (drag, "cancel", G_CALLBACK (dnd_cancel_cb), sidebar); + + gtk_widget_get_allocation (sidebar->drag_row, &allocation); + gtk_widget_hide (sidebar->drag_row); + + drag_widget = GTK_WIDGET (nautilus_gtk_sidebar_row_clone (NAUTILUS_GTK_SIDEBAR_ROW (sidebar->drag_row))); + sidebar->drag_row_height = allocation.height; + gtk_widget_set_size_request (drag_widget, allocation.width, allocation.height); + gtk_widget_set_opacity (drag_widget, 0.8); + + gtk_drag_icon_set_child (GTK_DRAG_ICON (gtk_drag_icon_get_for_drag (drag)), drag_widget); + + g_object_unref (drag); + } + + g_object_unref (sidebar); } static void popup_menu_cb (NautilusGtkSidebarRow *row) { - NautilusGtkPlacesSidebarPlaceType row_type; + NautilusGtkPlacesPlaceType row_type; g_object_get (row, "place-type", &row_type, NULL); - if (row_type != PLACES_CONNECT_TO_SERVER) + if (row_type != NAUTILUS_GTK_PLACES_CONNECT_TO_SERVER) show_row_popover (row); } static void long_press_cb (GtkGesture *gesture, - gdouble x, - gdouble y, + double x, + double y, NautilusGtkPlacesSidebar *sidebar) { GtkWidget *row; @@ -3844,16 +3498,16 @@ long_press_cb (GtkGesture *gesture, popup_menu_cb (NAUTILUS_GTK_SIDEBAR_ROW (row)); } -static gint +static int list_box_sort_func (GtkListBoxRow *row1, GtkListBoxRow *row2, gpointer user_data) { - NautilusGtkPlacesSidebarSectionType section_type_1, section_type_2; - NautilusGtkPlacesSidebarPlaceType place_type_1, place_type_2; - gchar *label_1, *label_2; - gint index_1, index_2; - gint retval = 0; + NautilusGtkPlacesSectionType section_type_1, section_type_2; + NautilusGtkPlacesPlaceType place_type_1, place_type_2; + char *label_1, *label_2; + int index_1, index_2; + int retval = 0; g_object_get (row1, "label", &label_1, @@ -3869,11 +3523,11 @@ list_box_sort_func (GtkListBoxRow *row1, NULL); /* Always last position for "connect to server" */ - if (place_type_1 == PLACES_CONNECT_TO_SERVER) + if (place_type_1 == NAUTILUS_GTK_PLACES_CONNECT_TO_SERVER) { retval = 1; } - else if (place_type_2 == PLACES_CONNECT_TO_SERVER) + else if (place_type_2 == NAUTILUS_GTK_PLACES_CONNECT_TO_SERVER) { retval = -1; } @@ -3881,20 +3535,20 @@ list_box_sort_func (GtkListBoxRow *row1, { if (section_type_1 == section_type_2) { - if ((section_type_1 == SECTION_COMPUTER && + if ((section_type_1 == NAUTILUS_GTK_PLACES_SECTION_COMPUTER && place_type_1 == place_type_2 && - place_type_1 == PLACES_XDG_DIR) || - section_type_1 == SECTION_MOUNTS) + place_type_1 == NAUTILUS_GTK_PLACES_XDG_DIR) || + section_type_1 == NAUTILUS_GTK_PLACES_SECTION_MOUNTS) { retval = g_utf8_collate (label_1, label_2); } - else if ((place_type_1 == PLACES_BOOKMARK || place_type_2 == PLACES_DROP_FEEDBACK) && - (place_type_1 == PLACES_DROP_FEEDBACK || place_type_2 == PLACES_BOOKMARK)) + else if ((place_type_1 == NAUTILUS_GTK_PLACES_BOOKMARK || place_type_2 == NAUTILUS_GTK_PLACES_DROP_FEEDBACK) && + (place_type_1 == NAUTILUS_GTK_PLACES_DROP_FEEDBACK || place_type_2 == NAUTILUS_GTK_PLACES_BOOKMARK)) { retval = index_1 - index_2; } /* We order the bookmarks sections based on the bookmark index that we - * set on the row as a order-index property, but we have to deal with + * set on the row as an order-index property, but we have to deal with * the placeholder row wanted to be between two consecutive bookmarks, * with two consecutive order-index values which is the usual case. * For that, in the list box sort func we give priority to the placeholder row, @@ -3903,14 +3557,14 @@ list_box_sort_func (GtkListBoxRow *row1, * the current row, for instance when the cursor is in the lower half * of the row, we need to increase the order-index. */ - else if (place_type_1 == PLACES_BOOKMARK_PLACEHOLDER && place_type_2 == PLACES_BOOKMARK) + else if (place_type_1 == NAUTILUS_GTK_PLACES_BOOKMARK_PLACEHOLDER && place_type_2 == NAUTILUS_GTK_PLACES_BOOKMARK) { if (index_1 == index_2) retval = index_1 - index_2 - 1; else retval = index_1 - index_2; } - else if (place_type_1 == PLACES_BOOKMARK && place_type_2 == PLACES_BOOKMARK_PLACEHOLDER) + else if (place_type_1 == NAUTILUS_GTK_PLACES_BOOKMARK && place_type_2 == NAUTILUS_GTK_PLACES_BOOKMARK_PLACEHOLDER) { if (index_1 == index_2) retval = index_1 - index_2 + 1; @@ -3937,7 +3591,7 @@ update_hostname (NautilusGtkPlacesSidebar *sidebar) { GVariant *variant; gsize len; - const gchar *hostname; + const char *hostname; if (sidebar->hostnamed_proxy == NULL) return; @@ -4046,13 +3700,19 @@ shell_shows_desktop_changed (GtkSettings *settings, static void nautilus_gtk_places_sidebar_init (NautilusGtkPlacesSidebar *sidebar) { - GtkTargetList *target_list; + GtkDropTarget *target; gboolean show_desktop; - GtkStyleContext *context; + GtkEventController *controller; + GtkGesture *gesture; sidebar->cancellable = g_cancellable_new (); sidebar->show_trash = TRUE; + sidebar->show_other_locations = TRUE; + sidebar->show_recent = TRUE; + sidebar->show_desktop = TRUE; + + sidebar->shortcuts = g_list_store_new (G_TYPE_FILE); create_volume_monitor (sidebar); @@ -4064,19 +3724,19 @@ nautilus_gtk_places_sidebar_init (NautilusGtkPlacesSidebar *sidebar) sidebar->trash_monitor_changed_id = g_signal_connect_swapped (sidebar->trash_monitor, "trash-state-changed", G_CALLBACK (update_trash_icon), sidebar); - gtk_widget_set_size_request (GTK_WIDGET (sidebar), 140, 280); + sidebar->swin = gtk_scrolled_window_new (); + gtk_widget_set_parent (sidebar->swin, GTK_WIDGET (sidebar)); + gtk_widget_set_size_request (sidebar->swin, 140, 280); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sidebar), + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sidebar->swin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sidebar), GTK_SHADOW_IN); - context = gtk_widget_get_style_context (GTK_WIDGET (sidebar)); - gtk_style_context_add_class (context, GTK_STYLE_CLASS_SIDEBAR); - gtk_style_context_set_junction_sides (context, GTK_JUNCTION_RIGHT | GTK_JUNCTION_LEFT); + gtk_widget_add_css_class (GTK_WIDGET (sidebar), "sidebar"); /* list box */ sidebar->list_box = gtk_list_box_new (); + gtk_widget_add_css_class (sidebar->list_box, "navigation-sidebar"); gtk_list_box_set_header_func (GTK_LIST_BOX (sidebar->list_box), list_box_header_func, sidebar, NULL); @@ -4087,48 +3747,33 @@ nautilus_gtk_places_sidebar_init (NautilusGtkPlacesSidebar *sidebar) g_signal_connect (sidebar->list_box, "row-activated", G_CALLBACK (on_row_activated), sidebar); - g_signal_connect (sidebar->list_box, "key-press-event", - G_CALLBACK (on_key_press_event), sidebar); - sidebar->long_press_gesture = gtk_gesture_long_press_new (GTK_WIDGET (sidebar)); - gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (sidebar->long_press_gesture), TRUE); - g_signal_connect (sidebar->long_press_gesture, "pressed", + controller = gtk_event_controller_key_new (); + g_signal_connect (controller, "key-pressed", + G_CALLBACK (on_key_pressed), sidebar); + gtk_widget_add_controller (sidebar->list_box, controller); + + gesture = gtk_gesture_long_press_new (); + gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture), TRUE); + g_signal_connect (gesture, "pressed", G_CALLBACK (long_press_cb), sidebar); + gtk_widget_add_controller (GTK_WIDGET (sidebar), GTK_EVENT_CONTROLLER (gesture)); /* DND support */ - gtk_drag_dest_set (sidebar->list_box, - 0, - NULL, 0, - GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK); - target_list = gtk_target_list_new (dnd_drop_targets, G_N_ELEMENTS (dnd_drop_targets)); - gtk_target_list_add_uri_targets (target_list, DND_TEXT_URI_LIST); - gtk_drag_dest_set_target_list (sidebar->list_box, target_list); - gtk_target_list_unref (target_list); - sidebar->source_targets = gtk_target_list_new (dnd_source_targets, G_N_ELEMENTS (dnd_source_targets)); - gtk_target_list_add_text_targets (sidebar->source_targets, 0); - - g_signal_connect (sidebar->list_box, "motion-notify-event", - G_CALLBACK (on_motion_notify_event), sidebar); - g_signal_connect (sidebar->list_box, "drag-begin", - G_CALLBACK (drag_begin_callback), sidebar); - g_signal_connect (sidebar->list_box, "drag-motion", - G_CALLBACK (drag_motion_callback), sidebar); - g_signal_connect (sidebar->list_box, "drag-data-get", - G_CALLBACK (drag_data_get_callback), sidebar); - g_signal_connect (sidebar->list_box, "drag-data-received", - G_CALLBACK (drag_data_received_callback), sidebar); - g_signal_connect (sidebar->list_box, "drag-drop", - G_CALLBACK (drag_drop_callback), sidebar); - g_signal_connect (sidebar->list_box, "drag-end", - G_CALLBACK (drag_end_callback), sidebar); - g_signal_connect (sidebar->list_box, "drag-leave", - G_CALLBACK (drag_leave_callback), sidebar); + target = gtk_drop_target_new (G_TYPE_INVALID, GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK); + gtk_drop_target_set_preload (target, TRUE); + gtk_drop_target_set_gtypes (target, (GType[2]) { NAUTILUS_TYPE_GTK_SIDEBAR_ROW, GDK_TYPE_FILE_LIST }, 2); + g_signal_connect (target, "enter", G_CALLBACK (drag_motion_callback), sidebar); + g_signal_connect (target, "motion", G_CALLBACK (drag_motion_callback), sidebar); + g_signal_connect (target, "drop", G_CALLBACK (drag_drop_callback), sidebar); + g_signal_connect (target, "leave", G_CALLBACK (drag_leave_callback), sidebar); + gtk_widget_add_controller (sidebar->list_box, GTK_EVENT_CONTROLLER (target)); + sidebar->drag_row = NULL; sidebar->row_placeholder = NULL; sidebar->dragging_over = FALSE; - sidebar->drag_data_info = DND_UNKNOWN; - gtk_container_add (GTK_CONTAINER (sidebar), sidebar->list_box); + gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sidebar->swin), sidebar->list_box); sidebar->hostname = g_strdup (_("Computer")); sidebar->hostnamed_cancellable = g_cancellable_new (); @@ -4163,7 +3808,11 @@ nautilus_gtk_places_sidebar_init (NautilusGtkPlacesSidebar *sidebar) /* populate the sidebar */ update_places (sidebar); - add_actions (sidebar); + sidebar->row_actions = G_ACTION_GROUP (g_simple_action_group_new ()); + g_action_map_add_action_entries (G_ACTION_MAP (sidebar->row_actions), + entries, G_N_ELEMENTS (entries), + sidebar); + gtk_widget_insert_action_group (GTK_WIDGET (sidebar), "row", sidebar->row_actions); } static void @@ -4192,12 +3841,6 @@ nautilus_gtk_places_sidebar_set_property (GObject *obj, nautilus_gtk_places_sidebar_set_show_desktop (sidebar, g_value_get_boolean (value)); break; - case PROP_SHOW_CONNECT_TO_SERVER: -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - nautilus_gtk_places_sidebar_set_show_connect_to_server (sidebar, g_value_get_boolean (value)); -G_GNUC_END_IGNORE_DEPRECATIONS - break; - case PROP_SHOW_ENTER_LOCATION: nautilus_gtk_places_sidebar_set_show_enter_location (sidebar, g_value_get_boolean (value)); break; @@ -4214,18 +3857,6 @@ G_GNUC_END_IGNORE_DEPRECATIONS nautilus_gtk_places_sidebar_set_show_starred_location (sidebar, g_value_get_boolean (value)); break; - case PROP_LOCAL_ONLY: - nautilus_gtk_places_sidebar_set_local_only (sidebar, g_value_get_boolean (value)); - break; - - case PROP_POPULATE_ALL: - if (sidebar->populate_all != g_value_get_boolean (value)) - { - sidebar->populate_all = g_value_get_boolean (value); - g_object_notify_by_pspec (obj, pspec); - } - break; - default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec); break; @@ -4258,12 +3889,6 @@ nautilus_gtk_places_sidebar_get_property (GObject *obj, g_value_set_boolean (value, nautilus_gtk_places_sidebar_get_show_desktop (sidebar)); break; - case PROP_SHOW_CONNECT_TO_SERVER: -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - g_value_set_boolean (value, nautilus_gtk_places_sidebar_get_show_connect_to_server (sidebar)); -G_GNUC_END_IGNORE_DEPRECATIONS - break; - case PROP_SHOW_ENTER_LOCATION: g_value_set_boolean (value, nautilus_gtk_places_sidebar_get_show_enter_location (sidebar)); break; @@ -4280,14 +3905,6 @@ G_GNUC_END_IGNORE_DEPRECATIONS g_value_set_boolean (value, nautilus_gtk_places_sidebar_get_show_starred_location (sidebar)); break; - case PROP_LOCAL_ONLY: - g_value_set_boolean (value, nautilus_gtk_places_sidebar_get_local_only (sidebar)); - break; - - case PROP_POPULATE_ALL: - g_value_set_boolean (value, sidebar->populate_all); - break; - default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec); break; @@ -4311,23 +3928,17 @@ nautilus_gtk_places_sidebar_dispose (GObject *object) sidebar->cancellable = NULL; } - free_drag_data (sidebar); - if (sidebar->bookmarks_manager != NULL) { _nautilus_gtk_bookmarks_manager_free (sidebar->bookmarks_manager); sidebar->bookmarks_manager = NULL; } - if (sidebar->popover) - { - gtk_widget_destroy (sidebar->popover); - sidebar->popover = NULL; - } + g_clear_pointer (&sidebar->popover, gtk_widget_unparent); if (sidebar->rename_popover) { - gtk_widget_destroy (sidebar->rename_popover); + gtk_widget_unparent (sidebar->rename_popover); sidebar->rename_popover = NULL; sidebar->rename_entry = NULL; sidebar->rename_button = NULL; @@ -4373,17 +3984,7 @@ nautilus_gtk_places_sidebar_dispose (GObject *object) g_clear_object (&sidebar->current_location); g_clear_pointer (&sidebar->rename_uri, g_free); - - g_clear_object (&sidebar->long_press_gesture); - - if (sidebar->source_targets) - { - gtk_target_list_unref (sidebar->source_targets); - sidebar->source_targets = NULL; - } - - g_slist_free_full (sidebar->shortcuts, g_object_unref); - sidebar->shortcuts = NULL; + g_clear_object (&sidebar->shortcuts); #ifdef HAVE_CLOUDPROVIDERS for (l = sidebar->unready_accounts; l != NULL; l = l->next) @@ -4392,7 +3993,6 @@ nautilus_gtk_places_sidebar_dispose (GObject *object) } g_list_free_full (sidebar->unready_accounts, g_object_unref); sidebar->unready_accounts = NULL; - if (sidebar->cloud_manager) { g_signal_handlers_disconnect_by_data (sidebar->cloud_manager, sidebar); @@ -4412,10 +4012,53 @@ nautilus_gtk_places_sidebar_dispose (GObject *object) static void nautilus_gtk_places_sidebar_finalize (GObject *object) { + NautilusGtkPlacesSidebar *sidebar = NAUTILUS_GTK_PLACES_SIDEBAR (object); + + g_clear_object (&sidebar->row_actions); + + g_clear_pointer (&sidebar->swin, gtk_widget_unparent); + G_OBJECT_CLASS (nautilus_gtk_places_sidebar_parent_class)->finalize (object); } static void +nautilus_gtk_places_sidebar_measure (GtkWidget *widget, + GtkOrientation orientation, + int for_size, + int *minimum, + int *natural, + int *minimum_baseline, + int *natural_baseline) +{ + NautilusGtkPlacesSidebar *sidebar = NAUTILUS_GTK_PLACES_SIDEBAR (widget); + + gtk_widget_measure (sidebar->swin, + orientation, + for_size, + minimum, natural, + minimum_baseline, natural_baseline); +} + +static void +nautilus_gtk_places_sidebar_size_allocate (GtkWidget *widget, + int width, + int height, + int baseline) +{ + NautilusGtkPlacesSidebar *sidebar = NAUTILUS_GTK_PLACES_SIDEBAR (widget); + + gtk_widget_size_allocate (sidebar->swin, + &(GtkAllocation) { 0, 0, width, height }, + baseline); + + if (sidebar->popover) + gtk_popover_present (GTK_POPOVER (sidebar->popover)); + + if (sidebar->rename_popover) + gtk_popover_present (GTK_POPOVER (sidebar->rename_popover)); +} + +static void nautilus_gtk_places_sidebar_class_init (NautilusGtkPlacesSidebarClass *class) { GObjectClass *gobject_class = G_OBJECT_CLASS (class); @@ -4427,18 +4070,19 @@ nautilus_gtk_places_sidebar_class_init (NautilusGtkPlacesSidebarClass *class) gobject_class->set_property = nautilus_gtk_places_sidebar_set_property; gobject_class->get_property = nautilus_gtk_places_sidebar_get_property; - /** + widget_class->measure = nautilus_gtk_places_sidebar_measure; + widget_class->size_allocate = nautilus_gtk_places_sidebar_size_allocate; + + /* * NautilusGtkPlacesSidebar::open-location: * @sidebar: the object which received the signal. - * @location: (type Gio.File): #GFile to which the caller should switch. - * @open_flags: a single value from #NautilusGtkPlacesOpenFlags specifying how the @location should be opened. + * @location: (type Gio.File): GFile to which the caller should switch. + * @open_flags: a single value from NautilusGtkPlacesOpenFlags specifying how the @location should be opened. * * The places sidebar emits this signal when the user selects a location * in it. The calling application should display the contents of that * location; for example, a file manager should show a list of files in * the specified location. - * - * Since: 3.10 */ places_sidebar_signals [OPEN_LOCATION] = g_signal_new ("open-location", @@ -4449,58 +4093,9 @@ nautilus_gtk_places_sidebar_class_init (NautilusGtkPlacesSidebarClass *class) NULL, G_TYPE_NONE, 2, G_TYPE_OBJECT, - GTK_TYPE_PLACES_OPEN_FLAGS); - - /** - * NautilusGtkPlacesSidebar::populate-popup: - * @sidebar: the object which received the signal. - * @container: (type Gtk.Widget): a #GtkMenu or another #GtkContainer - * @selected_item: (type Gio.File) (nullable): #GFile with the item to which - * the popup should refer, or %NULL in the case of a @selected_volume. - * @selected_volume: (type Gio.Volume) (nullable): #GVolume if the selected - * item is a volume, or %NULL if it is a file. - * - * The places sidebar emits this signal when the user invokes a contextual - * popup on one of its items. In the signal handler, the application may - * add extra items to the menu as appropriate. For example, a file manager - * may want to add a "Properties" command to the menu. - * - * It is not necessary to store the @selected_item for each menu item; - * during their callbacks, the application can use nautilus_gtk_places_sidebar_get_location() - * to get the file to which the item refers. - * - * The @selected_item argument may be %NULL in case the selection refers to - * a volume. In this case, @selected_volume will be non-%NULL. In this case, - * the calling application will have to g_object_ref() the @selected_volume and - * keep it around to use it in the callback. - * - * The @container and all its contents are destroyed after the user - * dismisses the popup. The popup is re-created (and thus, this signal is - * emitted) every time the user activates the contextual menu. - * - * Before 3.18, the @container always was a #GtkMenu, and you were expected - * to add your items as #GtkMenuItems. Since 3.18, the popup may be implemented - * as a #GtkPopover, in which case @container will be something else, e.g. a - * #GtkBox, to which you may add #GtkModelButtons or other widgets, such as - * #GtkEntries, #GtkSpinButtons, etc. If your application can deal with this - * situation, you can set #NautilusGtkPlacesSidebar::populate-all to %TRUE to request - * that this signal is emitted for populating popovers as well. - * - * Since: 3.10 - */ - places_sidebar_signals [POPULATE_POPUP] = - g_signal_new ("populate-popup", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NautilusGtkPlacesSidebarClass, populate_popup), - NULL, NULL, - NULL, - G_TYPE_NONE, 3, - GTK_TYPE_WIDGET, - G_TYPE_FILE, - G_TYPE_VOLUME); + NAUTILUS_TYPE_OPEN_FLAGS); - /** + /* * NautilusGtkPlacesSidebar::show-error-message: * @sidebar: the object which received the signal. * @primary: primary message with a summary of the error to show. @@ -4510,8 +4105,6 @@ nautilus_gtk_places_sidebar_class_init (NautilusGtkPlacesSidebarClass *class) * application to present an error message. Most of these messages * refer to mounting or unmounting media, for example, when a drive * cannot be started for some reason. - * - * Since: 3.10 */ places_sidebar_signals [SHOW_ERROR_MESSAGE] = g_signal_new ("show-error-message", @@ -4524,38 +4117,14 @@ nautilus_gtk_places_sidebar_class_init (NautilusGtkPlacesSidebarClass *class) G_TYPE_STRING, G_TYPE_STRING); - /** - * NautilusGtkPlacesSidebar::show-connect-to-server: - * @sidebar: the object which received the signal. - * - * The places sidebar emits this signal when it needs the calling - * application to present an way to connect directly to a network server. - * For example, the application may bring up a dialog box asking for - * a URL like "sftp://ftp.example.com". It is up to the application to create - * the corresponding mount by using, for example, g_file_mount_enclosing_volume(). - * - * Deprecated: 3.18: use the #NautilusGtkPlacesSidebar::show-other-locations signal - * to connect to network servers. - */ - places_sidebar_signals [SHOW_CONNECT_TO_SERVER] = - g_signal_new ("show-connect-to-server", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NautilusGtkPlacesSidebarClass, show_connect_to_server), - NULL, NULL, - NULL, - G_TYPE_NONE, 0); - - /** + /* * NautilusGtkPlacesSidebar::show-enter-location: * @sidebar: the object which received the signal. * * The places sidebar emits this signal when it needs the calling - * application to present an way to directly enter a location. + * application to present a way to directly enter a location. * For example, the application may bring up a dialog box asking for * a URL like "http://http.example.com". - * - * Since: 3.14 */ places_sidebar_signals [SHOW_ENTER_LOCATION] = g_signal_new ("show-enter-location", @@ -4566,13 +4135,13 @@ nautilus_gtk_places_sidebar_class_init (NautilusGtkPlacesSidebarClass *class) NULL, G_TYPE_NONE, 0); - /** + /* * NautilusGtkPlacesSidebar::drag-action-requested: * @sidebar: the object which received the signal. - * @context: (type Gdk.DragContext): #GdkDragContext with information about the drag operation - * @dest_file: (type Gio.File): #GFile with the tentative location that is being hovered for a drop - * @source_file_list: (type GLib.List) (element-type GFile) (transfer none): - * List of #GFile that are being dragged + * @drop: (type Gdk.Drop): GdkDrop with information about the drag operation + * @dest_file: (type Gio.File): GFile with the tentative location that is being hovered for a drop + * @source_file_list: (type GLib.SList) (element-type GFile) (transfer none): + * List of GFile that are being dragged * * When the user starts a drag-and-drop operation and the sidebar needs * to ask the application for which drag action to perform, then the @@ -4584,11 +4153,9 @@ nautilus_gtk_places_sidebar_class_init (NautilusGtkPlacesSidebarClass *class) * * The drag action to use must be the return value of the signal handler. * - * Returns: The drag action to use, for example, #GDK_ACTION_COPY - * or #GDK_ACTION_MOVE, or 0 if no action is allowed here (i.e. drops + * Returns: The drag action to use, for example, GDK_ACTION_COPY + * or GDK_ACTION_MOVE, or 0 if no action is allowed here (i.e. drops * are not allowed in the specified @dest_file). - * - * Since: 3.10 */ places_sidebar_signals [DRAG_ACTION_REQUESTED] = g_signal_new ("drag-action-requested", @@ -4597,12 +4164,11 @@ nautilus_gtk_places_sidebar_class_init (NautilusGtkPlacesSidebarClass *class) G_STRUCT_OFFSET (NautilusGtkPlacesSidebarClass, drag_action_requested), NULL, NULL, NULL, - G_TYPE_INT, 3, - GDK_TYPE_DRAG_CONTEXT, + GDK_TYPE_DRAG_ACTION, 2, G_TYPE_OBJECT, - G_TYPE_POINTER /* GList of GFile */ ); + GDK_TYPE_FILE_LIST); - /** + /* * NautilusGtkPlacesSidebar::drag-action-ask: * @sidebar: the object which received the signal. * @actions: Possible drag actions that need to be asked for. @@ -4612,8 +4178,6 @@ nautilus_gtk_places_sidebar_class_init (NautilusGtkPlacesSidebarClass *class) * * Returns: the final drag action that the sidebar should pass to the drag side * of the drag-and-drop operation. - * - * Since: 3.10 */ places_sidebar_signals [DRAG_ACTION_ASK] = g_signal_new ("drag-action-ask", @@ -4622,15 +4186,15 @@ nautilus_gtk_places_sidebar_class_init (NautilusGtkPlacesSidebarClass *class) G_STRUCT_OFFSET (NautilusGtkPlacesSidebarClass, drag_action_ask), NULL, NULL, NULL, - G_TYPE_INT, 1, - G_TYPE_INT); + GDK_TYPE_DRAG_ACTION, 1, + GDK_TYPE_DRAG_ACTION); - /** + /* * NautilusGtkPlacesSidebar::drag-perform-drop: * @sidebar: the object which received the signal. - * @dest_file: (type Gio.File): Destination #GFile. - * @source_file_list: (type GLib.List) (element-type GFile) (transfer none): - * #GList of #GFile that got dropped. + * @dest_file: (type Gio.File): Destination GFile. + * @source_file_list: (type GLib.SList) (element-type GFile) (transfer none): + * GSList of GFile that got dropped. * @action: Drop action to perform. * * The places sidebar emits this signal when the user completes a @@ -4638,8 +4202,6 @@ nautilus_gtk_places_sidebar_class_init (NautilusGtkPlacesSidebarClass *class) * destination. This item is in the @dest_file, and the * @source_file_list has the list of files that are dropped into it and * which should be copied/moved/etc. based on the specified @action. - * - * Since: 3.10 */ places_sidebar_signals [DRAG_PERFORM_DROP] = g_signal_new ("drag-perform-drop", @@ -4650,46 +4212,19 @@ nautilus_gtk_places_sidebar_class_init (NautilusGtkPlacesSidebarClass *class) NULL, G_TYPE_NONE, 3, G_TYPE_OBJECT, - G_TYPE_POINTER, /* GList of GFile */ - G_TYPE_INT); + GDK_TYPE_FILE_LIST, + GDK_TYPE_DRAG_ACTION); - /** - * NautilusGtkPlacesSidebar::show-other-locations: - * @sidebar: the object which received the signal. - * - * The places sidebar emits this signal when it needs the calling - * application to present a way to show other locations e.g. drives - * and network access points. - * For example, the application may bring up a page showing persistent - * volumes and discovered network addresses. - * - * Deprecated: 3.20: use the #NautilusGtkPlacesSidebar::show-other-locations-with-flags - * which includes the open flags in order to allow the user to specify to open - * in a new tab or window, in a similar way than #NautilusGtkPlacesSidebar::open-location - * - * Since: 3.18 - */ - places_sidebar_signals [SHOW_OTHER_LOCATIONS] = - g_signal_new ("show-other-locations", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST | G_SIGNAL_DEPRECATED, - G_STRUCT_OFFSET (NautilusGtkPlacesSidebarClass, show_other_locations), - NULL, NULL, - NULL, - G_TYPE_NONE, 0); - - /** + /* * NautilusGtkPlacesSidebar::show-other-locations-with-flags: * @sidebar: the object which received the signal. - * @open_flags: a single value from #NautilusGtkPlacesOpenFlags specifying how it should be opened. + * @open_flags: a single value from NautilusGtkPlacesOpenFlags specifying how it should be opened. * * The places sidebar emits this signal when it needs the calling * application to present a way to show other locations e.g. drives * and network access points. * For example, the application may bring up a page showing persistent * volumes and discovered network addresses. - * - * Since: 3.20 */ places_sidebar_signals [SHOW_OTHER_LOCATIONS_WITH_FLAGS] = g_signal_new ("show-other-locations-with-flags", @@ -4699,19 +4234,17 @@ nautilus_gtk_places_sidebar_class_init (NautilusGtkPlacesSidebarClass *class) NULL, NULL, NULL, G_TYPE_NONE, 1, - GTK_TYPE_PLACES_OPEN_FLAGS); + NAUTILUS_TYPE_OPEN_FLAGS); - /** + /* * NautilusGtkPlacesSidebar::mount: * @sidebar: the object which received the signal. - * @mount_operation: the #GMountOperation that is going to start. + * @mount_operation: the GMountOperation that is going to start. * * The places sidebar emits this signal when it starts a new operation * because the user clicked on some location that needs mounting. - * In this way the application using the #NautilusGtkPlacesSidebar can track the + * In this way the application using the NautilusGtkPlacesSidebar can track the * progress of the operation and, for example, show a notification. - * - * Since: 3.20 */ places_sidebar_signals [MOUNT] = g_signal_new ("mount", @@ -4723,17 +4256,15 @@ nautilus_gtk_places_sidebar_class_init (NautilusGtkPlacesSidebarClass *class) G_TYPE_NONE, 1, G_TYPE_MOUNT_OPERATION); - /** + /* * NautilusGtkPlacesSidebar::unmount: * @sidebar: the object which received the signal. - * @mount_operation: the #GMountOperation that is going to start. + * @mount_operation: the GMountOperation that is going to start. * * The places sidebar emits this signal when it starts a new operation * because the user for example ejected some drive or unmounted a mount. - * In this way the application using the #NautilusGtkPlacesSidebar can track the + * In this way the application using the NautilusGtkPlacesSidebar can track the * progress of the operation and, for example, show a notification. - * - * Since: 3.20 */ places_sidebar_signals [UNMOUNT] = g_signal_new ("unmount", @@ -4746,18 +4277,15 @@ nautilus_gtk_places_sidebar_class_init (NautilusGtkPlacesSidebarClass *class) 1, G_TYPE_MOUNT_OPERATION); - /** + /* * NautilusGtkPlacesSidebar::show-starred-location: - * @sidebar: the object which received the signal. - * @open_flags: a single value from #NautilusGtkPlacesOpenFlags specifying how the - * starred file should be opened. + * @sidebar: the object which received the signal + * @flags: the flags for the operation * * The places sidebar emits this signal when it needs the calling * application to present a way to show the starred files. In GNOME, * starred files are implemented by setting the nao:predefined-tag-favorite * tag in the tracker database. - * - * Since: 3.22.26 */ places_sidebar_signals [SHOW_STARRED_LOCATION] = g_signal_new ("show-starred-location", @@ -4767,103 +4295,73 @@ nautilus_gtk_places_sidebar_class_init (NautilusGtkPlacesSidebarClass *class) NULL, NULL, NULL, G_TYPE_NONE, 1, - GTK_TYPE_PLACES_OPEN_FLAGS); + NAUTILUS_TYPE_OPEN_FLAGS); properties[PROP_LOCATION] = g_param_spec_object ("location", "Location to Select", "The location to highlight in the sidebar", G_TYPE_FILE, - G_PARAM_READWRITE); + G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB); properties[PROP_OPEN_FLAGS] = g_param_spec_flags ("open-flags", "Open Flags", "Modes in which the calling application can open locations selected in the sidebar", - GTK_TYPE_PLACES_OPEN_FLAGS, + NAUTILUS_TYPE_OPEN_FLAGS, NAUTILUS_GTK_PLACES_OPEN_NORMAL, - G_PARAM_READWRITE); + G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB); properties[PROP_SHOW_RECENT] = g_param_spec_boolean ("show-recent", "Show recent files", "Whether the sidebar includes a builtin shortcut for recent files", TRUE, - G_PARAM_READWRITE); + G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB); properties[PROP_SHOW_DESKTOP] = g_param_spec_boolean ("show-desktop", - "Show 'Desktop'", + "Show “Desktop”", "Whether the sidebar includes a builtin shortcut to the Desktop folder", TRUE, - G_PARAM_READWRITE); - properties[PROP_SHOW_CONNECT_TO_SERVER] = - g_param_spec_boolean ("show-connect-to-server", - "Show 'Connect to Server'", - "Whether the sidebar includes a builtin shortcut to a 'Connect to server' dialog", - FALSE, - G_PARAM_READWRITE | G_PARAM_DEPRECATED); + G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB); properties[PROP_SHOW_ENTER_LOCATION] = g_param_spec_boolean ("show-enter-location", - "Show 'Enter Location'", + "Show “Enter Location”", "Whether the sidebar includes a builtin shortcut to manually enter a location", FALSE, - G_PARAM_READWRITE); - properties[PROP_LOCAL_ONLY] = - g_param_spec_boolean ("local-only", - "Local Only", - "Whether the sidebar only includes local files", - FALSE, - G_PARAM_READWRITE); + G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB); properties[PROP_SHOW_TRASH] = g_param_spec_boolean ("show-trash", - "Show 'Trash'", + "Show “Trash”", "Whether the sidebar includes a builtin shortcut to the Trash location", TRUE, - G_PARAM_READWRITE); + G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB); properties[PROP_SHOW_OTHER_LOCATIONS] = g_param_spec_boolean ("show-other-locations", - "Show 'Other locations'", + "Show “Other locations”", "Whether the sidebar includes an item to show external locations", - FALSE, - G_PARAM_READWRITE); + TRUE, + G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB); properties[PROP_SHOW_STARRED_LOCATION] = g_param_spec_boolean ("show-starred-location", "Show “Starred Location”", "Whether the sidebar includes an item to show starred files", FALSE, - G_PARAM_READWRITE); - - - /** - * NautilusGtkPlacesSidebar:populate-all: - * - * If :populate-all is %TRUE, the #NautilusGtkPlacesSidebar::populate-popup signal - * is also emitted for popovers. - * - * Since: 3.18 - */ - properties[PROP_POPULATE_ALL] = - g_param_spec_boolean ("populate-all", - "Populate all", - "Whether to emit ::populate-popup for popups that are not menus", - FALSE, - G_PARAM_READWRITE); + G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB); g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties); gtk_widget_class_set_css_name (widget_class, "placessidebar"); } -/** +/* * nautilus_gtk_places_sidebar_new: * - * Creates a new #NautilusGtkPlacesSidebar widget. + * Creates a new NautilusGtkPlacesSidebar widget. * * The application should connect to at least the - * #NautilusGtkPlacesSidebar::open-location signal to be notified + * NautilusGtkPlacesSidebar::open-location signal to be notified * when the user makes a selection in the sidebar. * - * Returns: a newly created #NautilusGtkPlacesSidebar - * - * Since: 3.10 + * Returns: a newly created NautilusGtkPlacesSidebar */ GtkWidget * nautilus_gtk_places_sidebar_new (void) @@ -4871,9 +4369,7 @@ nautilus_gtk_places_sidebar_new (void) return GTK_WIDGET (g_object_new (nautilus_gtk_places_sidebar_get_type (), NULL)); } -/* Public methods for NautilusGtkPlacesSidebar */ - -/** +/* * nautilus_gtk_places_sidebar_set_open_flags: * @sidebar: a places sidebar * @flags: Bitmask of modes in which the calling application can open locations @@ -4887,14 +4383,12 @@ nautilus_gtk_places_sidebar_new (void) * application can open new locations, so that the sidebar can display (or not) * the “Open in new tab” and “Open in new window” menu items as appropriate. * - * When the #NautilusGtkPlacesSidebar::open-location signal is emitted, its flags + * When the NautilusGtkPlacesSidebar::open-location signal is emitted, its flags * argument will be set to one of the @flags that was passed in * nautilus_gtk_places_sidebar_set_open_flags(). * - * Passing 0 for @flags will cause #NAUTILUS_GTK_PLACES_OPEN_NORMAL to always be sent + * Passing 0 for @flags will cause NAUTILUS_GTK_PLACES_OPEN_NORMAL to always be sent * to callbacks for the “open-location” signal. - * - * Since: 3.10 */ void nautilus_gtk_places_sidebar_set_open_flags (NautilusGtkPlacesSidebar *sidebar, @@ -4909,15 +4403,13 @@ nautilus_gtk_places_sidebar_set_open_flags (NautilusGtkPlacesSidebar *sidebar, } } -/** +/* * nautilus_gtk_places_sidebar_get_open_flags: - * @sidebar: a #NautilusGtkPlacesSidebar + * @sidebar: a NautilusGtkPlacesSidebar * * Gets the open flags. * - * Returns: the #NautilusGtkPlacesOpenFlags of @sidebar - * - * Since: 3.10 + * Returns: the NautilusGtkPlacesOpenFlags of @sidebar */ NautilusGtkPlacesOpenFlags nautilus_gtk_places_sidebar_get_open_flags (NautilusGtkPlacesSidebar *sidebar) @@ -4927,7 +4419,7 @@ nautilus_gtk_places_sidebar_get_open_flags (NautilusGtkPlacesSidebar *sidebar) return sidebar->open_flags; } -/** +/* * nautilus_gtk_places_sidebar_set_location: * @sidebar: a places sidebar * @location: (nullable): location to select, or %NULL for no current path @@ -4937,17 +4429,14 @@ nautilus_gtk_places_sidebar_get_open_flags (NautilusGtkPlacesSidebar *sidebar) * @sidebar will highlight that location if it is being shown in the list of * places, or it will unhighlight everything if the @location is not among the * places in the list. - * - * Since: 3.10 */ void nautilus_gtk_places_sidebar_set_location (NautilusGtkPlacesSidebar *sidebar, GFile *location) { - GList *children; - GList *child; - gchar *row_uri; - gchar *uri; + GtkWidget *row; + char *row_uri; + char *uri; gboolean found = FALSE; g_return_if_fail (NAUTILUS_IS_GTK_PLACES_SIDEBAR (sidebar)); @@ -4965,14 +4454,18 @@ nautilus_gtk_places_sidebar_set_location (NautilusGtkPlacesSidebar *sidebar, uri = g_file_get_uri (location); - children = gtk_container_get_children (GTK_CONTAINER (sidebar->list_box)); - for (child = children; child != NULL && !found; child = child->next) + for (row = gtk_widget_get_first_child (GTK_WIDGET (sidebar->list_box)); + row != NULL && !found; + row = gtk_widget_get_next_sibling (row)) { - g_object_get (child->data, "uri", &row_uri, NULL); + if (!GTK_IS_LIST_BOX_ROW (row)) + continue; + + g_object_get (row, "uri", &row_uri, NULL); if (row_uri != NULL && g_strcmp0 (row_uri, uri) == 0) { gtk_list_box_select_row (GTK_LIST_BOX (sidebar->list_box), - GTK_LIST_BOX_ROW (child->data)); + GTK_LIST_BOX_ROW (row)); found = TRUE; } @@ -4980,13 +4473,12 @@ nautilus_gtk_places_sidebar_set_location (NautilusGtkPlacesSidebar *sidebar, } g_free (uri); - g_list_free (children); out: g_object_notify_by_pspec (G_OBJECT (sidebar), properties[PROP_LOCATION]); } -/** +/* * nautilus_gtk_places_sidebar_get_location: * @sidebar: a places sidebar * @@ -4995,15 +4487,10 @@ nautilus_gtk_places_sidebar_set_location (NautilusGtkPlacesSidebar *sidebar, * been called with a location that is not among the sidebar’s list of places to * show. * - * You can use this function to get the selection in the @sidebar. Also, if you - * connect to the #NautilusGtkPlacesSidebar::populate-popup signal, you can use this - * function to get the location that is being referred to during the callbacks - * for your menu items. + * You can use this function to get the selection in the @sidebar. * - * Returns: (nullable) (transfer full): a #GFile with the selected location, or + * Returns: (nullable) (transfer full): a GFile with the selected location, or * %NULL if nothing is visually selected. - * - * Since: 3.10 */ GFile * nautilus_gtk_places_sidebar_get_location (NautilusGtkPlacesSidebar *sidebar) @@ -5018,7 +4505,7 @@ nautilus_gtk_places_sidebar_get_location (NautilusGtkPlacesSidebar *sidebar) if (selected) { - gchar *uri; + char *uri; g_object_get (selected, "uri", &uri, NULL); file = g_file_new_for_uri (uri); @@ -5028,11 +4515,11 @@ nautilus_gtk_places_sidebar_get_location (NautilusGtkPlacesSidebar *sidebar) return file; } -gchar * +char * nautilus_gtk_places_sidebar_get_location_title (NautilusGtkPlacesSidebar *sidebar) { GtkListBoxRow *selected; - gchar *title; + char *title; g_return_val_if_fail (sidebar != NULL, NULL); @@ -5045,7 +4532,7 @@ nautilus_gtk_places_sidebar_get_location_title (NautilusGtkPlacesSidebar *sideba return title; } -/** +/* * nautilus_gtk_places_sidebar_set_show_recent: * @sidebar: a places sidebar * @show_recent: whether to show an item for recent files @@ -5054,8 +4541,6 @@ nautilus_gtk_places_sidebar_get_location_title (NautilusGtkPlacesSidebar *sideba * The default value for this option is determined by the desktop * environment, but this function can be used to override it on a * per-application basis. - * - * Since: 3.18 */ void nautilus_gtk_places_sidebar_set_show_recent (NautilusGtkPlacesSidebar *sidebar, @@ -5074,15 +4559,13 @@ nautilus_gtk_places_sidebar_set_show_recent (NautilusGtkPlacesSidebar *sidebar, } } -/** +/* * nautilus_gtk_places_sidebar_get_show_recent: * @sidebar: a places sidebar * * Returns the value previously set with nautilus_gtk_places_sidebar_set_show_recent() * * Returns: %TRUE if the sidebar will display a builtin shortcut for recent files - * - * Since: 3.18 */ gboolean nautilus_gtk_places_sidebar_get_show_recent (NautilusGtkPlacesSidebar *sidebar) @@ -5092,7 +4575,7 @@ nautilus_gtk_places_sidebar_get_show_recent (NautilusGtkPlacesSidebar *sidebar) return sidebar->show_recent; } -/** +/* * nautilus_gtk_places_sidebar_set_show_desktop: * @sidebar: a places sidebar * @show_desktop: whether to show an item for the Desktop folder @@ -5101,8 +4584,6 @@ nautilus_gtk_places_sidebar_get_show_recent (NautilusGtkPlacesSidebar *sidebar) * The default value for this option is determined by the desktop * environment and the user’s configuration, but this function can be * used to override it on a per-application basis. - * - * Since: 3.10 */ void nautilus_gtk_places_sidebar_set_show_desktop (NautilusGtkPlacesSidebar *sidebar, @@ -5125,15 +4606,13 @@ nautilus_gtk_places_sidebar_set_show_desktop (NautilusGtkPlacesSidebar *sidebar, } } -/** +/* * nautilus_gtk_places_sidebar_get_show_desktop: * @sidebar: a places sidebar * * Returns the value previously set with nautilus_gtk_places_sidebar_set_show_desktop() * * Returns: %TRUE if the sidebar will display a builtin shortcut to the desktop folder. - * - * Since: 3.10 */ gboolean nautilus_gtk_places_sidebar_get_show_desktop (NautilusGtkPlacesSidebar *sidebar) @@ -5143,58 +4622,7 @@ nautilus_gtk_places_sidebar_get_show_desktop (NautilusGtkPlacesSidebar *sidebar) return sidebar->show_desktop; } -/** - * nautilus_gtk_places_sidebar_set_show_connect_to_server: - * @sidebar: a places sidebar - * @show_connect_to_server: whether to show an item for the Connect to Server command - * - * Sets whether the @sidebar should show an item for connecting to a network server; - * this is off by default. An application may want to turn this on if it implements - * a way for the user to connect to network servers directly. - * - * If you enable this, you should connect to the - * #NautilusGtkPlacesSidebar::show-connect-to-server signal. - * - * Since: 3.10 - * - * Deprecated: 3.18: It is recommended to group this functionality with the drives - * and network location under the new 'Other Location' item - */ -void -nautilus_gtk_places_sidebar_set_show_connect_to_server (NautilusGtkPlacesSidebar *sidebar, - gboolean show_connect_to_server) -{ - g_return_if_fail (NAUTILUS_IS_GTK_PLACES_SIDEBAR (sidebar)); - - show_connect_to_server = !!show_connect_to_server; - if (sidebar->show_connect_to_server != show_connect_to_server) - { - sidebar->show_connect_to_server = show_connect_to_server; - update_places (sidebar); - g_object_notify_by_pspec (G_OBJECT (sidebar), properties[PROP_SHOW_CONNECT_TO_SERVER]); - } -} - -/** - * nautilus_gtk_places_sidebar_get_show_connect_to_server: - * @sidebar: a places sidebar - * - * Returns the value previously set with nautilus_gtk_places_sidebar_set_show_connect_to_server() - * - * Returns: %TRUE if the sidebar will display a “Connect to Server” item. - * - * Deprecated: 3.18: It is recommended to group this functionality with the drives - * and network location under the new 'Other Location' item - */ -gboolean -nautilus_gtk_places_sidebar_get_show_connect_to_server (NautilusGtkPlacesSidebar *sidebar) -{ - g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_SIDEBAR (sidebar), FALSE); - - return sidebar->show_connect_to_server; -} - -/** +/* * nautilus_gtk_places_sidebar_set_show_enter_location: * @sidebar: a places sidebar * @show_enter_location: whether to show an item to enter a location @@ -5204,9 +4632,7 @@ nautilus_gtk_places_sidebar_get_show_connect_to_server (NautilusGtkPlacesSidebar * entering URLs is an expected user action. * * If you enable this, you should connect to the - * #NautilusGtkPlacesSidebar::show-enter-location signal. - * - * Since: 3.14 + * NautilusGtkPlacesSidebar::show-enter-location signal. */ void nautilus_gtk_places_sidebar_set_show_enter_location (NautilusGtkPlacesSidebar *sidebar, @@ -5223,15 +4649,13 @@ nautilus_gtk_places_sidebar_set_show_enter_location (NautilusGtkPlacesSidebar *s } } -/** +/* * nautilus_gtk_places_sidebar_get_show_enter_location: * @sidebar: a places sidebar * * Returns the value previously set with nautilus_gtk_places_sidebar_set_show_enter_location() * * Returns: %TRUE if the sidebar will display an “Enter Location” item. - * - * Since: 3.14 */ gboolean nautilus_gtk_places_sidebar_get_show_enter_location (NautilusGtkPlacesSidebar *sidebar) @@ -5241,7 +4665,7 @@ nautilus_gtk_places_sidebar_get_show_enter_location (NautilusGtkPlacesSidebar *s return sidebar->show_enter_location; } -/** +/* * nautilus_gtk_places_sidebar_set_show_other_locations: * @sidebar: a places sidebar * @show_other_locations: whether to show an item for the Other Locations view @@ -5253,9 +4677,7 @@ nautilus_gtk_places_sidebar_get_show_enter_location (NautilusGtkPlacesSidebar *s * see and interact with drives and network servers directly. * * If you enable this, you should connect to the - * #NautilusGtkPlacesSidebar::show-other-locations signal. - * - * Since: 3.18 + * NautilusGtkPlacesSidebar::show-other-locations-with-flags signal. */ void nautilus_gtk_places_sidebar_set_show_other_locations (NautilusGtkPlacesSidebar *sidebar, @@ -5272,15 +4694,13 @@ nautilus_gtk_places_sidebar_set_show_other_locations (NautilusGtkPlacesSidebar * } } -/** +/* * nautilus_gtk_places_sidebar_get_show_other_locations: * @sidebar: a places sidebar * * Returns the value previously set with nautilus_gtk_places_sidebar_set_show_other_locations() * * Returns: %TRUE if the sidebar will display an “Other Locations” item. - * - * Since: 3.18 */ gboolean nautilus_gtk_places_sidebar_get_show_other_locations (NautilusGtkPlacesSidebar *sidebar) @@ -5290,14 +4710,12 @@ nautilus_gtk_places_sidebar_get_show_other_locations (NautilusGtkPlacesSidebar * return sidebar->show_other_locations; } -/** +/* * nautilus_gtk_places_sidebar_set_show_trash: * @sidebar: a places sidebar * @show_trash: whether to show an item for the Trash location * * Sets whether the @sidebar should show an item for the Trash location. - * - * Since: 3.18 */ void nautilus_gtk_places_sidebar_set_show_trash (NautilusGtkPlacesSidebar *sidebar, @@ -5314,15 +4732,13 @@ nautilus_gtk_places_sidebar_set_show_trash (NautilusGtkPlacesSidebar *sidebar, } } -/** +/* * nautilus_gtk_places_sidebar_get_show_trash: * @sidebar: a places sidebar * * Returns the value previously set with nautilus_gtk_places_sidebar_set_show_trash() * * Returns: %TRUE if the sidebar will display a “Trash” item. - * - * Since: 3.18 */ gboolean nautilus_gtk_places_sidebar_get_show_trash (NautilusGtkPlacesSidebar *sidebar) @@ -5332,67 +4748,7 @@ nautilus_gtk_places_sidebar_get_show_trash (NautilusGtkPlacesSidebar *sidebar) return sidebar->show_trash; } -/** - * nautilus_gtk_places_sidebar_set_local_only: - * @sidebar: a places sidebar - * @local_only: whether to show only local files - * - * Sets whether the @sidebar should only show local files. - * - * Since: 3.12 - */ -void -nautilus_gtk_places_sidebar_set_local_only (NautilusGtkPlacesSidebar *sidebar, - gboolean local_only) -{ - g_return_if_fail (NAUTILUS_IS_GTK_PLACES_SIDEBAR (sidebar)); - - local_only = !!local_only; - if (sidebar->local_only != local_only) - { - sidebar->local_only = local_only; - update_places (sidebar); - g_object_notify_by_pspec (G_OBJECT (sidebar), properties[PROP_LOCAL_ONLY]); - } -} - -/** - * nautilus_gtk_places_sidebar_get_local_only: - * @sidebar: a places sidebar - * - * Returns the value previously set with nautilus_gtk_places_sidebar_set_local_only(). - * - * Returns: %TRUE if the sidebar will only show local files. - * - * Since: 3.12 - */ -gboolean -nautilus_gtk_places_sidebar_get_local_only (NautilusGtkPlacesSidebar *sidebar) -{ - g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_SIDEBAR (sidebar), FALSE); - - return sidebar->local_only; -} - -static GSList * -find_shortcut_link (NautilusGtkPlacesSidebar *sidebar, - GFile *location) -{ - GSList *l; - - for (l = sidebar->shortcuts; l; l = l->next) - { - GFile *shortcut; - - shortcut = G_FILE (l->data); - if (g_file_equal (shortcut, location)) - return l; - } - - return NULL; -} - -/** +/* * nautilus_gtk_places_sidebar_add_shortcut: * @sidebar: a places sidebar * @location: location to add as an application-specific shortcut @@ -5407,8 +4763,6 @@ find_shortcut_link (NautilusGtkPlacesSidebar *sidebar, * across applications, and they are not persistent. If this function * is called multiple times with different locations, then they are added * to the sidebar’s list in the same order as the function is called. - * - * Since: 3.10 */ void nautilus_gtk_places_sidebar_add_shortcut (NautilusGtkPlacesSidebar *sidebar, @@ -5417,13 +4771,12 @@ nautilus_gtk_places_sidebar_add_shortcut (NautilusGtkPlacesSidebar *sidebar, g_return_if_fail (NAUTILUS_IS_GTK_PLACES_SIDEBAR (sidebar)); g_return_if_fail (G_IS_FILE (location)); - g_object_ref (location); - sidebar->shortcuts = g_slist_append (sidebar->shortcuts, location); + g_list_store_append (sidebar->shortcuts, location); update_places (sidebar); } -/** +/* * nautilus_gtk_places_sidebar_remove_shortcut: * @sidebar: a places sidebar * @location: location to remove @@ -5431,95 +4784,93 @@ nautilus_gtk_places_sidebar_add_shortcut (NautilusGtkPlacesSidebar *sidebar, * Removes an application-specific shortcut that has been previously been * inserted with nautilus_gtk_places_sidebar_add_shortcut(). If the @location is not a * shortcut in the sidebar, then nothing is done. - * - * Since: 3.10 */ void nautilus_gtk_places_sidebar_remove_shortcut (NautilusGtkPlacesSidebar *sidebar, GFile *location) { - GSList *link; - GFile *shortcut; + guint i, n; g_return_if_fail (NAUTILUS_IS_GTK_PLACES_SIDEBAR (sidebar)); g_return_if_fail (G_IS_FILE (location)); - link = find_shortcut_link (sidebar, location); - if (!link) - return; + n = g_list_model_get_n_items (G_LIST_MODEL (sidebar->shortcuts)); + for (i = 0; i < n; i++) + { + GFile *shortcut = g_list_model_get_item (G_LIST_MODEL (sidebar->shortcuts), i); - shortcut = G_FILE (link->data); - g_object_unref (shortcut); + if (shortcut == location) + { + g_list_store_remove (sidebar->shortcuts, i); + g_object_unref (shortcut); + update_places (sidebar); + return; + } - sidebar->shortcuts = g_slist_delete_link (sidebar->shortcuts, link); - update_places (sidebar); + g_object_unref (shortcut); + } } -/** +/* * nautilus_gtk_places_sidebar_list_shortcuts: * @sidebar: a places sidebar * - * Gets the list of shortcuts. + * Gets the list of shortcuts, as a list model containing GFile objects. * - * Returns: (element-type GFile) (transfer full): - * A #GSList of #GFile of the locations that have been added as - * application-specific shortcuts with nautilus_gtk_places_sidebar_add_shortcut(). - * To free this list, you can use - * |[<!-- language="C" --> - * g_slist_free_full (list, (GDestroyNotify) g_object_unref); - * ]| + * You should not modify the returned list model. Future changes to + * @sidebar may or may not affect the returned model. * - * Since: 3.10 + * Returns: (transfer full): a list model of GFiles that have been added as + * application-specific shortcuts with nautilus_gtk_places_sidebar_add_shortcut() */ -GSList * -nautilus_gtk_places_sidebar_list_shortcuts (NautilusGtkPlacesSidebar *sidebar) +GListModel * +nautilus_gtk_places_sidebar_get_shortcuts (NautilusGtkPlacesSidebar *sidebar) { g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_SIDEBAR (sidebar), NULL); - return g_slist_copy_deep (sidebar->shortcuts, (GCopyFunc) g_object_ref, NULL); + return G_LIST_MODEL (g_object_ref (sidebar->shortcuts)); } -/** +/* * nautilus_gtk_places_sidebar_get_nth_bookmark: * @sidebar: a places sidebar * @n: index of the bookmark to query * * This function queries the bookmarks added by the user to the places sidebar, - * and returns one of them. This function is used by #GtkFileChooser to implement - * the “Alt-1”, “Alt-2”, etc. shortcuts, which activate the cooresponding bookmark. + * and returns one of them. This function is used by GtkFileChooser to implement + * the “Alt-1”, “Alt-2”, etc. shortcuts, which activate the corresponding bookmark. * * Returns: (nullable) (transfer full): The bookmark specified by the index @n, or * %NULL if no such index exist. Note that the indices start at 0, even though * the file chooser starts them with the keyboard shortcut "Alt-1". - * - * Since: 3.10 */ GFile * nautilus_gtk_places_sidebar_get_nth_bookmark (NautilusGtkPlacesSidebar *sidebar, - gint n) + int n) { - GList *rows; - GList *l; + GtkWidget *row; int k; GFile *file; g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_SIDEBAR (sidebar), NULL); file = NULL; - rows = gtk_container_get_children (GTK_CONTAINER (sidebar->list_box)); - l = rows; - k = 0; - while (l != NULL) + for (row = gtk_widget_get_first_child (GTK_WIDGET (sidebar->list_box)); + row != NULL; + row = gtk_widget_get_next_sibling (row)) { - NautilusGtkPlacesSidebarPlaceType place_type; - gchar *uri; + NautilusGtkPlacesPlaceType place_type; + char *uri; + + if (!GTK_IS_LIST_BOX_ROW (row)) + continue; - g_object_get (l->data, + g_object_get (row, "place-type", &place_type, "uri", &uri, NULL); - if (place_type == PLACES_BOOKMARK) + if (place_type == NAUTILUS_GTK_PLACES_BOOKMARK) { if (k == n) { @@ -5530,20 +4881,15 @@ nautilus_gtk_places_sidebar_get_nth_bookmark (NautilusGtkPlacesSidebar *sidebar, k++; } g_free (uri); - l = l->next; } - g_list_free (rows); - return file; } -/** +/* * nautilus_gtk_places_sidebar_set_drop_targets_visible: * @sidebar: a places sidebar. * @visible: whether to show the valid targets or not. - * @context: drag context used to ask the source about the action that wants to - * perform, so hints are more accurate. * * Make the NautilusGtkPlacesSidebar show drop targets, so it can show the available * drop targets and a "new bookmark" row. This improves the Drag-and-Drop @@ -5554,18 +4900,17 @@ nautilus_gtk_places_sidebar_get_nth_bookmark (NautilusGtkPlacesSidebar *sidebar, * that might target the sidebar. The drop-targets-visible state will be unset * automatically if the drag finishes in the NautilusGtkPlacesSidebar. You only need * to unset the state when the drag ends on some other widget on your application. - * - * Since: 3.18 */ void nautilus_gtk_places_sidebar_set_drop_targets_visible (NautilusGtkPlacesSidebar *sidebar, - gboolean visible, - GdkDragContext *context) + gboolean visible) { + g_return_if_fail (NAUTILUS_IS_GTK_PLACES_SIDEBAR (sidebar)); + if (visible) { sidebar->drop_state = DROP_STATE_NEW_BOOKMARK_ARMED_PERMANENT; - start_drop_feedback (sidebar, NULL, context); + start_drop_feedback (sidebar, NULL); } else { @@ -5589,15 +4934,13 @@ nautilus_gtk_places_sidebar_set_drop_targets_visible (NautilusGtkPlacesSidebar * } } -/** +/* * nautilus_gtk_places_sidebar_set_show_starred_location: * @sidebar: a places sidebar * @show_starred_location: whether to show an item for Starred files * * If you enable this, you should connect to the - * #NautilusGtkPlacesSidebar::show-starred-location signal. - * - * Since: 3.22.26 + * NautilusGtkPlacesSidebar::show-starred-location signal. */ void nautilus_gtk_places_sidebar_set_show_starred_location (NautilusGtkPlacesSidebar *sidebar, @@ -5614,15 +4957,13 @@ nautilus_gtk_places_sidebar_set_show_starred_location (NautilusGtkPlacesSidebar } } -/** +/* * nautilus_gtk_places_sidebar_get_show_starred_location: * @sidebar: a places sidebar * * Returns the value previously set with nautilus_gtk_places_sidebar_set_show_starred_location() * * Returns: %TRUE if the sidebar will display a Starred item. - * - * Since: 3.22.26 */ gboolean nautilus_gtk_places_sidebar_get_show_starred_location (NautilusGtkPlacesSidebar *sidebar) diff --git a/src/gtk/nautilusgtkplacessidebar.h b/src/gtk/nautilusgtkplacessidebar.h deleted file mode 100644 index e7111ecf6..000000000 --- a/src/gtk/nautilusgtkplacessidebar.h +++ /dev/null @@ -1,159 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ - -/* NautilusGtkPlacesSidebar - sidebar widget for places in the filesystem - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation, either version 2.1 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * This code comes from Nautilus, GNOME’s file manager. - * - * Authors : Mr Jamie McCracken (jamiemcc at blueyonder dot co dot uk) - * Federico Mena Quintero <federico@gnome.org> - */ - -#ifndef __NAUTILUS_GTK_PLACES_SIDEBAR_H__ -#define __NAUTILUS_GTK_PLACES_SIDEBAR_H__ - -#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) -#endif - -#include <gtk/gtkwidget.h> - -G_BEGIN_DECLS - -#define NAUTILUS_TYPE_GTK_PLACES_SIDEBAR (nautilus_gtk_places_sidebar_get_type ()) -#define NAUTILUS_GTK_PLACES_SIDEBAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NAUTILUS_TYPE_GTK_PLACES_SIDEBAR, NautilusGtkPlacesSidebar)) -#define NAUTILUS_GTK_PLACES_SIDEBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_GTK_PLACES_SIDEBAR, NautilusGtkPlacesSidebarClass)) -#define NAUTILUS_IS_GTK_PLACES_SIDEBAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NAUTILUS_TYPE_GTK_PLACES_SIDEBAR)) -#define NAUTILUS_IS_GTK_PLACES_SIDEBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_GTK_PLACES_SIDEBAR)) -#define NAUTILUS_GTK_PLACES_SIDEBAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NAUTILUS_TYPE_GTK_PLACES_SIDEBAR, NautilusGtkPlacesSidebarClass)) - -typedef struct _NautilusGtkPlacesSidebar NautilusGtkPlacesSidebar; -typedef struct _NautilusGtkPlacesSidebarClass NautilusGtkPlacesSidebarClass; - -/** - * NautilusGtkPlacesOpenFlags: - * @NAUTILUS_GTK_PLACES_OPEN_NORMAL: This is the default mode that #NautilusGtkPlacesSidebar uses if no other flags - * are specified. It indicates that the calling application should open the selected location - * in the normal way, for example, in the folder view beside the sidebar. - * @NAUTILUS_GTK_PLACES_OPEN_NEW_TAB: When passed to nautilus_gtk_places_sidebar_set_open_flags(), this indicates - * that the application can open folders selected from the sidebar in new tabs. This value - * will be passed to the #NautilusGtkPlacesSidebar::open-location signal when the user selects - * that a location be opened in a new tab instead of in the standard fashion. - * @NAUTILUS_GTK_PLACES_OPEN_NEW_WINDOW: Similar to @NAUTILUS_GTK_PLACES_OPEN_NEW_TAB, but indicates that the application - * can open folders in new windows. - * - * These flags serve two purposes. First, the application can call nautilus_gtk_places_sidebar_set_open_flags() - * using these flags as a bitmask. This tells the sidebar that the application is able to open - * folders selected from the sidebar in various ways, for example, in new tabs or in new windows in - * addition to the normal mode. - * - * Second, when one of these values gets passed back to the application in the - * #NautilusGtkPlacesSidebar::open-location signal, it means that the application should - * open the selected location in the normal way, in a new tab, or in a new - * window. The sidebar takes care of determining the desired way to open the location, - * based on the modifier keys that the user is pressing at the time the selection is made. - * - * If the application never calls nautilus_gtk_places_sidebar_set_open_flags(), then the sidebar will only - * use #NAUTILUS_GTK_PLACES_OPEN_NORMAL in the #NautilusGtkPlacesSidebar::open-location signal. This is the - * default mode of operation. - */ -typedef enum { - NAUTILUS_GTK_PLACES_OPEN_NORMAL = 1 << 0, - NAUTILUS_GTK_PLACES_OPEN_NEW_TAB = 1 << 1, - NAUTILUS_GTK_PLACES_OPEN_NEW_WINDOW = 1 << 2 -} NautilusGtkPlacesOpenFlags; - -GDK_AVAILABLE_IN_3_10 -GType nautilus_gtk_places_sidebar_get_type (void) G_GNUC_CONST; -GDK_AVAILABLE_IN_3_10 -GtkWidget * nautilus_gtk_places_sidebar_new (void); - -GDK_AVAILABLE_IN_3_10 -NautilusGtkPlacesOpenFlags nautilus_gtk_places_sidebar_get_open_flags (NautilusGtkPlacesSidebar *sidebar); -GDK_AVAILABLE_IN_3_10 -void nautilus_gtk_places_sidebar_set_open_flags (NautilusGtkPlacesSidebar *sidebar, - NautilusGtkPlacesOpenFlags flags); - -GDK_AVAILABLE_IN_3_10 -GFile * nautilus_gtk_places_sidebar_get_location (NautilusGtkPlacesSidebar *sidebar); -GDK_AVAILABLE_IN_3_10 -void nautilus_gtk_places_sidebar_set_location (NautilusGtkPlacesSidebar *sidebar, - GFile *location); - -GDK_AVAILABLE_IN_3_18 -gboolean nautilus_gtk_places_sidebar_get_show_recent (NautilusGtkPlacesSidebar *sidebar); -GDK_AVAILABLE_IN_3_18 -void nautilus_gtk_places_sidebar_set_show_recent (NautilusGtkPlacesSidebar *sidebar, - gboolean show_recent); - -GDK_AVAILABLE_IN_3_10 -gboolean nautilus_gtk_places_sidebar_get_show_desktop (NautilusGtkPlacesSidebar *sidebar); -GDK_AVAILABLE_IN_3_10 -void nautilus_gtk_places_sidebar_set_show_desktop (NautilusGtkPlacesSidebar *sidebar, - gboolean show_desktop); - -GDK_DEPRECATED_IN_3_18 -gboolean nautilus_gtk_places_sidebar_get_show_connect_to_server (NautilusGtkPlacesSidebar *sidebar); -GDK_DEPRECATED_IN_3_18 -void nautilus_gtk_places_sidebar_set_show_connect_to_server (NautilusGtkPlacesSidebar *sidebar, - gboolean show_connect_to_server); -GDK_AVAILABLE_IN_3_14 -gboolean nautilus_gtk_places_sidebar_get_show_enter_location (NautilusGtkPlacesSidebar *sidebar); -GDK_AVAILABLE_IN_3_14 -void nautilus_gtk_places_sidebar_set_show_enter_location (NautilusGtkPlacesSidebar *sidebar, - gboolean show_enter_location); - -GDK_AVAILABLE_IN_3_12 -void nautilus_gtk_places_sidebar_set_local_only (NautilusGtkPlacesSidebar *sidebar, - gboolean local_only); -GDK_AVAILABLE_IN_3_12 -gboolean nautilus_gtk_places_sidebar_get_local_only (NautilusGtkPlacesSidebar *sidebar); - - -GDK_AVAILABLE_IN_3_10 -void nautilus_gtk_places_sidebar_add_shortcut (NautilusGtkPlacesSidebar *sidebar, - GFile *location); -GDK_AVAILABLE_IN_3_10 -void nautilus_gtk_places_sidebar_remove_shortcut (NautilusGtkPlacesSidebar *sidebar, - GFile *location); -GDK_AVAILABLE_IN_3_10 -GSList * nautilus_gtk_places_sidebar_list_shortcuts (NautilusGtkPlacesSidebar *sidebar); - -GDK_AVAILABLE_IN_3_10 -GFile * nautilus_gtk_places_sidebar_get_nth_bookmark (NautilusGtkPlacesSidebar *sidebar, - gint n); -GDK_AVAILABLE_IN_3_18 -void nautilus_gtk_places_sidebar_set_drop_targets_visible (NautilusGtkPlacesSidebar *sidebar, - gboolean visible, - GdkDragContext *context); -GDK_AVAILABLE_IN_3_18 -gboolean nautilus_gtk_places_sidebar_get_show_trash (NautilusGtkPlacesSidebar *sidebar); -GDK_AVAILABLE_IN_3_18 -void nautilus_gtk_places_sidebar_set_show_trash (NautilusGtkPlacesSidebar *sidebar, - gboolean show_trash); - -GDK_AVAILABLE_IN_3_18 -void nautilus_gtk_places_sidebar_set_show_other_locations (NautilusGtkPlacesSidebar *sidebar, - gboolean show_other_locations); -GDK_AVAILABLE_IN_3_18 -gboolean nautilus_gtk_places_sidebar_get_show_other_locations (NautilusGtkPlacesSidebar *sidebar); - -GDK_AVAILABLE_IN_3_22 -void nautilus_gtk_places_sidebar_set_show_starred_location (NautilusGtkPlacesSidebar *sidebar, - gboolean show_starred_location); -GDK_AVAILABLE_IN_3_22 -gboolean nautilus_gtk_places_sidebar_get_show_starred_location (NautilusGtkPlacesSidebar *sidebar); -G_END_DECLS - -#endif /* __NAUTILUS_GTK_PLACES_SIDEBAR_H__ */ diff --git a/src/gtk/nautilusgtkplacessidebarprivate.h b/src/gtk/nautilusgtkplacessidebarprivate.h index 6c6dd3daa..c1503ad70 100644 --- a/src/gtk/nautilusgtkplacessidebarprivate.h +++ b/src/gtk/nautilusgtkplacessidebarprivate.h @@ -22,38 +22,126 @@ #define __NAUTILUS_GTK_PLACES_SIDEBAR_PRIVATE_H__ #include <glib.h> -#include "nautilusgtkplacessidebar.h" +#include <gtk/gtk.h> G_BEGIN_DECLS +#define NAUTILUS_TYPE_GTK_PLACES_SIDEBAR (nautilus_gtk_places_sidebar_get_type ()) +#define NAUTILUS_GTK_PLACES_SIDEBAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NAUTILUS_TYPE_GTK_PLACES_SIDEBAR, NautilusGtkPlacesSidebar)) +#define NAUTILUS_GTK_PLACES_SIDEBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_GTK_PLACES_SIDEBAR, NautilusGtkPlacesSidebarClass)) +#define NAUTILUS_IS_GTK_PLACES_SIDEBAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NAUTILUS_TYPE_GTK_PLACES_SIDEBAR)) +#define NAUTILUS_IS_GTK_PLACES_SIDEBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_GTK_PLACES_SIDEBAR)) +#define NAUTILUS_GTK_PLACES_SIDEBAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NAUTILUS_TYPE_GTK_PLACES_SIDEBAR, NautilusGtkPlacesSidebarClass)) + +typedef struct _NautilusGtkPlacesSidebar NautilusGtkPlacesSidebar; +typedef struct _NautilusGtkPlacesSidebarClass NautilusGtkPlacesSidebarClass; + +/* + * NautilusGtkPlacesOpenFlags: + * @NAUTILUS_GTK_PLACES_OPEN_NORMAL: This is the default mode that NautilusGtkPlacesSidebar uses if no other flags + * are specified. It indicates that the calling application should open the selected location + * in the normal way, for example, in the folder view beside the sidebar. + * @NAUTILUS_GTK_PLACES_OPEN_NEW_TAB: When passed to nautilus_gtk_places_sidebar_set_open_flags(), this indicates + * that the application can open folders selected from the sidebar in new tabs. This value + * will be passed to the NautilusGtkPlacesSidebar::open-location signal when the user selects + * that a location be opened in a new tab instead of in the standard fashion. + * @NAUTILUS_GTK_PLACES_OPEN_NEW_WINDOW: Similar to @NAUTILUS_GTK_PLACES_OPEN_NEW_TAB, but indicates that the application + * can open folders in new windows. + * + * These flags serve two purposes. First, the application can call nautilus_gtk_places_sidebar_set_open_flags() + * using these flags as a bitmask. This tells the sidebar that the application is able to open + * folders selected from the sidebar in various ways, for example, in new tabs or in new windows in + * addition to the normal mode. + * + * Second, when one of these values gets passed back to the application in the + * NautilusGtkPlacesSidebar::open-location signal, it means that the application should + * open the selected location in the normal way, in a new tab, or in a new + * window. The sidebar takes care of determining the desired way to open the location, + * based on the modifier keys that the user is pressing at the time the selection is made. + * + * If the application never calls nautilus_gtk_places_sidebar_set_open_flags(), then the sidebar will only + * use NAUTILUS_GTK_PLACES_OPEN_NORMAL in the NautilusGtkPlacesSidebar::open-location signal. This is the + * default mode of operation. + */ +typedef enum { + NAUTILUS_GTK_PLACES_OPEN_NORMAL = 1 << 0, + NAUTILUS_GTK_PLACES_OPEN_NEW_TAB = 1 << 1, + NAUTILUS_GTK_PLACES_OPEN_NEW_WINDOW = 1 << 2 +} NautilusGtkPlacesOpenFlags; + +GType nautilus_gtk_places_sidebar_get_type (void) G_GNUC_CONST; +GtkWidget * nautilus_gtk_places_sidebar_new (void); + +NautilusGtkPlacesOpenFlags nautilus_gtk_places_sidebar_get_open_flags (NautilusGtkPlacesSidebar *sidebar); +void nautilus_gtk_places_sidebar_set_open_flags (NautilusGtkPlacesSidebar *sidebar, + NautilusGtkPlacesOpenFlags flags); + +GFile * nautilus_gtk_places_sidebar_get_location (NautilusGtkPlacesSidebar *sidebar); +void nautilus_gtk_places_sidebar_set_location (NautilusGtkPlacesSidebar *sidebar, + GFile *location); + +gboolean nautilus_gtk_places_sidebar_get_show_recent (NautilusGtkPlacesSidebar *sidebar); +void nautilus_gtk_places_sidebar_set_show_recent (NautilusGtkPlacesSidebar *sidebar, + gboolean show_recent); + +gboolean nautilus_gtk_places_sidebar_get_show_desktop (NautilusGtkPlacesSidebar *sidebar); +void nautilus_gtk_places_sidebar_set_show_desktop (NautilusGtkPlacesSidebar *sidebar, + gboolean show_desktop); + +gboolean nautilus_gtk_places_sidebar_get_show_enter_location (NautilusGtkPlacesSidebar *sidebar); +void nautilus_gtk_places_sidebar_set_show_enter_location (NautilusGtkPlacesSidebar *sidebar, + gboolean show_enter_location); + +void nautilus_gtk_places_sidebar_add_shortcut (NautilusGtkPlacesSidebar *sidebar, + GFile *location); +void nautilus_gtk_places_sidebar_remove_shortcut (NautilusGtkPlacesSidebar *sidebar, + GFile *location); +GListModel * nautilus_gtk_places_sidebar_get_shortcuts (NautilusGtkPlacesSidebar *sidebar); + +GFile * nautilus_gtk_places_sidebar_get_nth_bookmark (NautilusGtkPlacesSidebar *sidebar, + int n); +void nautilus_gtk_places_sidebar_set_drop_targets_visible (NautilusGtkPlacesSidebar *sidebar, + gboolean visible); +gboolean nautilus_gtk_places_sidebar_get_show_trash (NautilusGtkPlacesSidebar *sidebar); +void nautilus_gtk_places_sidebar_set_show_trash (NautilusGtkPlacesSidebar *sidebar, + gboolean show_trash); + +void nautilus_gtk_places_sidebar_set_show_other_locations (NautilusGtkPlacesSidebar *sidebar, + gboolean show_other_locations); +gboolean nautilus_gtk_places_sidebar_get_show_other_locations (NautilusGtkPlacesSidebar *sidebar); + +void nautilus_gtk_places_sidebar_set_show_starred_location (NautilusGtkPlacesSidebar *sidebar, + gboolean show_starred_location); +gboolean nautilus_gtk_places_sidebar_get_show_starred_location (NautilusGtkPlacesSidebar *sidebar); + /* Keep order, since it's used for the sort functions */ typedef enum { - SECTION_INVALID, - SECTION_COMPUTER, - SECTION_MOUNTS, - SECTION_CLOUD, - SECTION_BOOKMARKS, - SECTION_OTHER_LOCATIONS, - N_SECTIONS -} NautilusGtkPlacesSidebarSectionType; + NAUTILUS_GTK_PLACES_SECTION_INVALID, + NAUTILUS_GTK_PLACES_SECTION_COMPUTER, + NAUTILUS_GTK_PLACES_SECTION_MOUNTS, + NAUTILUS_GTK_PLACES_SECTION_CLOUD, + NAUTILUS_GTK_PLACES_SECTION_BOOKMARKS, + NAUTILUS_GTK_PLACES_SECTION_OTHER_LOCATIONS, + NAUTILUS_GTK_PLACES_N_SECTIONS +} NautilusGtkPlacesSectionType; typedef enum { - PLACES_INVALID, - PLACES_BUILT_IN, - PLACES_XDG_DIR, - PLACES_MOUNTED_VOLUME, - PLACES_BOOKMARK, - PLACES_HEADING, - PLACES_CONNECT_TO_SERVER, - PLACES_ENTER_LOCATION, - PLACES_DROP_FEEDBACK, - PLACES_BOOKMARK_PLACEHOLDER, - PLACES_OTHER_LOCATIONS, - PLACES_STARRED_LOCATION, - N_PLACES -} NautilusGtkPlacesSidebarPlaceType; - -gchar *nautilus_gtk_places_sidebar_get_location_title (NautilusGtkPlacesSidebar *sidebar); + NAUTILUS_GTK_PLACES_INVALID, + NAUTILUS_GTK_PLACES_BUILT_IN, + NAUTILUS_GTK_PLACES_XDG_DIR, + NAUTILUS_GTK_PLACES_MOUNTED_VOLUME, + NAUTILUS_GTK_PLACES_BOOKMARK, + NAUTILUS_GTK_PLACES_HEADING, + NAUTILUS_GTK_PLACES_CONNECT_TO_SERVER, + NAUTILUS_GTK_PLACES_ENTER_LOCATION, + NAUTILUS_GTK_PLACES_DROP_FEEDBACK, + NAUTILUS_GTK_PLACES_BOOKMARK_PLACEHOLDER, + NAUTILUS_GTK_PLACES_OTHER_LOCATIONS, + NAUTILUS_GTK_PLACES_STARRED_LOCATION, + NAUTILUS_GTK_PLACES_N_PLACES +} NautilusGtkPlacesPlaceType; + +char *nautilus_gtk_places_sidebar_get_location_title (NautilusGtkPlacesSidebar *sidebar); G_END_DECLS diff --git a/src/gtk/nautilusgtkplacesview.c b/src/gtk/nautilusgtkplacesview.c index 62505c0e1..04fdb9fa4 100644 --- a/src/gtk/nautilusgtkplacesview.c +++ b/src/gtk/nautilusgtkplacesview.c @@ -19,6 +19,7 @@ #include "config.h" #include <glib/gi18n.h> #include <gtk/gtk.h> +#include "nautilus-enum-types.h" #include <gio/gio.h> #include <gio/gvfs.h> @@ -27,14 +28,11 @@ #include "nautilusgtkplacesviewprivate.h" #include "nautilusgtkplacesviewrowprivate.h" -/** - * SECTION:nautilusgtkplacesview - * @Short_description: Widget that displays persistent drives and manages mounted networks - * @Title: NautilusGtkPlacesView - * @See_also: #GtkFileChooser +/*< private > + * NautilusGtkPlacesView: * - * #NautilusGtkPlacesView is a stock widget that displays a list of persistent drives - * such as harddisk partitions and networks. #NautilusGtkPlacesView does not monitor + * NautilusGtkPlacesView is a widget that displays a list of persistent drives + * such as harddisk partitions and networks. NautilusGtkPlacesView does not monitor * removable devices. * * The places view displays drives and networks, and will automatically mount @@ -43,12 +41,27 @@ * shown at the network list. * * To make use of the places view, an application at least needs to connect - * to the #NautilusGtkPlacesView::open-location signal. This is emitted when the user + * to the NautilusGtkPlacesView::open-location signal. This is emitted when the user * selects a location to open in the view. */ -struct _NautilusGtkPlacesViewPrivate +struct _NautilusGtkPlacesViewClass { + GtkBoxClass parent_class; + + void (* open_location) (NautilusGtkPlacesView *view, + GFile *location, + NautilusGtkPlacesOpenFlags open_flags); + + void (* show_error_message) (NautilusGtkPlacesSidebar *sidebar, + const char *primary, + const char *secondary); +}; + +struct _NautilusGtkPlacesView +{ + GtkBox parent_instance; + GVolumeMonitor *volume_monitor; NautilusGtkPlacesOpenFlags open_flags; NautilusGtkPlacesOpenFlags current_open_flags; @@ -59,7 +72,7 @@ struct _NautilusGtkPlacesViewPrivate GCancellable *cancellable; - gchar *search_query; + char *search_query; GtkWidget *actionbar; GtkWidget *address_entry; @@ -83,7 +96,8 @@ struct _NautilusGtkPlacesViewPrivate GCancellable *networks_fetching_cancellable; - guint local_only : 1; + NautilusGtkPlacesViewRow *row_for_action; + guint should_open_location : 1; guint should_pulse_entry : 1; guint entry_pulse_timeout_id; @@ -98,13 +112,18 @@ struct _NautilusGtkPlacesViewPrivate static void mount_volume (NautilusGtkPlacesView *view, GVolume *volume); -static gboolean on_button_press_event (NautilusGtkPlacesViewRow *row, - GdkEventButton *event); - static void on_eject_button_clicked (GtkWidget *widget, NautilusGtkPlacesViewRow *row); -static gboolean on_row_popup_menu (NautilusGtkPlacesViewRow *row); +static gboolean on_row_popup_menu (GtkWidget *widget, + GVariant *args, + gpointer user_data); + +static void click_cb (GtkGesture *gesture, + int n_press, + double x, + double y, + gpointer user_data); static void populate_servers (NautilusGtkPlacesView *view); @@ -118,12 +137,11 @@ static void nautilus_gtk_places_view_set_loading (Nauti static void update_loading (NautilusGtkPlacesView *view); -G_DEFINE_TYPE_WITH_PRIVATE (NautilusGtkPlacesView, nautilus_gtk_places_view, GTK_TYPE_BOX) +G_DEFINE_TYPE (NautilusGtkPlacesView, nautilus_gtk_places_view, GTK_TYPE_BOX) /* NautilusGtkPlacesView properties & signals */ enum { PROP_0, - PROP_LOCAL_ONLY, PROP_OPEN_FLAGS, PROP_FETCHING_NETWORKS, PROP_LOADING, @@ -136,7 +154,7 @@ enum { LAST_SIGNAL }; -const gchar *unsupported_protocols [] = +const char *unsupported_protocols [] = { "file", "afc", "obex", "http", "trash", "burn", "computer", @@ -152,11 +170,7 @@ emit_open_location (NautilusGtkPlacesView *view, GFile *location, NautilusGtkPlacesOpenFlags open_flags) { - NautilusGtkPlacesViewPrivate *priv; - - priv = nautilus_gtk_places_view_get_instance_private (view); - - if ((open_flags & priv->open_flags) == 0) + if ((open_flags & view->open_flags) == 0) open_flags = NAUTILUS_GTK_PLACES_OPEN_NORMAL; g_signal_emit (view, places_view_signals[OPEN_LOCATION], 0, location, open_flags); @@ -164,8 +178,8 @@ emit_open_location (NautilusGtkPlacesView *view, static void emit_show_error_message (NautilusGtkPlacesView *view, - gchar *primary_message, - gchar *secondary_message) + char *primary_message, + char *secondary_message) { g_signal_emit (view, places_view_signals[SHOW_ERROR_MESSAGE], 0, primary_message, secondary_message); @@ -180,15 +194,13 @@ server_file_changed_cb (NautilusGtkPlacesView *view) static GBookmarkFile * server_list_load (NautilusGtkPlacesView *view) { - NautilusGtkPlacesViewPrivate *priv; GBookmarkFile *bookmarks; GError *error = NULL; - gchar *datadir; - gchar *filename; + char *datadir; + char *filename; - priv = nautilus_gtk_places_view_get_instance_private (view); bookmarks = g_bookmark_file_new (); - datadir = g_build_filename (g_get_user_config_dir (), "gtk-3.0", NULL); + datadir = g_build_filename (g_get_user_config_dir (), "gtk-4.0", NULL); filename = g_build_filename (datadir, "servers", NULL); g_mkdir_with_parents (datadir, 0700); @@ -207,13 +219,13 @@ server_list_load (NautilusGtkPlacesView *view) } /* Monitor the file in case it's modified outside this code */ - if (!priv->server_list_monitor) + if (!view->server_list_monitor) { - priv->server_list_file = g_file_new_for_path (filename); + view->server_list_file = g_file_new_for_path (filename); - if (priv->server_list_file) + if (view->server_list_file) { - priv->server_list_monitor = g_file_monitor_file (priv->server_list_file, + view->server_list_monitor = g_file_monitor_file (view->server_list_file, G_FILE_MONITOR_NONE, NULL, &error); @@ -225,14 +237,14 @@ server_list_load (NautilusGtkPlacesView *view) } else { - g_signal_connect_swapped (priv->server_list_monitor, + g_signal_connect_swapped (view->server_list_monitor, "changed", G_CALLBACK (server_file_changed_cb), view); } } - g_clear_object (&priv->server_list_file); + g_clear_object (&view->server_list_file); } g_free (datadir); @@ -244,9 +256,9 @@ server_list_load (NautilusGtkPlacesView *view) static void server_list_save (GBookmarkFile *bookmarks) { - gchar *filename; + char *filename; - filename = g_build_filename (g_get_user_config_dir (), "gtk-3.0", "servers", NULL); + filename = g_build_filename (g_get_user_config_dir (), "gtk-4.0", "servers", NULL); g_bookmark_file_to_file (bookmarks, filename, NULL); g_free (filename); } @@ -258,8 +270,9 @@ server_list_add_server (NautilusGtkPlacesView *view, GBookmarkFile *bookmarks; GFileInfo *info; GError *error; - gchar *title; - gchar *uri; + char *title; + char *uri; + GDateTime *now; error = NULL; bookmarks = server_list_load (view); @@ -277,7 +290,9 @@ server_list_add_server (NautilusGtkPlacesView *view, title = g_file_info_get_attribute_as_string (info, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME); g_bookmark_file_set_title (bookmarks, uri, title); - g_bookmark_file_set_visited (bookmarks, uri, -1); + now = g_date_time_new_now_utc (); + g_bookmark_file_set_visited_date_time (bookmarks, uri, now); + g_date_time_unref (now); g_bookmark_file_add_application (bookmarks, uri, NULL, NULL); server_list_save (bookmarks); @@ -290,7 +305,7 @@ server_list_add_server (NautilusGtkPlacesView *view, static void server_list_remove_server (NautilusGtkPlacesView *view, - const gchar *uri) + const char *uri) { GBookmarkFile *bookmarks; @@ -311,11 +326,11 @@ get_toplevel (GtkWidget *widget) { GtkWidget *toplevel; - toplevel = gtk_widget_get_toplevel (widget); - if (!gtk_widget_is_toplevel (toplevel)) - return NULL; - else + toplevel = GTK_WIDGET (gtk_widget_get_root (widget)); + if (GTK_IS_WINDOW (toplevel)) return GTK_WINDOW (toplevel); + else + return NULL; } static void @@ -324,26 +339,16 @@ set_busy_cursor (NautilusGtkPlacesView *view, { GtkWidget *widget; GtkWindow *toplevel; - GdkDisplay *display; - GdkCursor *cursor; toplevel = get_toplevel (GTK_WIDGET (view)); widget = GTK_WIDGET (toplevel); if (!toplevel || !gtk_widget_get_realized (widget)) return; - display = gtk_widget_get_display (widget); - if (busy) - cursor = gdk_cursor_new_from_name (display, "progress"); + gtk_widget_set_cursor_from_name (widget, "progress"); else - cursor = NULL; - - gdk_window_set_cursor (gtk_widget_get_window (widget), cursor); - gdk_display_flush (display); - - if (cursor) - g_object_unref (cursor); + gtk_widget_set_cursor (widget, NULL); } /* Activates the given row, with the given flags as parameter */ @@ -352,12 +357,10 @@ activate_row (NautilusGtkPlacesView *view, NautilusGtkPlacesViewRow *row, NautilusGtkPlacesOpenFlags flags) { - NautilusGtkPlacesViewPrivate *priv; GVolume *volume; GMount *mount; GFile *file; - priv = nautilus_gtk_places_view_get_instance_private (view); mount = nautilus_gtk_places_view_row_get_mount (row); volume = nautilus_gtk_places_view_row_get_volume (row); file = nautilus_gtk_places_view_row_get_file (row); @@ -380,7 +383,7 @@ activate_row (NautilusGtkPlacesView *view, * When the row is activated, the unmounted volume shall * be mounted and opened right after. */ - priv->should_open_location = TRUE; + view->should_open_location = TRUE; nautilus_gtk_places_view_row_set_busy (row, TRUE); mount_volume (view, volume); @@ -390,47 +393,46 @@ activate_row (NautilusGtkPlacesView *view, static void update_places (NautilusGtkPlacesView *view); static void -nautilus_gtk_places_view_destroy (GtkWidget *widget) +nautilus_gtk_places_view_finalize (GObject *object) { - NautilusGtkPlacesView *self = NAUTILUS_GTK_PLACES_VIEW (widget); - NautilusGtkPlacesViewPrivate *priv = nautilus_gtk_places_view_get_instance_private (self); + NautilusGtkPlacesView *view = (NautilusGtkPlacesView *)object; - priv->destroyed = 1; + if (view->entry_pulse_timeout_id > 0) + g_source_remove (view->entry_pulse_timeout_id); - g_signal_handlers_disconnect_by_func (priv->volume_monitor, update_places, widget); + g_clear_pointer (&view->search_query, g_free); + g_clear_object (&view->server_list_file); + g_clear_object (&view->server_list_monitor); + g_clear_object (&view->volume_monitor); + g_clear_object (&view->network_monitor); + g_clear_object (&view->cancellable); + g_clear_object (&view->networks_fetching_cancellable); + g_clear_object (&view->path_size_group); + g_clear_object (&view->space_size_group); - if (priv->network_monitor) - g_signal_handlers_disconnect_by_func (priv->network_monitor, update_places, widget); - - if (priv->server_list_monitor) - g_signal_handlers_disconnect_by_func (priv->server_list_monitor, server_file_changed_cb, widget); - - g_cancellable_cancel (priv->cancellable); - g_cancellable_cancel (priv->networks_fetching_cancellable); - - GTK_WIDGET_CLASS (nautilus_gtk_places_view_parent_class)->destroy (widget); + G_OBJECT_CLASS (nautilus_gtk_places_view_parent_class)->finalize (object); } static void -nautilus_gtk_places_view_finalize (GObject *object) +nautilus_gtk_places_view_dispose (GObject *object) { - NautilusGtkPlacesView *self = (NautilusGtkPlacesView *)object; - NautilusGtkPlacesViewPrivate *priv = nautilus_gtk_places_view_get_instance_private (self); + NautilusGtkPlacesView *view = (NautilusGtkPlacesView *)object; - if (priv->entry_pulse_timeout_id > 0) - g_source_remove (priv->entry_pulse_timeout_id); + view->destroyed = 1; - g_clear_pointer (&priv->search_query, g_free); - g_clear_object (&priv->server_list_file); - g_clear_object (&priv->server_list_monitor); - g_clear_object (&priv->volume_monitor); - g_clear_object (&priv->network_monitor); - g_clear_object (&priv->cancellable); - g_clear_object (&priv->networks_fetching_cancellable); - g_clear_object (&priv->path_size_group); - g_clear_object (&priv->space_size_group); + g_signal_handlers_disconnect_by_func (view->volume_monitor, update_places, object); - G_OBJECT_CLASS (nautilus_gtk_places_view_parent_class)->finalize (object); + if (view->network_monitor) + g_signal_handlers_disconnect_by_func (view->network_monitor, update_places, object); + + if (view->server_list_monitor) + g_signal_handlers_disconnect_by_func (view->server_list_monitor, server_file_changed_cb, object); + + g_cancellable_cancel (view->cancellable); + g_cancellable_cancel (view->networks_fetching_cancellable); + g_clear_pointer (&view->popup_menu, gtk_widget_unparent); + + G_OBJECT_CLASS (nautilus_gtk_places_view_parent_class)->dispose (object); } static void @@ -443,14 +445,14 @@ nautilus_gtk_places_view_get_property (GObject *object, switch (prop_id) { - case PROP_LOCAL_ONLY: - g_value_set_boolean (value, nautilus_gtk_places_view_get_local_only (self)); - break; - case PROP_LOADING: g_value_set_boolean (value, nautilus_gtk_places_view_get_loading (self)); break; + case PROP_OPEN_FLAGS: + g_value_set_flags (value, nautilus_gtk_places_view_get_open_flags (self)); + break; + case PROP_FETCHING_NETWORKS: g_value_set_boolean (value, nautilus_gtk_places_view_get_fetching_networks (self)); break; @@ -470,8 +472,8 @@ nautilus_gtk_places_view_set_property (GObject *object, switch (prop_id) { - case PROP_LOCAL_ONLY: - nautilus_gtk_places_view_set_local_only (self, g_value_get_boolean (value)); + case PROP_OPEN_FLAGS: + nautilus_gtk_places_view_set_open_flags (self, g_value_get_flags (value)); break; default: @@ -484,7 +486,7 @@ is_external_volume (GVolume *volume) { gboolean is_external; GDrive *drive; - gchar *id; + char *id; drive = g_volume_get_drive (volume); id = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_CLASS); @@ -505,7 +507,7 @@ is_external_volume (GVolume *volume) typedef struct { - gchar *uri; + char *uri; NautilusGtkPlacesView *view; } RemoveServerData; @@ -520,14 +522,12 @@ on_remove_server_button_clicked (RemoveServerData *data) static void populate_servers (NautilusGtkPlacesView *view) { - NautilusGtkPlacesViewPrivate *priv; GBookmarkFile *server_list; - GList *children; - gchar **uris; + GtkWidget *child; + char **uris; gsize num_uris; - gint i; + int i; - priv = nautilus_gtk_places_view_get_instance_private (view); server_list = server_list_load (view); if (!server_list) @@ -535,7 +535,7 @@ populate_servers (NautilusGtkPlacesView *view) uris = g_bookmark_file_get_uris (server_list, &num_uris); - gtk_stack_set_visible_child_name (GTK_STACK (priv->recent_servers_stack), + gtk_stack_set_visible_child_name (GTK_STACK (view->recent_servers_stack), num_uris > 0 ? "list" : "empty"); if (!uris) @@ -545,10 +545,10 @@ populate_servers (NautilusGtkPlacesView *view) } /* clear previous items */ - children = gtk_container_get_children (GTK_CONTAINER (priv->recent_servers_listbox)); - g_list_free_full (children, (GDestroyNotify) gtk_widget_destroy); + while ((child = gtk_widget_get_first_child (GTK_WIDGET (view->recent_servers_listbox)))) + gtk_list_box_remove (GTK_LIST_BOX (view->recent_servers_listbox), child); - gtk_list_store_clear (priv->completion_store); + gtk_list_store_clear (view->completion_store); for (i = 0; i < num_uris; i++) { @@ -558,15 +558,15 @@ populate_servers (NautilusGtkPlacesView *view) GtkWidget *grid; GtkWidget *button; GtkWidget *label; - gchar *name; - gchar *dup_uri; + char *name; + char *dup_uri; name = g_bookmark_file_get_title (server_list, uris[i], NULL); dup_uri = g_strdup (uris[i]); /* add to the completion list */ - gtk_list_store_append (priv->completion_store, &iter); - gtk_list_store_set (priv->completion_store, + gtk_list_store_append (view->completion_store, &iter); + gtk_list_store_set (view->completion_store, &iter, 0, name, 1, uris[i], @@ -577,7 +577,6 @@ populate_servers (NautilusGtkPlacesView *view) grid = g_object_new (GTK_TYPE_GRID, "orientation", GTK_ORIENTATION_VERTICAL, - "border-width", 3, NULL); /* name of the connected uri, if any */ @@ -585,26 +584,26 @@ populate_servers (NautilusGtkPlacesView *view) gtk_widget_set_hexpand (label, TRUE); gtk_label_set_xalign (GTK_LABEL (label), 0.0); gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END); - gtk_container_add (GTK_CONTAINER (grid), label); + gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1); /* the uri itself */ label = gtk_label_new (uris[i]); gtk_widget_set_hexpand (label, TRUE); gtk_label_set_xalign (GTK_LABEL (label), 0.0); gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END); - gtk_style_context_add_class (gtk_widget_get_style_context (label), "dim-label"); - gtk_container_add (GTK_CONTAINER (grid), label); + gtk_widget_add_css_class (label, "dim-label"); + gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1); /* remove button */ - button = gtk_button_new_from_icon_name ("window-close-symbolic", GTK_ICON_SIZE_BUTTON); + button = gtk_button_new_from_icon_name ("window-close-symbolic"); gtk_widget_set_halign (button, GTK_ALIGN_END); gtk_widget_set_valign (button, GTK_ALIGN_CENTER); - gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); - gtk_style_context_add_class (gtk_widget_get_style_context (button), "sidebar-button"); + gtk_button_set_has_frame (GTK_BUTTON (button), FALSE); + gtk_widget_add_css_class (button, "sidebar-button"); gtk_grid_attach (GTK_GRID (grid), button, 1, 0, 1, 2); - gtk_container_add (GTK_CONTAINER (row), grid); - gtk_container_add (GTK_CONTAINER (priv->recent_servers_listbox), row); + gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), grid); + gtk_list_box_insert (GTK_LIST_BOX (view->recent_servers_listbox), row, -1); /* custom data */ data = g_new0 (RemoveServerData, 1); @@ -619,8 +618,6 @@ populate_servers (NautilusGtkPlacesView *view) G_CALLBACK (on_remove_server_button_clicked), data); - gtk_widget_show_all (row); - g_free (name); } @@ -631,38 +628,33 @@ populate_servers (NautilusGtkPlacesView *view) static void update_view_mode (NautilusGtkPlacesView *view) { - NautilusGtkPlacesViewPrivate *priv; - GList *children; - GList *l; + GtkWidget *child; gboolean show_listbox; - priv = nautilus_gtk_places_view_get_instance_private (view); show_listbox = FALSE; /* drives */ - children = gtk_container_get_children (GTK_CONTAINER (priv->listbox)); - - for (l = children; l; l = l->next) + for (child = gtk_widget_get_first_child (GTK_WIDGET (view->listbox)); + child != NULL; + child = gtk_widget_get_next_sibling (child)) { /* GtkListBox filter rows by changing their GtkWidget::child-visible property */ - if (gtk_widget_get_child_visible (l->data)) + if (gtk_widget_get_child_visible (child)) { show_listbox = TRUE; break; } } - g_list_free (children); - if (!show_listbox && - priv->search_query && - priv->search_query[0] != '\0') + view->search_query && + view->search_query[0] != '\0') { - gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "empty-search"); + gtk_stack_set_visible_child_name (GTK_STACK (view->stack), "empty-search"); } else { - gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "browse"); + gtk_stack_set_visible_child_name (GTK_STACK (view->stack), "browse"); } } @@ -671,31 +663,36 @@ insert_row (NautilusGtkPlacesView *view, GtkWidget *row, gboolean is_network) { - NautilusGtkPlacesViewPrivate *priv; - - priv = nautilus_gtk_places_view_get_instance_private (view); + GtkEventController *controller; + GtkShortcutTrigger *trigger; + GtkShortcutAction *action; + GtkShortcut *shortcut; + GtkGesture *gesture; g_object_set_data (G_OBJECT (row), "is-network", GINT_TO_POINTER (is_network)); - g_signal_connect_swapped (nautilus_gtk_places_view_row_get_event_box (NAUTILUS_GTK_PLACES_VIEW_ROW (row)), - "button-press-event", - G_CALLBACK (on_button_press_event), - row); + controller = gtk_shortcut_controller_new (); + trigger = gtk_alternative_trigger_new (gtk_keyval_trigger_new (GDK_KEY_F10, GDK_SHIFT_MASK), + gtk_keyval_trigger_new (GDK_KEY_Menu, 0)); + action = gtk_callback_action_new (on_row_popup_menu, row, NULL); + shortcut = gtk_shortcut_new (trigger, action); + gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller), shortcut); + gtk_widget_add_controller (GTK_WIDGET (row), controller); - g_signal_connect (row, - "popup-menu", - G_CALLBACK (on_row_popup_menu), - row); + gesture = gtk_gesture_click_new (); + gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_SECONDARY); + g_signal_connect (gesture, "pressed", G_CALLBACK (click_cb), row); + gtk_widget_add_controller (row, GTK_EVENT_CONTROLLER (gesture)); g_signal_connect (nautilus_gtk_places_view_row_get_eject_button (NAUTILUS_GTK_PLACES_VIEW_ROW (row)), "clicked", G_CALLBACK (on_eject_button_clicked), row); - nautilus_gtk_places_view_row_set_path_size_group (NAUTILUS_GTK_PLACES_VIEW_ROW (row), priv->path_size_group); - nautilus_gtk_places_view_row_set_space_size_group (NAUTILUS_GTK_PLACES_VIEW_ROW (row), priv->space_size_group); + nautilus_gtk_places_view_row_set_path_size_group (NAUTILUS_GTK_PLACES_VIEW_ROW (row), view->path_size_group); + nautilus_gtk_places_view_row_set_space_size_group (NAUTILUS_GTK_PLACES_VIEW_ROW (row), view->space_size_group); - gtk_container_add (GTK_CONTAINER (priv->listbox), row); + gtk_list_box_insert (GTK_LIST_BOX (view->listbox), row, -1); } static void @@ -706,9 +703,9 @@ add_volume (NautilusGtkPlacesView *view, GMount *mount; GFile *root; GIcon *icon; - gchar *identifier; - gchar *name; - gchar *path; + char *identifier; + char *name; + char *path; if (is_external_volume (volume)) return; @@ -754,10 +751,10 @@ add_mount (NautilusGtkPlacesView *view, gboolean is_network; GFile *root; GIcon *icon; - gchar *name; - gchar *path; - gchar *uri; - gchar *schema; + char *name; + char *path; + char *uri; + char *schema; icon = g_mount_get_icon (mount); name = g_mount_get_name (mount); @@ -814,8 +811,8 @@ static void add_file (NautilusGtkPlacesView *view, GFile *file, GIcon *icon, - const gchar *display_name, - const gchar *path, + const char *display_name, + const char *path, gboolean is_network) { GtkWidget *row; @@ -835,55 +832,46 @@ add_file (NautilusGtkPlacesView *view, static gboolean has_networks (NautilusGtkPlacesView *view) { - GList *l; - NautilusGtkPlacesViewPrivate *priv; - GList *children; + GtkWidget *child; gboolean has_network = FALSE; - priv = nautilus_gtk_places_view_get_instance_private (view); - - children = gtk_container_get_children (GTK_CONTAINER (priv->listbox)); - for (l = children; l != NULL; l = l->next) + for (child = gtk_widget_get_first_child (GTK_WIDGET (view->listbox)); + child != NULL; + child = gtk_widget_get_next_sibling (child)) { - if (GPOINTER_TO_INT (g_object_get_data (l->data, "is-network")) == TRUE && - g_object_get_data (l->data, "is-placeholder") == NULL) + if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (child), "is-network")) && + g_object_get_data (G_OBJECT (child), "is-placeholder") == NULL) { has_network = TRUE; break; } } - g_list_free (children); - return has_network; } static void update_network_state (NautilusGtkPlacesView *view) { - NautilusGtkPlacesViewPrivate *priv; - - priv = nautilus_gtk_places_view_get_instance_private (view); - - if (priv->network_placeholder == NULL) + if (view->network_placeholder == NULL) { - priv->network_placeholder = gtk_list_box_row_new (); - priv->network_placeholder_label = gtk_label_new (""); - gtk_label_set_xalign (GTK_LABEL (priv->network_placeholder_label), 0.0); - gtk_widget_set_margin_start (priv->network_placeholder_label, 12); - gtk_widget_set_margin_end (priv->network_placeholder_label, 12); - gtk_widget_set_margin_top (priv->network_placeholder_label, 6); - gtk_widget_set_margin_bottom (priv->network_placeholder_label, 6); - gtk_widget_set_hexpand (priv->network_placeholder_label, TRUE); - gtk_widget_set_sensitive (priv->network_placeholder, FALSE); - gtk_container_add (GTK_CONTAINER (priv->network_placeholder), - priv->network_placeholder_label); - g_object_set_data (G_OBJECT (priv->network_placeholder), + view->network_placeholder = gtk_list_box_row_new (); + view->network_placeholder_label = gtk_label_new (""); + gtk_label_set_xalign (GTK_LABEL (view->network_placeholder_label), 0.0); + gtk_widget_set_margin_start (view->network_placeholder_label, 12); + gtk_widget_set_margin_end (view->network_placeholder_label, 12); + gtk_widget_set_margin_top (view->network_placeholder_label, 6); + gtk_widget_set_margin_bottom (view->network_placeholder_label, 6); + gtk_widget_set_hexpand (view->network_placeholder_label, TRUE); + gtk_widget_set_sensitive (view->network_placeholder, FALSE); + gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (view->network_placeholder), + view->network_placeholder_label); + g_object_set_data (G_OBJECT (view->network_placeholder), "is-network", GINT_TO_POINTER (TRUE)); /* mark the row as placeholder, so it always goes first */ - g_object_set_data (G_OBJECT (priv->network_placeholder), + g_object_set_data (G_OBJECT (view->network_placeholder), "is-placeholder", GINT_TO_POINTER (TRUE)); - gtk_container_add (GTK_CONTAINER (priv->listbox), priv->network_placeholder); + gtk_list_box_insert (GTK_LIST_BOX (view->listbox), view->network_placeholder, -1); } if (nautilus_gtk_places_view_get_fetching_networks (view)) @@ -892,38 +880,35 @@ update_network_state (NautilusGtkPlacesView *view) * otherwise just show the spinner in the header */ if (!has_networks (view)) { - gtk_widget_show_all (priv->network_placeholder); - gtk_label_set_text (GTK_LABEL (priv->network_placeholder_label), + gtk_widget_show (view->network_placeholder); + gtk_label_set_text (GTK_LABEL (view->network_placeholder_label), _("Searching for network locations")); } } else if (!has_networks (view)) { - gtk_widget_show_all (priv->network_placeholder); - gtk_label_set_text (GTK_LABEL (priv->network_placeholder_label), + gtk_widget_show (view->network_placeholder); + gtk_label_set_text (GTK_LABEL (view->network_placeholder_label), _("No network locations found")); } else { - gtk_widget_hide (priv->network_placeholder); + gtk_widget_hide (view->network_placeholder); } } static void -monitor_network (NautilusGtkPlacesView *self) +monitor_network (NautilusGtkPlacesView *view) { - NautilusGtkPlacesViewPrivate *priv; GFile *network_file; GError *error; - priv = nautilus_gtk_places_view_get_instance_private (self); - - if (priv->network_monitor) + if (view->network_monitor) return; error = NULL; network_file = g_file_new_for_uri ("network:///"); - priv->network_monitor = g_file_monitor (network_file, + view->network_monitor = g_file_monitor (network_file, G_FILE_MONITOR_NONE, NULL, &error); @@ -937,10 +922,10 @@ monitor_network (NautilusGtkPlacesView *self) return; } - g_signal_connect_swapped (priv->network_monitor, + g_signal_connect_swapped (view->network_monitor, "changed", G_CALLBACK (update_places), - self); + view); } static void @@ -951,10 +936,10 @@ populate_networks (NautilusGtkPlacesView *view, GList *l; GFile *file; GFile *activatable_file; - gchar *uri; + char *uri; GFileType type; GIcon *icon; - gchar *display_name; + char *display_name; for (l = detected_networks; l != NULL; l = l->next) { @@ -982,13 +967,11 @@ network_enumeration_next_files_finished (GObject *source_object, GAsyncResult *res, gpointer user_data) { - NautilusGtkPlacesViewPrivate *priv; NautilusGtkPlacesView *view; GList *detected_networks; GError *error; view = NAUTILUS_GTK_PLACES_VIEW (user_data); - priv = nautilus_gtk_places_view_get_instance_private (view); error = NULL; detected_networks = g_file_enumerator_next_files_finish (G_FILE_ENUMERATOR (source_object), @@ -996,9 +979,14 @@ network_enumeration_next_files_finished (GObject *source_object, if (error) { - if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning ("Failed to fetch network locations: %s", error->message); + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + { + g_clear_error (&error); + g_object_unref (view); + return; + } + g_warning ("Failed to fetch network locations: %s", error->message); g_clear_error (&error); } else @@ -1009,16 +997,11 @@ network_enumeration_next_files_finished (GObject *source_object, g_list_free_full (detected_networks, g_object_unref); } - g_object_unref (view); + update_network_state (view); + monitor_network (view); + update_loading (view); - /* avoid to update widgets if we are already destroyed - (and got cancelled s a result of that) */ - if (!priv->destroyed) - { - update_network_state (view); - monitor_network (view); - update_loading (view); - } + g_object_unref (view); } static void @@ -1026,7 +1009,7 @@ network_enumeration_finished (GObject *source_object, GAsyncResult *res, gpointer user_data) { - NautilusGtkPlacesViewPrivate *priv; + NautilusGtkPlacesView *view = NAUTILUS_GTK_PLACES_VIEW (user_data); GFileEnumerator *enumerator; GError *error; @@ -1040,15 +1023,14 @@ network_enumeration_finished (GObject *source_object, g_warning ("Failed to fetch network locations: %s", error->message); g_clear_error (&error); - g_object_unref (NAUTILUS_GTK_PLACES_VIEW (user_data)); + g_object_unref (view); } else { - priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (user_data)); g_file_enumerator_next_files_async (enumerator, G_MAXINT32, G_PRIORITY_DEFAULT, - priv->networks_fetching_cancellable, + view->networks_fetching_cancellable, network_enumeration_next_files_finished, user_data); g_object_unref (enumerator); @@ -1058,12 +1040,10 @@ network_enumeration_finished (GObject *source_object, static void fetch_networks (NautilusGtkPlacesView *view) { - NautilusGtkPlacesViewPrivate *priv; GFile *network_file; - const gchar * const *supported_uris; + const char * const *supported_uris; gboolean found; - priv = nautilus_gtk_places_view_get_instance_private (view); supported_uris = g_vfs_get_supported_uri_schemes (g_vfs_get_default ()); for (found = FALSE; !found && supported_uris && supported_uris[0]; supported_uris++) @@ -1075,9 +1055,9 @@ fetch_networks (NautilusGtkPlacesView *view) network_file = g_file_new_for_uri ("network:///"); - g_cancellable_cancel (priv->networks_fetching_cancellable); - g_clear_object (&priv->networks_fetching_cancellable); - priv->networks_fetching_cancellable = g_cancellable_new (); + g_cancellable_cancel (view->networks_fetching_cancellable); + g_clear_object (&view->networks_fetching_cancellable); + view->networks_fetching_cancellable = g_cancellable_new (); nautilus_gtk_places_view_set_fetching_networks (view, TRUE); update_network_state (view); @@ -1086,7 +1066,7 @@ fetch_networks (NautilusGtkPlacesView *view) "standard::type,standard::target-uri,standard::name,standard::display-name,standard::icon", G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, - priv->networks_fetching_cancellable, + view->networks_fetching_cancellable, network_enumeration_finished, view); @@ -1096,21 +1076,19 @@ fetch_networks (NautilusGtkPlacesView *view) static void update_places (NautilusGtkPlacesView *view) { - NautilusGtkPlacesViewPrivate *priv; - GList *children; GList *mounts; GList *volumes; GList *drives; GList *l; GIcon *icon; GFile *file; - - priv = nautilus_gtk_places_view_get_instance_private (view); + GtkWidget *child; /* Clear all previously added items */ - children = gtk_container_get_children (GTK_CONTAINER (priv->listbox)); - g_list_free_full (children, (GDestroyNotify) gtk_widget_destroy); - priv->network_placeholder = NULL; + while ((child = gtk_widget_get_first_child (GTK_WIDGET (view->listbox)))) + gtk_list_box_remove (GTK_LIST_BOX (view->listbox), child); + + view->network_placeholder = NULL; /* Inform clients that we started loading */ nautilus_gtk_places_view_set_loading (view, TRUE); @@ -1124,7 +1102,7 @@ update_places (NautilusGtkPlacesView *view) g_clear_object (&icon); /* Add currently connected drives */ - drives = g_volume_monitor_get_connected_drives (priv->volume_monitor); + drives = g_volume_monitor_get_connected_drives (view->volume_monitor); for (l = drives; l != NULL; l = l->next) add_drive (view, l->data); @@ -1136,7 +1114,7 @@ update_places (NautilusGtkPlacesView *view) * add_drive before, add all volumes that aren't associated with a * drive. */ - volumes = g_volume_monitor_get_volumes (priv->volume_monitor); + volumes = g_volume_monitor_get_volumes (view->volume_monitor); for (l = volumes; l != NULL; l = l->next) { @@ -1161,7 +1139,7 @@ update_places (NautilusGtkPlacesView *view) * Now that all necessary drives and volumes were already added, add mounts * that have no volume, such as /etc/mtab mounts, ftp, sftp, etc. */ - mounts = g_volume_monitor_get_mounts (priv->volume_monitor); + mounts = g_volume_monitor_get_mounts (view->volume_monitor); for (l = mounts; l != NULL; l = l->next) { @@ -1198,8 +1176,7 @@ server_mount_ready_cb (GObject *source_file, GAsyncResult *res, gpointer user_data) { - NautilusGtkPlacesViewPrivate *priv; - NautilusGtkPlacesView *view; + NautilusGtkPlacesView *view = NAUTILUS_GTK_PLACES_VIEW (user_data); gboolean should_show; GError *error; GFile *location; @@ -1208,8 +1185,6 @@ server_mount_ready_cb (GObject *source_file, should_show = TRUE; error = NULL; - view = NAUTILUS_GTK_PLACES_VIEW (user_data); - g_file_mount_enclosing_volume_finish (location, res, &error); if (error) { @@ -1236,19 +1211,19 @@ server_mount_ready_cb (GObject *source_file, g_clear_error (&error); } - priv = nautilus_gtk_places_view_get_instance_private (view); - - if (priv->destroyed) { - g_object_unref (view); - return; - } + if (view->destroyed) + { + g_object_unref (view); + return; + } - priv->should_pulse_entry = FALSE; + view->should_pulse_entry = FALSE; + gtk_entry_set_progress_fraction (GTK_ENTRY (view->address_entry), 0); /* Restore from Cancel to Connect */ - gtk_button_set_label (GTK_BUTTON (priv->connect_button), _("Con_nect")); - gtk_widget_set_sensitive (priv->address_entry, TRUE); - priv->connecting_to_server = FALSE; + gtk_button_set_label (GTK_BUTTON (view->connect_button), _("Con_nect")); + gtk_widget_set_sensitive (view->address_entry, TRUE); + view->connecting_to_server = FALSE; if (should_show) { @@ -1259,9 +1234,9 @@ server_mount_ready_cb (GObject *source_file, * Otherwise, the user would lost the typed address even if it fails * to connect. */ - gtk_entry_set_text (GTK_ENTRY (priv->address_entry), ""); + gtk_editable_set_text (GTK_EDITABLE (view->address_entry), ""); - if (priv->should_open_location) + if (view->should_open_location) { GMount *mount; GFile *root; @@ -1271,19 +1246,19 @@ server_mount_ready_cb (GObject *source_file, * invisible, which happens e.g for smb-browse, but the location * should be opened anyway... */ - mount = g_file_find_enclosing_mount (location, priv->cancellable, NULL); + mount = g_file_find_enclosing_mount (location, view->cancellable, NULL); if (mount) { root = g_mount_get_default_location (mount); - emit_open_location (view, root, priv->open_flags); + emit_open_location (view, root, view->open_flags); g_object_unref (root); g_object_unref (mount); } else { - emit_open_location (view, location, priv->open_flags); + emit_open_location (view, location, view->open_flags); } } } @@ -1297,8 +1272,7 @@ volume_mount_ready_cb (GObject *source_volume, GAsyncResult *res, gpointer user_data) { - NautilusGtkPlacesViewPrivate *priv; - NautilusGtkPlacesView *view; + NautilusGtkPlacesView *view = NAUTILUS_GTK_PLACES_VIEW (user_data); gboolean should_show; GVolume *volume; GError *error; @@ -1335,16 +1309,13 @@ volume_mount_ready_cb (GObject *source_volume, g_clear_error (&error); } - view = NAUTILUS_GTK_PLACES_VIEW (user_data); - priv = nautilus_gtk_places_view_get_instance_private (view); - - if (priv->destroyed) + if (view->destroyed) { g_object_unref(view); return; } - priv->mounting_volume = FALSE; + view->mounting_volume = FALSE; update_loading (view); if (should_show) @@ -1355,8 +1326,8 @@ volume_mount_ready_cb (GObject *source_volume, mount = g_volume_get_mount (volume); root = g_mount_get_default_location (mount); - if (priv->should_open_location) - emit_open_location (NAUTILUS_GTK_PLACES_VIEW (user_data), root, priv->open_flags); + if (view->should_open_location) + emit_open_location (NAUTILUS_GTK_PLACES_VIEW (user_data), root, view->open_flags); g_object_unref (mount); g_object_unref (root); @@ -1372,7 +1343,6 @@ unmount_ready_cb (GObject *source_mount, gpointer user_data) { NautilusGtkPlacesView *view; - NautilusGtkPlacesViewPrivate *priv; GMount *mount; GError *error; @@ -1395,14 +1365,12 @@ unmount_ready_cb (GObject *source_mount, g_clear_error (&error); } - priv = nautilus_gtk_places_view_get_instance_private (view); - - if (priv->destroyed) { + if (view->destroyed) { g_object_unref (view); return; } - priv->unmounting_mount = FALSE; + view->unmounting_mount = FALSE; update_loading (view); g_object_unref (view); @@ -1411,27 +1379,24 @@ unmount_ready_cb (GObject *source_mount, static gboolean pulse_entry_cb (gpointer user_data) { - NautilusGtkPlacesViewPrivate *priv; + NautilusGtkPlacesView *view = NAUTILUS_GTK_PLACES_VIEW (user_data); - priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (user_data)); - - if (priv->destroyed) + if (view->destroyed) { - priv->entry_pulse_timeout_id = 0; + view->entry_pulse_timeout_id = 0; return G_SOURCE_REMOVE; } - else if (priv->should_pulse_entry) + else if (view->should_pulse_entry) { - gtk_entry_progress_pulse (GTK_ENTRY (priv->address_entry)); + gtk_entry_progress_pulse (GTK_ENTRY (view->address_entry)); return G_SOURCE_CONTINUE; } else { - gtk_entry_set_progress_pulse_step (GTK_ENTRY (priv->address_entry), 0.0); - gtk_entry_set_progress_fraction (GTK_ENTRY (priv->address_entry), 0.0); - priv->entry_pulse_timeout_id = 0; + gtk_entry_set_progress_fraction (GTK_ENTRY (view->address_entry), 0); + view->entry_pulse_timeout_id = 0; return G_SOURCE_REMOVE; } @@ -1441,18 +1406,16 @@ static void unmount_mount (NautilusGtkPlacesView *view, GMount *mount) { - NautilusGtkPlacesViewPrivate *priv; GMountOperation *operation; GtkWidget *toplevel; - priv = nautilus_gtk_places_view_get_instance_private (view); - toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view)); + toplevel = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (view))); - g_cancellable_cancel (priv->cancellable); - g_clear_object (&priv->cancellable); - priv->cancellable = g_cancellable_new (); + g_cancellable_cancel (view->cancellable); + g_clear_object (&view->cancellable); + view->cancellable = g_cancellable_new (); - priv->unmounting_mount = TRUE; + view->unmounting_mount = TRUE; update_loading (view); g_object_ref (view); @@ -1461,7 +1424,7 @@ unmount_mount (NautilusGtkPlacesView *view, g_mount_unmount_with_operation (mount, 0, operation, - priv->cancellable, + view->cancellable, unmount_ready_cb, view); g_object_unref (operation); @@ -1471,32 +1434,30 @@ static void mount_server (NautilusGtkPlacesView *view, GFile *location) { - NautilusGtkPlacesViewPrivate *priv; GMountOperation *operation; GtkWidget *toplevel; - priv = nautilus_gtk_places_view_get_instance_private (view); - - g_cancellable_cancel (priv->cancellable); - g_clear_object (&priv->cancellable); + g_cancellable_cancel (view->cancellable); + g_clear_object (&view->cancellable); /* User cliked when the operation was ongoing, so wanted to cancel it */ - if (priv->connecting_to_server) + if (view->connecting_to_server) return; - priv->cancellable = g_cancellable_new (); - toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view)); + view->cancellable = g_cancellable_new (); + toplevel = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (view))); operation = gtk_mount_operation_new (GTK_WINDOW (toplevel)); - priv->should_pulse_entry = TRUE; - gtk_entry_set_progress_pulse_step (GTK_ENTRY (priv->address_entry), 0.1); + view->should_pulse_entry = TRUE; + gtk_entry_set_progress_pulse_step (GTK_ENTRY (view->address_entry), 0.1); + gtk_entry_set_progress_fraction (GTK_ENTRY (view->address_entry), 0.1); /* Allow to cancel the operation */ - gtk_button_set_label (GTK_BUTTON (priv->connect_button), _("Cance_l")); - gtk_widget_set_sensitive (priv->address_entry, FALSE); - priv->connecting_to_server = TRUE; + gtk_button_set_label (GTK_BUTTON (view->connect_button), _("Cance_l")); + gtk_widget_set_sensitive (view->address_entry, FALSE); + view->connecting_to_server = TRUE; update_loading (view); - if (priv->entry_pulse_timeout_id == 0) - priv->entry_pulse_timeout_id = g_timeout_add (100, (GSourceFunc) pulse_entry_cb, view); + if (view->entry_pulse_timeout_id == 0) + view->entry_pulse_timeout_id = g_timeout_add (100, (GSourceFunc) pulse_entry_cb, view); g_mount_operation_set_password_save (operation, G_PASSWORD_SAVE_FOR_SESSION); @@ -1506,7 +1467,7 @@ mount_server (NautilusGtkPlacesView *view, g_file_mount_enclosing_volume (location, 0, operation, - priv->cancellable, + view->cancellable, server_mount_ready_cb, view); @@ -1518,19 +1479,17 @@ static void mount_volume (NautilusGtkPlacesView *view, GVolume *volume) { - NautilusGtkPlacesViewPrivate *priv; GMountOperation *operation; GtkWidget *toplevel; - priv = nautilus_gtk_places_view_get_instance_private (view); - toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view)); + toplevel = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (view))); operation = gtk_mount_operation_new (GTK_WINDOW (toplevel)); - g_cancellable_cancel (priv->cancellable); - g_clear_object (&priv->cancellable); - priv->cancellable = g_cancellable_new (); + g_cancellable_cancel (view->cancellable); + g_clear_object (&view->cancellable); + view->cancellable = g_cancellable_new (); - priv->mounting_volume = TRUE; + view->mounting_volume = TRUE; update_loading (view); g_mount_operation_set_password_save (operation, G_PASSWORD_SAVE_FOR_SESSION); @@ -1541,7 +1500,7 @@ mount_volume (NautilusGtkPlacesView *view, g_volume_mount (volume, 0, operation, - priv->cancellable, + view->cancellable, volume_mount_ready_cb, view); @@ -1549,89 +1508,73 @@ mount_volume (NautilusGtkPlacesView *view, g_object_unref (operation); } -/* Callback used when the file list's popup menu is detached */ static void -popup_menu_detach_cb (GtkWidget *attach_widget, - GtkMenu *menu) +open_cb (GtkWidget *widget, + const char *action_name, + GVariant *parameter) { - NautilusGtkPlacesViewPrivate *priv; + NautilusGtkPlacesView *view = NAUTILUS_GTK_PLACES_VIEW (widget); + NautilusGtkPlacesOpenFlags flags = NAUTILUS_GTK_PLACES_OPEN_NORMAL; - priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (attach_widget)); - priv->popup_menu = NULL; -} - -static void -open_cb (GtkMenuItem *item, - NautilusGtkPlacesViewRow *row) -{ - NautilusGtkPlacesView *self; - - self = NAUTILUS_GTK_PLACES_VIEW (gtk_widget_get_ancestor (GTK_WIDGET (row), NAUTILUS_TYPE_GTK_PLACES_VIEW)); - activate_row (self, row, NAUTILUS_GTK_PLACES_OPEN_NORMAL); -} - -static void -open_in_new_tab_cb (GtkMenuItem *item, - NautilusGtkPlacesViewRow *row) -{ - NautilusGtkPlacesView *self; - - self = NAUTILUS_GTK_PLACES_VIEW (gtk_widget_get_ancestor (GTK_WIDGET (row), NAUTILUS_TYPE_GTK_PLACES_VIEW)); - activate_row (self, row, NAUTILUS_GTK_PLACES_OPEN_NEW_TAB); -} + if (view->row_for_action == NULL) + return; -static void -open_in_new_window_cb (GtkMenuItem *item, - NautilusGtkPlacesViewRow *row) -{ - NautilusGtkPlacesView *self; + if (strcmp (action_name, "location.open") == 0) + flags = NAUTILUS_GTK_PLACES_OPEN_NORMAL; + else if (strcmp (action_name, "location.open-tab") == 0) + flags = NAUTILUS_GTK_PLACES_OPEN_NEW_TAB; + else if (strcmp (action_name, "location.open-window") == 0) + flags = NAUTILUS_GTK_PLACES_OPEN_NEW_WINDOW; - self = NAUTILUS_GTK_PLACES_VIEW (gtk_widget_get_ancestor (GTK_WIDGET (row), NAUTILUS_TYPE_GTK_PLACES_VIEW)); - activate_row (self, row, NAUTILUS_GTK_PLACES_OPEN_NEW_WINDOW); + activate_row (view, view->row_for_action, flags); } static void -mount_cb (GtkMenuItem *item, - NautilusGtkPlacesViewRow *row) +mount_cb (GtkWidget *widget, + const char *action_name, + GVariant *parameter) { - NautilusGtkPlacesViewPrivate *priv; - GtkWidget *view; + NautilusGtkPlacesView *view = NAUTILUS_GTK_PLACES_VIEW (widget); GVolume *volume; - view = gtk_widget_get_ancestor (GTK_WIDGET (row), NAUTILUS_TYPE_GTK_PLACES_VIEW); - priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (view)); - volume = nautilus_gtk_places_view_row_get_volume (row); + if (view->row_for_action == NULL) + return; + + volume = nautilus_gtk_places_view_row_get_volume (view->row_for_action); /* * When the mount item is activated, it's expected that * the volume only gets mounted, without opening it after * the operation is complete. */ - priv->should_open_location = FALSE; + view->should_open_location = FALSE; - nautilus_gtk_places_view_row_set_busy (row, TRUE); - mount_volume (NAUTILUS_GTK_PLACES_VIEW (view), volume); + nautilus_gtk_places_view_row_set_busy (view->row_for_action, TRUE); + mount_volume (view, volume); } static void -unmount_cb (GtkMenuItem *item, - NautilusGtkPlacesViewRow *row) +unmount_cb (GtkWidget *widget, + const char *action_name, + GVariant *parameter) { - GtkWidget *view; + NautilusGtkPlacesView *view = NAUTILUS_GTK_PLACES_VIEW (widget); GMount *mount; - view = gtk_widget_get_ancestor (GTK_WIDGET (row), NAUTILUS_TYPE_GTK_PLACES_VIEW); - mount = nautilus_gtk_places_view_row_get_mount (row); + if (view->row_for_action == NULL) + return; - nautilus_gtk_places_view_row_set_busy (row, TRUE); + mount = nautilus_gtk_places_view_row_get_mount (view->row_for_action); - unmount_mount (NAUTILUS_GTK_PLACES_VIEW (view), mount); + nautilus_gtk_places_view_row_set_busy (view->row_for_action, TRUE); + + unmount_mount (view, mount); } static void attach_protocol_row_to_grid (GtkGrid *grid, - const gchar *protocol_name, - const gchar *protocol_prefix) + const char *protocol_name, + const char *protocol_prefix) { GtkWidget *name_label; GtkWidget *prefix_label; @@ -1648,213 +1591,239 @@ attach_protocol_row_to_grid (GtkGrid *grid, static void populate_available_protocols_grid (GtkGrid *grid) { - const gchar* const *supported_protocols; + const char * const *supported_protocols; + gboolean has_any = FALSE; supported_protocols = g_vfs_get_supported_uri_schemes (g_vfs_get_default ()); if (g_strv_contains (supported_protocols, "afp")) - attach_protocol_row_to_grid (grid, _("AppleTalk"), "afp://"); + { + attach_protocol_row_to_grid (grid, _("AppleTalk"), "afp://"); + has_any = TRUE; + } if (g_strv_contains (supported_protocols, "ftp")) - /* Translators: do not translate ftp:// and ftps:// */ - attach_protocol_row_to_grid (grid, _("File Transfer Protocol"), _("ftp:// or ftps://")); + { + attach_protocol_row_to_grid (grid, _("File Transfer Protocol"), + /* Translators: do not translate ftp:// and ftps:// */ + _("ftp:// or ftps://")); + has_any = TRUE; + } if (g_strv_contains (supported_protocols, "nfs")) - attach_protocol_row_to_grid (grid, _("Network File System"), "nfs://"); + { + attach_protocol_row_to_grid (grid, _("Network File System"), "nfs://"); + has_any = TRUE; + } if (g_strv_contains (supported_protocols, "smb")) - attach_protocol_row_to_grid (grid, _("Samba"), "smb://"); + { + attach_protocol_row_to_grid (grid, _("Samba"), "smb://"); + has_any = TRUE; + } if (g_strv_contains (supported_protocols, "ssh")) - /* Translators: do not translate sftp:// and ssh:// */ - attach_protocol_row_to_grid (grid, _("SSH File Transfer Protocol"), _("sftp:// or ssh://")); + { + attach_protocol_row_to_grid (grid, _("SSH File Transfer Protocol"), + /* Translators: do not translate sftp:// and ssh:// */ + _("sftp:// or ssh://")); + has_any = TRUE; + } if (g_strv_contains (supported_protocols, "dav")) - /* Translators: do not translate dav:// and davs:// */ - attach_protocol_row_to_grid (grid, _("WebDAV"), _("dav:// or davs://")); + { + attach_protocol_row_to_grid (grid, _("WebDAV"), + /* Translators: do not translate dav:// and davs:// */ + _("dav:// or davs://")); + has_any = TRUE; + } - gtk_widget_show_all (GTK_WIDGET (grid)); + if (!has_any) + gtk_widget_hide (GTK_WIDGET (grid)); } -/* Constructs the popup menu if needed */ -static void -build_popup_menu (NautilusGtkPlacesView *view, - NautilusGtkPlacesViewRow *row) +static GMenuModel * +get_menu_model (void) +{ + GMenu *menu; + GMenu *section; + GMenuItem *item; + + menu = g_menu_new (); + section = g_menu_new (); + item = g_menu_item_new (_("_Open"), "location.open"); + g_menu_append_item (section, item); + g_object_unref (item); + + item = g_menu_item_new (_("Open in New _Tab"), "location.open-tab"); + g_menu_item_set_attribute (item, "hidden-when", "s", "action-disabled"); + g_menu_append_item (section, item); + g_object_unref (item); + + item = g_menu_item_new (_("Open in New _Window"), "location.open-window"); + g_menu_item_set_attribute (item, "hidden-when", "s", "action-disabled"); + g_menu_append_item (section, item); + g_object_unref (item); + + g_menu_append_section (menu, NULL, G_MENU_MODEL (section)); + g_object_unref (section); + + section = g_menu_new (); + item = g_menu_item_new (_("_Disconnect"), "location.disconnect"); + g_menu_item_set_attribute (item, "hidden-when", "s", "action-disabled"); + g_menu_append_item (section, item); + g_object_unref (item); + + item = g_menu_item_new (_("_Unmount"), "location.unmount"); + g_menu_item_set_attribute (item, "hidden-when", "s", "action-disabled"); + g_menu_append_item (section, item); + g_object_unref (item); + + + item = g_menu_item_new (_("_Connect"), "location.connect"); + g_menu_item_set_attribute (item, "hidden-when", "s", "action-disabled"); + g_menu_append_item (section, item); + g_object_unref (item); + + item = g_menu_item_new (_("_Mount"), "location.mount"); + g_menu_item_set_attribute (item, "hidden-when", "s", "action-disabled"); + g_menu_append_item (section, item); + g_object_unref (item); + + g_menu_append_section (menu, NULL, G_MENU_MODEL (section)); + g_object_unref (section); + + return G_MENU_MODEL (menu); +} + +static gboolean +on_row_popup_menu (GtkWidget *widget, + GVariant *args, + gpointer user_data) { - NautilusGtkPlacesViewPrivate *priv; - GtkWidget *item; + NautilusGtkPlacesViewRow *row = NAUTILUS_GTK_PLACES_VIEW_ROW (widget); + NautilusGtkPlacesView *view; GMount *mount; GFile *file; gboolean is_network; - priv = nautilus_gtk_places_view_get_instance_private (view); + view = NAUTILUS_GTK_PLACES_VIEW (gtk_widget_get_ancestor (GTK_WIDGET (row), NAUTILUS_TYPE_GTK_PLACES_VIEW)); + mount = nautilus_gtk_places_view_row_get_mount (row); file = nautilus_gtk_places_view_row_get_file (row); is_network = nautilus_gtk_places_view_row_get_is_network (row); - priv->popup_menu = gtk_menu_new (); - gtk_style_context_add_class (gtk_widget_get_style_context (priv->popup_menu), - GTK_STYLE_CLASS_CONTEXT_MENU); - - gtk_menu_attach_to_widget (GTK_MENU (priv->popup_menu), - GTK_WIDGET (view), - popup_menu_detach_cb); + gtk_widget_action_set_enabled (GTK_WIDGET (view), "location.disconnect", + !file && mount && is_network); + gtk_widget_action_set_enabled (GTK_WIDGET (view), "location.unmount", + !file && mount && !is_network); + gtk_widget_action_set_enabled (GTK_WIDGET (view), "location.connect", + !file && !mount && is_network); + gtk_widget_action_set_enabled (GTK_WIDGET (view), "location.mount", + !file && !mount && !is_network); - /* Open item is always present */ - item = gtk_menu_item_new_with_mnemonic (_("_Open")); - g_signal_connect (item, - "activate", - G_CALLBACK (open_cb), - row); - gtk_widget_show (item); - gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item); - - if (priv->open_flags & NAUTILUS_GTK_PLACES_OPEN_NEW_TAB) + if (!view->popup_menu) { - item = gtk_menu_item_new_with_mnemonic (_("Open in New _Tab")); - g_signal_connect (item, - "activate", - G_CALLBACK (open_in_new_tab_cb), - row); - gtk_widget_show (item); - gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item); - } + GMenuModel *model = get_menu_model (); - if (priv->open_flags & NAUTILUS_GTK_PLACES_OPEN_NEW_WINDOW) - { - item = gtk_menu_item_new_with_mnemonic (_("Open in New _Window")); - g_signal_connect (item, - "activate", - G_CALLBACK (open_in_new_window_cb), - row); - gtk_widget_show (item); - gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item); - } + view->popup_menu = gtk_popover_menu_new_from_model (model); + gtk_popover_set_position (GTK_POPOVER (view->popup_menu), GTK_POS_BOTTOM); - /* - * The only item that contains a file up to now is the Computer - * item, which cannot be mounted or unmounted. - */ - if (file) - return; + gtk_popover_set_has_arrow (GTK_POPOVER (view->popup_menu), FALSE); + gtk_widget_set_halign (view->popup_menu, GTK_ALIGN_CENTER); - /* Separator */ - item = gtk_separator_menu_item_new (); - gtk_widget_show (item); - gtk_menu_shell_insert (GTK_MENU_SHELL (priv->popup_menu), item, -1); - - /* Mount/Unmount items */ - if (mount) - { - item = gtk_menu_item_new_with_mnemonic (is_network ? _("_Disconnect") : _("_Unmount")); - g_signal_connect (item, - "activate", - G_CALLBACK (unmount_cb), - row); - gtk_widget_show (item); - gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item); - } - else - { - item = gtk_menu_item_new_with_mnemonic (is_network ? _("_Connect") : _("_Mount")); - g_signal_connect (item, - "activate", - G_CALLBACK (mount_cb), - row); - gtk_widget_show (item); - gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item); + g_object_unref (model); } -} - -static void -popup_menu (NautilusGtkPlacesViewRow *row, - GdkEventButton *event) -{ - NautilusGtkPlacesViewPrivate *priv; - GtkWidget *view; - view = gtk_widget_get_ancestor (GTK_WIDGET (row), NAUTILUS_TYPE_GTK_PLACES_VIEW); - priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (view)); + if (view->row_for_action) + g_object_set_data (G_OBJECT (view->row_for_action), "menu", NULL); - g_clear_pointer (&priv->popup_menu, gtk_widget_destroy); + g_object_ref (view->popup_menu); + gtk_widget_unparent (view->popup_menu); + gtk_widget_set_parent (view->popup_menu, GTK_WIDGET (row)); + g_object_unref (view->popup_menu); - build_popup_menu (NAUTILUS_GTK_PLACES_VIEW (view), row); + view->row_for_action = row; + if (view->row_for_action) + g_object_set_data (G_OBJECT (view->row_for_action), "menu", view->popup_menu); - gtk_menu_popup_at_pointer (GTK_MENU (priv->popup_menu), (GdkEvent *) event); -} + gtk_popover_popup (GTK_POPOVER (view->popup_menu)); -static gboolean -on_row_popup_menu (NautilusGtkPlacesViewRow *row) -{ - popup_menu (row, NULL); return TRUE; } -static gboolean -on_button_press_event (NautilusGtkPlacesViewRow *row, - GdkEventButton *event) +static void +click_cb (GtkGesture *gesture, + int n_press, + double x, + double y, + gpointer user_data) { - if (row && - gdk_event_triggers_context_menu ((GdkEvent*) event) && - event->type == GDK_BUTTON_PRESS) - { - popup_menu (row, event); - - return TRUE; - } - - return FALSE; + on_row_popup_menu (GTK_WIDGET (user_data), NULL, NULL); } static gboolean -on_key_press_event (GtkWidget *widget, - GdkEventKey *event, - NautilusGtkPlacesView *view) +on_key_press_event (GtkEventController *controller, + guint keyval, + guint keycode, + GdkModifierType state, + NautilusGtkPlacesView *view) { - NautilusGtkPlacesViewPrivate *priv; + GdkModifierType modifiers; - priv = nautilus_gtk_places_view_get_instance_private (view); + modifiers = gtk_accelerator_get_default_mod_mask (); - if (event) + if (keyval == GDK_KEY_Return || + keyval == GDK_KEY_KP_Enter || + keyval == GDK_KEY_ISO_Enter || + keyval == GDK_KEY_space) { - guint modifiers; - - modifiers = gtk_accelerator_get_default_mod_mask (); - - if (event->keyval == GDK_KEY_Return || - event->keyval == GDK_KEY_KP_Enter || - event->keyval == GDK_KEY_ISO_Enter || - event->keyval == GDK_KEY_space) - { - GtkWidget *focus_widget; - GtkWindow *toplevel; + GtkWidget *focus_widget; + GtkWindow *toplevel; - priv->current_open_flags = NAUTILUS_GTK_PLACES_OPEN_NORMAL; - toplevel = get_toplevel (GTK_WIDGET (view)); + view->current_open_flags = NAUTILUS_GTK_PLACES_OPEN_NORMAL; + toplevel = get_toplevel (GTK_WIDGET (view)); - if (!toplevel) - return FALSE; + if (!toplevel) + return FALSE; - focus_widget = gtk_window_get_focus (toplevel); + focus_widget = gtk_root_get_focus (GTK_ROOT (toplevel)); - if (!NAUTILUS_IS_GTK_PLACES_VIEW_ROW (focus_widget)) - return FALSE; + if (!NAUTILUS_IS_GTK_PLACES_VIEW_ROW (focus_widget)) + return FALSE; - if ((event->state & modifiers) == GDK_SHIFT_MASK) - priv->current_open_flags = NAUTILUS_GTK_PLACES_OPEN_NEW_TAB; - else if ((event->state & modifiers) == GDK_CONTROL_MASK) - priv->current_open_flags = NAUTILUS_GTK_PLACES_OPEN_NEW_WINDOW; + if ((state & modifiers) == GDK_SHIFT_MASK) + view->current_open_flags = NAUTILUS_GTK_PLACES_OPEN_NEW_TAB; + else if ((state & modifiers) == GDK_CONTROL_MASK) + view->current_open_flags = NAUTILUS_GTK_PLACES_OPEN_NEW_WINDOW; - activate_row (view, NAUTILUS_GTK_PLACES_VIEW_ROW (focus_widget), priv->current_open_flags); + activate_row (view, NAUTILUS_GTK_PLACES_VIEW_ROW (focus_widget), view->current_open_flags); - return TRUE; - } + return TRUE; } return FALSE; } static void +on_middle_click_row_event (GtkGestureClick *gesture, + guint n_press, + double x, + double y, + NautilusGtkPlacesView *view) +{ + GtkListBoxRow *row; + + if (n_press != 1) + return; + + row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (view->listbox), y); + if (row != NULL && gtk_widget_is_sensitive (GTK_WIDGET (row))) + activate_row (view, NAUTILUS_GTK_PLACES_VIEW_ROW (row), NAUTILUS_GTK_PLACES_OPEN_NEW_TAB); +} + + +static void on_eject_button_clicked (GtkWidget *widget, NautilusGtkPlacesViewRow *row) { @@ -1869,11 +1838,9 @@ on_eject_button_clicked (GtkWidget *widget, static void on_connect_button_clicked (NautilusGtkPlacesView *view) { - NautilusGtkPlacesViewPrivate *priv; - const gchar *uri; + const char *uri; GFile *file; - priv = nautilus_gtk_places_view_get_instance_private (view); file = NULL; /* @@ -1881,17 +1848,17 @@ on_connect_button_clicked (NautilusGtkPlacesView *view) * address changes, it is sufficient to check if it's sensitive * or not, in order to determine if the given address is valid. */ - if (!gtk_widget_get_sensitive (priv->connect_button)) + if (!gtk_widget_get_sensitive (view->connect_button)) return; - uri = gtk_entry_get_text (GTK_ENTRY (priv->address_entry)); + uri = gtk_editable_get_text (GTK_EDITABLE (view->address_entry)); if (uri != NULL && uri[0] != '\0') file = g_file_new_for_commandline_arg (uri); if (file) { - priv->should_open_location = TRUE; + view->should_open_location = TRUE; mount_server (view, file); } @@ -1904,15 +1871,13 @@ on_connect_button_clicked (NautilusGtkPlacesView *view) static void on_address_entry_text_changed (NautilusGtkPlacesView *view) { - NautilusGtkPlacesViewPrivate *priv; - const gchar* const *supported_protocols; - gchar *address, *scheme; + const char * const *supported_protocols; + char *address, *scheme; gboolean supported; - priv = nautilus_gtk_places_view_get_instance_private (view); supported = FALSE; supported_protocols = g_vfs_get_supported_uri_schemes (g_vfs_get_default ()); - address = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->address_entry))); + address = g_strdup (gtk_editable_get_text (GTK_EDITABLE (view->address_entry))); scheme = g_uri_parse_scheme (address); if (!supported_protocols) @@ -1925,13 +1890,11 @@ on_address_entry_text_changed (NautilusGtkPlacesView *view) !g_strv_contains (unsupported_protocols, scheme); out: - gtk_widget_set_sensitive (priv->connect_button, supported); + gtk_widget_set_sensitive (view->connect_button, supported); if (scheme && !supported) - gtk_style_context_add_class (gtk_widget_get_style_context (priv->address_entry), - GTK_STYLE_CLASS_ERROR); + gtk_widget_add_css_class (view->address_entry, "error"); else - gtk_style_context_remove_class (gtk_widget_get_style_context (priv->address_entry), - GTK_STYLE_CLASS_ERROR); + gtk_widget_remove_css_class (view->address_entry, "error"); g_free (address); g_free (scheme); @@ -1940,21 +1903,22 @@ out: static void on_address_entry_show_help_pressed (NautilusGtkPlacesView *view, GtkEntryIconPosition icon_pos, - GdkEvent *event, GtkEntry *entry) { - NautilusGtkPlacesViewPrivate *priv; GdkRectangle rect; - - priv = nautilus_gtk_places_view_get_instance_private (view); + double x, y; /* Setup the auxiliary popover's rectangle */ - gtk_entry_get_icon_area (GTK_ENTRY (priv->address_entry), + gtk_entry_get_icon_area (GTK_ENTRY (view->address_entry), GTK_ENTRY_ICON_SECONDARY, &rect); + gtk_widget_translate_coordinates (view->address_entry, GTK_WIDGET (view), + rect.x, rect.y, &x, &y); - gtk_popover_set_pointing_to (GTK_POPOVER (priv->server_adresses_popover), &rect); - gtk_widget_set_visible (priv->server_adresses_popover, TRUE); + rect.x = x; + rect.y = y; + gtk_popover_set_pointing_to (GTK_POPOVER (view->server_adresses_popover), &rect); + gtk_widget_set_visible (view->server_adresses_popover, TRUE); } static void @@ -1962,15 +1926,13 @@ on_recent_servers_listbox_row_activated (NautilusGtkPlacesView *view, NautilusGtkPlacesViewRow *row, GtkWidget *listbox) { - NautilusGtkPlacesViewPrivate *priv; - gchar *uri; + char *uri; - priv = nautilus_gtk_places_view_get_instance_private (view); uri = g_object_get_data (G_OBJECT (row), "uri"); - gtk_entry_set_text (GTK_ENTRY (priv->address_entry), uri); + gtk_editable_set_text (GTK_EDITABLE (view->address_entry), uri); - gtk_widget_hide (priv->recent_servers_popover); + gtk_widget_hide (view->recent_servers_popover); } static void @@ -1978,84 +1940,25 @@ on_listbox_row_activated (NautilusGtkPlacesView *view, NautilusGtkPlacesViewRow *row, GtkWidget *listbox) { - NautilusGtkPlacesViewPrivate *priv; - GdkEvent *event; - guint button; - NautilusGtkPlacesOpenFlags open_flags; - - priv = nautilus_gtk_places_view_get_instance_private (view); - - event = gtk_get_current_event (); - gdk_event_get_button (event, &button); - - if (gdk_event_get_event_type (event) == GDK_BUTTON_RELEASE && button == GDK_BUTTON_MIDDLE) - open_flags = NAUTILUS_GTK_PLACES_OPEN_NEW_TAB; - else - open_flags = priv->current_open_flags; - - activate_row (view, row, open_flags); -} - -static gboolean -is_mount_locally_accessible (GMount *mount) -{ - GFile *base_file; - gchar *path; - - if (mount == NULL) - return FALSE; - - base_file = g_mount_get_root (mount); - - if (base_file == NULL) - return FALSE; - - path = g_file_get_path (base_file); - g_object_unref (base_file); - - if (path == NULL) - return FALSE; - - g_free (path); - return TRUE; + activate_row (view, row, view->current_open_flags); } static gboolean listbox_filter_func (GtkListBoxRow *row, gpointer user_data) { - NautilusGtkPlacesViewPrivate *priv; - gboolean is_network; + NautilusGtkPlacesView *view = NAUTILUS_GTK_PLACES_VIEW (user_data); gboolean is_placeholder; - gboolean is_local = FALSE; gboolean retval; gboolean searching; - gchar *name; - gchar *path; + char *name; + char *path; - priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (user_data)); retval = FALSE; - searching = priv->search_query && priv->search_query[0] != '\0'; + searching = view->search_query && view->search_query[0] != '\0'; - is_network = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row), "is-network")); is_placeholder = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row), "is-placeholder")); - if (NAUTILUS_IS_GTK_PLACES_VIEW_ROW (row)) - { - NautilusGtkPlacesViewRow *placesviewrow; - GMount *mount; - - placesviewrow = NAUTILUS_GTK_PLACES_VIEW_ROW (row); - g_object_get(G_OBJECT (placesviewrow), "mount", &mount, NULL); - - is_local = is_mount_locally_accessible (mount); - - g_clear_object (&mount); - } - - if (is_network && priv->local_only && !is_local) - return FALSE; - if (is_placeholder && searching) return FALSE; @@ -2068,10 +1971,22 @@ listbox_filter_func (GtkListBoxRow *row, NULL); if (name) - retval |= strstr (name, priv->search_query) != NULL; + { + char *lowercase_name = g_utf8_strdown (name, -1); + + retval |= strstr (lowercase_name, view->search_query) != NULL; + + g_free (lowercase_name); + } if (path) - retval |= strstr (path, priv->search_query) != NULL; + { + char *lowercase_path = g_utf8_strdown (path, -1); + + retval |= strstr (lowercase_path, view->search_query) != NULL; + + g_free (lowercase_path); + } g_free (name); g_free (path); @@ -2085,7 +2000,7 @@ listbox_header_func (GtkListBoxRow *row, gpointer user_data) { gboolean row_is_network; - gchar *text; + char *text; text = NULL; row_is_network = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row), "is-network")); @@ -2126,36 +2041,29 @@ listbox_header_func (GtkListBoxRow *row, GtkWidget *header_name; GtkWidget *network_header_spinner; - g_object_set (label, - "margin-end", 6, - NULL); + gtk_widget_set_margin_end (label, 6); header_name = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); network_header_spinner = gtk_spinner_new (); - g_object_set (network_header_spinner, - "margin-end", 12, - NULL); + gtk_widget_set_margin_end (network_header_spinner, 12); g_object_bind_property (NAUTILUS_GTK_PLACES_VIEW (user_data), "fetching-networks", network_header_spinner, - "active", + "spinning", G_BINDING_SYNC_CREATE); - gtk_container_add (GTK_CONTAINER (header_name), label); - gtk_container_add (GTK_CONTAINER (header_name), network_header_spinner); - gtk_container_add (GTK_CONTAINER (header), header_name); + gtk_box_append (GTK_BOX (header_name), label); + gtk_box_append (GTK_BOX (header_name), network_header_spinner); + gtk_box_append (GTK_BOX (header), header_name); } else { - g_object_set (label, - "hexpand", TRUE, - "margin-end", 12, - NULL); - gtk_container_add (GTK_CONTAINER (header), label); + gtk_widget_set_hexpand (label, TRUE); + gtk_widget_set_margin_end (label, 12); + gtk_box_append (GTK_BOX (header), label); } - gtk_container_add (GTK_CONTAINER (header), separator); - gtk_widget_show_all (header); + gtk_box_append (GTK_BOX (header), separator); gtk_list_box_row_set_header (row, header); @@ -2167,18 +2075,18 @@ listbox_header_func (GtkListBoxRow *row, } } -static gint +static int listbox_sort_func (GtkListBoxRow *row1, GtkListBoxRow *row2, gpointer user_data) { gboolean row1_is_network; gboolean row2_is_network; - gchar *path1; - gchar *path2; + char *path1; + char *path2; gboolean *is_placeholder1; gboolean *is_placeholder2; - gint retval; + int retval; row1_is_network = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row1), "is-network")); row2_is_network = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row2), "is-network")); @@ -2213,49 +2121,47 @@ listbox_sort_func (GtkListBoxRow *row1, static void nautilus_gtk_places_view_constructed (GObject *object) { - NautilusGtkPlacesViewPrivate *priv; - - priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (object)); + NautilusGtkPlacesView *view = NAUTILUS_GTK_PLACES_VIEW (object); G_OBJECT_CLASS (nautilus_gtk_places_view_parent_class)->constructed (object); - gtk_list_box_set_sort_func (GTK_LIST_BOX (priv->listbox), + gtk_list_box_set_sort_func (GTK_LIST_BOX (view->listbox), listbox_sort_func, object, NULL); - gtk_list_box_set_filter_func (GTK_LIST_BOX (priv->listbox), + gtk_list_box_set_filter_func (GTK_LIST_BOX (view->listbox), listbox_filter_func, object, NULL); - gtk_list_box_set_header_func (GTK_LIST_BOX (priv->listbox), + gtk_list_box_set_header_func (GTK_LIST_BOX (view->listbox), listbox_header_func, object, NULL); /* load drives */ - update_places (NAUTILUS_GTK_PLACES_VIEW (object)); + update_places (view); - g_signal_connect_swapped (priv->volume_monitor, + g_signal_connect_swapped (view->volume_monitor, "mount-added", G_CALLBACK (update_places), object); - g_signal_connect_swapped (priv->volume_monitor, + g_signal_connect_swapped (view->volume_monitor, "mount-changed", G_CALLBACK (update_places), object); - g_signal_connect_swapped (priv->volume_monitor, + g_signal_connect_swapped (view->volume_monitor, "mount-removed", G_CALLBACK (update_places), object); - g_signal_connect_swapped (priv->volume_monitor, + g_signal_connect_swapped (view->volume_monitor, "volume-added", G_CALLBACK (update_places), object); - g_signal_connect_swapped (priv->volume_monitor, + g_signal_connect_swapped (view->volume_monitor, "volume-changed", G_CALLBACK (update_places), object); - g_signal_connect_swapped (priv->volume_monitor, + g_signal_connect_swapped (view->volume_monitor, "volume-removed", G_CALLBACK (update_places), object); @@ -2264,11 +2170,9 @@ nautilus_gtk_places_view_constructed (GObject *object) static void nautilus_gtk_places_view_map (GtkWidget *widget) { - NautilusGtkPlacesViewPrivate *priv; - - priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (widget)); + NautilusGtkPlacesView *view = NAUTILUS_GTK_PLACES_VIEW (widget); - gtk_entry_set_text (GTK_ENTRY (priv->address_entry), ""); + gtk_editable_set_text (GTK_EDITABLE (view->address_entry), ""); GTK_WIDGET_CLASS (nautilus_gtk_places_view_parent_class)->map (widget); } @@ -2280,26 +2184,24 @@ nautilus_gtk_places_view_class_init (NautilusGtkPlacesViewClass *klass) GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); object_class->finalize = nautilus_gtk_places_view_finalize; + object_class->dispose = nautilus_gtk_places_view_dispose; object_class->constructed = nautilus_gtk_places_view_constructed; object_class->get_property = nautilus_gtk_places_view_get_property; object_class->set_property = nautilus_gtk_places_view_set_property; - widget_class->destroy = nautilus_gtk_places_view_destroy; widget_class->map = nautilus_gtk_places_view_map; - /** + /* * NautilusGtkPlacesView::open-location: * @view: the object which received the signal. - * @location: (type Gio.File): #GFile to which the caller should switch. - * @open_flags: a single value from #NautilusGtkPlacesOpenFlags specifying how the @location + * @location: (type Gio.File): GFile to which the caller should switch. + * @open_flags: a single value from NautilusGtkPlacesOpenFlags specifying how the @location * should be opened. * * The places view emits this signal when the user selects a location * in it. The calling application should display the contents of that * location; for example, a file manager should show a list of files in * the specified location. - * - * Since: 3.18 */ places_view_signals [OPEN_LOCATION] = g_signal_new ("open-location", @@ -2310,9 +2212,9 @@ nautilus_gtk_places_view_class_init (NautilusGtkPlacesViewClass *klass) NULL, G_TYPE_NONE, 2, G_TYPE_OBJECT, - GTK_TYPE_PLACES_OPEN_FLAGS); + NAUTILUS_TYPE_OPEN_FLAGS); - /** + /* * NautilusGtkPlacesView::show-error-message: * @view: the object which received the signal. * @primary: primary message with a summary of the error to show. @@ -2322,8 +2224,6 @@ nautilus_gtk_places_view_class_init (NautilusGtkPlacesViewClass *klass) * application to present an error message. Most of these messages * refer to mounting or unmounting media, for example, when a drive * cannot be started for some reason. - * - * Since: 3.18 */ places_view_signals [SHOW_ERROR_MESSAGE] = g_signal_new ("show-error-message", @@ -2336,92 +2236,147 @@ nautilus_gtk_places_view_class_init (NautilusGtkPlacesViewClass *klass) G_TYPE_STRING, G_TYPE_STRING); - properties[PROP_LOCAL_ONLY] = - g_param_spec_boolean ("local-only", - "Local Only", - "Whether the sidebar only includes local files", - FALSE, - G_PARAM_READWRITE); - properties[PROP_LOADING] = g_param_spec_boolean ("loading", "Loading", "Whether the view is loading locations", FALSE, - G_PARAM_READABLE); + G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB); properties[PROP_FETCHING_NETWORKS] = g_param_spec_boolean ("fetching-networks", "Fetching networks", "Whether the view is fetching networks", FALSE, - G_PARAM_READABLE); + G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB); properties[PROP_OPEN_FLAGS] = g_param_spec_flags ("open-flags", "Open Flags", "Modes in which the calling application can open locations selected in the sidebar", - GTK_TYPE_PLACES_OPEN_FLAGS, + NAUTILUS_TYPE_OPEN_FLAGS, NAUTILUS_GTK_PLACES_OPEN_NORMAL, - G_PARAM_READWRITE); + G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB); g_object_class_install_properties (object_class, LAST_PROP, properties); /* Bind class to template */ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/nautilus/gtk/ui/nautilusgtkplacesview.ui"); - gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, actionbar); - gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, address_entry); - gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, address_entry_completion); - gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, completion_store); - gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, connect_button); - gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, listbox); - gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, recent_servers_listbox); - gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, recent_servers_popover); - gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, recent_servers_stack); - gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, stack); - gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, server_adresses_popover); - gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, available_protocols_grid); + gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesView, actionbar); + gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesView, address_entry); + gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesView, address_entry_completion); + gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesView, completion_store); + gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesView, connect_button); + gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesView, listbox); + gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesView, recent_servers_listbox); + gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesView, recent_servers_popover); + gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesView, recent_servers_stack); + gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesView, stack); + gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesView, server_adresses_popover); + gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesView, available_protocols_grid); gtk_widget_class_bind_template_callback (widget_class, on_address_entry_text_changed); gtk_widget_class_bind_template_callback (widget_class, on_address_entry_show_help_pressed); gtk_widget_class_bind_template_callback (widget_class, on_connect_button_clicked); - gtk_widget_class_bind_template_callback (widget_class, on_key_press_event); gtk_widget_class_bind_template_callback (widget_class, on_listbox_row_activated); gtk_widget_class_bind_template_callback (widget_class, on_recent_servers_listbox_row_activated); + /** + * NautilusGtkPlacesView|location.open: + * + * Opens the location in the current window. + */ + gtk_widget_class_install_action (widget_class, "location.open", NULL, open_cb); + + /** + * NautilusGtkPlacesView|location.open-tab: + * + * Opens the location in a new tab. + */ + gtk_widget_class_install_action (widget_class, "location.open-tab", NULL, open_cb); + + /** + * NautilusGtkPlacesView|location.open-window: + * + * Opens the location in a new window. + */ + gtk_widget_class_install_action (widget_class, "location.open-window", NULL, open_cb); + + /** + * NautilusGtkPlacesView|location.mount: + * + * Mount the location. + */ + gtk_widget_class_install_action (widget_class, "location.mount", NULL, mount_cb); + + /** + * NautilusGtkPlacesView|location.connect: + * + * Connect the location. + */ + gtk_widget_class_install_action (widget_class, "location.connect", NULL, mount_cb); + + /** + * NautilusGtkPlacesView|location.unmount: + * + * Unmount the location. + */ + gtk_widget_class_install_action (widget_class, "location.unmount", NULL, unmount_cb); + + /** + * NautilusGtkPlacesView|location.disconnect: + * + * Disconnect the location. + */ + gtk_widget_class_install_action (widget_class, "location.disconnect", NULL, unmount_cb); + gtk_widget_class_set_css_name (widget_class, "placesview"); } static void nautilus_gtk_places_view_init (NautilusGtkPlacesView *self) { - NautilusGtkPlacesViewPrivate *priv; + GtkEventController *controller; - priv = nautilus_gtk_places_view_get_instance_private (self); + self->volume_monitor = g_volume_monitor_get (); + self->open_flags = NAUTILUS_GTK_PLACES_OPEN_NORMAL; + self->path_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); + self->space_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); - priv->volume_monitor = g_volume_monitor_get (); - priv->open_flags = NAUTILUS_GTK_PLACES_OPEN_NORMAL; - priv->path_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); - priv->space_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); + gtk_widget_action_set_enabled (GTK_WIDGET (self), "location.open-tab", FALSE); + gtk_widget_action_set_enabled (GTK_WIDGET (self), "location.open-window", FALSE); gtk_widget_init_template (GTK_WIDGET (self)); - populate_available_protocols_grid (GTK_GRID (priv->available_protocols_grid)); + gtk_widget_set_parent (self->server_adresses_popover, GTK_WIDGET (self)); + controller = gtk_event_controller_key_new (); + g_signal_connect (controller, "key-pressed", G_CALLBACK (on_key_press_event), self); + gtk_widget_add_controller (GTK_WIDGET (self), controller); + + /* We need an additional controller because GtkListBox only + * activates rows for GDK_BUTTON_PRIMARY clicks + */ + controller = (GtkEventController *) gtk_gesture_click_new (); + gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_BUBBLE); + gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (controller), GDK_BUTTON_MIDDLE); + g_signal_connect (controller, "released", + G_CALLBACK (on_middle_click_row_event), self); + gtk_widget_add_controller (self->listbox, controller); + + populate_available_protocols_grid (GTK_GRID (self->available_protocols_grid)); } -/** +/* * nautilus_gtk_places_view_new: * - * Creates a new #NautilusGtkPlacesView widget. + * Creates a new NautilusGtkPlacesView widget. * * The application should connect to at least the - * #NautilusGtkPlacesView::open-location signal to be notified + * NautilusGtkPlacesView::open-location signal to be notified * when the user makes a selection in the view. * - * Returns: a newly created #NautilusGtkPlacesView - * - * Since: 3.18 + * Returns: a newly created NautilusGtkPlacesView */ GtkWidget * nautilus_gtk_places_view_new (void) @@ -2429,9 +2384,9 @@ nautilus_gtk_places_view_new (void) return g_object_new (NAUTILUS_TYPE_GTK_PLACES_VIEW, NULL); } -/** +/* * nautilus_gtk_places_view_set_open_flags: - * @view: a #NautilusGtkPlacesView + * @view: a NautilusGtkPlacesView * @flags: Bitmask of modes in which the calling application can open locations * * Sets the way in which the calling application can open new locations from @@ -2443,77 +2398,67 @@ nautilus_gtk_places_view_new (void) * application can open new locations, so that the view can display (or not) * the “Open in new tab” and “Open in new window” menu items as appropriate. * - * When the #NautilusGtkPlacesView::open-location signal is emitted, its flags + * When the NautilusGtkPlacesView::open-location signal is emitted, its flags * argument will be set to one of the @flags that was passed in * nautilus_gtk_places_view_set_open_flags(). * - * Passing 0 for @flags will cause #NAUTILUS_GTK_PLACES_OPEN_NORMAL to always be sent + * Passing 0 for @flags will cause NAUTILUS_GTK_PLACES_OPEN_NORMAL to always be sent * to callbacks for the “open-location” signal. - * - * Since: 3.18 */ void nautilus_gtk_places_view_set_open_flags (NautilusGtkPlacesView *view, NautilusGtkPlacesOpenFlags flags) { - NautilusGtkPlacesViewPrivate *priv; - g_return_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view)); - priv = nautilus_gtk_places_view_get_instance_private (view); + if (view->open_flags == flags) + return; - if (priv->open_flags != flags) - { - priv->open_flags = flags; - g_object_notify_by_pspec (G_OBJECT (view), properties[PROP_OPEN_FLAGS]); - } + view->open_flags = flags; + + gtk_widget_action_set_enabled (GTK_WIDGET (view), "location.open-tab", + (flags & NAUTILUS_GTK_PLACES_OPEN_NEW_TAB) != 0); + gtk_widget_action_set_enabled (GTK_WIDGET (view), "location.open-window", + (flags & NAUTILUS_GTK_PLACES_OPEN_NEW_WINDOW) != 0); + + g_object_notify_by_pspec (G_OBJECT (view), properties[PROP_OPEN_FLAGS]); } -/** +/* * nautilus_gtk_places_view_get_open_flags: - * @view: a #NautilusGtkPlacesSidebar + * @view: a NautilusGtkPlacesSidebar * * Gets the open flags. * - * Returns: the #NautilusGtkPlacesOpenFlags of @view - * - * Since: 3.18 + * Returns: the NautilusGtkPlacesOpenFlags of @view */ NautilusGtkPlacesOpenFlags nautilus_gtk_places_view_get_open_flags (NautilusGtkPlacesView *view) { - NautilusGtkPlacesViewPrivate *priv; - g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view), 0); - priv = nautilus_gtk_places_view_get_instance_private (view); - - return priv->open_flags; + return view->open_flags; } -/** +/* * nautilus_gtk_places_view_get_search_query: - * @view: a #NautilusGtkPlacesView + * @view: a NautilusGtkPlacesView * * Retrieves the current search query from @view. * * Returns: (transfer none): the current search query. */ -const gchar* +const char * nautilus_gtk_places_view_get_search_query (NautilusGtkPlacesView *view) { - NautilusGtkPlacesViewPrivate *priv; - g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view), NULL); - priv = nautilus_gtk_places_view_get_instance_private (view); - - return priv->search_query; + return view->search_query; } -/** +/* * nautilus_gtk_places_view_set_search_query: - * @view: a #NautilusGtkPlacesView + * @view: a NautilusGtkPlacesView * @query_text: the query, or NULL. * * Sets the search query of @view. The search is immediately performed @@ -2521,57 +2466,45 @@ nautilus_gtk_places_view_get_search_query (NautilusGtkPlacesView *view) */ void nautilus_gtk_places_view_set_search_query (NautilusGtkPlacesView *view, - const gchar *query_text) + const char *query_text) { - NautilusGtkPlacesViewPrivate *priv; - g_return_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view)); - priv = nautilus_gtk_places_view_get_instance_private (view); - - if (g_strcmp0 (priv->search_query, query_text) != 0) + if (g_strcmp0 (view->search_query, query_text) != 0) { - g_clear_pointer (&priv->search_query, g_free); - priv->search_query = g_strdup (query_text); + g_clear_pointer (&view->search_query, g_free); + view->search_query = g_utf8_strdown (query_text, -1); - gtk_list_box_invalidate_filter (GTK_LIST_BOX (priv->listbox)); - gtk_list_box_invalidate_headers (GTK_LIST_BOX (priv->listbox)); + gtk_list_box_invalidate_filter (GTK_LIST_BOX (view->listbox)); + gtk_list_box_invalidate_headers (GTK_LIST_BOX (view->listbox)); update_view_mode (view); } } -/** +/* * nautilus_gtk_places_view_get_loading: - * @view: a #NautilusGtkPlacesView + * @view: a NautilusGtkPlacesView * * Returns %TRUE if the view is loading locations. - * - * Since: 3.18 */ gboolean nautilus_gtk_places_view_get_loading (NautilusGtkPlacesView *view) { - NautilusGtkPlacesViewPrivate *priv; - g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view), FALSE); - priv = nautilus_gtk_places_view_get_instance_private (view); - - return priv->loading; + return view->loading; } static void update_loading (NautilusGtkPlacesView *view) { - NautilusGtkPlacesViewPrivate *priv; gboolean loading; g_return_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view)); - priv = nautilus_gtk_places_view_get_instance_private (view); - loading = priv->fetching_networks || priv->connecting_to_server || - priv->mounting_volume || priv->unmounting_mount; + loading = view->fetching_networks || view->connecting_to_server || + view->mounting_volume || view->unmounting_mount; set_busy_cursor (view, loading); nautilus_gtk_places_view_set_loading (view, loading); @@ -2581,15 +2514,11 @@ static void nautilus_gtk_places_view_set_loading (NautilusGtkPlacesView *view, gboolean loading) { - NautilusGtkPlacesViewPrivate *priv; - g_return_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view)); - priv = nautilus_gtk_places_view_get_instance_private (view); - - if (priv->loading != loading) + if (view->loading != loading) { - priv->loading = loading; + view->loading = loading; g_object_notify_by_pspec (G_OBJECT (view), properties [PROP_LOADING]); } } @@ -2597,83 +2526,20 @@ nautilus_gtk_places_view_set_loading (NautilusGtkPlacesView *view, static gboolean nautilus_gtk_places_view_get_fetching_networks (NautilusGtkPlacesView *view) { - NautilusGtkPlacesViewPrivate *priv; - g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view), FALSE); - priv = nautilus_gtk_places_view_get_instance_private (view); - - return priv->fetching_networks; + return view->fetching_networks; } static void nautilus_gtk_places_view_set_fetching_networks (NautilusGtkPlacesView *view, gboolean fetching_networks) { - NautilusGtkPlacesViewPrivate *priv; - g_return_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view)); - priv = nautilus_gtk_places_view_get_instance_private (view); - - if (priv->fetching_networks != fetching_networks) + if (view->fetching_networks != fetching_networks) { - priv->fetching_networks = fetching_networks; + view->fetching_networks = fetching_networks; g_object_notify_by_pspec (G_OBJECT (view), properties [PROP_FETCHING_NETWORKS]); } } - -/** - * nautilus_gtk_places_view_get_local_only: - * @view: a #NautilusGtkPlacesView - * - * Returns %TRUE if only local volumes are shown, i.e. no networks - * are displayed. - * - * Returns: %TRUE if only local volumes are shown, %FALSE otherwise. - * - * Since: 3.18 - */ -gboolean -nautilus_gtk_places_view_get_local_only (NautilusGtkPlacesView *view) -{ - NautilusGtkPlacesViewPrivate *priv; - - g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view), FALSE); - - priv = nautilus_gtk_places_view_get_instance_private (view); - - return priv->local_only; -} - -/** - * nautilus_gtk_places_view_set_local_only: - * @view: a #NautilusGtkPlacesView - * @local_only: %TRUE to hide remote locations, %FALSE to show. - * - * Sets the #NautilusGtkPlacesView::local-only property to @local_only. - * - * Since: 3.18 - */ -void -nautilus_gtk_places_view_set_local_only (NautilusGtkPlacesView *view, - gboolean local_only) -{ - NautilusGtkPlacesViewPrivate *priv; - - g_return_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view)); - - priv = nautilus_gtk_places_view_get_instance_private (view); - - if (priv->local_only != local_only) - { - priv->local_only = local_only; - - gtk_widget_set_visible (priv->actionbar, !local_only); - update_places (view); - - update_view_mode (view); - - g_object_notify_by_pspec (G_OBJECT (view), properties [PROP_LOCAL_ONLY]); - } -} diff --git a/src/gtk/nautilusgtkplacesview.ui b/src/gtk/nautilusgtkplacesview.ui index c5e785854..a7d5bdf21 100644 --- a/src/gtk/nautilusgtkplacesview.ui +++ b/src/gtk/nautilusgtkplacesview.ui @@ -1,11 +1,8 @@ <?xml version="1.0" encoding="UTF-8"?> -<interface domain="gtk30"> - <requires lib="gtk+" version="3.16"/> +<interface domain="gtk40"> <object class="GtkListStore" id="completion_store"> <columns> - <!-- column-name name --> <column type="gchararray"/> - <!-- column-name uri --> <column type="gchararray"/> </columns> </object> @@ -16,20 +13,21 @@ <property name="popup-completion">0</property> </object> <object class="GtkPopover" id="server_adresses_popover"> - <property name="relative-to">address_entry</property> + <property name="position">2</property> <child> <object class="GtkBox"> - <property name="visible">1</property> - <property name="border-width">18</property> - <property name="orientation">vertical</property> + <property name="orientation">1</property> <property name="spacing">6</property> + <property name="margin-start">18</property> + <property name="margin-end">18</property> + <property name="margin-top">18</property> + <property name="margin-bottom">18</property> <child> <object class="GtkLabel"> - <property name="visible">1</property> <property name="hexpand">1</property> - <property name="label" translatable="yes">Server Addresses</property> + <property name="label" translatable="1">Server Addresses</property> <attributes> - <attribute name="weight" value="bold"/> + <attribute name="weight" value="bold"></attribute> </attributes> <style> <class name="dim-label"/> @@ -38,21 +36,16 @@ </child> <child> <object class="GtkLabel"> - <property name="visible">1</property> <property name="hexpand">1</property> - <property name="label" translatable="yes">Server addresses are made up of a protocol prefix and an address. Examples:</property> + <property name="label" translatable="1">Server addresses are made up of a protocol prefix and an address. Examples:</property> <property name="wrap">1</property> <property name="width-chars">40</property> <property name="max-width-chars">40</property> <property name="xalign">0</property> </object> - <packing> - <property name="position">1</property> - </packing> </child> <child> <object class="GtkLabel"> - <property name="visible">1</property> <property name="hexpand">1</property> <property name="label">smb://gnome.org, ssh://192.168.0.1, ftp://[2001:db8::1]</property> <property name="wrap">1</property> @@ -60,50 +53,41 @@ <property name="max-width-chars">40</property> <property name="xalign">0</property> </object> - <packing> - <property name="position">2</property> - </packing> </child> <child> <object class="GtkGrid" id="available_protocols_grid"> - <property name="visible">1</property> <property name="margin-top">12</property> <property name="hexpand">1</property> <property name="row-spacing">6</property> <property name="column-spacing">12</property> <child> <object class="GtkLabel"> - <property name="visible">1</property> <property name="hexpand">1</property> - <property name="label" translatable="yes">Available Protocols</property> + <property name="label" translatable="1">Available Protocols</property> <property name="xalign">0</property> <attributes> - <attribute name="weight" value="bold"/> + <attribute name="weight" value="bold"></attribute> </attributes> + <layout> + <property name="column">0</property> + <property name="row">0</property> + </layout> </object> - <packing> - <property name="left-attach">0</property> - <property name="top-attach">0</property> - </packing> </child> <child> <object class="GtkLabel"> - <property name="visible">1</property> - <property name="label" translatable="yes">Prefix</property> + <property name="label" translatable="1">Prefix</property> <property name="xalign">0</property> <attributes> - <attribute name="weight" value="bold"/> + <attribute name="weight" value="bold"></attribute> </attributes> + <layout> + <property name="column">1</property> + <property name="row">0</property> + </layout> </object> - <packing> - <property name="left-attach">1</property> - <property name="top-attach">0</property> - </packing> </child> </object> - <packing> - <property name="position">3</property> - </packing> </child> </object> </child> @@ -111,233 +95,186 @@ <object class="GtkPopover" id="recent_servers_popover"> <child> <object class="GtkStack" id="recent_servers_stack"> - <property name="visible">1</property> <child> - <object class="GtkBox"> - <property name="visible">1</property> - <property name="vexpand">1</property> - <property name="valign">center</property> - <property name="orientation">vertical</property> - <property name="spacing">18</property> - <child> - <object class="GtkImage"> - <property name="visible">1</property> - <property name="pixel-size">48</property> - <property name="icon-name">network-server-symbolic</property> - <style> - <class name="dim-label"/> - </style> - </object> - </child> - <child> - <object class="GtkLabel"> - <property name="visible">1</property> - <property name="label" translatable="yes" comments="Translators: Server as any successfully connected network address">No recent servers found</property> - <style> - <class name="dim-label"/> - </style> + <object class="GtkStackPage"> + <property name="name">empty</property> + <property name="child"> + <object class="GtkBox"> + <property name="vexpand">1</property> + <property name="valign">3</property> + <property name="orientation">1</property> + <property name="spacing">18</property> + <child> + <object class="GtkImage"> + <property name="pixel-size">48</property> + <property name="icon-name">network-server-symbolic</property> + <style> + <class name="dim-label"/> + </style> + </object> + </child> + <child> + <object class="GtkLabel"> + <property name="label" translatable="1" comments="Translators: Server as any successfully connected network address">No recent servers found</property> + <style> + <class name="dim-label"/> + </style> + </object> + </child> </object> - <packing> - <property name="position">1</property> - </packing> - </child> + </property> </object> - <packing> - <property name="name">empty</property> - </packing> </child> <child> - <object class="GtkBox"> - <property name="visible">1</property> - <property name="border-width">12</property> - <property name="orientation">vertical</property> - <property name="spacing">12</property> - <child> - <object class="GtkLabel"> - <property name="visible">1</property> - <property name="label" translatable="yes">Recent Servers</property> - <attributes> - <attribute name="weight" value="bold"/> - </attributes> - </object> - </child> - <child> - <object class="GtkScrolledWindow"> - <property name="visible">1</property> - <property name="can-focus">1</property> - <property name="vexpand">1</property> - <property name="shadow-type">in</property> - <property name="min-content-width">250</property> - <property name="min-content-height">200</property> + <object class="GtkStackPage"> + <property name="name">list</property> + <property name="child"> + <object class="GtkBox"> + <property name="orientation">1</property> + <property name="spacing">12</property> + <property name="margin-start">12</property> + <property name="margin-end">12</property> + <property name="margin-top">12</property> + <property name="margin-bottom">12</property> <child> - <object class="GtkViewport"> - <property name="visible">1</property> - <property name="shadow-type">none</property> + <object class="GtkLabel"> + <property name="label" translatable="1">Recent Servers</property> + <attributes> + <attribute name="weight" value="bold"></attribute> + </attributes> + </object> + </child> + <child> + <object class="GtkScrolledWindow"> + <property name="vexpand">1</property> + <property name="has-frame">1</property> + <property name="min-content-width">250</property> + <property name="min-content-height">200</property> <child> - <object class="GtkListBox" id="recent_servers_listbox"> - <property name="visible">1</property> - <property name="can-focus">1</property> - <property name="selection-mode">none</property> - <signal name="row-activated" handler="on_recent_servers_listbox_row_activated" object="NautilusGtkPlacesView" swapped="yes"/> + <object class="GtkViewport"> + <child> + <object class="GtkListBox" id="recent_servers_listbox"> + <property name="selection-mode">0</property> + <signal name="row-activated" handler="on_recent_servers_listbox_row_activated" object="NautilusGtkPlacesView" swapped="yes"/> + </object> + </child> </object> </child> </object> </child> </object> - <packing> - <property name="position">1</property> - </packing> - </child> + </property> </object> - <packing> - <property name="name">list</property> - </packing> </child> </object> </child> </object> <template class="NautilusGtkPlacesView" parent="GtkBox"> - <property name="visible">True</property> - <property name="can-focus">False</property> - <property name="orientation">vertical</property> - <signal name="key-press-event" handler="on_key_press_event" object="NautilusGtkPlacesView" swapped="no"/> + <property name="orientation">1</property> <child> <object class="GtkStack" id="stack"> - <property name="visible">1</property> <property name="vhomogeneous">0</property> - <property name="transition-type">crossfade</property> + <property name="transition-type">1</property> <child> - <object class="GtkFrame"> - <property name="visible">1</property> - <property name="shadow-type">none</property> - <child> + <object class="GtkStackPage"> + <property name="name">browse</property> + <property name="child"> <object class="GtkScrolledWindow"> - <property name="visible">1</property> <property name="hexpand">1</property> <property name="vexpand">1</property> <child> <object class="GtkViewport"> - <property name="visible">1</property> - <property name="shadow-type">none</property> <child> <object class="GtkListBox" id="listbox"> - <property name="visible">1</property> - <property name="can-focus">1</property> - <property name="selection-mode">none</property> + <property name="selection-mode">0</property> <signal name="row-activated" handler="on_listbox_row_activated" object="NautilusGtkPlacesView" swapped="yes"/> </object> </child> </object> </child> </object> - </child> + </property> </object> - <packing> - <property name="name">browse</property> - </packing> </child> <child> - <object class="GtkBox"> - <property name="visible">1</property> - <property name="halign">center</property> - <property name="valign">center</property> - <property name="hexpand">1</property> - <property name="vexpand">1</property> - <property name="orientation">vertical</property> - <property name="spacing">12</property> - <child> - <object class="GtkImage"> - <property name="visible">1</property> - <property name="pixel-size">72</property> - <property name="icon-name">edit-find-symbolic</property> - <style> - <class name="dim-label"/> - </style> - </object> - </child> - <child> - <object class="GtkLabel"> - <property name="visible">1</property> - <property name="label" translatable="yes">No results found</property> - <attributes> - <attribute name="weight" value="bold"/> - <attribute name="scale" value="1.44"/> - </attributes> - </object> - <packing> - <property name="position">1</property> - </packing> - </child> - <child> - <object class="GtkLabel"> - <property name="visible">1</property> - <property name="label" translatable="yes">Try a different search</property> - <style> - <class name="dim-label"/> - </style> + <object class="GtkStackPage"> + <property name="name">empty-search</property> + <property name="child"> + <object class="GtkBox"> + <property name="halign">3</property> + <property name="valign">3</property> + <property name="hexpand">1</property> + <property name="vexpand">1</property> + <property name="orientation">1</property> + <property name="spacing">12</property> + <child> + <object class="GtkImage"> + <property name="pixel-size">72</property> + <property name="icon-name">edit-find-symbolic</property> + <style> + <class name="dim-label"/> + </style> + </object> + </child> + <child> + <object class="GtkLabel"> + <property name="label" translatable="1">No results found</property> + <attributes> + <attribute name="weight" value="bold"></attribute> + <attribute name="scale" value="1.44"></attribute> + </attributes> + </object> + </child> + <child> + <object class="GtkLabel"> + <property name="label" translatable="1">Try a different search</property> + <style> + <class name="dim-label"/> + </style> + </object> + </child> </object> - <packing> - <property name="position">2</property> - </packing> - </child> + </property> </object> - <packing> - <property name="name">empty-search</property> - </packing> </child> </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> </child> <child> <object class="GtkActionBar" id="actionbar"> - <property name="visible">1</property> <property name="hexpand">1</property> <style> <class name="background"/> </style> <child> <object class="GtkLabel"> - <property name="visible">1</property> <property name="hexpand">1</property> <property name="xalign">0</property> - <property name="label" translatable="yes">Connect to _Server</property> + <property name="label" translatable="1">Connect to _Server</property> <property name="mnemonic-widget">address_entry</property> <property name="use-underline">1</property> <attributes> - <attribute name="weight" value="bold"/> + <attribute name="weight" value="bold"></attribute> </attributes> </object> </child> - <child> + <child type="end"> <object class="GtkButton" id="connect_button"> - <property name="label" translatable="yes">Con_nect</property> + <property name="label" translatable="1">Con_nect</property> <property name="use-underline">1</property> - <property name="visible">1</property> - <property name="can-focus">1</property> <property name="sensitive">0</property> <property name="receives-default">1</property> - <property name="valign">center</property> + <property name="valign">3</property> <signal name="clicked" handler="on_connect_button_clicked" object="NautilusGtkPlacesView" swapped="yes"/> </object> - <packing> - <property name="pack-type">end</property> - </packing> </child> - <child> + <child type="end"> <object class="GtkBox"> - <property name="visible">1</property> <property name="hexpand">1</property> <child> <object class="GtkEntry" id="address_entry"> - <property name="visible">1</property> - <property name="can-focus">1</property> <property name="hexpand">1</property> <property name="width-chars">20</property> - <property name="placeholder-text" translatable="yes">Enter server address…</property> + <property name="placeholder-text" translatable="1">Enter server address…</property> <property name="secondary-icon-name">dialog-question-symbolic</property> <property name="completion">address_entry_completion</property> <signal name="notify::text" handler="on_address_entry_text_changed" object="NautilusGtkPlacesView" swapped="yes"/> @@ -347,36 +284,21 @@ </child> <child> <object class="GtkMenuButton" id="server_list_button"> - <property name="visible">1</property> - <property name="can-focus">1</property> <property name="receives-default">1</property> - <property name="direction">up</property> + <property name="direction">0</property> <property name="popover">recent_servers_popover</property> + <property name="icon-name">pan-down-symbolic</property> <style> <class name="server-list-button"/> </style> - <child> - <object class="GtkImage"> - <property name="visible">1</property> - <property name="icon-name">pan-down-symbolic</property> - </object> - </child> </object> </child> <style> <class name="linked"/> </style> </object> - <packing> - <property name="pack-type">end</property> - </packing> </child> </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> </child> </template> </interface> diff --git a/src/gtk/nautilusgtkplacesviewprivate.h b/src/gtk/nautilusgtkplacesviewprivate.h index b821476cf..4cf6e3e17 100644 --- a/src/gtk/nautilusgtkplacesviewprivate.h +++ b/src/gtk/nautilusgtkplacesviewprivate.h @@ -22,7 +22,7 @@ #if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) #endif -#include "nautilusgtkplacessidebar.h" +#include "nautilusgtkplacessidebarprivate.h" G_BEGIN_DECLS @@ -35,30 +35,6 @@ G_BEGIN_DECLS typedef struct _NautilusGtkPlacesView NautilusGtkPlacesView; typedef struct _NautilusGtkPlacesViewClass NautilusGtkPlacesViewClass; -typedef struct _NautilusGtkPlacesViewPrivate NautilusGtkPlacesViewPrivate; - -struct _NautilusGtkPlacesViewClass -{ - GtkBoxClass parent_class; - - void (* open_location) (NautilusGtkPlacesView *view, - GFile *location, - NautilusGtkPlacesOpenFlags open_flags); - - void (* show_error_message) (NautilusGtkPlacesSidebar *sidebar, - const gchar *primary, - const gchar *secondary); - - /*< private >*/ - - /* Padding for future expansion */ - gpointer reserved[10]; -}; - -struct _NautilusGtkPlacesView -{ - GtkBox parent_instance; -}; GType nautilus_gtk_places_view_get_type (void) G_GNUC_CONST; @@ -66,14 +42,9 @@ NautilusGtkPlacesOpenFlags nautilus_gtk_places_view_get_open_flags void nautilus_gtk_places_view_set_open_flags (NautilusGtkPlacesView *view, NautilusGtkPlacesOpenFlags flags); -const gchar* nautilus_gtk_places_view_get_search_query (NautilusGtkPlacesView *view); +const char * nautilus_gtk_places_view_get_search_query (NautilusGtkPlacesView *view); void nautilus_gtk_places_view_set_search_query (NautilusGtkPlacesView *view, - const gchar *query_text); - -gboolean nautilus_gtk_places_view_get_local_only (NautilusGtkPlacesView *view); - -void nautilus_gtk_places_view_set_local_only (NautilusGtkPlacesView *view, - gboolean local_only); + const char *query_text); gboolean nautilus_gtk_places_view_get_loading (NautilusGtkPlacesView *view); diff --git a/src/gtk/nautilusgtkplacesviewrow.c b/src/gtk/nautilusgtkplacesviewrow.c index f07dd4e70..0fe87ec10 100644 --- a/src/gtk/nautilusgtkplacesviewrow.c +++ b/src/gtk/nautilusgtkplacesviewrow.c @@ -19,6 +19,7 @@ #include "config.h" #include <glib/gi18n.h> #include <gtk/gtk.h> +#include "nautilus-enum-types.h" #include <gio/gio.h> @@ -42,7 +43,6 @@ struct _NautilusGtkPlacesViewRow GtkSpinner *busy_spinner; GtkButton *eject_button; GtkImage *eject_icon; - GtkEventBox *event_box; GtkImage *icon_image; GtkLabel *name_label; GtkLabel *path_label; @@ -53,7 +53,7 @@ struct _NautilusGtkPlacesViewRow GCancellable *cancellable; - gint is_network : 1; + int is_network : 1; }; G_DEFINE_TYPE (NautilusGtkPlacesViewRow, nautilus_gtk_places_view_row, GTK_TYPE_LIST_BOX_ROW) @@ -82,9 +82,9 @@ measure_available_space_finished (GObject *object, GError *error; guint64 free_space; guint64 total_space; - gchar *formatted_free_size; - gchar *formatted_total_size; - gchar *label; + char *formatted_free_size; + char *formatted_total_size; + char *label; guint plural_form; error = NULL; @@ -210,16 +210,13 @@ nautilus_gtk_places_view_row_get_property (GObject *object, GParamSpec *pspec) { NautilusGtkPlacesViewRow *self; - GIcon *icon; self = NAUTILUS_GTK_PLACES_VIEW_ROW (object); - icon = NULL; switch (prop_id) { case PROP_ICON: - gtk_image_get_gicon (self->icon_image, &icon, NULL); - g_value_set_object (value, icon); + g_value_set_object (value, gtk_image_get_gicon (self->icon_image)); break; case PROP_NAME: @@ -262,9 +259,7 @@ nautilus_gtk_places_view_row_set_property (GObject *object, switch (prop_id) { case PROP_ICON: - gtk_image_set_from_gicon (self->icon_image, - g_value_get_object (value), - GTK_ICON_SIZE_LARGE_TOOLBAR); + gtk_image_set_from_gicon (self->icon_image, g_value_get_object (value)); break; case PROP_NAME: @@ -309,6 +304,19 @@ nautilus_gtk_places_view_row_set_property (GObject *object, } static void +nautilus_gtk_places_view_row_size_allocate (GtkWidget *widget, + int width, + int height, + int baseline) +{ + GtkWidget *menu = GTK_WIDGET (g_object_get_data (G_OBJECT (widget), "menu")); + + GTK_WIDGET_CLASS (nautilus_gtk_places_view_row_parent_class)->size_allocate (widget, width, height, baseline); + if (menu) + gtk_popover_present (GTK_POPOVER (menu)); +} + +static void nautilus_gtk_places_view_row_class_init (NautilusGtkPlacesViewRowClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); @@ -318,6 +326,8 @@ nautilus_gtk_places_view_row_class_init (NautilusGtkPlacesViewRowClass *klass) object_class->get_property = nautilus_gtk_places_view_row_get_property; object_class->set_property = nautilus_gtk_places_view_row_set_property; + widget_class->size_allocate = nautilus_gtk_places_view_row_size_allocate; + properties[PROP_ICON] = g_param_spec_object ("icon", "Icon of the row", @@ -376,7 +386,6 @@ nautilus_gtk_places_view_row_class_init (NautilusGtkPlacesViewRowClass *klass) gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesViewRow, busy_spinner); gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesViewRow, eject_button); gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesViewRow, eject_icon); - gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesViewRow, event_box); gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesViewRow, icon_image); gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesViewRow, name_label); gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesViewRow, path_label); @@ -430,14 +439,6 @@ nautilus_gtk_places_view_row_get_eject_button (NautilusGtkPlacesViewRow *row) return GTK_WIDGET (row->eject_button); } -GtkWidget* -nautilus_gtk_places_view_row_get_event_box (NautilusGtkPlacesViewRow *row) -{ - g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW_ROW (row), NULL); - - return GTK_WIDGET (row->event_box); -} - void nautilus_gtk_places_view_row_set_busy (NautilusGtkPlacesViewRow *row, gboolean is_busy) @@ -448,10 +449,12 @@ nautilus_gtk_places_view_row_set_busy (NautilusGtkPlacesViewRow *row, { gtk_stack_set_visible_child (row->mount_stack, GTK_WIDGET (row->busy_spinner)); gtk_widget_set_child_visible (GTK_WIDGET (row->mount_stack), TRUE); + gtk_spinner_start (row->busy_spinner); } else { gtk_widget_set_child_visible (GTK_WIDGET (row->mount_stack), FALSE); + gtk_spinner_stop (row->busy_spinner); } } @@ -471,7 +474,7 @@ nautilus_gtk_places_view_row_set_is_network (NautilusGtkPlacesViewRow *row, { row->is_network = is_network; - gtk_image_set_from_icon_name (row->eject_icon, "media-eject-symbolic", GTK_ICON_SIZE_BUTTON); + gtk_image_set_from_icon_name (row->eject_icon, "media-eject-symbolic"); gtk_widget_set_tooltip_text (GTK_WIDGET (row->eject_button), is_network ? _("Disconnect") : _("Unmount")); } } diff --git a/src/gtk/nautilusgtkplacesviewrow.ui b/src/gtk/nautilusgtkplacesviewrow.ui index 99d2dcb42..231d65975 100644 --- a/src/gtk/nautilusgtkplacesviewrow.ui +++ b/src/gtk/nautilusgtkplacesviewrow.ui @@ -1,80 +1,59 @@ <?xml version="1.0" encoding="UTF-8"?> -<interface domain="gtk30"> - <requires lib="gtk+" version="3.16"/> +<interface domain="gtk40"> <template class="NautilusGtkPlacesViewRow" parent="GtkListBoxRow"> <property name="width-request">100</property> - <property name="visible">True</property> - <property name="can-focus">True</property> - <child> - <object class="GtkEventBox" id="event_box"> - <property name="visible">1</property> + <property name="child"> + <object class="GtkBox" id="box"> + <property name="margin-start">12</property> + <property name="margin-end">12</property> + <property name="margin-top">6</property> + <property name="margin-bottom">6</property> + <property name="spacing">18</property> <child> - <object class="GtkBox" id="box"> - <property name="visible">1</property> - <property name="margin-start">12</property> - <property name="margin-end">12</property> - <property name="margin-top">6</property> - <property name="margin-bottom">6</property> - <property name="spacing">18</property> - <child> - <object class="GtkImage" id="icon_image"> - <property name="visible">1</property> - <property name="pixel-size">32</property> - </object> - </child> - <child> - <object class="GtkLabel" id="name_label"> - <property name="visible">1</property> - <property name="hexpand">1</property> - <property name="xalign">0</property> - <property name="ellipsize">end</property> - </object> - <packing> - <property name="position">1</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="available_space_label"> - <property name="xalign">1</property> - <style> - <class name="dim-label"/> - </style> - </object> - <packing> - <property name="position">2</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="path_label"> - <property name="visible">1</property> - <property name="justify">right</property> - <property name="ellipsize">middle</property> - <property name="xalign">0</property> - <property name="max-width-chars">15</property> - <style> - <class name="dim-label"/> - </style> - </object> - <packing> - <property name="position">3</property> - </packing> - </child> + <object class="GtkImage" id="icon_image"> + <property name="pixel-size">32</property> + </object> + </child> + <child> + <object class="GtkLabel" id="name_label"> + <property name="hexpand">1</property> + <property name="xalign">0</property> + <property name="ellipsize">3</property> + </object> + </child> + <child> + <object class="GtkLabel" id="available_space_label"> + <property name="xalign">1</property> + <style> + <class name="dim-label"/> + </style> + </object> + </child> + <child> + <object class="GtkLabel" id="path_label"> + <property name="justify">1</property> + <property name="ellipsize">2</property> + <property name="xalign">0</property> + <property name="max-width-chars">15</property> + <style> + <class name="dim-label"/> + </style> + </object> + </child> + <child> + <object class="GtkStack" id="mount_stack"> <child> - <object class="GtkStack" id="mount_stack"> - <property name="visible">1</property> - <property name="hhomogeneous">1</property> - <property name="vhomogeneous">1</property> - <child> + <object class="GtkStackPage"> + <property name="name">button</property> + <property name="child"> <object class="GtkButton" id="eject_button"> - <property name="visible">1</property> - <property name="halign">center</property> - <property name="valign">center</property> - <property name="tooltip-text" translatable="yes">Unmount</property> + <property name="visible">0</property> + <property name="halign">3</property> + <property name="valign">3</property> + <property name="tooltip-text" translatable="1">Unmount</property> <child> <object class="GtkImage" id="eject_icon"> - <property name="visible">1</property> <property name="icon-name">media-eject-symbolic</property> - <property name="icon-size">1</property> </object> </child> <style> @@ -82,23 +61,23 @@ <class name="sidebar-button"/> </style> </object> - </child> - <child> + </property> + </object> + </child> + <child> + <object class="GtkStackPage"> + <property name="name">spinner</property> + <property name="child"> <object class="GtkSpinner" id="busy_spinner"> - <property name="visible">1</property> - <property name="active">1</property> - <property name="halign">center</property> - <property name="valign">center</property> + <property name="halign">3</property> + <property name="valign">3</property> </object> - </child> + </property> </object> - <packing> - <property name="position">4</property> - </packing> </child> </object> </child> </object> - </child> + </property> </template> </interface> diff --git a/src/gtk/nautilusgtkplacesviewrowprivate.h b/src/gtk/nautilusgtkplacesviewrowprivate.h index fb32e1c67..d54b918c0 100644 --- a/src/gtk/nautilusgtkplacesviewrowprivate.h +++ b/src/gtk/nautilusgtkplacesviewrowprivate.h @@ -34,8 +34,6 @@ GtkWidget* nautilus_gtk_places_view_row_new (GVolu GtkWidget* nautilus_gtk_places_view_row_get_eject_button (NautilusGtkPlacesViewRow *row); -GtkWidget* nautilus_gtk_places_view_row_get_event_box (NautilusGtkPlacesViewRow *row); - GMount* nautilus_gtk_places_view_row_get_mount (NautilusGtkPlacesViewRow *row); GVolume* nautilus_gtk_places_view_row_get_volume (NautilusGtkPlacesViewRow *row); diff --git a/src/gtk/nautilusgtksidebarrow.c b/src/gtk/nautilusgtksidebarrow.c index 7cc24b09f..0b0d6103f 100644 --- a/src/gtk/nautilusgtksidebarrow.c +++ b/src/gtk/nautilusgtksidebarrow.c @@ -19,14 +19,14 @@ #include "config.h" #include <glib/gi18n.h> #include <gtk/gtk.h> +#include "nautilus-enum-types.h" #include "nautilusgtksidebarrowprivate.h" /* For section and place type enums */ #include "nautilusgtkplacessidebarprivate.h" -#include "nautilusgtkplacessidebar.h" #ifdef HAVE_CLOUDPROVIDERS -#include <cloudproviders/cloudprovidersaccount.h> +#include <cloudproviders.h> #endif struct _NautilusGtkSidebarRow @@ -36,22 +36,21 @@ struct _NautilusGtkSidebarRow GIcon *end_icon; GtkWidget *start_icon_widget; GtkWidget *end_icon_widget; - gchar *label; - gchar *tooltip; + char *label; + char *tooltip; GtkWidget *label_widget; gboolean ejectable; GtkWidget *eject_button; - gint order_index; - NautilusGtkPlacesSidebarSectionType section_type; - NautilusGtkPlacesSidebarPlaceType place_type; - gchar *uri; + int order_index; + NautilusGtkPlacesSectionType section_type; + NautilusGtkPlacesPlaceType place_type; + char *uri; GDrive *drive; GVolume *volume; GMount *mount; GObject *cloud_provider_account; gboolean placeholder; NautilusGtkPlacesSidebar *sidebar; - GtkWidget *event_box; GtkWidget *revealer; GtkWidget *busy_spinner; }; @@ -88,7 +87,7 @@ cloud_row_update (NautilusGtkSidebarRow *self) { CloudProvidersAccount *account; GIcon *end_icon; - gint provider_status; + int provider_status; account = CLOUD_PROVIDERS_ACCOUNT (self->cloud_provider_account); provider_status = cloud_providers_account_get_status (account); @@ -165,11 +164,11 @@ nautilus_gtk_sidebar_row_get_property (GObject *object, break; case PROP_SECTION_TYPE: - g_value_set_int (value, self->section_type); + g_value_set_enum (value, self->section_type); break; case PROP_PLACE_TYPE: - g_value_set_int (value, self->place_type); + g_value_set_enum (value, self->place_type); break; case PROP_URI: @@ -208,7 +207,6 @@ nautilus_gtk_sidebar_row_set_property (GObject *object, GParamSpec *pspec) { NautilusGtkSidebarRow *self = NAUTILUS_GTK_SIDEBAR_ROW (object); - GtkStyleContext *context; switch (prop_id) { @@ -223,9 +221,7 @@ nautilus_gtk_sidebar_row_set_property (GObject *object, if (object != NULL) { self->start_icon = G_ICON (g_object_ref (object)); - gtk_image_set_from_gicon (GTK_IMAGE (self->start_icon_widget), - self->start_icon, - GTK_ICON_SIZE_MENU); + gtk_image_set_from_gicon (GTK_IMAGE (self->start_icon_widget), self->start_icon); } else { @@ -241,9 +237,7 @@ nautilus_gtk_sidebar_row_set_property (GObject *object, if (object != NULL) { self->end_icon = G_ICON (g_object_ref (object)); - gtk_image_set_from_gicon (GTK_IMAGE (self->end_icon_widget), - self->end_icon, - GTK_ICON_SIZE_MENU); + gtk_image_set_from_gicon (GTK_IMAGE (self->end_icon_widget), self->end_icon); gtk_widget_show (self->end_icon_widget); } else @@ -279,16 +273,16 @@ nautilus_gtk_sidebar_row_set_property (GObject *object, break; case PROP_SECTION_TYPE: - self->section_type = g_value_get_int (value); - if (self->section_type == SECTION_COMPUTER || - self->section_type == SECTION_OTHER_LOCATIONS) + self->section_type = g_value_get_enum (value); + if (self->section_type == NAUTILUS_GTK_PLACES_SECTION_COMPUTER || + self->section_type == NAUTILUS_GTK_PLACES_SECTION_OTHER_LOCATIONS) gtk_label_set_ellipsize (GTK_LABEL (self->label_widget), PANGO_ELLIPSIZE_NONE); else gtk_label_set_ellipsize (GTK_LABEL (self->label_widget), PANGO_ELLIPSIZE_END); break; case PROP_PLACE_TYPE: - self->place_type = g_value_get_int (value); + self->place_type = g_value_get_enum (value); break; case PROP_URI: @@ -340,8 +334,8 @@ nautilus_gtk_sidebar_row_set_property (GObject *object, self->tooltip = NULL; gtk_widget_set_tooltip_text (GTK_WIDGET (self), NULL); self->ejectable = FALSE; - self->section_type = SECTION_BOOKMARKS; - self->place_type = PLACES_BOOKMARK_PLACEHOLDER; + self->section_type = NAUTILUS_GTK_PLACES_SECTION_BOOKMARKS; + self->place_type = NAUTILUS_GTK_PLACES_BOOKMARK_PLACEHOLDER; g_free (self->uri); self->uri = NULL; g_clear_object (&self->drive); @@ -349,12 +343,9 @@ nautilus_gtk_sidebar_row_set_property (GObject *object, g_clear_object (&self->mount); g_clear_object (&self->cloud_provider_account); - gtk_container_foreach (GTK_CONTAINER (self), - (GtkCallback) gtk_widget_destroy, - NULL); + gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (self), NULL); - context = gtk_widget_get_style_context (GTK_WIDGET (self)); - gtk_style_context_add_class (context, "sidebar-placeholder-row"); + gtk_widget_add_css_class (GTK_WIDGET (self), "sidebar-placeholder-row"); } break; @@ -380,18 +371,18 @@ on_child_revealed (GObject *self, void nautilus_gtk_sidebar_row_reveal (NautilusGtkSidebarRow *self) { - gtk_widget_show_all (GTK_WIDGET (self)); + gtk_widget_show (GTK_WIDGET (self)); gtk_revealer_set_reveal_child (GTK_REVEALER (self->revealer), TRUE); } void nautilus_gtk_sidebar_row_hide (NautilusGtkSidebarRow *self, - gboolean inmediate) + gboolean immediate) { guint transition_duration; transition_duration = gtk_revealer_get_transition_duration (GTK_REVEALER (self->revealer)); - if (inmediate) + if (immediate) gtk_revealer_set_transition_duration (GTK_REVEALER (self->revealer), 0); gtk_revealer_set_reveal_child (GTK_REVEALER (self->revealer), FALSE); @@ -409,8 +400,7 @@ nautilus_gtk_sidebar_row_set_start_icon (NautilusGtkSidebarRow *self, { g_set_object (&self->start_icon, icon); if (self->start_icon != NULL) - gtk_image_set_from_gicon (GTK_IMAGE (self->start_icon_widget), self->start_icon, - GTK_ICON_SIZE_MENU); + gtk_image_set_from_gicon (GTK_IMAGE (self->start_icon_widget), self->start_icon); else gtk_image_clear (GTK_IMAGE (self->start_icon_widget)); @@ -428,8 +418,7 @@ nautilus_gtk_sidebar_row_set_end_icon (NautilusGtkSidebarRow *self, { g_set_object (&self->end_icon, icon); if (self->end_icon != NULL) - gtk_image_set_from_gicon (GTK_IMAGE (self->end_icon_widget), self->end_icon, - GTK_ICON_SIZE_MENU); + gtk_image_set_from_gicon (GTK_IMAGE (self->end_icon_widget), self->end_icon); else if (self->end_icon_widget != NULL) gtk_image_clear (GTK_IMAGE (self->end_icon_widget)); @@ -467,6 +456,8 @@ static void nautilus_gtk_sidebar_row_init (NautilusGtkSidebarRow *self) { gtk_widget_init_template (GTK_WIDGET (self)); + + gtk_widget_set_focus_on_click (GTK_WIDGET (self), FALSE); } static void @@ -537,22 +528,24 @@ nautilus_gtk_sidebar_row_class_init (NautilusGtkSidebarRowClass *klass) G_PARAM_STATIC_STRINGS)); properties [PROP_SECTION_TYPE] = - g_param_spec_int ("section-type", - "section type", - "The section type.", - SECTION_INVALID, N_SECTIONS, SECTION_INVALID, - (G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS | - G_PARAM_CONSTRUCT_ONLY)); + g_param_spec_enum ("section-type", + "section type", + "The section type.", + NAUTILUS_TYPE_GTK_PLACES_SECTION_TYPE, + NAUTILUS_GTK_PLACES_SECTION_INVALID, + (G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS | + G_PARAM_CONSTRUCT_ONLY)); properties [PROP_PLACE_TYPE] = - g_param_spec_int ("place-type", - "place type", - "The place type.", - PLACES_INVALID, N_PLACES, PLACES_INVALID, - (G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS | - G_PARAM_CONSTRUCT_ONLY)); + g_param_spec_enum ("place-type", + "place type", + "The place type.", + NAUTILUS_TYPE_GTK_PLACES_PLACE_TYPE, + NAUTILUS_GTK_PLACES_INVALID, + (G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS | + G_PARAM_CONSTRUCT_ONLY)); properties [PROP_URI] = g_param_spec_string ("uri", @@ -616,7 +609,6 @@ nautilus_gtk_sidebar_row_class_init (NautilusGtkSidebarRowClass *klass) gtk_widget_class_bind_template_child (widget_class, NautilusGtkSidebarRow, end_icon_widget); gtk_widget_class_bind_template_child (widget_class, NautilusGtkSidebarRow, label_widget); gtk_widget_class_bind_template_child (widget_class, NautilusGtkSidebarRow, eject_button); - gtk_widget_class_bind_template_child (widget_class, NautilusGtkSidebarRow, event_box); gtk_widget_class_bind_template_child (widget_class, NautilusGtkSidebarRow, revealer); gtk_widget_class_bind_template_child (widget_class, NautilusGtkSidebarRow, busy_spinner); @@ -651,12 +643,6 @@ nautilus_gtk_sidebar_row_get_eject_button (NautilusGtkSidebarRow *self) return self->eject_button; } -GtkWidget* -nautilus_gtk_sidebar_row_get_event_box (NautilusGtkSidebarRow *self) -{ - return self->event_box; -} - void nautilus_gtk_sidebar_row_set_busy (NautilusGtkSidebarRow *row, gboolean is_busy) diff --git a/src/gtk/nautilusgtksidebarrow.ui b/src/gtk/nautilusgtksidebarrow.ui index 26265fcb3..956ea63cb 100644 --- a/src/gtk/nautilusgtksidebarrow.ui +++ b/src/gtk/nautilusgtksidebarrow.ui @@ -1,92 +1,70 @@ <?xml version="1.0" encoding="UTF-8"?> -<interface domain="gtk30"> +<interface domain="gtk40"> <template class="NautilusGtkSidebarRow" parent="GtkListBoxRow"> - <property name="visible">True</property> - <property name="margin-top">1</property> - <property name="margin-bottom">1</property> - <property name="focus-on-click">False</property> + <property name="focus-on-click">0</property> <style> <class name="sidebar-row"/> </style> - <child> + <property name="child"> <object class="GtkRevealer" id="revealer"> - <property name="visible">1</property> <property name="reveal-child">1</property> <signal name="notify::child-revealed" handler="on_child_revealed"/> <style> <class name="sidebar-revealer"/> </style> <child> - <object class="GtkEventBox" id="event_box"> - <property name="visible">1</property> + <object class="GtkBox"> <child> - <object class="GtkBox"> - <property name="visible">1</property> - <child> - <object class="GtkImage" id="start_icon_widget"> - <property name="visible">True</property> - <style> - <class name="sidebar-icon"/> - </style> - </object> - </child> - <child> - <object class="GtkLabel" id="label_widget"> - <property name="visible">1</property> - <property name="hexpand">1</property> - <property name="xalign">0</property> - <style> - <class name="sidebar-label"/> - </style> - </object> - </child> - <child> - <object class="GtkImage" id="end_icon_widget"> - <property name="visible">False</property> - <property name="hexpand">True</property> - <property name="halign">end</property> - <property name="valign">center</property> - <property name="no-show-all">1</property> - <style> - <class name="sidebar-icon"/> - </style> - </object> - </child> - <child> - <object class="GtkButton" id="eject_button"> - <property name="visible">1</property> - <property name="halign">center</property> - <property name="valign">center</property> - <property name="margin-start">4px</property> - <property name="no-show-all">1</property> - <property name="tooltip-text" translatable="yes">Unmount</property> - <child> - <object class="GtkImage"> - <property name="visible">1</property> - <property name="icon-name">media-eject-symbolic</property> - <property name="icon-size">1</property> - </object> - </child> - <style> - <class name="image-button"/> - <class name="sidebar-button"/> - </style> - </object> - </child> - <child> - <object class="GtkSpinner" id="busy_spinner"> - <property name="active">1</property> - <property name="halign">center</property> - <property name="valign">center</property> - <property name="margin-start">4px</property> - <property name="no-show-all">1</property> - </object> - </child> + <object class="GtkImage" id="start_icon_widget"> + <style> + <class name="sidebar-icon"/> + </style> + </object> + </child> + <child> + <object class="GtkLabel" id="label_widget"> + <property name="hexpand">1</property> + <property name="xalign">0</property> + <style> + <class name="sidebar-label"/> + </style> + </object> + </child> + <child> + <object class="GtkImage" id="end_icon_widget"> + <property name="visible">0</property> + <property name="hexpand">1</property> + <property name="halign">2</property> + <property name="valign">3</property> + <style> + <class name="sidebar-icon"/> + </style> + </object> + </child> + <child> + <object class="GtkButton" id="eject_button"> + <property name="halign">3</property> + <property name="valign">3</property> + <property name="margin-start">4px</property> + <property name="icon-name">media-eject-symbolic</property> + <property name="tooltip-text" translatable="1">Unmount</property> + <style> + <class name="sidebar-button"/> + </style> + </object> + </child> + <child> + <object class="GtkSpinner" id="busy_spinner"> + <property name="spinning">1</property> + <property name="halign">3</property> + <property name="valign">3</property> + <property name="margin-start">4px</property> + <property name="visible">0</property> </object> </child> </object> </child> </object> - </child> + </property> </template> </interface> diff --git a/src/gtk/nautilusgtksidebarrowprivate.h b/src/gtk/nautilusgtksidebarrowprivate.h index 437384954..0bd9355af 100644 --- a/src/gtk/nautilusgtksidebarrowprivate.h +++ b/src/gtk/nautilusgtksidebarrowprivate.h @@ -44,11 +44,10 @@ NautilusGtkSidebarRow *nautilus_gtk_sidebar_row_clone (NautilusGtkSidebarRow *s /* Use these methods instead of gtk_widget_hide/show to use an animation */ void nautilus_gtk_sidebar_row_hide (NautilusGtkSidebarRow *self, - gboolean inmediate); + gboolean immediate); void nautilus_gtk_sidebar_row_reveal (NautilusGtkSidebarRow *self); GtkWidget *nautilus_gtk_sidebar_row_get_eject_button (NautilusGtkSidebarRow *self); -GtkWidget *nautilus_gtk_sidebar_row_get_event_box (NautilusGtkSidebarRow *self); void nautilus_gtk_sidebar_row_set_start_icon (NautilusGtkSidebarRow *self, GIcon *icon); void nautilus_gtk_sidebar_row_set_end_icon (NautilusGtkSidebarRow *self, diff --git a/src/meson.build b/src/meson.build index 3ced86915..4c171bd6d 100644 --- a/src/meson.build +++ b/src/meson.build @@ -14,6 +14,7 @@ libnautilus_sources = [ c_template: 'nautilus-enum-types.c.template', h_template: 'nautilus-enum-types.h.template', sources: [ + 'gtk/nautilusgtkplacessidebarprivate.h', 'nautilus-enums.h', 'nautilus-search-popover.h', 'nautilus-special-location-bar.h', @@ -55,10 +56,9 @@ libnautilus_sources = [ namespace: 'Nautilus' ), 'gtk/nautilusgtkbookmarksmanager.c', - 'gtk/nautilusgtkbookmarksmanager.h', + 'gtk/nautilusgtkbookmarksmanagerprivate.h', 'gtk/nautilusgtkplacessidebar.c', 'gtk/nautilusgtkplacessidebarprivate.h', - 'gtk/nautilusgtkplacessidebar.h', 'gtk/nautilusgtksidebarrow.c', 'gtk/nautilusgtksidebarrowprivate.h', 'gtk/nautilusgtkplacesview.c', diff --git a/src/nautilus-places-view.c b/src/nautilus-places-view.c index eca8bff2b..366b5b147 100644 --- a/src/nautilus-places-view.c +++ b/src/nautilus-places-view.c @@ -71,20 +71,20 @@ open_location_cb (NautilusPlacesView *view, switch (open_flags) { - case GTK_PLACES_OPEN_NEW_TAB: + case NAUTILUS_OPEN_FLAG_NEW_TAB: { flags = NAUTILUS_OPEN_FLAG_NEW_TAB | NAUTILUS_OPEN_FLAG_DONT_MAKE_ACTIVE; } break; - case GTK_PLACES_OPEN_NEW_WINDOW: + case NAUTILUS_OPEN_FLAG_NEW_WINDOW: { flags = NAUTILUS_OPEN_FLAG_NEW_WINDOW; } break; - case GTK_PLACES_OPEN_NORMAL: /* fall-through */ + case NAUTILUS_OPEN_FLAG_NORMAL: /* fall-through */ default: { flags = 0; @@ -385,7 +385,7 @@ nautilus_places_view_init (NautilusPlacesView *self) /* Places view */ priv->places_view = nautilus_gtk_places_view_new (); nautilus_gtk_places_view_set_open_flags (NAUTILUS_GTK_PLACES_VIEW (priv->places_view), - GTK_PLACES_OPEN_NEW_TAB | GTK_PLACES_OPEN_NEW_WINDOW | GTK_PLACES_OPEN_NORMAL); + NAUTILUS_OPEN_FLAG_NEW_TAB | NAUTILUS_OPEN_FLAG_NEW_WINDOW | NAUTILUS_OPEN_FLAG_NORMAL); gtk_widget_set_hexpand (priv->places_view, TRUE); gtk_widget_set_vexpand (priv->places_view, TRUE); gtk_widget_show (priv->places_view); diff --git a/src/nautilus-window.c b/src/nautilus-window.c index a1be9b307..f098c6657 100644 --- a/src/nautilus-window.c +++ b/src/nautilus-window.c @@ -46,7 +46,7 @@ #define DEBUG_FLAG NAUTILUS_DEBUG_WINDOW #include "nautilus-debug.h" -#include "gtk/nautilusgtkplacessidebar.h" +#include "gtk/nautilusgtkplacessidebarprivate.h" #include "nautilus-application.h" #include "nautilus-bookmark-list.h" @@ -1245,6 +1245,7 @@ add_menu_separator (GtkWidget *menu) gtk_widget_show (separator); } +#if 0 && SIDEBAR_MENU_ITEMS_NEEDS_GTK4_REIMPLEMENTATION static void places_sidebar_populate_popup_cb (NautilusGtkPlacesSidebar *sidebar, GtkWidget *menu, @@ -1317,6 +1318,7 @@ places_sidebar_populate_popup_cb (NautilusGtkPlacesSidebar *sidebar, } } } +#endif static void nautilus_window_set_up_sidebar (NautilusWindow *window) @@ -1344,8 +1346,10 @@ nautilus_window_set_up_sidebar (NautilusWindow *window) g_signal_connect (window->places_sidebar, "drag-perform-drop", G_CALLBACK (places_sidebar_drag_perform_drop_cb), window); #endif +#if 0 && SIDEBAR_MENU_ITEMS_NEEDS_GTK4_REIMPLEMENTATION g_signal_connect (window->places_sidebar, "populate-popup", G_CALLBACK (places_sidebar_populate_popup_cb), window); +#endif g_signal_connect (window->places_sidebar, "unmount", G_CALLBACK (places_sidebar_unmount_operation_cb), window); } @@ -2610,7 +2614,6 @@ nautilus_window_init (NautilusWindow *window) g_object_set (window->places_sidebar, "vexpand", TRUE, "visible", TRUE, - "populate-all", TRUE, "show-other-locations", TRUE, "show-starred-location", TRUE, NULL); |