2010-04-16 00:22:14 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2010 Codethink Limited
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the licence, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2014-01-23 12:58:29 +01:00
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2010-04-16 00:22:14 +02:00
|
|
|
*
|
|
|
|
* Author: Ryan Lortie <desrt@desrt.ca>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2010-12-05 15:34:26 +01:00
|
|
|
#include "gsettingsbackendinternal.h"
|
|
|
|
#include "giomodule.h"
|
2010-06-04 23:07:40 +02:00
|
|
|
#include "gsimplepermission.h"
|
2010-04-16 00:22:14 +02:00
|
|
|
|
2010-04-16 18:02:29 +02:00
|
|
|
|
2010-04-16 00:22:14 +02:00
|
|
|
#define G_TYPE_NULL_SETTINGS_BACKEND (g_null_settings_backend_get_type ())
|
|
|
|
#define G_NULL_SETTINGS_BACKEND(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
|
|
|
|
G_TYPE_NULL_SETTINGS_BACKEND, \
|
|
|
|
GNullSettingsBackend))
|
|
|
|
|
|
|
|
|
|
|
|
typedef GSettingsBackendClass GNullSettingsBackendClass;
|
|
|
|
typedef GSettingsBackend GNullSettingsBackend;
|
|
|
|
|
2010-12-05 15:34:26 +01:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GNullSettingsBackend,
|
|
|
|
g_null_settings_backend,
|
|
|
|
G_TYPE_SETTINGS_BACKEND,
|
|
|
|
g_io_extension_point_implement (G_SETTINGS_BACKEND_EXTENSION_POINT_NAME,
|
|
|
|
g_define_type_id, "null", 10))
|
2010-04-16 00:22:14 +02:00
|
|
|
|
|
|
|
static GVariant *
|
|
|
|
g_null_settings_backend_read (GSettingsBackend *backend,
|
|
|
|
const gchar *key,
|
2010-04-26 05:00:28 +02:00
|
|
|
const GVariantType *expected_type,
|
|
|
|
gboolean default_value)
|
2010-04-16 00:22:14 +02:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
g_null_settings_backend_write (GSettingsBackend *backend,
|
|
|
|
const gchar *key,
|
|
|
|
GVariant *value,
|
|
|
|
gpointer origin_tag)
|
|
|
|
{
|
2011-01-06 23:30:09 +01:00
|
|
|
if (value)
|
|
|
|
g_variant_unref (g_variant_ref_sink (value));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
g_null_settings_backend_write_one (gpointer key,
|
|
|
|
gpointer value,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
if (value)
|
|
|
|
g_variant_unref (g_variant_ref_sink (value));
|
2010-04-16 00:22:14 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-07-23 00:39:50 +02:00
|
|
|
g_null_settings_backend_write_tree (GSettingsBackend *backend,
|
2010-04-16 00:22:14 +02:00
|
|
|
GTree *tree,
|
|
|
|
gpointer origin_tag)
|
|
|
|
{
|
2011-01-06 23:30:09 +01:00
|
|
|
g_tree_foreach (tree, g_null_settings_backend_write_one, backend);
|
2010-04-16 00:22:14 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_null_settings_backend_reset (GSettingsBackend *backend,
|
|
|
|
const gchar *key,
|
|
|
|
gpointer origin_tag)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
g_null_settings_backend_get_writable (GSettingsBackend *backend,
|
2010-06-04 23:07:40 +02:00
|
|
|
const gchar *name)
|
2010-04-16 00:22:14 +02:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-06-04 23:07:40 +02:00
|
|
|
static GPermission *
|
|
|
|
g_null_settings_backend_get_permission (GSettingsBackend *backend,
|
|
|
|
const gchar *path)
|
|
|
|
{
|
|
|
|
return g_simple_permission_new (FALSE);
|
|
|
|
}
|
|
|
|
|
2010-04-16 00:22:14 +02:00
|
|
|
static void
|
|
|
|
g_null_settings_backend_init (GNullSettingsBackend *memory)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_null_settings_backend_class_init (GNullSettingsBackendClass *class)
|
|
|
|
{
|
|
|
|
GSettingsBackendClass *backend_class = G_SETTINGS_BACKEND_CLASS (class);
|
|
|
|
|
|
|
|
backend_class->read = g_null_settings_backend_read;
|
|
|
|
backend_class->write = g_null_settings_backend_write;
|
2010-07-23 00:39:50 +02:00
|
|
|
backend_class->write_tree = g_null_settings_backend_write_tree;
|
2010-04-16 00:22:14 +02:00
|
|
|
backend_class->reset = g_null_settings_backend_reset;
|
|
|
|
backend_class->get_writable = g_null_settings_backend_get_writable;
|
2010-06-04 23:07:40 +02:00
|
|
|
backend_class->get_permission = g_null_settings_backend_get_permission;
|
2010-04-16 00:22:14 +02:00
|
|
|
}
|
|
|
|
|
2011-02-08 16:05:00 +01:00
|
|
|
/**
|
|
|
|
* g_null_settings_backend_new:
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Creates a readonly #GSettingsBackend.
|
|
|
|
*
|
|
|
|
* This backend does not allow changes to settings, so all settings
|
|
|
|
* will always have their default values.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a newly created #GSettingsBackend
|
|
|
|
*
|
|
|
|
* Since: 2.28
|
|
|
|
*/
|
2010-04-16 00:22:14 +02:00
|
|
|
GSettingsBackend *
|
|
|
|
g_null_settings_backend_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (G_TYPE_NULL_SETTINGS_BACKEND, NULL);
|
|
|
|
}
|