~ubuntu-branches/ubuntu/quantal/ibus/quantal

« back to all changes in this revision

Viewing changes to memconf/config.c

  • Committer: Bazaar Package Importer
  • Author(s): Barry Warsaw
  • Date: 2011-08-11 17:00:57 UTC
  • mfrom: (6.2.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110811170057-6dmbfs4s3cchzl7x
Tags: 1.3.99.20110419-1ubuntu1
* Merge with Debian unstable.  Remaining Ubuntu changes:
  - Indicator support:
    + Add 05_appindicator.patch: Use an indicator rather than a notification
      icon.
    + debian/control: Recommend python-appindicator.
  - debian/control: Install im-switch instead of im-config by default.
  - debian/README.source: Removed, it was outdated and no longer correct
  - debian/patches/01_ubuntu_desktop: Fix "Desktop entry needs the
    X-Ubuntu-Gettext-Domain key"  (LP: #457632)
  - debian/patches/02_title_update.patch: Rename "IBus Preferences" to
    "Keyboard Input Methods"
  - debian/patches/06_locale_parser.patch: Cherry-picked from upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
 
2
/* vim:set et sts=4: */
 
3
/* ibus - The Input Bus
 
4
 * Copyright (c) 2010, Google Inc. All rights reserved.
 
5
 * Copyright (C) 2010 Peng Huang <shawn.p.huang@gmail.com>
 
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 of the License, 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
#include <string.h>
 
23
#include <ibus.h>
 
24
#include "config.h"
 
25
 
 
26
 
 
27
typedef struct _IBusConfigMemconfClass IBusConfigMemconfClass;
 
28
 
 
29
struct _IBusConfigMemconf {
 
30
    IBusConfigService parent;
 
31
    GHashTable *values;
 
32
};
 
33
 
 
34
struct _IBusConfigMemconfClass {
 
35
    IBusConfigServiceClass parent;
 
36
};
 
37
 
 
38
/* functions prototype */
 
39
static void         ibus_config_memconf_class_init  (IBusConfigMemconfClass *class);
 
40
static void         ibus_config_memconf_init        (IBusConfigMemconf      *config);
 
41
static void         ibus_config_memconf_destroy     (IBusConfigMemconf      *config);
 
42
static gboolean     ibus_config_memconf_set_value   (IBusConfigService      *config,
 
43
                                                     const gchar            *section,
 
44
                                                     const gchar            *name,
 
45
                                                     GVariant               *value,
 
46
                                                     GError                **error);
 
47
static GVariant    *ibus_config_memconf_get_value   (IBusConfigService      *config,
 
48
                                                     const gchar            *section,
 
49
                                                     const gchar            *name,
 
50
                                                     GError                **error);
 
51
static gboolean     ibus_config_memconf_unset_value (IBusConfigService      *config,
 
52
                                                     const gchar            *section,
 
53
                                                     const gchar            *name,
 
54
                                                     GError                **error);
 
55
 
 
56
G_DEFINE_TYPE (IBusConfigMemconf, ibus_config_memconf, IBUS_TYPE_CONFIG_SERVICE)
 
57
 
 
58
static void
 
59
ibus_config_memconf_class_init (IBusConfigMemconfClass *class)
 
60
{
 
61
    GObjectClass *object_class = G_OBJECT_CLASS (class);
 
62
 
 
63
    IBUS_OBJECT_CLASS (object_class)->destroy = (IBusObjectDestroyFunc) ibus_config_memconf_destroy;
 
64
    IBUS_CONFIG_SERVICE_CLASS (object_class)->set_value   = ibus_config_memconf_set_value;
 
65
    IBUS_CONFIG_SERVICE_CLASS (object_class)->get_value   = ibus_config_memconf_get_value;
 
66
    IBUS_CONFIG_SERVICE_CLASS (object_class)->unset_value = ibus_config_memconf_unset_value;
 
67
}
 
68
 
 
69
static void
 
70
ibus_config_memconf_init (IBusConfigMemconf *config)
 
71
{
 
72
    config->values = g_hash_table_new_full (g_str_hash,
 
73
                                            g_str_equal,
 
74
                                            (GDestroyNotify)g_free,
 
75
                                            (GDestroyNotify)g_variant_unref);
 
76
}
 
77
 
 
78
static void
 
79
ibus_config_memconf_destroy (IBusConfigMemconf *config)
 
80
{
 
81
    g_hash_table_destroy (config->values);
 
82
    IBUS_OBJECT_CLASS (ibus_config_memconf_parent_class)->destroy ((IBusObject *)config);
 
83
}
 
84
 
 
85
static gboolean
 
86
ibus_config_memconf_set_value (IBusConfigService *config,
 
87
                               const gchar       *section,
 
88
                               const gchar       *name,
 
89
                               GVariant          *value,
 
90
                               GError           **error)
 
91
{
 
92
    g_assert (IBUS_IS_CONFIG_MEMCONF (config));
 
93
    g_assert (section);
 
94
    g_assert (name);
 
95
    g_assert (value);
 
96
    g_assert (error == NULL || *error == NULL);
 
97
 
 
98
    gchar *key = g_strdup_printf ("%s:%s", section, name);
 
99
 
 
100
    g_hash_table_insert (IBUS_CONFIG_MEMCONF (config)->values,
 
101
                         key, g_variant_ref_sink (value));
 
102
 
 
103
    ibus_config_service_value_changed (config, section, name, value);
 
104
 
 
105
    return TRUE;
 
106
}
 
107
 
 
108
static GVariant *
 
109
ibus_config_memconf_get_value (IBusConfigService *config,
 
110
                               const gchar       *section,
 
111
                               const gchar       *name,
 
112
                               GError           **error)
 
113
{
 
114
    g_assert (IBUS_IS_CONFIG_MEMCONF (config));
 
115
    g_assert (section);
 
116
    g_assert (name);
 
117
    g_assert (error == NULL || *error == NULL);
 
118
 
 
119
    gchar *key = g_strdup_printf ("%s:%s", section, name);
 
120
    GVariant *value = (GVariant *)g_hash_table_lookup (IBUS_CONFIG_MEMCONF (config)->values, key);
 
121
    g_free (key);
 
122
 
 
123
    if (value != NULL) {
 
124
        g_variant_ref (value);
 
125
    }
 
126
    else if (error != NULL) {
 
127
        *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
 
128
                              "Config value [%s:%s] does not exist.", section, name);
 
129
    }
 
130
    return value;
 
131
}
 
