use rand::Rng; use std::collections::HashMap; pub const CONN_BUS_NAME: &'static str = "org.freedesktop.Telepathy.Connection.padfoot.delta"; pub const CONN_OBJECT_PATH: &'static str = "org/freedesktop/Telepathy/Connection/padfoot/delta"; #[derive(Debug)] pub struct Connection { path: String, account: String, password: String, } impl Connection { pub fn new(params: HashMap<&str, super::Variant>) -> Result { let err = Err(dbus::tree::MethodErr::no_arg()); // Generate a unique identifier for this connection let id = rand::thread_rng() .sample_iter(&rand::distributions::Alphanumeric) .take(16) .collect::(); let path = super::CONN_OBJECT_PATH.to_owned() + "/" + &id; let acct = match params.get("account") { Some(variant) => match variant.0.as_str() { Some(str) => str.to_string(), None => return err, }, None => return err, }; let password = match params.get("password") { Some(variant) => match variant.0.as_str() { Some(str) => str.to_string(), None => return err, }, None => return err, }; Ok(Connection { path: path, account: acct, password: password, }) } pub fn path(&self) -> String { return self.path.to_owned(); } }