Synopsis#include <glib.h> GBookmarkFile; #define G_BOOKMARK_FILE_ERROR enum GBookmarkFileError; GBookmarkFile* g_bookmark_file_new (void); void g_bookmark_file_free (GBookmarkFile *bookmark); gboolean g_bookmark_file_load_from_file (GBookmarkFile *bookmark, const gchar *filename, GError **error); gboolean g_bookmark_file_load_from_data (GBookmarkFile *bookmark, const gchar *data, gsize length, GError **error); gboolean g_bookmark_file_load_from_data_dirs (GBookmarkFile *bookmark, const gchar *file, gchar **full_path, GError **error); gchar* g_bookmark_file_to_data (GBookmarkFile *bookmark, gsize *length, GError **error); gboolean g_bookmark_file_to_file (GBookmarkFile *bookmark, const gchar *filename, GError **error); gboolean g_bookmark_file_has_item (GBookmarkFile *bookmark, const gchar *uri); gboolean g_bookmark_file_has_group (GBookmarkFile *bookmark, const gchar *uri, const gchar *group, GError **error); gboolean g_bookmark_file_has_application (GBookmarkFile *bookmark, const gchar *uri, const gchar *name, GError **error); gint g_bookmark_file_get_size (GBookmarkFile *bookmark); gchar** g_bookmark_file_get_uris (GBookmarkFile *bookmark, gsize *length); gchar* g_bookmark_file_get_title (GBookmarkFile *bookmark, const gchar *uri, GError **error); gchar* g_bookmark_file_get_description (GBookmarkFile *bookmark, const gchar *uri, GError **error); gchar* g_bookmark_file_get_mime_type (GBookmarkFile *bookmark, const gchar *uri, GError **error); gboolean g_bookmark_file_get_is_private (GBookmarkFile *bookmark, const gchar *uri, GError **error); gboolean g_bookmark_file_get_icon (GBookmarkFile *bookmark, const gchar *uri, gchar **href, gchar **mime_type, GError **error); time_t g_bookmark_file_get_added (GBookmarkFile *bookmark, const gchar *uri, GError **error); time_t g_bookmark_file_get_modified (GBookmarkFile *bookmark, const gchar *uri, GError **error); time_t g_bookmark_file_get_visited (GBookmarkFile *bookmark, const gchar *uri, GError **error); gchar** g_bookmark_file_get_groups (GBookmarkFile *bookmark, const gchar *uri, gsize *length, GError **error); gchar** g_bookmark_file_get_applications (GBookmarkFile *bookmark, const gchar *uri, gsize *length, GError **error); gboolean g_bookmark_file_get_app_info (GBookmarkFile *bookmark, const gchar *uri, const gchar *name, gchar **exec, guint *count, time_t *stamp, GError **error); void g_bookmark_file_set_title (GBookmarkFile *bookmark, const gchar *uri, const gchar *title); void g_bookmark_file_set_description (GBookmarkFile *bookmark, const gchar *uri, const gchar *description); void g_bookmark_file_set_mime_type (GBookmarkFile *bookmark, const gchar *uri, const gchar *mime_type); void g_bookmark_file_set_is_private (GBookmarkFile *bookmark, const gchar *uri, gboolean is_private); void g_bookmark_file_set_icon (GBookmarkFile *bookmark, const gchar *uri, const gchar *href, const gchar *mime_type); void g_bookmark_file_set_added (GBookmarkFile *bookmark, const gchar *uri, time_t added); void g_bookmark_file_set_groups (GBookmarkFile *bookmark, const gchar *uri, const gchar **groups, gsize length); void g_bookmark_file_set_modified (GBookmarkFile *bookmark, const gchar *uri, time_t modified); void g_bookmark_file_set_visited (GBookmarkFile *bookmark, const gchar *uri, time_t visited); gboolean g_bookmark_file_set_app_info (GBookmarkFile *bookmark, const gchar *uri, const gchar *name, const gchar *exec, gint count, time_t stamp, GError **error); void g_bookmark_file_add_group (GBookmarkFile *bookmark, const gchar *uri, const gchar *group); void g_bookmark_file_add_application (GBookmarkFile *bookmark, const gchar *uri, const gchar *name, const gchar *exec); gboolean g_bookmark_file_remove_group (GBookmarkFile *bookmark, const gchar *uri, const gchar *group, GError **error); gboolean g_bookmark_file_remove_application (GBookmarkFile *bookmark, const gchar *uri, const gchar *name, GError **error); gboolean g_bookmark_file_remove_item (GBookmarkFile *bookmark, const gchar *uri, GError **error); gboolean g_bookmark_file_move_item (GBookmarkFile *bookmark, const gchar *old_uri, const gchar *new_uri, GError **error); DescriptionGBookmarkFile lets you parse, edit or create files containing bookmarks to URI, along with some meta-data about the resource pointed by the URI like its MIME type, the application that is registering the bookmark and the icon that should be used to represent the bookmark. The data is stored using the Desktop Bookmark Specification.
The syntax of the bookmark files is described in detail inside the Desktop
Bookmark Specification, here is a quick summary: bookmark files use a sub-class
of the
XML Bookmark Exchange Language specification, consisting
of valid UTF-8 encoded XML, under the <?xml version="1.0"?> <!DOCTYPE xbel PUBLIC "+//IDN python.org//DTD XML Bookmark Exchange Language 1.0//EN//XML" "http://www.python.org/topics/xml/dtds/xbel-1.0.dtd"> <xbel version="1.0" xmlns:mime="http://www.freedesktop.org/standards/shared-mime-info" xmlns:bookmark="http://www.freedesktop.org/standards/desktop-bookmarks"> <bookmark href="file:///home/ebassi/bookmark-spec/bookmark-spec.xml"> <title>Desktop Bookmarks Spec</title> <info> <metadata owner="http://freedesktop.org"> <mime:mime-type>text/xml</mime:mime-type> <bookmark:applications> <bookmark:application name="GEdit" count="2" exec="gedit %u" timestamp="1115726763"/> <bookmark:application name="GViM" count="7" exec="gvim %f" timestamp="1115726812"/> </bookmark:applications> <bookmark:groups> <bookmark:group>Editors</bookmark:group> </bookmark:groups> </metadata> </info> </bookmark> </xbel> A bookmark file might contain more than one bookmark; each bookmark is accessed through its URI.
The important caveat of bookmark files is that when you add a new bookmark you
must also add the application that is registering it, using
The GBookmarkFile parser was added in GLib 2.12. DetailsGBookmarkFiletypedef struct _GBookmarkFile GBookmarkFile; The GBookmarkFile struct contains only private data and should not be used directly. G_BOOKMARK_FILE_ERROR#define G_BOOKMARK_FILE_ERROR Error domain for bookmark file parsing. Errors in this domain will be from the GBookmarkFileError enumeration. See GError for informations on error domains. enum GBookmarkFileErrortypedef enum { G_BOOKMARK_FILE_ERROR_INVALID_URI, G_BOOKMARK_FILE_ERROR_INVALID_VALUE, G_BOOKMARK_FILE_ERROR_APP_NOT_REGISTERED, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND, G_BOOKMARK_FILE_ERROR_READ, G_BOOKMARK_FILE_ERROR_UNKNOWN_ENCODING, G_BOOKMARK_FILE_ERROR_WRITE, G_BOOKMARK_FILE_ERROR_FILE_NOT_FOUND } GBookmarkFileError; Error codes returned by bookmark file parsing.
g_bookmark_file_new ()GBookmarkFile* g_bookmark_file_new (void); Creates a new empty GBookmarkFile object.
Use
Since 2.12 g_bookmark_file_free ()void g_bookmark_file_free (GBookmarkFile *bookmark); Frees a GBookmarkFile.
Since 2.12 g_bookmark_file_load_from_file ()gboolean g_bookmark_file_load_from_file (GBookmarkFile *bookmark, const gchar *filename, GError **error);
Loads a desktop bookmark file into an empty GBookmarkFile structure.
If the file could not be loaded then
Since 2.12 g_bookmark_file_load_from_data ()gboolean g_bookmark_file_load_from_data (GBookmarkFile *bookmark, const gchar *data, gsize length, GError **error);
Loads a bookmark file from memory into an empty GBookmarkFile
structure. If the object cannot be created then
Since 2.12 g_bookmark_file_load_from_data_dirs ()gboolean g_bookmark_file_load_from_data_dirs (GBookmarkFile *bookmark, const gchar *file, gchar **full_path, GError **error);
This function looks for a desktop bookmark file named
Since 2.12 g_bookmark_file_to_data ()gchar* g_bookmark_file_to_data (GBookmarkFile *bookmark, gsize *length, GError **error);
This function outputs
Since 2.12 g_bookmark_file_to_file ()gboolean g_bookmark_file_to_file (GBookmarkFile *bookmark, const gchar *filename, GError **error);
This function outputs
Since 2.12 g_bookmark_file_has_item ()gboolean g_bookmark_file_has_item (GBookmarkFile *bookmark, const gchar *uri);
Looks whether the desktop bookmark has an item with its URI set to
Since 2.12 g_bookmark_file_has_group ()gboolean g_bookmark_file_has_group (GBookmarkFile *bookmark, const gchar *uri, const gchar *group, GError **error);
Checks whether
In the event the URI cannot be found,
Since 2.12 g_bookmark_file_has_application ()gboolean g_bookmark_file_has_application (GBookmarkFile *bookmark, const gchar *uri, const gchar *name, GError **error);
Checks whether the bookmark for
In the event the URI cannot be found,
Since 2.12 g_bookmark_file_get_size ()gint g_bookmark_file_get_size (GBookmarkFile *bookmark);
Gets the number of bookmarks inside
Since 2.12 g_bookmark_file_get_uris ()gchar** g_bookmark_file_get_uris (GBookmarkFile *bookmark, gsize *length);
Returns all URIs of the bookmarks in the bookmark file
Since 2.12 g_bookmark_file_get_title ()gchar* g_bookmark_file_get_title (GBookmarkFile *bookmark, const gchar *uri, GError **error);
Returns the title of the bookmark for
If
In the event the URI cannot be found,
Since 2.12 g_bookmark_file_get_description ()gchar* g_bookmark_file_get_description (GBookmarkFile *bookmark, const gchar *uri, GError **error);
Retrieves the description of the bookmark for
In the event the URI cannot be found,
Since 2.12 g_bookmark_file_get_mime_type ()gchar* g_bookmark_file_get_mime_type (GBookmarkFile *bookmark, const gchar *uri, GError **error);
Retrieves the MIME type of the resource pointed by
In the event the URI cannot be found,
Since 2.12 g_bookmark_file_get_is_private ()gboolean g_bookmark_file_get_is_private (GBookmarkFile *bookmark, const gchar *uri, GError **error);
Gets whether the private flag of the bookmark for
In the event the URI cannot be found,
Since 2.12 g_bookmark_file_get_icon ()gboolean g_bookmark_file_get_icon (GBookmarkFile *bookmark, const gchar *uri, gchar **href, gchar **mime_type, GError **error);
Gets the icon of the bookmark for
In the event the URI cannot be found,
Since 2.12 g_bookmark_file_get_added ()time_t g_bookmark_file_get_added (GBookmarkFile *bookmark, const gchar *uri, GError **error);
Gets the time the bookmark for
In the event the URI cannot be found, -1 is returned and
Since 2.12 g_bookmark_file_get_modified ()time_t g_bookmark_file_get_modified (GBookmarkFile *bookmark, const gchar *uri, GError **error);
Gets the time when the bookmark for
In the event the URI cannot be found, -1 is returned and
Since 2.12 g_bookmark_file_get_visited ()time_t g_bookmark_file_get_visited (GBookmarkFile *bookmark, const gchar *uri, GError **error);
Gets the time the bookmark for
In the event the URI cannot be found, -1 is returned and
Since 2.12 g_bookmark_file_get_groups ()gchar** g_bookmark_file_get_groups (GBookmarkFile *bookmark, const gchar *uri, gsize *length, GError **error);
Retrieves the list of group names of the bookmark for
In the event the URI cannot be found,
The returned array is
Since 2.12 g_bookmark_file_get_applications ()gchar** g_bookmark_file_get_applications (GBookmarkFile *bookmark, const gchar *uri, gsize *length, GError **error);
Retrieves the names of the applications that have registered the
bookmark for
In the event the URI cannot be found,
Since 2.12 g_bookmark_file_get_app_info ()gboolean g_bookmark_file_get_app_info (GBookmarkFile *bookmark, const gchar *uri, const gchar *name, gchar **exec, guint *count, time_t *stamp, GError **error);
Gets the registration informations of
The string returned in
In the event the URI cannot be found,
Since 2.12 g_bookmark_file_set_title ()void g_bookmark_file_set_title (GBookmarkFile *bookmark, const gchar *uri, const gchar *title);
Sets
If
If a bookmark for
Since 2.12 g_bookmark_file_set_description ()void g_bookmark_file_set_description (GBookmarkFile *bookmark, const gchar *uri, const gchar *description);
Sets
If
If a bookmark for
Since 2.12 g_bookmark_file_set_mime_type ()void g_bookmark_file_set_mime_type (GBookmarkFile *bookmark, const gchar *uri, const gchar *mime_type);
Sets
If a bookmark for
Since 2.12 g_bookmark_file_set_is_private ()void g_bookmark_file_set_is_private (GBookmarkFile *bookmark, const gchar *uri, gboolean is_private);
Sets the private flag of the bookmark for
If a bookmark for
Since 2.12 g_bookmark_file_set_icon ()void g_bookmark_file_set_icon (GBookmarkFile *bookmark, const gchar *uri, const gchar *href, const gchar *mime_type);
Sets the icon for the bookmark for
If no bookmark for
Since 2.12 g_bookmark_file_set_added ()void g_bookmark_file_set_added (GBookmarkFile *bookmark, const gchar *uri, time_t added);
Sets the time the bookmark for
If no bookmark for
Since 2.12 g_bookmark_file_set_groups ()void g_bookmark_file_set_groups (GBookmarkFile *bookmark, const gchar *uri, const gchar **groups, gsize length);
Sets a list of group names for the item with URI
If
Since 2.12 g_bookmark_file_set_modified ()void g_bookmark_file_set_modified (GBookmarkFile *bookmark, const gchar *uri, time_t modified);
Sets the last time the bookmark for
If no bookmark for
The "modified" time should only be set when the bookmark's meta-data
was actually changed. Every function of GBookmarkFile that
modifies a bookmark also changes the modification time, except for
Since 2.12 g_bookmark_file_set_visited ()void g_bookmark_file_set_visited (GBookmarkFile *bookmark, const gchar *uri, time_t visited);
Sets the time the bookmark for
If no bookmark for
The "visited" time should only be set if the bookmark was launched,
either using the command line retrieved by
Since 2.12 g_bookmark_file_set_app_info ()gboolean g_bookmark_file_set_app_info (GBookmarkFile *bookmark, const gchar *uri, const gchar *name, const gchar *exec, gint count, time_t stamp, GError **error);
Sets the meta-data of application
You should rarely use this function; use
If you try to remove an application by setting its registration count to
zero, and no bookmark for
Since 2.12 g_bookmark_file_add_group ()void g_bookmark_file_add_group (GBookmarkFile *bookmark, const gchar *uri, const gchar *group);
Adds
If no bookmark for
Since 2.12 g_bookmark_file_add_application ()void g_bookmark_file_add_application (GBookmarkFile *bookmark, const gchar *uri, const gchar *name, const gchar *exec);
Adds the application with Every bookmark inside a GBookmarkFile must have at least an application registered. Each application must provide a name, a command line useful for launching the bookmark, the number of times the bookmark has been registered by the application and the last time the application registered this bookmark.
If
This function will automatically take care of updating the
registrations count and timestamping in case an application
with the same
If no bookmark for
Since 2.12 g_bookmark_file_remove_group ()gboolean g_bookmark_file_remove_group (GBookmarkFile *bookmark, const gchar *uri, const gchar *group, GError **error);
Removes
In the event the URI cannot be found,
Since 2.12 g_bookmark_file_remove_application ()gboolean g_bookmark_file_remove_application (GBookmarkFile *bookmark, const gchar *uri, const gchar *name, GError **error);
Removes application registered with
In the event the URI cannot be found,
Since 2.12 g_bookmark_file_remove_item ()gboolean g_bookmark_file_remove_item (GBookmarkFile *bookmark, const gchar *uri, GError **error);
Removes the bookmark for
Since 2.12 g_bookmark_file_move_item ()gboolean g_bookmark_file_move_item (GBookmarkFile *bookmark, const gchar *old_uri, const gchar *new_uri, GError **error);
Changes the URI of a bookmark item from
In the event the URI cannot be found,
Since 2.12 |