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.
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"
40 #define LOG_DOMAIN "Gmpc.Plugin.Manager"
42 /* @todo this needs to be globally available. find a good solution to where to
45 GmpcBrowsersMetadata
*browsers_metadata
= NULL
;
47 void plugin_manager_load_internal_plugins(void)
50 plugin_add(&file_browser_plug
, 0, NULL
);
51 /** current playlist */
52 plugin_add_new((GmpcPluginBase
*)
53 play_queue_plugin_new("current-pl"),
55 /* Add it to the plugin command */
56 plugin_add_new(GMPC_PLUGIN_BASE(gmpc_easy_command
), 0, NULL
);
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
);
68 plugin_add(&mmkeys_plug
, 0, NULL
);
71 plugin_add(&tray_icon2_plug
, 0, NULL
);
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
);
81 GMPC_PLUGIN_BASE((browsers_metadata
= gmpc_browsers_metadata_new())),
85 GMPC_PLUGIN_BASE(gmpc_tools_metadata_prefetcher_new()),
89 GMPC_PLUGIN_BASE(gmpc_tools_database_update_tracker_new()),
93 GMPC_PLUGIN_BASE(gmpc_browsers_nowplaying_new()),
97 GMPC_PLUGIN_BASE(gmpc_tools_metadata_appearance_new()),
101 /* Initialize the message system */
102 plugin_add_new(GMPC_PLUGIN_BASE(pl3_messages
), 0, NULL
);
104 plugin_add_new((GmpcPluginBase
*)
105 gmpc_plugins_auto_mpd_new(),
108 plugin_add_new((GmpcPluginBase
*)
109 gmpc_plugins_sidebar_search_new(),
112 plugin_add_new((GmpcPluginBase
*)
113 gmpc_plugins_sidebar_next_song_new(),
116 plugin_add_new((GmpcPluginBase
*)
117 gmpc_plugins_sidebar_play_queue_time_new(),
120 plugin_add_new((GmpcPluginBase
*)
121 gmpc_external_command_new(),
125 void plugin_manager_initialize_plugins(void)
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
]));
137 gmpc_plugin_get_name(plugins
[i
]));
142 void plugin_manager_destroy_plugins(void)
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
]));
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)
162 for (i
= 0; i
< num_plugins
&& plugins
[i
] != NULL
; i
++)
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
)
177 for (i
= 0; i
< num_plugins
; i
++)
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
)
191 for (i
= 0; i
< num_plugins
; i
++)
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
))
212 "Trying to load plugins in: %s", url
);
213 plugin_load_dir(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
);
231 static void plugin_manager_load_global_plugins(void)
235 gchar
*packdir
= g_win32_get_package_installation_directory_of_module(NULL
);
238 "Got %s as package installation dir", packdir
);
239 url
= g_build_filename(packdir
, "lib", "gmpc", "plugins", NULL
);
242 plugin_load_dir(url
);
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
);
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: */