diff options
author | Alexander Larsson <alexl@redhat.com> | 2004-03-31 09:24:55 +0000 |
---|---|---|
committer | Alexander Larsson <alexl@src.gnome.org> | 2004-03-31 09:24:55 +0000 |
commit | b3175310b94f6bff55c7946997935b91c9cc93f2 (patch) | |
tree | cc0831b4ce37a2ac39249a275e3e94ad8b91cab9 | |
parent | 0ff09bc6fda79f3d6973d44763ade79e948f70d5 (diff) | |
download | nautilus-b3175310b94f6bff55c7946997935b91c9cc93f2.tar.gz |
Based on patch from Soeren Sandmann:
2004-03-31 Alexander Larsson <alexl@redhat.com>
Based on patch from Soeren Sandmann:
* libnautilus-private/nautilus-file.c: (get_description):
Only warn once per mimetype with no description.
* libnautilus-private/nautilus-icon-factory.[ch]:
Add force_size option to force the nominal size.
* src/file-manager/fm-list-model.c:
* src/file-manager/fm-tree-model.c:
Use force_size to avoid constantly scaling things.
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | libnautilus-private/nautilus-file.c | 19 | ||||
-rw-r--r-- | libnautilus-private/nautilus-icon-factory.c | 126 | ||||
-rw-r--r-- | libnautilus-private/nautilus-icon-factory.h | 41 | ||||
-rw-r--r-- | src/file-manager/fm-list-model.c | 26 | ||||
-rw-r--r-- | src/file-manager/fm-tree-model.c | 2 |
6 files changed, 162 insertions, 66 deletions
@@ -1,3 +1,17 @@ +2004-03-31 Alexander Larsson <alexl@redhat.com> + + Based on patch from Soeren Sandmann: + + * libnautilus-private/nautilus-file.c: (get_description): + Only warn once per mimetype with no description. + + * libnautilus-private/nautilus-icon-factory.[ch]: + Add force_size option to force the nominal size. + + * src/file-manager/fm-list-model.c: + * src/file-manager/fm-tree-model.c: + Use force_size to avoid constantly scaling things. + 2004-03-31 Christian Rose <menthos@menthos.com> * configure.in: Added "af" to ALL_LINGUAS. diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c index 2e2c4065f..0e35a68d1 100644 --- a/libnautilus-private/nautilus-file.c +++ b/libnautilus-private/nautilus-file.c @@ -4701,10 +4701,21 @@ get_description (NautilusFile *file) "probably means that your gnome-vfs.keys file is in the wrong place " "or isn't being found for some other reason.")); } else { - g_warning (_("No description found for mime type \"%s\" (file is \"%s\"), " - "please tell the gnome-vfs mailing list."), - mime_type, - file->details->relative_uri); + static GHashTable *warned = NULL; + + if (warned == NULL) { + warned = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + eel_debug_call_at_shutdown_with_data ((GFreeFunc)g_hash_table_destroy, warned); + } + + if (!g_hash_table_lookup (warned, mime_type)) { + g_warning (_("No description found for mime type \"%s\" (file is \"%s\"), " + "please tell the gnome-vfs mailing list."), + mime_type, + file->details->relative_uri); + + g_hash_table_insert (warned, g_strdup (mime_type), GINT_TO_POINTER (1)); + } } return mime_type; } diff --git a/libnautilus-private/nautilus-icon-factory.c b/libnautilus-private/nautilus-icon-factory.c index b895d6e5b..94aaffd16 100644 --- a/libnautilus-private/nautilus-icon-factory.c +++ b/libnautilus-private/nautilus-icon-factory.c @@ -99,6 +99,7 @@ typedef struct { char *name; /* Icon name or absolute filename */ char *modifier; guint nominal_size; + gboolean force_nominal; } CacheKey; /* The value in the same table. */ @@ -186,7 +187,8 @@ static CacheIcon *cache_icon_new (GdkPixbuf double scale_y); static CacheIcon *get_icon_from_cache (const char *icon, const char *modifier, - guint nominal_size); + guint nominal_size, + gboolean force_nominal); static void nautilus_icon_factory_clear (void); GNOME_CLASS_BOILERPLATE (NautilusIconFactory, @@ -1084,6 +1086,7 @@ static GdkPixbuf * load_icon_file (const char *filename, guint base_size, guint nominal_size, + gboolean force_nominal, double *scale_x, double *scale_y) { @@ -1115,7 +1118,15 @@ load_icon_file (const char *filename, return NULL; } - if (base_size == 0) { + if (force_nominal) { + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); + size = MAX (width, height); + + if (size > base_size) { + base_size = size; + } + } else if (base_size == 0) { if (is_thumbnail) { base_size = 128 * NAUTILUS_ICON_SIZE_STANDARD / NAUTILUS_ICON_SIZE_THUMBNAIL; } else { @@ -1147,7 +1158,8 @@ load_icon_file (const char *filename, static CacheIcon * create_normal_cache_icon (const char *icon, const char *modifier, - guint nominal_size) + guint nominal_size, + gboolean force_nominal) { NautilusIconFactory *factory; const char *filename; @@ -1208,6 +1220,7 @@ create_normal_cache_icon (const char *icon, pixbuf = load_icon_file (filename, base_size, nominal_size, + force_nominal, &scale_x, &scale_y); if (pixbuf == NULL) { if (info) { @@ -1232,11 +1245,14 @@ create_normal_cache_icon (const char *icon, * If @picky is true, then only an unscaled icon is acceptable. * Also, if @picky is true, the icon must be a custom icon if * @custom is true or a standard icon is @custom is false. + * If @force_nominal is #TRUE, the returned icon will be guaranteed + * to be smaller than the nominal size */ static CacheIcon * get_icon_from_cache (const char *icon, const char *modifier, - guint nominal_size) + guint nominal_size, + gboolean force_nominal) { NautilusIconFactory *factory; GHashTable *hash_table; @@ -1258,6 +1274,7 @@ get_icon_from_cache (const char *icon, lookup_key.name = (char *)icon; lookup_key.modifier = (char *)modifier; lookup_key.nominal_size = nominal_size; + lookup_key.force_nominal = force_nominal; if (g_hash_table_lookup_extended (hash_table, &lookup_key, &key_in_table, &value)) { @@ -1288,12 +1305,14 @@ get_icon_from_cache (const char *icon, cached_icon = create_normal_cache_icon (icon, modifier, - nominal_size); + nominal_size, + force_nominal); /* Try to fallback without modifier */ if (cached_icon == NULL && modifier != NULL) { cached_icon = create_normal_cache_icon (icon, NULL, - nominal_size); + nominal_size, + force_nominal); } if (cached_icon == NULL) { @@ -1306,6 +1325,7 @@ get_icon_from_cache (const char *icon, key->name = g_strdup (icon); key->modifier = g_strdup (modifier); key->nominal_size = nominal_size; + key->force_nominal = force_nominal; g_hash_table_insert (hash_table, key, cached_icon); } @@ -1322,14 +1342,15 @@ get_icon_from_cache (const char *icon, return cached_icon; } -GdkPixbuf * -nautilus_icon_factory_get_pixbuf_for_icon (const char *icon, - const char *modifier, - guint nominal_size, - NautilusEmblemAttachPoints *attach_points, - GdkRectangle *embedded_text_rect, - gboolean wants_default, - char **display_name) +static GdkPixbuf * +nautilus_icon_factory_get_pixbuf_for_icon_internal (const char *icon, + const char *modifier, + guint nominal_size, + gboolean force_size, + NautilusEmblemAttachPoints *attach_points, + GdkRectangle *embedded_text_rect, + gboolean wants_default, + char **display_name) { NautilusIconFactory *factory; CacheIcon *cached_icon; @@ -1339,7 +1360,8 @@ nautilus_icon_factory_get_pixbuf_for_icon (const char *icon, factory = get_icon_factory (); cached_icon = get_icon_from_cache (icon, modifier, - nominal_size); + nominal_size, + force_size); if (attach_points != NULL) { if (cached_icon->attach_points != NULL) { @@ -1381,6 +1403,35 @@ nautilus_icon_factory_get_pixbuf_for_icon (const char *icon, return pixbuf; } +GdkPixbuf * +nautilus_icon_factory_get_pixbuf_for_icon (const char *icon, + const char *modifier, + guint nominal_size, + NautilusEmblemAttachPoints *attach_points, + GdkRectangle *embedded_text_rect, + gboolean wants_default, + char **display_name) +{ + return nautilus_icon_factory_get_pixbuf_for_icon_internal (icon, modifier, nominal_size, FALSE, + attach_points, embedded_text_rect, + wants_default, display_name); +} + +GdkPixbuf * +nautilus_icon_factory_get_pixbuf_for_icon_force_size (const char *icon, + const char *modifier, + guint nominal_size, + NautilusEmblemAttachPoints *attach_points, + GdkRectangle *embedded_text_rect, + gboolean wants_default, + char **display_name) +{ + return nautilus_icon_factory_get_pixbuf_for_icon_internal (icon, modifier, nominal_size, TRUE, + attach_points, embedded_text_rect, + wants_default, display_name); +} + + static guint cache_key_hash (gconstpointer p) { @@ -1390,12 +1441,12 @@ cache_key_hash (gconstpointer p) key = p; hash = g_str_hash (key->name) ^ - (key->nominal_size << 4); + ((key->nominal_size << 4) + (gint)key->force_nominal); if (key->modifier) { hash ^= g_str_hash (key->modifier); } - + return hash; } @@ -1409,6 +1460,7 @@ cache_key_equal (gconstpointer a, gconstpointer b) return eel_strcmp (key_a->name, key_b->name) == 0 && key_a->nominal_size == key_b->nominal_size && + key_a->force_nominal == key_b->force_nominal && eel_strcmp (key_a->modifier, key_b->modifier) == 0; } @@ -1443,10 +1495,11 @@ nautilus_get_icon_size_for_zoom_level (NautilusZoomLevel zoom_level) /* Convenience cover for nautilus_icon_factory_get_icon_for_file * and nautilus_icon_factory_get_pixbuf_for_icon. */ -GdkPixbuf * -nautilus_icon_factory_get_pixbuf_for_file (NautilusFile *file, - const char *modifier, - guint size_in_pixels) +static GdkPixbuf * +nautilus_icon_factory_get_pixbuf_for_file_internal (NautilusFile *file, + const char *modifier, + guint size_in_pixels, + gboolean force_size) { char *icon; GdkPixbuf *pixbuf; @@ -1458,16 +1511,39 @@ nautilus_icon_factory_get_pixbuf_for_file (NautilusFile *file, return NULL; } - pixbuf = nautilus_icon_factory_get_pixbuf_for_icon (icon, modifier, - size_in_pixels, - NULL, NULL, - TRUE, NULL); + pixbuf = nautilus_icon_factory_get_pixbuf_for_icon_internal (icon, modifier, + size_in_pixels, + force_size, + NULL, NULL, + TRUE, NULL); g_free (icon); return pixbuf; } +GdkPixbuf * +nautilus_icon_factory_get_pixbuf_for_file (NautilusFile *file, + const char *modifier, + guint size_in_pixels) +{ + return nautilus_icon_factory_get_pixbuf_for_file_internal (file, + modifier, + size_in_pixels, + FALSE); +} + +GdkPixbuf * +nautilus_icon_factory_get_pixbuf_for_file_force_size (NautilusFile *file, + const char *modifier, + guint size_in_pixels) +{ + return nautilus_icon_factory_get_pixbuf_for_file_internal (file, + modifier, + size_in_pixels, + TRUE); +} + /* Convenience routine for getting a pixbuf from an icon name. */ GdkPixbuf * nautilus_icon_factory_get_pixbuf_from_name (const char *icon_name, diff --git a/libnautilus-private/nautilus-icon-factory.h b/libnautilus-private/nautilus-icon-factory.h index c7cfe9a8a..1b1a055c7 100644 --- a/libnautilus-private/nautilus-icon-factory.h +++ b/libnautilus-private/nautilus-icon-factory.h @@ -124,20 +124,30 @@ char * nautilus_icon_factory_get_emblem_icon_by_name (const * If the wants_default boolean is set, return a default icon instead * of NULL if we can't find anything */ -GdkPixbuf * nautilus_icon_factory_get_pixbuf_for_icon (const char *icon, - const char *modifier, - guint nominal_size, - NautilusEmblemAttachPoints *attach_points, - GdkRectangle *embedded_text_rect, - gboolean wants_default, - char **display_name); +GdkPixbuf *nautilus_icon_factory_get_pixbuf_for_icon (const char *icon, + const char *modifier, + guint nominal_size, + NautilusEmblemAttachPoints *attach_points, + GdkRectangle *embedded_text_rect, + gboolean wants_default, + char **display_name); +GdkPixbuf *nautilus_icon_factory_get_pixbuf_for_icon_force_size (const char *icon, + const char *modifier, + guint nominal_size, + NautilusEmblemAttachPoints *attach_points, + GdkRectangle *embedded_text_rect, + gboolean wants_default, + char **display_name); /* Convenience functions for the common case where you want to choose * and render the icon into a pixbuf all at once. */ -GdkPixbuf * nautilus_icon_factory_get_pixbuf_for_file (NautilusFile *file, - const char *modifer, - guint size_in_pixels); +GdkPixbuf *nautilus_icon_factory_get_pixbuf_for_file (NautilusFile *file, + const char *modifer, + guint size_in_pixels); +GdkPixbuf *nautilus_icon_factory_get_pixbuf_for_file_force_size (NautilusFile *file, + const char *modifier, + guint size_in_pixels); /* Convenience routine for getting a pixbuf from an icon name */ @@ -146,11 +156,12 @@ GdkPixbuf * nautilus_icon_factory_get_pixbuf_from_name (const guint size_in_pixels, char **display_name); -GtkIconTheme * nautilus_icon_factory_get_icon_theme (void); -GnomeThumbnailFactory *nautilus_icon_factory_get_thumbnail_factory (void); -gboolean nautilus_icon_factory_remove_from_cache (const char *icon_name, - const char *modifier, - guint size); +GtkIconTheme * nautilus_icon_factory_get_icon_theme (void); +GnomeThumbnailFactory *nautilus_icon_factory_get_thumbnail_factory (void); +gboolean nautilus_icon_factory_remove_from_cache (const char *icon_name, + const char *modifier, + guint size); + #endif /* NAUTILUS_ICON_FACTORY_H */ diff --git a/src/file-manager/fm-list-model.c b/src/file-manager/fm-list-model.c index 73c89d743..5bb362e4d 100644 --- a/src/file-manager/fm-list-model.c +++ b/src/file-manager/fm-list-model.c @@ -172,10 +172,9 @@ fm_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column FMListModel *model; NautilusFile *file; char *str; - GdkPixbuf *icon, *tmp; + GdkPixbuf *icon; int icon_size; NautilusZoomLevel zoom_level; - int width, height; char *modifier; GList *emblem_icons; NautilusFile *parent_file; @@ -229,16 +228,8 @@ fm_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column modifier = "visiting"; } - icon = nautilus_icon_factory_get_pixbuf_for_file (file, modifier, icon_size); + icon = nautilus_icon_factory_get_pixbuf_for_file_force_size (file, modifier, icon_size); - height = gdk_pixbuf_get_height (icon); - if (height > icon_size) { - width = gdk_pixbuf_get_width (icon) * icon_size / height; - height = icon_size; - tmp = gdk_pixbuf_scale_simple (icon, width, height, GDK_INTERP_BILINEAR); - g_object_unref (icon); - icon = tmp; - } g_value_set_object (value, icon); g_object_unref (icon); break; @@ -265,18 +256,11 @@ fm_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column if (emblem_icons != NULL) { zoom_level = fm_list_model_get_zoom_level_from_emblem_column_id (column); icon_size = nautilus_get_icon_size_for_zoom_level (zoom_level); - icon = nautilus_icon_factory_get_pixbuf_for_icon (emblem_icons->data, NULL, icon_size, - NULL, NULL, FALSE, NULL); + icon = nautilus_icon_factory_get_pixbuf_for_icon_force_size ( + emblem_icons->data, NULL, icon_size, + NULL, NULL, FALSE, NULL); eel_g_list_free_deep (emblem_icons); - height = gdk_pixbuf_get_height (icon); - if (height > icon_size) { - width = gdk_pixbuf_get_width (icon) * icon_size / height; - height = icon_size; - tmp = gdk_pixbuf_scale_simple (icon, width, height, GDK_INTERP_BILINEAR); - g_object_unref (icon); - icon = tmp; - } g_value_set_object (value, icon); g_object_unref (icon); } diff --git a/src/file-manager/fm-tree-model.c b/src/file-manager/fm-tree-model.c index b3615d915..12e369f76 100644 --- a/src/file-manager/fm-tree-model.c +++ b/src/file-manager/fm-tree-model.c @@ -249,7 +249,7 @@ tree_node_get_pixbuf_from_factory (TreeNode *node, (node->icon_name, NULL, NAUTILUS_ICON_SIZE_FOR_MENUS, NULL); } - return nautilus_icon_factory_get_pixbuf_for_file + return nautilus_icon_factory_get_pixbuf_for_file_force_size (node->file, modifier, NAUTILUS_ICON_SIZE_FOR_MENUS); } |