summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--deadbeef.h10
-rw-r--r--plugins/cdda/cdda.c8
-rw-r--r--plugins/gtkui/actions.c135
-rw-r--r--plugins/gtkui/actions.h3
-rw-r--r--plugins/gtkui/gtkui.c2
-rw-r--r--plugins/gtkui/plcommon.c51
-rw-r--r--plugins/lastfm/lastfm.c21
-rw-r--r--plugins/shellexec/shellexec.c27
8 files changed, 145 insertions, 112 deletions
diff --git a/deadbeef.h b/deadbeef.h
index fd213156..5bf8b003 100644
--- a/deadbeef.h
+++ b/deadbeef.h
@@ -524,7 +524,10 @@ enum {
DB_ACTION_ALLOW_MULTIPLE_TRACKS = 1 << 2,
/* Action can (and prefer) traverse multiple tracks by itself */
- DB_ACTION_CAN_MULTIPLE_TRACKS = 1 << 3
+ DB_ACTION_CAN_MULTIPLE_TRACKS = 1 << 3,
+
+ /* Action is inactive */
+ DB_ACTION_DISABLED = 1 << 4
};
typedef struct DB_plugin_action_s {
@@ -583,10 +586,9 @@ typedef struct DB_plugin_s {
// actions
/* by get_actions function plugin is queried for implemented actions
- @action is linked list (initially null), function must add its actions to list
- @returns nonzero on success, 0 on fail
+ @returns linked list of actions
*/
- int (*get_actions) (DB_plugin_action_t **actions);
+ DB_plugin_action_t* (*get_actions) (DB_playItem_t *it);
} DB_plugin_t;
typedef struct DB_fileinfo_s {
diff --git a/plugins/cdda/cdda.c b/plugins/cdda/cdda.c
index 8e01458e..3eb0c2a4 100644
--- a/plugins/cdda/cdda.c
+++ b/plugins/cdda/cdda.c
@@ -547,12 +547,10 @@ static DB_plugin_action_t add_cd_action = {
.next = NULL
};
-static int
-cda_get_actions (DB_plugin_action_t **actions)
+static DB_plugin_action_t *
+cda_get_actions (DB_playItem_t *unused)
{
- add_cd_action.next = *actions;
- *actions = &add_cd_action;
- return 1;
+ return &add_cd_action;
}
static const char *exts[] = { "cda", "nrg", NULL };
diff --git a/plugins/gtkui/actions.c b/plugins/gtkui/actions.c
index 83f88151..0f07a4b0 100644
--- a/plugins/gtkui/actions.c
+++ b/plugins/gtkui/actions.c
@@ -26,22 +26,6 @@
#define trace(...) { fprintf(stderr, __VA_ARGS__); }
//#define trace(fmt,...)
-DB_plugin_action_t *plugins_actions = NULL;
-
-void
-gather_actions ()
-{
- trace ("gathering actions\n");
- DB_plugin_t **plugins = deadbeef->plug_get_list();
- int i;
-
- for (i = 0; plugins[i]; i++)
- {
- if (plugins[i]->get_actions)
- plugins[i]->get_actions (&plugins_actions);
- }
-}
-
static void
on_actionitem_activate (GtkMenuItem *menuitem,
DB_plugin_action_t *action)
@@ -52,70 +36,81 @@ on_actionitem_activate (GtkMenuItem *menuitem,
void
add_mainmenu_actions (GtkWidget *mainwin)
{
- DB_plugin_action_t *action;
- for (action = plugins_actions; action; action = action->next)
- {
- if (0 == (action->flags & DB_ACTION_COMMON))
- continue;
+ DB_plugin_t **plugins = deadbeef->plug_get_list();
+ int i;
- //We won't add item directly to main menu
- if (!strchr (action->title, '/'))
+ for (i = 0; plugins[i]; i++)
+ {
+ if (!plugins[i]->get_actions)
continue;
- char *tmp;
- char *ptr = tmp = strdup (action->title);
- char *prev_title = NULL;
-
- GtkWidget *current = mainwin;
- GtkWidget *previous;
+ DB_plugin_action_t *actions = plugins[i]->get_actions (NULL);
+ DB_plugin_action_t *action;
- while (1)
+ for (action = actions; action; action = action->next)
{
- char *slash = strchr (ptr, '/');
- if (!slash)
- {
- GtkWidget *actionitem;
- actionitem = gtk_image_menu_item_new_with_mnemonic (ptr);
- gtk_widget_show (actionitem);
-
- /* Here we have special cases for different submenus */
- if (0 == strcmp ("File", prev_title))
- gtk_menu_shell_insert (GTK_MENU_SHELL (current), actionitem, 5);
- else if (0 == strcmp ("Edit", prev_title))
- gtk_menu_shell_insert (GTK_MENU_SHELL (current), actionitem, 7);
- else
- gtk_container_add (GTK_CONTAINER (current), actionitem);
-
- g_signal_connect ((gpointer) actionitem, "activate",
- G_CALLBACK (on_actionitem_activate),
- action);
- break;
- }
- *slash = 0;
- char menuname [1024];
+ if (0 == (action->flags & DB_ACTION_COMMON))
+ continue;
- snprintf (menuname, sizeof (menuname), "%s_menu", ptr);
+ //We won't add item directly to main menu
+ if (!strchr (action->title, '/'))
+ continue;
- previous = current;
- current = lookup_widget (current, menuname);
- if (!current)
- {
- GtkWidget *newitem;
+ char *tmp;
+ char *ptr = tmp = strdup (action->title);
+ char *prev_title = NULL;
- newitem = gtk_menu_item_new_with_mnemonic (ptr);
- gtk_widget_show (newitem);
+ GtkWidget *current = mainwin;
+ GtkWidget *previous;
- //If we add new submenu in main bar, add it before 'Help'
- if (NULL == prev_title)
- gtk_menu_shell_insert (GTK_MENU_SHELL (previous), newitem, 4);
- else
- gtk_container_add (GTK_CONTAINER (previous), newitem);
-
- current = gtk_menu_new ();
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (newitem), current);
+ while (1)
+ {
+ char *slash = strchr (ptr, '/');
+ if (!slash)
+ {
+ GtkWidget *actionitem;
+ actionitem = gtk_image_menu_item_new_with_mnemonic (ptr);
+ gtk_widget_show (actionitem);
+
+ /* Here we have special cases for different submenus */
+ if (0 == strcmp ("File", prev_title))
+ gtk_menu_shell_insert (GTK_MENU_SHELL (current), actionitem, 5);
+ else if (0 == strcmp ("Edit", prev_title))
+ gtk_menu_shell_insert (GTK_MENU_SHELL (current), actionitem, 7);
+ else
+ gtk_container_add (GTK_CONTAINER (current), actionitem);
+
+ g_signal_connect ((gpointer) actionitem, "activate",
+ G_CALLBACK (on_actionitem_activate),
+ action);
+ break;
+ }
+ *slash = 0;
+ char menuname [1024];
+
+ snprintf (menuname, sizeof (menuname), "%s_menu", ptr);
+
+ previous = current;
+ current = lookup_widget (current, menuname);
+ if (!current)
+ {
+ GtkWidget *newitem;
+
+ newitem = gtk_menu_item_new_with_mnemonic (ptr);
+ gtk_widget_show (newitem);
+
+ //If we add new submenu in main bar, add it before 'Help'
+ if (NULL == prev_title)
+ gtk_menu_shell_insert (GTK_MENU_SHELL (previous), newitem, 4);
+ else
+ gtk_container_add (GTK_CONTAINER (previous), newitem);
+
+ current = gtk_menu_new ();
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (newitem), current);
+ }
+ prev_title = ptr;
+ ptr = slash + 1;
}
- prev_title = ptr;
- ptr = slash + 1;
}
}
}
diff --git a/plugins/gtkui/actions.h b/plugins/gtkui/actions.h
index 2f8eb827..b064647f 100644
--- a/plugins/gtkui/actions.h
+++ b/plugins/gtkui/actions.h
@@ -21,9 +21,6 @@
#ifndef __ACTIONS_H
#define __ACTIONS_H
-extern DB_plugin_action_t *plugins_actions;
-
-void gather_actions ();
void add_mainmenu_actions (GtkWidget *mainwin);
#endif
diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c
index 2e89509d..6e2eb038 100644
--- a/plugins/gtkui/gtkui.c
+++ b/plugins/gtkui/gtkui.c
@@ -927,8 +927,6 @@ gtkui_start (void) {
}
}
- gather_actions ();
-
// gtk must be running in separate thread
gtk_initialized = 0;
gtk_tid = deadbeef->thread_start (gtkui_thread, NULL);
diff --git a/plugins/gtkui/plcommon.c b/plugins/gtkui/plcommon.c
index 5b0eef0f..fbd87c2b 100644
--- a/plugins/gtkui/plcommon.c
+++ b/plugins/gtkui/plcommon.c
@@ -433,25 +433,38 @@ list_context_menu (DdbListview *listview, DdbListviewIter it, int idx) {
gtk_container_add (GTK_CONTAINER (playlist_menu), separator8);
gtk_widget_set_sensitive (separator8, FALSE);
+ int selected_count = 0;
+ DB_playItem_t *pit = deadbeef->pl_get_first (PL_MAIN);
+ DB_playItem_t *selected = NULL;
+ while (pit) {
+ if (deadbeef->pl_is_selected (pit))
+ {
+ if (!selected)
+ selected = pit;
+ selected_count++;
+ }
+ DB_playItem_t *next = deadbeef->pl_get_next (pit, PL_MAIN);
+ deadbeef->pl_item_unref (pit);
+ pit = next;
+ }
- if (plugins_actions)
+ DB_plugin_t **plugins = deadbeef->plug_get_list();
+ int i;
+
+ for (i = 0; plugins[i]; i++)
{
- int selected_count = 0;
- DB_playItem_t *it = deadbeef->pl_get_first (PL_MAIN);
- while (it) {
- if (deadbeef->pl_is_selected (it))
- selected_count++;
- DB_playItem_t *next = deadbeef->pl_get_next (it, PL_MAIN);
- deadbeef->pl_item_unref (it);
- it = next;
- }
+ if (!plugins[i]->get_actions)
+ continue;
+ DB_plugin_action_t *actions = plugins[i]->get_actions (selected);
DB_plugin_action_t *action;
- for (action = plugins_actions; action; action = action->next)
+
+ int count = 0;
+ for (action = actions; action; action = action->next)
{
if (action->flags & DB_ACTION_COMMON)
continue;
-
+ count++;
GtkWidget *actionitem;
actionitem = gtk_menu_item_new_with_mnemonic (action->title);
gtk_widget_show (actionitem);
@@ -464,15 +477,19 @@ list_context_menu (DdbListview *listview, DdbListviewIter it, int idx) {
if (!(
((selected_count == 1) && (action->flags & DB_ACTION_SINGLE_TRACK)) ||
((selected_count > 1) && (action->flags & DB_ACTION_ALLOW_MULTIPLE_TRACKS))
- ))
+ ) ||
+ action->flags & DB_ACTION_DISABLED)
{
gtk_widget_set_sensitive (GTK_WIDGET (actionitem), FALSE);
}
}
- separator8 = gtk_separator_menu_item_new ();
- gtk_widget_show (separator8);
- gtk_container_add (GTK_CONTAINER (playlist_menu), separator8);
- gtk_widget_set_sensitive (separator8, FALSE);
+ if (count > 0)
+ {
+ separator8 = gtk_separator_menu_item_new ();
+ gtk_widget_show (separator8);
+ gtk_container_add (GTK_CONTAINER (playlist_menu), separator8);
+ gtk_widget_set_sensitive (separator8, FALSE);
+ }
}
properties1 = gtk_menu_item_new_with_mnemonic ("Properties");
diff --git a/plugins/lastfm/lastfm.c b/plugins/lastfm/lastfm.c
index d8ddf5f6..1773abd6 100644
--- a/plugins/lastfm/lastfm.c
+++ b/plugins/lastfm/lastfm.c
@@ -869,13 +869,22 @@ static DB_plugin_action_t lookup_action = {
.next = &love_action
};
-static int
-lfm_get_actions (DB_plugin_action_t **actions)
+static DB_plugin_action_t *
+lfm_get_actions (DB_playItem_t *it)
{
- // Just prepend our action
- love_action.next = *actions;
- *actions = &lookup_action;
- return 1;
+ if (!it ||
+ !deadbeef->pl_find_meta (it, "artist") ||
+ !deadbeef->pl_find_meta (it, "title"))
+ {
+ love_action.flags |= DB_ACTION_DISABLED;
+ lookup_action.flags |= DB_ACTION_DISABLED;
+ }
+ else
+ {
+ love_action.flags &= ~DB_ACTION_DISABLED;
+ lookup_action.flags &= ~DB_ACTION_DISABLED;
+ }
+ return &lookup_action;
}
static const char settings_dlg[] =
diff --git a/plugins/shellexec/shellexec.c b/plugins/shellexec/shellexec.c
index ec7fdcad..178add2e 100644
--- a/plugins/shellexec/shellexec.c
+++ b/plugins/shellexec/shellexec.c
@@ -27,6 +27,8 @@
static DB_misc_t plugin;
static DB_functions_t *deadbeef;
+static DB_plugin_action_t *actions;
+
DB_plugin_t *
shellexec_load (DB_functions_t *api) {
deadbeef = api;
@@ -53,9 +55,18 @@ shx_callback (DB_playItem_t *it, void *data)
return 0;
}
+static DB_plugin_action_t *
+shx_get_actions (DB_playItem_t *unused)
+{
+ return actions;
+}
+
static int
-shx_get_actions (DB_plugin_action_t **actions)
+shx_start ()
{
+ actions = NULL;
+ DB_plugin_action_t *prev = NULL;
+
DB_conf_item_t *item = deadbeef->conf_find ("shellexec.", NULL);
while (item)
{
@@ -79,13 +90,18 @@ shx_get_actions (DB_plugin_action_t **actions)
action->callback = shx_callback;
action->data = strdup (trim (tmp));
action->flags = DB_ACTION_SINGLE_TRACK | DB_ACTION_ALLOW_MULTIPLE_TRACKS;
+ action->next = NULL;
+
+ if (prev)
+ prev->next = action;
+ prev = action;
- action->next = *actions;
- *actions = action;
+ if (!actions)
+ actions = action;
item = deadbeef->conf_find ("shellexec.", item);
}
- return 1;
+ return 0;
}
// define plugin interface
@@ -94,11 +110,12 @@ static DB_misc_t plugin = {
.plugin.api_vminor = DB_API_VERSION_MINOR,
.plugin.type = DB_PLUGIN_MISC,
.plugin.id = "shellexec",
- .plugin.name = "Shell commands for tracks",
+ .plugin.name = "Shell commands",
.plugin.descr = "Executes configurable shell commands for tracks",
.plugin.author = "Viktor Semykin",
.plugin.email = "thesame.ml@gmail.com",
.plugin.website = "http://deadbeef.sf.net",
+ .plugin.start = shx_start,
.plugin.get_actions = shx_get_actions
};