~timo-jyrinki/ubuntu/trusty/maliit-framework/fix_qt52

« back to all changes in this revision

Viewing changes to maliit-glib/maliitsettingsentry.c

  • Committer: Package Import Robot
  • Author(s): Ricardo Salveti de Araujo, Sergio Schvezov, Ricardo Salveti de Araujo
  • Date: 2013-07-23 19:47:04 UTC
  • mfrom: (1.1.2) (1.2.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130723194704-1lsy1kmlda069cea
Tags: 0.99.0+git20130615+97e8335-0ubuntu1
[ Sergio Schvezov ]
* New build from HEAD 97e8335.
* Packaging import from lp:phablet-extras/maliit-framework.

[ Ricardo Salveti de Araujo ]
* debian/control: adding vcs and fixing dependencies
* General package cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of Maliit framework
2
 
 *
3
 
 * Copyright (C) 2012 Openismus GmbH
4
 
 *
5
 
 * Contact: maliit-discuss@lists.maliit.org
6
 
 *
7
 
 * This library is free software; you can redistribute it and/or
8
 
 * modify it under the terms of the GNU Lesser General Public
9
 
 * License as published by the Free Software Foundation; either
10
 
 * version 2.1 of the licence, or (at your option) any later version.
11
 
 *
12
 
 * This library is distributed in the hope that it will be useful,
13
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 
 * Lesser General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU Lesser General Public
18
 
 * License along with this library; if not, write to the
19
 
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
 
 * Boston, MA 02111-1307, USA.
21
 
 */
22
 
 
23
 
#include "maliitpluginsettingsprivate.h"
24
 
#include "maliitsettingsentryprivate.h"
25
 
 
26
 
#include <dbus/dbus-glib.h>
27
 
 
28
 
/**
29
 
 * SECTION:maliitsettingsentry
30
 
 * @short_description: settings entry
31
 
 * @title: MaliitSettingsEntry
32
 
 * @see_also: #MaliitSettingsEntry, #MaliitPluginSettings
33
 
 * @stability: Stable
34
 
 * @include: maliit/maliitsettingsentry.h
35
 
 *
36
 
 * The #MaliitSettingsEntry is a class holding single plugin
37
 
 * setting. It can be one of several available types
38
 
 * (#MaliitSettingsEntryType). It can also have some attributes like
39
 
 * value domain (MALIIT_SETTING_VALUE_DOMAIN()), default value
40
 
 * (MALIIT_SETTING_DEFAULT_VALUE) and value ranges
41
 
 * (MALIIT_SETTING_VALUE_RANGE_MIN() and
42
 
 * MALIIT_SETTING_VALUE_RANGE_MAX()).
43
 
 */
44
 
 
45
 
struct _MaliitSettingsEntryPrivate
46
 
{
47
 
    MaliitAttributeExtension *extension;
48
 
    gchar *description;
49
 
    gchar *extension_key;
50
 
    MaliitSettingsEntryType type;
51
 
    gboolean valid;
52
 
    GHashTable *attributes;
53
 
 
54
 
    guint extension_signal_id;
55
 
};
56
 
 
57
 
G_DEFINE_TYPE (MaliitSettingsEntry, maliit_settings_entry, G_TYPE_OBJECT)
58
 
 
59
 
enum
60
 
{
61
 
    PROP_0,
62
 
 
63
 
    PROP_EXTENSION,
64
 
    PROP_DESCRIPTION,
65
 
    PROP_EXTENSION_KEY,
66
 
    PROP_TYPE,
67
 
    PROP_VALID,
68
 
    PROP_VALUE,
69
 
    PROP_ATTRIBUTES
70
 
};
71
 
 
72
 
enum
73
 
{
74
 
    VALUE_CHANGED,
75
 
 
76
 
    LAST_SIGNAL
77
 
};
78
 
 
79
 
static guint signals[LAST_SIGNAL] = { 0 };
80
 
 
81
 
static void
82
 
maliit_settings_entry_finalize (GObject *object)
83
 
{
84
 
    MaliitSettingsEntry *entry = MALIIT_SETTINGS_ENTRY (object);
85
 
    MaliitSettingsEntryPrivate *priv = entry->priv;
86
 
 
87
 
    g_free (priv->description);
88
 
    g_free (priv->extension_key);
89
 
 
90
 
    G_OBJECT_CLASS (maliit_settings_entry_parent_class)->finalize (object);
91
 
}
92
 
 
93
 
static void
94
 
maliit_settings_entry_dispose (GObject *object)
95
 
{
96
 
    MaliitSettingsEntry *entry = MALIIT_SETTINGS_ENTRY (object);
97
 
    MaliitSettingsEntryPrivate *priv = entry->priv;
98
 
 
99
 
    if (priv->extension_signal_id) {
100
 
        if (priv->extension) {
101
 
            g_signal_handler_disconnect (priv->extension,
102
 
                                         priv->extension_signal_id);
103
 
        }
104
 
        priv->extension_signal_id = 0;
105
 
    }
106
 
    g_clear_object (&priv->extension);
107
 
    if (priv->attributes) {
108
 
        GHashTable *attributes = priv->attributes;
109
 
 
110
 
        priv->attributes = NULL;
111
 
        g_hash_table_unref (attributes);
112
 
    }
113
 
 
114
 
    G_OBJECT_CLASS (maliit_settings_entry_parent_class)->dispose (object);
115
 
}
116
 
 
117
 
static void
118
 
maliit_settings_entry_set_property (GObject *object,
119
 
                                    guint prop_id,
120
 
                                    const GValue *value,
121
 
                                    GParamSpec *pspec)
122
 
{
123
 
    MaliitSettingsEntry *entry = MALIIT_SETTINGS_ENTRY (object);
124
 
    MaliitSettingsEntryPrivate *priv = entry->priv;
125
 
 
126
 
    switch (prop_id) {
127
 
    case PROP_EXTENSION:
128
 
        if (priv->extension) {
129
 
            g_object_unref (priv->extension);
130
 
        }
131
 
        priv->extension = g_value_dup_object (value);
132
 
        break;
133
 
    case PROP_DESCRIPTION:
134
 
        g_free (priv->description);
135
 
        priv->description = g_value_dup_string (value);
136
 
        break;
137
 
    case PROP_EXTENSION_KEY:
138
 
        g_free (priv->extension_key);
139
 
        priv->extension_key = g_value_dup_string (value);
140
 
        break;
141
 
    case PROP_TYPE:
142
 
        priv->type = g_value_get_enum (value);
143
 
        break;
144
 
    case PROP_VALID:
145
 
        priv->valid = g_value_get_boolean (value);
146
 
        break;
147
 
    case PROP_VALUE:
148
 
        maliit_settings_entry_set_value (entry, g_value_get_variant (value));
149
 
        break;
150
 
    case PROP_ATTRIBUTES:
151
 
        if (priv->attributes) {
152
 
            g_hash_table_unref (priv->attributes);
153
 
        }
154
 
        priv->attributes = g_value_dup_boxed (value);
155
 
        break;
156
 
    default:
157
 
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
158
 
        break;
159
 
    }
160
 
}
161
 
 
162
 
static void
163
 
maliit_settings_entry_get_property (GObject *object,
164
 
                                     guint prop_id,
165
 
                                     GValue *value,
166
 
                                     GParamSpec *pspec)
167
 
{
168
 
    MaliitSettingsEntry *entry = MALIIT_SETTINGS_ENTRY (object);
169
 
    MaliitSettingsEntryPrivate *priv = entry->priv;
170
 
 
171
 
    switch (prop_id) {
172
 
        /* PROP_EXTENSION is write only, construction only - omitted here */
173
 
    case PROP_DESCRIPTION:
174
 
        g_value_set_string (value, priv->description);
175
 
        break;
176
 
    case PROP_EXTENSION_KEY:
177
 
        g_value_set_string (value, priv->extension_key);
178
 
        break;
179
 
    case PROP_TYPE:
180
 
        g_value_set_enum (value, priv->type);
181
 
        break;
182
 
    case PROP_VALID:
183
 
        g_value_set_boolean (value, priv->valid);
184
 
        break;
185
 
    case PROP_VALUE:
186
 
        g_value_set_variant (value,
187
 
                             maliit_settings_entry_get_value (entry));
188
 
        break;
189
 
    case PROP_ATTRIBUTES:
190
 
        g_value_set_boxed (value, priv->attributes);
191
 
        break;
192
 
    default:
193
 
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
194
 
        break;
195
 
    }
196
 
}
197
 
 
198
 
static void
199
 
value_changed(MaliitSettingsEntry *entry,
200
 
              const gchar *key,
201
 
              GVariant *value G_GNUC_UNUSED,
202
 
              gpointer user_data G_GNUC_UNUSED)
203
 
{
204
 
    if (!g_strcmp0 (key, entry->priv->extension_key)) {
205
 
        g_signal_emit(entry, signals[VALUE_CHANGED], 0);
206
 
    }
207
 
}
208
 
 
209
 
static void
210
 
maliit_settings_entry_constructed (GObject *object)
211
 
{
212
 
    MaliitSettingsEntry *entry = MALIIT_SETTINGS_ENTRY (object);
213
 
    MaliitSettingsEntryPrivate *priv = entry->priv;
214
 
 
215
 
    if (priv->extension) {
216
 
        priv->extension_signal_id = g_signal_connect_swapped (priv->extension,
217
 
                                                              "extended-attribute-changed",
218
 
                                                              G_CALLBACK (value_changed),
219
 
                                                              entry);
220
 
    }
221
 
}
222
 
 
223
 
static void
224
 
maliit_settings_entry_class_init (MaliitSettingsEntryClass *entry_class)
225
 
{
226
 
    GObjectClass *g_object_class = G_OBJECT_CLASS (entry_class);
227
 
 
228
 
    g_object_class->finalize = maliit_settings_entry_finalize;
229
 
    g_object_class->dispose = maliit_settings_entry_dispose;
230
 
    g_object_class->set_property = maliit_settings_entry_set_property;
231
 
    g_object_class->get_property = maliit_settings_entry_get_property;
232
 
    g_object_class->constructed = maliit_settings_entry_constructed;
233
 
 
234
 
    /**
235
 
     * MaliitSettingsEntry:extension:
236
 
     *
237
 
     * #MaliitAttributeExtension used by this entry.
238
 
     */
239
 
    g_object_class_install_property (g_object_class,
240
 
                                     PROP_EXTENSION,
241
 
                                     g_param_spec_object ("extension",
242
 
                                                          "Extension", /* TODO: mark as translatable? */
243
 
                                                          "Extension used by this entry", /* TODO: mark as translatable? */
244
 
                                                          MALIIT_TYPE_ATTRIBUTE_EXTENSION,
245
 
                                                          G_PARAM_WRITABLE |
246
 
                                                          G_PARAM_CONSTRUCT_ONLY |
247
 
                                                          G_PARAM_STATIC_NAME |
248
 
                                                          G_PARAM_STATIC_BLURB |
249
 
                                                          G_PARAM_STATIC_NICK));
250
 
 
251
 
    /**
252
 
     * MaliitSettingsEntry:description:
253
 
     *
254
 
     * Description of the entry.
255
 
     */
256
 
    g_object_class_install_property (g_object_class,
257
 
                                     PROP_DESCRIPTION,
258
 
                                     g_param_spec_string ("description",
259
 
                                                          "Description", /* TODO: mark as translatable? */
260
 
                                                          "Description of the entry", /* TODO: mark as translatable? */
261
 
                                                          "",
262
 
                                                          G_PARAM_READABLE |
263
 
                                                          G_PARAM_WRITABLE |
264
 
                                                          G_PARAM_CONSTRUCT_ONLY |
265
 
                                                          G_PARAM_STATIC_NAME |
266
 
                                                          G_PARAM_STATIC_BLURB |
267
 
                                                          G_PARAM_STATIC_NICK));
268
 
 
269
 
    /**
270
 
     * MaliitSettingsEntry:extension-key:
271
 
     *
272
 
     * Key of the entry.
273
 
     */
274
 
    g_object_class_install_property (g_object_class,
275
 
                                     PROP_EXTENSION_KEY,
276
 
                                     g_param_spec_string ("extension-key",
277
 
                                                          "Extension key", /* TODO: mark as translatable? */
278
 
                                                          "Key of the entry.", /* TODO: mark as translatable? */
279
 
                                                          "",
280
 
                                                          G_PARAM_READABLE |
281
 
                                                          G_PARAM_WRITABLE |
282
 
                                                          G_PARAM_CONSTRUCT_ONLY |
283
 
                                                          G_PARAM_STATIC_NAME |
284
 
                                                          G_PARAM_STATIC_BLURB |
285
 
                                                          G_PARAM_STATIC_NICK));
286
 
 
287
 
    /**
288
 
     * MaliitSettingsEntry:type:
289
 
     *
290
 
     * Type of the entry
291
 
     */
292
 
    g_object_class_install_property (g_object_class,
293
 
                                     PROP_TYPE,
294
 
                                     g_param_spec_enum ("type",
295
 
                                                        "Type", /* TODO: mark as translatable? */
296
 
                                                        "Type if the entry", /* TODO: mark as translatable? */
297
 
                                                        MALIIT_TYPE_SETTINGS_ENTRY_TYPE,
298
 
                                                        MALIIT_STRING_TYPE,
299
 
                                                        G_PARAM_READABLE |
300
 
                                                        G_PARAM_WRITABLE |
301
 
                                                        G_PARAM_CONSTRUCT_ONLY |
302
 
                                                        G_PARAM_STATIC_NAME |
303
 
                                                        G_PARAM_STATIC_BLURB |
304
 
                                                        G_PARAM_STATIC_NICK));
305
 
 
306
 
    /**
307
 
     * MaliitSettingsEntry:valid:
308
 
     *
309
 
     * Whether entry's value is valid.
310
 
     */
311
 
    g_object_class_install_property (g_object_class,
312
 
                                     PROP_VALID,
313
 
                                     g_param_spec_boolean ("valid",
314
 
                                                           "Valid", /* TODO: mark as translatable? */
315
 
                                                           "Whether entry's value is valid", /* TODO: mark as translatable? */
316
 
                                                           FALSE,
317
 
                                                           G_PARAM_READABLE |
318
 
                                                           G_PARAM_WRITABLE |
319
 
                                                           G_PARAM_CONSTRUCT_ONLY |
320
 
                                                           G_PARAM_STATIC_NAME |
321
 
                                                           G_PARAM_STATIC_BLURB |
322
 
                                                           G_PARAM_STATIC_NICK));
323
 
 
324
 
    /**
325
 
     * MaliitSettingsEntry:value:
326
 
     *
327
 
     * Value of the entry.
328
 
     */
329
 
    g_object_class_install_property (g_object_class,
330
 
                                     PROP_VALUE,
331
 
                                     g_param_spec_variant ("value",
332
 
                                                           "Value", /* TODO: mark as translatable? */
333
 
                                                           "Value of the entry", /* TODO: mark as translatable? */
334
 
                                                           G_VARIANT_TYPE_ANY,
335
 
                                                           g_variant_new_int32 (0),
336
 
                                                           G_PARAM_READABLE |
337
 
                                                           G_PARAM_WRITABLE |
338
 
                                                           G_PARAM_CONSTRUCT_ONLY |
339
 
                                                           G_PARAM_STATIC_NAME |
340
 
                                                           G_PARAM_STATIC_BLURB |
341
 
                                                           G_PARAM_STATIC_NICK));
342
 
 
343
 
    /**
344
 
     * MaliitSettingsEntry:attributes:
345
 
     *
346
 
     * Attributes of the entry.
347
 
     */
348
 
    g_object_class_install_property (g_object_class,
349
 
                                     PROP_ATTRIBUTES,
350
 
                                     g_param_spec_boxed ("attributes",
351
 
                                                         "Attributes", /* TODO: mark as translatable? */
352
 
                                                         "Attributes of the entry", /* TODO: mark as translatable? */
353
 
                                                         G_TYPE_HASH_TABLE,
354
 
                                                         G_PARAM_READABLE |
355
 
                                                         G_PARAM_WRITABLE |
356
 
                                                         G_PARAM_CONSTRUCT_ONLY |
357
 
                                                         G_PARAM_STATIC_NAME |
358
 
                                                         G_PARAM_STATIC_BLURB |
359
 
                                                         G_PARAM_STATIC_NICK));
360
 
 
361
 
    /**
362
 
     * MaliitSettingsEntry::value-changed:
363
 
     * @entry: The #MaliitSettingsEntry emitting the signal.
364
 
     *
365
 
     * Emitted when value of the entry was changed in the plugin.
366
 
     */
367
 
    signals[VALUE_CHANGED] =
368
 
        g_signal_new ("value-changed",
369
 
                      MALIIT_TYPE_SETTINGS_ENTRY,
370
 
                      G_SIGNAL_RUN_FIRST,
371
 
                      0,
372
 
                      NULL,
373
 
                      NULL,
374
 
                      g_cclosure_marshal_VOID__VOID,
375
 
                      G_TYPE_NONE,
376
 
                      0);
377
 
 
378
 
    g_type_class_add_private (entry_class, sizeof (MaliitSettingsEntryPrivate));
379
 
}
380
 
 
381
 
static void
382
 
maliit_settings_entry_init (MaliitSettingsEntry *entry)
383
 
{
384
 
    MaliitSettingsEntryPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (entry,
385
 
                                                                    MALIIT_TYPE_SETTINGS_ENTRY,
386
 
                                                                    MaliitSettingsEntryPrivate);
387
 
 
388
 
    priv->extension = NULL;
389
 
    priv->description = NULL;
390
 
    priv->extension_key = NULL;
391
 
    priv->type = MALIIT_STRING_TYPE;
392
 
    priv->valid = FALSE;
393
 
    priv->attributes = NULL;
394
 
    priv->extension_signal_id = 0;
395
 
 
396
 
    entry->priv = priv;
397
 
}
398
 
 
399
 
static GHashTable *
400
 
attributes_from_dbus_g_hash_table (GHashTable *dbus_attributes)
401
 
{
402
 
    GHashTable *attributes = g_hash_table_new_full (g_str_hash,
403
 
                                                    g_str_equal,
404
 
                                                    g_free,
405
 
                                                    (GDestroyNotify)g_variant_unref);
406
 
    GHashTableIter iter;
407
 
    gchar *key;
408
 
    GValue *value;
409
 
 
410
 
    g_hash_table_iter_init (&iter, dbus_attributes);
411
 
    while (g_hash_table_iter_next (&iter, (gpointer *)&key, (gpointer *)&value)) {
412
 
        gchar *new_key = g_strdup (key);
413
 
        GVariant *new_variant = dbus_g_value_build_g_variant (value);
414
 
 
415
 
        if (!new_variant) {
416
 
            g_warning ("Failed to convert GValue (%s) to GVariant", G_VALUE_TYPE_NAME (value));
417
 
        }
418
 
        if (g_variant_is_floating (new_variant)) {
419
 
            g_variant_ref_sink (new_variant);
420
 
        }
421
 
        g_hash_table_replace (attributes, new_key, new_variant);
422
 
    }
423
 
 
424
 
    return attributes;
425
 
}
426
 
 
427
 
static gboolean
428
 
dbus_info_is_valid (GValueArray *info)
429
 
{
430
 
    static GType expected_types[] = {
431
 
        G_TYPE_STRING, /* description */
432
 
        G_TYPE_STRING, /* extension key */
433
 
        G_TYPE_INT, /* entry type */
434
 
        G_TYPE_BOOLEAN, /* value validity */
435
 
        G_TYPE_INVALID, /* current value, set in the first run */
436
 
        G_TYPE_INVALID /* attributes, set in the first run */
437
 
    };
438
 
 
439
 
    guint iter;
440
 
    gint enum_value;
441
 
 
442
 
 
443
 
    if (expected_types[4] == G_TYPE_INVALID) {
444
 
        expected_types[4] = G_TYPE_VALUE;
445
 
    }
446
 
    if (expected_types[5] == G_TYPE_INVALID) {
447
 
        expected_types[5] = dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE);
448
 
    }
449
 
 
450
 
    if (!info) {
451
 
        return FALSE;
452
 
    }
453
 
    if (info->n_values != G_N_ELEMENTS(expected_types)) {
454
 
        return FALSE;
455
 
    }
456
 
 
457
 
    for (iter = 0; iter < G_N_ELEMENTS(expected_types); ++iter) {
458
 
        GValue *value = g_value_array_get_nth (info, iter);
459
 
 
460
 
        if (!value) {
461
 
            return FALSE;
462
 
        }
463
 
        if (!G_VALUE_HOLDS (value, expected_types[iter])) {
464
 
            return FALSE;
465
 
        }
466
 
    }
467
 
 
468
 
    enum_value = g_value_get_int (g_value_array_get_nth (info, 2));
469
 
 
470
 
    if (enum_value < MALIIT_STRING_TYPE || enum_value > MALIIT_INT_LIST_TYPE) {
471
 
        return FALSE;
472
 
    }
473
 
 
474
 
    return TRUE;
475
 
}
476
 
 
477
 
