gsettings.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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.1 of the License, 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 <desrt@desrt.ca>
  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_DEPRECATED_IN_2_46_FOR(g_settings_schema_list_keys)
  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_50
  125. gint64 g_settings_get_int64 (GSettings *settings,
  126. const gchar *key);
  127. GLIB_AVAILABLE_IN_2_50
  128. gboolean g_settings_set_int64 (GSettings *settings,
  129. const gchar *key,
  130. gint64 value);
  131. GLIB_AVAILABLE_IN_2_32
  132. guint g_settings_get_uint (GSettings *settings,
  133. const gchar *key);
  134. GLIB_AVAILABLE_IN_2_32
  135. gboolean g_settings_set_uint (GSettings *settings,
  136. const gchar *key,
  137. guint value);
  138. GLIB_AVAILABLE_IN_2_50
  139. guint64 g_settings_get_uint64 (GSettings *settings,
  140. const gchar *key);
  141. GLIB_AVAILABLE_IN_2_50
  142. gboolean g_settings_set_uint64 (GSettings *settings,
  143. const gchar *key,
  144. guint64 value);
  145. GLIB_AVAILABLE_IN_ALL
  146. gchar * g_settings_get_string (GSettings *settings,
  147. const gchar *key);
  148. GLIB_AVAILABLE_IN_ALL
  149. gboolean g_settings_set_string (GSettings *settings,
  150. const gchar *key,
  151. const gchar *value);
  152. GLIB_AVAILABLE_IN_ALL
  153. gboolean g_settings_get_boolean (GSettings *settings,
  154. const gchar *key);
  155. GLIB_AVAILABLE_IN_ALL
  156. gboolean g_settings_set_boolean (GSettings *settings,
  157. const gchar *key,
  158. gboolean value);
  159. GLIB_AVAILABLE_IN_ALL
  160. gdouble g_settings_get_double (GSettings *settings,
  161. const gchar *key);
  162. GLIB_AVAILABLE_IN_ALL
  163. gboolean g_settings_set_double (GSettings *settings,
  164. const gchar *key,
  165. gdouble value);
  166. GLIB_AVAILABLE_IN_ALL
  167. gchar ** g_settings_get_strv (GSettings *settings,
  168. const gchar *key);
  169. GLIB_AVAILABLE_IN_ALL
  170. gboolean g_settings_set_strv (GSettings *settings,
  171. const gchar *key,
  172. const gchar *const *value);
  173. GLIB_AVAILABLE_IN_ALL
  174. gint g_settings_get_enum (GSettings *settings,
  175. const gchar *key);
  176. GLIB_AVAILABLE_IN_ALL
  177. gboolean g_settings_set_enum (GSettings *settings,
  178. const gchar *key,
  179. gint value);
  180. GLIB_AVAILABLE_IN_ALL
  181. guint g_settings_get_flags (GSettings *settings,
  182. const gchar *key);
  183. GLIB_AVAILABLE_IN_ALL
  184. gboolean g_settings_set_flags (GSettings *settings,
  185. const gchar *key,
  186. guint value);
  187. GLIB_AVAILABLE_IN_ALL
  188. GSettings * g_settings_get_child (GSettings *settings,
  189. const gchar *name);
  190. GLIB_AVAILABLE_IN_ALL
  191. gboolean g_settings_is_writable (GSettings *settings,
  192. const gchar *name);
  193. GLIB_AVAILABLE_IN_ALL
  194. void g_settings_delay (GSettings *settings);
  195. GLIB_AVAILABLE_IN_ALL
  196. void g_settings_apply (GSettings *settings);
  197. GLIB_AVAILABLE_IN_ALL
  198. void g_settings_revert (GSettings *settings);
  199. GLIB_AVAILABLE_IN_ALL
  200. gboolean g_settings_get_has_unapplied (GSettings *settings);
  201. GLIB_AVAILABLE_IN_ALL
  202. void g_settings_sync (void);
  203. /**
  204. * GSettingsBindSetMapping:
  205. * @value: a #GValue containing the property value to map
  206. * @expected_type: the #GVariantType to create
  207. * @user_data: user data that was specified when the binding was created
  208. *
  209. * The type for the function that is used to convert an object property
  210. * value to a #GVariant for storing it in #GSettings.
  211. *
  212. * Returns: a new #GVariant holding the data from @value,
  213. * or %NULL in case of an error
  214. */
  215. typedef GVariant * (*GSettingsBindSetMapping) (const GValue *value,
  216. const GVariantType *expected_type,
  217. gpointer user_data);
  218. /**
  219. * GSettingsBindGetMapping:
  220. * @value: return location for the property value
  221. * @variant: the #GVariant
  222. * @user_data: user data that was specified when the binding was created
  223. *
  224. * The type for the function that is used to convert from #GSettings to
  225. * an object property. The @value is already initialized to hold values
  226. * of the appropriate type.
  227. *
  228. * Returns: %TRUE if the conversion succeeded, %FALSE in case of an error
  229. */
  230. typedef gboolean (*GSettingsBindGetMapping) (GValue *value,
  231. GVariant *variant,
  232. gpointer user_data);
  233. /**
  234. * GSettingsGetMapping:
  235. * @value: the #GVariant to map, or %NULL
  236. * @result: (out): the result of the mapping
  237. * @user_data: (closure): the user data that was passed to
  238. * g_settings_get_mapped()
  239. *
  240. * The type of the function that is used to convert from a value stored
  241. * in a #GSettings to a value that is useful to the application.
  242. *
  243. * If the value is successfully mapped, the result should be stored at
  244. * @result and %TRUE returned. If mapping fails (for example, if @value
  245. * is not in the right format) then %FALSE should be returned.
  246. *
  247. * If @value is %NULL then it means that the mapping function is being
  248. * given a "last chance" to successfully return a valid value. %TRUE
  249. * must be returned in this case.
  250. *
  251. * Returns: %TRUE if the conversion succeeded, %FALSE in case of an error
  252. **/
  253. typedef gboolean (*GSettingsGetMapping) (GVariant *value,
  254. gpointer *result,
  255. gpointer user_data);
  256. /**
  257. * GSettingsBindFlags:
  258. * @G_SETTINGS_BIND_DEFAULT: Equivalent to `G_SETTINGS_BIND_GET|G_SETTINGS_BIND_SET`
  259. * @G_SETTINGS_BIND_GET: Update the #GObject property when the setting changes.
  260. * It is an error to use this flag if the property is not writable.
  261. * @G_SETTINGS_BIND_SET: Update the setting when the #GObject property changes.
  262. * It is an error to use this flag if the property is not readable.
  263. * @G_SETTINGS_BIND_NO_SENSITIVITY: Do not try to bind a "sensitivity" property to the writability of the setting
  264. * @G_SETTINGS_BIND_GET_NO_CHANGES: When set in addition to #G_SETTINGS_BIND_GET, set the #GObject property
  265. * value initially from the setting, but do not listen for changes of the setting
  266. * @G_SETTINGS_BIND_INVERT_BOOLEAN: When passed to g_settings_bind(), uses a pair of mapping functions that invert
  267. * the boolean value when mapping between the setting and the property. The setting and property must both
  268. * be booleans. You cannot pass this flag to g_settings_bind_with_mapping().
  269. *
  270. * Flags used when creating a binding. These flags determine in which
  271. * direction the binding works. The default is to synchronize in both
  272. * directions.
  273. */
  274. typedef enum
  275. {
  276. G_SETTINGS_BIND_DEFAULT,
  277. G_SETTINGS_BIND_GET = (1<<0),
  278. G_SETTINGS_BIND_SET = (1<<1),
  279. G_SETTINGS_BIND_NO_SENSITIVITY = (1<<2),
  280. G_SETTINGS_BIND_GET_NO_CHANGES = (1<<3),
  281. G_SETTINGS_BIND_INVERT_BOOLEAN = (1<<4)
  282. } GSettingsBindFlags;
  283. GLIB_AVAILABLE_IN_ALL
  284. void g_settings_bind (GSettings *settings,
  285. const gchar *key,
  286. gpointer object,
  287. const gchar *property,
  288. GSettingsBindFlags flags);
  289. GLIB_AVAILABLE_IN_ALL
  290. void g_settings_bind_with_mapping (GSettings *settings,
  291. const gchar *key,
  292. gpointer object,
  293. const gchar *property,
  294. GSettingsBindFlags flags,
  295. GSettingsBindGetMapping get_mapping,
  296. GSettingsBindSetMapping set_mapping,
  297. gpointer user_data,
  298. GDestroyNotify destroy);
  299. GLIB_AVAILABLE_IN_ALL
  300. void g_settings_bind_writable (GSettings *settings,
  301. const gchar *key,
  302. gpointer object,
  303. const gchar *property,
  304. gboolean inverted);
  305. GLIB_AVAILABLE_IN_ALL
  306. void g_settings_unbind (gpointer object,
  307. const gchar *property);
  308. GLIB_AVAILABLE_IN_2_32
  309. GAction * g_settings_create_action (GSettings *settings,
  310. const gchar *key);
  311. GLIB_AVAILABLE_IN_ALL
  312. gpointer g_settings_get_mapped (GSettings *settings,
  313. const gchar *key,
  314. GSettingsGetMapping mapping,
  315. gpointer user_data);
  316. G_END_DECLS
  317. #endif /* __G_SETTINGS_H__ */