mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-02 09:16:17 +01:00
gcontenttype: Add platform-independent top level API file
This file doesn’t contain any real implementation, it just call the `impl` functions from the platform-specific files `gcontenttype-{fdo,osx,win32}.[cm]`. It serves as a location for the doc comments, introspection annotations and API preconditions, and will be built on every platform. In particular, this means that we get consistent GIR output for the `g_content_type_*()` APIs regardless of whether GLib was built on Linux or Windows or macOS. Signed-off-by: Philip Withnall <pwithnall@gnome.org> Helps: #3399
This commit is contained in:
parent
7bec6327a2
commit
460d284fce
@ -36,21 +36,6 @@
|
||||
#include "glibintl.h"
|
||||
#include "glib-private.h"
|
||||
|
||||
|
||||
/**
|
||||
* GContentType:
|
||||
*
|
||||
* A content type is a platform specific string that defines the type
|
||||
* of a file. On UNIX it is a
|
||||
* [MIME type](http://www.wikipedia.org/wiki/Internet_media_type)
|
||||
* like `text/plain` or `image/png`.
|
||||
* On Win32 it is an extension string like `.doc`, `.txt` or a perceived
|
||||
* string like `audio`. Such strings can be looked up in the registry at
|
||||
* `HKEY_CLASSES_ROOT`.
|
||||
* On macOS it is a [Uniform Type Identifier](https://en.wikipedia.org/wiki/Uniform_Type_Identifier)
|
||||
* such as `com.apple.application`.
|
||||
**/
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
#define XDG_PREFIX _gio_xdg
|
||||
@ -154,61 +139,18 @@ _g_content_type_set_mime_dirs_locked (const char * const *dirs)
|
||||
tree_magic_schedule_reload ();
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_set_mime_dirs:
|
||||
* @dirs: (array zero-terminated=1) (nullable): %NULL-terminated list of
|
||||
* directories to load MIME data from, including any `mime/` subdirectory,
|
||||
* and with the first directory to try listed first
|
||||
*
|
||||
* Set the list of directories used by GIO to load the MIME database.
|
||||
* If @dirs is %NULL, the directories used are the default:
|
||||
*
|
||||
* - the `mime` subdirectory of the directory in `$XDG_DATA_HOME`
|
||||
* - the `mime` subdirectory of every directory in `$XDG_DATA_DIRS`
|
||||
*
|
||||
* This function is intended to be used when writing tests that depend on
|
||||
* information stored in the MIME database, in order to control the data.
|
||||
*
|
||||
* Typically, in case your tests use %G_TEST_OPTION_ISOLATE_DIRS, but they
|
||||
* depend on the system’s MIME database, you should call this function
|
||||
* with @dirs set to %NULL before calling g_test_init(), for instance:
|
||||
*
|
||||
* |[<!-- language="C" -->
|
||||
* // Load MIME data from the system
|
||||
* g_content_type_set_mime_dirs (NULL);
|
||||
* // Isolate the environment
|
||||
* g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
|
||||
*
|
||||
* …
|
||||
*
|
||||
* return g_test_run ();
|
||||
* ]|
|
||||
*
|
||||
* Since: 2.60
|
||||
*/
|
||||
/*< private >*/
|
||||
void
|
||||
g_content_type_set_mime_dirs (const gchar * const *dirs)
|
||||
g_content_type_set_mime_dirs_impl (const gchar * const *dirs)
|
||||
{
|
||||
G_LOCK (global_mime_dirs);
|
||||
_g_content_type_set_mime_dirs_locked (dirs);
|
||||
G_UNLOCK (global_mime_dirs);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_get_mime_dirs:
|
||||
*
|
||||
* Get the list of directories which MIME data is loaded from. See
|
||||
* g_content_type_set_mime_dirs() for details.
|
||||
*
|
||||
* Returns: (transfer none) (array zero-terminated=1): %NULL-terminated list of
|
||||
* directories to load MIME data from, including any `mime/` subdirectory,
|
||||
* and with the first directory to try listed first
|
||||
* Since: 2.60
|
||||
*/
|
||||
/*< private >*/
|
||||
const gchar * const *
|
||||
g_content_type_get_mime_dirs (void)
|
||||
g_content_type_get_mime_dirs_impl (void)
|
||||
{
|
||||
const gchar * const *mime_dirs;
|
||||
|
||||
@ -225,19 +167,9 @@ g_content_type_get_mime_dirs (void)
|
||||
return mime_dirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_equals:
|
||||
* @type1: a content type string
|
||||
* @type2: a content type string
|
||||
*
|
||||
* Compares two content types for equality.
|
||||
*
|
||||
* Returns: %TRUE if the two strings are identical or equivalent,
|
||||
* %FALSE otherwise.
|
||||
*/
|
||||
gboolean
|
||||
g_content_type_equals (const gchar *type1,
|
||||
const gchar *type2)
|
||||
g_content_type_equals_impl (const gchar *type1,
|
||||
const gchar *type2)
|
||||
{
|
||||
gboolean res;
|
||||
|
||||
@ -253,19 +185,9 @@ g_content_type_equals (const gchar *type1,
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_is_a:
|
||||
* @type: a content type string
|
||||
* @supertype: a content type string
|
||||
*
|
||||
* Determines if @type is a subset of @supertype.
|
||||
*
|
||||
* Returns: %TRUE if @type is a kind of @supertype,
|
||||
* %FALSE otherwise.
|
||||
*/
|
||||
gboolean
|
||||
g_content_type_is_a (const gchar *type,
|
||||
const gchar *supertype)
|
||||
g_content_type_is_a_impl (const gchar *type,
|
||||
const gchar *supertype)
|
||||
{
|
||||
gboolean res;
|
||||
|
||||
@ -281,39 +203,15 @@ g_content_type_is_a (const gchar *type,
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_is_mime_type:
|
||||
* @type: a content type string
|
||||
* @mime_type: a mime type string
|
||||
*
|
||||
* Determines if @type is a subset of @mime_type.
|
||||
* Convenience wrapper around g_content_type_is_a().
|
||||
*
|
||||
* Returns: %TRUE if @type is a kind of @mime_type,
|
||||
* %FALSE otherwise.
|
||||
*
|
||||
* Since: 2.52
|
||||
*/
|
||||
gboolean
|
||||
g_content_type_is_mime_type (const gchar *type,
|
||||
const gchar *mime_type)
|
||||
g_content_type_is_mime_type_impl (const gchar *type,
|
||||
const gchar *mime_type)
|
||||
{
|
||||
return g_content_type_is_a (type, mime_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_is_unknown:
|
||||
* @type: a content type string
|
||||
*
|
||||
* Checks if the content type is the generic "unknown" type.
|
||||
* On UNIX this is the "application/octet-stream" mimetype,
|
||||
* while on win32 it is "*" and on OSX it is a dynamic type
|
||||
* or octet-stream.
|
||||
*
|
||||
* Returns: %TRUE if the type is the unknown type.
|
||||
*/
|
||||
gboolean
|
||||
g_content_type_is_unknown (const gchar *type)
|
||||
g_content_type_is_unknown_impl (const gchar *type)
|
||||
{
|
||||
g_return_val_if_fail (type != NULL, FALSE);
|
||||
|
||||
@ -470,17 +368,8 @@ load_comment_for_mime (const char *mimetype)
|
||||
return g_strdup_printf (_("%s type"), mimetype);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_get_description:
|
||||
* @type: a content type string
|
||||
*
|
||||
* Gets the human readable description of the content type.
|
||||
*
|
||||
* Returns: a short description of the content type @type. Free the
|
||||
* returned string with g_free()
|
||||
*/
|
||||
gchar *
|
||||
g_content_type_get_description (const gchar *type)
|
||||
g_content_type_get_description_impl (const gchar *type)
|
||||
{
|
||||
static GHashTable *type_comment_cache = NULL;
|
||||
gchar *type_copy = NULL;
|
||||
@ -519,17 +408,8 @@ g_content_type_get_description (const gchar *type)
|
||||
return g_steal_pointer (&comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_get_mime_type:
|
||||
* @type: a content type string
|
||||
*
|
||||
* Gets the mime type for the content type, if one is registered.
|
||||
*
|
||||
* Returns: (nullable) (transfer full): the registered mime type for the
|
||||
* given @type, or %NULL if unknown; free with g_free().
|
||||
*/
|
||||
char *
|
||||
g_content_type_get_mime_type (const char *type)
|
||||
g_content_type_get_mime_type_impl (const char *type)
|
||||
{
|
||||
g_return_val_if_fail (type != NULL, NULL);
|
||||
|
||||
@ -589,55 +469,20 @@ g_content_type_get_icon_internal (const gchar *type,
|
||||
return themed_icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_get_icon:
|
||||
* @type: a content type string
|
||||
*
|
||||
* Gets the icon for a content type.
|
||||
*
|
||||
* Returns: (transfer full): #GIcon corresponding to the content type. Free the returned
|
||||
* object with g_object_unref()
|
||||
*/
|
||||
GIcon *
|
||||
g_content_type_get_icon (const gchar *type)
|
||||
g_content_type_get_icon_impl (const gchar *type)
|
||||
{
|
||||
return g_content_type_get_icon_internal (type, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_get_symbolic_icon:
|
||||
* @type: a content type string
|
||||
*
|
||||
* Gets the symbolic icon for a content type.
|
||||
*
|
||||
* Returns: (transfer full): symbolic #GIcon corresponding to the content type.
|
||||
* Free the returned object with g_object_unref()
|
||||
*
|
||||
* Since: 2.34
|
||||
*/
|
||||
GIcon *
|
||||
g_content_type_get_symbolic_icon (const gchar *type)
|
||||
g_content_type_get_symbolic_icon_impl (const gchar *type)
|
||||
{
|
||||
return g_content_type_get_icon_internal (type, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_get_generic_icon_name:
|
||||
* @type: a content type string
|
||||
*
|
||||
* Gets the generic icon name for a content type.
|
||||
*
|
||||
* See the
|
||||
* [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec)
|
||||
* specification for more on the generic icon name.
|
||||
*
|
||||
* Returns: (nullable): the registered generic icon name for the given @type,
|
||||
* or %NULL if unknown. Free with g_free()
|
||||
*
|
||||
* Since: 2.34
|
||||
*/
|
||||
gchar *
|
||||
g_content_type_get_generic_icon_name (const gchar *type)
|
||||
g_content_type_get_generic_icon_name_impl (const gchar *type)
|
||||
{
|
||||
const gchar *xdg_icon_name;
|
||||
gchar *icon_name;
|
||||
@ -672,18 +517,8 @@ g_content_type_get_generic_icon_name (const gchar *type)
|
||||
return icon_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_can_be_executable:
|
||||
* @type: a content type string
|
||||
*
|
||||
* Checks if a content type can be executable. Note that for instance
|
||||
* things like text files can be executables (i.e. scripts and batch files).
|
||||
*
|
||||
* Returns: %TRUE if the file type corresponds to a type that
|
||||
* can be executable, %FALSE otherwise.
|
||||
*/
|
||||
gboolean
|
||||
g_content_type_can_be_executable (const gchar *type)
|
||||
g_content_type_can_be_executable_impl (const gchar *type)
|
||||
{
|
||||
g_return_val_if_fail (type != NULL, FALSE);
|
||||
|
||||
@ -712,19 +547,8 @@ looks_like_text (const guchar *data, gsize data_size)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_from_mime_type:
|
||||
* @mime_type: a mime type string
|
||||
*
|
||||
* Tries to find a content type based on the mime type name.
|
||||
*
|
||||
* Returns: (nullable): Newly allocated string with content type or
|
||||
* %NULL. Free with g_free()
|
||||
*
|
||||
* Since: 2.18
|
||||
**/
|
||||
gchar *
|
||||
g_content_type_from_mime_type (const gchar *mime_type)
|
||||
g_content_type_from_mime_type_impl (const gchar *mime_type)
|
||||
{
|
||||
char *umime;
|
||||
|
||||
@ -740,27 +564,11 @@ g_content_type_from_mime_type (const gchar *mime_type)
|
||||
return umime;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_guess:
|
||||
* @filename: (nullable) (type filename): a path, or %NULL
|
||||
* @data: (nullable) (array length=data_size): a stream of data, or %NULL
|
||||
* @data_size: the size of @data
|
||||
* @result_uncertain: (out) (optional): return location for the certainty
|
||||
* of the result, or %NULL
|
||||
*
|
||||
* Guesses the content type based on example data. If the function is
|
||||
* uncertain, @result_uncertain will be set to %TRUE. Either @filename
|
||||
* or @data may be %NULL, in which case the guess will be based solely
|
||||
* on the other argument.
|
||||
*
|
||||
* Returns: a string indicating a guessed content type for the
|
||||
* given data. Free with g_free()
|
||||
*/
|
||||
gchar *
|
||||
g_content_type_guess (const gchar *filename,
|
||||
const guchar *data,
|
||||
gsize data_size,
|
||||
gboolean *result_uncertain)
|
||||
g_content_type_guess_impl (const gchar *filename,
|
||||
const guchar *data,
|
||||
gsize data_size,
|
||||
gboolean *result_uncertain)
|
||||
{
|
||||
char *basename;
|
||||
const char *name_mimetypes[10], *sniffed_mimetype;
|
||||
@ -933,18 +741,8 @@ enumerate_mimetypes_dir (const char *dir,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_types_get_registered:
|
||||
*
|
||||
* Gets a list of strings containing all the registered content types
|
||||
* known to the system. The list and its data should be freed using
|
||||
* `g_list_free_full (list, g_free)`.
|
||||
*
|
||||
* Returns: (element-type utf8) (transfer full): list of the registered
|
||||
* content types
|
||||
*/
|
||||
GList *
|
||||
g_content_types_get_registered (void)
|
||||
g_content_types_get_registered_impl (void)
|
||||
{
|
||||
const char * const *dirs;
|
||||
GHashTable *mimetypes;
|
||||
@ -1533,30 +1331,8 @@ match_match (TreeMatch *match,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_guess_for_tree:
|
||||
* @root: the root of the tree to guess a type for
|
||||
*
|
||||
* Tries to guess the type of the tree with root @root, by
|
||||
* looking at the files it contains. The result is an array
|
||||
* of content types, with the best guess coming first.
|
||||
*
|
||||
* The types returned all have the form x-content/foo, e.g.
|
||||
* x-content/audio-cdda (for audio CDs) or x-content/image-dcf
|
||||
* (for a camera memory card). See the
|
||||
* [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec)
|
||||
* specification for more on x-content types.
|
||||
*
|
||||
* This function is useful in the implementation of
|
||||
* g_mount_guess_content_type().
|
||||
*
|
||||
* Returns: (transfer full) (array zero-terminated=1): an %NULL-terminated
|
||||
* array of zero or more content types. Free with g_strfreev()
|
||||
*
|
||||
* Since: 2.18
|
||||
*/
|
||||
gchar **
|
||||
g_content_type_guess_for_tree (GFile *root)
|
||||
g_content_type_guess_for_tree_impl (GFile *root)
|
||||
{
|
||||
GPtrArray *types;
|
||||
GList *l;
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "gcontenttype.h"
|
||||
#include "gcontenttypeprivate.h"
|
||||
#include "gicon.h"
|
||||
#include "gthemedicon.h"
|
||||
|
||||
@ -107,22 +108,22 @@ create_cstr_from_cfstring_with_fallback (CFStringRef str,
|
||||
|
||||
/*< private >*/
|
||||
void
|
||||
g_content_type_set_mime_dirs (const gchar * const *dirs)
|
||||
g_content_type_set_mime_dirs_impl (const gchar * const *dirs)
|
||||
{
|
||||
/* noop on macOS */
|
||||
}
|
||||
|
||||
/*< private >*/
|
||||
const gchar * const *
|
||||
g_content_type_get_mime_dirs (void)
|
||||
g_content_type_get_mime_dirs_impl (void)
|
||||
{
|
||||
const gchar * const *mime_dirs = { NULL };
|
||||
return mime_dirs;
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_content_type_equals (const gchar *type1,
|
||||
const gchar *type2)
|
||||
g_content_type_equals_impl (const gchar *type1,
|
||||
const gchar *type2)
|
||||
{
|
||||
CFStringRef str1, str2;
|
||||
gboolean ret;
|
||||
@ -145,8 +146,8 @@ g_content_type_equals (const gchar *type1,
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_content_type_is_a (const gchar *ctype,
|
||||
const gchar *csupertype)
|
||||
g_content_type_is_a_impl (const gchar *ctype,
|
||||
const gchar *csupertype)
|
||||
{
|
||||
CFStringRef type, supertype;
|
||||
gboolean ret;
|
||||
@ -166,8 +167,8 @@ g_content_type_is_a (const gchar *ctype,
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_content_type_is_mime_type (const gchar *type,
|
||||
const gchar *mime_type)
|
||||
g_content_type_is_mime_type_impl (const gchar *type,
|
||||
const gchar *mime_type)
|
||||
{
|
||||
gchar *content_type;
|
||||
gboolean ret;
|
||||
@ -183,7 +184,7 @@ g_content_type_is_mime_type (const gchar *type,
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_content_type_is_unknown (const gchar *type)
|
||||
g_content_type_is_unknown_impl (const gchar *type)
|
||||
{
|
||||
g_return_val_if_fail (type != NULL, FALSE);
|
||||
|
||||
@ -198,7 +199,7 @@ g_content_type_is_unknown (const gchar *type)
|
||||
}
|
||||
|
||||
gchar *
|
||||
g_content_type_get_description (const gchar *type)
|
||||
g_content_type_get_description_impl (const gchar *type)
|
||||
{
|
||||
CFStringRef str;
|
||||
CFStringRef desc_str;
|
||||
@ -327,25 +328,25 @@ g_content_type_get_icon_internal (const gchar *uti,
|
||||
}
|
||||
|
||||
GIcon *
|
||||
g_content_type_get_icon (const gchar *type)
|
||||
g_content_type_get_icon_impl (const gchar *type)
|
||||
{
|
||||
return g_content_type_get_icon_internal (type, FALSE);
|
||||
}
|
||||
|
||||
GIcon *
|
||||
g_content_type_get_symbolic_icon (const gchar *type)
|
||||
g_content_type_get_symbolic_icon_impl (const gchar *type)
|
||||
{
|
||||
return g_content_type_get_icon_internal (type, TRUE);
|
||||
}
|
||||
|
||||
gchar *
|
||||
g_content_type_get_generic_icon_name (const gchar *type)
|
||||
g_content_type_get_generic_icon_name_impl (const gchar *type)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_content_type_can_be_executable (const gchar *type)
|
||||
g_content_type_can_be_executable_impl (const gchar *type)
|
||||
{
|
||||
CFStringRef uti;
|
||||
gboolean ret = FALSE;
|
||||
@ -369,7 +370,7 @@ g_content_type_can_be_executable (const gchar *type)
|
||||
}
|
||||
|
||||
gchar *
|
||||
g_content_type_from_mime_type (const gchar *mime_type)
|
||||
g_content_type_from_mime_type_impl (const gchar *mime_type)
|
||||
{
|
||||
CFStringRef mime_str;
|
||||
CFStringRef uti_str;
|
||||
@ -437,7 +438,7 @@ g_content_type_from_mime_type (const gchar *mime_type)
|
||||
}
|
||||
|
||||
gchar *
|
||||
g_content_type_get_mime_type (const gchar *type)
|
||||
g_content_type_get_mime_type_impl (const gchar *type)
|
||||
{
|
||||
CFStringRef uti_str;
|
||||
CFStringRef mime_str;
|
||||
@ -489,10 +490,10 @@ looks_like_text (const guchar *data,
|
||||
}
|
||||
|
||||
gchar *
|
||||
g_content_type_guess (const gchar *filename,
|
||||
const guchar *data,
|
||||
gsize data_size,
|
||||
gboolean *result_uncertain)
|
||||
g_content_type_guess_impl (const gchar *filename,
|
||||
const guchar *data,
|
||||
gsize data_size,
|
||||
gboolean *result_uncertain)
|
||||
{
|
||||
CFStringRef uti = NULL;
|
||||
gchar *cextension;
|
||||
@ -595,14 +596,14 @@ g_content_type_guess (const gchar *filename,
|
||||
}
|
||||
|
||||
GList *
|
||||
g_content_types_get_registered (void)
|
||||
g_content_types_get_registered_impl (void)
|
||||
{
|
||||
/* TODO: UTTypeCreateAllIdentifiersForTag? */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gchar **
|
||||
g_content_type_guess_for_tree (GFile *root)
|
||||
g_content_type_guess_for_tree_impl (GFile *root)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "gcontenttype.h"
|
||||
#include "gcontenttypeprivate.h"
|
||||
#include "gthemedicon.h"
|
||||
#include "gicon.h"
|
||||
#include "glibintl.h"
|
||||
@ -87,22 +88,22 @@ get_registry_classes_key (const char *subdir,
|
||||
|
||||
/*< private >*/
|
||||
void
|
||||
g_content_type_set_mime_dirs (const gchar * const *dirs)
|
||||
g_content_type_set_mime_dirs_impl (const gchar * const *dirs)
|
||||
{
|
||||
/* noop on Windows */
|
||||
}
|
||||
|
||||
/*< private >*/
|
||||
const gchar * const *
|
||||
g_content_type_get_mime_dirs (void)
|
||||
g_content_type_get_mime_dirs_impl (void)
|
||||
{
|
||||
const gchar * const *mime_dirs = { NULL };
|
||||
return mime_dirs;
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_content_type_equals (const gchar *type1,
|
||||
const gchar *type2)
|
||||
g_content_type_equals_impl (const gchar *type1,
|
||||
const gchar *type2)
|
||||
{
|
||||
char *progid1, *progid2;
|
||||
gboolean res;
|
||||
@ -126,8 +127,8 @@ g_content_type_equals (const gchar *type1,
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_content_type_is_a (const gchar *type,
|
||||
const gchar *supertype)
|
||||
g_content_type_is_a_impl (const gchar *type,
|
||||
const gchar *supertype)
|
||||
{
|
||||
gboolean res;
|
||||
char *perceived_type;
|
||||
@ -152,8 +153,8 @@ g_content_type_is_a (const gchar *type,
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_content_type_is_mime_type (const gchar *type,
|
||||
const gchar *mime_type)
|
||||
g_content_type_is_mime_type_impl (const gchar *type,
|
||||
const gchar *mime_type)
|
||||
{
|
||||
gchar *content_type;
|
||||
gboolean ret;
|
||||
@ -169,7 +170,7 @@ g_content_type_is_mime_type (const gchar *type,
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_content_type_is_unknown (const gchar *type)
|
||||
g_content_type_is_unknown_impl (const gchar *type)
|
||||
{
|
||||
g_return_val_if_fail (type != NULL, FALSE);
|
||||
|
||||
@ -177,7 +178,7 @@ g_content_type_is_unknown (const gchar *type)
|
||||
}
|
||||
|
||||
gchar *
|
||||
g_content_type_get_description (const gchar *type)
|
||||
g_content_type_get_description_impl (const gchar *type)
|
||||
{
|
||||
char *progid;
|
||||
char *description;
|
||||
@ -201,7 +202,7 @@ g_content_type_get_description (const gchar *type)
|
||||
}
|
||||
|
||||
gchar *
|
||||
g_content_type_get_mime_type (const gchar *type)
|
||||
g_content_type_get_mime_type_impl (const gchar *type)
|
||||
{
|
||||
char *mime;
|
||||
|
||||
@ -224,17 +225,8 @@ g_content_type_get_mime_type (const gchar *type)
|
||||
G_LOCK_DEFINE_STATIC (_type_icons);
|
||||
static GHashTable *_type_icons = NULL;
|
||||
|
||||
/**
|
||||
* g_content_type_get_icon:
|
||||
* @type: a content type string
|
||||
*
|
||||
* Gets the icon for a content type.
|
||||
*
|
||||
* Returns: (transfer full): #GIcon corresponding to the content type. Free the returned
|
||||
* object with g_object_unref()
|
||||
*/
|
||||
GIcon *
|
||||
g_content_type_get_icon (const gchar *type)
|
||||
g_content_type_get_icon_impl (const gchar *type)
|
||||
{
|
||||
GIcon *themed_icon;
|
||||
char *name = NULL;
|
||||
@ -292,19 +284,19 @@ g_content_type_get_icon (const gchar *type)
|
||||
}
|
||||
|
||||
GIcon *
|
||||
g_content_type_get_symbolic_icon (const gchar *type)
|
||||
g_content_type_get_symbolic_icon_impl (const gchar *type)
|
||||
{
|
||||
return g_content_type_get_icon (type);
|
||||
}
|
||||
|
||||
gchar *
|
||||
g_content_type_get_generic_icon_name (const gchar *type)
|
||||
g_content_type_get_generic_icon_name_impl (const gchar *type)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_content_type_can_be_executable (const gchar *type)
|
||||
g_content_type_can_be_executable_impl (const gchar *type)
|
||||
{
|
||||
g_return_val_if_fail (type != NULL, FALSE);
|
||||
|
||||
@ -343,7 +335,7 @@ looks_like_text (const guchar *data,
|
||||
}
|
||||
|
||||
gchar *
|
||||
g_content_type_from_mime_type (const gchar *mime_type)
|
||||
g_content_type_from_mime_type_impl (const gchar *mime_type)
|
||||
{
|
||||
char *key, *content_type;
|
||||
|
||||
@ -362,10 +354,10 @@ g_content_type_from_mime_type (const gchar *mime_type)
|
||||
}
|
||||
|
||||
gchar *
|
||||
g_content_type_guess (const gchar *filename,
|
||||
const guchar *data,
|
||||
gsize data_size,
|
||||
gboolean *result_uncertain)
|
||||
g_content_type_guess_impl (const gchar *filename,
|
||||
const guchar *data,
|
||||
gsize data_size,
|
||||
gboolean *result_uncertain)
|
||||
{
|
||||
char *basename;
|
||||
char *type;
|
||||
@ -410,7 +402,7 @@ g_content_type_guess (const gchar *filename,
|
||||
}
|
||||
|
||||
GList *
|
||||
g_content_types_get_registered (void)
|
||||
g_content_types_get_registered_impl (void)
|
||||
{
|
||||
DWORD index;
|
||||
wchar_t keyname[256];
|
||||
@ -446,7 +438,7 @@ g_content_types_get_registered (void)
|
||||
}
|
||||
|
||||
gchar **
|
||||
g_content_type_guess_for_tree (GFile *root)
|
||||
g_content_type_guess_for_tree_impl (GFile *root)
|
||||
{
|
||||
/* FIXME: implement */
|
||||
return NULL;
|
||||
|
380
gio/gcontenttype.c
Normal file
380
gio/gcontenttype.c
Normal file
@ -0,0 +1,380 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||
|
||||
/* GIO - GLib Input, Output and Streaming Library
|
||||
*
|
||||
* Copyright (C) 2006-2007 Red Hat, Inc.
|
||||
*
|
||||
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General
|
||||
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Author: Alexander Larsson <alexl@redhat.com>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "gcontenttypeprivate.h"
|
||||
#include "gfile.h"
|
||||
|
||||
|
||||
/**
|
||||
* GContentType:
|
||||
*
|
||||
* A content type is a platform specific string that defines the type
|
||||
* of a file. On UNIX it is a
|
||||
* [MIME type](http://www.wikipedia.org/wiki/Internet_media_type)
|
||||
* like `text/plain` or `image/png`.
|
||||
* On Win32 it is an extension string like `.doc`, `.txt` or a perceived
|
||||
* string like `audio`. Such strings can be looked up in the registry at
|
||||
* `HKEY_CLASSES_ROOT`.
|
||||
* On macOS it is a [Uniform Type Identifier](https://en.wikipedia.org/wiki/Uniform_Type_Identifier)
|
||||
* such as `com.apple.application`.
|
||||
**/
|
||||
|
||||
/**
|
||||
* g_content_type_set_mime_dirs:
|
||||
* @dirs: (array zero-terminated=1) (nullable): %NULL-terminated list of
|
||||
* directories to load MIME data from, including any `mime/` subdirectory,
|
||||
* and with the first directory to try listed first
|
||||
*
|
||||
* Set the list of directories used by GIO to load the MIME database.
|
||||
* If @dirs is %NULL, the directories used are the default:
|
||||
*
|
||||
* - the `mime` subdirectory of the directory in `$XDG_DATA_HOME`
|
||||
* - the `mime` subdirectory of every directory in `$XDG_DATA_DIRS`
|
||||
*
|
||||
* This function is intended to be used when writing tests that depend on
|
||||
* information stored in the MIME database, in order to control the data.
|
||||
*
|
||||
* Typically, in case your tests use %G_TEST_OPTION_ISOLATE_DIRS, but they
|
||||
* depend on the system’s MIME database, you should call this function
|
||||
* with @dirs set to %NULL before calling g_test_init(), for instance:
|
||||
*
|
||||
* |[<!-- language="C" -->
|
||||
* // Load MIME data from the system
|
||||
* g_content_type_set_mime_dirs (NULL);
|
||||
* // Isolate the environment
|
||||
* g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
|
||||
*
|
||||
* …
|
||||
*
|
||||
* return g_test_run ();
|
||||
* ]|
|
||||
*
|
||||
* Since: 2.60
|
||||
*/
|
||||
void
|
||||
g_content_type_set_mime_dirs (const gchar * const *dirs)
|
||||
{
|
||||
g_content_type_set_mime_dirs_impl (dirs);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_get_mime_dirs:
|
||||
*
|
||||
* Get the list of directories which MIME data is loaded from. See
|
||||
* g_content_type_set_mime_dirs() for details.
|
||||
*
|
||||
* Returns: (transfer none) (array zero-terminated=1): %NULL-terminated list of
|
||||
* directories to load MIME data from, including any `mime/` subdirectory,
|
||||
* and with the first directory to try listed first
|
||||
* Since: 2.60
|
||||
*/
|
||||
const gchar * const *
|
||||
g_content_type_get_mime_dirs (void)
|
||||
{
|
||||
return g_content_type_get_mime_dirs_impl ();
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_equals:
|
||||
* @type1: a content type string
|
||||
* @type2: a content type string
|
||||
*
|
||||
* Compares two content types for equality.
|
||||
*
|
||||
* Returns: %TRUE if the two strings are identical or equivalent,
|
||||
* %FALSE otherwise.
|
||||
*/
|
||||
gboolean
|
||||
g_content_type_equals (const gchar *type1,
|
||||
const gchar *type2)
|
||||
{
|
||||
g_return_val_if_fail (type1 != NULL, FALSE);
|
||||
g_return_val_if_fail (type2 != NULL, FALSE);
|
||||
|
||||
return g_content_type_equals_impl (type1, type2);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_is_a:
|
||||
* @type: a content type string
|
||||
* @supertype: a content type string
|
||||
*
|
||||
* Determines if @type is a subset of @supertype.
|
||||
*
|
||||
* Returns: %TRUE if @type is a kind of @supertype,
|
||||
* %FALSE otherwise.
|
||||
*/
|
||||
gboolean
|
||||
g_content_type_is_a (const gchar *type,
|
||||
const gchar *supertype)
|
||||
{
|
||||
g_return_val_if_fail (type != NULL, FALSE);
|
||||
g_return_val_if_fail (supertype != NULL, FALSE);
|
||||
|
||||
return g_content_type_is_a_impl (type, supertype);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_is_mime_type:
|
||||
* @type: a content type string
|
||||
* @mime_type: a mime type string
|
||||
*
|
||||
* Determines if @type is a subset of @mime_type.
|
||||
* Convenience wrapper around g_content_type_is_a().
|
||||
*
|
||||
* Returns: %TRUE if @type is a kind of @mime_type,
|
||||
* %FALSE otherwise.
|
||||
*
|
||||
* Since: 2.52
|
||||
*/
|
||||
gboolean
|
||||
g_content_type_is_mime_type (const gchar *type,
|
||||
const gchar *mime_type)
|
||||
{
|
||||
g_return_val_if_fail (type != NULL, FALSE);
|
||||
g_return_val_if_fail (mime_type != NULL, FALSE);
|
||||
|
||||
return g_content_type_is_mime_type_impl (type, mime_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_is_unknown:
|
||||
* @type: a content type string
|
||||
*
|
||||
* Checks if the content type is the generic "unknown" type.
|
||||
* On UNIX this is the "application/octet-stream" mimetype,
|
||||
* while on win32 it is "*" and on OSX it is a dynamic type
|
||||
* or octet-stream.
|
||||
*
|
||||
* Returns: %TRUE if the type is the unknown type.
|
||||
*/
|
||||
gboolean
|
||||
g_content_type_is_unknown (const gchar *type)
|
||||
{
|
||||
g_return_val_if_fail (type != NULL, FALSE);
|
||||
|
||||
return g_content_type_is_unknown_impl (type);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_get_description:
|
||||
* @type: a content type string
|
||||
*
|
||||
* Gets the human readable description of the content type.
|
||||
*
|
||||
* Returns: a short description of the content type @type. Free the
|
||||
* returned string with g_free()
|
||||
*/
|
||||
gchar *
|
||||
g_content_type_get_description (const gchar *type)
|
||||
{
|
||||
g_return_val_if_fail (type != NULL, NULL);
|
||||
|
||||
return g_content_type_get_description_impl (type);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_get_mime_type:
|
||||
* @type: a content type string
|
||||
*
|
||||
* Gets the mime type for the content type, if one is registered.
|
||||
*
|
||||
* Returns: (nullable) (transfer full): the registered mime type for the
|
||||
* given @type, or %NULL if unknown; free with g_free().
|
||||
*/
|
||||
char *
|
||||
g_content_type_get_mime_type (const char *type)
|
||||
{
|
||||
g_return_val_if_fail (type != NULL, NULL);
|
||||
|
||||
return g_content_type_get_mime_type_impl (type);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_get_icon:
|
||||
* @type: a content type string
|
||||
*
|
||||
* Gets the icon for a content type.
|
||||
*
|
||||
* Returns: (transfer full): #GIcon corresponding to the content type. Free the returned
|
||||
* object with g_object_unref()
|
||||
*/
|
||||
GIcon *
|
||||
g_content_type_get_icon (const gchar *type)
|
||||
{
|
||||
g_return_val_if_fail (type != NULL, NULL);
|
||||
|
||||
return g_content_type_get_icon_impl (type);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_get_symbolic_icon:
|
||||
* @type: a content type string
|
||||
*
|
||||
* Gets the symbolic icon for a content type.
|
||||
*
|
||||
* Returns: (transfer full): symbolic #GIcon corresponding to the content type.
|
||||
* Free the returned object with g_object_unref()
|
||||
*
|
||||
* Since: 2.34
|
||||
*/
|
||||
GIcon *
|
||||
g_content_type_get_symbolic_icon (const gchar *type)
|
||||
{
|
||||
g_return_val_if_fail (type != NULL, NULL);
|
||||
|
||||
return g_content_type_get_symbolic_icon_impl (type);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_get_generic_icon_name:
|
||||
* @type: a content type string
|
||||
*
|
||||
* Gets the generic icon name for a content type.
|
||||
*
|
||||
* See the
|
||||
* [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec)
|
||||
* specification for more on the generic icon name.
|
||||
*
|
||||
* Returns: (nullable): the registered generic icon name for the given @type,
|
||||
* or %NULL if unknown. Free with g_free()
|
||||
*
|
||||
* Since: 2.34
|
||||
*/
|
||||
gchar *
|
||||
g_content_type_get_generic_icon_name (const gchar *type)
|
||||
{
|
||||
g_return_val_if_fail (type != NULL, NULL);
|
||||
|
||||
return g_content_type_get_generic_icon_name_impl (type);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_can_be_executable:
|
||||
* @type: a content type string
|
||||
*
|
||||
* Checks if a content type can be executable. Note that for instance
|
||||
* things like text files can be executables (i.e. scripts and batch files).
|
||||
*
|
||||
* Returns: %TRUE if the file type corresponds to a type that
|
||||
* can be executable, %FALSE otherwise.
|
||||
*/
|
||||
gboolean
|
||||
g_content_type_can_be_executable (const gchar *type)
|
||||
{
|
||||
g_return_val_if_fail (type != NULL, FALSE);
|
||||
|
||||
return g_content_type_can_be_executable_impl (type);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_from_mime_type:
|
||||
* @mime_type: a mime type string
|
||||
*
|
||||
* Tries to find a content type based on the mime type name.
|
||||
*
|
||||
* Returns: (nullable): Newly allocated string with content type or
|
||||
* %NULL. Free with g_free()
|
||||
*
|
||||
* Since: 2.18
|
||||
**/
|
||||
gchar *
|
||||
g_content_type_from_mime_type (const gchar *mime_type)
|
||||
{
|
||||
g_return_val_if_fail (mime_type != NULL, NULL);
|
||||
|
||||
return g_content_type_from_mime_type_impl (mime_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_guess:
|
||||
* @filename: (nullable) (type filename): a path, or %NULL
|
||||
* @data: (nullable) (array length=data_size): a stream of data, or %NULL
|
||||
* @data_size: the size of @data
|
||||
* @result_uncertain: (out) (optional): return location for the certainty
|
||||
* of the result, or %NULL
|
||||
*
|
||||
* Guesses the content type based on example data. If the function is
|
||||
* uncertain, @result_uncertain will be set to %TRUE. Either @filename
|
||||
* or @data may be %NULL, in which case the guess will be based solely
|
||||
* on the other argument.
|
||||
*
|
||||
* Returns: a string indicating a guessed content type for the
|
||||
* given data. Free with g_free()
|
||||
*/
|
||||
gchar *
|
||||
g_content_type_guess (const gchar *filename,
|
||||
const guchar *data,
|
||||
gsize data_size,
|
||||
gboolean *result_uncertain)
|
||||
{
|
||||
return g_content_type_guess_impl (filename, data, data_size, result_uncertain);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_types_get_registered:
|
||||
*
|
||||
* Gets a list of strings containing all the registered content types
|
||||
* known to the system. The list and its data should be freed using
|
||||
* `g_list_free_full (list, g_free)`.
|
||||
*
|
||||
* Returns: (element-type utf8) (transfer full): list of the registered
|
||||
* content types
|
||||
*/
|
||||
GList *
|
||||
g_content_types_get_registered (void)
|
||||
{
|
||||
return g_content_types_get_registered_impl ();
|
||||
}
|
||||
|
||||
/**
|
||||
* g_content_type_guess_for_tree:
|
||||
* @root: the root of the tree to guess a type for
|
||||
*
|
||||
* Tries to guess the type of the tree with root @root, by
|
||||
* looking at the files it contains. The result is an array
|
||||
* of content types, with the best guess coming first.
|
||||
*
|
||||
* The types returned all have the form x-content/foo, e.g.
|
||||
* x-content/audio-cdda (for audio CDs) or x-content/image-dcf
|
||||
* (for a camera memory card). See the
|
||||
* [shared-mime-info](http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec)
|
||||
* specification for more on x-content types.
|
||||
*
|
||||
* This function is useful in the implementation of
|
||||
* g_mount_guess_content_type().
|
||||
*
|
||||
* Returns: (transfer full) (array zero-terminated=1): an %NULL-terminated
|
||||
* array of zero or more content types. Free with g_strfreev()
|
||||
*
|
||||
* Since: 2.18
|
||||
*/
|
||||
gchar **
|
||||
g_content_type_guess_for_tree (GFile *root)
|
||||
{
|
||||
g_return_val_if_fail (G_IS_FILE (root), NULL);
|
||||
|
||||
return g_content_type_guess_for_tree_impl (root);
|
||||
}
|
@ -31,6 +31,29 @@ gsize _g_unix_content_type_get_sniff_len (void);
|
||||
char * _g_unix_content_type_unalias (const char *type);
|
||||
char **_g_unix_content_type_get_parents (const char *type);
|
||||
|
||||
void g_content_type_set_mime_dirs_impl (const gchar * const *dirs);
|
||||
const gchar * const *g_content_type_get_mime_dirs_impl (void);
|
||||
gboolean g_content_type_equals_impl (const gchar *type1,
|
||||
const gchar *type2);
|
||||
gboolean g_content_type_is_a_impl (const gchar *type,
|
||||
const gchar *supertype);
|
||||
gboolean g_content_type_is_mime_type_impl (const gchar *type,
|
||||
const gchar *mime_type);
|
||||
gboolean g_content_type_is_unknown_impl (const gchar *type);
|
||||
gchar *g_content_type_get_description_impl (const gchar *type);
|
||||
char *g_content_type_get_mime_type_impl (const char *type);
|
||||
GIcon *g_content_type_get_icon_impl (const gchar *type);
|
||||
GIcon *g_content_type_get_symbolic_icon_impl (const gchar *type);
|
||||
gchar *g_content_type_get_generic_icon_name_impl (const gchar *type);
|
||||
gboolean g_content_type_can_be_executable_impl (const gchar *type);
|
||||
gchar *g_content_type_from_mime_type_impl (const gchar *mime_type);
|
||||
gchar *g_content_type_guess_impl (const gchar *filename,
|
||||
const guchar *data,
|
||||
gsize data_size,
|
||||
gboolean *result_uncertain);
|
||||
GList *g_content_types_get_registered_impl (void);
|
||||
gchar **g_content_type_guess_for_tree_impl (GFile *root);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_CONTENT_TYPE_PRIVATE_H__ */
|
||||
|
@ -489,6 +489,7 @@ gio_base_sources = files(
|
||||
'gbytesicon.c',
|
||||
'gcancellable.c',
|
||||
'gcharsetconverter.c',
|
||||
'gcontenttype.c',
|
||||
'gcontextspecificgroup.c',
|
||||
'gconverter.c',
|
||||
'gconverterinputstream.c',
|
||||
|
Loading…
Reference in New Issue
Block a user