Skip to content

Instantly share code, notes, and snippets.

@jhenstridge
Created October 30, 2018 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhenstridge/d4f05b61103941257bd95f18a9e7f069 to your computer and use it in GitHub Desktop.
Save jhenstridge/d4f05b61103941257bd95f18a9e7f069 to your computer and use it in GitHub Desktop.
A passthrough GSettings backend (with broken change signalling)
#define G_SETTINGS_ENABLE_BACKEND
#include <gio/gio.h>
#include <gio/gsettingsbackend.h>
typedef GSettingsBackendClass PassthroughSettingsBackendClass;
typedef struct _PassthroughSettingsBackend PassthroughSettingsBackend;
struct _PassthroughSettingsBackend
{
GSettingsBackend backend;
GSettingsBackend *real;
};
static GType passthrough_settings_backend_get_type (void);
G_DEFINE_TYPE(PassthroughSettingsBackend, passthrough_settings_backend, G_TYPE_SETTINGS_BACKEND)
static GVariant *
passthrough_settings_backend_read (GSettingsBackend *backend,
const gchar *key,
const GVariantType *expected_type,
gboolean default_value)
{
PassthroughSettingsBackend *b = (PassthroughSettingsBackend *)backend;
g_message ("passthrough_settings_backend_read(%s)", key);
return G_SETTINGS_BACKEND_GET_CLASS (b->real)->read (b->real, key, expected_type, default_value);
}
static GVariant *
passthrough_settings_backend_read_user_value (GSettingsBackend *backend,
const gchar *key,
const GVariantType *expected_type)
{
PassthroughSettingsBackend *b = (PassthroughSettingsBackend *)backend;
g_message ("passthrough_settings_backend_read_user_value(%s)", key);
return G_SETTINGS_BACKEND_GET_CLASS (b->real)->read_user_value (b->real, key, expected_type);
}
static gboolean
passthrough_settings_backend_write (GSettingsBackend *backend,
const gchar *key,
GVariant *value,
gpointer origin_tag)
{
PassthroughSettingsBackend *b = (PassthroughSettingsBackend *)backend;
return G_SETTINGS_BACKEND_GET_CLASS (b->real)->write (b->real, key, value, origin_tag);
}
static gboolean
passthrough_settings_backend_write_tree (GSettingsBackend *backend,
GTree *tree,
gpointer origin_tag)
{
PassthroughSettingsBackend *b = (PassthroughSettingsBackend *)backend;
return G_SETTINGS_BACKEND_GET_CLASS (b->real)->write_tree (b->real, tree, origin_tag);
}
static void
passthrough_settings_backend_reset (GSettingsBackend *backend,
const gchar *key,
gpointer origin_tag)
{
PassthroughSettingsBackend *b = (PassthroughSettingsBackend *)backend;
G_SETTINGS_BACKEND_GET_CLASS (b->real)->reset (b->real, key, origin_tag);
}
static gboolean
passthrough_settings_backend_get_writable (GSettingsBackend *backend,
const gchar *name)
{
PassthroughSettingsBackend *b = (PassthroughSettingsBackend *)backend;
return G_SETTINGS_BACKEND_GET_CLASS (b->real)->get_writable (b->real, name);
}
static void
passthrough_settings_backend_subscribe (GSettingsBackend *backend,
const gchar *name)
{
PassthroughSettingsBackend *b = (PassthroughSettingsBackend *)backend;
G_SETTINGS_BACKEND_GET_CLASS (b->real)->subscribe (b->real, name);
}
static void
passthrough_settings_backend_unsubscribe (GSettingsBackend *backend,
const gchar *name)
{
PassthroughSettingsBackend *b = (PassthroughSettingsBackend *)backend;
G_SETTINGS_BACKEND_GET_CLASS (b->real)->unsubscribe (b->real, name);
}
static void
passthrough_settings_backend_sync (GSettingsBackend *backend)
{
PassthroughSettingsBackend *b = (PassthroughSettingsBackend *)backend;
G_SETTINGS_BACKEND_GET_CLASS (b->real)->sync (b->real);
}
static void
passthrough_settings_backend_init (PassthroughSettingsBackend *backend)
{
GIOExtensionPoint *ep;
GIOExtension *e;
g_message("passthrough_settings_backend_init");
ep = g_io_extension_point_lookup (G_SETTINGS_BACKEND_EXTENSION_POINT_NAME);
e = g_io_extension_point_get_extension_by_name (ep, "dconf");
backend->real = g_object_new (g_io_extension_get_type (e), NULL);
}
static void
passthrough_settings_backend_finalize (GObject *object)
{
PassthroughSettingsBackend *backend = (PassthroughSettingsBackend *)object;
g_clear_object (&backend->real);
G_OBJECT_CLASS (passthrough_settings_backend_parent_class)->finalize (object);
}
static void
passthrough_settings_backend_class_init (GSettingsBackendClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->finalize = passthrough_settings_backend_finalize;
class->read = passthrough_settings_backend_read;
class->read_user_value = passthrough_settings_backend_read_user_value;
class->write = passthrough_settings_backend_write;
class->write_tree = passthrough_settings_backend_write_tree;
class->reset = passthrough_settings_backend_reset;
class->get_writable = passthrough_settings_backend_get_writable;
class->subscribe = passthrough_settings_backend_subscribe;
class->unsubscribe = passthrough_settings_backend_unsubscribe;
class->sync = passthrough_settings_backend_sync;
}
void
g_io_module_load (GIOModule *module)
{
g_type_module_use (G_TYPE_MODULE (module));
g_io_extension_point_implement (G_SETTINGS_BACKEND_EXTENSION_POINT_NAME,
passthrough_settings_backend_get_type (),
"passthrough", 10);
}
void
g_io_module_unload (GIOModule *module)
{
g_assert_not_reached ();
}
gchar **
g_io_module_query (void)
{
return g_strsplit (G_SETTINGS_BACKEND_EXTENSION_POINT_NAME, "!", 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment