Add g_settings_sync() and use it

This commit is contained in:
Ryan Lortie 2010-06-10 22:30:44 -04:00
parent 7c36619d26
commit a8b5353b14
7 changed files with 49 additions and 18 deletions

View File

@ -2135,6 +2135,7 @@ g_settings_new_with_path
g_settings_new_with_context g_settings_new_with_context
g_settings_new_with_context_and_path g_settings_new_with_context_and_path
g_settings_supports_context g_settings_supports_context
g_settings_sync
g_settings_get_value g_settings_get_value
g_settings_set_value g_settings_set_value
g_settings_is_writable g_settings_is_writable

View File

@ -1467,6 +1467,7 @@ g_settings_get_double
g_settings_set_double g_settings_set_double
g_settings_get_boolean g_settings_get_boolean
g_settings_set_boolean g_settings_set_boolean
g_settings_sync
#endif #endif
#endif #endif

View File

@ -213,26 +213,9 @@ handle_set (gint *argc,
goto out; goto out;
} }
g_settings_sync (NULL);
ret = 0; ret = 0;
/* XXX: workaround for now
*
* if we exit() so quickly, GDBus may not have had a chance to
* actually send the message (since we're using it async).
*
* GDBusConnection has no API to sync or wait for messages to be sent,
* so we send a meaningless message and wait for the reply to ensure
* that all messages that came before must have been sent.
*/
{
GDBusConnection *session;
session = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
g_dbus_connection_call_sync (session, "org.gtk.DoesNotExist", "/",
"org.gtk.DoesNotExist", "Workaround",
g_variant_new ("()"), NULL, 0, -1, NULL, NULL);
}
out: out:
g_option_context_free (context); g_option_context_free (context);

View File

@ -1860,5 +1860,33 @@ g_settings_set_strv (GSettings *settings,
return g_settings_set_value (settings, key, array); return g_settings_set_value (settings, key, array);
} }
/**
* g_settings_sync:
* @context: the context to sync, or %NULL
*
* Ensures that all pending operations for the given context are
* complete.
*
* Writes made to a #GSettings are handled asynchronously. For this
* reason, it is very unlikely that the changes have it to disk by the
* time g_settings_set() returns.
*
* This call will block until all of the writes have made it to the
* backend. Since the mainloop is not running, no change notifications
* will be dispatched during this call (but some may be queued by the
* time the call is done).
**/
void
g_settings_sync (const gchar *context)
{
GSettingsBackend *backend;
if (context == NULL)
context = "";
backend = g_settings_backend_get_with_context (context);
g_settings_backend_sync (backend);
}
#define __G_SETTINGS_C__ #define __G_SETTINGS_C__
#include "gioaliasdef.c" #include "gioaliasdef.c"

View File

@ -132,6 +132,7 @@ void g_settings_delay (GSettin
void g_settings_apply (GSettings *settings); void g_settings_apply (GSettings *settings);
void g_settings_revert (GSettings *settings); void g_settings_revert (GSettings *settings);
gboolean g_settings_get_has_unapplied (GSettings *settings); gboolean g_settings_get_has_unapplied (GSettings *settings);
void g_settings_sync (const gchar *context);
/** /**
* GSettingsBindSetMapping: * GSettingsBindSetMapping:

View File

@ -1219,5 +1219,20 @@ g_settings_backend_setup (const gchar *context,
g_object_ref (backend)); g_object_ref (backend));
} }
/*< private >
* g_settings_backend_sync:
* @backend: a #GSettingsBackend
*
* Syncs the backend.
*/
void
g_settings_backend_sync (GSettingsBackend *backend)
{
GSettingsBackendClass *class = G_SETTINGS_BACKEND_GET_CLASS (backend);
if (class->sync)
class->sync (backend);
}
#define __G_SETTINGS_BACKEND_C__ #define __G_SETTINGS_BACKEND_C__
#include "gioaliasdef.c" #include "gioaliasdef.c"

View File

@ -103,5 +103,7 @@ GPermission * g_settings_backend_get_permission (GSettin
const gchar *path); const gchar *path);
G_GNUC_INTERNAL G_GNUC_INTERNAL
GMainContext * g_settings_backend_get_active_context (void); GMainContext * g_settings_backend_get_active_context (void);
G_GNUC_INTERNAL
void g_settings_backend_sync (GSettingsBackend *backend);
#endif /* __G_SETTINGS_BACKEND_INTERNAL_H__ */ #endif /* __G_SETTINGS_BACKEND_INTERNAL_H__ */