diff options
author | John Sullivan <sullivan@src.gnome.org> | 2000-06-16 02:01:05 +0000 |
---|---|---|
committer | John Sullivan <sullivan@src.gnome.org> | 2000-06-16 02:01:05 +0000 |
commit | 22c0f773a8faaa08a0dc3f3e9d2dcb840cbf6700 (patch) | |
tree | 400dc522566aa415936c01d9f7eeba98cfb591ef /libnautilus-private | |
parent | 2cefd51ed98f7cbc9d4f8e6622114f3b5a1c6b93 (diff) | |
download | nautilus-22c0f773a8faaa08a0dc3f3e9d2dcb840cbf6700.tar.gz |
Fixed bug 705 (Need to avoid network hit on startup for
each remote bookmark). Bookmarks now get their icon only
when they're initially created, and then store a text
version of it to disk for future sessions. We might have
to update the icon at certain times later (maybe when it's
used?).
* libnautilus-extensions/nautilus-bookmark.h,
* libnautilus-extensions/nautilus-bookmark.c:
(nautilus_bookmark_copy), (nautilus_bookmark_get_pixbuf),
(nautilus_bookmark_get_icon), (get_icon_for_uri),
(nautilus_bookmark_new), (nautilus_bookmark_new_with_icon):
Changed guts of NautilusBookmark to keep a
NautilusScalableIcon around. Also some miscellaneous
cleanup in this ancient file (need to do more).
* libnautilus-extensions/nautilus-icon-factory.h,
* libnautilus-extensions/nautilus-icon-factory.c:
(get_themed_icon_file_path): Added icon != NULL assert.
(get_icon_file_path): Handle NULL icon name by returning NULL;
some style fixes.
(nautilus_scalable_icon_get_text_pieces): New function,
returns all four pieces of text used to define a
NautilusScalableIcon.
(nautilus_scalable_icon_new_from_text_pieces):
Renamed from nautilus_scalable_icon_get and made public.
(nautilus_icon_factory_get_icon_for_file),
(nautilus_icon_factory_get_emblem_icon_by_name),
(load_image_with_embedded_text): Updated for function renaming.
* src/nautilus-bookmark-list.c: (append_bookmark_node),
(make_bookmark_from_node), (nautilus_bookmark_list_load_file):
Save & restore NautilusScalableIcon with each bookmark.
Added custom error message when trying to open a location
fails with GNOME_VFS_LOGINFAILED
* src/nautilus-applicable-views.h: Define
NAUTILUS_NAVIGATION_RESULT_LOGIN_FAILED
* src/nautilus-applicable-views.c:
(get_nautilus_navigation_result_from_gnome_vfs_result):
Support GNOME_VFS_LOGINFAILED, and tweak message for
unhandled case.
* src/nautilus-window-manage-views.c:
(nautilus_window_end_location_change_callback):
Support NAUTILUS_NAVIGATION_RESULT_LOGIN_FAILED and
remove message for unhandled case since complaining
about unhandled cases is done elsewhere.
Diffstat (limited to 'libnautilus-private')
-rw-r--r-- | libnautilus-private/nautilus-bookmark.c | 87 | ||||
-rw-r--r-- | libnautilus-private/nautilus-bookmark.h | 6 | ||||
-rw-r--r-- | libnautilus-private/nautilus-icon-factory.c | 64 | ||||
-rw-r--r-- | libnautilus-private/nautilus-icon-factory.h | 18 |
4 files changed, 136 insertions, 39 deletions
diff --git a/libnautilus-private/nautilus-bookmark.c b/libnautilus-private/nautilus-bookmark.c index 7ee32b5f8..62ea2aa73 100644 --- a/libnautilus-private/nautilus-bookmark.c +++ b/libnautilus-private/nautilus-bookmark.c @@ -40,6 +40,7 @@ struct NautilusBookmarkDetails { char *name; char *uri; + NautilusScalableIcon *icon; }; @@ -129,9 +130,10 @@ nautilus_bookmark_copy (const NautilusBookmark *bookmark) { g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (bookmark), NULL); - return nautilus_bookmark_new ( - nautilus_bookmark_get_uri (bookmark), - nautilus_bookmark_get_name (bookmark)); + return nautilus_bookmark_new_with_icon ( + bookmark->details->uri, + bookmark->details->name, + bookmark->details->icon); } const char * @@ -166,24 +168,25 @@ GdkPixbuf * nautilus_bookmark_get_pixbuf (const NautilusBookmark *bookmark, guint icon_size) { - NautilusFile *file; - GdkPixbuf *pixbuf; - - file = nautilus_file_get (nautilus_bookmark_get_uri (bookmark)); + g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (bookmark), NULL); - /* FIXME bugzilla.eazel.com 461: This might be a bookmark that points - * to nothing, or maybe its uri cannot be converted to a NautilusFile - * for some other reason. It should get some sort of generic icon, but - * for now it gets none. - */ - if (file == NULL) { + if (bookmark->details->icon == NULL) { return NULL; } + + return nautilus_icon_factory_get_pixbuf_for_icon + (bookmark->details->icon, icon_size, icon_size, icon_size, icon_size); +} - pixbuf = nautilus_icon_factory_get_pixbuf_for_file (file, icon_size); - nautilus_file_unref (file); +NautilusScalableIcon * +nautilus_bookmark_get_icon (const NautilusBookmark *bookmark) +{ + g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (bookmark), NULL); - return pixbuf; + if (bookmark->details->icon != NULL) { + nautilus_scalable_icon_ref (bookmark->details->icon); + } + return bookmark->details->icon; } const char * @@ -212,6 +215,29 @@ nautilus_bookmark_set_name (NautilusBookmark *bookmark, const char *new_name) bookmark->details->name = g_strdup (new_name); } +static NautilusScalableIcon * +get_icon_for_uri (const char *uri) +{ + NautilusFile *file; + NautilusScalableIcon *icon; + + file = nautilus_file_get (uri); + + /* FIXME bugzilla.eazel.com 461: This might be a bookmark that points + * to nothing, or maybe its uri cannot be converted to a NautilusFile + * for some other reason. It should get some sort of generic icon, but + * for now it gets none. + */ + if (file == NULL) { + return NULL; + } + + icon = nautilus_icon_factory_get_icon_for_file (file, NULL); + nautilus_file_unref (file); + + return icon; +} + /** * nautilus_bookmark_new: * @@ -225,6 +251,26 @@ nautilus_bookmark_set_name (NautilusBookmark *bookmark, const char *new_name) NautilusBookmark * nautilus_bookmark_new (const char *uri, const char *name) { + NautilusScalableIcon *icon; + NautilusBookmark *result; + + /* FIXME: This needs to do fancy asynch stuff to be + * notified when the icon is ready; we can't just get it + * right away like this. + */ + icon = get_icon_for_uri (uri); + result = nautilus_bookmark_new_with_icon (uri, name, icon); + if (icon != NULL) { + nautilus_scalable_icon_unref (icon); + } + + return result; +} + +NautilusBookmark * +nautilus_bookmark_new_with_icon (const char *uri, const char *name, + NautilusScalableIcon *icon) +{ NautilusBookmark *new_bookmark; new_bookmark = gtk_type_new (NAUTILUS_TYPE_BOOKMARK); @@ -232,8 +278,13 @@ nautilus_bookmark_new (const char *uri, const char *name) new_bookmark->details->name = g_strdup (name); new_bookmark->details->uri = g_strdup (uri); + if (icon != NULL) { + nautilus_scalable_icon_ref (icon); + } + new_bookmark->details->icon = icon; + return new_bookmark; -} +} static GtkWidget * create_pixmap_widget_for_bookmark (const NautilusBookmark *bookmark) @@ -252,7 +303,7 @@ create_pixmap_widget_for_bookmark (const NautilusBookmark *bookmark) } /** - * nautilus_bookmark_menu_item_new: + * nautilus_bookmarnuk_menu_item_new: * * Return a menu item representing a bookmark. * @bookmark: The bookmark the menu item represents. diff --git a/libnautilus-private/nautilus-bookmark.h b/libnautilus-private/nautilus-bookmark.h index f51087507..3aa170ff5 100644 --- a/libnautilus-private/nautilus-bookmark.h +++ b/libnautilus-private/nautilus-bookmark.h @@ -25,6 +25,8 @@ #ifndef NAUTILUS_BOOKMARK_H #define NAUTILUS_BOOKMARK_H +#include "nautilus-icon-factory.h" + #include <gtk/gtkwidget.h> #include <gdk/gdktypes.h> #include <gdk-pixbuf/gdk-pixbuf.h> @@ -60,9 +62,13 @@ typedef struct NautilusBookmarkClass NautilusBookmarkClass; GtkType nautilus_bookmark_get_type (void); NautilusBookmark *nautilus_bookmark_new (const char *uri, const char *name); +NautilusBookmark *nautilus_bookmark_new_with_icon (const char *uri, + const char *name, + NautilusScalableIcon *icon); NautilusBookmark *nautilus_bookmark_copy (const NautilusBookmark *bookmark); const char * nautilus_bookmark_get_name (const NautilusBookmark *bookmark); const char * nautilus_bookmark_get_uri (const NautilusBookmark *bookmark); +NautilusScalableIcon *nautilus_bookmark_get_icon (const NautilusBookmark *bookmark); void nautilus_bookmark_set_name (NautilusBookmark *bookmark, const char *new_name); int nautilus_bookmark_compare_with (gconstpointer a, diff --git a/libnautilus-private/nautilus-icon-factory.c b/libnautilus-private/nautilus-icon-factory.c index 68a728137..d0a95bf9b 100644 --- a/libnautilus-private/nautilus-icon-factory.c +++ b/libnautilus-private/nautilus-icon-factory.c @@ -211,10 +211,6 @@ static NautilusIconFactory * nautilus_get_current_icon_factory (void); static char * nautilus_icon_factory_get_thumbnail_uri (NautilusFile *file); static NautilusIconFactory * nautilus_icon_factory_new (const char *theme_name); static void nautilus_icon_factory_set_theme (const char *theme_name); -static NautilusScalableIcon *nautilus_scalable_icon_get (const char *uri, - const char *name, - const char *modifier, - const char *embedded_text); static guint nautilus_scalable_icon_hash (gconstpointer p); static gboolean nautilus_scalable_icon_equal (gconstpointer a, gconstpointer b); @@ -527,6 +523,8 @@ get_themed_icon_file_path (const char *theme_name, char *size_as_string, *property; ArtIRect parsed_rect; + g_assert (icon_name != NULL); + if (theme_name == NULL || icon_name[0] == '/') { themed_icon_name = g_strdup (icon_name); } else { @@ -624,6 +622,10 @@ get_icon_file_path (const char *name, const char *theme_name; char *path; + if (name == NULL) { + return NULL; + } + use_theme_icon = FALSE; theme_name = nautilus_get_current_icon_factory ()->theme_name; @@ -645,15 +647,16 @@ get_icon_file_path (const char *name, /* Now we know whether or not to use the theme. */ /* if there's a modifier, try using that first */ - if (modifier && strlen(modifier)) { - char* modified_name = g_strdup_printf("%s-%s", name, modifier); + if (modifier && modifier[0] != '\0') { + char* modified_name = g_strdup_printf ("%s-%s", name, modifier); path = get_themed_icon_file_path (use_theme_icon ? theme_name : NULL, modified_name, size_in_pixels, text_rect); - g_free(modified_name); - if (path) + g_free (modified_name); + if (path != NULL) { return path; + } } return get_themed_icon_file_path (use_theme_icon ? theme_name : NULL, @@ -678,12 +681,36 @@ icon_theme_changed_callback (gpointer user_data) } -/* Get or create a scalable icon. */ -static NautilusScalableIcon * -nautilus_scalable_icon_get (const char *uri, - const char *name, - const char *modifier, - const char *embedded_text) +/* Decompose a scalable icon into its text pieces. */ +void +nautilus_scalable_icon_get_text_pieces (NautilusScalableIcon *icon, + char **uri_return, + char **name_return, + char **modifier_return, + char **embedded_text_return) +{ + g_return_if_fail (icon != NULL); + + if (uri_return != NULL) { + *uri_return = g_strdup (icon->uri); + } + if (name_return != NULL) { + *name_return = g_strdup (icon->name); + } + if (modifier_return != NULL) { + *modifier_return = g_strdup (icon->modifier); + } + if (embedded_text_return != NULL) { + *embedded_text_return = g_strdup (icon->embedded_text); + } +} + +/* Get or create a scalable icon from text pieces. */ +NautilusScalableIcon * +nautilus_scalable_icon_new_from_text_pieces (const char *uri, + const char *name, + const char *modifier, + const char *embedded_text) { GHashTable *hash_table; NautilusScalableIcon icon_key, *icon; @@ -863,8 +890,8 @@ nautilus_icon_factory_get_icon_for_file (NautilusFile *file, const char* modifie /* Create the icon or find it in the cache if it's already there. */ - scalable_icon = nautilus_scalable_icon_get (uri, icon_name, modifier, - top_left_text); + scalable_icon = nautilus_scalable_icon_new_from_text_pieces + (uri, icon_name, modifier, top_left_text); g_free (uri); g_free (icon_name); g_free (top_left_text); @@ -879,7 +906,8 @@ nautilus_icon_factory_get_emblem_icon_by_name (const char *emblem_name) char *name_with_prefix; name_with_prefix = g_strconcat (EMBLEM_NAME_PREFIX, emblem_name, NULL); - scalable_icon = nautilus_scalable_icon_get (NULL, name_with_prefix, NULL, NULL); + scalable_icon = nautilus_scalable_icon_new_from_text_pieces + (NULL, name_with_prefix, NULL, NULL); g_free (name_with_prefix); return scalable_icon; @@ -1910,7 +1938,7 @@ load_image_with_embedded_text (NautilusScalableIcon *scalable_icon, g_assert (scalable_icon->embedded_text != NULL); - scalable_icon_without_text = nautilus_scalable_icon_get + scalable_icon_without_text = nautilus_scalable_icon_new_from_text_pieces (scalable_icon->uri, scalable_icon->name, scalable_icon->modifier, diff --git a/libnautilus-private/nautilus-icon-factory.h b/libnautilus-private/nautilus-icon-factory.h index 8a9adaf96..002c7c02b 100644 --- a/libnautilus-private/nautilus-icon-factory.h +++ b/libnautilus-private/nautilus-icon-factory.h @@ -139,10 +139,22 @@ void nautilus_icon_factory_get_pixmap_and_mask_by_name (Nautil void nautilus_scalable_icon_ref (NautilusScalableIcon *scalable_icon); void nautilus_scalable_icon_unref (NautilusScalableIcon *scalable_icon); -/* The name of a scalable icon is suitable for storage in metadata. - * This is a quick way to record the result of getting an icon by name. +/* A scalable icon can be decomposed into text and reconstituted later + * using nautilus_scalable_icon_new_from_text_pieces. This is the way + * to store scalable icons in metadata or other files. */ -char * nautilus_scalable_icon_get_name (NautilusScalableIcon *scalable_icon); +void nautilus_scalable_icon_get_text_pieces (NautilusScalableIcon *scalable_icon, + char **uri_return, + char **name_return, + char **modifier_return, + char **embedded_text_return); +/* Get a scalable icon using the earlier results of + * nautilus_scalable_icon_get_text_pieces. + */ +NautilusScalableIcon *nautilus_scalable_icon_new_from_text_pieces (const char *uri, + const char *name, + const char *modifier, + const char *embedded_text); /* Convenience function for freeing a list of scalable icons. * Unrefs all the icons before freeing the list. |