diff --git a/src/Services/PlaybackManager.vala b/src/Services/PlaybackManager.vala index 72f1c14e8..7be1514a2 100644 --- a/src/Services/PlaybackManager.vala +++ b/src/Services/PlaybackManager.vala @@ -206,8 +206,6 @@ public class Audience.PlaybackManager : Object { playbin.uri = uri; - ((Gtk.Application) Application.get_default ()).active_window.title = get_title (uri); - /* Set progress before subtitle uri else it gets reset to zero */ if (from_beginning) { seek (0); diff --git a/src/Widgets/HeaderBar.vala b/src/Widgets/HeaderBar.vala index 91180b5f1..42866de66 100644 --- a/src/Widgets/HeaderBar.vala +++ b/src/Widgets/HeaderBar.vala @@ -25,6 +25,7 @@ public class Audience.HeaderBar : Gtk.Box { construct { var navigation_button = new Gtk.Button.with_label ("") { + action_name = Window.ACTION_PREFIX + Window.ACTION_BACK, valign = Gtk.Align.CENTER }; navigation_button.get_style_context ().add_class (Granite.STYLE_CLASS_BACK_BUTTON); @@ -34,8 +35,12 @@ public class Audience.HeaderBar : Gtk.Box { tooltip_text = _("Unfullscreen") }; + var title_label = new Gtk.Label (""); + title_label.add_css_class (Granite.STYLE_CLASS_TITLE_LABEL); + header_bar = new Gtk.HeaderBar () { show_title_buttons = true, + title_widget = title_label, hexpand = true }; header_bar.pack_start (navigation_button); @@ -45,10 +50,15 @@ public class Audience.HeaderBar : Gtk.Box { append (header_bar); map.connect (() => { - var adjacent_page_name = ((Window) get_root ()).get_adjacent_page_name (); - if (adjacent_page_name != null) { + var current_page = (Adw.NavigationPage) get_ancestor (typeof (Adw.NavigationPage)); + var navigation_view = (Adw.NavigationView) get_ancestor (typeof (Adw.NavigationView)); + + current_page.bind_property ("title", title_label, "label", SYNC_CREATE); + + var previous_page = navigation_view.get_previous_page (current_page); + if (previous_page != null) { navigation_button.visible = true; - navigation_button.label = adjacent_page_name; + navigation_button.label = previous_page.title; } else { navigation_button.visible = false; } @@ -58,8 +68,6 @@ public class Audience.HeaderBar : Gtk.Box { unmap.connect (() => binding.unbind ()); - navigation_button.clicked.connect (() => ((Adw.Leaflet) get_ancestor (typeof (Adw.Leaflet))).navigate (BACK)); - unfullscreen_button.clicked.connect (() => ((Window) get_root ()).unfullscreen ()); } } diff --git a/src/Widgets/Library/EpisodesPage.vala b/src/Widgets/Library/EpisodesPage.vala index e2bfcf222..39d45ba76 100644 --- a/src/Widgets/Library/EpisodesPage.vala +++ b/src/Widgets/Library/EpisodesPage.vala @@ -18,7 +18,7 @@ * */ -public class Audience.EpisodesPage : Gtk.Box { +public class Audience.EpisodesPage : Adw.NavigationPage { private Gtk.Picture poster; private Gtk.FilterListModel filter_model; private Gtk.SearchEntry search_entry; @@ -91,9 +91,12 @@ public class Audience.EpisodesPage : Gtk.Box { grid.attach (scrolled_window, 1, 1); grid.attach (alert_view, 1, 1); - orientation = VERTICAL; - append (header_bar); - append (grid); + var box = new Gtk.Box (VERTICAL, 0); + box.append (header_bar); + box.append (grid); + + child = box; + title = _("Episodes"); factory.setup.connect ((obj) => { var item = (Gtk.ListItem) obj; diff --git a/src/Widgets/Library/LibraryPage.vala b/src/Widgets/Library/LibraryPage.vala index 93a43a4f2..78a732baa 100644 --- a/src/Widgets/Library/LibraryPage.vala +++ b/src/Widgets/Library/LibraryPage.vala @@ -18,7 +18,7 @@ * */ -public class Audience.LibraryPage : Gtk.Box { +public class Audience.LibraryPage : Adw.NavigationPage { public signal void show_episodes (Objects.MediaItem item, bool setup_only = false); private Audience.Services.LibraryManager manager; @@ -76,7 +76,8 @@ public class Audience.LibraryPage : Gtk.Box { }; toolbarview.add_top_bar (header_bar); - append (toolbarview); + child = toolbarview; + title = _("Library"); factory.setup.connect ((obj) => { var item = (Gtk.ListItem) obj; diff --git a/src/Widgets/Player/PlayerPage.vala b/src/Widgets/Player/PlayerPage.vala index c39a65c05..ad0de5eb3 100644 --- a/src/Widgets/Player/PlayerPage.vala +++ b/src/Widgets/Player/PlayerPage.vala @@ -25,7 +25,7 @@ namespace Audience { "asc" }; - public class PlayerPage : Gtk.Box { + public class PlayerPage : Adw.NavigationPage { private Audience.Widgets.BottomBar bottom_bar; private Adw.ToolbarView toolbarview; @@ -57,7 +57,7 @@ namespace Audience { toolbarview.add_top_bar (header_bar); toolbarview.add_bottom_bar (bottom_bar); - append (toolbarview); + child = toolbarview; map.connect (() => update_actions_enabled (true)); @@ -95,6 +95,10 @@ namespace Audience { var play_pause_action = Application.get_default ().lookup_action (Audience.App.ACTION_PLAY_PAUSE); ((SimpleAction) play_pause_action).activate (null); }); + + playback_manager.uri_changed.connect ((uri) => { + title = Audience.get_title (uri); + }); } private void update_actions_enabled (bool enabled) { diff --git a/src/Widgets/WelcomePage.vala b/src/Widgets/WelcomePage.vala index 5c0d4a1e5..baf3d0173 100644 --- a/src/Widgets/WelcomePage.vala +++ b/src/Widgets/WelcomePage.vala @@ -15,28 +15,32 @@ * along with this program. If not, see . */ -public class Audience.WelcomePage : Granite.Placeholder { +public class Audience.WelcomePage : Adw.NavigationPage { private string current_video; private Gtk.Button replay_button; private Gtk.Image replay_button_image; private Gtk.Label replay_button_title; private Gtk.Label replay_button_description; - public WelcomePage () { - Object ( - title: _("No Videos Open"), - description: _("Select a source to begin playing.") - ); - } - construct { - hexpand = true; - vexpand = true; + var placeholder = new Granite.Placeholder (_("No Videos Open")) { + description = _("Select a source to begin playing."), + hexpand = true, + vexpand = true + }; + + var open_button = placeholder.append_button (new ThemedIcon ("document-open"), _("Open file"), _("Open a saved file.")); + replay_button = placeholder.append_button (new ThemedIcon ("media-playlist-repeat"), _("Replay last video"), ""); + var disk_button = placeholder.append_button (new ThemedIcon ("media-cdrom"), _("Play from Disc"), _("Watch a DVD or open a file from disc")); + var library_button = placeholder.append_button (new ThemedIcon ("folder-videos"), _("Browse Library"), _("Watch a movie from your library")); + + var box = new Gtk.Box (VERTICAL, 0); + box.append (new HeaderBar ()); + box.append (placeholder); + box.add_css_class (Granite.STYLE_CLASS_VIEW); - var open_button = append_button (new ThemedIcon ("document-open"), _("Open file"), _("Open a saved file.")); - replay_button = append_button (new ThemedIcon ("media-playlist-repeat"), _("Replay last video"), ""); - var disk_button = append_button (new ThemedIcon ("media-cdrom"), _("Play from Disc"), _("Watch a DVD or open a file from disc")); - var library_button = append_button (new ThemedIcon ("folder-videos"), _("Browse Library"), _("Watch a movie from your library")); + child = box; + title = _("Home"); //A hacky way to update the labels and icon of the replay button var replay_button_grid = (Gtk.Grid)replay_button.child; @@ -98,7 +102,7 @@ public class Audience.WelcomePage : Granite.Placeholder { if (current_video != "") { var last_file = File.new_for_uri (current_video); if (last_file.query_exists ()) { - replay_button_description.label = get_title (last_file.get_basename ()); + replay_button_description.label = Audience.get_title (last_file.get_basename ()); show_replay_button = true; } diff --git a/src/Window.vala b/src/Window.vala index 20a160c0c..a28f9f4df 100644 --- a/src/Window.vala +++ b/src/Window.vala @@ -21,12 +21,12 @@ */ public class Audience.Window : Gtk.ApplicationWindow { - private Adw.Leaflet leaflet; + private Adw.NavigationView navigation_view; private Granite.Toast app_notification; private EpisodesPage episodes_page; private LibraryPage library_page; - private Gtk.Box welcome_page_box; private PlayerPage player_page; + private WelcomePage welcome_page; public enum NavigationPage { WELCOME, LIBRARY, EPISODES } @@ -53,8 +53,6 @@ public class Audience.Window : Gtk.ApplicationWindow { }; static construct { - action_accelerators[ACTION_BACK] = "Left"; - action_accelerators[ACTION_BACK] = "Back"; action_accelerators[ACTION_FULLSCREEN] = "F"; action_accelerators[ACTION_FULLSCREEN] = "F11"; action_accelerators[ACTION_OPEN_FILE] = "O"; @@ -77,37 +75,19 @@ public class Audience.Window : Gtk.ApplicationWindow { library_page = LibraryPage.get_instance (); - library_page.show_episodes.connect ((item, setup_only) => { - episodes_page.set_show (item); - if (!setup_only) { - leaflet.append (episodes_page); - leaflet.visible_child = episodes_page; - - title = item.title; - } - }); - - var welcome_page = new WelcomePage (); - - welcome_page_box = new Gtk.Box (VERTICAL, 0); - welcome_page_box.append (new HeaderBar ()); - welcome_page_box.append (welcome_page); - welcome_page_box.add_css_class (Granite.STYLE_CLASS_VIEW); + welcome_page = new WelcomePage (); player_page = new PlayerPage (); episodes_page = new EpisodesPage (); - leaflet = new Adw.Leaflet () { - can_navigate_back = true, - can_unfold = false - }; - leaflet.append (welcome_page_box); + navigation_view = new Adw.NavigationView (); + navigation_view.add (welcome_page); app_notification = new Granite.Toast (""); var overlay = new Gtk.Overlay () { - child = leaflet + child = navigation_view }; overlay.add_overlay (app_notification); @@ -135,7 +115,14 @@ public class Audience.Window : Gtk.ApplicationWindow { app_notification.send_notification (); }); - leaflet.notify["visible-child"].connect (() => { + library_page.show_episodes.connect ((item, setup_only) => { + episodes_page.set_show (item); + if (!setup_only) { + navigation_view.push (episodes_page); + } + }); + + navigation_view.notify["visible-page"].connect (() => { update_navigation (); }); @@ -165,7 +152,7 @@ public class Audience.Window : Gtk.ApplicationWindow { key_controller.key_released.connect (handle_key_press); var drop_target = new Gtk.DropTarget (typeof (Gdk.FileList), COPY); - leaflet.add_controller (drop_target); + navigation_view.add_controller (drop_target); drop_target.drop.connect ((val) => { if (val.type () != typeof (Gdk.FileList)) { return false; @@ -184,7 +171,7 @@ public class Audience.Window : Gtk.ApplicationWindow { } private void action_back () { - leaflet.navigate (Adw.NavigationDirection.BACK); + navigation_view.pop (); } private void action_fullscreen () { @@ -204,9 +191,9 @@ public class Audience.Window : Gtk.ApplicationWindow { } private void action_search () { - if (leaflet.visible_child == library_page) { + if (navigation_view.visible_page == library_page) { library_page.search (); - } else if (leaflet.visible_child == episodes_page) { + } else if (navigation_view.visible_page == episodes_page) { episodes_page.search (); } else { Gdk.Display.get_default ().beep (); @@ -219,10 +206,6 @@ public class Audience.Window : Gtk.ApplicationWindow { */ if (!is_sandboxed ()) { Audience.Services.LibraryManager.get_instance ().undo_delete_item (); - - if (leaflet.visible_child != episodes_page) { - leaflet.visible_child = library_page; - } } } @@ -251,7 +234,7 @@ public class Audience.Window : Gtk.ApplicationWindow { } } - if (leaflet.visible_child == player_page) { + if (navigation_view.visible_page == player_page) { if (match_keycode (Gdk.Key.space, keycode) || match_keycode (Gdk.Key.p, keycode)) { var play_pause_action = Application.get_default ().lookup_action (Audience.App.ACTION_PLAY_PAUSE); ((SimpleAction) play_pause_action).activate (null); @@ -284,7 +267,7 @@ public class Audience.Window : Gtk.ApplicationWindow { default: break; } - } else if (leaflet.visible_child == welcome_page_box) { + } else if (navigation_view.visible_page == welcome_page) { bool ctrl_pressed = CONTROL_MASK in state; if (match_keycode (Gdk.Key.p, keycode) || match_keycode (Gdk.Key.space, keycode)) { resume_last_videos (); @@ -333,8 +316,7 @@ public class Audience.Window : Gtk.ApplicationWindow { } public void show_library () { - leaflet.append (library_page); - leaflet.visible_child = library_page; + navigation_view.push (library_page); } public void run_open_file (bool clear_playlist = false, bool force_play = true) { @@ -402,29 +384,15 @@ public class Audience.Window : Gtk.ApplicationWindow { } private void on_player_ended () { - leaflet.navigate (Adw.NavigationDirection.BACK); + navigation_view.pop (); } public void play_file (string uri, NavigationPage origin, bool from_beginning = true) { - leaflet.append (player_page); - leaflet.visible_child = player_page; + navigation_view.push (player_page); PlaybackManager.get_default ().play_file (uri, from_beginning); } - public string? get_adjacent_page_name () { - var previous_child = leaflet.get_adjacent_child (Adw.NavigationDirection.BACK); - if (previous_child == episodes_page) { - return _("Episodes"); - } else if (previous_child == library_page) { - return _("Library"); - } else if (previous_child == welcome_page_box) { - return _("Back"); - } else { - return null; - } - } - private void update_navigation () { int64 position = PlaybackManager.get_default ().position; if (position > 0) { @@ -432,19 +400,11 @@ public class Audience.Window : Gtk.ApplicationWindow { } var play_pause_action = Application.get_default ().lookup_action (Audience.App.ACTION_PLAY_PAUSE); - ((SimpleAction) play_pause_action).set_state (false); - if (leaflet.visible_child == welcome_page_box) { - title = _("Videos"); - } else if (leaflet.visible_child == library_page) { - title = _("Library"); - } else if (leaflet.visible_child == player_page) { + if (navigation_view.visible_page == player_page) { ((SimpleAction) play_pause_action).set_state (true); - } - - var next_child = leaflet.get_adjacent_child (Adw.NavigationDirection.FORWARD); - if (next_child != null) { - leaflet.remove (next_child); + } else { + ((SimpleAction) play_pause_action).set_state (false); } } }