diff --git a/src/main.rs b/src/main.rs index 0d08379..58839f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,7 @@ use padfoot::{ }; use std::time::Duration; +// TODO: move this to the ConnectionManager? fn run() -> Result<()> { let (cm, msg_r) = ConnectionManager::new(); let cm_rc = std::rc::Rc::new(cm); @@ -24,7 +25,12 @@ fn run() -> Result<()> { let mut tree = f.tree(()); let cm_iface = telepathy::connection_manager_server(&f, (), move |_| cm_rc.clone()); - let proto_iface = telepathy::protocol_server(&f, (), move |_| proto_rc.clone()); + + let proto_rc_1 = proto_rc.clone(); + let proto_iface = telepathy::protocol_server(&f, (), move |_| proto_rc_1.clone()); + + let proto_presence_iface = + telepathy::protocol_interface_presence_server(&f, (), move |_| proto_rc.clone()); tree = tree.add( f.object_path(CM_OBJECT_PATH, ()) @@ -34,7 +40,8 @@ fn run() -> Result<()> { tree = tree.add( f.object_path(PROTO_OBJECT_PATH, ()) .introspectable() - .add(proto_iface), + .add(proto_iface) + .add(proto_presence_iface), ); tree = tree.add(f.object_path("/", ()).introspectable()); diff --git a/src/padfoot/connection/simple_presence.rs b/src/padfoot/connection/simple_presence.rs index c0f1461..afba1f5 100644 --- a/src/padfoot/connection/simple_presence.rs +++ b/src/padfoot/connection/simple_presence.rs @@ -1,3 +1,4 @@ +use crate::padfoot::{statuses, SimpleStatusSpec}; use crate::telepathy; use dbus::tree::MethodErr; @@ -11,12 +12,6 @@ pub type SimplePresenceSpec = ( String, // status message ); -pub type SimpleStatusSpec = ( - u32, // connection presence type - bool, // may set on self? - bool, // can have message? -); - impl AsRef for std::rc::Rc { fn as_ref(&self) -> &(dyn telepathy::ConnectionInterfaceSimplePresence + 'static) { &**self @@ -55,12 +50,7 @@ impl telepathy::ConnectionInterfaceSimplePresence for Connection { fn statuses(&self) -> Result, MethodErr> { println!("Connection<{}>::statuses()", self.id()); - let mut out = HashMap::::new(); - - out.insert("available".to_string(), (2, true, false)); - out.insert("offline".to_string(), (1, true, false)); - - Ok(out) + Ok(statuses()) } fn maximum_status_message_length(&self) -> Result { diff --git a/src/padfoot/protocol.rs b/src/padfoot/protocol.rs index c503d36..d828923 100644 --- a/src/padfoot/protocol.rs +++ b/src/padfoot/protocol.rs @@ -54,6 +54,13 @@ pub fn parameters() -> Vec { ] } +pub fn protocol_interfaces() -> Vec { + vec![ + "org.freedesktop.Telepathy.Protocol".to_string(), + "org.freedesktop.Telepathy.Protocol.Interface.Presence".to_string(), + ] +} + pub fn requestables() -> Vec { let mut rf = HashMap::::new(); @@ -101,7 +108,7 @@ impl telepathy::Protocol for Protocol { fn interfaces(&self) -> Result, MethodErr> { println!("Protocol::interfaces()"); - Ok(vec![]) + Ok(protocol_interfaces()) } fn parameters(&self) -> Result, MethodErr> { @@ -148,3 +155,32 @@ impl telepathy::Protocol for Protocol { ]) } } + +pub type SimpleStatusSpec = ( + u32, // connection presence type + bool, // may set on self? + bool, // can have message? +); + +pub fn statuses() -> HashMap { + let mut out = HashMap::::new(); + + out.insert("available".to_string(), (2, true, false)); + out.insert("offline".to_string(), (1, true, false)); + + out +} + +impl AsRef for std::rc::Rc { + fn as_ref(&self) -> &(dyn telepathy::ProtocolInterfacePresence + 'static) { + &**self + } +} + +impl telepathy::ProtocolInterfacePresence for Protocol { + fn statuses(&self) -> Result, MethodErr> { + println!("Protocol::presences()"); + + Ok(statuses()) + } +}