]> code.delx.au - pulseaudio/blob - src/modules/gconf/gconf-helper.c
add new module "module-gconf" which reads configuration information from gconf. this...
[pulseaudio] / src / modules / gconf / gconf-helper.c
1 /* $Id$ */
2
3 /***
4 This file is part of PulseAudio.
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 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 #define PA_GCONF_ROOT "/system/pulseaudio"
34 #define PA_GCONF_PATH_MODULES PA_GCONF_ROOT"/modules"
35
36 static void handle_module(GConfClient *client, const char *name) {
37 gchar p[1024];
38 gboolean enabled;
39 int i;
40
41 snprintf(p, sizeof(p), PA_GCONF_PATH_MODULES"/%s/enabled", name);
42 enabled = gconf_client_get_bool(client, p, FALSE);
43
44 printf("%c%s%c", enabled ? '+' : '-', name, 0);
45
46 if (enabled) {
47
48 for (i = 0; i < 10; i++) {
49 gchar *n, *a;
50
51 snprintf(p, sizeof(p), PA_GCONF_PATH_MODULES"/%s/name%i", name, i);
52 if (!(n = gconf_client_get_string(client, p, NULL)) || !*n)
53 break;
54
55 snprintf(p, sizeof(p), PA_GCONF_PATH_MODULES"/%s/args%i", name, i);
56 a = gconf_client_get_string(client, p, NULL);
57
58 printf("%s%c%s%c", n, 0, a ? a : "", 0);
59
60 g_free(n);
61 g_free(a);
62 }
63
64 printf("%c", 0);
65 }
66
67 fflush(stdout);
68 }
69
70 static void modules_callback(
71 GConfClient* client,
72 guint cnxn_id,
73 GConfEntry *entry,
74 gpointer user_data) {
75
76 const char *n;
77 char buf[128];
78
79 g_assert(strncmp(entry->key, PA_GCONF_PATH_MODULES"/", sizeof(PA_GCONF_PATH_MODULES)) == 0);
80
81 n = entry->key + sizeof(PA_GCONF_PATH_MODULES);
82
83 g_strlcpy(buf, n, sizeof(buf));
84 buf[strcspn(buf, "/")] = 0;
85
86 handle_module(client, buf);
87 }
88
89 int main(int argc, char *argv[]) {
90 GMainLoop *g;
91 GConfClient *client;
92 GSList *modules, *m;
93
94 if (!(client = gconf_client_get_default()))
95 goto fail;
96
97 gconf_client_add_dir(client, PA_GCONF_ROOT, GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
98 gconf_client_notify_add(client, PA_GCONF_PATH_MODULES, modules_callback, NULL, NULL, NULL);
99
100 modules = gconf_client_all_dirs(client, PA_GCONF_PATH_MODULES, NULL);
101
102 for (m = modules; m; m = m->next) {
103 char *e = strrchr(m->data, '/');
104 handle_module(client, e ? e+1 : m->data);
105 }
106
107 g_slist_free(modules);
108
109 /* Signal the parent that we are now initialized */
110 printf("!");
111 fflush(stdout);
112
113 g = g_main_loop_new(NULL, FALSE);
114 g_main_loop_run(g);
115 g_main_loop_unref(g);
116
117 g_object_unref(G_OBJECT(client));
118
119 return 0;
120
121 fail:
122 return 1;
123 }