Add a missing pa_xfree.
[pulseaudio.git] / src / modules / gconf / gconf-helper.c
blobabd132875e8c6b75b53cb9700ae479d826e6529e
1 /* $Id$ */
3 /***
4 This file is part of PulseAudio.
6 Copyright 2006 Lennart Poettering
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.
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.
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 ***/
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
28 #include <string.h>
29 #include <stdlib.h>
30 #include <stdio.h>
32 #include <gconf/gconf-client.h>
33 #include <glib.h>
35 #include <pulsecore/core-util.h>
37 #define PA_GCONF_ROOT "/system/pulseaudio"
38 #define PA_GCONF_PATH_MODULES PA_GCONF_ROOT"/modules"
40 static void handle_module(GConfClient *client, const char *name) {
41 gchar p[1024];
42 gboolean enabled, locked;
43 int i;
45 pa_snprintf(p, sizeof(p), PA_GCONF_PATH_MODULES"/%s/locked", name);
46 locked = gconf_client_get_bool(client, p, FALSE);
48 if (locked)
49 return;
51 pa_snprintf(p, sizeof(p), PA_GCONF_PATH_MODULES"/%s/enabled", name);
52 enabled = gconf_client_get_bool(client, p, FALSE);
54 printf("%c%s%c", enabled ? '+' : '-', name, 0);
56 if (enabled) {
58 for (i = 0; i < 10; i++) {
59 gchar *n, *a;
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;
65 pa_snprintf(p, sizeof(p), PA_GCONF_PATH_MODULES"/%s/args%i", name, i);
66 a = gconf_client_get_string(client, p, NULL);
68 printf("%s%c%s%c", n, 0, a ? a : "", 0);
70 g_free(n);
71 g_free(a);
74 printf("%c", 0);
77 fflush(stdout);
80 static void modules_callback(
81 GConfClient* client,
82 guint cnxn_id,
83 GConfEntry *entry,
84 gpointer user_data) {
86 const char *n;
87 char buf[128];
89 g_assert(strncmp(entry->key, PA_GCONF_PATH_MODULES"/", sizeof(PA_GCONF_PATH_MODULES)) == 0);
91 n = entry->key + sizeof(PA_GCONF_PATH_MODULES);
93 g_strlcpy(buf, n, sizeof(buf));
94 buf[strcspn(buf, "/")] = 0;
96 handle_module(client, buf);
99 int main(int argc, char *argv[]) {
100 GMainLoop *g;
101 GConfClient *client;
102 GSList *modules, *m;
104 g_type_init();
106 if (!(client = gconf_client_get_default()))
107 goto fail;
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);
112 modules = gconf_client_all_dirs(client, PA_GCONF_PATH_MODULES, NULL);
114 for (m = modules; m; m = m->next) {
115 char *e = strrchr(m->data, '/');
116 handle_module(client, e ? e+1 : m->data);
119 g_slist_free(modules);
121 /* Signal the parent that we are now initialized */
122 printf("!");
123 fflush(stdout);
125 g = g_main_loop_new(NULL, FALSE);
126 g_main_loop_run(g);
127 g_main_loop_unref(g);
129 g_object_unref(G_OBJECT(client));
131 return 0;
133 fail:
134 return 1;