/**
478
 
 * maliit_settings_entry_new_from_dbus_data: (skip)
479
 
 * @info: (transfer none): A #GValueArray of DBus provenance containing entry information.
480
 
 * @extension: (transfer none): A #MaliitAttributeExtensions for #MaliitAttributeSettingsEntry instance.
481
 
 *
482
 
 * Creates new settings entry. This is used internally only by
483
 
 * #MaliitPluginSettings.
484
 
 *
485
 
 * Returns: (transfer full): The newly created #MaliitSettingsEntry.
486
 
 */
487
 
MaliitSettingsEntry *
488
 
maliit_settings_entry_new_from_dbus_data (GValueArray *info,
489
 
                                          MaliitAttributeExtension *extension)
490
 
{
491
 
    const gchar *description;
492
 
    const gchar *extension_key;
493
 
    MaliitSettingsEntryType type;
494
 
    gboolean valid;
495
 
    GVariant *value;
496
 
    GHashTable *attributes;
497
 
    MaliitSettingsEntry *entry;
498
 
 
499
 
    g_return_val_if_fail (MALIIT_IS_ATTRIBUTE_EXTENSION (extension), NULL);
500
 
    g_return_val_if_fail (dbus_info_is_valid (info), NULL);
501
 
 
502
 
    description = g_value_get_string (g_value_array_get_nth (info, 0));
503
 
    extension_key = g_value_get_string (g_value_array_get_nth (info, 1));
504
 
    type = (MaliitSettingsEntryType) g_value_get_int (g_value_array_get_nth (info, 2));
505
 
    valid = g_value_get_boolean (g_value_array_get_nth (info, 3));
506
 
    value = dbus_g_value_build_g_variant (g_value_get_boxed (g_value_array_get_nth (info, 4)));
507
 
 
508
 
    if (g_variant_is_floating (value)) {
509
 
        g_variant_ref_sink (value);
510
 
    }
511
 
 
512
 
    attributes = attributes_from_dbus_g_hash_table (g_value_get_boxed (g_value_array_get_nth (info, 5)));
513
 
    entry = MALIIT_SETTINGS_ENTRY (g_object_new (MALIIT_TYPE_SETTINGS_ENTRY,
514
 
                                                 "extension", extension,
515
 
                                                 "description", description,
516
 
                                                 "extension-key", extension_key,
517
 
                                                 "type", type,
518
 
                                                 "valid", valid,
519
 
                                                 "value", value,
520
 
                                                 "attributes", attributes,
521
 
                                                 NULL));
522
 
 
523
 
    g_hash_table_unref (attributes);
524
 
    g_variant_unref (value);
525
 
    return entry;
526
 
}
527
 
 
528
 
