From 006ec267b2d6372ce547bbfd19df8e5a9bd24886 Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Wed, 5 Feb 2014 21:48:03 +0100 Subject: experimental: added support for DDB:CUSTOM_TITLE metadata, for setting radio station titles new text field in the Add Location dialog automatically use in title formatting for %B and %a --- playlist.c | 28 +++++++++- plugins/gtkui/actionhandlers.c | 38 ++++++++++++- plugins/gtkui/deadbeef.glade | 120 +++++++++++++++++++++++++++++++---------- plugins/gtkui/interface.c | 29 +++++++++- 4 files changed, 183 insertions(+), 32 deletions(-) diff --git a/playlist.c b/playlist.c index 27330ca7..62b97d30 100644 --- a/playlist.c +++ b/playlist.c @@ -2913,9 +2913,22 @@ pl_format_title_int (const char *escape_chars, playItem_t *it, int idx, char *s, } else if (*fmt == 'a') { meta = pl_find_meta_raw (it, "artist"); - if (!meta) { + const char *custom = pl_find_meta_raw (it, "DDB:CUSTOM_TITLE"); + if (!meta && !custom) { meta = "Unknown artist"; } + + if (custom) { + if (!meta) { + meta = custom; + } + else { + int l = strlen (custom) + strlen (meta) + 4; + char *out = alloca (l); + snprintf (out, l, "[%s] %s", custom, meta); + meta = out; + } + } } else if (*fmt == 't') { meta = pl_find_meta_raw (it, "title"); @@ -2963,6 +2976,19 @@ pl_format_title_int (const char *escape_chars, playItem_t *it, int idx, char *s, } } } + + const char *custom = pl_find_meta_raw (it, "DDB:CUSTOM_TITLE"); + if (custom) { + if (!meta) { + meta = custom; + } + else { + int l = strlen (custom) + strlen (meta) + 4; + char *out = alloca (l); + snprintf (out, l, "[%s] %s", custom, meta); + meta = out; + } + } } else if (*fmt == 'C') { meta = pl_find_meta_raw (it, "composer"); diff --git a/plugins/gtkui/actionhandlers.c b/plugins/gtkui/actionhandlers.c index 6e3934e4..b032ddb8 100644 --- a/plugins/gtkui/actionhandlers.c +++ b/plugins/gtkui/actionhandlers.c @@ -390,9 +390,38 @@ action_hide_mainwin_handler (struct DB_plugin_action_s *action, int ctx) { return 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 (); +} + + gboolean action_add_location_handler_cb (void *user_data) { GtkWidget *dlg = create_addlocationdlg (); + + 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); + } + + g_signal_connect ((gpointer) sct, "toggled", + G_CALLBACK (on_toggle_set_custom_title), + dlg); + gtk_dialog_set_default_response (GTK_DIALOG (dlg), GTK_RESPONSE_OK); int res = gtk_dialog_run (GTK_DIALOG (dlg)); if (res == GTK_RESPONSE_OK) { @@ -402,7 +431,14 @@ action_add_location_handler_cb (void *user_data) { if (text) { ddb_playlist_t *plt = deadbeef->plt_get_curr (); if (!deadbeef->plt_add_files_begin (plt, 0)) { - deadbeef->plt_add_file2 (0, plt, text, NULL, NULL); + 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 (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))); + } + if (tail) { + deadbeef->pl_item_unref (tail); + } deadbeef->plt_add_files_end (plt, 0); playlist_refresh (); } diff --git a/plugins/gtkui/deadbeef.glade b/plugins/gtkui/deadbeef.glade index b3782497..98f85ffc 100644 --- a/plugins/gtkui/deadbeef.glade +++ b/plugins/gtkui/deadbeef.glade @@ -6417,49 +6417,113 @@ if you don't press Apply. - + 12 True False 8 - + True - URL: - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 + False + 8 + + + + True + URL: + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + 297 + True + True + True + True + 0 + + True + + True + + + 0 + True + True + + 0 - False - False + True + True - - 297 + True - True - True - True - 0 - - True - - 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 diff --git a/plugins/gtkui/interface.c b/plugins/gtkui/interface.c index b08daf45..b712cba2 100644 --- a/plugins/gtkui/interface.c +++ b/plugins/gtkui/interface.c @@ -3272,9 +3272,13 @@ create_addlocationdlg (void) { GtkWidget *addlocationdlg; GtkWidget *dialog_vbox4; + GtkWidget *vbox45; GtkWidget *hbox34; GtkWidget *label41; GtkWidget *addlocation_entry; + GtkWidget *hbox122; + GtkWidget *set_custom_title; + GtkWidget *custom_title; GtkWidget *addlocation_actionarea; GtkWidget *cancelbutton3; GtkWidget *alignment18; @@ -3294,10 +3298,14 @@ create_addlocationdlg (void) dialog_vbox4 = gtk_dialog_get_content_area (GTK_DIALOG (addlocationdlg)); gtk_widget_show (dialog_vbox4); + vbox45 = gtk_vbox_new (FALSE, 8); + gtk_widget_show (vbox45); + gtk_box_pack_start (GTK_BOX (dialog_vbox4), vbox45, TRUE, TRUE, 0); + gtk_container_set_border_width (GTK_CONTAINER (vbox45), 12); + hbox34 = gtk_hbox_new (FALSE, 8); gtk_widget_show (hbox34); - gtk_box_pack_start (GTK_BOX (dialog_vbox4), hbox34, TRUE, TRUE, 0); - gtk_container_set_border_width (GTK_CONTAINER (hbox34), 12); + gtk_box_pack_start (GTK_BOX (vbox45), hbox34, TRUE, TRUE, 0); label41 = gtk_label_new (_("URL:")); gtk_widget_show (label41); @@ -3310,6 +3318,19 @@ create_addlocationdlg (void) gtk_entry_set_invisible_char (GTK_ENTRY (addlocation_entry), 8226); gtk_entry_set_activates_default (GTK_ENTRY (addlocation_entry), TRUE); + hbox122 = gtk_hbox_new (FALSE, 8); + gtk_widget_show (hbox122); + gtk_box_pack_start (GTK_BOX (vbox45), hbox122, TRUE, TRUE, 0); + + set_custom_title = gtk_check_button_new_with_mnemonic (_("Set custom title")); + gtk_widget_show (set_custom_title); + gtk_box_pack_start (GTK_BOX (hbox122), set_custom_title, FALSE, FALSE, 0); + + custom_title = gtk_entry_new (); + gtk_widget_show (custom_title); + gtk_box_pack_start (GTK_BOX (hbox122), custom_title, TRUE, TRUE, 0); + gtk_entry_set_invisible_char (GTK_ENTRY (custom_title), 8226); + addlocation_actionarea = gtk_dialog_get_action_area (GTK_DIALOG (addlocationdlg)); gtk_widget_show (addlocation_actionarea); gtk_button_box_set_layout (GTK_BUTTON_BOX (addlocation_actionarea), GTK_BUTTONBOX_END); @@ -3359,9 +3380,13 @@ create_addlocationdlg (void) /* Store pointers to all widgets, for use by lookup_widget(). */ GLADE_HOOKUP_OBJECT_NO_REF (addlocationdlg, addlocationdlg, "addlocationdlg"); GLADE_HOOKUP_OBJECT_NO_REF (addlocationdlg, dialog_vbox4, "dialog_vbox4"); + GLADE_HOOKUP_OBJECT (addlocationdlg, vbox45, "vbox45"); GLADE_HOOKUP_OBJECT (addlocationdlg, hbox34, "hbox34"); GLADE_HOOKUP_OBJECT (addlocationdlg, label41, "label41"); GLADE_HOOKUP_OBJECT (addlocationdlg, addlocation_entry, "addlocation_entry"); + GLADE_HOOKUP_OBJECT (addlocationdlg, hbox122, "hbox122"); + GLADE_HOOKUP_OBJECT (addlocationdlg, set_custom_title, "set_custom_title"); + GLADE_HOOKUP_OBJECT (addlocationdlg, custom_title, "custom_title"); GLADE_HOOKUP_OBJECT_NO_REF (addlocationdlg, addlocation_actionarea, "addlocation_actionarea"); GLADE_HOOKUP_OBJECT (addlocationdlg, cancelbutton3, "cancelbutton3"); GLADE_HOOKUP_OBJECT (addlocationdlg, alignment18, "alignment18"); -- cgit v1.2.3