0
|
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 General Public License as published by
|
|
9 * the Free Software Foundation; either version 2 of the License, or
|
|
10 * (at your option) any later version.
|
|
11 *
|
|
12 * This program is distributed in the hope that it will be useful,
|
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 * GNU General Public License for more details.
|
|
16 *
|
|
17 * You should have received a copy of the GNU General Public License
|
|
18 * along with this program; if not, write to the Free Software
|
|
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
20 */
|
|
21
|
|
22 #include <glib.h>
|
|
23 #include <string.h>
|
|
24 #include "plugin.h"
|
|
25 #include "general.h"
|
|
26
|
|
27 GeneralPluginData gp_data = {
|
|
28 NULL,
|
|
29 NULL
|
|
30 };
|
|
31
|
|
32 GList *
|
|
33 get_general_list(void)
|
|
34 {
|
|
35 return gp_data.general_list;
|
|
36 }
|
|
37
|
|
38 GList *
|
|
39 get_general_enabled_list(void)
|
|
40 {
|
|
41 return gp_data.enabled_list;
|
|
42 }
|
|
43
|
|
44 static GeneralPlugin *
|
|
45 get_general_plugin(gint i)
|
|
46 {
|
|
47 GList *node = g_list_nth(get_general_list(), i);
|
|
48
|
|
49 if (!node)
|
|
50 return NULL;
|
|
51
|
|
52 return GENERAL_PLUGIN(node->data);
|
|
53 }
|
|
54
|
|
55
|
|
56 void
|
|
57 general_about(gint i)
|
|
58 {
|
|
59 GeneralPlugin *plugin = get_general_plugin(i);
|
|
60
|
|
61 if (!plugin || !plugin->about)
|
|
62 return;
|
|
63
|
|
64 plugin->about();
|
|
65 }
|
|
66
|
|
67 void
|
|
68 general_configure(gint i)
|
|
69 {
|
|
70 GeneralPlugin *plugin = get_general_plugin(i);
|
|
71
|
|
72 if (!plugin || !plugin->configure)
|
|
73 return;
|
|
74
|
|
75 plugin->configure();
|
|
76 }
|
|
77
|
|
78 static gboolean
|
|
79 general_plugin_is_enabled(GeneralPlugin * plugin)
|
|
80 {
|
|
81 return (g_list_find(get_general_enabled_list(), plugin) != NULL);
|
|
82 }
|
|
83
|
|
84 void
|
|
85 enable_general_plugin(gint i, gboolean enable)
|
|
86 {
|
|
87 GeneralPlugin *plugin = get_general_plugin(i);
|
|
88
|
|
89 if (!plugin)
|
|
90 return;
|
|
91
|
|
92 if (enable && !general_plugin_is_enabled(plugin)) {
|
|
93 gp_data.enabled_list = g_list_append(gp_data.enabled_list, plugin);
|
|
94 if (plugin->init)
|
|
95 plugin->init();
|
|
96 }
|
|
97 else if (!enable && general_plugin_is_enabled(plugin)) {
|
|
98 gp_data.enabled_list = g_list_remove(gp_data.enabled_list, plugin);
|
|
99 if (plugin->cleanup)
|
|
100 plugin->cleanup();
|
|
101 }
|
|
102 }
|
|
103
|
|
104 gboolean
|
|
105 general_enabled(gint i)
|
|
106 {
|
|
107 return (g_list_find(gp_data.enabled_list,
|
|
108 get_general_plugin(i)) != NULL);
|
|
109 }
|
|
110
|
|
111 gchar *
|
|
112 general_stringify_enabled_list(void)
|
|
113 {
|
|
114 GString *enable_str;
|
|
115 gchar *name;
|
|
116 GList *node = get_general_enabled_list();
|
|
117
|
|
118 if (!node)
|
|
119 return NULL;
|
|
120
|
|
121 name = g_path_get_basename(GENERAL_PLUGIN(node->data)->filename);
|
|
122 enable_str = g_string_new(name);
|
|
123 g_free(name);
|
|
124
|
|
125 for (node = g_list_next(node); node; node = g_list_next(node)) {
|
|
126 name = g_path_get_basename(GENERAL_PLUGIN(node->data)->filename);
|
|
127 g_string_append_c(enable_str, ',');
|
|
128 g_string_append(enable_str, name);
|
|
129 g_free(name);
|
|
130 }
|
|
131
|
|
132 return g_string_free(enable_str, FALSE);
|
|
133 }
|
|
134
|
|
135 void
|
|
136 general_enable_from_stringified_list(const gchar * list_str)
|
|
137 {
|
|
138 gchar **list, **str;
|
|
139 GeneralPlugin *plugin;
|
|
140
|
|
141 if (!list_str || !strcmp(list_str, ""))
|
|
142 return;
|
|
143
|
|
144 list = g_strsplit(list_str, ",", 0);
|
|
145
|
|
146 for (str = list; *str; str++) {
|
|
147 GList *node;
|
|
148
|
|
149 for (node = get_general_list(); node; node = g_list_next(node)) {
|
|
150 gchar *base;
|
|
151
|
|
152 base = g_path_get_basename(GENERAL_PLUGIN(node->data)->filename);
|
|
153
|
|
154 if (!strcmp(*str, base)) {
|
|
155 plugin = GENERAL_PLUGIN(node->data);
|
|
156 gp_data.enabled_list = g_list_append(gp_data.enabled_list,
|
|
157 plugin);
|
|
158 if (plugin->init)
|
|
159 plugin->init();
|
|
160 }
|
|
161
|
|
162 g_free(base);
|
|
163 }
|
|
164 }
|
|
165
|
|
166 g_strfreev(list);
|
|
167 }
|