From 6498b5187f44a48571aac268c9c377b7c3e6af7b Mon Sep 17 00:00:00 2001 From: waker Date: Tue, 24 Apr 2012 19:40:56 +0200 Subject: shellexec[ui]: cleaned up api, fixed memleaks, add/remove/edit works without restarting player, Disabled flag is not user-editable and is not saved to config --- plugins/shellexecui/interface.c | 31 ++++++++--------- plugins/shellexecui/shellexec.glade | 68 ++++++++++++++----------------------- plugins/shellexecui/shellexecui.c | 45 ++++++++++++------------ 3 files changed, 64 insertions(+), 80 deletions(-) (limited to 'plugins/shellexecui') diff --git a/plugins/shellexecui/interface.c b/plugins/shellexecui/interface.c index c5795b0e..cb986101 100644 --- a/plugins/shellexecui/interface.c +++ b/plugins/shellexecui/interface.c @@ -120,16 +120,15 @@ create_shellexec_conf_edit_dialog (void) GtkWidget *table1; GtkWidget *title_label; GtkWidget *cmd_label; - GtkWidget *name_entry; GtkWidget *cmd_entry; GtkWidget *name_label; GtkWidget *title_entry; + GtkWidget *name_entry; GtkWidget *single_check; GtkWidget *multiple_check; GtkWidget *local_check; GtkWidget *remote_check; GtkWidget *playlist_check; - GtkWidget *disabled_check; GtkWidget *dialog_action_area1; GtkWidget *edit_cancel_button; GtkWidget *edit_ok_button; @@ -157,28 +156,22 @@ create_shellexec_conf_edit_dialog (void) (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment (GTK_MISC (title_label), 0, 0.5); - cmd_label = gtk_label_new (_("Shell Command:")); + cmd_label = gtk_label_new (_("Command:")); gtk_widget_show (cmd_label); gtk_table_attach (GTK_TABLE (table1), cmd_label, 0, 1, 2, 3, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment (GTK_MISC (cmd_label), 0, 0.5); - name_entry = gtk_entry_new (); - gtk_widget_show (name_entry); - gtk_table_attach (GTK_TABLE (table1), name_entry, 1, 2, 0, 1, - (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), - (GtkAttachOptions) (0), 0, 0); - gtk_entry_set_invisible_char (GTK_ENTRY (name_entry), 8226); - cmd_entry = gtk_entry_new (); gtk_widget_show (cmd_entry); gtk_table_attach (GTK_TABLE (table1), cmd_entry, 1, 2, 2, 3, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0); + gtk_widget_set_tooltip_text (cmd_entry, _("Arbitrary shell command. Will be executed in the shell context which the main application was started from. Title formatting can be used. Example: xdg-open %D")); gtk_entry_set_invisible_char (GTK_ENTRY (cmd_entry), 8226); - name_label = gtk_label_new (_("Name:")); + name_label = gtk_label_new (_("ID:")); gtk_widget_show (name_label); gtk_table_attach (GTK_TABLE (table1), name_label, 0, 1, 0, 1, (GtkAttachOptions) (GTK_FILL), @@ -190,8 +183,17 @@ create_shellexec_conf_edit_dialog (void) gtk_table_attach (GTK_TABLE (table1), title_entry, 1, 2, 1, 2, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0); + gtk_widget_set_tooltip_text (title_entry, _("Free-form name, for example \"My Shell Command\"")); gtk_entry_set_invisible_char (GTK_ENTRY (title_entry), 8226); + name_entry = gtk_entry_new (); + gtk_widget_show (name_entry); + gtk_table_attach (GTK_TABLE (table1), name_entry, 1, 2, 0, 1, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_widget_set_tooltip_text (name_entry, _("Command ID, normally it should be something short, for example \"youtube_open\". It must be unique.")); + gtk_entry_set_invisible_char (GTK_ENTRY (name_entry), 8226); + single_check = gtk_check_button_new_with_mnemonic (_("Single Tracks")); gtk_widget_show (single_check); gtk_box_pack_start (GTK_BOX (dialog_vbox1), single_check, FALSE, FALSE, 0); @@ -212,10 +214,6 @@ create_shellexec_conf_edit_dialog (void) gtk_widget_show (playlist_check); gtk_box_pack_start (GTK_BOX (dialog_vbox1), playlist_check, FALSE, FALSE, 0); - disabled_check = gtk_check_button_new_with_mnemonic (_("Disabled")); - gtk_widget_show (disabled_check); - gtk_box_pack_start (GTK_BOX (dialog_vbox1), disabled_check, FALSE, FALSE, 0); - dialog_action_area1 = gtk_dialog_get_action_area (GTK_DIALOG (shellexec_conf_edit_dialog)); gtk_widget_show (dialog_action_area1); gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1), GTK_BUTTONBOX_END); @@ -243,16 +241,15 @@ create_shellexec_conf_edit_dialog (void) GLADE_HOOKUP_OBJECT (shellexec_conf_edit_dialog, table1, "table1"); GLADE_HOOKUP_OBJECT (shellexec_conf_edit_dialog, title_label, "title_label"); GLADE_HOOKUP_OBJECT (shellexec_conf_edit_dialog, cmd_label, "cmd_label"); - GLADE_HOOKUP_OBJECT (shellexec_conf_edit_dialog, name_entry, "name_entry"); GLADE_HOOKUP_OBJECT (shellexec_conf_edit_dialog, cmd_entry, "cmd_entry"); GLADE_HOOKUP_OBJECT (shellexec_conf_edit_dialog, name_label, "name_label"); GLADE_HOOKUP_OBJECT (shellexec_conf_edit_dialog, title_entry, "title_entry"); + GLADE_HOOKUP_OBJECT (shellexec_conf_edit_dialog, name_entry, "name_entry"); GLADE_HOOKUP_OBJECT (shellexec_conf_edit_dialog, single_check, "single_check"); GLADE_HOOKUP_OBJECT (shellexec_conf_edit_dialog, multiple_check, "multiple_check"); GLADE_HOOKUP_OBJECT (shellexec_conf_edit_dialog, local_check, "local_check"); GLADE_HOOKUP_OBJECT (shellexec_conf_edit_dialog, remote_check, "remote_check"); GLADE_HOOKUP_OBJECT (shellexec_conf_edit_dialog, playlist_check, "playlist_check"); - GLADE_HOOKUP_OBJECT (shellexec_conf_edit_dialog, disabled_check, "disabled_check"); GLADE_HOOKUP_OBJECT_NO_REF (shellexec_conf_edit_dialog, dialog_action_area1, "dialog_action_area1"); GLADE_HOOKUP_OBJECT (shellexec_conf_edit_dialog, edit_cancel_button, "edit_cancel_button"); GLADE_HOOKUP_OBJECT (shellexec_conf_edit_dialog, edit_ok_button, "edit_ok_button"); diff --git a/plugins/shellexecui/shellexec.glade b/plugins/shellexecui/shellexec.glade index 69425367..2b291d9f 100644 --- a/plugins/shellexecui/shellexec.glade +++ b/plugins/shellexecui/shellexec.glade @@ -257,7 +257,7 @@ True - Shell Command: + Command: False False GTK_JUSTIFY_LEFT @@ -282,30 +282,10 @@ - - - True - True - True - True - 0 - - True - - False - - - 1 - 2 - 0 - 1 - - - - True + Arbitrary shell command. Will be executed in the shell context which the main application was started from. Title formatting can be used. Example: xdg-open %D True True True @@ -327,7 +307,7 @@ True - Name: + ID: False False GTK_JUSTIFY_LEFT @@ -355,6 +335,7 @@ True + Free-form name, for example "My Shell Command" True True True @@ -372,6 +353,28 @@ + + + + True + Command ID, normally it should be something short, for example "youtube_open". It must be unique. + True + True + True + 0 + + True + + False + + + 1 + 2 + 0 + 1 + + + 0 @@ -474,25 +477,6 @@ False - - - - True - True - Disabled - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - False - False - - diff --git a/plugins/shellexecui/shellexecui.c b/plugins/shellexecui/shellexecui.c index a767e4f7..6662798e 100644 --- a/plugins/shellexecui/shellexecui.c +++ b/plugins/shellexecui/shellexecui.c @@ -37,8 +37,6 @@ static GtkWidget *conf_dlg; static GtkWidget *edit_dlg; static Shx_action_t *current_action; // selection action when edit window is active -static int dirty = 0; - enum { COL_TITLE = 0, COL_META, @@ -47,12 +45,18 @@ enum { static int name_exists(const char *name, Shx_action_t *skip) { - Shx_action_t *action = actions; - while(action) { - if(action != skip && strcmp(action->parent.name, name) == 0) { - return 1; + DB_plugin_t **p = deadbeef->plug_get_list (); + for (int i = 0; p[i]; i++) { + if (!p[i]->get_actions) { + continue; + } + DB_plugin_action_t *action = p[i]->get_actions (NULL); + while(action) { + if(action != (DB_plugin_action_t*)skip && action->name && !strcmp(action->name, name)) { + return 1; + } + action = action->next; } - action = (Shx_action_t*)action->parent.next; } return 0; } @@ -72,9 +76,6 @@ is_empty(const char *name) { void on_save_button_clicked (GtkButton *button, gpointer user_data) { - if(dirty) { - shellexec_plugin->shx_save_actions(actions); - } gtk_widget_destroy(conf_dlg); } @@ -95,10 +96,13 @@ on_add_button_clicked (GtkButton *button, // generate unique command name char name[15] = "new_cmd"; int suffix = 0; - while(name_exists(name, NULL)) { // create a unique name - snprintf(name, 15, "new_cmd%d", suffix); + while(name_exists(name, NULL) && suffix < 1000) { // create a unique name + snprintf(name, sizeof (name), "new_cmd%d", suffix); suffix++; } + if (name_exists (name, NULL)) { + return; + } // Set default values in text fields gtk_entry_set_text( GTK_ENTRY(lookup_widget(edit_dlg, "name_entry")), @@ -173,7 +177,8 @@ on_remove_button_clicked (GtkButton *button, } gtk_list_store_remove(GTK_LIST_STORE(treemodel), &iter); - dirty = 1; + shellexec_plugin->save_actions(actions); + deadbeef->sendmessage (DB_EV_ACTIONSCHANGED, 0, 0, 0); } } @@ -235,19 +240,19 @@ validate_command_edit () { text = gtk_entry_get_text(GTK_ENTRY(lookup_widget(edit_dlg, "name_entry"))); if(is_empty(text) || name_exists(text, current_action)) { - strcat(message, _("Name should be non-empty and unique\n")); + strcat(message, _("ID must be non-empty and unique.\n")); valid = 0; } text = gtk_entry_get_text(GTK_ENTRY(lookup_widget(edit_dlg, "title_entry"))); if(is_empty(text)) { - strcat(message, _("Title should be non-empty\n")); + strcat(message, _("Title must be non-empty.\n")); valid = 0; } text = gtk_entry_get_text(GTK_ENTRY(lookup_widget(edit_dlg, "cmd_entry"))); if(is_empty(text)) { - strcat(message, _("Shell Command should be non-empty\n")); + strcat(message, _("Shell Command must be non-empty.\n")); valid = 0; } @@ -331,8 +336,8 @@ on_edit_ok_button_clicked (GtkButton *button, gpointer user_data) { edit_dlg = NULL; current_action = NULL; - dirty = 1; - //enable_button(conf_dlg, "save_button"); + shellexec_plugin->save_actions(actions); + deadbeef->sendmessage (DB_EV_ACTIONSCHANGED, 0, 0, 0); } static void @@ -350,7 +355,7 @@ init_treeview() { G_TYPE_STRING, //G_TYPE_BOOLEAN, G_TYPE_POINTER); - actions = shellexec_plugin->shx_get_actions(NULL, FALSE); + actions = (Shx_action_t *)shellexec_plugin->misc.plugin.get_actions(NULL); Shx_action_t *action = actions; GtkTreeIter iter; while(action) { @@ -370,11 +375,9 @@ shellexecui_action_callback(DB_plugin_action_t *action, void *user_data) { conf_dlg = create_shellexec_conf_dialog(); gtk_widget_set_size_request (conf_dlg, 400, 400); - dirty = 0; gtk_window_set_transient_for(GTK_WINDOW(conf_dlg), GTK_WINDOW(gtkui_plugin->get_mainwin())); init_treeview(); - //disable_button(conf_dlg, "save_button"); gtk_widget_show(conf_dlg); return 0; } -- cgit v1.2.3