gsettings.h 20 KB

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