diff options
author | Viktor Semykin <thesame.ml@gmail.com> | 2010-05-26 03:42:59 +0300 |
---|---|---|
committer | Viktor Semykin <thesame.ml@gmail.com> | 2010-05-26 03:42:59 +0300 |
commit | a6800830237690618eb454ab331ca6e4bdbd4100 (patch) | |
tree | ca1b2069f87c37f13f210bb053533fa730c2f2da /plugins/shellexec | |
parent | 8c012917f5530d947c1a31adfc6aba4b0cf3853c (diff) |
New plugins' actions system
Diffstat (limited to 'plugins/shellexec')
-rw-r--r-- | plugins/shellexec/shellexec.c | 63 |
1 files changed, 21 insertions, 42 deletions
diff --git a/plugins/shellexec/shellexec.c b/plugins/shellexec/shellexec.c index 39e7f4da..ec7fdcad 100644 --- a/plugins/shellexec/shellexec.c +++ b/plugins/shellexec/shellexec.c @@ -17,38 +17,31 @@ */ #include <stdio.h> #include <string.h> +#include <stdlib.h> #include "../../deadbeef.h" -#define MAX_COMMANDS 128 - #define trace(...) { fprintf(stderr, __VA_ARGS__); } //#define trace(fmt,...) static DB_misc_t plugin; static DB_functions_t *deadbeef; -DB_single_action_t shx_actions [MAX_COMMANDS]; -static int single_action_count; - DB_plugin_t * shellexec_load (DB_functions_t *api) { deadbeef = api; return DB_PLUGIN (&plugin); } -static int -shx_get_single_actions (DB_playItem_t *it, DB_single_action_t *actions[], int *size) +static char* +trim (char* s) { - if (*size < single_action_count) - return 0; - - int i; - *size = single_action_count; - trace ("Shellexec: %d actions\n", single_action_count); - for (i=0; i < single_action_count; i++) - actions[i] = &shx_actions[i]; - return 1; + char *h, *t; + + for (h = s; *h == ' ' || *h == '\t'; h++); + for (t = s + strlen (s); *t == ' ' || *t == '\t'; t--); + * (t+1) = 0; + return h; } static int @@ -60,30 +53,12 @@ shx_callback (DB_playItem_t *it, void *data) return 0; } -static char* -trim (char* s) -{ - char *h, *t; - - for (h = s; *h == ' ' || *h == '\t'; h++); - for (t = s + strlen (s); *t == ' ' || *t == '\t'; t--); - * (t+1) = 0; - return h; -} - static int -shellexec_start (void) +shx_get_actions (DB_plugin_action_t **actions) { - trace ("Starting shellexec\n"); - single_action_count = 0; DB_conf_item_t *item = deadbeef->conf_find ("shellexec.", NULL); while (item) { - if (single_action_count == MAX_COMMANDS) - { - fprintf (stdout, "Shellexec: max number of commands (%d) exceeded\n", MAX_COMMANDS); - break; - } size_t l = strlen (item->value) + 1; char tmp[l]; strcpy (tmp, item->value); @@ -98,13 +73,19 @@ shellexec_start (void) *semicolon = 0; - shx_actions[single_action_count].title = strdup (trim (semicolon + 1)); - shx_actions[single_action_count].callback = shx_callback; - shx_actions[single_action_count].data = strdup (trim (tmp)); + DB_plugin_action_t *action = calloc (sizeof (DB_plugin_action_t), 1); + + action->title = strdup (trim (semicolon + 1)); + action->callback = shx_callback; + action->data = strdup (trim (tmp)); + action->flags = DB_ACTION_SINGLE_TRACK | DB_ACTION_ALLOW_MULTIPLE_TRACKS; + + action->next = *actions; + *actions = action; item = deadbeef->conf_find ("shellexec.", item); - single_action_count++; } + return 1; } // define plugin interface @@ -118,8 +99,6 @@ static DB_misc_t plugin = { .plugin.author = "Viktor Semykin", .plugin.email = "thesame.ml@gmail.com", .plugin.website = "http://deadbeef.sf.net", - .plugin.start = shellexec_start, - - .get_single_actions = shx_get_single_actions + .plugin.get_actions = shx_get_actions }; |