/**
529
 
 * maliit_settings_entry_get_description:
530
 
 * @entry: (transfer none): The #MaliitSettingsEntry.
531
 
 *
532
 
 * Gets description of the entry.
533
 
 *
534
 
 * Returns: (transfer none): A description. Returned value should not be modified nor freed.
535
 
 */
536
 
const gchar *
537
 
maliit_settings_entry_get_description (MaliitSettingsEntry *entry)
538
 
{
539
 
    g_return_val_if_fail (MALIIT_IS_SETTINGS_ENTRY (entry), NULL);
540
 
 
541
 
    return entry->priv->description;
542
 
}
543
 
 
544
 
/**
545
 
 * maliit_settings_entry_get_key:
546
 
 * @entry: (transfer none): The #MaliitSettingsEntry.
547
 
 *
548
 
 * Gets key of the entry.
549
 
 *
550
 
 * Returns: (transfer none): A key. Returned value should not be modified nor freed.
551
 
 */
552
 
const gchar *
553
 
maliit_settings_entry_get_key (MaliitSettingsEntry *entry)
554
 
{
555
 
    g_return_val_if_fail (MALIIT_IS_SETTINGS_ENTRY (entry), NULL);
556
 
 
557
 
    return entry->priv->extension_key;
558
 
}
559
 
 
560
 
