HomeView: Use the new BaseView abstraction

This commit is contained in:
Jordan Petridis 2018-08-09 04:46:59 +03:00
parent 8fb84d9484
commit 4e3c3ee02f
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
3 changed files with 298 additions and 365 deletions

View File

@ -3,20 +3,20 @@
Copyright (C) 2017 - 2018
This file is part of Hammond.
This file is part of GNOME Podcasts.
Hammond is free software: you can redistribute it and/or modify
GNOME Podcasts is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Hammond is distributed in the hope that it will be useful,
GNOME Podcasts is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Hammond. If not, see <http://www.gnu.org/licenses/>.
along with GNOME Podcasts. If not, see <http://www.gnu.org/licenses/>.
Authors:
Jordan Petridis
@ -24,55 +24,15 @@ Tobias Bernard
-->
<interface>
<requires lib="gtk+" version="3.20"/>
<requires lib="gtk+" version="3.22"/>
<!-- interface-license-type gplv3 -->
<!-- interface-name Hammond -->
<!-- interface-name GNOME Podcasts -->
<!-- interface-description A podcast client for the GNOME Desktop -->
<!-- interface-copyright 2017 - 2018 -->
<!-- interface-authors Jordan Petridis\nTobias Bernard -->
<object class="GtkBox" id="container">
<property name="name">container</property>
<property name="width_request">290</property>
<property name="height_request">420</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkScrolledWindow" id="scrolled_window">
<property name="name">scrolled_window</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">never</property>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="frame_parent">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">32</property>
<property name="margin_right">32</property>
<property name="margin_top">32</property>
<property name="margin_bottom">32</property>
<property name="hexpand">True</property>
@ -362,38 +322,4 @@ Tobias Bernard
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
</interface>

View File

@ -34,7 +34,7 @@ impl HomeStack {
let stack = gtk::Stack::new();
let state = State::Empty;
stack.add_named(&episodes.container, "home");
stack.add_named(episodes.container(), "home");
stack.add_named(&empty.container, "empty");
let mut home = HomeStack {
@ -67,14 +67,14 @@ impl HomeStack {
fn replace_view(&mut self) -> Result<(), Error> {
// Get the container of the view
let old = &self.episodes.container.clone();
let old = &self.episodes.container().clone();
let eps = HomeView::new(self.sender.clone())?;
// Remove the old widget and add the new one
// during this the previous view is removed,
// and the visibile child fallsback to empty view.
self.stack.remove(old);
self.stack.add_named(&eps.container, "home");
self.stack.add_named(eps.container(), "home");
// Keep the previous state.
let s = self.state;
// Set the visible child back to the previous one to avoid

View File

@ -11,7 +11,7 @@ use podcasts_data::EpisodeWidgetModel;
use app::Action;
use utils::{self, lazy_load_full};
use widgets::EpisodeWidget;
use widgets::{BaseView, EpisodeWidget};
use std::cell::Cell;
use std::rc::Rc;
@ -33,8 +33,7 @@ enum ListSplit {
#[derive(Debug, Clone)]
pub(crate) struct HomeView {
pub(crate) container: gtk::Box,
scrolled_window: gtk::ScrolledWindow,
view: BaseView,
frame_parent: gtk::Box,
today_box: gtk::Box,
yday_box: gtk::Box,
@ -50,9 +49,8 @@ pub(crate) struct HomeView {
impl Default for HomeView {
fn default() -> Self {
let view = BaseView::default();
let builder = gtk::Builder::new_from_resource("/org/gnome/Podcasts/gtk/home_view.ui");
let container: gtk::Box = builder.get_object("container").unwrap();
let scrolled_window: gtk::ScrolledWindow = builder.get_object("scrolled_window").unwrap();
let frame_parent: gtk::Box = builder.get_object("frame_parent").unwrap();
let today_box: gtk::Box = builder.get_object("today_box").unwrap();
let yday_box: gtk::Box = builder.get_object("yday_box").unwrap();
@ -65,9 +63,10 @@ impl Default for HomeView {
let month_list: gtk::ListBox = builder.get_object("month_list").unwrap();
let rest_list: gtk::ListBox = builder.get_object("rest_list").unwrap();
view.add(&frame_parent);
HomeView {
container,
scrolled_window,
view,
frame_parent,
today_box,
yday_box,
@ -116,10 +115,18 @@ impl HomeView {
};
lazy_load_full(episodes, func, callback);
view.container.show_all();
view.container().show_all();
Ok(view)
}
pub(crate) fn container(&self) -> &gtk::Box {
self.view.container()
}
pub(crate) fn scrolled_window(&self) -> &gtk::ScrolledWindow {
self.view.scrolled_window()
}
/// Set scrolled window vertical adjustment.
fn set_vadjustment(&self) -> Result<(), Error> {
let guard = EPISODES_VIEW_VALIGNMENT
@ -130,7 +137,7 @@ impl HomeView {
// Copy the vertical scrollbar adjustment from the old view into the new one.
let res = fragile
.try_get()
.map(|x| utils::smooth_scroll_to(&self.scrolled_window, &x))
.map(|x| utils::smooth_scroll_to(self.scrolled_window(), &x))
.map_err(From::from);
debug_assert!(res.is_ok());
@ -144,7 +151,7 @@ impl HomeView {
pub(crate) fn save_alignment(&self) -> Result<(), Error> {
if let Ok(mut guard) = EPISODES_VIEW_VALIGNMENT.lock() {
let adj = self
.scrolled_window
.scrolled_window()
.get_vadjustment()
.ok_or_else(|| format_err!("Could not get the adjustment"))?;
*guard = Some(Fragile::new(adj));