diff --git a/share/dbus-1/services/org.freedesktop.Telepathy.ConnectionManager.padfoot.service b/share/dbus-1/services/org.freedesktop.Telepathy.ConnectionManager.padfoot.service new file mode 100644 index 0000000..087dac9 --- /dev/null +++ b/share/dbus-1/services/org.freedesktop.Telepathy.ConnectionManager.padfoot.service @@ -0,0 +1,4 @@ +[D-BUS Service] +Name=org.freedesktop.Telepathy.ConnectionManager.padfoot +Exec=/usr/lib/telepathy/telepathy-padfoot +//SystemdService=telepathy-padfoot.service diff --git a/share/managers/padfoot.manager b/share/managers/padfoot.manager new file mode 100644 index 0000000..05499f0 --- /dev/null +++ b/share/managers/padfoot.manager @@ -0,0 +1,11 @@ +[ConnectionManager] +Name = padfoot +BusName = org.freedesktop.Telepathy.ConnectionManager.padfoot +ObjectPath = /org/freedesktop/Telepathy/ConnectionManager/padfoot + +[Protocol delta] +param-account = s required +param-password = s required secret + +EnglishName=Delta Chat +Icon=delta diff --git a/src/main.rs b/src/main.rs index 02c6503..2a4fd50 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ mod telepathy; //use dbus::tree::{Interface, MTFn, MethodErr}; use dbus::{ blocking::{stdintf::org_freedesktop_dbus::RequestNameReply, LocalConnection}, - tree::{Factory, Interface, MTFn, Tree}, + tree::{Factory, MTFn, Tree}, }; use padfoot::{CMData, ConnectionManager}; @@ -14,8 +14,8 @@ use std::time::Duration; use anyhow::{anyhow, Result}; -const BUS_NAME: &'static str = "org.freedesktop.Telepathy.ConnectionManager.padfoot"; -const OBJECT_PATH: &'static str = "/org/freedesktop/Telepathy/ConnectionManager/padfoot"; +const CM_BUS_NAME: &'static str = "org.freedesktop.Telepathy.ConnectionManager.padfoot"; +const CM_OBJECT_PATH: &'static str = "/org/freedesktop/Telepathy/ConnectionManager/padfoot"; fn create_tree(cm: &Arc) -> Tree, CMData> { let f = Factory::new_fn(); @@ -29,7 +29,7 @@ fn create_tree(cm: &Arc) -> Tree, CMData> { }); tree = tree.add( - f.object_path(OBJECT_PATH, cm.clone()) + f.object_path(CM_OBJECT_PATH, cm.clone()) .introspectable() .add(iface), ); @@ -45,18 +45,18 @@ fn run() -> Result<()> { // Setup DBus connection let mut c = LocalConnection::new_session()?; - let result = c.request_name(BUS_NAME, false, false, true)?; + let result = c.request_name(CM_BUS_NAME, false, false, true)?; match result { RequestNameReply::Exists => { return Err(anyhow!( "Another process is already registered on {}", - BUS_NAME + CM_BUS_NAME )) } _ => {} // All other responses we can get are a success }; - println!("Bus registered: {}", BUS_NAME); + println!("Bus registered: {}", CM_BUS_NAME); tree.start_receive(&c); loop { diff --git a/src/padfoot/connection_manager.rs b/src/padfoot/connection_manager.rs index ecbe17d..c42d290 100644 --- a/src/padfoot/connection_manager.rs +++ b/src/padfoot/connection_manager.rs @@ -19,22 +19,43 @@ impl dbus::tree::DataType for CMData { const PROTO: &'static str = "delta"; +pub type ParamSpec = ( + String, // Name + u32, // Flags (Conn_Mgr_Param_Flags) + String, // Signature + arg::Variant>, // Default +); + pub type Dict = HashMap>>; +// FIXME: these should come from codegen +const FLAG_REQUIRED: u32 = 1; +//const FLAG_REGISTER: u32 = 2; +//const FLAG_HAS_DEFAULT: u32 = 4; +const FLAG_SECRET: u32 = 8; +//const FLAG_DBUS_PROP: u32 = 16; + impl telepathy::ConnectionManager for ConnectionManager { - fn get_parameters( - &self, - protocol: &str, - ) -> Result< - Vec<( - String, - u32, - String, - arg::Variant>, - )>, - tree::MethodErr, - > { - Err(tree::MethodErr::no_arg()) // FIXME: should be NotImplemented + fn get_parameters(&self, protocol: &str) -> Result, tree::MethodErr> { + if protocol != PROTO { + return Err(tree::MethodErr::no_arg()); // FIXME: should be NotImplemented? + } + + // TODO: query the protocol for these? + Ok(vec![ + ( + "account".to_string(), + FLAG_REQUIRED, + "s".to_string(), + arg::Variant(Box::new("".to_string())), + ), + ( + "password".to_string(), + FLAG_REQUIRED | FLAG_SECRET, + "s".to_string(), + arg::Variant(Box::new("".to_string())), + ), + ]) } fn list_protocols(&self) -> Result, tree::MethodErr> { @@ -43,22 +64,19 @@ impl telepathy::ConnectionManager for ConnectionManager { fn request_connection( &self, - protocol: &str, - parameters: HashMap<&str, arg::Variant>>, + _protocol: &str, + _parameters: HashMap<&str, arg::Variant>>, ) -> Result<(String, dbus::Path<'static>), tree::MethodErr> { Err(tree::MethodErr::no_arg()) } fn protocols(&self) -> Result, tree::MethodErr> { - let mut hm = HashMap::new(); - let mut props = Dict::new(); - - hm.insert(PROTO.to_string(), props); - - Ok(hm) + // If this map is empty or missing, clients SHOULD fall back to + // calling ListProtocol and GetParameters + Ok(HashMap::new()) } fn interfaces(&self) -> Result, tree::MethodErr> { - Err(tree::MethodErr::no_arg()) + Ok(vec![]) } } diff --git a/src/padfoot/protocol.rs b/src/padfoot/protocol.rs index 69d53fc..3dbbcdd 100644 --- a/src/padfoot/protocol.rs +++ b/src/padfoot/protocol.rs @@ -1,2 +1 @@ pub struct Protocol {} -