Commit 39b26449 authored by Darin Adler's avatar Darin Adler

Changed the icon factory interface in a few ways: 1) There's no longer a

	* libnautilus/nautilus-icon-factory.h:
	* libnautilus/nautilus-icon-factory.c:
	(nautilus_icon_factory_new):
	(nautilus_icon_factory_destroy):
	(nautilus_get_current_icon_factory):
	(nautilus_icon_factory_get_icon_for_file):
	(nautilus_icon_factory_set_theme):
	(nautilus_icon_factory_get_icon_by_name):
	(nautilus_icon_factory_get_pixbuf_for_icon):
	(nautilus_scalable_icon_ref):
	(nautilus_scalable_icon_unref):
	(nautilus_scalable_icon_get_name):
	(scalable_icon_get):
	(icon_set_possibly_free):
	(scalable_icon_new):
	Changed the icon factory interface in a few ways: 1) There's no
	longer a NautilusIconFactory object. There's just a single global
	icon factory. If we find that we need multiple factories, we can
	implement that later. 2) Instead of going straight from a file to
	a pixbuf, you get a scalable icon, and then get a pixbuf from
	that. This allows you to choose the icon and then get
	different-sized versions of it without going through the icon
	selection process over and over again. There's also a name for
	each icon which can be stored in the metafile so you can get the
	same icon again before you have full information on a file.

	* src/nautilus-bookmark.c:
	(nautilus_bookmark_get_pixmap_and_mask):
	* src/file-manager/fm-directory-view-list.c:
	(install_icon):
	* src/file-manager/fm-icons-controller.c:
	(fm_icons_controller_get_icon_image):
	Changed icon factory clients to use the new interface. Maybe
	after a while I'll add a convenience function that's as simple as
	the old interface was for the common case where you want to go
	straight to the pixbuf, but lets try it this way for a while.

	* libnautilus/nautilus-string.h:
	* libnautilus/nautilus-string.c:
	(nautilus_has_prefix):
	Added nautilus_has_prefix. This checks to see if a string has a
	particular prefix. It's both clearer to read and more efficient
	than Andy's typical trick of calling strstr.

	* libnautilus/nautilus-lib-self-check-functions.h:
	* libnautilus/nautilus-string.c:
	Added self-checks for nautilus-string.c. The tests uncovered a
	bug in nautilus_string_to_int that I fixed.

	* nautilus-glib-extensions.c:
	Just a stray new-line.
