diff options
author | 2012-11-05 22:17:25 +0100 | |
---|---|---|
committer | 2012-11-05 22:18:42 +0100 | |
commit | eee42b650c1408388e08e85dfbd473e521492906 (patch) | |
tree | cf3aa58456fead35c0917dd3bc121d973417dd5c | |
parent | e4b82f177f06caa3cc123899bc420627abe022b6 (diff) |
more adaptation of plugin actions to the new APIs
-rw-r--r-- | plugins/converter/convgui.c | 37 | ||||
-rw-r--r-- | plugins/lastfm/lastfm.c | 67 | ||||
-rw-r--r-- | plugins/shellexec/shellexec.c | 102 | ||||
-rw-r--r-- | plugins/shellexecui/shellexecui.c | 2 |
4 files changed, 162 insertions, 46 deletions
diff --git a/plugins/converter/convgui.c b/plugins/converter/convgui.c index be6795c3..302c31fb 100644 --- a/plugins/converter/convgui.c +++ b/plugins/converter/convgui.c @@ -344,22 +344,24 @@ converter_show_cb (void *data) { case DDB_ACTION_CTX_SELECTION: { // copy list - int nsel = deadbeef->pl_getselcount (); - conv->convert_items_count = nsel; - if (0 < nsel) { - conv->convert_items = malloc (sizeof (DB_playItem_t *) * nsel); - if (conv->convert_items) { - int n = 0; - DB_playItem_t *it = deadbeef->pl_get_first (PL_MAIN); - while (it) { - if (deadbeef->pl_is_selected (it)) { - assert (n < nsel); - deadbeef->pl_item_ref (it); - conv->convert_items[n++] = it; + ddb_playlist_t *plt = deadbeef->plt_get_curr (); + if (plt) { + conv->convert_items_count = deadbeef->plt_getselcount (plt); + if (0 < conv->convert_items_count) { + conv->convert_items = malloc (sizeof (DB_playItem_t *) * conv->convert_items_count); + if (conv->convert_items) { + int n = 0; + DB_playItem_t *it = deadbeef->pl_get_first (PL_MAIN); + while (it) { + if (deadbeef->pl_is_selected (it)) { + assert (n < conv->convert_items_count); + deadbeef->pl_item_ref (it); + conv->convert_items[n++] = it; + } + DB_playItem_t *next = deadbeef->pl_get_next (it, PL_MAIN); + deadbeef->pl_item_unref (it); + it = next; } - DB_playItem_t *next = deadbeef->pl_get_next (it, PL_MAIN); - deadbeef->pl_item_unref (it); - it = next; } } } @@ -377,11 +379,8 @@ converter_show_cb (void *data) { int n = 0; DB_playItem_t *it = deadbeef->pl_get_first (PL_MAIN); while (it) { - deadbeef->pl_item_ref (it); conv->convert_items[n++] = it; - DB_playItem_t *next = deadbeef->pl_get_next (it, PL_MAIN); - deadbeef->pl_item_unref (it); - it = next; + it = deadbeef->pl_get_next (it, PL_MAIN); } } } diff --git a/plugins/lastfm/lastfm.c b/plugins/lastfm/lastfm.c index 2f542a62..339587dd 100644 --- a/plugins/lastfm/lastfm.c +++ b/plugins/lastfm/lastfm.c @@ -869,31 +869,68 @@ lastfm_stop (void) { } static int -lfm_action_lookup (DB_plugin_action_t *action, DB_playItem_t *it) +lfm_action_lookup (DB_plugin_action_t *action, int ctx) { + char *command = NULL; + DB_playItem_t *it = NULL; char artist[META_FIELD_SIZE]; + char title[META_FIELD_SIZE]; + + if (ctx == DDB_ACTION_CTX_SELECTION) { + // find first selected + ddb_playlist_t *plt = deadbeef->plt_get_curr (); + if (plt) { + it = deadbeef->plt_get_first (plt, PL_MAIN); + while (it) { + if (deadbeef->pl_is_selected (it)) { + break; + } + DB_playItem_t *next = deadbeef->pl_get_next (it, PL_MAIN); + deadbeef->pl_item_unref (it); + it = next; + } + deadbeef->plt_unref (plt); + } + } + else if (ctx == DDB_ACTION_CTX_NOWPLAYING) { + it = deadbeef->streamer_get_playing_track (); + } + if (!it) { + goto out; + } + if (!deadbeef->pl_get_meta (it, "artist", artist, sizeof (artist))) { - return 0; + goto out; } - char title[META_FIELD_SIZE]; if (!deadbeef->pl_get_meta (it, "title", title, sizeof (title))) { - return 0; + goto out; } - char eartist [strlen (artist) * 3 + 1]; - char etitle [strlen (title) * 3 + 1]; + int la = strlen (artist) * 3 + 1; + int lt = strlen (title) * 3 + 1; + char *eartist = alloca (la); + char *etitle = alloca (lt); - if (-1 == lfm_uri_encode (eartist, sizeof (eartist), artist)) - return 0; + if (-1 == lfm_uri_encode (eartist, la, artist)) { + goto out; + } - if (-1 == lfm_uri_encode (etitle, sizeof (etitle), title)) - return 0; + if (-1 == lfm_uri_encode (etitle, lt, title)) { + goto out; + } + + if (-1 == asprintf (&command, "xdg-open 'http://www.last.fm/music/%s/_/%s' &", eartist, etitle)) { + goto out; + } - char *command = NULL; - if (-1 == asprintf (&command, "xdg-open 'http://www.last.fm/music/%s/_/%s' &", eartist, etitle)) - return 0; system (command); - free (command); +out: + if (it) { + deadbeef->pl_item_unref (it); + } + if (command) { + free (command); + } return 0; } @@ -952,7 +989,7 @@ static const char settings_dlg[] = // define plugin interface static DB_misc_t plugin = { .plugin.api_vmajor = 1, - .plugin.api_vminor = 0, + .plugin.api_vminor = 5, .plugin.version_major = 1, .plugin.version_minor = 0, .plugin.type = DB_PLUGIN_MISC, diff --git a/plugins/shellexec/shellexec.c b/plugins/shellexec/shellexec.c index b011067f..ce13db7d 100644 --- a/plugins/shellexec/shellexec.c +++ b/plugins/shellexec/shellexec.c @@ -48,7 +48,7 @@ #include <string.h> #include <stdlib.h> #include <limits.h> - +#include <assert.h> #include "../../deadbeef.h" #include "shellexec.h" @@ -80,14 +80,7 @@ trim (char* s) return h; } -static int -shx_callback (Shx_action_t *action, DB_playItem_t *it) -{ - if (action->parent.flags&(DB_ACTION_COMMON)) { - trace ("%s\n", action->shcommand); - system (action->shcommand); - return 0; - } +static int shx_exec_track_cmd (Shx_action_t *action, DB_playItem_t *it) { char cmd[_POSIX_ARG_MAX]; int res = deadbeef->pl_format_title_escaped (it, -1, cmd, sizeof (cmd) - 2, -1, action->shcommand); if (res < 0) { @@ -97,7 +90,94 @@ shx_callback (Shx_action_t *action, DB_playItem_t *it) strcat (cmd, "&"); trace ("%s\n", cmd); system (cmd); - return 0; +} + +static int +shx_callback (Shx_action_t *action, int ctx) +{ + int res = 0; + switch (ctx) { + case DDB_ACTION_CTX_MAIN: + trace ("%s\n", action->shcommand); + system (action->shcommand); + break; + case DDB_ACTION_CTX_SELECTION: + { + deadbeef->pl_lock (); + ddb_playlist_t *plt = deadbeef->plt_get_curr (); + if (plt) { + DB_playItem_t **items; + int items_count = deadbeef->plt_getselcount (plt); + if (0 < items_count) { + items = malloc (sizeof (DB_playItem_t *) * items_count); + if (items) { + int n = 0; + DB_playItem_t *it = deadbeef->pl_get_first (PL_MAIN); + while (it) { + if (deadbeef->pl_is_selected (it)) { + assert (n < items_count); + deadbeef->pl_item_ref (it); + items[n++] = it; + } + DB_playItem_t *next = deadbeef->pl_get_next (it, PL_MAIN); + deadbeef->pl_item_unref (it); + it = next; + } + } + } + deadbeef->pl_unlock (); + if (items) { + for (int i = 0; i < items_count; i++) { + res = shx_exec_track_cmd (action, items[i]); + deadbeef->pl_item_unref (items[i]); + } + free (items); + } + deadbeef->plt_unref (plt); + } + } + break; + case DDB_ACTION_CTX_PLAYLIST: + { + ddb_playlist_t *plt = deadbeef->plt_get_curr (); + if (plt) { + deadbeef->pl_lock (); + DB_playItem_t **items; + int items_count = deadbeef->plt_get_item_count (plt, PL_MAIN); + if (0 < items_count) { + items = malloc (sizeof (DB_playItem_t *) * items_count); + if (items) { + int n = 0; + DB_playItem_t *it = deadbeef->pl_get_first (PL_MAIN); + while (it) { + items[n++] = it; + it = deadbeef->pl_get_next (it, PL_MAIN); + } + } + } + deadbeef->pl_unlock (); + if (items) { + for (int i = 0; i < items_count; i++) { + res = shx_exec_track_cmd (action, items[i]); + deadbeef->pl_item_unref (items[i]); + } + free (items); + } + deadbeef->plt_unref (plt); + } + } + break; + case DDB_ACTION_CTX_NOWPLAYING: + { + DB_playItem_t *it = deadbeef->streamer_get_playing_track (); + if (it) { + res = shx_exec_track_cmd (action, it); + deadbeef->pl_item_unref (it); + } + } + break; + } + return res; } static DB_plugin_action_t * @@ -337,7 +417,7 @@ shx_stop () // define plugin interface static Shx_plugin_t plugin = { .misc.plugin.api_vmajor = 1, - .misc.plugin.api_vminor = 0, + .misc.plugin.api_vminor = 5, .misc.plugin.version_major = 1, .misc.plugin.version_minor = 1, .misc.plugin.type = DB_PLUGIN_MISC, diff --git a/plugins/shellexecui/shellexecui.c b/plugins/shellexecui/shellexecui.c index 9bd82bc6..39761ec5 100644 --- a/plugins/shellexecui/shellexecui.c +++ b/plugins/shellexecui/shellexecui.c @@ -395,7 +395,7 @@ int shxui_connect() { static DB_misc_t plugin = { .plugin.type = DB_PLUGIN_MISC, .plugin.api_vmajor = 1, - .plugin.api_vminor = 0, + .plugin.api_vminor = 5, .plugin.version_major = 1, .plugin.version_minor = 0, #if GTK_CHECK_VERSION(3,0,0) |