~noskcaj/ubuntu/wily/light-locker/merge

« back to all changes in this revision

Viewing changes to src/ll-config.c

  • Committer: Package Import Robot
  • Author(s): Sean Davis
  • Date: 2014-12-17 06:30:58 UTC
  • mfrom: (1.1.4) (0.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20141217063058-zqkhtlmtx8sfmjod
Tags: 1.5.1-0ubuntu1
* New development release.
* Merged packaging from debian unstable, remaining changes:
  - debian/control: 
    - Remove liblightdm-gobject-dev, not in Ubuntu and not required 
      to build and operate
    - Add light-locker-settings | xfce4-power-manager to Recommends
    - Update standards version to 3.9.6
  - debian/rules:
    - Build with no-lock-on-suspend and late-locking support

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "config.h"
 
2
 
 
3
#include <stdio.h>
 
4
#include <stdlib.h>
 
5
#include <string.h>
 
6
 
 
7
#include <gio/gio.h>
 
8
 
 
9
#include "ll-config.h"
 
10
 
 
11
#define LIGHT_LOCKER_SCHEMA          "apps.light-locker"
 
12
 
 
13
/* Property identifiers */
 
14
enum
 
15
{
 
16
    PROP_0,
 
17
    PROP_LOCK_ON_SUSPEND,
 
18
    PROP_LATE_LOCKING,
 
19
    PROP_LOCK_AFTER_SCREENSAVER,
 
20
    N_PROP
 
21
};
 
22
 
 
23
 
 
24
static void ll_config_get_property  (GObject        *object,
 
25
                                     guint           prop_id,
 
26
                                     GValue         *value,
 
27
                                     GParamSpec     *pspec);
 
28
static void ll_config_set_property  (GObject        *object,
 
29
                                     guint           prop_id,
 
30
                                     const GValue   *value,
 
31
                                     GParamSpec     *pspec);
 
32
 
 
33
 
 
34
struct _LLConfigClass
 
35
{
 
36
    GObjectClass __parent__;
 
37
};
 
38
 
 
39
struct _LLConfig
 
40
{
 
41
    GObject    __parent__;
 
42
    GSettings *settings;
 
43
    guint      lock_after_screensaver;
 
44
    gboolean   late_locking : 1;
 
45
    gboolean   lock_on_suspend : 1;
 
46
};
 
47
 
 
48
G_DEFINE_TYPE (LLConfig, ll_config, G_TYPE_OBJECT)
 
49
 
 
50
 
 
51
/**
 
52
 * ll_config_set_property:
 
53
 * @object  : a #LLConfig instance passed as #GObject.
 
54
 * @prop_id : the ID of the property being set.
 
55
 * @value   : the value of the property being set.
 
56
 * @pspec   : the property #GParamSpec.
 
57
 *
 
58
 * Write property-values to GSettings.
 
59
 **/
 
60
static void ll_config_set_property (GObject      *object,
 
61
                                    guint         prop_id,
 
62
                                    const GValue *value,
 
63
                                    GParamSpec   *pspec)
 
64
{
 
65
    LLConfig  *conf = LL_CONFIG (object);
 
66
 
 
67
    switch (prop_id)
 
68
    {
 
69
        case PROP_LATE_LOCKING:
 
70
            conf->late_locking = g_value_get_boolean(value);
 
71
            break;
 
72
 
 
73
        case PROP_LOCK_AFTER_SCREENSAVER:
 
74
            conf->lock_after_screensaver = g_value_get_uint(value);
 
75
            break;
 
76
 
 
77
        case PROP_LOCK_ON_SUSPEND:
 
78
            conf->lock_on_suspend = g_value_get_boolean(value);
 
79
            break;
 
80
 
 
81
        default:
 
82
            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
83
            break;
 
84
    }
 
85
}
 
86
 
 
87
/**
 
88
 * ll_config_get_property:
 
89
 * @object  : a #LLConfig instance passed as #GObject.
 
90
 * @prop_id : the ID of the property being retrieved.
 
91
 * @value   : the return variable for the value of the property being retrieved.
 
92
 * @pspec   : the property #GParamSpec.
 
93
 *
 
94
 * Read property-values from GSettings.
 
95
 **/
 
96
static void ll_config_get_property (GObject    *object,
 
97
                                    guint       prop_id,
 
98
                                    GValue     *value,
 
99
                                    GParamSpec *pspec)
 
100
{
 
101
    LLConfig  *conf = LL_CONFIG (object);
 
102
 
 
103
    switch (prop_id)
 
104
    {
 
105
        case PROP_LATE_LOCKING:
 
106
            g_value_set_boolean(value, conf->late_locking);
 
107
            break;
 
108
 
 
109
        case PROP_LOCK_AFTER_SCREENSAVER:
 
110
            g_value_set_uint(value, conf->lock_after_screensaver);
 
111
            break;
 
112
 
 
113
        case PROP_LOCK_ON_SUSPEND:
 
114
            g_value_set_boolean(value, conf->lock_on_suspend);
 
115
            break;
 
116
 
 
117
        default:
 
118
            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
119
            break;
 
120
    }
 
121
}
 
122
 
 
123
/**
 
124
 * ll_config_class_init:
 
125
 * @klass : a #LLConfigClass to initialize.
 
126
 *
 
127
 * Initialize a base #LLConfigClass instance.
 
128
 **/
 
129
static void
 
130
ll_config_class_init (LLConfigClass *klass)
 
131
{
 
132
    GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
133
 
 
134
    object_class->get_property = ll_config_get_property;
 
135
    object_class->set_property = ll_config_set_property;
 
136
 
 
137
    /**
 
138
     * LLConfig:lock-on-suspend:
 
139
     *
 
140
     * Enable lock-on-suspend
 
141
     **/
 
142
    g_object_class_install_property (object_class,
 
143
                                     PROP_LOCK_ON_SUSPEND,
 
144
                                     g_param_spec_boolean ("lock-on-suspend",
 
145
                                                           NULL,
 
146
                                                           NULL,
 
147
                                                           FALSE,
 
148
                                                           G_PARAM_READWRITE));
 
149
 
 
150
    /**
 
151
     * LLConfig:late-locking:
 
152
     *
 
153
     * Lock after screensaver has ended.
 
154
     **/
 
155
    g_object_class_install_property (object_class,
 
156
                                     PROP_LATE_LOCKING,
 
157
                                     g_param_spec_boolean ("late-locking",
 
158
                                                           NULL,
 
159
                                                           NULL,
 
160
                                                           FALSE,
 
161
                                                           G_PARAM_READWRITE));
 
162
 
 
163
    /**
 
164
     * LLConfig:lock-after-screensaver:
 
165
     *
 
166
     * Seconds after screensaver to lock
 
167
     **/
 
168
    g_object_class_install_property (object_class,
 
169
                                     PROP_LOCK_AFTER_SCREENSAVER,
 
170
                                     g_param_spec_uint ("lock-after-screensaver",
 
171
                                                        NULL,
 
172
                                                        NULL,
 
173
                                                        0,
 
174
                                                        3600,
 
175
                                                        0,
 
176
                                                        G_PARAM_READWRITE));
 
177
}
 
178
 
 
179
/**
 
180
 * ll_config_init:
 
181
 * @conf : a #LLConfig instance.
 
182
 *
 
183
 * Initialize a #LLConfig instance.
 
184
 **/
 
185
static void
 
186
ll_config_init (LLConfig *conf)
 
187
{
 
188
#ifdef WITH_SETTINGS_BACKEND
 
189
    GSettingsSchemaSource *schema_source;
 
190
    GSettingsSchema       *schema;
 
191
    GParamSpec           **prop_list;
 
192
    guint                  i, n_prop;
 
193
#endif
 
194
 
 
195
    conf->lock_after_screensaver = 5;
 
196
#ifdef WITH_LATE_LOCKING
 
197
    conf->late_locking = WITH_LATE_LOCKING;
 
198
#endif
 
199
#ifdef WITH_LOCK_ON_SUSPEND
 
200
    conf->lock_on_suspend = WITH_LOCK_ON_SUSPEND;
 
201
#endif
 
202
 
 
203
#ifdef WITH_SETTINGS_BACKEND
 
204
#define GSETTINGS 1
 
205
#if WITH_SETTINGS_BACKEND == GSETTINGS
 
206
    schema_source = g_settings_schema_source_get_default();
 
207
    schema = g_settings_schema_source_lookup (schema_source, LIGHT_LOCKER_SCHEMA, FALSE);
 
208
    if (schema != NULL)
 
209
    {
 
210
        conf->settings = g_settings_new(LIGHT_LOCKER_SCHEMA);
 
211
 
 
212
        prop_list = g_object_class_list_properties (G_OBJECT_GET_CLASS (conf), &n_prop);
 
213
        for (i = 0; i < n_prop; i++)
 
214
        {
 
215
            const gchar *name = g_param_spec_get_name (prop_list[i]);
 
216
            g_settings_bind (conf->settings, name, conf, name, G_SETTINGS_BIND_DEFAULT);
 
217
        }
 
218
        g_free (prop_list);
 
219
 
 
220
        g_settings_schema_unref (schema);
 
221
    }
 
222
    else
 
223
    {
 
224
        g_warning("Schema \"%s\" not found. Not storing runtime settings.", LIGHT_LOCKER_SCHEMA);
 
225
    }
 
226
#endif
 
227
#undef GSETTINGS
 
228
#endif
 
229
}
 
230
 
 
231
/**
 
232
 * ll_config_new:
 
233
 *
 
234
 * Create a new #LLConfig instance.
 
235
 **/
 
236
LLConfig *
 
237
ll_config_new (void)
 
238
{
 
239
    return g_object_new (LL_TYPE_CONFIG, NULL);
 
240
}