Proposed new API for libgnomeui



Hi, 

I've been working on the new NautilusIconFactory in the 
new-icon-factory-branch branch of nautilus. It now uses GnomeIconLoader 
from libgnomedesktop to do the theming instead of the nautilus icon 
theming crap.

This gives better performance in Nautilus, but it will also allow us to 
split out the file -> icon mapping from Nautilus into e.g. libgnomeui. 
I've coded it so that this will be simple. At the same time I've converted 
Nautilus to the new thumbnail specification, and the code for this is 
integrated with the icon handling and meant to go in libgnomeui too.

As a bonus I've added pluggable thumbnailing scripts.
By putting this:
video/x-msvideo: /home/alex/bin/avithumbnailer %i %o
application/pdf,application/postscript: gs  -sDEVICE=png16m -r11 -dFirstPage=1 -dLastPage=1 -sOutputFile=%o -dBATCH -dNOPAUSE %i

in ~/.gnome2/thumbnailrc i was able to get this:
http://people.redhat.com/alexl/files/thumbnails2.png

Here is the API for gnome-icon-lookup:

typedef enum {
  GNOME_ICON_LOOKUP_FLAGS_NONE = 0,
  GNOME_ICON_LOOKUP_FLAGS_EMBEDDING_TEXT = 1<<0,
  GNOME_ICON_LOOKUP_FLAGS_SHOW_SMALL_IMAGES_AS_THEMSELVES = 1<<1,
} GnomeIconLookupFlags;

typedef enum {
  GNOME_ICON_LOOKUP_RESULT_FLAGS_NONE = 0,
  GNOME_ICON_LOOKUP_RESULT_FLAGS_THUMBNAIL = 1<<0,
} GnomeIconLookupResultFlags;


char *gnome_icon_lookup      (GnomeIconLoader            *icon_loader,
			      GnomeThumbnailFactory      *thumbnail_factory,
			      const char                 *file_uri,
			      const char                 *custom_icon,
			      GnomeVFSFileInfo           *file_info,
			      const char                 *mime_type,
			      GnomeIconLookupFlags        flags,
			      GnomeIconLookupResultFlags *result);
char *gnome_icon_lookup_sync (GnomeIconLoader            *icon_loader,
			      GnomeThumbnailFactory      *thumbnail_factory,
			      const char                 *file_uri,
			      const char                 *custom_icon,
			      GnomeIconLookupFlags        flags,
			      GnomeIconLookupResultFlags *result);


It's basically one function (with a sync variant that loads data from 
the disk) that returns an icon name or a full absolute pathname.
You can optionally pass it a GnomeThumbnailFactory if you want to be able 
to read already exisitng thumbnails.

When it goes into libgnomeui i will write full docs. For now, if it's 
unclear, please ask.

The gnome-thumbnail API looks like this:

typedef enum {
  GNOME_THUMBNAIL_SIZE_NORMAL,
  GNOME_THUMBNAIL_SIZE_LARGE,
} GnomeThumbnailSize;

GType                  gnome_thumbnail_factory_get_type (void);
GnomeThumbnailFactory *gnome_thumbnail_factory_new      (GnomeThumbnailSize     size);

char *                 gnome_thumbnail_factory_lookup   (GnomeThumbnailFactory *factory,
							 const char            *uri,
							 time_t                 mtime);

gboolean               gnome_thumbnail_factory_has_valid_failed_thumbnail (GnomeThumbnailFactory *factory,
									   const char            *uri,
									   time_t                 mtime);
gboolean               gnome_thumbnail_factory_can_thumbnail (GnomeThumbnailFactory *factory,
							      const char            *uri,
							      const char            *mime_type,
							      time_t                 mtime);
GdkPixbuf *            gnome_thumbnail_factory_generate_thumbnail (GnomeThumbnailFactory *factory,
								   const char            *uri,
								   const char            *mime_type);
void                   gnome_thumbnail_factory_save_thumbnail (GnomeThumbnailFactory *factory,
							       GdkPixbuf             *thumbnail,
							       const char            *uri,
							       time_t                 original_mtime);
void                   gnome_thumbnail_factory_create_failed_thumbnail (GnomeThumbnailFactory *factory,
									const char            *uri,
									time_t                 mtime);


There are also some utility functions that can be useful while doing 
thumbnail work:

gboolean   gnome_thumbnail_has_uri           (GdkPixbuf          *pixbuf,
					      const char         *uri);
gboolean   gnome_thumbnail_is_valid          (GdkPixbuf          *pixbuf,
					      const char         *uri,
					      time_t              mtime);
char *     gnome_thumbnail_md5               (const char         *uri);
char *     gnome_thumbnail_path_for_uri      (const char         *uri,
					      GnomeThumbnailSize  size);

GdkPixbuf *gnome_thumbnail_scale_down_pixbuf (GdkPixbuf          *pixbuf,
					      int                 dest_width,
					      int                 dest_height);
GdkPixbuf *gnome_thumbnail_load_pixbuf       (const char         *uri);



The full code and examples how to use it is in the new-icon-factory-branch 
branch of nautilus.

Andersca is interested in getting this into libgnomeui. We would need to 
move GnomeIconLoader from gnome-desktop to avoid dependency loops too.
Comments on this API?

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Alexander Larsson                                            Red Hat, Inc 
                   alexl redhat com    alla lysator liu se 
He's a genetically engineered misogynist Green Beret plagued by the memory of 
his family's brutal murder. She's a plucky red-headed magician's assistant 
from the wrong side of the tracks. They fight crime! 




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]