notifications: initial logic for sending action signal

This commit is contained in:
Ian Douglas Scott 2021-09-23 14:42:24 -07:00
parent 94def67e85
commit 13aa62cef8
3 changed files with 31 additions and 4 deletions

View file

@ -35,7 +35,7 @@ impl ObjectImpl for NotificationListInner {
..set_parent(obj);
..connect_row_activated(clone!(@weak obj => move |_, row| {
if let Some(id) = obj.id_for_row(row) {
// TODO
obj.inner().notifications.invoke_action(id, "default");
}
}));
};

View file

@ -7,7 +7,7 @@ use gtk4::{
use crate::deref_cell::DerefCell;
use crate::notification_widget::NotificationWidget;
use crate::notifications::{Notification, Notifications};
use crate::notifications::{Notification, NotificationId, Notifications};
#[derive(Default)]
pub struct NotificationPopoverInner {
@ -27,6 +27,9 @@ impl ObjectImpl for NotificationPopoverInner {
obj.add_controller(&cascade! {
gtk4::GestureClick::new();
..connect_pressed(clone!(@weak obj => move |_, _, _, _| {
if let Some(id) = obj.id() {
obj.inner().notifications.invoke_action(id, "default");
}
obj.popdown();
}));
});
@ -64,7 +67,7 @@ impl NotificationPopover {
obj.handle_notification(&notification);
}));
notifications.connect_notification_closed(clone!(@weak obj => move |id| {
if obj.inner().notification_widget.id() == Some(id) {
if obj.id() == Some(id) {
obj.popdown();
}
}));
@ -76,6 +79,10 @@ impl NotificationPopover {
NotificationPopoverInner::from_instance(self)
}
fn id(&self) -> Option<NotificationId> {
self.inner().notification_widget.id()
}
fn handle_notification(&self, notification: &Notification) {
self.inner()
.notification_widget

View file

@ -207,6 +207,12 @@ impl From<NotificationId> for u32 {
}
}
impl ToVariant for NotificationId {
fn to_variant(&self) -> glib::Variant {
self.0.get().to_variant()
}
}
impl NotificationId {
fn new(value: u32) -> Option<Self> {
NonZeroU32::new(value).map(Self)
@ -308,7 +314,7 @@ impl Notifications {
PATH,
INTERFACE,
"CloseNotification",
Some(&(&(reason as u32),).to_variant()),
Some(&(id, &(reason as u32)).to_variant()),
)
.unwrap();
}
@ -318,6 +324,20 @@ impl Notifications {
self.close_notification(id, CloseReason::Dismiss);
}
pub fn invoke_action(&self, id: NotificationId, action_key: &str) {
if let Some(connection) = self.inner().connection.borrow().as_ref() {
connection
.emit_signal(
None,
PATH,
INTERFACE,
"ActionInvoked",
Some(&(&(id, action_key),).to_variant()),
)
.unwrap();
}
}
fn bus_acquired(&self, connection: gio::DBusConnection, _name: &str) {
*self.inner().connection.borrow_mut() = Some(connection);
}