[totem/wip/hadess/subtitle-labels-fixes] main: Re-add support for track with no language



commit 6f57d11c3c28a79e72dcced9146d8ececb1ac1da
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Feb 18 18:03:16 2019 +0100

    main: Re-add support for track with no language
    
    This was what get_label_for_type() did, make sure not to lose that
    support.

 src/test-totem.c |  6 +++---
 src/totem-menu.c | 37 +++++++++++++++++++++++++++----------
 src/totem-menu.h |  4 +++-
 3 files changed, 33 insertions(+), 14 deletions(-)
---
diff --git a/src/test-totem.c b/src/test-totem.c
index a56c10af2..9ff714052 100644
--- a/src/test-totem.c
+++ b/src/test-totem.c
@@ -30,7 +30,7 @@ test_menus_lang_info (void)
        l = g_list_append (l, bvw_lang_info_new ("eng", "Dolby Pro Racing"));
        l = g_list_append (l, bvw_lang_info_new ("fre", "Dolby Amateur 5.1"));
 
-       ret = bvw_lang_info_to_menu_labels (l);
+       ret = bvw_lang_info_to_menu_labels (l, BVW_TRACK_TYPE_AUDIO);
        g_list_free_full (l, (GDestroyNotify) bacon_video_widget_lang_info_free);
 
        g_assert_cmpstr (g_list_nth_data (ret, 0), ==, "English #1");
@@ -44,7 +44,7 @@ test_menus_lang_info (void)
        l = g_list_append (l, bvw_lang_info_new ("eng", "Dolby Amateur 5.1"));
        l = g_list_append (l, bvw_lang_info_new ("fre", "Dolby Amateur 5.1"));
 
-       ret = bvw_lang_info_to_menu_labels (l);
+       ret = bvw_lang_info_to_menu_labels (l, BVW_TRACK_TYPE_AUDIO);
        g_list_free_full (l, (GDestroyNotify) bacon_video_widget_lang_info_free);
 
        g_assert_cmpstr (g_list_nth_data (ret, 0), ==, "English — Dolby Pro Racing");
@@ -58,7 +58,7 @@ test_menus_lang_info (void)
        l = g_list_append (l, bvw_lang_info_new ("spa", "Dolby Amateur 5.1"));
        l = g_list_append (l, bvw_lang_info_new ("fre", "Dolby Amateur 5.1"));
 
-       ret = bvw_lang_info_to_menu_labels (l);
+       ret = bvw_lang_info_to_menu_labels (l, BVW_TRACK_TYPE_AUDIO);
        g_list_free_full (l, (GDestroyNotify) bacon_video_widget_lang_info_free);
 
        g_assert_cmpstr (g_list_nth_data (ret, 0), ==, "English");
diff --git a/src/totem-menu.c b/src/totem-menu.c
index 4570659e7..9cb4f7c43 100644
--- a/src/totem-menu.c
+++ b/src/totem-menu.c
@@ -394,15 +394,32 @@ hash_table_num_instances (GHashTable *ht,
 }
 
 static const char *
-get_language_name_no_und (const char *lang)
-{
-       if (g_str_equal (lang, "und"))
-               return gst_tag_get_language_name ("eng");
-       return gst_tag_get_language_name (lang);
+get_language_name_no_und (const char   *lang,
+                         BvwTrackType  track_type)
+{
+       const char *ret;
+
+       ret =  gst_tag_get_language_name (lang);
+       if (ret != NULL)
+               return ret;
+
+       switch (track_type) {
+       case BVW_TRACK_TYPE_AUDIO:
+               return _("Audio Track");
+               break;
+       case BVW_TRACK_TYPE_SUBTITLE:
+               return _("Subtitle");
+               break;
+       case BVW_TRACK_TYPE_VIDEO:
+               g_assert_not_reached ();
+       }
+
+       return NULL;
 }
 
 GList *
-bvw_lang_info_to_menu_labels (GList *langs)
+bvw_lang_info_to_menu_labels (GList        *langs,
+                             BvwTrackType  track_type)
 {
        GList *l, *ret;
        GHashTable *lang_table, *lang_codec_table, *printed_table;
@@ -452,16 +469,16 @@ bvw_lang_info_to_menu_labels (GList *langs)
                                                     GINT_TO_POINTER (num));
 
                                str = g_strdup_printf ("%s #%d",
-                                                      get_language_name_no_und (info->language),
+                                                      get_language_name_no_und (info->language, track_type),
                                                       num);
                        } else {
                                str = g_strdup_printf ("%s — %s",
-                                                      get_language_name_no_und (info->language),
+                                                      get_language_name_no_und (info->language, track_type),
                                                       info->codec);
                        }
                        g_free (id);
                } else {
-                       str = g_strdup (get_language_name_no_und (info->language));
+                       str = g_strdup (get_language_name_no_und (info->language, track_type));
                }
 
                ret = g_list_prepend (ret, str);
@@ -517,7 +534,7 @@ create_lang_actions (GMenu *menu,
        /* Translators: an entry in the "Languages" menu, used to choose the audio language of a DVD */
        add_lang_action (menu, action, C_("Language", "Auto"), -1);
 
-       ui_list = bvw_lang_info_to_menu_labels (list);
+       ui_list = bvw_lang_info_to_menu_labels (list, is_lang ? BVW_TRACK_TYPE_AUDIO : 
BVW_TRACK_TYPE_SUBTITLE);
 
        for (l = ui_list, i = 0; l != NULL; l = l->next, i++)
                add_lang_action (menu, action, l->data, i);
diff --git a/src/totem-menu.h b/src/totem-menu.h
index bf13159e5..0f165c689 100644
--- a/src/totem-menu.h
+++ b/src/totem-menu.h
@@ -24,6 +24,7 @@
 #define TOTEM_MENU_H
 
 #include "totem.h"
+#include "bacon-video-widget.h"
 
 G_BEGIN_DECLS
 
@@ -34,7 +35,8 @@ void totem_sublang_update (Totem *totem);
 void totem_sublang_exit (Totem *totem);
 
 /* For test use only */
-GList *bvw_lang_info_to_menu_labels (GList *langs);
+GList *bvw_lang_info_to_menu_labels (GList        *langs,
+                                    BvwTrackType  track_type);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]