From 8c012917f5530d947c1a31adfc6aba4b0cf3853c Mon Sep 17 00:00:00 2001 From: Viktor Semykin Date: Tue, 25 May 2010 03:37:44 +0300 Subject: Misc plugin actions --- plugins/shellexec/Makefile.am | 9 +++ plugins/shellexec/shellexec.c | 125 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 plugins/shellexec/Makefile.am create mode 100644 plugins/shellexec/shellexec.c (limited to 'plugins/shellexec') diff --git a/plugins/shellexec/Makefile.am b/plugins/shellexec/Makefile.am new file mode 100644 index 00000000..65d6a5b8 --- /dev/null +++ b/plugins/shellexec/Makefile.am @@ -0,0 +1,9 @@ +if HAVE_SHELLEXEC +shxdir = $(libdir)/$(PACKAGE) +pkglib_LTLIBRARIES = shellexec.la +shellexec_la_SOURCES = shellexec.c +shellexec_la_LDFLAGS = -module + +shellexec_la_LIBADD = $(LDADD) $(HOTKEYS_LIBS) +AM_CFLAGS = $(CFLAGS) -std=c99 +endif diff --git a/plugins/shellexec/shellexec.c b/plugins/shellexec/shellexec.c new file mode 100644 index 00000000..39e7f4da --- /dev/null +++ b/plugins/shellexec/shellexec.c @@ -0,0 +1,125 @@ +/* + Shellexec plugin for DeaDBeeF + Copyright (C) 2009 Viktor Semykin + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#include +#include + +#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) +{ + 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; +} + +static int +shx_callback (DB_playItem_t *it, void *data) +{ + char fmt[1024]; //FIXME: possible stack corruption + deadbeef->pl_format_title (it, -1, fmt, sizeof (fmt), -1, data); + printf ("%s\n", fmt); + 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) +{ + 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); + trace ("Shellexec: %s\n", tmp); + + char *semicolon = strchr (tmp, ':'); + if (!semicolon) + { + fprintf (stdout, "Shellexec: wrong option <%s>\n", tmp); + continue; + } + + *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)); + + item = deadbeef->conf_find ("shellexec.", item); + single_action_count++; + } +} + +// define plugin interface +static DB_misc_t plugin = { + .plugin.api_vmajor = DB_API_VERSION_MAJOR, + .plugin.api_vminor = DB_API_VERSION_MINOR, + .plugin.type = DB_PLUGIN_MISC, + .plugin.id = "shellexec", + .plugin.name = "Shell commands for tracks", + .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 = shellexec_start, + + .get_single_actions = shx_get_single_actions +}; + -- cgit v1.2.3