mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-02 17:26:17 +01:00
unGObjectify GSettingsSchema
This commit is contained in:
parent
eaaf18960f
commit
577faeae5b
@ -533,7 +533,7 @@ g_settings_finalize (GObject *object)
|
|||||||
settings->priv->path);
|
settings->priv->path);
|
||||||
g_main_context_unref (settings->priv->main_context);
|
g_main_context_unref (settings->priv->main_context);
|
||||||
g_object_unref (settings->priv->backend);
|
g_object_unref (settings->priv->backend);
|
||||||
g_object_unref (settings->priv->schema);
|
g_settings_schema_unref (settings->priv->schema);
|
||||||
g_free (settings->priv->schema_name);
|
g_free (settings->priv->schema_name);
|
||||||
g_free (settings->priv->path);
|
g_free (settings->priv->path);
|
||||||
|
|
||||||
|
@ -26,9 +26,7 @@
|
|||||||
|
|
||||||
#include <glibintl.h>
|
#include <glibintl.h>
|
||||||
|
|
||||||
G_DEFINE_TYPE (GSettingsSchema, g_settings_schema, G_TYPE_OBJECT)
|
struct _GSettingsSchema
|
||||||
|
|
||||||
struct _GSettingsSchemaPrivate
|
|
||||||
{
|
{
|
||||||
const gchar *gettext_domain;
|
const gchar *gettext_domain;
|
||||||
const gchar *path;
|
const gchar *path;
|
||||||
@ -36,6 +34,8 @@ struct _GSettingsSchemaPrivate
|
|||||||
gint n_items;
|
gint n_items;
|
||||||
GvdbTable *table;
|
GvdbTable *table;
|
||||||
gchar *name;
|
gchar *name;
|
||||||
|
|
||||||
|
gint ref_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
static GSList *schema_sources;
|
static GSList *schema_sources;
|
||||||
@ -216,34 +216,25 @@ g_settings_list_relocatable_schemas (void)
|
|||||||
return relocatable_schema_list;
|
return relocatable_schema_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
GSettingsSchema *
|
||||||
g_settings_schema_finalize (GObject *object)
|
g_settings_schema_ref (GSettingsSchema *schema)
|
||||||
{
|
{
|
||||||
GSettingsSchema *schema = G_SETTINGS_SCHEMA (object);
|
g_atomic_int_inc (&schema->ref_count);
|
||||||
|
|
||||||
gvdb_table_unref (schema->priv->table);
|
return schema;
|
||||||
g_free (schema->priv->items);
|
|
||||||
g_free (schema->priv->name);
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (g_settings_schema_parent_class)
|
|
||||||
->finalize (object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
g_settings_schema_init (GSettingsSchema *schema)
|
g_settings_schema_unref (GSettingsSchema *schema)
|
||||||
{
|
{
|
||||||
schema->priv = G_TYPE_INSTANCE_GET_PRIVATE (schema, G_TYPE_SETTINGS_SCHEMA,
|
if (g_atomic_int_dec_and_test (&schema->ref_count))
|
||||||
GSettingsSchemaPrivate);
|
{
|
||||||
}
|
gvdb_table_unref (schema->table);
|
||||||
|
g_free (schema->items);
|
||||||
|
g_free (schema->name);
|
||||||
|
|
||||||
static void
|
g_slice_free (GSettingsSchema, schema);
|
||||||
g_settings_schema_class_init (GSettingsSchemaClass *class)
|
}
|
||||||
{
|
|
||||||
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
|
||||||
|
|
||||||
object_class->finalize = g_settings_schema_finalize;
|
|
||||||
|
|
||||||
g_type_class_add_private (class, sizeof (GSettingsSchemaPrivate));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const gchar *
|
const gchar *
|
||||||
@ -253,7 +244,7 @@ g_settings_schema_get_string (GSettingsSchema *schema,
|
|||||||
const gchar *result = NULL;
|
const gchar *result = NULL;
|
||||||
GVariant *value;
|
GVariant *value;
|
||||||
|
|
||||||
if ((value = gvdb_table_get_raw_value (schema->priv->table, key)))
|
if ((value = gvdb_table_get_raw_value (schema->table, key)))
|
||||||
{
|
{
|
||||||
result = g_variant_get_string (value, NULL);
|
result = g_variant_get_string (value, NULL);
|
||||||
g_variant_unref (value);
|
g_variant_unref (value);
|
||||||
@ -284,16 +275,17 @@ g_settings_schema_new (const gchar *name)
|
|||||||
if (table == NULL)
|
if (table == NULL)
|
||||||
g_error ("Settings schema '%s' is not installed\n", name);
|
g_error ("Settings schema '%s' is not installed\n", name);
|
||||||
|
|
||||||
schema = g_object_new (G_TYPE_SETTINGS_SCHEMA, NULL);
|
schema = g_slice_new0 (GSettingsSchema);
|
||||||
schema->priv->name = g_strdup (name);
|
schema->ref_count = 1;
|
||||||
schema->priv->table = table;
|
schema->name = g_strdup (name);
|
||||||
schema->priv->path =
|
schema->table = table;
|
||||||
|
schema->path =
|
||||||
g_settings_schema_get_string (schema, ".path");
|
g_settings_schema_get_string (schema, ".path");
|
||||||
schema->priv->gettext_domain =
|
schema->gettext_domain =
|
||||||
g_settings_schema_get_string (schema, ".gettext-domain");
|
g_settings_schema_get_string (schema, ".gettext-domain");
|
||||||
|
|
||||||
if (schema->priv->gettext_domain)
|
if (schema->gettext_domain)
|
||||||
bind_textdomain_codeset (schema->priv->gettext_domain, "UTF-8");
|
bind_textdomain_codeset (schema->gettext_domain, "UTF-8");
|
||||||
|
|
||||||
return schema;
|
return schema;
|
||||||
}
|
}
|
||||||
@ -305,11 +297,11 @@ g_settings_schema_get_value (GSettingsSchema *schema,
|
|||||||
GVariantIter *iter;
|
GVariantIter *iter;
|
||||||
GVariant *value;
|
GVariant *value;
|
||||||
|
|
||||||
value = gvdb_table_get_raw_value (schema->priv->table, key);
|
value = gvdb_table_get_raw_value (schema->table, key);
|
||||||
|
|
||||||
if G_UNLIKELY (value == NULL)
|
if G_UNLIKELY (value == NULL)
|
||||||
g_error ("Settings schema '%s' does not contain a key named '%s'",
|
g_error ("Settings schema '%s' does not contain a key named '%s'",
|
||||||
schema->priv->name, key);
|
schema->name, key);
|
||||||
|
|
||||||
iter = g_variant_iter_new (value);
|
iter = g_variant_iter_new (value);
|
||||||
g_variant_unref (value);
|
g_variant_unref (value);
|
||||||
@ -320,20 +312,20 @@ g_settings_schema_get_value (GSettingsSchema *schema,
|
|||||||
const gchar *
|
const gchar *
|
||||||
g_settings_schema_get_path (GSettingsSchema *schema)
|
g_settings_schema_get_path (GSettingsSchema *schema)
|
||||||
{
|
{
|
||||||
return schema->priv->path;
|
return schema->path;
|
||||||
}
|
}
|
||||||
|
|
||||||
const gchar *
|
const gchar *
|
||||||
g_settings_schema_get_gettext_domain (GSettingsSchema *schema)
|
g_settings_schema_get_gettext_domain (GSettingsSchema *schema)
|
||||||
{
|
{
|
||||||
return schema->priv->gettext_domain;
|
return schema->gettext_domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
g_settings_schema_has_key (GSettingsSchema *schema,
|
g_settings_schema_has_key (GSettingsSchema *schema,
|
||||||
const gchar *key)
|
const gchar *key)
|
||||||
{
|
{
|
||||||
return gvdb_table_has_value (schema->priv->table, key);
|
return gvdb_table_has_value (schema->table, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
const GQuark *
|
const GQuark *
|
||||||
@ -342,25 +334,25 @@ g_settings_schema_list (GSettingsSchema *schema,
|
|||||||
{
|
{
|
||||||
gint i, j;
|
gint i, j;
|
||||||
|
|
||||||
if (schema->priv->items == NULL)
|
if (schema->items == NULL)
|
||||||
{
|
{
|
||||||
gchar **list;
|
gchar **list;
|
||||||
gint len;
|
gint len;
|
||||||
|
|
||||||
list = gvdb_table_list (schema->priv->table, "");
|
list = gvdb_table_list (schema->table, "");
|
||||||
len = list ? g_strv_length (list) : 0;
|
len = list ? g_strv_length (list) : 0;
|
||||||
|
|
||||||
schema->priv->items = g_new (GQuark, len);
|
schema->items = g_new (GQuark, len);
|
||||||
j = 0;
|
j = 0;
|
||||||
|
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
if (list[i][0] != '.')
|
if (list[i][0] != '.')
|
||||||
schema->priv->items[j++] = g_quark_from_string (list[i]);
|
schema->items[j++] = g_quark_from_string (list[i]);
|
||||||
schema->priv->n_items = j;
|
schema->n_items = j;
|
||||||
|
|
||||||
g_strfreev (list);
|
g_strfreev (list);
|
||||||
}
|
}
|
||||||
|
|
||||||
*n_items = schema->priv->n_items;
|
*n_items = schema->n_items;
|
||||||
return schema->priv->items;
|
return schema->items;
|
||||||
}
|
}
|
||||||
|
@ -20,43 +20,19 @@
|
|||||||
#ifndef __G_SETTINGS_SCHEMA_H__
|
#ifndef __G_SETTINGS_SCHEMA_H__
|
||||||
#define __G_SETTINGS_SCHEMA_H__
|
#define __G_SETTINGS_SCHEMA_H__
|
||||||
|
|
||||||
#include <glib-object.h>
|
#include <glib.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
#define G_TYPE_SETTINGS_SCHEMA (g_settings_schema_get_type ())
|
|
||||||
#define G_SETTINGS_SCHEMA(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
|
|
||||||
G_TYPE_SETTINGS_SCHEMA, GSettingsSchema))
|
|
||||||
#define G_SETTINGS_SCHEMA_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), \
|
|
||||||
G_TYPE_SETTINGS_SCHEMA, GSettingsSchemaClass))
|
|
||||||
#define G_IS_SETTINGS_SCHEMA(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), \
|
|
||||||
G_TYPE_SETTINGS_SCHEMA))
|
|
||||||
#define G_IS_SETTINGS_SCHEMA_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), \
|
|
||||||
G_TYPE_SETTINGS_SCHEMA))
|
|
||||||
#define G_SETTINGS_SCHEMA_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), \
|
|
||||||
G_TYPE_SETTINGS_SCHEMA, GSettingsSchemaClass))
|
|
||||||
|
|
||||||
typedef struct _GSettingsSchemaPrivate GSettingsSchemaPrivate;
|
|
||||||
typedef struct _GSettingsSchemaClass GSettingsSchemaClass;
|
|
||||||
typedef struct _GSettingsSchema GSettingsSchema;
|
typedef struct _GSettingsSchema GSettingsSchema;
|
||||||
|
|
||||||
struct _GSettingsSchemaClass
|
|
||||||
{
|
|
||||||
GObjectClass parent_class;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _GSettingsSchema
|
|
||||||
{
|
|
||||||
GObject parent_instance;
|
|
||||||
|
|
||||||
GSettingsSchemaPrivate *priv;
|
|
||||||
};
|
|
||||||
|
|
||||||
G_GNUC_INTERNAL
|
|
||||||
GType g_settings_schema_get_type (void);
|
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
GSettingsSchema * g_settings_schema_new (const gchar *name);
|
GSettingsSchema * g_settings_schema_new (const gchar *name);
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
|
GSettingsSchema * g_settings_schema_ref (GSettingsSchema *schema);
|
||||||
|
G_GNUC_INTERNAL
|
||||||
|
void g_settings_schema_unref (GSettingsSchema *schema);
|
||||||
|
G_GNUC_INTERNAL
|
||||||
const gchar * g_settings_schema_get_path (GSettingsSchema *schema);
|
const gchar * g_settings_schema_get_path (GSettingsSchema *schema);
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
const gchar * g_settings_schema_get_gettext_domain (GSettingsSchema *schema);
|
const gchar * g_settings_schema_get_gettext_domain (GSettingsSchema *schema);
|
||||||
|
Loading…
Reference in New Issue
Block a user