[totem/wip/hadess/disable-languages] main: Disable the Languages menu with one audio track



commit ea68d90e3c8ee8c016d65b8f1440178ec6b1c066
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Feb 21 22:11:28 2019 +0100

    main: Disable the Languages menu with one audio track
    
    Disable the languages menu if there's just a single audio track. This is
    slightly cumbersome as we need to go and find the widgets themselves to
    disable them, as there's no actions related to the menus, so nothing we
    can disable by hand.
    
    Closes: #102

 src/totem-menu.c    | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/totem-menu.h    |  1 +
 src/totem-object.c  |  1 +
 src/totem-private.h |  2 ++
 4 files changed, 64 insertions(+)
---
diff --git a/src/totem-menu.c b/src/totem-menu.c
index 028ec495b..3dca97da0 100644
--- a/src/totem-menu.c
+++ b/src/totem-menu.c
@@ -590,6 +590,9 @@ totem_languages_update (Totem *totem, GList *list)
                create_lang_actions (menu, "app.set-language", list, BVW_TRACK_TYPE_AUDIO);
        }
 
+       gtk_widget_set_sensitive (totem->fs_languages_submenu, list != NULL);
+       gtk_widget_set_sensitive (totem->languages_submenu, list != NULL);
+
        action = g_action_map_lookup_action (G_ACTION_MAP (totem), "set-language");
        totem->updating_menu = TRUE;
        current = bacon_video_widget_get_language (totem->bvw);
@@ -645,6 +648,63 @@ totem_sublang_update (Totem *totem)
        }
 }
 
+typedef struct {
+       GtkWidget *widget;
+       char *label;
+} WidgetRet;
+
+static void
+foreach_child (GtkWidget *widget,
+              gpointer   data)
+{
+       WidgetRet *ret = data;
+
+       if (ret->widget != NULL)
+               return;
+
+       if (GTK_IS_MODEL_BUTTON (widget)) {
+               char *text;
+
+               g_object_get (G_OBJECT (widget), "text", &text, NULL);
+               if (g_strcmp0 (text, ret->label) == 0)
+                       ret->widget = widget;
+               g_free (text);
+               if (ret->widget != NULL)
+                       return;
+       }
+
+       if (GTK_IS_CONTAINER (widget))
+               gtk_container_foreach (GTK_CONTAINER (widget), foreach_child, data);
+
+}
+
+static GtkWidget *
+get_language_menu_item (GtkMenuButton *button)
+{
+       GtkPopover *popover;
+       WidgetRet ret;
+       char **s;
+
+       popover = gtk_menu_button_get_popover (button);
+       ret.widget = NULL;
+       s = g_strsplit (_("_Languages"), "_", -1);
+       ret.label = g_strjoinv ("", s);
+       g_strfreev (s);
+       gtk_container_foreach (GTK_CONTAINER (popover), foreach_child, (gpointer) &ret);
+       g_free (ret.label);
+       return ret.widget;
+}
+
+void
+totem_sublang_setup (Totem *totem)
+{
+       totem->fs_languages_submenu = get_language_menu_item (GTK_MENU_BUTTON 
(totem->fullscreen_gear_button));
+       totem->languages_submenu = get_language_menu_item (GTK_MENU_BUTTON (totem->gear_button));
+
+       gtk_widget_set_sensitive (totem->fs_languages_submenu, FALSE);
+       gtk_widget_set_sensitive (totem->languages_submenu, FALSE);
+}
+
 void
 totem_sublang_exit (Totem *totem)
 {
diff --git a/src/totem-menu.h b/src/totem-menu.h
index 0f165c689..a32f2bb4a 100644
--- a/src/totem-menu.h
+++ b/src/totem-menu.h
@@ -31,6 +31,7 @@ G_BEGIN_DECLS
 void totem_app_menu_setup (Totem *totem);
 void totem_app_actions_setup (Totem *totem);
 
+void totem_sublang_setup (Totem *totem);
 void totem_sublang_update (Totem *totem);
 void totem_sublang_exit (Totem *totem);
 
diff --git a/src/totem-object.c b/src/totem-object.c
index 5152fad8b..7d7116237 100644
--- a/src/totem-object.c
+++ b/src/totem-object.c
@@ -210,6 +210,7 @@ totem_object_app_activate (GApplication *app)
        totem->pause_start = optionstate.pause;
 
        totem_callback_connect (totem);
+       totem_sublang_setup (totem);
 
        gtk_widget_grab_focus (GTK_WIDGET (totem->bvw));
 
diff --git a/src/totem-private.h b/src/totem-private.h
index 8e228b166..a072ff237 100644
--- a/src/totem-private.h
+++ b/src/totem-private.h
@@ -110,6 +110,8 @@ struct _TotemObject {
        gboolean updating_menu;
        GList *subtitles_list;
        GList *languages_list;
+       GtkWidget *languages_submenu;
+       GtkWidget *fs_languages_submenu;
 
        /* controls management */
        ControlsVisibility controls_visibility;


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