From 4a501b2e07202f2d058cc72718f16f6fda91f8ee Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Sat, 16 May 2020 21:05:58 +0100 Subject: [PATCH] Backfill the Protocol interface --- README.md | 2 +- src/padfoot/protocol.rs | 42 +++++++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index b79c507..b81c279 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Here's where we're at right now: - [x] Disconnect! - [ ] Set up an account manually - [ ] Contacts handling -- [ ] Text messages +- [~] Text messages - [ ] Multimedia messages - [ ] Setup messages - [ ] Import/Export diff --git a/src/padfoot/protocol.rs b/src/padfoot/protocol.rs index e370885..c503d36 100644 --- a/src/padfoot/protocol.rs +++ b/src/padfoot/protocol.rs @@ -1,7 +1,12 @@ use crate::telepathy; -use dbus::{arg, tree}; + +use dbus::arg; +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"; @@ -79,62 +84,63 @@ impl AsRef for std::rc::Rc { } impl telepathy::Protocol for Protocol { - fn identify_account(&self, params: HashMap<&str, Variant>) -> Result { - println!("Protocol::identify_account({:?})", params); + fn identify_account(&self, params: HashMap<&str, Variant>) -> Result { + println!("Protocol::identify_account(...)"); - Err(tree::MethodErr::no_arg()) + let settings = ConnSettings::from_params(params)?; + + Ok(settings.id()) } - fn normalize_contact(&self, contact_id: &str) -> Result { + fn normalize_contact(&self, contact_id: &str) -> Result { println!("Protocol::normalize_contact({})", contact_id); - Err(tree::MethodErr::no_arg()) + Ok(dc::contact::addr_normalize(contact_id).to_string()) } - fn interfaces(&self) -> Result, tree::MethodErr> { + fn interfaces(&self) -> Result, MethodErr> { println!("Protocol::interfaces()"); Ok(vec![]) } - fn parameters(&self) -> Result, tree::MethodErr> { + + fn parameters(&self) -> Result, MethodErr> { println!("Protocol::parameters()"); Ok(parameters()) } - fn connection_interfaces(&self) -> Result, tree::MethodErr> { + fn connection_interfaces(&self) -> Result, MethodErr> { println!("Protocol::connection_interfaces()"); - Ok(vec![ - "org.freedesktop.Telepathy.Connection.Interface.Contacts".to_string(), - "org.freedesktop.Telepathy.Connection.Interface.Requests".to_string(), - ]) + Ok(super::connection_interfaces()) } - fn requestable_channel_classes(&self) -> Result, tree::MethodErr> { + + fn requestable_channel_classes(&self) -> Result, MethodErr> { println!("Protocol::requestable_channel_classes()"); Ok(requestables()) } - fn vcard_field(&self) -> Result { + fn vcard_field(&self) -> Result { println!("Protocol::vcard_field()"); Ok("email".to_string()) } - fn english_name(&self) -> Result { + fn english_name(&self) -> Result { println!("Protocol::english_name()"); Ok("Delta Chat".to_string()) } - fn icon(&self) -> Result { + fn icon(&self) -> Result { println!("Protocol::icon()"); Ok("im-delta".to_string()) } - fn authentication_types(&self) -> Result, tree::MethodErr> { + fn authentication_types(&self) -> Result, MethodErr> { println!("Protocol::authentication_types()"); Ok(vec![