gbookmarkfile.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /* gbookmarkfile.h: parsing and building desktop bookmarks
  2. *
  3. * Copyright (C) 2005-2006 Emmanuele Bassi
  4. *
  5. * SPDX-License-Identifier: LGPL-2.1-or-later
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License
  18. * along with this library; if not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef __G_BOOKMARK_FILE_H__
  21. #define __G_BOOKMARK_FILE_H__
  22. #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  23. #error "Only <glib.h> can be included directly."
  24. #endif
  25. #include <glib/gdatetime.h>
  26. #include <glib/gerror.h>
  27. #include <time.h>
  28. G_BEGIN_DECLS
  29. /**
  30. * G_BOOKMARK_FILE_ERROR:
  31. *
  32. * Error domain for bookmark file parsing.
  33. *
  34. * Errors in this domain will be from the #GBookmarkFileError
  35. * enumeration. See #GError for information on error domains.
  36. */
  37. #define G_BOOKMARK_FILE_ERROR (g_bookmark_file_error_quark ())
  38. /**
  39. * GBookmarkFileError:
  40. * @G_BOOKMARK_FILE_ERROR_INVALID_URI: URI was ill-formed
  41. * @G_BOOKMARK_FILE_ERROR_INVALID_VALUE: a requested field was not found
  42. * @G_BOOKMARK_FILE_ERROR_APP_NOT_REGISTERED: a requested application did
  43. * not register a bookmark
  44. * @G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND: a requested URI was not found
  45. * @G_BOOKMARK_FILE_ERROR_READ: document was ill formed
  46. * @G_BOOKMARK_FILE_ERROR_UNKNOWN_ENCODING: the text being parsed was
  47. * in an unknown encoding
  48. * @G_BOOKMARK_FILE_ERROR_WRITE: an error occurred while writing
  49. * @G_BOOKMARK_FILE_ERROR_FILE_NOT_FOUND: requested file was not found
  50. *
  51. * Error codes returned by bookmark file parsing.
  52. */
  53. typedef enum
  54. {
  55. G_BOOKMARK_FILE_ERROR_INVALID_URI,
  56. G_BOOKMARK_FILE_ERROR_INVALID_VALUE,
  57. G_BOOKMARK_FILE_ERROR_APP_NOT_REGISTERED,
  58. G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND,
  59. G_BOOKMARK_FILE_ERROR_READ,
  60. G_BOOKMARK_FILE_ERROR_UNKNOWN_ENCODING,
  61. G_BOOKMARK_FILE_ERROR_WRITE,
  62. G_BOOKMARK_FILE_ERROR_FILE_NOT_FOUND
  63. } GBookmarkFileError;
  64. GLIB_AVAILABLE_IN_ALL
  65. GQuark g_bookmark_file_error_quark (void);
  66. /**
  67. * GBookmarkFile:
  68. *
  69. * `GBookmarkFile` lets you parse, edit or create files containing bookmarks.
  70. *
  71. * Bookmarks refer to a URI, along with some meta-data about the resource
  72. * pointed by the URI like its MIME type, the application that is registering
  73. * the bookmark and the icon that should be used to represent the bookmark.
  74. * The data is stored using the
  75. * [Desktop Bookmark Specification](https://www.freedesktop.org/wiki/Specifications/desktop-bookmark-spec/).
  76. *
  77. * The syntax of the bookmark files is described in detail inside the
  78. * Desktop Bookmark Specification, here is a quick summary: bookmark
  79. * files use a sub-class of the XML Bookmark Exchange Language
  80. * specification, consisting of valid UTF-8 encoded XML, under the
  81. * `<xbel>` root element; each bookmark is stored inside a
  82. * `<bookmark>` element, using its URI: no relative paths can
  83. * be used inside a bookmark file. The bookmark may have a user defined
  84. * title and description, to be used instead of the URI. Under the
  85. * `<metadata>` element, with its owner attribute set to
  86. * `http://freedesktop.org`, is stored the meta-data about a resource
  87. * pointed by its URI. The meta-data consists of the resource's MIME
  88. * type; the applications that have registered a bookmark; the groups
  89. * to which a bookmark belongs to; a visibility flag, used to set the
  90. * bookmark as "private" to the applications and groups that has it
  91. * registered; the URI and MIME type of an icon, to be used when
  92. * displaying the bookmark inside a GUI.
  93. *
  94. * Here is an example of a bookmark file:
  95. * [bookmarks.xbel](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/glib/tests/bookmarks.xbel)
  96. *
  97. * A bookmark file might contain more than one bookmark; each bookmark
  98. * is accessed through its URI.
  99. *
  100. * The important caveat of bookmark files is that when you add a new
  101. * bookmark you must also add the application that is registering it, using
  102. * [method@GLib.BookmarkFile.add_application] or [method@GLib.BookmarkFile.set_application_info].
  103. * If a bookmark has no applications then it won't be dumped when creating
  104. * the on disk representation, using [method@GLib.BookmarkFile.to_data] or
  105. * [method@GLib.BookmarkFile.to_file].
  106. *
  107. * Since: 2.12
  108. */
  109. typedef struct _GBookmarkFile GBookmarkFile;
  110. GLIB_AVAILABLE_IN_ALL
  111. GBookmarkFile *g_bookmark_file_new (void);
  112. GLIB_AVAILABLE_IN_ALL
  113. void g_bookmark_file_free (GBookmarkFile *bookmark);
  114. GLIB_AVAILABLE_IN_2_76
  115. GBookmarkFile *g_bookmark_file_copy (GBookmarkFile *bookmark);
  116. GLIB_AVAILABLE_IN_ALL
  117. gboolean g_bookmark_file_load_from_file (GBookmarkFile *bookmark,
  118. const gchar *filename,
  119. GError **error);
  120. GLIB_AVAILABLE_IN_ALL
  121. gboolean g_bookmark_file_load_from_data (GBookmarkFile *bookmark,
  122. const gchar *data,
  123. gsize length,
  124. GError **error);
  125. GLIB_AVAILABLE_IN_ALL
  126. gboolean g_bookmark_file_load_from_data_dirs (GBookmarkFile *bookmark,
  127. const gchar *file,
  128. gchar **full_path,
  129. GError **error);
  130. GLIB_AVAILABLE_IN_ALL
  131. gchar * g_bookmark_file_to_data (GBookmarkFile *bookmark,
  132. gsize *length,
  133. GError **error) G_GNUC_MALLOC;
  134. GLIB_AVAILABLE_IN_ALL
  135. gboolean g_bookmark_file_to_file (GBookmarkFile *bookmark,
  136. const gchar *filename,
  137. GError **error);
  138. GLIB_AVAILABLE_IN_ALL
  139. void g_bookmark_file_set_title (GBookmarkFile *bookmark,
  140. const gchar *uri,
  141. const gchar *title);
  142. GLIB_AVAILABLE_IN_ALL
  143. gchar * g_bookmark_file_get_title (GBookmarkFile *bookmark,
  144. const gchar *uri,
  145. GError **error) G_GNUC_MALLOC;
  146. GLIB_AVAILABLE_IN_ALL
  147. void g_bookmark_file_set_description (GBookmarkFile *bookmark,
  148. const gchar *uri,
  149. const gchar *description);
  150. GLIB_AVAILABLE_IN_ALL
  151. gchar * g_bookmark_file_get_description (GBookmarkFile *bookmark,
  152. const gchar *uri,
  153. GError **error) G_GNUC_MALLOC;
  154. GLIB_AVAILABLE_IN_ALL
  155. void g_bookmark_file_set_mime_type (GBookmarkFile *bookmark,
  156. const gchar *uri,
  157. const gchar *mime_type);
  158. GLIB_AVAILABLE_IN_ALL
  159. gchar * g_bookmark_file_get_mime_type (GBookmarkFile *bookmark,
  160. const gchar *uri,
  161. GError **error) G_GNUC_MALLOC;
  162. GLIB_AVAILABLE_IN_ALL
  163. void g_bookmark_file_set_groups (GBookmarkFile *bookmark,
  164. const gchar *uri,
  165. const gchar **groups,
  166. gsize length);
  167. GLIB_AVAILABLE_IN_ALL
  168. void g_bookmark_file_add_group (GBookmarkFile *bookmark,
  169. const gchar *uri,
  170. const gchar *group);
  171. GLIB_AVAILABLE_IN_ALL
  172. gboolean g_bookmark_file_has_group (GBookmarkFile *bookmark,
  173. const gchar *uri,
  174. const gchar *group,
  175. GError **error);
  176. GLIB_AVAILABLE_IN_ALL
  177. gchar ** g_bookmark_file_get_groups (GBookmarkFile *bookmark,
  178. const gchar *uri,
  179. gsize *length,
  180. GError **error);
  181. GLIB_AVAILABLE_IN_ALL
  182. void g_bookmark_file_add_application (GBookmarkFile *bookmark,
  183. const gchar *uri,
  184. const gchar *name,
  185. const gchar *exec);
  186. GLIB_AVAILABLE_IN_ALL
  187. gboolean g_bookmark_file_has_application (GBookmarkFile *bookmark,
  188. const gchar *uri,
  189. const gchar *name,
  190. GError **error);
  191. GLIB_AVAILABLE_IN_ALL
  192. gchar ** g_bookmark_file_get_applications (GBookmarkFile *bookmark,
  193. const gchar *uri,
  194. gsize *length,
  195. GError **error);
  196. GLIB_DEPRECATED_IN_2_66_FOR(g_bookmark_file_set_application_info)
  197. gboolean g_bookmark_file_set_app_info (GBookmarkFile *bookmark,
  198. const gchar *uri,
  199. const gchar *name,
  200. const gchar *exec,
  201. gint count,
  202. time_t stamp,
  203. GError **error);
  204. GLIB_AVAILABLE_IN_2_66
  205. gboolean g_bookmark_file_set_application_info (GBookmarkFile *bookmark,
  206. const char *uri,
  207. const char *name,
  208. const char *exec,
  209. int count,
  210. GDateTime *stamp,
  211. GError **error);
  212. GLIB_DEPRECATED_IN_2_66_FOR(g_bookmark_file_get_application_info)
  213. gboolean g_bookmark_file_get_app_info (GBookmarkFile *bookmark,
  214. const gchar *uri,
  215. const gchar *name,
  216. gchar **exec,
  217. guint *count,
  218. time_t *stamp,
  219. GError **error);
  220. GLIB_AVAILABLE_IN_2_66
  221. gboolean g_bookmark_file_get_application_info (GBookmarkFile *bookmark,
  222. const char *uri,
  223. const char *name,
  224. char **exec,
  225. unsigned int *count,
  226. GDateTime **stamp,
  227. GError **error);
  228. GLIB_AVAILABLE_IN_ALL
  229. void g_bookmark_file_set_is_private (GBookmarkFile *bookmark,
  230. const gchar *uri,
  231. gboolean is_private);
  232. GLIB_AVAILABLE_IN_ALL
  233. gboolean g_bookmark_file_get_is_private (GBookmarkFile *bookmark,
  234. const gchar *uri,
  235. GError **error);
  236. GLIB_AVAILABLE_IN_ALL
  237. void g_bookmark_file_set_icon (GBookmarkFile *bookmark,
  238. const gchar *uri,
  239. const gchar *href,
  240. const gchar *mime_type);
  241. GLIB_AVAILABLE_IN_ALL
  242. gboolean g_bookmark_file_get_icon (GBookmarkFile *bookmark,
  243. const gchar *uri,
  244. gchar **href,
  245. gchar **mime_type,
  246. GError **error);
  247. GLIB_DEPRECATED_IN_2_66_FOR(g_bookmark_file_set_added_date_time)
  248. void g_bookmark_file_set_added (GBookmarkFile *bookmark,
  249. const gchar *uri,
  250. time_t added);
  251. GLIB_AVAILABLE_IN_2_66
  252. void g_bookmark_file_set_added_date_time (GBookmarkFile *bookmark,
  253. const char *uri,
  254. GDateTime *added);
  255. GLIB_DEPRECATED_IN_2_66_FOR(g_bookmark_file_get_added_date_time)
  256. time_t g_bookmark_file_get_added (GBookmarkFile *bookmark,
  257. const gchar *uri,
  258. GError **error);
  259. GLIB_AVAILABLE_IN_2_66
  260. GDateTime *g_bookmark_file_get_added_date_time (GBookmarkFile *bookmark,
  261. const char *uri,
  262. GError **error);
  263. GLIB_DEPRECATED_IN_2_66_FOR(g_bookmark_file_set_modified_date_time)
  264. void g_bookmark_file_set_modified (GBookmarkFile *bookmark,
  265. const gchar *uri,
  266. time_t modified);
  267. GLIB_AVAILABLE_IN_2_66
  268. void g_bookmark_file_set_modified_date_time (GBookmarkFile *bookmark,
  269. const char *uri,
  270. GDateTime *modified);
  271. GLIB_DEPRECATED_IN_2_66_FOR(g_bookmark_file_get_modified_date_time)
  272. time_t g_bookmark_file_get_modified (GBookmarkFile *bookmark,
  273. const gchar *uri,
  274. GError **error);
  275. GLIB_AVAILABLE_IN_2_66
  276. GDateTime *g_bookmark_file_get_modified_date_time (GBookmarkFile *bookmark,
  277. const char *uri,
  278. GError **error);
  279. GLIB_DEPRECATED_IN_2_66_FOR(g_bookmark_file_set_visited_date_time)
  280. void g_bookmark_file_set_visited (GBookmarkFile *bookmark,
  281. const gchar *uri,
  282. time_t visited);
  283. GLIB_AVAILABLE_IN_2_66
  284. void g_bookmark_file_set_visited_date_time (GBookmarkFile *bookmark,
  285. const char *uri,
  286. GDateTime *visited);
  287. GLIB_DEPRECATED_IN_2_66_FOR(g_bookmark_file_get_visited_date_time)
  288. time_t g_bookmark_file_get_visited (GBookmarkFile *bookmark,
  289. const gchar *uri,
  290. GError **error);
  291. GLIB_AVAILABLE_IN_2_66
  292. GDateTime *g_bookmark_file_get_visited_date_time (GBookmarkFile *bookmark,
  293. const char *uri,
  294. GError **error);
  295. GLIB_AVAILABLE_IN_ALL
  296. gboolean g_bookmark_file_has_item (GBookmarkFile *bookmark,
  297. const gchar *uri);
  298. GLIB_AVAILABLE_IN_ALL
  299. gint g_bookmark_file_get_size (GBookmarkFile *bookmark);
  300. GLIB_AVAILABLE_IN_ALL
  301. gchar ** g_bookmark_file_get_uris (GBookmarkFile *bookmark,
  302. gsize *length);
  303. GLIB_AVAILABLE_IN_ALL
  304. gboolean g_bookmark_file_remove_group (GBookmarkFile *bookmark,
  305. const gchar *uri,
  306. const gchar *group,
  307. GError **error);
  308. GLIB_AVAILABLE_IN_ALL
  309. gboolean g_bookmark_file_remove_application (GBookmarkFile *bookmark,
  310. const gchar *uri,
  311. const gchar *name,
  312. GError **error);
  313. GLIB_AVAILABLE_IN_ALL
  314. gboolean g_bookmark_file_remove_item (GBookmarkFile *bookmark,
  315. const gchar *uri,
  316. GError **error);
  317. GLIB_AVAILABLE_IN_ALL
  318. gboolean g_bookmark_file_move_item (GBookmarkFile *bookmark,
  319. const gchar *old_uri,
  320. const gchar *new_uri,
  321. GError **error);
  322. G_END_DECLS
  323. #endif /* __G_BOOKMARK_FILE_H__ */