summaryrefslogtreecommitdiff
path: root/plugins/shellexec
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2012-04-25 22:25:46 +0200
committerGravatar waker <wakeroid@gmail.com>2012-04-25 22:25:46 +0200
commit6974e0672bcd9cdab22cabc6b2aa64a533fa871a (patch)
treed8840a6dc8e547897b3145622c5fa505e4d6dbb2 /plugins/shellexec
parentce7f7611615bbe32c859a94a13f343097a120f19 (diff)
shellexec: fixed adding first and removing last shell command
Diffstat (limited to 'plugins/shellexec')
-rw-r--r--plugins/shellexec/shellexec.c57
-rw-r--r--plugins/shellexec/shellexec.h7
2 files changed, 59 insertions, 5 deletions
diff --git a/plugins/shellexec/shellexec.c b/plugins/shellexec/shellexec.c
index 58b21262..11f8f603 100644
--- a/plugins/shellexec/shellexec.c
+++ b/plugins/shellexec/shellexec.c
@@ -127,10 +127,10 @@ shx_find_sep (char *str) {
}
void
-shx_save_actions(Shx_action_t *action_list)
+shx_save_actions (void)
{
deadbeef->conf_remove_items("shellexec.");
- Shx_action_t *action = action_list;
+ Shx_action_t *action = actions;
int i = 0;
while(action) {
// build config line
@@ -254,6 +254,54 @@ shx_get_actions (DB_plugin_action_callback_t callback)
return action_list;
}
+Shx_action_t*
+shx_action_add (void) {
+ Shx_action_t *a = calloc (sizeof (Shx_action_t), 1);
+ if (!actions) {
+ actions = a;
+ }
+ else {
+ for (Shx_action_t *last = actions; last; last = (Shx_action_t *)last->parent.next) {
+ if (!last->parent.next) {
+ last->parent.next = (DB_plugin_action_t *)a;
+ }
+ }
+ }
+ return a;
+}
+
+void
+shx_action_free (Shx_action_t *a) {
+ if (a->shcommand) {
+ free ((char *)a->shcommand);
+ }
+ if (a->parent.title) {
+ free ((char *)a->parent.title);
+ }
+ if (a->parent.name) {
+ free ((char *)a->parent.name);
+ }
+ free (a);
+}
+
+void
+shx_action_remove (Shx_action_t *action) {
+ Shx_action_t *prev = NULL;
+ for (Shx_action_t *a = actions; a; a = (Shx_action_t *)a->parent.next) {
+ if (a == action) {
+ if (prev) {
+ prev->parent.next = a->parent.next;
+ }
+ else {
+ actions = (Shx_action_t *)a->parent.next;
+ }
+ break;
+ }
+ prev = a;
+ }
+ shx_action_free (action);
+}
+
static int
shx_start ()
{
@@ -331,6 +379,9 @@ static Shx_plugin_t plugin = {
.misc.plugin.start = shx_start,
.misc.plugin.stop = shx_stop,
.misc.plugin.get_actions = shx_get_plugin_actions,
- .save_actions = shx_save_actions
+ .save_actions = shx_save_actions,
+ .action_add = shx_action_add,
+ .action_remove = shx_action_remove,
+ .action_free = shx_action_free,
};
diff --git a/plugins/shellexec/shellexec.h b/plugins/shellexec/shellexec.h
index b76dfd85..1d10ac7d 100644
--- a/plugins/shellexec/shellexec.h
+++ b/plugins/shellexec/shellexec.h
@@ -40,8 +40,11 @@ typedef struct Shx_action_s
typedef struct Shx_plugin_s
{
DB_misc_t misc;
- void
- (*save_actions)(Shx_action_t *action_list);
+
+ void (*save_actions) (void);
+ Shx_action_t* (*action_add) (void);
+ void (*action_remove) (Shx_action_t *a);
+ void (*action_free) (Shx_action_t *a);
} Shx_plugin_t;
#endif