From d390a25a61f2f9ba17938079a704f38a60e4f149 Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Tue, 17 Jun 2014 21:47:03 +0200 Subject: gtkui: better custom title configuration using context menu --- plugins/gtkui/actionhandlers.c | 2 +- plugins/gtkui/deadbeef.glade | 117 +++++++++++++++++++++++++++++++++++++++++ plugins/gtkui/interface.c | 61 +++++++++++++++++++++ plugins/gtkui/interface.h | 1 + plugins/gtkui/plcommon.c | 98 ++++++++++++++++++++++++++++++---- 5 files changed, 269 insertions(+), 10 deletions(-) (limited to 'plugins') diff --git a/plugins/gtkui/actionhandlers.c b/plugins/gtkui/actionhandlers.c index f9fa9ecc..ad4bf04c 100644 --- a/plugins/gtkui/actionhandlers.c +++ b/plugins/gtkui/actionhandlers.c @@ -434,7 +434,7 @@ action_add_location_handler_cb (void *user_data) { DB_playItem_t *tail = deadbeef->plt_get_last (plt, PL_MAIN); DB_playItem_t *it = deadbeef->plt_insert_file2 (0, plt, tail, text, NULL, NULL, NULL); if (it && deadbeef->conf_get_int ("gtkui.location_set_custom_title", 0)) { - deadbeef->pl_replace_meta (it, "DDB:CUSTOM_TITLE", gtk_entry_get_text (GTK_ENTRY (ct))); + deadbeef->pl_replace_meta (it, ":CUSTOM_TITLE", gtk_entry_get_text (GTK_ENTRY (ct))); } if (tail) { deadbeef->pl_item_unref (tail); diff --git a/plugins/gtkui/deadbeef.glade b/plugins/gtkui/deadbeef.glade index f4bb6c8e..fc2fefbb 100644 --- a/plugins/gtkui/deadbeef.glade +++ b/plugins/gtkui/deadbeef.glade @@ -8724,4 +8724,121 @@ Descending + + True + Set Custom Title + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + True + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + False + True + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 12 + True + False + 8 + + + + True + True + Set custom title + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 0 + False + False + + + + + + True + True + True + True + 0 + + True + + False + + + 0 + True + True + + + + + 0 + True + True + + + + + + diff --git a/plugins/gtkui/interface.c b/plugins/gtkui/interface.c index 3f70035a..7f5ce942 100644 --- a/plugins/gtkui/interface.c +++ b/plugins/gtkui/interface.c @@ -4397,3 +4397,64 @@ create_select_action (void) return select_action; } +GtkWidget* +create_setcustomtitledlg (void) +{ + GtkWidget *setcustomtitledlg; + GtkWidget *dialog_vbox16; + GtkWidget *hbox123; + GtkWidget *set_custom_title; + GtkWidget *custom_title; + GtkWidget *dialog_action_area15; + GtkWidget *cancelbutton11; + GtkWidget *okbutton11; + + setcustomtitledlg = gtk_dialog_new (); + gtk_window_set_title (GTK_WINDOW (setcustomtitledlg), _("Set Custom Title")); + gtk_window_set_modal (GTK_WINDOW (setcustomtitledlg), TRUE); + gtk_window_set_type_hint (GTK_WINDOW (setcustomtitledlg), GDK_WINDOW_TYPE_HINT_DIALOG); + + dialog_vbox16 = gtk_dialog_get_content_area (GTK_DIALOG (setcustomtitledlg)); + gtk_widget_show (dialog_vbox16); + + hbox123 = gtk_hbox_new (FALSE, 8); + gtk_widget_show (hbox123); + gtk_box_pack_start (GTK_BOX (dialog_vbox16), hbox123, TRUE, TRUE, 0); + gtk_container_set_border_width (GTK_CONTAINER (hbox123), 12); + + set_custom_title = gtk_check_button_new_with_mnemonic (_("Set custom title")); + gtk_widget_show (set_custom_title); + gtk_box_pack_start (GTK_BOX (hbox123), set_custom_title, FALSE, FALSE, 0); + + custom_title = gtk_entry_new (); + gtk_widget_show (custom_title); + gtk_box_pack_start (GTK_BOX (hbox123), custom_title, TRUE, TRUE, 0); + gtk_entry_set_invisible_char (GTK_ENTRY (custom_title), 8226); + + dialog_action_area15 = gtk_dialog_get_action_area (GTK_DIALOG (setcustomtitledlg)); + gtk_widget_show (dialog_action_area15); + gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area15), GTK_BUTTONBOX_END); + + cancelbutton11 = gtk_button_new_from_stock ("gtk-cancel"); + gtk_widget_show (cancelbutton11); + gtk_dialog_add_action_widget (GTK_DIALOG (setcustomtitledlg), cancelbutton11, GTK_RESPONSE_CANCEL); + gtk_widget_set_can_default(cancelbutton11, TRUE); + + okbutton11 = gtk_button_new_from_stock ("gtk-ok"); + gtk_widget_show (okbutton11); + gtk_dialog_add_action_widget (GTK_DIALOG (setcustomtitledlg), okbutton11, GTK_RESPONSE_OK); + gtk_widget_set_can_default(okbutton11, TRUE); + + /* Store pointers to all widgets, for use by lookup_widget(). */ + GLADE_HOOKUP_OBJECT_NO_REF (setcustomtitledlg, setcustomtitledlg, "setcustomtitledlg"); + GLADE_HOOKUP_OBJECT_NO_REF (setcustomtitledlg, dialog_vbox16, "dialog_vbox16"); + GLADE_HOOKUP_OBJECT (setcustomtitledlg, hbox123, "hbox123"); + GLADE_HOOKUP_OBJECT (setcustomtitledlg, set_custom_title, "set_custom_title"); + GLADE_HOOKUP_OBJECT (setcustomtitledlg, custom_title, "custom_title"); + GLADE_HOOKUP_OBJECT_NO_REF (setcustomtitledlg, dialog_action_area15, "dialog_action_area15"); + GLADE_HOOKUP_OBJECT (setcustomtitledlg, cancelbutton11, "cancelbutton11"); + GLADE_HOOKUP_OBJECT (setcustomtitledlg, okbutton11, "okbutton11"); + + return setcustomtitledlg; +} + diff --git a/plugins/gtkui/interface.h b/plugins/gtkui/interface.h index 9321b1d1..dc9ead7c 100644 --- a/plugins/gtkui/interface.h +++ b/plugins/gtkui/interface.h @@ -20,3 +20,4 @@ GtkWidget* create_ctmappingdlg (void); GtkWidget* create_ctmappingeditdlg (void); GtkWidget* create_button_properties (void); GtkWidget* create_select_action (void); +GtkWidget* create_setcustomtitledlg (void); diff --git a/plugins/gtkui/plcommon.c b/plugins/gtkui/plcommon.c index 2347540b..a6077929 100644 --- a/plugins/gtkui/plcommon.c +++ b/plugins/gtkui/plcommon.c @@ -32,6 +32,7 @@ #include "actions.h" #include "search.h" #include "actionhandlers.h" +#include "../../strdupa.h" #define min(x,y) ((x)<(y)?(x):(y)) //#define trace(...) { fprintf(stderr, __VA_ARGS__); } @@ -466,6 +467,70 @@ on_remove2_activate (GtkMenuItem *menuitem, deadbeef->sendmessage (DB_EV_PLAYLISTCHANGED, 0, 0, 0); } +static void +on_toggle_set_custom_title (GtkToggleButton *togglebutton, gpointer user_data) { + gboolean active = gtk_toggle_button_get_active (togglebutton); + deadbeef->conf_set_int ("gtkui.location_set_custom_title", active); + + GtkWidget *ct = lookup_widget (GTK_WIDGET (user_data), "custom_title"); + gtk_widget_set_sensitive (ct, active); + + deadbeef->conf_save (); +} + +void +on_set_custom_title_activate (GtkMenuItem *menuitem, gpointer user_data) +{ + DdbListview *lv = user_data; + int idx = lv->binding->cursor (); + if (idx < 0) { + return; + } + DdbListviewIter it = lv->binding->get_for_idx (idx); + if (!it) { + return; + } + + GtkWidget *dlg = create_setcustomtitledlg (); + GtkWidget *sct = lookup_widget (dlg, "set_custom_title"); + GtkWidget *ct = lookup_widget (dlg, "custom_title"); + if (deadbeef->conf_get_int ("gtkui.location_set_custom_title", 0)) { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sct), TRUE); + gtk_widget_set_sensitive (ct, TRUE); + } + else { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sct), FALSE); + gtk_widget_set_sensitive (ct, FALSE); + } + deadbeef->pl_lock (); + const char *custom_title = deadbeef->pl_find_meta ((DB_playItem_t *)it, ":CUSTOM_TITLE"); + if (custom_title) { + custom_title = strdupa (custom_title); + } + else { + custom_title = ""; + } + deadbeef->pl_unlock (); + + g_signal_connect ((gpointer) sct, "toggled", + G_CALLBACK (on_toggle_set_custom_title), + dlg); + gtk_entry_set_text (GTK_ENTRY (ct), custom_title); + + gtk_dialog_set_default_response (GTK_DIALOG (dlg), GTK_RESPONSE_OK); + gint response = gtk_dialog_run (GTK_DIALOG (dlg)); + if (response == GTK_RESPONSE_OK) { + if (it && deadbeef->conf_get_int ("gtkui.location_set_custom_title", 0)) { + deadbeef->pl_replace_meta ((DB_playItem_t *)it, ":CUSTOM_TITLE", gtk_entry_get_text (GTK_ENTRY (ct))); + } + else { + deadbeef->pl_delete_meta ((DB_playItem_t *)it, ":CUSTOM_TITLE"); + } + } + gtk_widget_destroy (dlg); + lv->binding->unref (it); +} + void on_remove_from_disk_activate (GtkMenuItem *menuitem, gpointer user_data) @@ -553,12 +618,13 @@ list_context_menu (DdbListview *listview, DdbListviewIter it, int idx) { GtkWidget *playlist_menu; GtkWidget *add_to_playback_queue1; GtkWidget *remove_from_playback_queue1; - GtkWidget *separator9; + GtkWidget *separator; GtkWidget *remove2; GtkWidget *remove_from_disk; GtkWidget *separator8; GtkWidget *properties1; GtkWidget *reload_metadata; + GtkWidget *set_custom_title; playlist_menu = gtk_menu_new (); add_to_playback_queue1 = gtk_menu_item_new_with_mnemonic (_("Add To Playback Queue")); @@ -579,10 +645,10 @@ list_context_menu (DdbListview *listview, DdbListviewIter it, int idx) { gtk_container_add (GTK_CONTAINER (playlist_menu), reload_metadata); g_object_set_data (G_OBJECT (reload_metadata), "ps", listview); - separator9 = gtk_separator_menu_item_new (); - gtk_widget_show (separator9); - gtk_container_add (GTK_CONTAINER (playlist_menu), separator9); - gtk_widget_set_sensitive (separator9, FALSE); + separator = gtk_separator_menu_item_new (); + gtk_widget_show (separator); + gtk_container_add (GTK_CONTAINER (playlist_menu), separator); + gtk_widget_set_sensitive (separator, FALSE); remove2 = gtk_menu_item_new_with_mnemonic (_("Remove")); gtk_widget_show (remove2); @@ -598,10 +664,10 @@ list_context_menu (DdbListview *listview, DdbListviewIter it, int idx) { g_object_set_data (G_OBJECT (remove_from_disk), "ps", listview); } - separator8 = gtk_separator_menu_item_new (); - gtk_widget_show (separator8); - gtk_container_add (GTK_CONTAINER (playlist_menu), separator8); - gtk_widget_set_sensitive (separator8, FALSE); + separator = gtk_separator_menu_item_new (); + gtk_widget_show (separator); + gtk_container_add (GTK_CONTAINER (playlist_menu), separator); + gtk_widget_set_sensitive (separator, FALSE); int selected_count = 0; DB_playItem_t *pit = deadbeef->pl_get_first (PL_MAIN); @@ -729,6 +795,17 @@ list_context_menu (DdbListview *listview, DdbListviewIter it, int idx) { gtk_widget_set_sensitive (separator8, FALSE); } + set_custom_title = gtk_menu_item_new_with_mnemonic (_("Set Custom Title")); + gtk_widget_show (set_custom_title); + gtk_container_add (GTK_CONTAINER (playlist_menu), set_custom_title); + if (selected_count != 1) { + gtk_widget_set_sensitive (GTK_WIDGET (set_custom_title), FALSE); + } + + separator = gtk_separator_menu_item_new (); + gtk_widget_show (separator); + gtk_container_add (GTK_CONTAINER (playlist_menu), separator); + gtk_widget_set_sensitive (separator, FALSE); properties1 = gtk_menu_item_new_with_mnemonic (_("Track Properties")); gtk_widget_show (properties1); @@ -752,6 +829,9 @@ list_context_menu (DdbListview *listview, DdbListviewIter it, int idx) { G_CALLBACK (on_remove_from_disk_activate), NULL); } + g_signal_connect ((gpointer) set_custom_title, "activate", + G_CALLBACK (on_set_custom_title_activate), + listview); g_signal_connect ((gpointer) properties1, "activate", G_CALLBACK (main_properties_activate), NULL); -- cgit v1.2.3