132
 
 
133
static gboolean
 
134
ibus_config_memconf_unset_value (IBusConfigService *config,
 
135
                                 const gchar       *section,
 
136
                                 const gchar       *name,
 
137
                                 GError            **error)
 
138
{
 
139
    g_assert (IBUS_IS_CONFIG_MEMCONF (config));
 
140
    g_assert (section);
 
141
    g_assert (name);
 
142
    g_assert (error == NULL || *error == NULL);
 
143
 
 
144
    gchar *key = g_strdup_printf ("%s:%s", section, name);
 
145
    gboolean retval = g_hash_table_remove (IBUS_CONFIG_MEMCONF (config)->values, key);
 
146
    g_free (key);
 
147
 
 
148
    if (retval) {
 
149
    }
 
150
    else {
 
151
        if (error && *error) {
 
152
            *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
 
153
                                  "Config value [%s:%s] does not exist.", section, name);
 
154
        }
 
155
    }
 
156
    return retval;
 
157
}
 
158
 
 
159
IBusConfigMemconf *
 
160
ibus_config_memconf_new (GDBusConnection *connection)
 
161
{
 
162
    IBusConfigMemconf *config;
 
163
    config = (IBusConfigMemconf *) g_object_new (IBUS_TYPE_CONFIG_MEMCONF,
 
164
                                                 "object-path", IBUS_PATH_CONFIG,
 
165
                                                 "connection", connection,
 
166
                                                 NULL);
 
167
    return config;
 
168
}