]> code.delx.au - pulseaudio/blob - src/modules/gconf/gconf-helper.c
gconf: Avoid calling deprecated function if possible
[pulseaudio] / src / modules / gconf / gconf-helper.c
1 /***
2 This file is part of PulseAudio.
3
4 Copyright 2006 Lennart Poettering
5
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2.1 of the License,
9 or (at your option) any later version.
10
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <string.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29
30 #include <gconf/gconf-client.h>
31 #include <glib.h>
32
33 #include <pulsecore/core-util.h>
34
35 #define PA_GCONF_ROOT "/system/pulseaudio"
36 #define PA_GCONF_PATH_MODULES PA_GCONF_ROOT"/modules"
37
38 static void handle_module(GConfClient *client, const char *name) {
39 gchar p[1024];
40 gboolean enabled, locked;
41 int i;
42
43 pa_snprintf(p, sizeof(p), PA_GCONF_PATH_MODULES"/%s/locked", name);
44 locked = gconf_client_get_bool(client, p, FALSE);
45
46 if (locked)
47 return;
48
49 pa_snprintf(p, sizeof(p), PA_GCONF_PATH_MODULES"/%s/enabled", name);
50 enabled = gconf_client_get_bool(client, p, FALSE);
51
52 printf("%c%s%c", enabled ? '+' : '-', name, 0);
53
54 if (enabled) {
55
56 for (i = 0; i < 10; i++) {
57 gchar *n, *a;
58
59 pa_snprintf(p, sizeof(p), PA_GCONF_PATH_MODULES"/%s/name%i", name, i);
60 if (!(n = gconf_client_get_string(client, p, NULL)) || !*n)
61 break;
62
63 pa_snprintf(p, sizeof(p), PA_GCONF_PATH_MODULES"/%s/args%i", name, i);
64 a = gconf_client_get_string(client, p, NULL);
65
66 printf("%s%c%s%c", n, 0, a ? a : "", 0);
67
68 g_free(n);
69 g_free(a);
70 }
71
72 printf("%c", 0);
73 }
74
75 fflush(stdout);
76 }
77
78 static void modules_callback(
79 GConfClient* client,
80 guint cnxn_id,
81 GConfEntry *entry,
82 gpointer user_data) {
83
84 const char *n;
85 char buf[128];
86
87 g_assert(strncmp(entry->key, PA_GCONF_PATH_MODULES"/", sizeof(PA_GCONF_PATH_MODULES)) == 0);
88
89 n = entry->key + sizeof(PA_GCONF_PATH_MODULES);
90
91 g_strlcpy(buf, n, sizeof(buf));
92 buf[strcspn(buf, "/")] = 0;
93
94 handle_module(client, buf);
95 }
96
97 int main(int argc, char *argv[]) {
98 GMainLoop *g;
99 GConfClient *client;
100 GSList *modules, *m;
101
102 #if !GLIB_CHECK_VERSION(2,36,0)
103 g_type_init();
104 #endif
105
106 if (!(client = gconf_client_get_default()))
107 goto fail;
108
109 gconf_client_add_dir(client, PA_GCONF_ROOT, GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
110 gconf_client_notify_add(client, PA_GCONF_PATH_MODULES, modules_callback, NULL, NULL, NULL);
111
112 modules = gconf_client_all_dirs(client, PA_GCONF_PATH_MODULES, NULL);
113
114 for (m = modules; m; m = m->next) {
115 char *e = strrchr(m->data, '/');
116 handle_module(client, e ? e+1 : m->data);
117 }
118
119 g_slist_free(modules);
120
121 /* Signal the parent that we are now initialized */
122 printf("!");
123 fflush(stdout);
124
125 g = g_main_loop_new(NULL, FALSE);
126 g_main_loop_run(g);
127 g_main_loop_unref(g);
128
129 g_object_unref(G_OBJECT(client));
130
131 return 0;
132
133 fail:
134 return 1;
135 }