Change NautilusBookmark API.

Remove _set_has_custom_name() method and use just one _new()
constructor.

Also, emit the CONTENTS_CHANGED signal when we're setting a new name, as
that will trigger a save/reload of .gtk-bookmarks due to saving a new
label.

Finally, don't use gnome-fs-bookmark* icon names anymore, as they're
deprecated. We now use 'folder' as a default icon, and add a 'warning'
emblem when the URI does not exist.
This commit is contained in:
Cosimo Cecchi 2010-05-06 18:13:24 +02:00
parent 1756fb0b77
commit 856177d1dc
2 changed files with 32 additions and 49 deletions

View file

@ -34,6 +34,7 @@
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <libnautilus-private/nautilus-file.h>
#include <libnautilus-private/nautilus-icon-names.h>
enum {
APPEARANCE_CHANGED,
@ -41,9 +42,6 @@ enum {
LAST_SIGNAL
};
#define GENERIC_BOOKMARK_ICON_NAME "gnome-fs-bookmark"
#define MISSING_BOOKMARK_ICON_NAME "gnome-fs-bookmark-missing"
#define ELLIPSISED_MENU_ITEM_MIN_CHARS 32
static guint signals[LAST_SIGNAL];
@ -187,7 +185,7 @@ nautilus_bookmark_copy (NautilusBookmark *bookmark)
{
g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (bookmark), NULL);
return nautilus_bookmark_new_with_icon (
return nautilus_bookmark_new (
bookmark->details->location,
bookmark->details->name,
bookmark->details->has_custom_name,
@ -298,6 +296,8 @@ nautilus_bookmark_set_name (NautilusBookmark *bookmark, const char *new_name)
if (strcmp (new_name, bookmark->details->name) == 0) {
return FALSE;
} else if (!bookmark->details->has_custom_name) {
bookmark->details->has_custom_name = TRUE;
}
g_free (bookmark->details->name);
@ -305,13 +305,11 @@ nautilus_bookmark_set_name (NautilusBookmark *bookmark, const char *new_name)
g_signal_emit (bookmark, signals[APPEARANCE_CHANGED], 0);
return TRUE;
}
if (bookmark->details->has_custom_name) {
g_signal_emit (bookmark, signals[CONTENTS_CHANGED], 0);
}
void
nautilus_bookmark_set_has_custom_name (NautilusBookmark *bookmark, gboolean has_custom_name)
{
bookmark->details->has_custom_name = has_custom_name;
return TRUE;
}
static gboolean
@ -438,40 +436,29 @@ bookmark_file_changed_callback (NautilusFile *file, NautilusBookmark *bookmark)
static void
nautilus_bookmark_set_icon_to_default (NautilusBookmark *bookmark)
{
const char *icon_name;
GIcon *icon, *emblemed_icon, *folder;
GEmblem *emblem;
if (bookmark->details->icon) {
g_object_unref (bookmark->details->icon);
}
if (nautilus_bookmark_uri_known_not_to_exist (bookmark)) {
icon_name = MISSING_BOOKMARK_ICON_NAME;
} else {
icon_name = GENERIC_BOOKMARK_ICON_NAME;
}
bookmark->details->icon = g_themed_icon_new (icon_name);
}
folder = g_themed_icon_new (NAUTILUS_ICON_FOLDER);
/**
* nautilus_bookmark_new:
*
* Create a new NautilusBookmark from a text uri and a display name.
* The initial icon for the bookmark will be based on the information
* already available without any explicit action on NautilusBookmark's
* part.
*
* @uri: Any uri, even a malformed or non-existent one.
* @name: A string to display to the user as the bookmark's name.
*
* Return value: A newly allocated NautilusBookmark.
*
**/
NautilusBookmark *
nautilus_bookmark_new (GFile *location, const char *name)
{
return nautilus_bookmark_new_with_icon (location, name, TRUE, NULL);
if (nautilus_bookmark_uri_known_not_to_exist (bookmark)) {
icon = g_themed_icon_new (GTK_STOCK_DIALOG_WARNING);
emblem = g_emblem_new (icon);
emblemed_icon = g_emblemed_icon_new (folder, emblem);
g_object_unref (emblem);
g_object_unref (icon);
g_object_unref (folder);
folder = emblemed_icon;
}
bookmark->details->icon = folder;
}
static void
@ -535,8 +522,8 @@ nautilus_bookmark_connect_file (NautilusBookmark *bookmark)
}
NautilusBookmark *
nautilus_bookmark_new_with_icon (GFile *location, const char *name, gboolean has_custom_name,
GIcon *icon)
nautilus_bookmark_new (GFile *location, const char *name, gboolean has_custom_name,
GIcon *icon)
{
NautilusBookmark *new_bookmark;

View file

@ -67,12 +67,10 @@ struct NautilusBookmarkClass {
typedef struct NautilusBookmarkClass NautilusBookmarkClass;
GType nautilus_bookmark_get_type (void);
NautilusBookmark * nautilus_bookmark_new (GFile *location,
const char *name);
NautilusBookmark * nautilus_bookmark_new_with_icon (GFile *location,
const char *name,
gboolean has_custom_name,
GIcon *icon);
NautilusBookmark * nautilus_bookmark_new (GFile *location,
const char *name,
gboolean has_custom_name,
GIcon *icon);
NautilusBookmark * nautilus_bookmark_copy (NautilusBookmark *bookmark);
char * nautilus_bookmark_get_name (NautilusBookmark *bookmark);
GFile * nautilus_bookmark_get_location (NautilusBookmark *bookmark);
@ -80,9 +78,7 @@ char * nautilus_bookmark_get_uri (NautilusBookmark
GIcon * nautilus_bookmark_get_icon (NautilusBookmark *bookmark);
gboolean nautilus_bookmark_get_has_custom_name (NautilusBookmark *bookmark);
gboolean nautilus_bookmark_set_name (NautilusBookmark *bookmark,
const char *new_name);
void nautilus_bookmark_set_has_custom_name (NautilusBookmark *bookmark,
gboolean has_custom_name);
const char *new_name);
gboolean nautilus_bookmark_uri_known_not_to_exist (NautilusBookmark *bookmark);
int nautilus_bookmark_compare_with (gconstpointer a,
gconstpointer b);