summaryrefslogtreecommitdiff
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
parentce7f7611615bbe32c859a94a13f343097a120f19 (diff)
shellexec: fixed adding first and removing last shell command
-rw-r--r--plugins/shellexec/shellexec.c57
-rw-r--r--plugins/shellexec/shellexec.h7
-rw-r--r--plugins/shellexecui/shellexecui.c33
3 files changed, 65 insertions, 32 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
diff --git a/plugins/shellexecui/shellexecui.c b/plugins/shellexecui/shellexecui.c
index 04661bdd..0f979653 100644
--- a/plugins/shellexecui/shellexecui.c
+++ b/plugins/shellexecui/shellexecui.c
@@ -149,20 +149,8 @@ on_remove_button_clicked (GtkButton *button,
gtk_tree_model_get(treemodel, &iter, COL_META, &action, -1);
//remove action from list
- if(actions == action) {
- actions = (Shx_action_t*)action->parent.next;
- }
- else {
- Shx_action_t *prev = actions;
- while(((Shx_action_t*)prev->parent.next) != action) {
- prev = (Shx_action_t*)prev->parent.next;
- }
- prev->parent.next = action->parent.next;
- }
- free((void *)action->shcommand);
- free((void *)action->parent.name);
- free((void *)action->parent.title);
- free(action);
+ shellexec_plugin->action_remove (action);
+ actions = (Shx_action_t *)shellexec_plugin->misc.plugin.get_actions(NULL);
GtkTreeIter next_iter = iter;
if(gtk_tree_model_iter_next(treemodel, &next_iter)) {
@@ -177,7 +165,7 @@ on_remove_button_clicked (GtkButton *button,
}
gtk_list_store_remove(GTK_LIST_STORE(treemodel), &iter);
- shellexec_plugin->save_actions(actions);
+ shellexec_plugin->save_actions();
deadbeef->sendmessage (DB_EV_ACTIONSCHANGED, 0, 0, 0);
}
}
@@ -281,17 +269,8 @@ on_edit_ok_button_clicked (GtkButton *button, gpointer user_data) {
GtkTreeIter iter;
if(current_action == NULL) {
- current_action = calloc(sizeof(Shx_action_t), 1);
- if(!actions) {
- actions = current_action;
- }
- else {
- Shx_action_t *last = actions;
- while(last->parent.next) {
- last = (Shx_action_t *)last->parent.next;
- }
- last->parent.next = (DB_plugin_action_t*)current_action;
- }
+ current_action = shellexec_plugin->action_add ();
+ actions = (Shx_action_t *)shellexec_plugin->misc.plugin.get_actions(NULL);
gtk_list_store_append(GTK_LIST_STORE(treemodel), &iter);
gtk_list_store_set(GTK_LIST_STORE(treemodel), &iter, COL_META, current_action, -1);
gtk_tree_selection_select_iter(selection, &iter);
@@ -335,7 +314,7 @@ on_edit_ok_button_clicked (GtkButton *button, gpointer user_data) {
edit_dlg = NULL;
current_action = NULL;
- shellexec_plugin->save_actions(actions);
+ shellexec_plugin->save_actions();
deadbeef->sendmessage (DB_EV_ACTIONSCHANGED, 0, 0, 0);
}