From 7ea43f8102d7fcc49425a75092ece929b6001a1a Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Sun, 13 Feb 2022 12:06:16 +0100 Subject: menu: Show sub/audio tracks titles if available Closes: #21 --- src/test-totem.c | 27 +++++++++++++++++++++++++++ src/totem-menu.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/src/test-totem.c b/src/test-totem.c index de4520a22..2c580924c 100644 --- a/src/test-totem.c +++ b/src/test-totem.c @@ -90,6 +90,33 @@ test_menus_lang_info (void) g_assert_cmpstr (nth_label (ret, 1), ==, "Spanish; Castilian"); g_assert_cmpstr (nth_label (ret, 2), ==, "French"); g_list_free_full (ret, g_free); + + /* Tracks with titles */ + l = NULL; + l = g_list_append (l, bvw_lang_info_new ("Closed Captions", "eng", NULL)); + l = g_list_append (l, bvw_lang_info_new ("Closed Captions", "fre", NULL)); + l = g_list_append (l, bvw_lang_info_new ("SDH", "eng", NULL)); + l = g_list_append (l, bvw_lang_info_new ("SDH", "fre", NULL)); + + ret = bvw_lang_info_to_menu_labels (l, BVW_TRACK_TYPE_SUBTITLE); + g_list_free_full (l, (GDestroyNotify) bacon_video_widget_lang_info_free); + + g_assert_cmpstr (nth_label (ret, 0), ==, "Closed Captions (English)"); + g_assert_cmpstr (nth_label (ret, 1), ==, "Closed Captions (French)"); + g_assert_cmpstr (nth_label (ret, 2), ==, "SDH (English)"); + g_assert_cmpstr (nth_label (ret, 3), ==, "SDH (French)"); + g_list_free_full (ret, g_free); + + l = NULL; + l = g_list_append (l, bvw_lang_info_new ("Closed Captions", "eng", NULL)); + l = g_list_append (l, bvw_lang_info_new ("Closed Captions", "eng", NULL)); + + ret = bvw_lang_info_to_menu_labels (l, BVW_TRACK_TYPE_SUBTITLE); + g_list_free_full (l, (GDestroyNotify) bacon_video_widget_lang_info_free); + + g_assert_cmpstr (nth_label (ret, 0), ==, "Closed Captions (English) #1"); + g_assert_cmpstr (nth_label (ret, 1), ==, "Closed Captions (English) #2"); + g_list_free_full (ret, g_free); } static void diff --git a/src/totem-menu.c b/src/totem-menu.c index cc9f27057..da1a82229 100644 --- a/src/totem-menu.c +++ b/src/totem-menu.c @@ -381,6 +381,14 @@ bvw_lang_info_to_id (BvwLangInfo *info) return g_strdup_printf ("%s-%s", info->language, info->codec); } +static char * +bvw_lang_info_to_id2 (BvwLangInfo *info) +{ + if (!info->title) + return NULL; + return g_strdup_printf ("%s-%s", info->title, info->language); +} + static int hash_table_num_instances (GHashTable *ht, const char *key) @@ -461,10 +469,11 @@ bvw_lang_info_to_menu_labels (GList *langs, BvwTrackType track_type) { GList *l, *ret; - GHashTable *lang_table, *lang_codec_table, *printed_table; + GHashTable *lang_table, *lang_codec_table, *title_lang_table, *printed_table; lang_table = g_hash_table_new (g_str_hash, g_str_equal); lang_codec_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + title_lang_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); /* Populate the hash tables */ for (l = langs; l != NULL; l = l->next) { @@ -487,6 +496,15 @@ bvw_lang_info_to_menu_labels (GList *langs, g_hash_table_insert (lang_codec_table, id, GINT_TO_POINTER (num)); + + id = bvw_lang_info_to_id2 (info); + if (id) { + num = hash_table_num_instances (title_lang_table, id); + num++; + g_hash_table_insert (title_lang_table, + id, + GINT_TO_POINTER (num)); + } } ret = NULL; @@ -503,6 +521,32 @@ bvw_lang_info_to_menu_labels (GList *langs, continue; } + if (info->title) { + char *id; + + id = bvw_lang_info_to_id2 (info); + num = hash_table_num_instances (title_lang_table, id); + if (num > 1) { + num = hash_table_num_instances (printed_table, info->language); + num++; + g_hash_table_insert (printed_table, + (gpointer) info->language, + GINT_TO_POINTER (num)); + + str = g_strdup_printf ("%s (%s) #%d", + info->title, + get_language_name_no_und (info->language, track_type), + num); + } else { + str = g_strdup_printf ("%s (%s)", + info->title, + get_language_name_no_und (info->language, track_type)); + } + g_free (id); + ret = g_list_prepend (ret, create_menu_item (str, info->id)); + continue; + } + num = hash_table_num_instances (lang_table, info->language); g_assert (num >= 1); if (num > 1) { @@ -535,6 +579,7 @@ bvw_lang_info_to_menu_labels (GList *langs, g_hash_table_destroy (printed_table); g_hash_table_destroy (lang_codec_table); + g_hash_table_destroy (title_lang_table); g_hash_table_destroy (lang_table); return g_list_reverse (ret); -- cgit v1.2.1