Commit d4df96c1 authored by Cosimo Cecchi's avatar Cosimo Cecchi

all: use new NautilusBookmark API

parent 3aa0396d
......@@ -40,7 +40,7 @@
#define SAVE_JOB 2
enum {
CONTENTS_CHANGED,
CHANGED,
LAST_SIGNAL
};
......@@ -60,9 +60,7 @@ new_bookmark_from_uri (const char *uri, const char *label)
{
NautilusBookmark *new_bookmark;
NautilusFile *file;
char *name;
GIcon *icon;
gboolean has_label;
GFile *location;
gboolean native;
......@@ -71,14 +69,6 @@ new_bookmark_from_uri (const char *uri, const char *label)
location = g_file_new_for_uri (uri);
}
has_label = FALSE;
if (!label) {
name = nautilus_compute_title_for_location (location);
} else {
name = g_strdup (label);
has_label = TRUE;
}
new_bookmark = NULL;
if (uri) {
......@@ -91,18 +81,18 @@ new_bookmark_from_uri (const char *uri, const char *label)
icon = nautilus_file_get_gicon (file, 0);
}
nautilus_file_unref (file);
if (icon == NULL) {
icon = native ? g_themed_icon_new (NAUTILUS_ICON_FOLDER) :
g_themed_icon_new (NAUTILUS_ICON_FOLDER_REMOTE);
}
new_bookmark = nautilus_bookmark_new (location, name, has_label, icon);
new_bookmark = nautilus_bookmark_new (location, label, icon);
g_object_unref (icon);
}
g_free (name);
g_object_unref (location);
return new_bookmark;
}
......@@ -132,10 +122,19 @@ bookmark_in_list_changed_callback (NautilusBookmark *bookmark,
g_assert (NAUTILUS_IS_BOOKMARK (bookmark));
g_assert (NAUTILUS_IS_BOOKMARK_LIST (bookmarks));
/* Save changes so we'll have the good icon next time. */
/* save changes to the list */
nautilus_bookmark_list_save_file (bookmarks);
}
static void
bookmark_in_list_notify (GObject *object,
GParamSpec *pspec,
NautilusBookmarkList *bookmarks)
{
/* emit the changed signal without saving, as only appearance properties changed */
g_signal_emit (bookmarks, signals[CHANGED], 0);
}
static void
stop_monitoring_bookmark (NautilusBookmarkList *bookmarks,
NautilusBookmark *bookmark)
......@@ -207,12 +206,12 @@ nautilus_bookmark_list_class_init (NautilusBookmarkListClass *class)
object_class->finalize = do_finalize;
object_class->constructor = do_constructor;
signals[CONTENTS_CHANGED] =
g_signal_new ("contents_changed",
signals[CHANGED] =
g_signal_new ("changed",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NautilusBookmarkListClass,
contents_changed),
changed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
......@@ -258,8 +257,12 @@ insert_bookmark_internal (NautilusBookmarkList *bookmarks,
{
bookmarks->list = g_list_insert (bookmarks->list, bookmark, index);
g_signal_connect_object (bookmark, "contents_changed",
g_signal_connect_object (bookmark, "contents-changed",
G_CALLBACK (bookmark_in_list_changed_callback), bookmarks, 0);
g_signal_connect_object (bookmark, "notify::icon",
G_CALLBACK (bookmark_in_list_notify), bookmarks, 0);
g_signal_connect_object (bookmark, "notify::name",
G_CALLBACK (bookmark_in_list_notify), bookmarks, 0);
}
/**
......@@ -518,7 +521,7 @@ load_file_finish (NautilusBookmarkList *bookmarks,
g_free (contents);
g_strfreev (lines);
g_signal_emit (bookmarks, signals[CONTENTS_CHANGED], 0);
g_signal_emit (bookmarks, signals[CHANGED], 0);
} else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) {
g_warning ("Could not load bookmark file: %s\n", error->message);
g_error_free (error);
......@@ -595,13 +598,13 @@ save_file_async (NautilusBookmarkList *bookmarks,
/* make sure we save label if it has one for compatibility with GTK 2.7 and 2.8 */
if (nautilus_bookmark_get_has_custom_name (bookmark)) {
char *label, *uri;
const char *label;
char *uri;
label = nautilus_bookmark_get_name (bookmark);
uri = nautilus_bookmark_get_uri (bookmark);
g_string_append_printf (bookmark_string,
"%s %s\n", uri, label);
g_free (uri);
g_free (label);
} else {
char *uri;
uri = nautilus_bookmark_get_uri (bookmark);
......@@ -686,7 +689,7 @@ nautilus_bookmark_list_load_file (NautilusBookmarkList *bookmarks)
static void
nautilus_bookmark_list_save_file (NautilusBookmarkList *bookmarks)
{
g_signal_emit (bookmarks, signals[CONTENTS_CHANGED], 0);
g_signal_emit (bookmarks, signals[CHANGED], 0);
g_queue_push_head (bookmarks->pending_ops, GINT_TO_POINTER (SAVE_JOB));
......
......@@ -56,7 +56,7 @@ struct NautilusBookmarkList {
struct NautilusBookmarkListClass {
GObjectClass parent_class;
void (* contents_changed) (NautilusBookmarkList *bookmarks);
void (* changed) (NautilusBookmarkList *bookmarks);
};
GType nautilus_bookmark_list_get_type (void);
......
......@@ -339,7 +339,7 @@ create_bookmarks_window (NautilusBookmarkList *list, GObject *undo_manager_sourc
uri_field);
bookmark_list_changed_signal_id =
g_signal_connect (bookmarks, "contents_changed",
g_signal_connect (bookmarks, "changed",
G_CALLBACK (on_bookmark_list_changed), NULL);
row_changed_signal_id =
g_signal_connect (bookmark_list_store, "row_changed",
......@@ -766,7 +766,8 @@ on_selection_changed (GtkTreeSelection *treeselection,
gpointer user_data)
{
NautilusBookmark *selected;
char *name = NULL, *entry_text = NULL;
const char *name = NULL;
char *entry_text = NULL;
GFile *location;
g_assert (GTK_IS_ENTRY (name_field));
......@@ -801,7 +802,6 @@ on_selection_changed (GtkTreeSelection *treeselection,
text_changed = FALSE;
name_text_changed = FALSE;
g_free (name);
g_free (entry_text);
}
......@@ -827,8 +827,9 @@ update_bookmark_from_text (void)
location = g_file_parse_name
(gtk_entry_get_text (GTK_ENTRY (uri_field)));
bookmark = nautilus_bookmark_new (location, gtk_entry_get_text (GTK_ENTRY (name_field)),
name_text_changed, NULL);
bookmark = nautilus_bookmark_new (location,
name_text_changed ? gtk_entry_get_text (GTK_ENTRY (name_field)) : NULL,
NULL);
g_object_unref (location);
......
......@@ -431,7 +431,7 @@ update_places (NautilusPlacesSidebar *sidebar)
GVolume *volume;
int bookmark_count, index;
char *location, *mount_uri, *name, *desktop_path, *last_uri;
const gchar *path;
const gchar *path, *bookmark_name;
GIcon *icon;
GFile *root;
NautilusWindowSlot *slot;
......@@ -606,20 +606,20 @@ update_places (NautilusPlacesSidebar *sidebar)
continue;
}
name = nautilus_bookmark_get_name (bookmark);
bookmark_name = nautilus_bookmark_get_name (bookmark);
icon = nautilus_bookmark_get_icon (bookmark);
mount_uri = nautilus_bookmark_get_uri (bookmark);
tooltip = g_file_get_parse_name (root);
last_iter = add_place (sidebar, PLACES_BOOKMARK,
SECTION_BOOKMARKS,
name, icon, mount_uri,
bookmark_name, icon, mount_uri,
NULL, NULL, NULL, index,
tooltip);
compare_for_selection (sidebar,
location, mount_uri, last_uri,
&last_iter, &select_path);
g_free (name);
g_object_unref (root);
g_object_unref (icon);
g_free (mount_uri);
......@@ -1264,7 +1264,6 @@ bookmarks_drop_uris (NautilusPlacesSidebar *sidebar,
char **uris;
int i;
GFile *location;
GIcon *icon;
uris = gtk_selection_data_get_uris (selection_data);
if (!uris)
......@@ -1283,9 +1282,7 @@ bookmarks_drop_uris (NautilusPlacesSidebar *sidebar,
location = g_file_new_for_uri (uri);
nautilus_file_unref (file);
name = nautilus_compute_title_for_location (location);
icon = g_themed_icon_new (NAUTILUS_ICON_FOLDER);
bookmark = nautilus_bookmark_new (location, name, TRUE, icon);
bookmark = nautilus_bookmark_new (location, NULL, NULL);
if (!nautilus_bookmark_list_contains (sidebar->bookmarks, bookmark)) {
nautilus_bookmark_list_insert_item (sidebar->bookmarks, bookmark, position++);
......@@ -1293,7 +1290,6 @@ bookmarks_drop_uris (NautilusPlacesSidebar *sidebar,
g_object_unref (location);
g_object_unref (bookmark);
g_object_unref (icon);
g_free (name);
g_free (uri);
}
......@@ -2781,7 +2777,7 @@ bookmarks_edited (GtkCellRenderer *cell,
bookmark = nautilus_bookmark_list_item_at (sidebar->bookmarks, index);
if (bookmark != NULL) {
nautilus_bookmark_set_name (bookmark, new_text);
nautilus_bookmark_set_custom_name (bookmark, new_text);
}
}
......@@ -3177,7 +3173,7 @@ nautilus_places_sidebar_set_parent_window (NautilusPlacesSidebar *sidebar,
sidebar->bookmarks = nautilus_bookmark_list_new ();
sidebar->uri = nautilus_window_slot_get_current_uri (slot);
g_signal_connect_object (sidebar->bookmarks, "contents_changed",
g_signal_connect_object (sidebar->bookmarks, "changed",
G_CALLBACK (update_places),
sidebar, G_CONNECT_SWAPPED);
......
......@@ -278,7 +278,7 @@ nautilus_window_initialize_bookmarks_menu (NautilusWindow *window)
refresh_bookmarks_menu (window);
/* Recreate dynamic part of menu if bookmark list changes */
g_signal_connect_object (window->details->bookmark_list, "contents_changed",
g_signal_connect_object (window->details->bookmark_list, "changed",
G_CALLBACK (refresh_bookmarks_menu),
window, G_CONNECT_SWAPPED);
}
......@@ -113,7 +113,6 @@ set_displayed_location (NautilusWindowSlot *slot, GFile *location)
NautilusWindow *window;
GFile *bookmark_location;
gboolean recreate;
char *name;
window = slot->pane->window;
......@@ -131,10 +130,8 @@ set_displayed_location (NautilusWindowSlot *slot, GFile *location)
g_object_unref (slot->last_location_bookmark);
}
slot->last_location_bookmark = slot->current_location_bookmark;
name = g_file_get_basename (location);
slot->current_location_bookmark = (location == NULL) ? NULL
: nautilus_bookmark_new (location, name, FALSE, NULL);
g_free (name);
: nautilus_bookmark_new (location, NULL, NULL);
}
}
......
......@@ -67,7 +67,7 @@
typedef struct {
NautilusBookmark *bookmark;
NautilusWindow *window;
guint changed_handler_id;
GCallback refresh_callback;
NautilusBookmarkFailedCallback failed_callback;
} BookmarkHolder;
......@@ -83,14 +83,17 @@ bookmark_holder_new (NautilusBookmark *bookmark,
new_bookmark_holder->window = window;
new_bookmark_holder->bookmark = bookmark;
new_bookmark_holder->failed_callback = failed_callback;
new_bookmark_holder->refresh_callback = refresh_callback;
/* Ref the bookmark because it might be unreffed away while
* we're holding onto it (not an issue for window).
*/
g_object_ref (bookmark);
new_bookmark_holder->changed_handler_id =
g_signal_connect_object (bookmark, "appearance_changed",
refresh_callback,
window, G_CONNECT_SWAPPED);
g_signal_connect_object (bookmark, "notify::icon",
refresh_callback,
window, G_CONNECT_SWAPPED);
g_signal_connect_object (bookmark, "notify::name",
refresh_callback,
window, G_CONNECT_SWAPPED);
return new_bookmark_holder;
}
......@@ -98,8 +101,8 @@ bookmark_holder_new (NautilusBookmark *bookmark,
static void
bookmark_holder_free (BookmarkHolder *bookmark_holder)
{
g_signal_handler_disconnect (bookmark_holder->bookmark,
bookmark_holder->changed_handler_id);
g_signal_handlers_disconnect_by_func (bookmark_holder->bookmark,
bookmark_holder->refresh_callback, bookmark_holder->window);
g_object_unref (bookmark_holder->bookmark);
g_free (bookmark_holder);
}
......@@ -165,7 +168,7 @@ nautilus_menus_append_bookmark_to_menu (NautilusWindow *window,
{
BookmarkHolder *bookmark_holder;
char action_name[128];
char *name;
const char *name;
char *path;
GIcon *icon;
GtkAction *action;
......@@ -216,7 +219,6 @@ nautilus_menus_append_bookmark_to_menu (NautilusWindow *window,
TRUE);
g_free (path);
g_free (name);
}
static void
......
......@@ -535,7 +535,6 @@ char *
nautilus_window_slot_get_current_uri (NautilusWindowSlot *slot)
{
if (slot->pending_location != NULL) {
g_print ("returning pending\n");
return g_file_get_uri (slot->pending_location);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment