diff options
-rw-r--r-- | csid.cpp | 1 | ||||
-rw-r--r-- | deadbeef.h | 3 | ||||
-rw-r--r-- | plugins.c | 41 | ||||
-rw-r--r-- | plugins.h | 7 | ||||
-rw-r--r-- | plugins/cdda/cdda.c | 2 | ||||
-rw-r--r-- | plugins/gtkui/callbacks.c | 49 | ||||
-rw-r--r-- | plugins/gtkui/gtkui.c | 1 |
7 files changed, 84 insertions, 20 deletions
@@ -67,6 +67,7 @@ static DB_decoder_t plugin = { /* .plugin.version_major = */0, /* .plugin.version_minor = */1, /* .inactive = */0, + /* .plugin.nostop = */0, /* .plugin.name = */"SID decoder", /* .plugin.descr = */"SID player based on libsidplay2", /* .plugin.author = */"Alexey Yakovenko", @@ -338,6 +338,7 @@ typedef struct { // plugin communication struct DB_decoder_s **(*plug_get_decoder_list) (void); struct DB_plugin_s **(*plug_get_list) (void); + int (*plug_activate) (struct DB_plugin_s *p, int activate); // exporting plugin conf options for gui // all exported options are grouped by plugin, and will be available to user // from gui @@ -361,6 +362,8 @@ typedef struct DB_plugin_s { int16_t version_minor; // may be deactivated on failures after load int inactive; + // prevent plugin from being dynamically stopped + int nostop; // any of those can be left NULL // though it's much better to fill them with something useful const char *name; @@ -166,6 +166,7 @@ static DB_functions_t deadbeef_api = { // plugin communication .plug_get_decoder_list = plug_get_decoder_list, .plug_get_list = plug_get_list, + .plug_activate = plug_activate, }; DB_functions_t *deadbeef = &deadbeef_api; @@ -609,3 +610,43 @@ struct DB_plugin_s ** plug_get_list (void) { return g_plugins; } + +int +plug_activate (DB_plugin_t *plug, int activate) { + if (plug->inactive && !activate) { + return -1; + } + if (!plug->inactive && activate) { + return -1; + } + if (activate) { + if (plug->start) { + if (!plug->start ()) { + plug->inactive = 0; + } + else { + fprintf (stderr, "failed to start plugin %s\n", plug->name); + return -1; + } + return 0; + } + else { + return -1; + } + } + else { + if (plug->stop) { + if (!plug->stop ()) { + plug->inactive = 1; + } + else { + fprintf (stderr, "failed to stop plugin %s\n", plug->name); + return -1; + } + return 0; + } + else { + return -1; + } + } +} @@ -103,10 +103,7 @@ plug_volume_set_amp (float amp); const char * plug_get_config_dir (void); -void -plug_gui_lock (void); - -void -plug_gui_unlock (void); +int +plug_activate (DB_plugin_t *plug, int activate); #endif // __PLUGINS_H diff --git a/plugins/cdda/cdda.c b/plugins/cdda/cdda.c index 5b6eb88a..38bc9dad 100644 --- a/plugins/cdda/cdda.c +++ b/plugins/cdda/cdda.c @@ -412,11 +412,13 @@ cda_insert (DB_playItem_t *after, const char *fname) { static int cda_start (void) { mutex = deadbeef->mutex_create (); + return 0; } static int cda_stop (void) { deadbeef->mutex_free (mutex); + return 0; } static const char *exts[] = { "cda", "nrg", NULL }; diff --git a/plugins/gtkui/callbacks.c b/plugins/gtkui/callbacks.c index bba9aa4f..a297b21c 100644 --- a/plugins/gtkui/callbacks.c +++ b/plugins/gtkui/callbacks.c @@ -788,7 +788,6 @@ save_playlist_as (void) { if (fname) { int res = deadbeef->pl_save (fname); - printf ("save as res: %d\n", res); if (res >= 0 && strlen (fname) < 1024) { strcpy (last_playlist_save_name, fname); } @@ -809,7 +808,6 @@ on_playlist_save_activate (GtkMenuItem *menuitem, } else { int res = deadbeef->pl_save (last_playlist_save_name); - printf ("save res: %d\n", res); } } @@ -1189,7 +1187,6 @@ on_mainwin_configure_event (GtkWidget *widget, deadbeef->conf_set_int ("mainwin.geometry.y", y); deadbeef->conf_set_int ("mainwin.geometry.w", w); deadbeef->conf_set_int ("mainwin.geometry.h", h); - printf ("save %d %d %d %d\n", x, y, w, h); } return FALSE; } @@ -1344,6 +1341,28 @@ gtk_enum_sound_callback (const char *name, const char *desc, void *userdata) { } void +on_plugin_active_toggled (GtkCellRendererToggle *cell_renderer, gchar *path, GtkTreeModel *model) { + GtkTreePath *p = gtk_tree_path_new_from_string (path); + if (p) { + int *indices = gtk_tree_path_get_indices (p); + //gtk_tree_path_free (p); // wtf?? gtk crashes on this + if (indices) { + DB_plugin_t **plugins = deadbeef->plug_get_list (); + DB_plugin_t *plug = plugins[*indices]; + printf ("plugin %d active\n", *indices); + gboolean state; + GtkTreeIter iter; + gtk_tree_model_get_iter (model, &iter, p); + gtk_tree_model_get (model, &iter, 0, &state, -1); + if (!deadbeef->plug_activate (plug, !state)) { + gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, !state, -1); + } + } + g_free (indices); + } +} + +void on_preferences_activate (GtkMenuItem *menuitem, gpointer user_data) { @@ -1409,16 +1428,22 @@ on_preferences_activate (GtkMenuItem *menuitem, // list of plugins GtkTreeView *tree = GTK_TREE_VIEW (lookup_widget (w, "pref_pluginlist")); - GtkListStore *store = gtk_list_store_new (1, G_TYPE_STRING);//GTK_LIST_STORE (gtk_tree_view_get_model (tree)); - GtkCellRenderer *rend = gtk_cell_renderer_text_new (); - GtkTreeViewColumn *col = gtk_tree_view_column_new_with_attributes ("Title", rend, "text", 0, NULL); - gtk_tree_view_append_column (tree, col); + GtkListStore *store = gtk_list_store_new (3, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_BOOLEAN); + GtkCellRenderer *rend_toggle = gtk_cell_renderer_toggle_new (); + GtkCellRenderer *rend_text = gtk_cell_renderer_text_new (); + g_signal_connect ((gpointer)rend_toggle, "toggled", + G_CALLBACK (on_plugin_active_toggled), + store); + GtkTreeViewColumn *col1 = gtk_tree_view_column_new_with_attributes ("Active", rend_toggle, "active", 0, "activatable", 2, NULL); + GtkTreeViewColumn *col2 = gtk_tree_view_column_new_with_attributes ("Title", rend_text, "text", 1, NULL); + gtk_tree_view_append_column (tree, col1); + gtk_tree_view_append_column (tree, col2); DB_plugin_t **plugins = deadbeef->plug_get_list (); int i; for (i = 0; plugins[i]; i++) { GtkTreeIter it; gtk_list_store_append (store, &it); - gtk_list_store_set (store, &it, 0, plugins[i]->name, -1); + gtk_list_store_set (store, &it, 0, plugins[i]->inactive ? FALSE : TRUE, 1, plugins[i]->name, 2, plugins[i]->nostop ? FALSE : TRUE, -1); } gtk_tree_view_set_model (tree, GTK_TREE_MODEL (store)); @@ -1485,13 +1510,6 @@ on_pref_close_send_to_tray_clicked (GtkButton *button, deadbeef->sendmessage (M_CONFIGCHANGED, 0, 0, 0); } - -void -on_pref_plugin_configure_activate (GtkButton *button, - gpointer user_data) -{ -} - void on_pref_pluginlist_cursor_changed (GtkTreeView *treeview, gpointer user_data) @@ -1506,6 +1524,7 @@ on_pref_pluginlist_cursor_changed (GtkTreeView *treeview, int *indices = gtk_tree_path_get_indices (path); DB_plugin_t **plugins = deadbeef->plug_get_list (); DB_plugin_t *p = plugins[*indices]; + g_free (indices); assert (p); GtkWidget *w = prefwin;//GTK_WIDGET (gtk_widget_get_parent_window (GTK_WIDGET (treeview))); assert (w); diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c index 0c30773d..1eba2b02 100644 --- a/plugins/gtkui/gtkui.c +++ b/plugins/gtkui/gtkui.c @@ -424,6 +424,7 @@ static DB_gui_t plugin = { DB_PLUGIN_SET_API_VERSION .plugin.version_major = 0, .plugin.version_minor = 1, + .plugin.nostop = 1, .plugin.type = DB_PLUGIN_MISC, .plugin.name = "Standard GTK2 user interface", .plugin.descr = "", |