Fix the label int he sidebar
[gmpc.git] / src / Tools / plugin-man.c
blob8c000aa275c3b20df5b3d8ba027b1223cea53583
1 /* Gnome Music Player Client (GMPC)
2 * Copyright (C) 2011-2012 Qball Cow <qball@gmpclient.org>
3 * Project homepage: http://gmpclient.org/
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include <strings.h>
24 #include <config.h>
26 #include "main.h"
27 #include "plugin-man.h"
28 #include "internal-plugins.h"
30 /* Internal plugins definition */
31 #include "browsers/playlist3-current-playlist-browser.h"
32 #include "browsers/playlist3-file-browser.h"
33 #include "browsers/playlist3-find2-browser.h"
34 #include "browsers/playlist3-playlist-editor.h"
35 #include "browsers/playlist3-tag2-browser.h"
36 #ifdef ENABLE_MMKEYS
37 #include "mm-keys.h"
38 #endif
40 #define LOG_DOMAIN "Gmpc.Plugin.Manager"
42 /* @todo this needs to be globally available. find a good solution to where to
43 * hide this one
45 GmpcBrowsersMetadata *browsers_metadata = NULL;
47 void plugin_manager_load_internal_plugins(void)
49 /** file browser */
50 plugin_add(&file_browser_plug, 0, NULL);
51 /** current playlist */
52 plugin_add_new((GmpcPluginBase *)
53 play_queue_plugin_new("current-pl"),
54 0, NULL);
55 /* Add it to the plugin command */
56 plugin_add_new(GMPC_PLUGIN_BASE(gmpc_easy_command), 0, NULL);
57 /** Find Browser */
58 plugin_add(&find2_browser_plug, 0, NULL);
59 /* this shows the connection preferences */
60 plugin_add(&connection_plug, 0, NULL);
61 /* this the server preferences */
62 plugin_add(&server_plug, 0, NULL);
63 /* this shows the playlist preferences */
64 plugin_add(&playlist_plug, 0, NULL);
65 /* this shows the markup stuff */
66 plugin_add(&tag2_plug, 0, NULL);
67 #ifdef ENABLE_MMKEYS
68 plugin_add(&mmkeys_plug, 0, NULL);
69 #endif
70 /* the tray icon */
71 plugin_add(&tray_icon2_plug, 0, NULL);
73 /* Playlist editor */
74 plugin_add(&playlist_editor_plugin, 0, NULL);
76 plugin_add(&statistics_plugin, 0, NULL);
77 plugin_add(&proxyplug, 0, NULL);
79 plugin_add(&extraplaylist_plugin, 0, NULL);
80 plugin_add_new(
81 GMPC_PLUGIN_BASE((browsers_metadata = gmpc_browsers_metadata_new())),
82 0, NULL);
84 plugin_add_new(
85 GMPC_PLUGIN_BASE(gmpc_tools_metadata_prefetcher_new()),
86 0, NULL);
88 plugin_add_new(
89 GMPC_PLUGIN_BASE(gmpc_tools_database_update_tracker_new()),
90 0, NULL);
92 plugin_add_new(
93 GMPC_PLUGIN_BASE(gmpc_browsers_nowplaying_new()),
94 0, NULL);
96 plugin_add_new(
97 GMPC_PLUGIN_BASE(gmpc_tools_metadata_appearance_new()),
98 0, NULL);
101 /* Initialize the message system */
102 plugin_add_new(GMPC_PLUGIN_BASE(pl3_messages), 0, NULL);
103 /** Provider */
104 plugin_add_new((GmpcPluginBase *)
105 gmpc_plugins_auto_mpd_new(),
106 0, NULL);
108 plugin_add_new((GmpcPluginBase *)
109 gmpc_plugins_sidebar_search_new(),
110 0, NULL);
112 plugin_add_new((GmpcPluginBase *)
113 gmpc_plugins_sidebar_next_song_new(),
114 0, NULL);
116 plugin_add_new((GmpcPluginBase *)
117 gmpc_plugins_sidebar_play_queue_time_new(),
118 0, NULL);
120 plugin_add_new((GmpcPluginBase *)
121 gmpc_external_command_new(),
122 0, NULL);
125 void plugin_manager_initialize_plugins(void)
127 int i = 0;
128 INIT_TIC_TAC();
130 for (i = 0; i < num_plugins && plugins[i] != NULL; i++)
132 gmpc_plugin_init(plugins[i]);
133 TEC("Initializing plugin: %s", gmpc_plugin_get_name(plugins[i]));
134 g_log(LOG_DOMAIN,
135 G_LOG_LEVEL_DEBUG,
136 "Initializing '%s'",
137 gmpc_plugin_get_name(plugins[i]));
142 void plugin_manager_destroy_plugins(void)
144 int i = 0;
145 INIT_TIC_TAC();
146 /* time todo some destruction of plugins */
147 for (; i < num_plugins && plugins[i] != NULL; i++)
149 TEC("Destroying plugin: %s", gmpc_plugin_get_name(plugins[i]));
150 g_log(LOG_DOMAIN,
151 G_LOG_LEVEL_DEBUG,
152 "Telling '%s' to destroy itself",
153 gmpc_plugin_get_name(plugins[i]));
154 gmpc_plugin_destroy(plugins[i]);
158 void plugin_manager_save_state(void)
160 int i = 0;
161 INIT_TIC_TAC();
162 for (i = 0; i < num_plugins && plugins[i] != NULL; i++)
164 g_log(LOG_DOMAIN,
165 G_LOG_LEVEL_DEBUG, "Telling '%s' to save itself",
166 gmpc_plugin_get_name(plugins[i]));
167 gmpc_plugin_save_yourself(plugins[i]);
168 TEC("Saving state: %s", gmpc_plugin_get_name(plugins[i]));
174 void plugin_manager_connection_changed(MpdObj *mi, const int connected)
176 int i = 0;
177 for (i = 0; i < num_plugins; i++)
179 g_log(LOG_DOMAIN,
180 G_LOG_LEVEL_DEBUG,
181 "Connection changed plugin: %s\n",
182 gmpc_plugin_get_name(plugins[i]));
184 gmpc_plugin_mpd_connection_changed(plugins[i], mi, connected, NULL);
188 void plugin_manager_status_changed(MpdObj *mi, const ChangedStatusType what)
190 int i = 0;
191 for (i = 0; i < num_plugins; i++)
193 g_log(LOG_DOMAIN,
194 G_LOG_LEVEL_DEBUG,
195 "Status changed plugin: %s\n",
196 gmpc_plugin_get_name(plugins[i]));
197 gmpc_plugin_status_changed(plugins[i], mi, what);
201 /* \todo change this away from ~/.config/*/
202 static void plugin_manager_load_userspace_plugins(void)
204 char *url = gmpc_get_user_path("plugins");
206 * if dir exists, try to load the plugins.
208 if (g_file_test(url, G_FILE_TEST_IS_DIR))
210 g_log(LOG_DOMAIN,
211 G_LOG_LEVEL_DEBUG,
212 "Trying to load plugins in: %s", url);
213 plugin_load_dir(url);
215 g_free(url);
217 static void plugin_manager_load_env_path(void)
219 /* Load plugin from $PLUGIN_DIR if set */
220 if (g_getenv("PLUGIN_DIR") != NULL)
222 gchar *path = g_build_filename(g_getenv("PLUGIN_DIR"), NULL);
223 if (path && g_file_test(path, G_FILE_TEST_IS_DIR))
225 plugin_load_dir(path);
227 if (path)
228 g_free(path);
231 static void plugin_manager_load_global_plugins(void)
233 gchar *url = NULL;
234 #ifdef WIN32
235 gchar *packdir = g_win32_get_package_installation_directory_of_module(NULL);
236 g_log(LOG_DOMAIN,
237 G_LOG_LEVEL_DEBUG,
238 "Got %s as package installation dir", packdir);
239 url = g_build_filename(packdir, "lib", "gmpc", "plugins", NULL);
240 g_free(packdir);
242 plugin_load_dir(url);
243 g_free(url);
244 #else
245 /* This is the right location to load gmpc plugins */
246 url = g_build_path(G_DIR_SEPARATOR_S, PACKAGE_LIB_DIR, "plugins", NULL);
247 plugin_load_dir(url);
248 g_free(url);
249 #endif
252 void plugin_manager_load_plugins(void)
254 plugin_manager_load_global_plugins();
255 plugin_manager_load_env_path();
256 plugin_manager_load_userspace_plugins();
259 /* vim: set noexpandtab ts=4 sw=4 sts=4 tw=80: */