comparison src/audacious/discovery.c @ 3227:2619f4c62abe trunk

added Discovery plugin type
author Cristi Magherusan <majeru@atheme-project.org>
date Fri, 03 Aug 2007 07:20:58 +0300
parents
children 3092a8b3fe34
comparison
equal deleted inserted replaced
3226:db3983f423f3 3227:2619f4c62abe
1 /* BMP - Cross-platform multimedia player
2 * Copyright (C) 2003-2004 BMP development team.
3 *
4 * Based on XMMS:
5 * Copyright (C) 1998-2003 XMMS development team.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Discovery Public License as published by
9 * the Free Software Foundation; under version 3 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Discovery Public License for more details.
15 *
16 * You should have received a copy of the GNU Discovery Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses>.
18 *
19 * The Audacious team does not consider modular code linking to
20 * Audacious or using our public API to be a derived work.
21 */
22
23 #include <glib.h>
24 #include <string.h>
25 #include "plugin.h"
26 #include "discovery.h"
27
28 DiscoveryPluginData dp_data = {
29 NULL,
30 NULL
31 };
32
33 GList *
34 get_discovery_list(void)
35 {
36 return dp_data.discovery_list;
37 }
38
39 GList *
40 get_discovery_enabled_list(void)
41 {
42 return dp_data.enabled_list;
43 }
44
45 static DiscoveryPlugin *
46 get_discovery_plugin(gint i)
47 {
48 GList *node = g_list_nth(get_discovery_list(), i);
49
50 if (!node)
51 return NULL;
52
53 return DISCOVERY_PLUGIN(node->data);
54 }
55
56
57 void
58 discovery_about(gint i)
59 {
60 DiscoveryPlugin *plugin = get_discovery_plugin(i);
61
62 if (!plugin || !plugin->about)
63 return;
64
65 plugin->about();
66 }
67
68 void
69 discovery_configure(gint i)
70 {
71 DiscoveryPlugin *plugin = get_discovery_plugin(i);
72
73 if (!plugin || !plugin->configure)
74 return;
75
76 plugin->configure();
77 }
78
79 static gboolean
80 discovery_plugin_is_enabled(DiscoveryPlugin * plugin)
81 {
82 return (g_list_find(get_discovery_enabled_list(), plugin) != NULL);
83 }
84
85 void
86 enable_discovery_plugin(gint i, gboolean enable)
87 {
88 DiscoveryPlugin *plugin = get_discovery_plugin(i);
89
90 if (!plugin)
91 return;
92
93 if (enable && !discovery_plugin_is_enabled(plugin)) {
94 dp_data.enabled_list = g_list_append(dp_data.enabled_list, plugin);
95 if (plugin->init)
96 plugin->init();
97 }
98 else if (!enable && discovery_plugin_is_enabled(plugin)) {
99 dp_data.enabled_list = g_list_remove(dp_data.enabled_list, plugin);
100 if (plugin->cleanup)
101 plugin->cleanup();
102 }
103 }
104
105 gboolean
106 discovery_enabled(gint i)
107 {
108 return (g_list_find(dp_data.enabled_list,
109 get_discovery_plugin(i)) != NULL);
110 }
111
112 gchar *
113 discovery_stringify_enabled_list(void)
114 {
115 GString *enable_str;
116 gchar *name;
117 GList *node = get_discovery_enabled_list();
118
119 if (!node)
120 return NULL;
121
122 name = g_path_get_basename(DISCOVERY_PLUGIN(node->data)->filename);
123 enable_str = g_string_new(name);
124 g_free(name);
125
126 for (node = g_list_next(node); node; node = g_list_next(node)) {
127 name = g_path_get_basename(DISCOVERY_PLUGIN(node->data)->filename);
128 g_string_append_c(enable_str, ',');
129 g_string_append(enable_str, name);
130 g_free(name);
131 }
132
133 return g_string_free(enable_str, FALSE);
134 }
135
136 void
137 discovery_enable_from_stringified_list(const gchar * list_str)
138 {
139 gchar **list, **str;
140 DiscoveryPlugin *plugin;
141
142 if (!list_str || !strcmp(list_str, ""))
143 return;
144
145 list = g_strsplit(list_str, ",", 0);
146
147 for (str = list; *str; str++) {
148 GList *node;
149
150 for (node = get_discovery_list(); node; node = g_list_next(node)) {
151 gchar *base;
152
153 base = g_path_get_basename(DISCOVERY_PLUGIN(node->data)->filename);
154
155 if (!strcmp(*str, base)) {
156 plugin = DISCOVERY_PLUGIN(node->data);
157 dp_data.enabled_list = g_list_append(dp_data.enabled_list,
158 plugin);
159 if (plugin->init)
160 plugin->init();
161 }
162
163 g_free(base);
164 }
165 }
166
167 g_strfreev(list);
168 }