parent 9bef26f2
2000-02-01 Darin Adler <darin@eazel.com>
* libnautilus/nautilus-icon-factory.h:
* libnautilus/nautilus-icon-factory.c:
(nautilus_icon_factory_new):
(nautilus_icon_factory_destroy):
(nautilus_get_current_icon_factory):
(nautilus_icon_factory_get_icon_for_file):
(nautilus_icon_factory_set_theme):
(nautilus_icon_factory_get_icon_by_name):
(nautilus_icon_factory_get_pixbuf_for_icon):
(nautilus_scalable_icon_ref):
(nautilus_scalable_icon_unref):
(nautilus_scalable_icon_get_name):
(scalable_icon_get):
(icon_set_possibly_free):
(scalable_icon_new):
Changed the icon factory interface in a few ways: 1) There's no
longer a NautilusIconFactory object. There's just a single global
icon factory. If we find that we need multiple factories, we can
implement that later. 2) Instead of going straight from a file to
a pixbuf, you get a scalable icon, and then get a pixbuf from
that. This allows you to choose the icon and then get
different-sized versions of it without going through the icon
selection process over and over again. There's also a name for
each icon which can be stored in the metafile so you can get the
same icon again before you have full information on a file.
* src/nautilus-bookmark.c:
(nautilus_bookmark_get_pixmap_and_mask):
* src/file-manager/fm-directory-view-list.c:
(install_icon):
* src/file-manager/fm-icons-controller.c:
(fm_icons_controller_get_icon_image):
Changed icon factory clients to use the new interface. Maybe
after a while I'll add a convenience function that's as simple as
the old interface was for the common case where you want to go
straight to the pixbuf, but lets try it this way for a while.
* libnautilus/nautilus-string.h:
* libnautilus/nautilus-string.c:
(nautilus_has_prefix):
Added nautilus_has_prefix. This checks to see if a string has a
particular prefix. It's both clearer to read and more efficient
than Andy's typical trick of calling strstr.
* libnautilus/nautilus-lib-self-check-functions.h:
* libnautilus/nautilus-string.c:
Added self-checks for nautilus-string.c. The tests uncovered a
bug in nautilus_string_to_int that I fixed.
* nautilus-glib-extensions.c:
Just a stray new-line.
2000-02-01 John Sullivan <sullivan@eazel.com>
Fixed bug where selection info didn't appear in the status bar when
......
......@@ -108,4 +108,3 @@ nautilus_self_check_glib_extensions (void)
}
#endif /* !NAUTILUS_OMIT_SELF_CHECK */
......@@ -33,6 +33,7 @@
#include <libgnome/gnome-mime-info.h>
#include <libgnome/gnome-util.h>
#include "nautilus-string.h"
#include "nautilus-default-file-icon.h"
#define ICON_CACHE_MAX_ENTRIES 10
......@@ -42,6 +43,7 @@
static guint use_counter = 0;
typedef struct {
guint ref_count;
char *name;
GdkPixbuf *plain, *symlink;
guint last_use;
......@@ -62,7 +64,7 @@ typedef enum {
ICON_SET_SPECIAL_LAST
} SpecialIconSetType;
struct _NautilusIconFactory {
typedef struct {
char *theme_name;
GHashTable *name_to_image;
......@@ -71,13 +73,24 @@ struct _NautilusIconFactory {
GdkPixbuf *symlink_overlay;
guint sweep_timer;
} NautilusIconFactory;
struct _NautilusScalableIcon {
guint ref_count;
char *uri;
IconSet *icon_set;
gboolean is_symbolic_link;
};
/* forward declarations */
static GdkPixbuf *nautilus_icon_factory_scale (NautilusIconFactory *factory,
GdkPixbuf *standard_sized_pixbuf,
guint size_in_pixels);
static NautilusIconFactory * nautilus_get_current_icon_factory (void);
static GdkPixbuf * nautilus_icon_factory_scale (NautilusIconFactory *factory,
GdkPixbuf *standard_sized_pixbuf,
guint size_in_pixels);
static NautilusScalableIcon *scalable_icon_get (const char *uri,
IconSet *icon_set,
gboolean is_symbolic_link);
static IconSet *
icon_set_new (const gchar *name)
......@@ -93,18 +106,19 @@ icon_set_new (const gchar *name)
static void
icon_set_destroy (IconSet *icon_set, gboolean free_name)
{
if (icon_set != NULL) {
if (free_name)
g_free (icon_set->name);
if (icon_set->plain)
gdk_pixbuf_unref (icon_set->plain);
if (icon_set->symlink)
gdk_pixbuf_unref (icon_set->symlink);
}
if (icon_set == NULL)
return;
if (free_name)
g_free (icon_set->name);
if (icon_set->plain != NULL)
gdk_pixbuf_unref (icon_set->plain);
if (icon_set->symlink != NULL)
gdk_pixbuf_unref (icon_set->symlink);
}
NautilusIconFactory *
nautilus_icon_factory_new(const char *theme_name)
static NautilusIconFactory *
nautilus_icon_factory_new (const char *theme_name)
{
NautilusIconFactory *factory;
......@@ -128,9 +142,9 @@ nautilus_icon_factory_new(const char *theme_name)
}
static gboolean
nautilus_icon_factory_destroy_icon_sets(gpointer key, gpointer value, gpointer user_data)
nautilus_icon_factory_destroy_icon_sets (gpointer key, gpointer value, gpointer user_data)
{
icon_set_destroy(value, TRUE);
icon_set_destroy (value, TRUE);
return TRUE;
}
......@@ -152,7 +166,9 @@ nautilus_icon_factory_invalidate (NautilusIconFactory *factory)
}
}
void
#if 0
static void
nautilus_icon_factory_destroy (NautilusIconFactory *factory)
{
nautilus_icon_factory_invalidate (factory);
......@@ -162,12 +178,14 @@ nautilus_icon_factory_destroy (NautilusIconFactory *factory)
g_free (factory);
}
#endif
static gboolean
icon_set_possibly_free (gpointer key, gpointer value, gpointer user_data)
{
IconSet *is = value;
if(is->last_use > (use_counter - ICON_CACHE_MAX_ENTRIES))
if (is->last_use > (use_counter - ICON_CACHE_MAX_ENTRIES))
return FALSE;
if (is->plain && is->plain->ref_count <= 1) {
......@@ -180,7 +198,7 @@ icon_set_possibly_free (gpointer key, gpointer value, gpointer user_data)
is->symlink = NULL;
}
if (!is->symlink && !is->plain) {
if (is->symlink == NULL && is->plain == NULL && is->ref_count == 0) {
g_free (is->name);
return TRUE;
}
......@@ -191,10 +209,11 @@ icon_set_possibly_free (gpointer key, gpointer value, gpointer user_data)
static gboolean
nautilus_icon_factory_sweep(gpointer data)
{
NautilusIconFactory *factory = data;
NautilusIconFactory *factory;
g_hash_table_foreach_remove(factory->name_to_image, icon_set_possibly_free, NULL);
factory = data;
g_hash_table_foreach_remove (factory->name_to_image, icon_set_possibly_free, NULL);
factory->sweep_timer = 0;
return FALSE;
......@@ -203,22 +222,25 @@ nautilus_icon_factory_sweep(gpointer data)
static void
nautilus_icon_factory_setup_sweep(NautilusIconFactory *factory)
{
if(factory->sweep_timer)
if (factory->sweep_timer)
return;
if(g_hash_table_size(factory->name_to_image) < ICON_CACHE_MAX_ENTRIES)
if (g_hash_table_size (factory->name_to_image) < ICON_CACHE_MAX_ENTRIES)
return;
factory->sweep_timer = g_timeout_add(ICON_CACHE_SWEEP_TIMEOUT * 1000,
nautilus_icon_factory_sweep, factory);
factory->sweep_timer = g_timeout_add (ICON_CACHE_SWEEP_TIMEOUT * 1000,
nautilus_icon_factory_sweep, factory);
}
void
nautilus_icon_factory_set_theme(NautilusIconFactory *factory, const char *theme_name)
nautilus_icon_factory_set_theme(const char *theme_name)
{
nautilus_icon_factory_invalidate(factory);
g_free(factory->theme_name);
factory->theme_name = g_strdup(theme_name);
NautilusIconFactory *factory;
factory = nautilus_get_current_icon_factory ();
nautilus_icon_factory_invalidate (factory);
g_free (factory->theme_name);
factory->theme_name = g_strdup (theme_name);
}
static IconSet *
......@@ -333,19 +355,63 @@ nautilus_icon_factory_load_icon(NautilusIconFactory *factory, IconSet *is, gbool
return image;
}
GdkPixbuf *
nautilus_icon_factory_get_icon_for_file (NautilusIconFactory *factory,
NautilusFile *file,
guint size_in_pixels)
static NautilusScalableIcon *
scalable_icon_new (const char *uri,
IconSet *icon_set,
gboolean is_symbolic_link)
{
IconSet *set;
const gchar *file_type;
gboolean is_symbolic_link;
GdkPixbuf *image;
NautilusScalableIcon *icon;
g_return_val_if_fail (icon_set != NULL, NULL);
icon = g_new (NautilusScalableIcon, 1);
icon->ref_count = 1;
icon->uri = g_strdup (uri);
icon->icon_set = icon_set;
icon->is_symbolic_link = is_symbolic_link;
icon_set->ref_count++;
g_return_val_if_fail (factory, NULL);
g_return_val_if_fail (file, NULL);
return icon;
}
static NautilusScalableIcon *
scalable_icon_get (const char *uri,
IconSet *icon_set,
gboolean is_symbolic_link)
{
/* FIXME: These should come from a hash table. */
return scalable_icon_new (uri, icon_set, is_symbolic_link);
}
void
nautilus_scalable_icon_unref (NautilusScalableIcon *icon)
{
g_return_if_fail (icon->ref_count != 0);
if (--icon->ref_count != 0)
return;
g_free (icon->uri);
g_assert (icon->icon_set->ref_count != 0);
icon->icon_set->ref_count--;
g_free (icon);
}
NautilusScalableIcon *
nautilus_icon_factory_get_icon_for_file (NautilusFile *file)
{
NautilusIconFactory *factory;
IconSet *set;
char *uri;
gboolean is_symbolic_link;
NautilusScalableIcon *scalable_icon;
factory = nautilus_get_current_icon_factory ();
/* Get an icon set based on the file's type. */
switch (nautilus_file_get_type (file)) {
case GNOME_VFS_FILE_TYPE_UNKNOWN:
case GNOME_VFS_FILE_TYPE_REGULAR:
......@@ -371,45 +437,80 @@ nautilus_icon_factory_get_icon_for_file (NautilusIconFactory *factory,
set = &factory->special_icon_sets[ICON_SET_BROKEN_SYMBOLIC_LINK];
break;
}
/* Also record whether it's a symbolic link or not.
* Later, we'll probably use a separate icon badge for this,
* but for now, we'll keep it.
*/
is_symbolic_link = nautilus_file_is_symbolic_link (file);
/* Use the image itself as a custom icon. */
if (nautilus_has_prefix (nautilus_file_get_mime_type (file), "image/")
&& nautilus_file_get_size (file) < 10000)
uri = nautilus_file_get_uri (file);
else
uri = NULL;
/* Create the icon or find it in the cache if it's already there. */
scalable_icon = scalable_icon_get (uri, set, is_symbolic_link);
g_free (uri);
nautilus_icon_factory_setup_sweep (factory);
return scalable_icon;
}
GdkPixbuf *
nautilus_icon_factory_get_pixbuf_for_icon (NautilusScalableIcon *scalable_icon,
guint size_in_pixels)
{
NautilusIconFactory *factory;
IconSet *set;
GdkPixbuf *image;
file_type = nautilus_file_get_mime_type(file);
if (file_type && (strstr(file_type, "image/") == file_type) && (nautilus_file_get_size(file) < 10000))
{
gchar *path = nautilus_file_get_uri(file);
image = gdk_pixbuf_new_from_file (path + 7);
g_free(path);
}
else
{
set->last_use = use_counter++;
image = nautilus_icon_factory_load_icon (factory, set, is_symbolic_link);
}
factory = nautilus_get_current_icon_factory ();
/* FIXME: This works only with file:// images, because there's
* no convenience function for loading an image with gnome-vfs
* and gdk-pixbuf.
*/
image = NULL;
if (nautilus_has_prefix (scalable_icon->uri, "file://"))
image = gdk_pixbuf_new_from_file (scalable_icon->uri + 7);
/* If there was no suitable custom icon URI, then use the icon set. */
if (image == NULL) {
set = scalable_icon->icon_set;
set->last_use = use_counter++;
image = nautilus_icon_factory_load_icon
(factory, set, scalable_icon->is_symbolic_link);
}
/* If the icon set failed, then use the fallback set. */
if (image == NULL) {
g_warning ("failed to load icon, using fallback icon set");
set = &factory->special_icon_sets[ICON_SET_FALLBACK];
set->last_use = use_counter++;
image = nautilus_icon_factory_load_icon (factory, set, is_symbolic_link);
image = nautilus_icon_factory_load_icon
(factory, set, scalable_icon->is_symbolic_link);
}
g_assert (image != NULL);
/* First cut at handling multiple sizes. If size is other than standard,
* scale the pixbuf here. Eventually we'll store icons at multiple sizes
* rather than relying on scaling in every case (though we'll still need
* scaling as a fallback). The scaled pixbufs also might want to be cached.
* scaling as a fallback). We'll also cache the scaled pixbufs.
* For now, assume that the icon found so far is of standard size.
*/
if (size_in_pixels != NAUTILUS_ICON_SIZE_STANDARD)
{
GdkPixbuf *non_standard_size_icon;
GdkPixbuf *scaled_icon;
non_standard_size_icon = nautilus_icon_factory_scale (factory,
image,
size_in_pixels);
scaled_icon = nautilus_icon_factory_scale
(factory, image, size_in_pixels);
gdk_pixbuf_unref (image);
image = non_standard_size_icon;
image = scaled_icon;
}
nautilus_icon_factory_setup_sweep (factory);
......
......@@ -24,7 +24,7 @@
*/
#ifndef NAUTILUS_ICON_FACTORY_H
#define NAUTILUS_ICON_FACTORY_H 1
#define NAUTILUS_ICON_FACTORY_H
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <libnautilus/nautilus-directory.h>
......@@ -67,20 +67,35 @@ typedef enum {
#define NAUTILUS_ICON_SIZE_LARGER 96
#define NAUTILUS_ICON_SIZE_LARGEST 192
typedef struct _NautilusIconFactory NautilusIconFactory;
typedef struct _NautilusScalableIcon NautilusScalableIcon;
NautilusIconFactory *nautilus_icon_factory_new (const char *theme_name);
void nautilus_icon_factory_destroy (NautilusIconFactory *factory);
void nautilus_icon_factory_set_theme (NautilusIconFactory *factory,
const char *theme_name);
NautilusIconFactory *nautilus_get_current_icon_factory (void);
/* Relationship between zoom levels and icons sizes. */
guint nautilus_icon_size_for_zoom_level (NautilusZoomLevel zoom_level);
guint nautilus_icon_size_for_zoom_level (NautilusZoomLevel zoom_level);
/* Switch themes. */
void nautilus_icon_factory_set_theme (const char *theme_name);
/* Ownership of a ref. count in this pixbuf comes with the deal */
GdkPixbuf * nautilus_icon_factory_get_icon_for_file (NautilusIconFactory *factory,
NautilusFile *file,
guint size_in_pixels);
/* Choose the appropriate icon, but don't render it yet. */
NautilusScalableIcon *nautilus_icon_factory_get_icon_for_file (NautilusFile *file);
NautilusScalableIcon *nautilus_icon_factory_get_icon_by_name (const char *scalable_icon_name);
#endif /* NAUTILUS_ICON_FACTORY_H */
/* Render an icon to a particular size.
* Ownership of a ref. count in this pixbuf comes with the deal.
*/
GdkPixbuf * nautilus_icon_factory_get_pixbuf_for_icon (NautilusScalableIcon *scalable_icon,
guint size_in_pixels);
/* Manage a scalable icon.
* Since the factory always passes out references to the same scalable
* icon, you can compare two scalable icons to see if they are the same
* with ==.
*/
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.
*/
char * nautilus_scalable_icon_get_name (NautilusScalableIcon *scalable_icon);
#endif /* NAUTILUS_ICON_FACTORY_H */
......@@ -39,10 +39,11 @@ void nautilus_run_lib_self_checks (void);
*/
#define NAUTILUS_LIB_FOR_EACH_SELF_CHECK_FUNCTION(macro) \
macro(nautilus_self_check_background) \
macro(nautilus_self_check_directory) \
macro(nautilus_self_check_gdk_extensions) \
macro(nautilus_self_check_glib_extensions) \
macro (nautilus_self_check_background) \
macro (nautilus_self_check_directory) \
macro (nautilus_self_check_gdk_extensions) \
macro (nautilus_self_check_glib_extensions) \
macro (nautilus_self_check_string) \
/* Add new self-check functions to the list above this line. */
/* Generate prototypes for all the functions. */
......
......@@ -29,6 +29,8 @@
#include <errno.h>
#include <stdlib.h>
#include "nautilus-lib-self-check-functions.h"
size_t
nautilus_strlen (const char *string_null_allowed)
{
......@@ -58,6 +60,23 @@ nautilus_eat_strcmp (char *string_a, const char *string_b)
return result;
}
gboolean
nautilus_has_prefix (const char *haystack_null_allowed, const char *needle_null_allowed)
{
const char *h, *n;
/* Eat one character at a time. */
h = haystack_null_allowed == NULL ? "" : haystack_null_allowed;
n = needle_null_allowed == NULL ? "" : needle_null_allowed;
do {
if (*n == '\0')
return TRUE;
if (*h == '\0')
return FALSE;
} while (*h++ == *n++);
return FALSE;
}
gboolean
nautilus_string_to_int (const char *string, int *integer)
{
......@@ -69,6 +88,7 @@ nautilus_string_to_int (const char *string, int *integer)
return FALSE;
/* Call the standard library routine to do the conversion. */
errno = 0;
result = strtol (string, &parse_end, 0);
/* Check that the result is in range. */
......@@ -96,3 +116,109 @@ nautilus_eat_string_to_int (char *string, int *integer)
g_free (string);
return result;
}
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
static int
call_string_to_int (const char *string)
{
int integer;
integer = 9999;
nautilus_string_to_int (string, &integer);
return integer;
}
static int
call_eat_string_to_int (char *string)
{
int integer;
integer = 9999;
nautilus_eat_string_to_int (string, &integer);
return integer;
}
void
nautilus_self_check_string (void)
{
int integer;
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_strlen (NULL), 0);
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_strlen (""), 0);
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_strlen ("abc"), 3);
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_strcmp (NULL, NULL), 0);
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_strcmp (NULL, ""), 0);
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_strcmp ("", NULL), 0);
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_strcmp ("a", "a"), 0);
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_strcmp ("aaab", "aaab"), 0);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_strcmp (NULL, "a") < 0, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_strcmp ("a", NULL) > 0, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_strcmp ("", "a") < 0, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_strcmp ("a", "") > 0, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_strcmp ("a", "b") < 0, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_strcmp ("a", "ab") < 0, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_strcmp ("ab", "a") > 0, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_strcmp ("aaa", "aaab") < 0, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_strcmp ("aaab", "aaa") > 0, TRUE);
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_eat_strcmp (NULL, NULL), 0);
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_eat_strcmp (NULL, ""), 0);
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_eat_strcmp (g_strdup (""), NULL), 0);
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_eat_strcmp (g_strdup ("a"), "a"), 0);
NAUTILUS_CHECK_INTEGER_RESULT (nautilus_eat_strcmp (g_strdup ("aaab"), "aaab"), 0);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_eat_strcmp (NULL, "a") < 0, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_eat_strcmp (g_strdup ("a"), NULL) > 0, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_eat_strcmp (g_strdup (""), "a") < 0, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_eat_strcmp (g_strdup ("a"), "") > 0, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_eat_strcmp (g_strdup ("a"), "b") < 0, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_eat_strcmp (g_strdup ("a"), "ab") < 0, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_eat_strcmp (g_strdup ("ab"), "a") > 0, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_eat_strcmp (g_strdup ("aaa"), "aaab") < 0, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_eat_strcmp (g_strdup ("aaab"), "aaa") > 0, TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix (NULL, NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix (NULL, ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("a", "a"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("aaab", "aaab"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix (NULL, "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("a", NULL), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("", "a"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("a", ""), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("a", "b"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("a", "ab"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("ab", "a"), TRUE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("aaa", "aaab"), FALSE);
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_has_prefix ("aaab", "aaa"), TRUE);
#define TEST_INTEGER_CONVERSION_FUNCTIONS(string, boolean_result, integer_result) \
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_string_to_int (string, &integer), boolean_result); \
NAUTILUS_CHECK_INTEGER_RESULT (call_string_to_int (string), integer_result); \
NAUTILUS_CHECK_BOOLEAN_RESULT (nautilus_eat_string_to_int (g_strdup (string), &integer), boolean_result); \
NAUTILUS_CHECK_INTEGER_RESULT (call_eat_string_to_int (g_strdup (string)), integer_result);
TEST_INTEGER_CONVERSION_FUNCTIONS (NULL, FALSE, 9999)
TEST_INTEGER_CONVERSION_FUNCTIONS ("", FALSE, 9999)
TEST_INTEGER_CONVERSION_FUNCTIONS ("a", FALSE, 9999)
TEST_INTEGER_CONVERSION_FUNCTIONS (".", FALSE, 9999)
TEST_INTEGER_CONVERSION_FUNCTIONS ("0", TRUE, 0)
TEST_INTEGER_CONVERSION_FUNCTIONS ("1", TRUE, 1)
TEST_INTEGER_CONVERSION_FUNCTIONS ("+1", TRUE, 1)
TEST_INTEGER_CONVERSION_FUNCTIONS ("-1", TRUE, -1)
TEST_INTEGER_CONVERSION_FUNCTIONS ("2147483647", TRUE, 2147483647)
TEST_INTEGER_CONVERSION_FUNCTIONS ("2147483648", FALSE, 9999)
TEST_INTEGER_CONVERSION_FUNCTIONS ("+2147483647", TRUE, 2147483647)
TEST_INTEGER_CONVERSION_FUNCTIONS ("+2147483648", FALSE, 9999)
TEST_INTEGER_CONVERSION_FUNCTIONS ("-2147483648", TRUE, INT_MIN)
TEST_INTEGER_CONVERSION_FUNCTIONS ("-2147483649", FALSE, 9999)
TEST_INTEGER_CONVERSION_FUNCTIONS ("1a", FALSE, 9999)
TEST_INTEGER_CONVERSION_FUNCTIONS ("0.0", FALSE, 9999)
TEST_INTEGER_CONVERSION_FUNCTIONS ("1e1", FALSE, 9999)
TEST_INTEGER_CONVERSION_FUNCTIONS ("21474836470", FALSE, 9999)
TEST_INTEGER_CONVERSION_FUNCTIONS ("+21474836470", FALSE, 9999)
TEST_INTEGER_CONVERSION_FUNCTIONS ("-21474836480", FALSE, 9999)
}
#endif /* !NAUTILUS_OMIT_SELF_CHECK */
......@@ -39,6 +39,10 @@ int nautilus_strcmp (const char *string_a_null_allowed,
int nautilus_eat_strcmp (char *string_a_null_allowed_gets_freed,
const char *string_b_null_allowed);
/* Other basic string operations. */
gboolean nautilus_has_prefix (const char *target_null_allowed,
const char *prefix_null_allowed);
/* Conversions to and from strings. */
gboolean nautilus_string_to_int (const char *string,
int *integer);
......
......@@ -108,4 +108,3 @@ nautilus_self_check_glib_extensions (void)
}
#endif /* !NAUTILUS_OMIT_SELF_CHECK */
......@@ -33,6 +33,7 @@
#include <libgnome/gnome-mime-info.h>
#include <libgnome/gnome-util.h>
#include "nautilus-string.h"
#include "nautilus-default-file-icon.h"
#define ICON_CACHE_MAX_ENTRIES 10
......@@ -42,6 +43,7 @@
static guint use_counter = 0;
typedef struct {
guint ref_count;
char *name;
GdkPixbuf *plain, *symlink;
guint last_use;
......@@ -62,7 +64,7 @@ typedef enum {
ICON_SET_SPECIAL_LAST
} SpecialIconSetType;
struct _NautilusIconFactory {
typedef struct {
char *theme_name;
GHashTable *name_to_image;
......@@ -71,13 +73,24 @@ struct _NautilusIconFactory {
GdkPixbuf *symlink_overlay;
guint sweep_timer;
} NautilusIconFactory;
struct _NautilusScalableIcon {
guint ref_count;
char *uri;
IconSet *icon_set;
gboolean is_symbolic_link;
};
/* forward declarations */
static GdkPixbuf *nautilus_icon_factory_scale (NautilusIconFactory *factory,
GdkPixbuf *standard_sized_pixbuf,
guint size_in_pixels);
static NautilusIconFactory * nautilus_get_current_icon_factory (void);
static GdkPixbuf * nautilus_icon_factory_scale (NautilusIconFactory *factory,
GdkPixbuf *standard_sized_pixbuf,
guint size_in_pixels);
static NautilusScalableIcon *scalable_icon_get (const char *uri,
IconSet *icon_set,
gboolean is_symbolic_link);
static IconSet *
icon_set_new (const gchar *name)
......@@ -93,18 +106,19 @@ icon_set_new (const gchar *name)
static void
icon_set_destroy (IconSet *icon_set, gboolean free_name)
{
if (icon_set != NULL) {
if (free_name)
g_free (icon_set->name);