/**
561
 
 * maliit_settings_entry_get_entry_type:
562
 
 * @entry: (transfer none): The #MaliitSettingsEntry.
563
 
 *
564
 
 * Gets type of the entry.
565
 
 *
566
 
 * Returns: A type.
567
 
 */
568
 
MaliitSettingsEntryType
569
 
maliit_settings_entry_get_entry_type (MaliitSettingsEntry *entry)
570
 
{
571
 
    g_return_val_if_fail (MALIIT_IS_SETTINGS_ENTRY (entry), MALIIT_STRING_TYPE);
572
 
 
573
 
    return entry->priv->type;
574
 
}
575
 
 
576
 
/**
577
 
 * maliit_settings_entry_is_current_value_valid:
578
 
 * @entry: (transfer none): The #MaliitSettingsEntry.
579
 
 *
580
 
 * Gets whether current value of the entry is valid.
581
 
 *
582
 
 * Returns: %TRUE if valid, otherwise %FALSE
583
 
 */
584
 
gboolean
585
 
maliit_settings_entry_is_current_value_valid (MaliitSettingsEntry *entry)
586
 
{
587
 
    g_return_val_if_fail (MALIIT_IS_SETTINGS_ENTRY (entry), FALSE);
588
 
 
589
 
    return entry->priv->valid;
590
 
}
591
 
 
592
 
