Re: mime api shortcomings



On Tue, 2006-01-10 at 19:30 +0100, Paolo Borelli wrote:
> Hi,
> 
> 	in gedit we hit some shortcomings of the current gnome-vfs api with
> regard to getting mime type for a file/filename.
> 
> Basically we need these two functions:
> 
> 1 - guess_mime_from_filename(), which guesses the mime from just the
> filename (the real file may not exist and anyway we don't want to stat()
> it). As a usecase think of "gedit foo.c" where foo.c doesn't exist yet
> and where we want to be able to guess that's aC file.
> 
> 2 - guess_mime_type_from_data_and_filename() which guesses the mime type
> given a chunk of data *and* the filename, once again without hitting the
> disk. The use case here is an mmapped file for which we have the data in
> memory and thus we don't want to reread the data a second time.
> 
> 
> Note that gnome-vfs already has more than a function which does (1)
> however non of these functions are exported to apps, they all seem
> private to developers of vfs modules. See
> http://bugzilla.gnome.org/show_bug.cgi?id=324185.
> 
> As for (2) vfs currently has gnome_vfs_get_mime_type_for_data() however
> this uses *only* data, so for our mmapped file it returns text/plain no
> matter if it's a C file, a python file or whatever else.
> 
> 
> Any thoughts/suggestions on how the api should look and on where to
> implement this stuff? We are willing to take a look, but current mime
> stuff is a bit of a mess to get oriented in given that it's split across
> many files, that lots of functions are deprecated and that many mime
> related functions are not in the public api...

I have a distinct memory that we have discussed this on irc already some
time ago. Anyway, I see the need for these functions, so it makes sense
to add them. 

We have gnome_vfs_get_mime_type_for_data in gnome-vfs-mime-utils.h,
can't we just add:
const char *gnome_vfs_get_mime_type_for_name (const char *filename);
const char *gnome_vfs_get_mime_type_for_name_and_data (const char *filename,
					               gconstpointer  data,
					               int            data_size);

The first is just gnome_vfs_mime_type_from_name() (availible to modules)
with a better name. We should probably change all uses of that inside
vfs to the new name.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Alexander Larsson                                            Red Hat, Inc 
                   alexl redhat com    alla lysator liu se 
He's a war-weary native American shaman searching for his wife's true killer. 
She's a high-kicking wisecracking politician descended from a line of powerful 
witches. They fight crime! 




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