hammond-gtk: Create Application wide actions.
This commit is contained in:
parent
ca06a16bd9
commit
fdd63afdfe
@ -249,6 +249,7 @@
|
|||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">True</property>
|
<property name="receives_default">True</property>
|
||||||
|
<property name="action_name">app.update</property>
|
||||||
<property name="text" translatable="yes">Check for new episodes</property>
|
<property name="text" translatable="yes">Check for new episodes</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
|
|||||||
@ -2,8 +2,7 @@ use gtk;
|
|||||||
use glib;
|
use glib;
|
||||||
use gio;
|
use gio;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gio::ApplicationExtManual;
|
use gio::{ActionMapExt, ApplicationExt, ApplicationExtManual, SimpleActionExt};
|
||||||
use gio::ApplicationExt;
|
|
||||||
|
|
||||||
use hammond_data::utils::checkup;
|
use hammond_data::utils::checkup;
|
||||||
|
|
||||||
@ -64,13 +63,23 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(&self) {
|
pub fn setup_actions(&self) {
|
||||||
let window = self.window.clone();
|
let update = gio::SimpleAction::new("update", None);
|
||||||
let app = self.app_instance.clone();
|
let content = self.content.clone();
|
||||||
self.app_instance.connect_startup(move |_| {
|
update.connect_activate(move |_, _| {
|
||||||
build_ui(&window, &app);
|
utils::refresh_feed(content.clone(), None);
|
||||||
});
|
});
|
||||||
|
self.app_instance.add_action(&update);
|
||||||
|
|
||||||
|
let refresh = gio::SimpleAction::new("refresh", None);
|
||||||
|
let content = self.content.clone();
|
||||||
|
update.connect_activate(move |_, _| {
|
||||||
|
content.update();
|
||||||
|
});
|
||||||
|
self.app_instance.add_action(&refresh);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn setup_timed_callbacks(&self) {
|
||||||
let content = self.content.clone();
|
let content = self.content.clone();
|
||||||
// Update 30 seconds after the Application is initialized.
|
// Update 30 seconds after the Application is initialized.
|
||||||
gtk::timeout_add_seconds(
|
gtk::timeout_add_seconds(
|
||||||
@ -98,6 +107,16 @@ impl App {
|
|||||||
let _ = checkup();
|
let _ = checkup();
|
||||||
glib::Continue(false)
|
glib::Continue(false)
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run(&self) {
|
||||||
|
let window = self.window.clone();
|
||||||
|
let app = self.app_instance.clone();
|
||||||
|
self.app_instance.connect_startup(move |_| {
|
||||||
|
build_ui(&window, &app);
|
||||||
|
});
|
||||||
|
self.setup_timed_callbacks();
|
||||||
|
self.setup_actions();
|
||||||
|
|
||||||
ApplicationExtManual::run(&self.app_instance, &[]);
|
ApplicationExtManual::run(&self.app_instance, &[]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -56,7 +56,6 @@ impl Header {
|
|||||||
let menu_popover: gtk::PopoverMenu = builder.get_object("menu_popover").unwrap();
|
let menu_popover: gtk::PopoverMenu = builder.get_object("menu_popover").unwrap();
|
||||||
let new_url: gtk::Entry = builder.get_object("new_url").unwrap();
|
let new_url: gtk::Entry = builder.get_object("new_url").unwrap();
|
||||||
let add_button: gtk::Button = builder.get_object("add_button").unwrap();
|
let add_button: gtk::Button = builder.get_object("add_button").unwrap();
|
||||||
let refresh_button: gtk::Button = builder.get_object("refresh_button").unwrap();
|
|
||||||
self.switch.set_stack(&content.get_stack());
|
self.switch.set_stack(&content.get_stack());
|
||||||
|
|
||||||
new_url.connect_changed(move |url| {
|
new_url.connect_changed(move |url| {
|
||||||
@ -71,10 +70,6 @@ impl Header {
|
|||||||
add_popover.hide();
|
add_popover.hide();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
refresh_button.connect_clicked(clone!(content => move |_| {
|
|
||||||
utils::refresh_feed(content.clone(), None);
|
|
||||||
}));
|
|
||||||
|
|
||||||
self.add_toggle.set_popover(&add_popover);
|
self.add_toggle.set_popover(&add_popover);
|
||||||
self.menu_toggle.set_popover(&menu_popover);
|
self.menu_toggle.set_popover(&menu_popover);
|
||||||
|
|
||||||
|
|||||||
@ -45,11 +45,11 @@ pub fn refresh_feed(content: Rc<Content>, source: Option<Vec<Source>>) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
sender.send(true).expect("Couldn't send data to channel");;
|
sender.send(true).expect("Couldn't send data to channel");;
|
||||||
glib::idle_add(refresh_podcasts_view);
|
glib::idle_add(refresh_everything);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn refresh_podcasts_view() -> glib::Continue {
|
fn refresh_everything() -> glib::Continue {
|
||||||
GLOBAL.with(|global| {
|
GLOBAL.with(|global| {
|
||||||
if let Some((ref content, ref reciever)) = *global.borrow() {
|
if let Some((ref content, ref reciever)) = *global.borrow() {
|
||||||
if reciever.try_recv().is_ok() {
|
if reciever.try_recv().is_ok() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user