gnullsettingsbackend.c 4.32 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * 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
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Author: Ryan Lortie <desrt@desrt.ca>
 */

#include "config.h"

24 25
#include "gsettingsbackendinternal.h"
#include "giomodule.h"
26
#include "gsimplepermission.h"
27

28

29 30 31 32 33 34 35 36 37
#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;

38 39 40 41 42
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))
43 44 45 46

static GVariant *
g_null_settings_backend_read (GSettingsBackend   *backend,
                              const gchar        *key,
47 48
                              const GVariantType *expected_type,
                              gboolean            default_value)
49 50 51 52 53 54 55 56 57 58
{
  return NULL;
}

static gboolean
g_null_settings_backend_write (GSettingsBackend *backend,
                               const gchar      *key,
                               GVariant         *value,
                               gpointer          origin_tag)
{
59 60 61 62 63 64 65 66 67 68 69 70
  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));
71 72 73 74
  return FALSE;
}

static gboolean
75
g_null_settings_backend_write_tree (GSettingsBackend *backend,
76 77 78
                                    GTree            *tree,
                                    gpointer          origin_tag)
{
79
  g_tree_foreach (tree, g_null_settings_backend_write_one, backend);
80 81 82 83 84 85 86 87 88 89 90 91
  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,
92
                                      const gchar      *name)
93 94 95 96
{
  return FALSE;
}

97 98 99 100 101 102 103
static GPermission *
g_null_settings_backend_get_permission (GSettingsBackend *backend,
                                        const gchar      *path)
{
  return g_simple_permission_new (FALSE);
}

104 105 106 107 108 109 110 111 112 113 114 115
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;
116
  backend_class->write_tree = g_null_settings_backend_write_tree;
117 118
  backend_class->reset = g_null_settings_backend_reset;
  backend_class->get_writable = g_null_settings_backend_get_writable;
119
  backend_class->get_permission = g_null_settings_backend_get_permission;
120 121
}

Matthias Clasen's avatar
Matthias Clasen committed
122 123 124 125 126 127 128 129 130 131 132 133 134
/**
 * 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
 */
135 136 137 138 139
GSettingsBackend *
g_null_settings_backend_new (void)
{
  return g_object_new (G_TYPE_NULL_SETTINGS_BACKEND, NULL);
}