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