~audio-recorder/audio-recorder/trunk

69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
1
/*
1424 by Osmo Antero
Version 3.0.0
2
 * Copyright (c) 2011- Osmo Antero.
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Library General Public
6
 * License as published by the Free Software Foundation; either
239 by Osmo Antero
Moving to GPL3 license. All src/*.c should now comply to GPL3.
7
 * version 3 of the License (GPL3), or any later version.
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
8
 *
9
 * This library is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
463 by Osmo Antero
Updated README and INSTALL files.
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
239 by Osmo Antero
Moving to GPL3 license. All src/*.c should now comply to GPL3.
12
 * See the GNU Library General Public License 3 for more details.
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
13
 *
14
 * You should have received a copy of the GNU Library General Public
239 by Osmo Antero
Moving to GPL3 license. All src/*.c should now comply to GPL3.
15
 * License 3 along with this program; if not, see /usr/share/common-licenses/GPL file
1012.1.5 by David Rabel
GPL boilerplate updated in source files.
16
 * or <http://www.gnu.org/licenses/>.
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
17
*/
18
#include <string.h>
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
19
#include <stdlib.h>
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
20
#include "dconf.h"
21
#include "support.h"
22
#include "utility.h"
23
#include "log.h"
470.2.2 by Osmo Antero
Preparing packaging of v.1.6-5 for Ubuntu 15.10.
24
#include <gio/gio.h>
25
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
26
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
27
// This module writes and reads values from/to GNOME's configuration registry (GSettings).
28
// DConf is most likely the backend.
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
29
// You can check these values in dconf-editor.
30
// Start dconf-editor and browse to /apps/audio-recorder/.
31
32
// Notice:
33
// All valid configuration keys must be defined in the schema file "org.gnome.audio-recorder.gschema.xml".
34
// It's in the data/ folder.
35
// You must also compile and install this file to /usr/share/glib-2.0/schemas/ directory.
36
//
37
// 0) Test the schema file first. I assume here that the schema is in the current (.) directory.
38
//    $ glib-compile-schemas --dry-run .
39
//
40
// 1) Copy the schema file to /usr/share/glib-2.0/schemas/.
41
//    $ sudo cp org.gnome.audio-recorder.gschema.xml /usr/share/glib-2.0/schemas/
42
//
43
// 2) Then re-compile all schemas.
44
//    $ sudo glib-compile-schemas /usr/share/glib-2.0/schemas/
45
//
46
// The Makefile.am in the data/ folder should do this installation automatically.
47
//
48
// You can also study various schema values with gsettings tool.
49
// $ gsettings
469 by Osmo Antero
audio-recorder --reset did not always work because GSettings registry was not flushed immediately.
50
//
51
// This command will list all keys and values for org.gnome.audio-recorder 
52
// $ gsettings  list-recursively  org.gnome.audio-recorder
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
53
// -----------------------------------------------------------------
54
//
55
// The main schema name is "org.gnome.audio-recorder", and its path is /apps/audio-recorder/.
56
// Notice that there are also child schemas (sub paths) for
57
//  track/ (/apps/audio-recorder/track/).
58
//  skype/ (/apps/audio-recorder/skype/).
59
//  players/ (/apps/audio-recorder/players/).
60
61
// The main configuration schema for this application
62
#define APPLICATION_SETTINGS_SCHEMA "org.gnome.audio-recorder"
63
469 by Osmo Antero
audio-recorder --reset did not always work because GSettings registry was not flushed immediately.
64
static GSettings *conf_get_base_settings();
65
66
void conf_flush_settings() {
67
    // Flush and write settings cache to disk
68
    g_settings_sync();
69
70
    GSettings *settings = conf_get_base_settings();
71
    if (!settings) {
72
        return;
73
    }
74
75
    guint i = 0;
76
    while (i++ < 4 && g_settings_get_has_unapplied(settings)) {
77
        g_settings_sync();
78
        g_usleep(G_USEC_PER_SEC * 0.1);
79
    }
80
}
81
82
static gboolean conf_is_valid_key(GSettings *settings, gchar *key) {
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
83
    // Check if the key is valid key within settings
84
    if (!G_IS_SETTINGS(settings)) {
85
        return FALSE;
86
    }
87
88
    // Get list of keys
89
    gchar **keys = NULL;
470.2.5 by Osmo Antero
Removed deprecated GLIB 2.46 and GTK 3.16 functions.
90
91
// Check:
92
// $ pkg-config --modversion glib-2.0 
93
//
94
#if GLIB_CHECK_VERSION(2, 45, 6)
470.2.2 by Osmo Antero
Preparing packaging of v.1.6-5 for Ubuntu 15.10.
95
    GSettingsSchema *schema = NULL;
470.2.5 by Osmo Antero
Removed deprecated GLIB 2.46 and GTK 3.16 functions.
96
    g_object_get(settings, "settings-schema", &schema, NULL);
470.2.2 by Osmo Antero
Preparing packaging of v.1.6-5 for Ubuntu 15.10.
97
    keys = g_settings_schema_list_keys(schema);
470.2.5 by Osmo Antero
Removed deprecated GLIB 2.46 and GTK 3.16 functions.
98
#else
99
    keys = g_settings_list_keys(settings);
100
#endif
470.2.2 by Osmo Antero
Preparing packaging of v.1.6-5 for Ubuntu 15.10.
101
102
    gint i = 0;
103
    gboolean found = FALSE;
104
    while (keys && keys[i]) {
105
470.2.5 by Osmo Antero
Removed deprecated GLIB 2.46 and GTK 3.16 functions.
106
        //Debug:
107
        //GVariant *value = NULL;
108
        //gchar *str = NULL;
470.2.2 by Osmo Antero
Preparing packaging of v.1.6-5 for Ubuntu 15.10.
109
        //value = g_settings_get_value (settings, keys[i]);
110
        //str = g_variant_print(value, TRUE);
111
        //g_print ("%s %s %s\n", g_settings_schema_get_id (schema), keys[i], str);
112
        //g_variant_unref(value);
113
        //g_free (str);
114
115
        if (!g_strcmp0(key, keys[i])) {
116
            found = TRUE;
117
            break;
118
        }
119
        i++;
120
    }
121
122
    g_strfreev(keys);
470.2.5 by Osmo Antero
Removed deprecated GLIB 2.46 and GTK 3.16 functions.
123
124
#if GLIB_CHECK_VERSION(2, 45, 6)
470.2.2 by Osmo Antero
Preparing packaging of v.1.6-5 for Ubuntu 15.10.
125
    g_settings_schema_unref(schema);
470.2.5 by Osmo Antero
Removed deprecated GLIB 2.46 and GTK 3.16 functions.
126
#endif
470.2.2 by Osmo Antero
Preparing packaging of v.1.6-5 for Ubuntu 15.10.
127
128
    return found;
129
}
130
131
132
#if 0
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
133
void conf_list_keys(GSettings *settings) {
134
    // List keys for the given settings (and schema)
135
    gchar *str = NULL;
136
    g_object_get(settings, "schema", &str, NULL);
137
    if (!str) {
138
        g_print("Bad schema:%s\n", str);
139
    }
140
141
    gchar **keys = NULL;
142
    gint i = 0;
143
    keys = g_settings_list_keys(settings);
144
    while (keys && keys[i]) {
145
        g_print("List key for schema:%s key:%s\n",  str, keys[i]);
146
        i++;
147
    }
148
149
    g_strfreev(keys);
150
    g_free(str);
151
}
152
153
void conf_list_children(GSettings *settings) {
154
    // List children of the given settings (and schema)
155
    gchar *str = NULL;
156
    g_object_get(settings, "schema", &str, NULL);
157
    if (!str) {
158
        g_print("Bad schema:%s\n", str);
159
    }
160
161
    gchar **children = NULL;
162
    gint i = 0;
163
    children = g_settings_list_children(settings);
164
    while (children && children[i]) {
165
        g_print("List child for schema:%s child:%s\n",  str, children[i]);
166
        i++;
167
    }
168
169
    g_strfreev(children);
170
    g_free(str);
171
}
172
#endif
173
469 by Osmo Antero
audio-recorder --reset did not always work because GSettings registry was not flushed immediately.
174
static void conf_get_child_path(gchar *key, gchar **child_path, gchar **child_key) {
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
175
    // Split the key to child_path and child_key.
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
176
    // Eg. "track/track-title" has child_path "track/" and child_key "track-title".
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
177
    *child_path = NULL;
178
    *child_key = NULL;
179
180
    static gchar buf[MAX_PATH_LEN];
181
182
    // Find "/" in key
183
    gchar *p = g_strrstr(key, "/");
184
    if (p) {
185
        memset(buf, '\0', MAX_PATH_LEN);
186
        g_utf8_strncpy(buf, key, p - key);
187
        *child_path = g_strdup(buf);
188
189
        *child_key = g_strdup(p+1);
190
    }
191
}
192
469 by Osmo Antero
audio-recorder --reset did not always work because GSettings registry was not flushed immediately.
193
static GSettings *conf_get_base_settings() {
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
194
    // Return GSettings (base) object. This points to /apps/audio-recorder/.
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
195
463 by Osmo Antero
Updated README and INSTALL files.
196
#if 0
197
    // This code failed on some Linux-distributions. Reverting to g_settings_new().
198
1012.1.4 by David Rabel
Replaced http by https wherever it was reasonable. Also replaced some broken links and link that where only redirecting.
199
    // Ref: https://developer.gnome.org/gio/2.32/gio-GSettingsSchema-GSettingsSchemaSource.html
463 by Osmo Antero
Updated README and INSTALL files.
200
    GSettingsSchemaSource *source = g_settings_schema_source_get_default();
201
    GSettingsSchema *schema = g_settings_schema_source_lookup(source, APPLICATION_SETTINGS_SCHEMA, TRUE);
202
203
    // Check if schema has been installed
204
    if (!schema) {
205
        g_printerr("Error: Cannot find settings for %s in GNOME's registry. "
206
                   "Please run \"make install\" as sudo or root user.\n", "/apps/audio-recorder/");
207
    }
208
209
    GSettings *settings = g_settings_new_full(schema, NULL, NULL);
210
    g_settings_schema_unref(schema);
211
#endif
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
212
287 by Osmo Antero
Preparing version 1.0 for Ubuntu 13.04. Fixed dconf.c bug #1074928 on Arch-Linux.
213
    GSettings *settings = g_settings_new(APPLICATION_SETTINGS_SCHEMA);
214
    if (!G_IS_SETTINGS(settings)) {
463 by Osmo Antero
Updated README and INSTALL files.
215
        g_printerr("Error: Cannot find settings for %s in GNOME's registry. "
287 by Osmo Antero
Preparing version 1.0 for Ubuntu 13.04. Fixed dconf.c bug #1074928 on Arch-Linux.
216
                   "Please run \"make install\" as sudo or root user.\n", "/apps/audio-recorder/");
217
    }
218
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
219
    return settings;
220
}
221
469 by Osmo Antero
audio-recorder --reset did not always work because GSettings registry was not flushed immediately.
222
static GSettings *conf_get_settings_for_key(gchar *key, gchar **child_path, gchar **child_key) {
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
223
    // Return GSettings object for the given key
224
    *child_path = NULL;
225
    *child_key = NULL;
226
227
    // The key may contain a child path (it has a "/" in it).
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
228
    // For example the key "track/track-title" contains child_path ("track/") and child_key "track-title".
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
229
    // Take possible child_path and child_key.
230
    conf_get_child_path(key, child_path, child_key);
231
232
    // The main GSettings object
233
    GSettings *settings = conf_get_base_settings(); // Points to /apps/audio-recorder/.
234
235
    if (*child_path) {
236
        // Get GSettings object for child_path
237
        GSettings *child_settings = g_settings_get_child(settings, *child_path);
238
        if (G_IS_SETTINGS(child_settings)) {
239
            g_object_unref(settings);
240
            settings = child_settings; // Points to /apps/audio-recorder/some child_path/.
241
        }
242
    }
243
244
    return settings;
245
}
246
247
void conf_get_boolean_value(gchar *key, gboolean *value) {
248
    gchar *child_path = NULL;
249
    gchar *child_key = NULL;
250
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
251
    // Get GSettings object. Handle also child_path and child_key (like "track/track-title")
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
252
    GSettings *settings = conf_get_settings_for_key(key, &child_path, &child_key);
253
254
    gchar *k = NULL;
255
    if (child_key)
256
        k = child_key; // settings object points to child_path (/apps/audio-recorder/some child_path/).
257
    else
258
        k = key; // settings object points to main path (/apps/audio-recorder/).
259
260
    // Check if the key is valid. Avoid crash.
261
    if (!conf_is_valid_key(settings, k)) {
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
262
        LOG_ERROR("Cannot find configuration key \"%s\". Run \"make install\" as sudo or root user.\n", key);
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
263
        goto LBL_1;
264
    }
265
266
    // Read value
267
    *value = g_settings_get_boolean(settings, k);
268
269
LBL_1:
270
    // Free values
271
    g_free(child_path);
272
    g_free(child_key);
273
    g_object_unref(settings);
274
}
275
276
void conf_get_int_value(gchar *key, gint *value) {
277
    gchar *child_path = NULL;
278
    gchar *child_key = NULL;
279
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
280
    // Get GSettings object. Handle also child_path and child_key (like "track/track-title")
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
281
    GSettings *settings = conf_get_settings_for_key(key, &child_path, &child_key);
282
283
    gchar *k = NULL;
284
    if (child_key)
285
        k = child_key; // settings object points to child_path (/apps/audio-recorder/some child_path/).
286
    else
287
        k = key; // settings object points to main path (/apps/audio-recorder/).
288
289
    // Check if the key is valid. Avoid crash.
290
    if (!conf_is_valid_key(settings, k)) {
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
291
        LOG_ERROR("Cannot find configuration key \"%s\". Run \"make install\" as sudo or root user.\n", key);
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
292
        goto LBL_1;
293
    }
294
295
    // Read value
296
    *value = g_settings_get_int(settings, k);
297
298
LBL_1:
299
    // Free values
300
    g_free(child_path);
301
    g_free(child_key);
302
    g_object_unref(settings);
303
}
304
305
void conf_get_string_value(gchar *key, gchar **value) {
306
    gchar *child_path = NULL;
307
    gchar *child_key = NULL;
308
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
309
    // Get GSettings object. Handle also child_path and child_key (like "track/track-title")
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
310
    GSettings *settings = conf_get_settings_for_key(key, &child_path, &child_key);
311
312
    gchar *k = NULL;
313
    if (child_key)
314
        k = child_key; // settings object points to child_path (/apps/audio-recorder/some child_path/).
315
    else
316
        k = key; // settings object points to main path (/apps/audio-recorder/).
317
318
    // Check if the key is valid. Avoid crash.
319
    if (!conf_is_valid_key(settings, k)) {
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
320
        LOG_ERROR("Cannot find configuration key \"%s\". Run \"make install\" as sudo or root user.\n", key);
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
321
        goto LBL_1;
322
    }
323
324
    // Read value
325
    *value = g_settings_get_string(settings, k);
326
327
LBL_1:
328
    // Free values
329
    g_free(child_path);
330
    g_free(child_key);
331
    g_object_unref(settings);
332
333
    // The caller should g_free() the value
334
}
335
336
void conf_get_string_list(gchar *key, GList **list) {
337
    gchar *child_path = NULL;
338
    gchar *child_key = NULL;
339
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
340
    // Get GSettings object. Handle also child_path and child_key (like "track/track-title")
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
341
    GSettings *settings = conf_get_settings_for_key(key, &child_path, &child_key);
342
343
    gchar *k = NULL;
344
    if (child_key)
345
        k = child_key; // settings object points to child_path (/apps/audio-recorder/some child_path/).
346
    else
347
        k = key; // settings object points to main path (/apps/audio-recorder/).
348
349
    // Check if the key is valid. Avoid crash.
350
    if (!conf_is_valid_key(settings, k)) {
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
351
        LOG_ERROR("Cannot find configuration key \"%s\". Run \"make install\" as sudo or root user.\n", key);
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
352
        goto LBL_1;
353
    }
354
355
    // Read string list
356
    gchar **argv = g_settings_get_strv(settings, k);
357
358
    // From gchar *argv[] to GList
359
    *list = NULL;
360
    guint i = 0;
361
    while (argv && argv[i]) {
362
        *list = g_list_append(*list, g_strdup(argv[i]));
363
        i++;
364
    }
365
366
    // Free argv[]
367
    g_strfreev(argv);
368
369
370
LBL_1:
371
    // Free values
372
    g_free(child_path);
373
    g_free(child_key);
374
    g_object_unref(settings);
375
376
    // The caller should free the list
377
}
378
404 by Osmo Antero
Removed dependency to libpulse-dev. Using now Gstreamer to get the device list. Completed src/win-settings-pipe.[ch] module.
379
void conf_get_variant_value(gchar *key, GVariant **var) {
380
    gchar *child_path = NULL;
381
    gchar *child_key = NULL;
382
383
    *var = NULL;
384
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
385
    // Get GSettings object. Handle also child_path and child_key (like "track/track-title")
404 by Osmo Antero
Removed dependency to libpulse-dev. Using now Gstreamer to get the device list. Completed src/win-settings-pipe.[ch] module.
386
    GSettings *settings = conf_get_settings_for_key(key, &child_path, &child_key);
387
388
    gchar *k = NULL;
389
    if (child_key)
390
        k = child_key; // settings object points to child_path (/apps/audio-recorder/some child_path/).
391
    else
392
        k = key; // settings object points to main path (/apps/audio-recorder/).
393
394
    // Check if the key is valid. Avoid crash.
395
    if (!conf_is_valid_key(settings, k)) {
396
        LOG_ERROR("Cannot find configuration key \"%s\". Run \"make install\" as sudo or root user.\n", key);
397
        goto LBL_1;
398
    }
399
400
    *var = g_settings_get_value(settings, k);
401
402
LBL_1:
403
    // Free values
404
    g_free(child_path);
405
    g_free(child_key);
406
    g_object_unref(settings);
407
408
    // The caller should free the value
409
}
410
411
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
412
void conf_save_boolean_value(gchar *key, gboolean value) {
413
    gchar *child_path = NULL;
414
    gchar *child_key = NULL;
415
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
416
    // Get GSettings object. Handle also child_path and child_key (like "track/track-title")
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
417
    GSettings *settings = conf_get_settings_for_key(key, &child_path, &child_key);
418
419
    gchar *k = NULL;
420
    if (child_key)
421
        k = child_key; // settings object points to child_path (/apps/audio-recorder/some child_path/).
422
    else
423
        k = key; // settings object points to main path (/apps/audio-recorder/).
424
425
426
    // Check if the key is valid. Avoid crash.
427
    if (!conf_is_valid_key(settings, k)) {
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
428
        LOG_ERROR("Cannot find configuration key \"%s\". Run \"make install\" as sudo or root user.\n", key);
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
429
        goto LBL_1;
430
    }
431
432
    // Save value
433
    if (!g_settings_set_boolean(settings, k, value)) {
434
        LOG_ERROR("Cannot save configuration key \"%s\" (%s).\n", key, (value ? "true" : "false"));
435
    }
436
437
LBL_1:
438
    // Free values
439
    g_free(child_path);
440
    g_free(child_key);
441
    g_object_unref(settings);
442
}
443
444
void conf_save_int_value(gchar *key, gint value) {
445
    gchar *child_path = NULL;
446
    gchar *child_key = NULL;
447
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
448
    // Get GSettings object. Handle also child_path and child_key (like "track/track-title")
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
449
    GSettings *settings = conf_get_settings_for_key(key, &child_path, &child_key);
450
451
    gchar *k = NULL;
452
    if (child_key)
453
        k = child_key; // settings object points to child_path (/apps/audio-recorder/some child_path/).
454
    else
455
        k = key; // settings object points to main path (/apps/audio-recorder/).
456
457
    // Check if the key is valid. Avoid crash.
458
    if (!conf_is_valid_key(settings, k)) {
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
459
        LOG_ERROR("Cannot find configuration key \"%s\". Run \"make install\" as sudo or root user.\n", key);
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
460
        goto LBL_1;
461
    }
462
463
    // Save value
464
    if (!g_settings_set_int(settings, k, value)) {
465
        LOG_ERROR("Cannot save configuration key \"%s\" (%d).\n", key, value);
466
    }
467
468
LBL_1:
469
    // Free values
470
    g_free(child_path);
471
    g_free(child_key);
472
    g_object_unref(settings);
473
}
474
475
void conf_save_string_value(gchar *key, gchar *value) {
476
    gchar *child_path = NULL;
477
    gchar *child_key = NULL;
478
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
479
    // Get GSettings object. Handle also child_path and child_key (like "track/track-title")
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
480
    GSettings *settings = conf_get_settings_for_key(key, &child_path, &child_key);
481
482
    gchar *k = NULL;
483
    if (child_key)
484
        k = child_key; // settings object points to child_path (/apps/audio-recorder/some child_path/).
485
    else
486
        k = key; // settings object points to main path (/apps/audio-recorder/).
487
488
    // Check if the key is valid. Avoid crash.
489
    if (!conf_is_valid_key(settings, k)) {
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
490
        LOG_ERROR("Cannot find configuration key \"%s\". Run \"make install\" as sudo or root user.\n", key);
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
491
        goto LBL_1;
492
    }
493
494
    // Save value
495
    if (!g_settings_set_string(settings, k, value)) {
496
        LOG_ERROR("Cannot save configuration key \"%s\" (%s).\n", key, value);
497
    }
498
309 by Osmo Antero
Upgraded dbus-skype.c to use the newer GDBus intrerface.
499
    g_settings_apply(settings);
500
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
501
LBL_1:
502
    // Free values
503
    g_free(child_path);
504
    g_free(child_key);
505
    g_object_unref(settings);
506
}
507
508
void conf_save_string_list(gchar *key, GList *list) {
509
    gchar *child_path = NULL;
510
    gchar *child_key = NULL;
511
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
512
    // Get GSettings object. Handle also child_path and child_key (like "track/track-title")
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
513
    GSettings *settings = conf_get_settings_for_key(key, &child_path, &child_key);
514
515
    gchar *k = NULL;
516
    if (child_key)
517
        k = child_key; // settings object points to child_path (/apps/audio-recorder/some child_path/).
518
    else
519
        k = key; // settings object points to main path (/apps/audio-recorder/).
520
521
    // Check if the key is valid. Avoid crash.
522
    if (!conf_is_valid_key(settings, k)) {
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
523
        LOG_ERROR("Cannot find configuration key \"%s\". Run \"make install\" as sudo or root user.\n", key);
69 by Osmo Antero
Ported this application to GTK/GDK 3. Using now GSettings (and dconf) instead of GConf2
524
        goto LBL_1;
525
    }
526
527
    // From GList to gchar *argv[].
528
    guint len = g_list_length(list);
529
    // Allocate argv[]
530
    gchar **argv = g_new(gchar*, len + 1 /*+1 for NULL*/);
531
532
    guint i = 0;
533
    GList *n = g_list_first(list);
534
    while (n) {
535
        argv[i++] = g_strdup(n->data);
536
        n = g_list_next(n);
537
    }
538
    argv[len] = NULL;
539
540
    // Save string list
541
    if (!g_settings_set_strv(settings, k, (const gchar* const*)argv)) {
542
        LOG_ERROR("Cannot save configuration key \"%s\" (value is a string list).\n", key);
543
    }
544
545
    // Free argv[]
546
    g_strfreev((gchar **)argv);
547
548
LBL_1:
549
    // Free values
550
    g_free(child_path);
551
    g_free(child_key);
552
    g_object_unref(settings);
553
}
554
555
404 by Osmo Antero
Removed dependency to libpulse-dev. Using now Gstreamer to get the device list. Completed src/win-settings-pipe.[ch] module.
556
void conf_save_variant(gchar *key, GVariant *var) {
557
    gchar *child_path = NULL;
558
    gchar *child_key = NULL;
559
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
560
    // Get GSettings object. Handle also child_path and child_key (like "track/track-title")
404 by Osmo Antero
Removed dependency to libpulse-dev. Using now Gstreamer to get the device list. Completed src/win-settings-pipe.[ch] module.
561
    GSettings *settings = conf_get_settings_for_key(key, &child_path, &child_key);
562
563
    gchar *k = NULL;
564
    if (child_key)
565
        k = child_key; // settings object points to child_path (/apps/audio-recorder/some child_path/).
566
    else
567
        k = key; // settings object points to main path (/apps/audio-recorder/).
568
569
    // Check if the key is valid. Avoid crash.
570
    if (!conf_is_valid_key(settings, k)) {
571
        LOG_ERROR("Cannot find configuration key \"%s\". Run \"make install\" as sudo or root user.\n", key);
572
        goto LBL_1;
573
    }
574
575
    g_settings_set_value(settings, k, var);
576
577
LBL_1:
578
    // Free values
579
    g_free(child_path);
580
    g_free(child_key);
581
    g_object_unref(settings);
582
}