gsettings.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. /*
  2. * Copyright © 2009, 2010 Codethink Limited
  3. *
  4. * SPDX-License-Identifier: LGPL-2.1-or-later
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * Author: Ryan Lortie <desrt@desrt.ca>
  20. */
  21. #ifndef __G_SETTINGS_H__
  22. #define __G_SETTINGS_H__
  23. #if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
  24. #error "Only <gio/gio.h> can be included directly."
  25. #endif
  26. #include <gio/gsettingsschema.h>
  27. #include <gio/giotypes.h>
  28. G_BEGIN_DECLS
  29. #define G_TYPE_SETTINGS (g_settings_get_type ())
  30. #define G_SETTINGS(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
  31. G_TYPE_SETTINGS, GSettings))
  32. #define G_SETTINGS_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), \
  33. G_TYPE_SETTINGS, GSettingsClass))
  34. #define G_IS_SETTINGS(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), G_TYPE_SETTINGS))
  35. #define G_IS_SETTINGS_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_SETTINGS))
  36. #define G_SETTINGS_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), \
  37. G_TYPE_SETTINGS, GSettingsClass))
  38. typedef struct _GSettingsPrivate GSettingsPrivate;
  39. typedef struct _GSettingsClass GSettingsClass;
  40. struct _GSettingsClass
  41. {
  42. GObjectClass parent_class;
  43. /* Signals */
  44. void (*writable_changed) (GSettings *settings,
  45. const gchar *key);
  46. void (*changed) (GSettings *settings,
  47. const gchar *key);
  48. gboolean (*writable_change_event) (GSettings *settings,
  49. GQuark key);
  50. gboolean (*change_event) (GSettings *settings,
  51. const GQuark *keys,
  52. gint n_keys);
  53. gpointer padding[20];
  54. };
  55. struct _GSettings
  56. {
  57. GObject parent_instance;
  58. GSettingsPrivate *priv;
  59. };
  60. GIO_AVAILABLE_IN_ALL
  61. GType g_settings_get_type (void);
  62. GIO_DEPRECATED_IN_2_40_FOR(g_settings_schema_source_list_schemas)
  63. const gchar * const * g_settings_list_schemas (void);
  64. GIO_DEPRECATED_IN_2_40_FOR(g_settings_schema_source_list_schemas)
  65. const gchar * const * g_settings_list_relocatable_schemas (void);
  66. GIO_AVAILABLE_IN_ALL
  67. GSettings * g_settings_new (const gchar *schema_id);
  68. GIO_AVAILABLE_IN_ALL
  69. GSettings * g_settings_new_with_path (const gchar *schema_id,
  70. const gchar *path);
  71. GIO_AVAILABLE_IN_ALL
  72. GSettings * g_settings_new_with_backend (const gchar *schema_id,
  73. GSettingsBackend *backend);
  74. GIO_AVAILABLE_IN_ALL
  75. GSettings * g_settings_new_with_backend_and_path (const gchar *schema_id,
  76. GSettingsBackend *backend,
  77. const gchar *path);
  78. GIO_AVAILABLE_IN_2_32
  79. GSettings * g_settings_new_full (GSettingsSchema *schema,
  80. GSettingsBackend *backend,
  81. const gchar *path);
  82. GIO_AVAILABLE_IN_ALL
  83. gchar ** g_settings_list_children (GSettings *settings);
  84. GIO_DEPRECATED_IN_2_46_FOR(g_settings_schema_list_keys)
  85. gchar ** g_settings_list_keys (GSettings *settings);
  86. GIO_DEPRECATED_IN_2_40_FOR(g_settings_schema_key_get_range)
  87. GVariant * g_settings_get_range (GSettings *settings,
  88. const gchar *key);
  89. GIO_DEPRECATED_IN_2_40_FOR(g_settings_schema_key_range_check)
  90. gboolean g_settings_range_check (GSettings *settings,
  91. const gchar *key,
  92. GVariant *value);
  93. GIO_AVAILABLE_IN_ALL
  94. gboolean g_settings_set_value (GSettings *settings,
  95. const gchar *key,
  96. GVariant *value);
  97. GIO_AVAILABLE_IN_ALL
  98. GVariant * g_settings_get_value (GSettings *settings,
  99. const gchar *key);
  100. GIO_AVAILABLE_IN_2_40
  101. GVariant * g_settings_get_user_value (GSettings *settings,
  102. const gchar *key);
  103. GIO_AVAILABLE_IN_2_40
  104. GVariant * g_settings_get_default_value (GSettings *settings,
  105. const gchar *key);
  106. GIO_AVAILABLE_IN_ALL
  107. gboolean g_settings_set (GSettings *settings,
  108. const gchar *key,
  109. const gchar *format,
  110. ...);
  111. GIO_AVAILABLE_IN_ALL
  112. void g_settings_get (GSettings *settings,
  113. const gchar *key,
  114. const gchar *format,
  115. ...);
  116. GIO_AVAILABLE_IN_ALL
  117. void g_settings_reset (GSettings *settings,
  118. const gchar *key);
  119. GIO_AVAILABLE_IN_ALL
  120. gint g_settings_get_int (GSettings *settings,
  121. const gchar *key);
  122. GIO_AVAILABLE_IN_ALL
  123. gboolean g_settings_set_int (GSettings *settings,
  124. const gchar *key,
  125. gint value);
  126. GIO_AVAILABLE_IN_2_50
  127. gint64 g_settings_get_int64 (GSettings *settings,
  128. const gchar *key);
  129. GIO_AVAILABLE_IN_2_50
  130. gboolean g_settings_set_int64 (GSettings *settings,
  131. const gchar *key,
  132. gint64 value);
  133. GIO_AVAILABLE_IN_2_32
  134. guint g_settings_get_uint (GSettings *settings,
  135. const gchar *key);
  136. GIO_AVAILABLE_IN_2_32
  137. gboolean g_settings_set_uint (GSettings *settings,
  138. const gchar *key,
  139. guint value);
  140. GIO_AVAILABLE_IN_2_50
  141. guint64 g_settings_get_uint64 (GSettings *settings,
  142. const gchar *key);
  143. GIO_AVAILABLE_IN_2_50
  144. gboolean g_settings_set_uint64 (GSettings *settings,
  145. const gchar *key,
  146. guint64 value);
  147. GIO_AVAILABLE_IN_ALL
  148. gchar * g_settings_get_string (GSettings *settings,
  149. const gchar *key);
  150. GIO_AVAILABLE_IN_ALL
  151. gboolean g_settings_set_string (GSettings *settings,
  152. const gchar *key,
  153. const gchar *value);
  154. GIO_AVAILABLE_IN_ALL
  155. gboolean g_settings_get_boolean (GSettings *settings,
  156. const gchar *key);
  157. GIO_AVAILABLE_IN_ALL
  158. gboolean g_settings_set_boolean (GSettings *settings,
  159. const gchar *key,
  160. gboolean value);
  161. GIO_AVAILABLE_IN_ALL
  162. gdouble g_settings_get_double (GSettings *settings,
  163. const gchar *key);
  164. GIO_AVAILABLE_IN_ALL
  165. gboolean g_settings_set_double (GSettings *settings,
  166. const gchar *key,
  167. gdouble value);
  168. GIO_AVAILABLE_IN_ALL
  169. gchar ** g_settings_get_strv (GSettings *settings,
  170. const gchar *key);
  171. GIO_AVAILABLE_IN_ALL
  172. gboolean g_settings_set_strv (GSettings *settings,
  173. const gchar *key,
  174. const gchar *const *value);
  175. GIO_AVAILABLE_IN_ALL
  176. gint g_settings_get_enum (GSettings *settings,
  177. const gchar *key);
  178. GIO_AVAILABLE_IN_ALL
  179. gboolean g_settings_set_enum (GSettings *settings,
  180. const gchar *key,
  181. gint value);
  182. GIO_AVAILABLE_IN_ALL
  183. guint g_settings_get_flags (GSettings *settings,
  184. const gchar *key);
  185. GIO_AVAILABLE_IN_ALL
  186. gboolean g_settings_set_flags (GSettings *settings,
  187. const gchar *key,
  188. guint value);
  189. GIO_AVAILABLE_IN_ALL
  190. GSettings * g_settings_get_child (GSettings *settings,
  191. const gchar *name);
  192. GIO_AVAILABLE_IN_ALL
  193. gboolean g_settings_is_writable (GSettings *settings,
  194. const gchar *name);
  195. GIO_AVAILABLE_IN_ALL
  196. void g_settings_delay (GSettings *settings);
  197. GIO_AVAILABLE_IN_ALL
  198. void g_settings_apply (GSettings *settings);
  199. GIO_AVAILABLE_IN_ALL
  200. void g_settings_revert (GSettings *settings);
  201. GIO_AVAILABLE_IN_ALL
  202. gboolean g_settings_get_has_unapplied (GSettings *settings);
  203. GIO_AVAILABLE_IN_ALL
  204. void g_settings_sync (void);
  205. /**
  206. * GSettingsBindSetMapping:
  207. * @value: a #GValue containing the property value to map
  208. * @expected_type: the #GVariantType to create
  209. * @user_data: user data that was specified when the binding was created
  210. *
  211. * The type for the function that is used to convert an object property
  212. * value to a #GVariant for storing it in #GSettings.
  213. *
  214. * Returns: a new #GVariant holding the data from @value,
  215. * or %NULL in case of an error
  216. */
  217. typedef GVariant * (*GSettingsBindSetMapping) (const GValue *value,
  218. const GVariantType *expected_type,
  219. gpointer user_data);
  220. /**
  221. * GSettingsBindGetMapping:
  222. * @value: return location for the property value
  223. * @variant: the #GVariant
  224. * @user_data: user data that was specified when the binding was created
  225. *
  226. * The type for the function that is used to convert from #GSettings to
  227. * an object property. The @value is already initialized to hold values
  228. * of the appropriate type.
  229. *
  230. * Returns: %TRUE if the conversion succeeded, %FALSE in case of an error
  231. */
  232. typedef gboolean (*GSettingsBindGetMapping) (GValue *value,
  233. GVariant *variant,
  234. gpointer user_data);
  235. /**
  236. * GSettingsGetMapping:
  237. * @value: the #GVariant to map, or %NULL
  238. * @result: (out): the result of the mapping
  239. * @user_data: (closure): the user data that was passed to
  240. * g_settings_get_mapped()
  241. *
  242. * The type of the function that is used to convert from a value stored
  243. * in a #GSettings to a value that is useful to the application.
  244. *
  245. * If the value is successfully mapped, the result should be stored at
  246. * @result and %TRUE returned. If mapping fails (for example, if @value
  247. * is not in the right format) then %FALSE should be returned.
  248. *
  249. * If @value is %NULL then it means that the mapping function is being
  250. * given a "last chance" to successfully return a valid value. %TRUE
  251. * must be returned in this case.
  252. *
  253. * Returns: %TRUE if the conversion succeeded, %FALSE in case of an error
  254. **/
  255. typedef gboolean (*GSettingsGetMapping) (GVariant *value,
  256. gpointer *result,
  257. gpointer user_data);
  258. /**
  259. * GSettingsBindFlags:
  260. * @G_SETTINGS_BIND_DEFAULT: Equivalent to `G_SETTINGS_BIND_GET|G_SETTINGS_BIND_SET`
  261. * @G_SETTINGS_BIND_GET: Update the #GObject property when the setting changes.
  262. * It is an error to use this flag if the property is not writable.
  263. * @G_SETTINGS_BIND_SET: Update the setting when the #GObject property changes.
  264. * It is an error to use this flag if the property is not readable.
  265. * @G_SETTINGS_BIND_NO_SENSITIVITY: Do not try to bind a "sensitivity" property to the writability of the setting
  266. * @G_SETTINGS_BIND_GET_NO_CHANGES: When set in addition to %G_SETTINGS_BIND_GET, set the #GObject property
  267. * value initially from the setting, but do not listen for changes of the setting
  268. * @G_SETTINGS_BIND_INVERT_BOOLEAN: When passed to g_settings_bind(), uses a pair of mapping functions that invert
  269. * the boolean value when mapping between the setting and the property. The setting and property must both
  270. * be booleans. You cannot pass this flag to g_settings_bind_with_mapping().
  271. *
  272. * Flags used when creating a binding. These flags determine in which
  273. * direction the binding works. The default is to synchronize in both
  274. * directions.
  275. */
  276. typedef enum
  277. {
  278. G_SETTINGS_BIND_DEFAULT,
  279. G_SETTINGS_BIND_GET = (1<<0),
  280. G_SETTINGS_BIND_SET = (1<<1),
  281. G_SETTINGS_BIND_NO_SENSITIVITY = (1<<2),
  282. G_SETTINGS_BIND_GET_NO_CHANGES = (1<<3),
  283. G_SETTINGS_BIND_INVERT_BOOLEAN = (1<<4)
  284. } GSettingsBindFlags;
  285. GIO_AVAILABLE_IN_ALL
  286. void g_settings_bind (GSettings *settings,
  287. const gchar *key,
  288. gpointer object,
  289. const gchar *property,
  290. GSettingsBindFlags flags);
  291. GIO_AVAILABLE_IN_ALL
  292. void g_settings_bind_with_mapping (GSettings *settings,
  293. const gchar *key,
  294. gpointer object,
  295. const gchar *property,
  296. GSettingsBindFlags flags,
  297. GSettingsBindGetMapping get_mapping,
  298. GSettingsBindSetMapping set_mapping,
  299. gpointer user_data,
  300. GDestroyNotify destroy);
  301. GIO_AVAILABLE_IN_2_82
  302. void g_settings_bind_with_mapping_closures (GSettings *settings,
  303. const char *key,
  304. GObject *object,
  305. const char *property,
  306. GSettingsBindFlags flags,
  307. GClosure *get_mapping,
  308. GClosure *set_mapping);
  309. GIO_AVAILABLE_IN_ALL
  310. void g_settings_bind_writable (GSettings *settings,
  311. const gchar *key,
  312. gpointer object,
  313. const gchar *property,
  314. gboolean inverted);
  315. GIO_AVAILABLE_IN_ALL
  316. void g_settings_unbind (gpointer object,
  317. const gchar *property);
  318. GIO_AVAILABLE_IN_2_32
  319. GAction * g_settings_create_action (GSettings *settings,
  320. const gchar *key);
  321. GIO_AVAILABLE_IN_ALL
  322. gpointer g_settings_get_mapped (GSettings *settings,
  323. const gchar *key,
  324. GSettingsGetMapping mapping,
  325. gpointer user_data);
  326. G_END_DECLS
  327. #endif /* __G_SETTINGS_H__ */