use crate::padfoot::{var_bool, var_str, var_u32, VarArg}; use crate::telepathy; use dbus::tree::MethodErr; use deltachat as dc; use std::collections::HashMap; use super::ConnSettings; pub const PROTO_OBJECT_PATH: &str = "/org/freedesktop/Telepathy/ConnectionManager/padfoot/delta"; pub const PROTO_BUS_NAME: &str = "org.freedesktop.Telepathy.ConnectionManager.padfoot.delta"; pub const PROTO_NAME: &str = "delta"; #[derive(Debug)] pub struct Protocol {} pub type ParamSpec = ( String, // Name u32, // Flags (Conn_Mgr_Param_Flags) String, // Signature VarArg, // Default value ); // Requestable_Channel_Class pub type RequestableChannelSpec = ( HashMap, // Fixed properties Vec, // Allowed properties ); // FIXME: these should come from codegen //const FLAG_NONE: u32 = 0; 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; pub fn parameters() -> Vec { vec![ ( "account".to_string(), FLAG_REQUIRED, "s".to_string(), var_str("".to_string()), ), ( "password".to_string(), FLAG_REQUIRED | FLAG_SECRET, "s".to_string(), var_str("".to_string()), ), ("bcc-self".to_string(), 0, "b".to_string(), var_bool(false)), ] } 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(); rf.insert( "org.freedesktop.Telepathy.Channel.ChannelType".to_string(), var_str("org.freedesktop.Telepathy.Channel.Type.Text".to_string()), ); rf.insert( "org.freedesktop.Telepathy.Channel.TargetHandleType".to_string(), var_u32(1), ); let ra = vec![ "org.freedesktop.Telepathy.Channel.TargetHandle".to_string(), "org.freedesktop.Telepathy.Channel.TargetID".to_string(), ]; vec![(rf, ra)] } impl AsRef for std::rc::Rc { fn as_ref(&self) -> &(dyn telepathy::Protocol + 'static) { &**self } } impl telepathy::Protocol for Protocol { fn identify_account(&self, params: HashMap<&str, VarArg>) -> Result { println!("Protocol::identify_account(...)"); let settings = ConnSettings::from_params(params)?; Ok(settings.id()) } fn normalize_contact(&self, contact_id: &str) -> Result { println!("Protocol::normalize_contact({})", contact_id); Ok(dc::contact::addr_normalize(contact_id).to_string()) } fn interfaces(&self) -> Result, MethodErr> { println!("Protocol::interfaces()"); Ok(protocol_interfaces()) } fn parameters(&self) -> Result, MethodErr> { println!("Protocol::parameters()"); Ok(parameters()) } fn connection_interfaces(&self) -> Result, MethodErr> { println!("Protocol::connection_interfaces()"); Ok(super::connection_interfaces()) } fn requestable_channel_classes(&self) -> Result, MethodErr> { println!("Protocol::requestable_channel_classes()"); Ok(requestables()) } fn vcard_field(&self) -> Result { println!("Protocol::vcard_field()"); Ok("email".to_string()) } fn english_name(&self) -> Result { println!("Protocol::english_name()"); Ok("Delta Chat".to_string()) } fn icon(&self) -> Result { println!("Protocol::icon()"); Ok("im-delta".to_string()) } fn authentication_types(&self) -> Result, MethodErr> { println!("Protocol::authentication_types()"); Ok(vec![ "org.freedesktop.Telepathy.Channel.Type.ServerTLSConnection".to_string(), ]) } } 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()) } }