/**
593
 
 * maliit_settings_entry_get_value:
594
 
 * @entry: (transfer none): The #MaliitSettingsEntry.
595
 
 *
596
 
 * Gets value of the entry. Check its validity with
597
 
 * maliit_settings_entry_is_current_value_valid() before using it.
598
 
 *
599
 
 * Returns: (transfer none): A value.
600
 
 */
601
 
GVariant *
602
 
maliit_settings_entry_get_value (MaliitSettingsEntry *entry)
603
 
{
604
 
    GHashTable *attributes;
605
 
    MaliitSettingsEntryPrivate *priv;
606
 
 
607
 
    g_return_val_if_fail (MALIIT_IS_SETTINGS_ENTRY (entry), NULL);
608
 
 
609
 
    priv = entry->priv;
610
 
    attributes = maliit_attribute_extension_get_attributes (priv->extension);
611
 
 
612
 
    return g_hash_table_lookup (attributes, priv->extension_key);
613
 
}
614
 
 
615
 
/**
616
 
 * maliit_settings_entry_set_value:
617
 
 * @entry: (transfer none): The #MaliitSettingsEntry.
618
 
 * @value: (transfer none): The #GVariant.
619
 
 *
620
 
 * Sets a new value of the entry. Before setting new value, validate
621
 
 * it with maliit_settings_entry_is_value_valid().
622
 
 */
623
 
void
624
 
maliit_settings_entry_set_value (MaliitSettingsEntry *entry,
625
 
                                 GVariant *value)
626
 
{
627
 
    MaliitSettingsEntryPrivate *priv;
628
 
 
629
 
    g_return_if_fail (MALIIT_IS_SETTINGS_ENTRY (entry));
630
 
 
631
 
    priv = entry->priv;
632
 
    maliit_attribute_extension_set_attribute (priv->extension,
633
 
                                              priv->extension_key,
634
 
                                              value);
635
 
}
636
 
 
637
 
/**
638
 
 * maliit_settings_entry_is_value_valid:
639
 
 * @entry: (transfer none): The #MaliitSettingsEntry.
640
 
 * @value: (transfer none): The #GVariant
641
 
 *
642
 
 * Checks whether the value is valid one for the entry.
643
 
 *
644
 
 * Returns: %TRUE if valid, otherwise %FALSE.
645
 
 */
646
 
gboolean
647
 
maliit_settings_entry_is_value_valid (MaliitSettingsEntry *entry,
648
 
                                      GVariant *value)
649
 
{
650
 
    MaliitSettingsEntryPrivate *priv;
651
 
 
652
 
    g_return_val_if_fail (MALIIT_IS_SETTINGS_ENTRY (entry), FALSE);
653
 
 
654
 
    priv = entry->priv;
655
 
    return maliit_validate_setting_value (priv->type, priv->attributes, value);
656
 
}
657
 
 
658
 
/**
659
 
 * maliit_settings_entry_get_attributes:
660
 
 * @entry: (transfer none): The #MaliitSettingsEntry.
661
 
 *
662
 
 * Gets attributes of the entry. The keys of the attributes are
663
 
 * MALIIT_SETTING_VALUE_DOMAIN(),
664
 
 * MALIIT_SETTING_VALUE_DOMAIN_DESCRIPTIONS(),
665
 
 * MALIIT_SETTING_VALUE_RANGE_MIN(), MALIIT_SETTING_VALUE_RANGE_MAX()
666
 
 * and MALIIT_SETTING_DEFAULT_VALUE(). Note that these keys don't have
667
 
 * to exist in attributes.
668
 
 *
669
 
 * Returns: (transfer none) (element-type utf8 GLib.Variant): Attributes. Returned value should not be modified nor freed.
670
 
 */
671
 
GHashTable *
672
 
maliit_settings_entry_get_attributes (MaliitSettingsEntry *entry)
673
 
{
674
 
    g_return_val_if_fail (MALIIT_IS_SETTINGS_ENTRY (entry), NULL);
675
 
 
676
 
    return entry->priv->attributes;
677
 
}