25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

259 lines
16 KiB

  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, write to the
  16. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17. * Boston, MA 02111-1307, USA.
  18. *
  19. * Author: Ryan Lortie <desrt@desrt.ca>
  20. */
  21. #if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
  22. #error "Only <gio/gio.h> can be included directly."
  23. #endif
  24. #ifndef __G_SETTINGS_H__
  25. #define __G_SETTINGS_H__
  26. #include <gio/giotypes.h>
  27. G_BEGIN_DECLS
  28. #define G_TYPE_SETTINGS (g_settings_get_type ())
  29. #define G_SETTINGS(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
  30. G_TYPE_SETTINGS, GSettings))
  31. #define G_SETTINGS_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), \
  32. G_TYPE_SETTINGS, GSettingsClass))
  33. #define G_IS_SETTINGS(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), G_TYPE_SETTINGS))
  34. #define G_IS_SETTINGS_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_SETTINGS))
  35. #define G_SETTINGS_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), \
  36. G_TYPE_SETTINGS, GSettingsClass))
  37. typedef struct _GSettingsPrivate GSettingsPrivate;
  38. typedef struct _GSettingsClass GSettingsClass;
  39. struct _GSettingsClass
  40. {
  41. GObjectClass parent_class;
  42. /* Signals */
  43. void (*writable_changed) (GSettings *settings,
  44. const gchar *key);
  45. void (*changed) (GSettings *settings,
  46. const gchar *key);
  47. gboolean (*writable_change_event) (GSettings *settings,
  48. GQuark key);
  49. gboolean (*change_event) (GSettings *settings,
  50. const GQuark *keys,
  51. gint n_keys);
  52. gpointer padding[20];
  53. };
  54. struct _GSettings
  55. {
  56. GObject parent_instance;
  57. GSettingsPrivate *priv;
  58. };
  59. GType g_settings_get_type (void);
  60. const gchar * const * g_settings_list_schemas (void);
  61. GSettings * g_settings_new (const gchar *schema);
  62. GSettings * g_settings_new_with_path (const gchar *schema,
  63. const gchar *path);
  64. GSettings * g_settings_new_with_backend (const gchar *schema,
  65. GSettingsBackend *backend);
  66. GSettings * g_settings_new_with_backend_and_path (const gchar *schema,
  67. GSettingsBackend *backend,
  68. const gchar *path);
  69. gchar ** g_settings_list_children (GSettings *settings);
  70. gchar ** g_settings_list_keys (GSettings *settings);
  71. gboolean g_settings_set_value (GSettings *settings,
  72. const gchar *key,
  73. GVariant *value);
  74. GVariant * g_settings_get_value (GSettings *settings,
  75. const gchar *key);
  76. gboolean g_settings_set (GSettings *settings,
  77. const gchar *key,
  78. const gchar *format,
  79. ...);
  80. void g_settings_get (GSettings *settings,
  81. const gchar *key,
  82. const gchar *format,
  83. ...);
  84. void g_settings_reset (GSettings *settings,
  85. const gchar *key);
  86. gint g_settings_get_int (GSettings *settings,
  87. const gchar *key);
  88. gboolean g_settings_set_int (GSettings *settings,
  89. const gchar *key,
  90. gint value);
  91. gchar * g_settings_get_string (GSettings *settings,
  92. const gchar *key);
  93. gboolean g_settings_set_string (GSettings *settings,
  94. const gchar *key,
  95. const gchar *value);
  96. gboolean g_settings_get_boolean (GSettings *settings,
  97. const gchar *key);
  98. gboolean g_settings_set_boolean (GSettings *settings,
  99. const gchar *key,
  100. gboolean value);
  101. gdouble g_settings_get_double (GSettings *settings,
  102. const gchar *key);
  103. gboolean g_settings_set_double (GSettings *settings,
  104. const gchar *key,
  105. gdouble value);
  106. gchar ** g_settings_get_strv (GSettings *settings,
  107. const gchar *key);
  108. gboolean g_settings_set_strv (GSettings *settings,
  109. const gchar *key,
  110. const gchar *const *value);
  111. gint g_settings_get_enum (GSettings *settings,
  112. const gchar *key);
  113. gboolean g_settings_set_enum (GSettings *settings,
  114. const gchar *key,
  115. gint value);
  116. guint g_settings_get_flags (GSettings *settings,
  117. const gchar *key);
  118. gboolean g_settings_set_flags (GSettings *settings,
  119. const gchar *key,
  120. guint value);
  121. GSettings * g_settings_get_child (GSettings *settings,
  122. const gchar *name);
  123. gboolean g_settings_is_writable (GSettings *settings,
  124. const gchar *name);
  125. void g_settings_delay (GSettings *settings);
  126. void g_settings_apply (GSettings *settings);
  127. void g_settings_revert (GSettings *settings);
  128. gboolean g_settings_get_has_unapplied (GSettings *settings);
  129. void g_settings_sync (void);
  130. /**
  131. * GSettingsBindSetMapping:
  132. * @value: a #GValue containing the property value to map
  133. * @expected_type: the #GVariantType to create
  134. * @user_data: user data that was specified when the binding was created
  135. * @returns: a new #GVariant holding the data from @value,
  136. * or %NULL in case of an error
  137. *
  138. * The type for the function that is used to convert an object property
  139. * value to a #GVariant for storing it in #GSettings.
  140. */
  141. typedef GVariant * (*GSettingsBindSetMapping) (const GValue *value,
  142. const GVariantType *expected_type,
  143. gpointer user_data);
  144. /**
  145. * GSettingsBindGetMapping:
  146. * @value: return location for the property value
  147. * @variant: the #GVariant
  148. * @user_data: user data that was specified when the binding was created
  149. * @returns: %TRUE if the conversion succeeded, %FALSE in case of an error
  150. *
  151. * The type for the function that is used to convert from #GSettings to
  152. * an object property. The @value is already initialized to hold values
  153. * of the appropriate type.
  154. */
  155. typedef gboolean (*GSettingsBindGetMapping) (GValue *value,
  156. GVariant *variant,
  157. gpointer user_data);
  158. /**
  159. * GSettingsGetMapping:
  160. * @value: the #GVariant to map, or %NULL
  161. * @result: the result of the mapping
  162. * @user_data: the user data that was passed to g_settings_get_mapped()
  163. * @returns: %TRUE if the conversion succeeded, %FALSE in case of an error
  164. *
  165. * The type of the function that is used to convert from a value stored
  166. * in a #GSettings to a value that is useful to the application.
  167. *
  168. * If the value is successfully mapped, the result should be stored at
  169. * @result and %TRUE returned. If mapping fails (for example, if @value
  170. * is not in the right format) then %FALSE should be returned.
  171. *
  172. * If @value is %NULL then it means that the mapping function is being
  173. * given a "last chance" to successfully return a valid value. %TRUE
  174. * must be returned in this case.
  175. **/
  176. typedef gboolean (*GSettingsGetMapping) (GVariant *value,
  177. gpointer *result,
  178. gpointer user_data);
  179. /**
  180. * GSettingsBindFlags:
  181. * @G_SETTINGS_BIND_DEFAULT: Equivalent to <literal>G_SETTINGS_BIND_GET|G_SETTINGS_BIND_SET</literal>
  182. * @G_SETTINGS_BIND_GET: Update the #GObject property when the setting changes.
  183. * It is an error to use this flag if the property is not writable.
  184. * @G_SETTINGS_BIND_SET: Update the setting when the #GObject property changes.
  185. * It is an error to use this flag if the property is not readable.
  186. * @G_SETTINGS_BIND_NO_SENSITIVITY: Do not try to bind a "sensitivity" property to the writability of the setting
  187. * @G_SETTINGS_BIND_GET_NO_CHANGES: When set in addition to #G_SETTINGS_BIND_GET, set the #GObject property
  188. * value initially from the setting, but do not listen for changes of the setting
  189. * @G_SETTINGS_BIND_INVERT_BOOLEAN: When passed to g_settings_bind(), uses a pair of mapping functions that invert
  190. * the boolean value when mapping between the setting and the property. The setting and property must both
  191. * be booleans. You can not pass this flag to g_settings_bind_with_mapping().
  192. *
  193. * Flags used when creating a binding. These flags determine in which
  194. * direction the binding works. The default is to synchronize in both
  195. * directions.
  196. */
  197. typedef enum
  198. {
  199. G_SETTINGS_BIND_DEFAULT,
  200. G_SETTINGS_BIND_GET = (1<<0),
  201. G_SETTINGS_BIND_SET = (1<<1),
  202. G_SETTINGS_BIND_NO_SENSITIVITY = (1<<2),
  203. G_SETTINGS_BIND_GET_NO_CHANGES = (1<<3),
  204. G_SETTINGS_BIND_INVERT_BOOLEAN = (1<<4)
  205. } GSettingsBindFlags;
  206. void g_settings_bind (GSettings *settings,
  207. const gchar *key,
  208. gpointer object,
  209. const gchar *property,
  210. GSettingsBindFlags flags);
  211. void g_settings_bind_with_mapping (GSettings *settings,
  212. const gchar *key,
  213. gpointer object,
  214. const gchar *property,
  215. GSettingsBindFlags flags,
  216. GSettingsBindGetMapping get_mapping,
  217. GSettingsBindSetMapping set_mapping,
  218. gpointer user_data,
  219. GDestroyNotify destroy);
  220. void g_settings_bind_writable (GSettings *settings,
  221. const gchar *key,
  222. gpointer object,
  223. const gchar *property,
  224. gboolean inverted);
  225. void g_settings_unbind (gpointer object,
  226. const gchar *property);
  227. gpointer g_settings_get_mapped (GSettings *settings,
  228. const gchar *key,
  229. GSettingsGetMapping mapping,
  230. gpointer user_data);
  231. G_END_DECLS
  232. #endif /* __G_SETTINGS_H__ */