diff options
author | waker <wakeroid@gmail.com> | 2012-04-24 19:40:56 +0200 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2012-04-24 19:40:56 +0200 |
commit | 6498b5187f44a48571aac268c9c377b7c3e6af7b (patch) | |
tree | f37b114e098b4bf63de93f5664860762f99d9680 /plugins/shellexecui | |
parent | 15bd1af9f7c6bdad62b9610b1303b281f252b367 (diff) |
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
Diffstat (limited to 'plugins/shellexecui')
-rw-r--r-- | plugins/shellexecui/interface.c | 31 | ||||
-rw-r--r-- | plugins/shellexecui/shellexec.glade | 68 | ||||
-rw-r--r-- | plugins/shellexecui/shellexecui.c | 45 |
3 files changed, 64 insertions, 80 deletions
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 @@ <child> <widget class="GtkLabel" id="cmd_label"> <property name="visible">True</property> - <property name="label" translatable="yes">Shell Command:</property> + <property name="label" translatable="yes">Command:</property> <property name="use_underline">False</property> <property name="use_markup">False</property> <property name="justify">GTK_JUSTIFY_LEFT</property> @@ -283,29 +283,9 @@ </child> <child> - <widget class="GtkEntry" id="name_entry"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="editable">True</property> - <property name="visibility">True</property> - <property name="max_length">0</property> - <property name="text" translatable="yes"></property> - <property name="has_frame">True</property> - <property name="invisible_char">•</property> - <property name="activates_default">False</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">0</property> - <property name="bottom_attach">1</property> - <property name="y_options"></property> - </packing> - </child> - - <child> <widget class="GtkEntry" id="cmd_entry"> <property name="visible">True</property> + <property name="tooltip" translatable="yes">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</property> <property name="can_focus">True</property> <property name="editable">True</property> <property name="visibility">True</property> @@ -327,7 +307,7 @@ <child> <widget class="GtkLabel" id="name_label"> <property name="visible">True</property> - <property name="label" translatable="yes">Name:</property> + <property name="label" translatable="yes">ID:</property> <property name="use_underline">False</property> <property name="use_markup">False</property> <property name="justify">GTK_JUSTIFY_LEFT</property> @@ -355,6 +335,7 @@ <child> <widget class="GtkEntry" id="title_entry"> <property name="visible">True</property> + <property name="tooltip" translatable="yes">Free-form name, for example "My Shell Command"</property> <property name="can_focus">True</property> <property name="editable">True</property> <property name="visibility">True</property> @@ -372,6 +353,28 @@ <property name="y_options"></property> </packing> </child> + + <child> + <widget class="GtkEntry" id="name_entry"> + <property name="visible">True</property> + <property name="tooltip" translatable="yes">Command ID, normally it should be something short, for example "youtube_open". It must be unique.</property> + <property name="can_focus">True</property> + <property name="editable">True</property> + <property name="visibility">True</property> + <property name="max_length">0</property> + <property name="text" translatable="yes"></property> + <property name="has_frame">True</property> + <property name="invisible_char">•</property> + <property name="activates_default">False</property> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">0</property> + <property name="bottom_attach">1</property> + <property name="y_options"></property> + </packing> + </child> </widget> <packing> <property name="padding">0</property> @@ -474,25 +477,6 @@ <property name="fill">False</property> </packing> </child> - - <child> - <widget class="GtkCheckButton" id="disabled_check"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">Disabled</property> - <property name="use_underline">True</property> - <property name="relief">GTK_RELIEF_NORMAL</property> - <property name="focus_on_click">True</property> - <property name="active">False</property> - <property name="inconsistent">False</property> - <property name="draw_indicator">True</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">False</property> - </packing> - </child> </widget> </child> </widget> 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; } |