Cleanup windows.rs

It shouldn't result in any functional changes, but some unnecessary
parts were removed and windows.rs is now tracked by meson
This commit is contained in:
Julian Hofer 2020-03-22 17:17:47 +01:00 committed by Jordan Petridis
parent 59e1c7d6f4
commit 2ee2181211
2 changed files with 46 additions and 54 deletions

View File

@ -54,7 +54,8 @@ podcasts_sources = files(
'main.rs', 'main.rs',
'manager.rs', 'manager.rs',
'settings.rs', 'settings.rs',
'utils.rs' 'utils.rs',
'window.rs',
) )
cargo_release = custom_target('cargo-build', cargo_release = custom_target('cargo-build',

View File

@ -48,7 +48,7 @@ use crate::i18n::i18n;
fn action<T, F>(thing: &T, name: &str, action: F) fn action<T, F>(thing: &T, name: &str, action: F)
where where
T: ActionMapExt, T: ActionMapExt,
for<'r, 's> F: Fn(&'r gio::SimpleAction, Option<&Variant>) + 'static, F: Fn(&gio::SimpleAction, Option<&Variant>) + 'static,
{ {
// Create a stateless, parameterless action // Create a stateless, parameterless action
let act = gio::SimpleAction::new(name, None); let act = gio::SimpleAction::new(name, None);
@ -84,27 +84,17 @@ impl MainWindow {
window.get_style_context().add_class("devel"); window.get_style_context().add_class("devel");
} }
let weak_s = settings.downgrade(); window.connect_delete_event(
let weak_app = app.downgrade(); clone!(@weak settings, @weak app => @default-return Inhibit(false), move |window, _| {
window.connect_delete_event(move |window, _| { info!("Saving window position");
let app = match weak_app.upgrade() { WindowGeometry::from_window(&window).write(&settings);
Some(a) => a,
None => return Inhibit(false),
};
let settings = match weak_s.upgrade() { info!("Application is exiting");
Some(s) => s, let app = app.upcast::<gio::Application>();
None => return Inhibit(false), app.quit();
}; Inhibit(false)
}),
info!("Saving window position"); );
WindowGeometry::from_window(&window).write(&settings);
info!("Application is exiting");
let app = app.clone().upcast::<gio::Application>();
app.quit();
Inhibit(false)
});
// Create a content instance // Create a content instance
let content = Content::new(&sender).expect("Content initialization failed."); let content = Content::new(&sender).expect("Content initialization failed.");
@ -128,8 +118,6 @@ impl MainWindow {
wrap.add(&header.bottom_switcher); wrap.add(&header.bottom_switcher);
let updater = RefCell::new(None);
window.add(&wrap); window.add(&wrap);
// Retrieve the previous window position and size. // Retrieve the previous window position and size.
@ -138,20 +126,19 @@ impl MainWindow {
// Update the feeds right after the Window is initialized. // Update the feeds right after the Window is initialized.
if settings.get_boolean("refresh-on-startup") { if settings.get_boolean("refresh-on-startup") {
info!("Refresh on startup."); info!("Refresh on startup.");
let s: Option<Vec<_>> = None; utils::schedule_refresh(None, sender.clone());
utils::schedule_refresh(s, sender.clone());
} }
let refresh_interval = settings::get_refresh_interval(&settings).num_seconds() as u32; let refresh_interval = settings::get_refresh_interval(&settings).num_seconds() as u32;
info!("Auto-refresh every {:?} seconds.", refresh_interval); info!("Auto-refresh every {:?} seconds.", refresh_interval);
let r_sender = sender.clone(); gtk::timeout_add_seconds(
gtk::timeout_add_seconds(refresh_interval, move || { refresh_interval,
let s: Option<Vec<_>> = None; clone!(@strong sender => move || {
utils::schedule_refresh(s, r_sender.clone()); utils::schedule_refresh(None, sender.clone());
glib::Continue(true)
glib::Continue(true) }),
}); );
Self { Self {
app: app.clone(), app: app.clone(),
@ -161,7 +148,7 @@ impl MainWindow {
content, content,
player, player,
updating: Cell::new(false), updating: Cell::new(false),
updater, updater: RefCell::new(None),
sender, sender,
receiver, receiver,
} }
@ -176,41 +163,45 @@ impl MainWindow {
// Create the `refresh` action. // Create the `refresh` action.
// //
// This will trigger a refresh of all the shows in the database. // This will trigger a refresh of all the shows in the database.
action(&self.window, "refresh", clone!(@strong sender => move |_, _| { action(&self.window, "refresh",
gtk::idle_add(clone!(@strong sender => move || { clone!(@strong sender => move |_, _| {
let s: Option<Vec<_>> = None; gtk::idle_add(
utils::schedule_refresh(s, sender.clone()); clone!(@strong sender => move || {
glib::Continue(false) utils::schedule_refresh(None, sender.clone());
glib::Continue(false)
})); }));
})); }));
self.app.set_accels_for_action("win.refresh", &["<primary>r"]); self.app.set_accels_for_action("win.refresh", &["<primary>r"]);
// Create the `OPML` import action // Create the `OPML` import action
action(&self.window, "import", clone!(@strong sender, @weak self.window as win => move |_, _| { action(&self.window, "import",
utils::on_import_clicked(&win, &sender); clone!(@strong sender, @weak self.window as window => move |_, _| {
utils::on_import_clicked(&window, &sender);
})); }));
action(&self.window, "export", clone!(@strong sender, @weak self.window as win => move |_, _| { action(&self.window, "export",
utils::on_export_clicked(&win, &sender); clone!(@strong sender, @weak self.window as window => move |_, _| {
utils::on_export_clicked(&window, &sender);
})); }));
// Create the action that shows a `gtk::AboutDialog` // Create the action that shows a `gtk::AboutDialog`
action(&self.window, "about", clone!(@weak self.window as win => move |_, _| { action(&self.window, "about",
about_dialog(&win); clone!(@weak self.window as win => move |_, _| {
about_dialog(&win);
})); }));
// Create the quit action // Create the quit action
let weak_instance = self.app.downgrade(); action(&self.window, "quit",
action(&self.window, "quit", move |_, _| { clone!(@weak self.app as app => move |_, _| {
weak_instance.upgrade().map(|app| app.quit()); app.quit();
}); }));
self.app.set_accels_for_action("win.quit", &["<primary>q"]); self.app.set_accels_for_action("win.quit", &["<primary>q"]);
// Create the menu action // Create the menu actions
let header = Rc::downgrade(&self.headerbar); action(&self.window, "menu",
action(&self.window, "menu", move |_, _| { clone!(@weak self.headerbar as headerbar => move |_, _| {
header.upgrade().map(|h| h.open_menu()); headerbar.open_menu();
}); }));
// Bind the hamburger menu button to `F10` // Bind the hamburger menu button to `F10`
self.app.set_accels_for_action("win.menu", &["F10"]); self.app.set_accels_for_action("win.menu", &["F10"]);
} }