Add copyright notices to all relevant files. (based on svn log)
[profile/ivi/pulseaudio.git] / 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 #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     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     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             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             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     g_type_init();
103
104     if (!(client = gconf_client_get_default()))
105         goto fail;
106
107     gconf_client_add_dir(client, PA_GCONF_ROOT, GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
108     gconf_client_notify_add(client, PA_GCONF_PATH_MODULES, modules_callback, NULL, NULL, NULL);
109
110     modules = gconf_client_all_dirs(client, PA_GCONF_PATH_MODULES, NULL);
111
112     for (m = modules; m; m = m->next) {
113         char *e = strrchr(m->data, '/');
114         handle_module(client, e ? e+1 : m->data);
115     }
116     
117     g_slist_free(modules);
118
119     /* Signal the parent that we are now initialized */
120     printf("!");
121     fflush(stdout);
122     
123     g = g_main_loop_new(NULL, FALSE);
124     g_main_loop_run(g);
125     g_main_loop_unref(g);
126     
127     g_object_unref(G_OBJECT(client));
128
129     return 0;
130
131 fail:
132     return 1;
133 }