efl/legacy/efreet/src/lib/Efreet_Mime.h

128 lines
3.0 KiB
C
Raw Normal View History

#ifndef EFREET_MIME_H
#define EFREET_MIME_H
/**
* @file Efreet_Mime.h
* @brief The file that must be included by any project wishing to use
* @addtogroup Efreet_Mime Efreet_Mime: The XDG Shared Mime Info standard
* Efreet Mime is a library designed to help apps work with the
* Freedesktop.org Shared Mime Info standard.
* Efreet_Mime.h provides all of the necessary headers and
* includes to work with Efreet_Mime.
* @{
*/
2007-11-04 03:19:55 -08:00
#ifdef EAPI
# undef EAPI
2007-11-04 03:19:55 -08:00
#endif
#ifdef _WIN32
# ifdef EFL_EFREET_MIME_BUILD
# ifdef DLL_EXPORT
# define EAPI __declspec(dllexport)
# else
# define EAPI
# endif /* ! DLL_EXPORT */
2007-11-04 03:19:55 -08:00
# else
# define EAPI __declspec(dllimport)
# endif /* ! EFL_EFREET_MIME_BUILD */
2007-11-04 03:19:55 -08:00
#else
# ifdef __GNUC__
# if __GNUC__ >= 4
# define EAPI __attribute__ ((visibility("default")))
# else
# define EAPI
# endif
# else
# define EAPI
# endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
2007-07-01 09:32:34 -07:00
2011-04-08 04:01:08 -07:00
/**
* @return @c 1 on success or @c 0 on failure.
2011-04-08 04:01:08 -07:00
* @brief Initializes the efreet mime settings
*/
2007-11-04 01:32:35 -08:00
EAPI int efreet_mime_init(void);
2011-04-08 04:01:08 -07:00
/**
* @return The number of times the init function has been called minus the
* corresponding init call.
* @brief Shuts down Efreet mime settings system if a balanced number of
* init/shutdown calls have been made
2011-04-08 04:01:08 -07:00
*/
EAPI int efreet_mime_shutdown(void);
2007-07-01 09:32:34 -07:00
2011-04-08 04:01:08 -07:00
/**
* @param file The file to find the mime type
* @return Mime type as a string.
* @brief Retrieve the mime type of a file
2011-04-08 04:01:08 -07:00
*/
2007-11-04 01:32:35 -08:00
EAPI const char *efreet_mime_type_get(const char *file);
2011-04-08 04:01:08 -07:00
/**
* @param file The file to check the mime type
* @return Mime type as a string.
* @brief Retrieve the mime type of a file using magic
2011-04-08 04:01:08 -07:00
*/
2007-11-04 01:32:35 -08:00
EAPI const char *efreet_mime_magic_type_get(const char *file);
2011-04-08 04:01:08 -07:00
/**
* @param file The file to check the mime type
* @return Mime type as a string.
* @brief Retrieve the mime type of a file using globs
2011-04-08 04:01:08 -07:00
*/
2007-11-04 01:32:35 -08:00
EAPI const char *efreet_mime_globs_type_get(const char *file);
2011-04-08 04:01:08 -07:00
/**
* @param file The file to check the mime type
* @return Mime type as a string.
* @brief Retrieve the special mime type of a file
2011-04-08 04:01:08 -07:00
*/
2007-11-04 01:32:35 -08:00
EAPI const char *efreet_mime_special_type_get(const char *file);
2011-04-08 04:01:08 -07:00
/**
* @param file The file to check the mime type
* @return Mime type as a string.
* @brief Retrieve the fallback mime type of a file.
2011-04-08 04:01:08 -07:00
*/
2007-11-04 01:32:35 -08:00
EAPI const char *efreet_mime_fallback_type_get(const char *file);
2011-04-08 04:01:08 -07:00
/**
* @param mime The name of the mime type
* @param theme The name of the theme to search icons in
* @param size The wanted size of the icon
* @return Mime type icon path as a string.
* @brief Retrieve the mime type icon for a file.
2011-04-08 04:01:08 -07:00
*/
EAPI const char *efreet_mime_type_icon_get(const char *mime, const char *theme,
2011-04-08 04:01:08 -07:00
unsigned int size);
2011-04-08 04:01:08 -07:00
/**
* @brief Clear mime icons mapping cache
*/
efreet mime types icon cache. This cache is very simple and should work fine when system does not change, it keeps a direct association of mime-types and found icons, remembering theme and icon size. Search is very fast since it uses stringshared strings and thus direct pointer comparison in hash search. We could optimize it even more if we assumed stringshared strings to come in, so no need to eina_stringshare_add() (which is a hash per se), using just eina_stringshare_ref(). Cache population is limited to compile-time value and just values older than a given threshold are deleted. I do not keep a LRU explicit list, so you might have some old but unused items always alive. I don't find this too bad, sure it will consume more memory, but will not hurt performance. We can change this to purge all expired items by not checking for number of items to remove, removing all that match. Next I plan to find out a good way to cache and speed up file->mime discovery. I plan to do auto-generated state-machine to match extensions, so you don't need to check the same extension character more than once. Example: Input: bla.edc Extensions: edc edj eps png bmp It would first try to match against 'e', 'p' and 'b'. It will match 'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match 'd' and then check for 'c' or 'j'. This will reduce number of comparisons considerably. As I'm running out of time (4am, not much time left on this month), I could use some help here. SVN revision: 39343
2009-03-02 23:20:21 -08:00
EAPI void efreet_mime_type_cache_clear(void);
2011-04-08 04:01:08 -07:00
/**
* @brief Flush mime icons mapping cache
*
* Flush timeout is defined at compile time by
* EFREET_MIME_ICONS_FLUSH_TIMEOUT
*/
efreet mime types icon cache. This cache is very simple and should work fine when system does not change, it keeps a direct association of mime-types and found icons, remembering theme and icon size. Search is very fast since it uses stringshared strings and thus direct pointer comparison in hash search. We could optimize it even more if we assumed stringshared strings to come in, so no need to eina_stringshare_add() (which is a hash per se), using just eina_stringshare_ref(). Cache population is limited to compile-time value and just values older than a given threshold are deleted. I do not keep a LRU explicit list, so you might have some old but unused items always alive. I don't find this too bad, sure it will consume more memory, but will not hurt performance. We can change this to purge all expired items by not checking for number of items to remove, removing all that match. Next I plan to find out a good way to cache and speed up file->mime discovery. I plan to do auto-generated state-machine to match extensions, so you don't need to check the same extension character more than once. Example: Input: bla.edc Extensions: edc edj eps png bmp It would first try to match against 'e', 'p' and 'b'. It will match 'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match 'd' and then check for 'c' or 'j'. This will reduce number of comparisons considerably. As I'm running out of time (4am, not much time left on this month), I could use some help here. SVN revision: 39343
2009-03-02 23:20:21 -08:00
EAPI void efreet_mime_type_cache_flush(void);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif