sidebar: Replace gtkbookmarksmanager with nautilus-bookmark-list

This commit is contained in:
Corey Berla 2024-01-31 17:29:08 -08:00 committed by António Fernandes
parent 3aca4ce418
commit 26480b7017
5 changed files with 53 additions and 845 deletions

View file

@ -96,6 +96,5 @@ src/gtk/nautilusgtkplacesview.c
src/gtk/nautilusgtkplacesviewrow.c
src/gtk/nautilusgtkplacesviewrow.ui
src/gtk/nautilusgtkplacesview.ui
src/gtk/nautilusgtkbookmarksmanager.c
src/gtk/nautilusgtkplacessidebar.c
src/gtk/nautilusgtksidebarrow.ui

View file

@ -1,646 +0,0 @@
/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
/* GTK - The GIMP Toolkit
* nautilusgtkbookmarksmanager.c: Utilities to manage and monitor ~/.gtk-bookmarks
* Copyright (C) 2003, Red Hat, Inc.
* Copyright (C) 2007-2008 Carlos Garnacho
* Copyright (C) 2011 Suse
*
* 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/>.
*
* Authors: Federico Mena Quintero <federico@gnome.org>
*/
#include "config.h"
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include "nautilus-enum-types.h"
#include <string.h>
#include "nautilusgtkbookmarksmanagerprivate.h"
static void
_gtk_bookmark_free (gpointer data)
{
GtkBookmark *bookmark = data;
g_object_unref (bookmark->file);
g_free (bookmark->label);
g_slice_free (GtkBookmark, bookmark);
}
static void
set_error_bookmark_doesnt_exist (GFile *file, GError **error)
{
char *uri = g_file_get_uri (file);
g_set_error (error,
GTK_FILE_CHOOSER_ERROR,
GTK_FILE_CHOOSER_ERROR_NONEXISTENT,
_("%s does not exist in the bookmarks list"),
uri);
g_free (uri);
}
static GFile *
get_legacy_bookmarks_file (void)
{
GFile *file;
char *filename;
filename = g_build_filename (g_get_home_dir (), ".gtk-bookmarks", NULL);
file = g_file_new_for_path (filename);
g_free (filename);
return file;
}
static GFile *
get_bookmarks_file (void)
{
GFile *file;
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);
return file;
}
static GSList *
parse_bookmarks (const char *contents)
{
char **lines, *space;
GSList *bookmarks = NULL;
int i;
lines = g_strsplit (contents, "\n", -1);
for (i = 0; lines[i]; i++)
{
GtkBookmark *bookmark;
if (!*lines[i])
continue;
if (!g_utf8_validate (lines[i], -1, NULL))
continue;
bookmark = g_slice_new0 (GtkBookmark);
if ((space = strchr (lines[i], ' ')) != NULL)
{
space[0] = '\0';
bookmark->label = g_strdup (space + 1);
}
bookmark->file = g_file_new_for_uri (lines[i]);
bookmarks = g_slist_prepend (bookmarks, bookmark);
}
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)
{
GError *error = NULL;
GString *contents;
GSList *l;
GFile *parent = NULL;
contents = g_string_new ("");
for (l = bookmarks; l; l = l->next)
{
GtkBookmark *bookmark = l->data;
char *uri;
uri = g_file_get_uri (bookmark->file);
if (!uri)
continue;
g_string_append (contents, uri);
if (bookmark->label && g_utf8_validate (bookmark->label, -1, NULL))
g_string_append_printf (contents, " %s", bookmark->label);
g_string_append_c (contents, '\n');
g_free (uri);
}
parent = g_file_get_parent (bookmarks_file);
if (!g_file_make_directory_with_parents (parent, NULL, &error))
{
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
g_clear_error (&error);
else
goto out;
}
if (!g_file_replace_contents (bookmarks_file,
contents->str,
contents->len,
NULL, FALSE, 0, NULL,
NULL, &error))
goto out;
out:
if (error)
{
g_critical ("%s", error->message);
g_error_free (error);
}
g_clear_object (&parent);
g_string_free (contents, TRUE);
}
static void
bookmarks_file_changed (GFileMonitor *monitor,
GFile *file,
GFile *other_file,
GFileMonitorEvent event,
gpointer data)
{
NautilusGtkBookmarksManager *manager = data;
switch (event)
{
case G_FILE_MONITOR_EVENT_CHANGED:
case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
case G_FILE_MONITOR_EVENT_CREATED:
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;
}
}
NautilusGtkBookmarksManager *
_nautilus_gtk_bookmarks_manager_new (GtkBookmarksChangedFunc changed_func, gpointer changed_func_data)
{
NautilusGtkBookmarksManager *manager;
GFile *bookmarks_file;
GError *error;
manager = g_new0 (NautilusGtkBookmarksManager, 1);
manager->changed_func = changed_func;
manager->changed_func_data = changed_func_data;
manager->cancellable = g_cancellable_new ();
bookmarks_file = get_bookmarks_file ();
if (!g_file_query_exists (bookmarks_file, NULL))
{
GFile *legacy_bookmarks_file;
/* Read the legacy one and write it to the new one */
legacy_bookmarks_file = get_legacy_bookmarks_file ();
manager->bookmarks = read_bookmarks (legacy_bookmarks_file);
if (manager->bookmarks)
save_bookmarks (bookmarks_file, manager->bookmarks);
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,
G_FILE_MONITOR_NONE,
NULL, &error);
if (error)
{
g_warning ("%s", error->message);
g_error_free (error);
}
else
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;
}
void
_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);
g_signal_handler_disconnect (manager->bookmarks_monitor, manager->bookmarks_monitor_changed_id);
manager->bookmarks_monitor_changed_id = 0;
g_object_unref (manager->bookmarks_monitor);
}
g_slist_free_full (manager->bookmarks, _gtk_bookmark_free);
g_free (manager);
}
GSList *
_nautilus_gtk_bookmarks_manager_list_bookmarks (NautilusGtkBookmarksManager *manager)
{
GSList *bookmarks, *files = NULL;
g_return_val_if_fail (manager != NULL, NULL);
bookmarks = manager->bookmarks;
while (bookmarks)
{
GtkBookmark *bookmark;
bookmark = bookmarks->data;
bookmarks = bookmarks->next;
files = g_slist_prepend (files, g_object_ref (bookmark->file));
}
return g_slist_reverse (files);
}
static GSList *
find_bookmark_link_for_file (GSList *bookmarks, GFile *file, int *position_ret)
{
int pos;
pos = 0;
for (; bookmarks; bookmarks = bookmarks->next)
{
GtkBookmark *bookmark = bookmarks->data;
if (g_file_equal (file, bookmark->file))
{
if (position_ret)
*position_ret = pos;
return bookmarks;
}
pos++;
}
if (position_ret)
*position_ret = -1;
return NULL;
}
gboolean
_nautilus_gtk_bookmarks_manager_has_bookmark (NautilusGtkBookmarksManager *manager,
GFile *file)
{
GSList *link;
link = find_bookmark_link_for_file (manager->bookmarks, file, NULL);
return (link != NULL);
}
gboolean
_nautilus_gtk_bookmarks_manager_insert_bookmark (NautilusGtkBookmarksManager *manager,
GFile *file,
int position,
GError **error)
{
GSList *link;
GtkBookmark *bookmark;
GFile *bookmarks_file;
g_return_val_if_fail (manager != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
link = find_bookmark_link_for_file (manager->bookmarks, file, NULL);
if (link)
{
char *uri;
bookmark = link->data;
uri = g_file_get_uri (bookmark->file);
g_set_error (error,
GTK_FILE_CHOOSER_ERROR,
GTK_FILE_CHOOSER_ERROR_ALREADY_EXISTS,
_("%s already exists in the bookmarks list"),
uri);
g_free (uri);
return FALSE;
}
bookmark = g_slice_new0 (GtkBookmark);
bookmark->file = g_object_ref (file);
manager->bookmarks = g_slist_insert (manager->bookmarks, bookmark, position);
bookmarks_file = get_bookmarks_file ();
save_bookmarks (bookmarks_file, manager->bookmarks);
g_object_unref (bookmarks_file);
notify_changed (manager);
return TRUE;
}
gboolean
_nautilus_gtk_bookmarks_manager_remove_bookmark (NautilusGtkBookmarksManager *manager,
GFile *file,
GError **error)
{
GSList *link;
GFile *bookmarks_file;
g_return_val_if_fail (manager != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
if (!manager->bookmarks)
return FALSE;
link = find_bookmark_link_for_file (manager->bookmarks, file, NULL);
if (link)
{
GtkBookmark *bookmark = link->data;
manager->bookmarks = g_slist_remove_link (manager->bookmarks, link);
_gtk_bookmark_free (bookmark);
g_slist_free_1 (link);
}
else
{
set_error_bookmark_doesnt_exist (file, error);
return FALSE;
}
bookmarks_file = get_bookmarks_file ();
save_bookmarks (bookmarks_file, manager->bookmarks);
g_object_unref (bookmarks_file);
notify_changed (manager);
return TRUE;
}
gboolean
_nautilus_gtk_bookmarks_manager_reorder_bookmark (NautilusGtkBookmarksManager *manager,
GFile *file,
int new_position,
GError **error)
{
GSList *link;
GFile *bookmarks_file;
int old_position;
g_return_val_if_fail (manager != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
g_return_val_if_fail (new_position >= 0, FALSE);
if (!manager->bookmarks)
return FALSE;
link = find_bookmark_link_for_file (manager->bookmarks, file, &old_position);
if (new_position == old_position)
return TRUE;
if (link)
{
GtkBookmark *bookmark = link->data;
manager->bookmarks = g_slist_remove_link (manager->bookmarks, link);
g_slist_free_1 (link);
if (new_position > old_position)
new_position--;
manager->bookmarks = g_slist_insert (manager->bookmarks, bookmark, new_position);
}
else
{
set_error_bookmark_doesnt_exist (file, error);
return FALSE;
}
bookmarks_file = get_bookmarks_file ();
save_bookmarks (bookmarks_file, manager->bookmarks);
g_object_unref (bookmarks_file);
notify_changed (manager);
return TRUE;
}
char *
_nautilus_gtk_bookmarks_manager_get_bookmark_label (NautilusGtkBookmarksManager *manager,
GFile *file)
{
GSList *bookmarks;
char *label = NULL;
g_return_val_if_fail (manager != NULL, NULL);
g_return_val_if_fail (file != NULL, NULL);
bookmarks = manager->bookmarks;
while (bookmarks)
{
GtkBookmark *bookmark;
bookmark = bookmarks->data;
bookmarks = bookmarks->next;
if (g_file_equal (file, bookmark->file))
{
label = g_strdup (bookmark->label);
break;
}
}
return label;
}
gboolean
_nautilus_gtk_bookmarks_manager_set_bookmark_label (NautilusGtkBookmarksManager *manager,
GFile *file,
const char *label,
GError **error)
{
GFile *bookmarks_file;
GSList *link;
g_return_val_if_fail (manager != NULL, FALSE);
g_return_val_if_fail (file != NULL, FALSE);
link = find_bookmark_link_for_file (manager->bookmarks, file, NULL);
if (link)
{
GtkBookmark *bookmark = link->data;
GString *inlined_label = g_string_new (label);
g_string_replace (inlined_label, "\n", " ", 0);
g_free (bookmark->label);
bookmark->label = g_string_free_and_steal (inlined_label);
}
else
{
set_error_bookmark_doesnt_exist (file, error);
return FALSE;
}
bookmarks_file = get_bookmarks_file ();
save_bookmarks (bookmarks_file, manager->bookmarks);
g_object_unref (bookmarks_file);
notify_changed (manager);
return TRUE;
}
static gboolean
_nautilus_gtk_bookmarks_manager_get_xdg_type (NautilusGtkBookmarksManager *manager,
GFile *file,
GUserDirectory *directory)
{
GSList *link;
gboolean match;
GFile *location;
const char *path;
GUserDirectory dir;
GtkBookmark *bookmark;
link = find_bookmark_link_for_file (manager->bookmarks, file, NULL);
if (!link)
return FALSE;
match = FALSE;
bookmark = link->data;
for (dir = 0; dir < G_USER_N_DIRECTORIES; dir++)
{
path = g_get_user_special_dir (dir);
if (!path)
continue;
location = g_file_new_for_path (path);
match = g_file_equal (location, bookmark->file);
g_object_unref (location);
if (match)
break;
}
if (match && directory != NULL)
*directory = dir;
return match;
}
gboolean
_nautilus_gtk_bookmarks_manager_get_is_builtin (NautilusGtkBookmarksManager *manager,
GFile *file)
{
GUserDirectory xdg_type;
/* if this is not an XDG dir, it's never builtin */
if (!_nautilus_gtk_bookmarks_manager_get_xdg_type (manager, file, &xdg_type))
return FALSE;
/* exclude XDG locations we don't display by default */
return _nautilus_gtk_bookmarks_manager_get_is_xdg_dir_builtin (xdg_type);
}
gboolean
_nautilus_gtk_bookmarks_manager_get_is_xdg_dir_builtin (GUserDirectory xdg_type)
{
return (xdg_type != G_USER_DIRECTORY_DESKTOP) &&
(xdg_type != G_USER_DIRECTORY_TEMPLATES) &&
(xdg_type != G_USER_DIRECTORY_PUBLIC_SHARE);
}

View file

@ -1,89 +0,0 @@
/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
/* GTK - The GIMP Toolkit
* nautilusgtkbookmarksmanager.h: Utilities to manage and monitor ~/.gtk-bookmarks
* Copyright (C) 2003, Red Hat, Inc.
* Copyright (C) 2007-2008 Carlos Garnacho
* Copyright (C) 2011 Suse
*
* 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/>.
*
* Authors: Federico Mena Quintero <federico@gnome.org>
*/
#ifndef __NAUTILUS_GTK_BOOKMARKS_MANAGER_H__
#define __NAUTILUS_GTK_BOOKMARKS_MANAGER_H__
#include <gio/gio.h>
typedef void (* GtkBookmarksChangedFunc) (gpointer data);
typedef struct
{
/* This list contains GtkBookmark structs */
GSList *bookmarks;
GFileMonitor *bookmarks_monitor;
gulong bookmarks_monitor_changed_id;
gpointer changed_func_data;
GtkBookmarksChangedFunc changed_func;
GCancellable *cancellable;
} NautilusGtkBookmarksManager;
typedef struct
{
GFile *file;
char *label;
} GtkBookmark;
NautilusGtkBookmarksManager *_nautilus_gtk_bookmarks_manager_new (GtkBookmarksChangedFunc changed_func,
gpointer changed_func_data);
void _nautilus_gtk_bookmarks_manager_free (NautilusGtkBookmarksManager *manager);
GSList *_nautilus_gtk_bookmarks_manager_list_bookmarks (NautilusGtkBookmarksManager *manager);
gboolean _nautilus_gtk_bookmarks_manager_insert_bookmark (NautilusGtkBookmarksManager *manager,
GFile *file,
int position,
GError **error);
gboolean _nautilus_gtk_bookmarks_manager_remove_bookmark (NautilusGtkBookmarksManager *manager,
GFile *file,
GError **error);
gboolean _nautilus_gtk_bookmarks_manager_reorder_bookmark (NautilusGtkBookmarksManager *manager,
GFile *file,
int new_position,
GError **error);
gboolean _nautilus_gtk_bookmarks_manager_has_bookmark (NautilusGtkBookmarksManager *manager,
GFile *file);
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 char *label,
GError **error);
gboolean _nautilus_gtk_bookmarks_manager_get_is_builtin (NautilusGtkBookmarksManager *manager,
GFile *file);
gboolean _nautilus_gtk_bookmarks_manager_get_is_xdg_dir_builtin (GUserDirectory xdg_type);
#endif /* __NAUTILUS_GTK_BOOKMARKS_MANAGER_H__ */

View file

@ -34,7 +34,8 @@
#include "nautilusgtkplacessidebarprivate.h"
#include "nautilusgtksidebarrowprivate.h"
#include "gdk/gdkkeysyms.h"
#include "nautilusgtkbookmarksmanagerprivate.h"
#include "nautilus-application.h"
#include "nautilus-bookmark-list.h"
#include "nautilus-dnd.h"
#include "nautilus-dbus-launcher.h"
#include "nautilus-file.h"
@ -108,7 +109,7 @@ struct _NautilusGtkPlacesSidebar {
GtkWidget *list_box;
GtkWidget *new_bookmark_row;
NautilusGtkBookmarksManager *bookmarks_manager;
NautilusBookmarkList *bookmark_list;
GActionGroup *row_actions;
@ -568,8 +569,11 @@ add_special_dirs (NautilusGtkPlacesSidebar *sidebar)
char *name;
char *mount_uri;
char *tooltip;
NautilusBookmark *bookmark;
if (!_nautilus_gtk_bookmarks_manager_get_is_xdg_dir_builtin (index))
if (index == G_USER_DIRECTORY_DESKTOP ||
index == G_USER_DIRECTORY_TEMPLATES ||
index == G_USER_DIRECTORY_PUBLIC_SHARE)
continue;
path = g_get_user_special_dir (index);
@ -585,8 +589,11 @@ add_special_dirs (NautilusGtkPlacesSidebar *sidebar)
root = g_file_new_for_path (path);
name = _nautilus_gtk_bookmarks_manager_get_bookmark_label (sidebar->bookmarks_manager, root);
if (!name)
bookmark = nautilus_bookmark_list_item_with_location (sidebar->bookmark_list, root, NULL);
if (bookmark)
name = g_strdup (nautilus_bookmark_get_name (bookmark));
else
name = g_file_get_basename (root);
start_icon = special_directory_get_gicon (index);
@ -749,67 +756,6 @@ typedef struct {
gboolean is_native;
} BookmarkQueryClosure;
static void
on_bookmark_query_info_complete (GObject *source,
GAsyncResult *result,
gpointer data)
{
BookmarkQueryClosure *clos = data;
NautilusGtkPlacesSidebar *sidebar = clos->sidebar;
GFile *root = G_FILE (source);
GError *error = NULL;
GFileInfo *info;
char *bookmark_name;
char *mount_uri;
char *tooltip;
GIcon *start_icon;
info = g_file_query_info_finish (root, result, &error);
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
goto out;
bookmark_name = _nautilus_gtk_bookmarks_manager_get_bookmark_label (sidebar->bookmarks_manager, root);
if (bookmark_name == NULL && info != NULL)
bookmark_name = g_strdup (g_file_info_get_display_name (info));
else if (bookmark_name == NULL)
{
/* 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);
goto out;
}
}
if (info)
start_icon = g_object_ref (g_file_info_get_symbolic_icon (info));
else
start_icon = g_themed_icon_new_with_default_fallbacks (clos->is_native ? ICON_NAME_FOLDER : ICON_NAME_FOLDER_NETWORK);
mount_uri = g_file_get_uri (root);
tooltip = clos->is_native ? g_file_get_path (root) : g_uri_unescape_string (mount_uri, NULL);
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);
g_free (mount_uri);
g_free (tooltip);
g_free (bookmark_name);
g_object_unref (start_icon);
out:
g_clear_object (&info);
g_clear_error (&error);
g_slice_free (BookmarkQueryClosure, clos);
}
static gboolean
is_external_volume (GVolume *volume)
{
@ -937,7 +883,7 @@ update_places (NautilusGtkPlacesSidebar *sidebar)
GDrive *drive;
GList *volumes;
GVolume *volume;
GSList *bookmarks, *sl;
GList *bookmarks;
int index;
char *original_uri, *name, *identifier;
GtkListBoxRow *selected;
@ -1333,33 +1279,30 @@ update_places (NautilusGtkPlacesSidebar *sidebar)
g_list_free (mounts);
/* add bookmarks */
bookmarks = _nautilus_gtk_bookmarks_manager_list_bookmarks (sidebar->bookmarks_manager);
bookmarks = nautilus_bookmark_list_get_all (sidebar->bookmark_list);
index = 0;
for (sl = bookmarks, index = 0; sl; sl = sl->next, index++)
for (GList *l = bookmarks; l != NULL; l = l->next)
{
gboolean is_native;
BookmarkQueryClosure *clos;
GtkWidget *row;
root = sl->data;
is_native = g_file_is_native (root);
if (_nautilus_gtk_bookmarks_manager_get_is_builtin (sidebar->bookmarks_manager, root))
if (nautilus_bookmark_get_is_builtin (l->data))
continue;
clos = g_slice_new (BookmarkQueryClosure);
clos->sidebar = sidebar;
clos->index = index;
clos->is_native = is_native;
g_file_query_info_async (root,
"standard::display-name,standard::symbolic-icon",
G_FILE_QUERY_INFO_NONE,
G_PRIORITY_DEFAULT,
sidebar->cancellable,
on_bookmark_query_info_complete,
clos);
}
g_autoptr (GFile) location = nautilus_bookmark_get_location (l->data);
g_autofree char *mount_uri = nautilus_bookmark_get_uri (l->data);
g_slist_free_full (bookmarks, g_object_unref);
gboolean is_native = g_file_is_native (location);
tooltip = is_native ? g_file_get_path (location) : g_uri_unescape_string (mount_uri, NULL);
row = add_place (sidebar, NAUTILUS_GTK_PLACES_BOOKMARK,
NAUTILUS_GTK_PLACES_SECTION_BOOKMARKS,
nautilus_bookmark_get_name (l->data),
nautilus_bookmark_get_symbolic_icon (l->data),
NULL, mount_uri, NULL, NULL, NULL, NULL, index, tooltip);
g_object_bind_property (l->data, "symbolic-icon", row, "start-icon", G_BINDING_SYNC_CREATE);
index++;
}
/* Add new bookmark row */
new_bookmark_icon = g_themed_icon_new ("bookmark-new-symbolic");
@ -1787,10 +1730,12 @@ reorder_bookmarks (NautilusGtkPlacesSidebar *sidebar,
{
char *uri;
GFile *file;
guint old_position;
g_object_get (row, "uri", &uri, NULL);
file = g_file_new_for_uri (uri);
_nautilus_gtk_bookmarks_manager_reorder_bookmark (sidebar->bookmarks_manager, file, new_position, NULL);
nautilus_bookmark_list_item_with_location (sidebar->bookmark_list, file, &old_position);
nautilus_bookmark_list_move_item (sidebar->bookmark_list, old_position, new_position);
g_object_unref (file);
g_free (uri);
@ -1819,7 +1764,10 @@ drop_files_as_bookmarks (NautilusGtkPlacesSidebar *sidebar,
g_file_info_get_file_type (info) == G_FILE_TYPE_MOUNTABLE ||
g_file_info_get_file_type (info) == G_FILE_TYPE_SHORTCUT ||
g_file_info_get_file_type (info) == G_FILE_TYPE_SYMBOLIC_LINK))
_nautilus_gtk_bookmarks_manager_insert_bookmark (sidebar->bookmarks_manager, f, position++, NULL);
{
g_autoptr (NautilusBookmark) bookmark = nautilus_bookmark_new (f, NULL);
nautilus_bookmark_list_insert_item (sidebar->bookmark_list, bookmark, position++);
}
g_object_unref (info);
}
@ -2224,8 +2172,8 @@ add_shortcut_cb (GSimpleAction *action,
if (uri != NULL)
{
location = g_file_new_for_uri (uri);
if (_nautilus_gtk_bookmarks_manager_insert_bookmark (sidebar->bookmarks_manager, location, -1, NULL))
_nautilus_gtk_bookmarks_manager_set_bookmark_label (sidebar->bookmarks_manager, location, name, NULL);
g_autoptr (NautilusBookmark) bookmark = nautilus_bookmark_new (location, name);
nautilus_bookmark_list_append (sidebar->bookmark_list, bookmark);
g_object_unref (location);
}
@ -2286,20 +2234,25 @@ do_rename (GtkButton *button,
{
char *new_text;
GFile *file;
g_autoptr (NautilusBookmark) bookmark = NULL;
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))
_nautilus_gtk_bookmarks_manager_insert_bookmark (sidebar->bookmarks_manager, file, -1, NULL);
bookmark = nautilus_bookmark_list_item_with_location (sidebar->bookmark_list, file, NULL);
if (!bookmark)
{
bookmark = nautilus_bookmark_new (file, new_text);
nautilus_bookmark_list_append (sidebar->bookmark_list, bookmark);
}
else
nautilus_bookmark_set_name (g_steal_pointer (&bookmark), new_text);
if (sidebar->rename_popover)
{
gtk_popover_popdown (GTK_POPOVER (sidebar->rename_popover));
}
_nautilus_gtk_bookmarks_manager_set_bookmark_label (sidebar->bookmarks_manager, file, new_text, NULL);
g_object_unref (file);
g_free (new_text);
@ -2530,7 +2483,6 @@ remove_bookmark (NautilusGtkSidebarRow *row)
{
NautilusGtkPlacesPlaceType type;
char *uri;
GFile *file;
NautilusGtkPlacesSidebar *sidebar;
g_object_get (row,
@ -2541,9 +2493,7 @@ remove_bookmark (NautilusGtkSidebarRow *row)
if (type == NAUTILUS_GTK_PLACES_BOOKMARK)
{
file = g_file_new_for_uri (uri);
_nautilus_gtk_bookmarks_manager_remove_bookmark (sidebar->bookmarks_manager, file, NULL);
g_object_unref (file);
nautilus_bookmark_list_delete_items_with_uri (sidebar->bookmark_list, uri);
}
g_free (uri);
@ -3821,7 +3771,9 @@ nautilus_gtk_places_sidebar_init (NautilusGtkPlacesSidebar *sidebar)
sidebar->open_flags = NAUTILUS_GTK_PLACES_OPEN_NORMAL;
sidebar->bookmarks_manager = _nautilus_gtk_bookmarks_manager_new ((GtkBookmarksChangedFunc)update_places, sidebar);
NautilusApplication *app = NAUTILUS_APPLICATION (g_application_get_default ());
sidebar->bookmark_list = nautilus_application_get_bookmarks (app);
g_signal_connect_swapped (sidebar->bookmark_list, "changed", G_CALLBACK (update_places), sidebar);
g_signal_connect_object (nautilus_trash_monitor_get (), "trash-state-changed",
G_CALLBACK (update_trash_icon), sidebar,
@ -4033,12 +3985,6 @@ nautilus_gtk_places_sidebar_dispose (GObject *object)
sidebar->cancellable = NULL;
}
if (sidebar->bookmarks_manager != NULL)
{
_nautilus_gtk_bookmarks_manager_free (sidebar->bookmarks_manager);
sidebar->bookmarks_manager = NULL;
}
g_clear_pointer (&sidebar->popover, gtk_widget_unparent);
if (sidebar->rename_popover)

View file

@ -55,8 +55,6 @@ libnautilus_sources = [
interface_prefix: 'org.gnome',
namespace: 'Nautilus'
),
'gtk/nautilusgtkbookmarksmanager.c',
'gtk/nautilusgtkbookmarksmanagerprivate.h',
'gtk/nautilusgtkplacessidebar.c',
'gtk/nautilusgtkplacessidebarprivate.h',
'gtk/nautilusgtksidebarrow.c',