From 684dd62ef6674c75d8059c048098c817e766b192 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 21 May 2015 21:46:45 +0200 Subject: [PATCH] Add a traditional menubar Some desktops prefer a traditional menubar over an app menu. GtkApplication can detect this and loads menus from different resources depending on the environment. Thus, move the exisiting menus into resources instead of manually loading them from totem's main ui file and add a traditional menubar (contributed by Tim Lunn ). Only show the gear menu when not showing the menubar. https://bugzilla.gnome.org/show_bug.cgi?id=749695 Conflicts: src/totem-object.c --- data/totem.ui | 157 ------------------------------------------- src/Makefile.am | 8 ++- src/grilo.gresource.xml | 5 ++ src/menus-appmenu.ui | 105 +++++++++++++++++++++++++++++ src/menus-common.ui | 57 ++++++++++++++++ src/menus-traditional.ui | 171 +++++++++++++++++++++++++++++++++++++++++++++++ src/totem-menu.c | 4 -- src/totem-object.c | 100 ++++++++++++++------------- 8 files changed, 397 insertions(+), 210 deletions(-) create mode 100644 src/menus-appmenu.ui create mode 100644 src/menus-common.ui create mode 100644 src/menus-traditional.ui diff --git a/data/totem.ui b/data/totem.ui index 090ff93..8ccd94b 100644 --- a/data/totem.ui +++ b/data/totem.ui @@ -4,163 +4,6 @@ - -
- - Prefere_nces - app.preferences - -
-
-
- - _Help - app.help - F1 - - - _Quit - app.quit - <Ctrl>Q - -
-
- - -
- - Add _Local Video… - app.open - <Ctrl>O - - - Add _Web Video… - app.open-location - <Ctrl>L - -
-
- - -
-
-
-
-
-
-
-
- - _Aspect Ratio -
- - Auto - app.aspect-ratio - 0 - - - Square - app.aspect-ratio - 1 - - - 4∶3 (TV) - app.aspect-ratio - 2 - - - 16∶9 (Widescreen) - app.aspect-ratio - 3 - - - 2.11∶1 (DVB) - app.aspect-ratio - 4 - -
-
- - Zoom In - app.zoom - -
- - Switch An_gles - app.next-angle - <Ctrl>G - -
-
- - _Languages -
- - - S_ubtitles -
- - _Select Text Subtitles… - app.select-subtitle - -
-
-
- -
-
-
-
-
- - _Eject - app.eject - <Ctrl>E - action-disabled - -
-
- - -
- - _Repeat - app.repeat - -
-
- - _DVD Menu - app.dvd-root-menu - <Ctrl>M - action-disabled - - - _Title Menu - app.dvd-title-menu - action-disabled - - - A_udio Menu - app.dvd-audio-menu - action-disabled - - - _Angle Menu - app.dvd-angle-menu - action-disabled - - - _Chapter Menu - app.dvd-chapter-menu - action-disabled - -
-
-
-
-
- 0 0 diff --git a/src/Makefile.am b/src/Makefile.am index 54598cf..9b82b49 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -53,7 +53,13 @@ libtotem_player_la_CFLAGS = \ # Totem main library (used for main player; separate to allow gtk-doc to be used) BUILT_SOURCES = griloresources.h griloresources.c -EXTRA_DIST = grilo.gresource.xml totemmaintoolbar.ui totemselectiontoolbar.ui grilo.ui totem-grilo.conf +EXTRA_DIST = grilo.gresource.xml \ + totemmaintoolbar.ui \ + totemselectiontoolbar.ui \ + grilo.ui totem-grilo.conf \ + menus-appmenu.ui \ + menus-traditional.ui \ + menus-common.ui griloresources.h: grilo.gresource.xml $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) $(srcdir)/grilo.gresource.xml \ diff --git a/src/grilo.gresource.xml b/src/grilo.gresource.xml index 6ff4b33..3dcbb7e 100644 --- a/src/grilo.gresource.xml +++ b/src/grilo.gresource.xml @@ -6,4 +6,9 @@ grilo.ui totem-grilo.conf + + menus-appmenu.ui + menus-traditional.ui + menus-common.ui + diff --git a/src/menus-appmenu.ui b/src/menus-appmenu.ui new file mode 100644 index 0000000..2140e7b --- /dev/null +++ b/src/menus-appmenu.ui @@ -0,0 +1,105 @@ + + + +
+ + Prefere_nces + app.preferences + +
+
+
+ + _Help + app.help + F1 + + + _Quit + app.quit + <Ctrl>Q + +
+
+ + +
+
+
+
+
+
+
+
+ + _Aspect Ratio +
+ + Auto + app.aspect-ratio + 0 + + + Square + app.aspect-ratio + 1 + + + 4∶3 (TV) + app.aspect-ratio + 2 + + + 16∶9 (Widescreen) + app.aspect-ratio + 3 + + + 2.11∶1 (DVB) + app.aspect-ratio + 4 + +
+
+ + Zoom In + app.zoom + +
+ + Switch An_gles + app.next-angle + <Ctrl>G + +
+
+ + _Languages +
+ + + S_ubtitles +
+ + _Select Text Subtitles… + app.select-subtitle + +
+
+
+ +
+
+
+
+
+ + _Eject + app.eject + <Ctrl>E + action-disabled + +
+
+ +
diff --git a/src/menus-common.ui b/src/menus-common.ui new file mode 100644 index 0000000..b231c93 --- /dev/null +++ b/src/menus-common.ui @@ -0,0 +1,57 @@ + + + +
+ + Add _Local Video… + app.open + <Ctrl>O + + + Add _Web Video… + app.open-location + <Ctrl>L + +
+
+ + +
+ + _Repeat + app.repeat + +
+
+ + _DVD Menu + app.dvd-root-menu + <Ctrl>M + action-disabled + + + _Title Menu + app.dvd-title-menu + action-disabled + + + A_udio Menu + app.dvd-audio-menu + action-disabled + + + _Angle Menu + app.dvd-angle-menu + action-disabled + + + _Chapter Menu + app.dvd-chapter-menu + action-disabled + +
+
+
+
+
+
diff --git a/src/menus-traditional.ui b/src/menus-traditional.ui new file mode 100644 index 0000000..f9c5f41 --- /dev/null +++ b/src/menus-traditional.ui @@ -0,0 +1,171 @@ + + + + + _Movie +
+ + Add _Local Video… + app.open + <Ctrl>O + + + Add _Web Video… + app.open-location + <Ctrl>L + +
+
+
+
+
+
+
+
+
+ + _Eject + app.eject + <Ctrl>E + +
+
+ + _Play / Pause + app.play + <Ctrl>space + +
+
+ + _Quit + app.quit + <Ctrl>Q + +
+ + + + _Edit +
+ + _Repeat + app.repeat + +
+
+
+
+
+ + Prefere_nces + app.preferences + +
+ + + + _View +
+ + _Aspect Ratio +
+ + Auto + app.aspect-ratio + 0 + + + Square + app.aspect-ratio + 1 + + + 4∶3 (TV) + app.aspect-ratio + 2 + + + 16∶9 (Widescreen) + app.aspect-ratio + 3 + + + 2.11∶1 (DVB) + app.aspect-ratio + 4 + +
+
+ + Zoom In + app.zoom + +
+ + Switch An_gles + app.next-angle + <Ctrl>G + +
+
+ + _Languages +
+ + + S_ubtitles +
+ + _Select Text Subtitles… + app.select-subtitle + +
+
+
+ +
+ + + + _Go +
+ + _DVD Menu + app.dvd-root-menu + <Ctrl>M + + + _Title Menu + app.dvd-title-menu + + + A_udio Menu + app.dvd-audio-menu + + + _Angle Menu + app.dvd-angle-menu + + + _Chapter Menu + app.dvd-chapter-menu + +
+
+
+
+ + + + _Help +
+ + _Contents + app.help + F1 + +
+
+
+
diff --git a/src/totem-menu.c b/src/totem-menu.c index 89a2142..21811c6 100644 --- a/src/totem-menu.c +++ b/src/totem-menu.c @@ -332,12 +332,8 @@ totem_app_actions_setup (Totem *totem) void totem_app_menu_setup (Totem *totem) { - GMenuModel *appmenu; char *accels[] = { NULL, NULL }; - appmenu = (GMenuModel *)gtk_builder_get_object (totem->xml, "appmenu"); - gtk_application_set_app_menu (GTK_APPLICATION (totem), appmenu); - /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=700085 */ accels[0] = "G"; gtk_application_set_accels_for_action (GTK_APPLICATION (totem), "app.next-angle", (const char * const *) accels); diff --git a/src/totem-object.c b/src/totem-object.c index 622ab77..4918265 100644 --- a/src/totem-object.c +++ b/src/totem-object.c @@ -628,14 +628,7 @@ GMenu * totem_object_get_menu_section (TotemObject *totem, const char *id) { - GObject *object; - g_return_val_if_fail (TOTEM_IS_OBJECT (totem), NULL); - - object = gtk_builder_get_object (totem->xml, id); - if (object == NULL || !G_IS_MENU (object)) - return NULL; - - return G_MENU (object); + return gtk_application_get_menu_by_id (GTK_APPLICATION (totem), id); } /** @@ -655,7 +648,7 @@ totem_object_empty_menu_section (TotemObject *totem, g_return_if_fail (TOTEM_IS_OBJECT (totem)); - menu = G_MENU (gtk_builder_get_object (totem->xml, id)); + menu = gtk_application_get_menu_by_id (GTK_APPLICATION (totem), id); g_return_if_fail (menu != NULL); while (g_menu_model_get_n_items (G_MENU_MODEL (menu)) > 0) { @@ -1047,7 +1040,8 @@ totem_object_set_main_page (TotemObject *totem, "custom-title", NULL, NULL); gtk_widget_show (totem->fullscreen_button); - gtk_widget_show (totem->gear_button); + if (gtk_application_prefers_app_menu (GTK_APPLICATION (totem))) + gtk_widget_show (totem->gear_button); gtk_widget_hide (totem->add_button); bacon_video_widget_show_popup (totem->bvw); } else if (g_strcmp0 (page_id, "grilo") == 0) { @@ -1068,7 +1062,8 @@ totem_object_set_main_page (TotemObject *totem, g_clear_pointer (&totem->player_title, g_free); g_clear_object (&totem->custom_title); gtk_widget_hide (totem->fullscreen_button); - gtk_widget_hide (totem->gear_button); + if (gtk_application_prefers_app_menu (GTK_APPLICATION (totem))) + gtk_widget_hide (totem->gear_button); if (totem_grilo_get_current_page (TOTEM_GRILO (totem->grilo)) == TOTEM_GRILO_PAGE_RECENT) gtk_widget_show (totem->add_button); totem_grilo_start (TOTEM_GRILO (totem->grilo)); @@ -3391,14 +3386,16 @@ totem_object_handle_key_press (TotemObject *totem, GdkEventKey *event) case GDK_KEY_Menu: case GDK_KEY_F10: bacon_video_widget_show_popup (totem->bvw); - if (totem->controls_visibility != TOTEM_CONTROLS_FULLSCREEN) { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (totem->gear_button), - !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (totem->gear_button))); - } else { - /* FIXME - * The menu won't be correctly positioned */ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (totem->fullscreen_gear_button), - !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (totem->fullscreen_gear_button))); + if (gtk_application_prefers_app_menu (GTK_APPLICATION (totem))) { + if (totem->controls_visibility != TOTEM_CONTROLS_FULLSCREEN) { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (totem->gear_button), + !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (totem->gear_button))); + } else { + /* FIXME + * The menu won't be correctly positioned */ + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (totem->fullscreen_gear_button), + !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (totem->fullscreen_gear_button))); + } } break; case GDK_KEY_Time: @@ -3757,7 +3754,8 @@ totem_callback_connect (TotemObject *totem) GtkWidget *item; GtkBox *box; GAction *gaction; - GMenuModel *menu; + GMenu *menu; + GtkPopover *popover; /* Menu items */ gaction = g_action_map_lookup_action (G_ACTION_MAP (totem), "repeat"); @@ -3803,20 +3801,25 @@ totem_callback_connect (TotemObject *totem) /* Go button */ item = g_object_get_data (totem->controls, "go_button"); - menu = (GMenuModel *) gtk_builder_get_object (totem->xml, "gomenu"); - gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (item), menu); + menu = gtk_application_get_menu_by_id (GTK_APPLICATION (totem), "gomenu"); + gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (item), G_MENU_MODEL (menu)); + popover = gtk_menu_button_get_popover (GTK_MENU_BUTTON (item)); + gtk_popover_set_transitions_enabled (GTK_POPOVER (popover), FALSE); g_signal_connect (G_OBJECT (item), "toggled", G_CALLBACK (popup_menu_shown_cb), totem); /* Cog wheel */ - item = totem->gear_button = totem_interface_create_header_button (totem->header, - gtk_menu_button_new (), - "open-menu-symbolic", - GTK_PACK_END); - g_object_set (G_OBJECT (totem->gear_button), "use-popover", TRUE, NULL); - menu = (GMenuModel *) gtk_builder_get_object (totem->xml, "playermenu"); - gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (item), menu); - g_signal_connect (G_OBJECT (item), "toggled", - G_CALLBACK (popup_menu_shown_cb), totem); + if (gtk_application_prefers_app_menu (GTK_APPLICATION (totem))) { + item = totem->gear_button = totem_interface_create_header_button (totem->header, + gtk_menu_button_new (), + "open-menu-symbolic", + GTK_PACK_END); + menu = gtk_application_get_menu_by_id (GTK_APPLICATION (totem), "playermenu"); + gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (item), G_MENU_MODEL (menu)); + popover = gtk_menu_button_get_popover (GTK_MENU_BUTTON (item)); + gtk_popover_set_transitions_enabled (GTK_POPOVER (popover), FALSE); + g_signal_connect (G_OBJECT (item), "toggled", + G_CALLBACK (popup_menu_shown_cb), totem); + } /* Add button */ item = totem->add_button = totem_interface_create_header_button (totem->header, @@ -3824,8 +3827,8 @@ totem_callback_connect (TotemObject *totem) "list-add-symbolic", GTK_PACK_START); g_object_set (G_OBJECT (totem->add_button), "use-popover", TRUE, NULL); - menu = (GMenuModel *) gtk_builder_get_object (totem->xml, "addmenu"); - gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (item), menu); + menu = gtk_application_get_menu_by_id (GTK_APPLICATION (totem), "addmenu"); + gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (item), G_MENU_MODEL (menu)); gtk_widget_show (item); g_signal_connect (G_OBJECT (totem->header), "notify::search-mode", @@ -3950,7 +3953,7 @@ static void add_fullscreen_toolbar (TotemObject *totem) { GtkWidget *item; - GMenuModel *menu; + GMenu *menu; totem->revealer = GTK_WIDGET (gtk_builder_get_object (totem->xml, "toolbar-revealer")); totem->fullscreen_header = g_object_new (TOTEM_TYPE_MAIN_TOOLBAR, @@ -3971,20 +3974,21 @@ add_fullscreen_toolbar (TotemObject *totem) GTK_PACK_END); gtk_actionable_set_action_name (GTK_ACTIONABLE (item), "app.fullscreen"); - item = gtk_separator_new (GTK_ORIENTATION_VERTICAL); - gtk_header_bar_pack_end (GTK_HEADER_BAR (totem->fullscreen_header), item); - gtk_style_context_add_class (gtk_widget_get_style_context (item), "header-bar-separator"); - - item = totem_interface_create_header_button (totem->fullscreen_header, - gtk_menu_button_new (), - "open-menu-symbolic", - GTK_PACK_END); - g_object_set (G_OBJECT (item), "use-popover", TRUE, NULL); - menu = (GMenuModel *) gtk_builder_get_object (totem->xml, "playermenu"); - gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (item), menu); - g_signal_connect (G_OBJECT (item), "toggled", - G_CALLBACK (popup_menu_shown_cb), totem); - totem->fullscreen_gear_button = item; + if (gtk_application_prefers_app_menu (GTK_APPLICATION (totem))) { + item = gtk_separator_new (GTK_ORIENTATION_VERTICAL); + gtk_header_bar_pack_end (GTK_HEADER_BAR (totem->fullscreen_header), item); + gtk_style_context_add_class (gtk_widget_get_style_context (item), "header-bar-separator"); + + item = totem_interface_create_header_button (totem->fullscreen_header, + gtk_menu_button_new (), + "open-menu-symbolic", + GTK_PACK_END); + menu = gtk_application_get_menu_by_id (GTK_APPLICATION (totem), "playermenu"); + gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (item), G_MENU_MODEL (menu)); + g_signal_connect (G_OBJECT (item), "toggled", + G_CALLBACK (popup_menu_shown_cb), totem); + totem->fullscreen_gear_button = item; + } gtk_container_add (GTK_CONTAINER (totem->revealer), totem->fullscreen_header); gtk_widget_show_all (totem->fullscreen_header); -- 2.1.4