Compare commits
2 Commits
9473a13b65
...
011ee98340
Author | SHA1 | Date | |
---|---|---|---|
011ee98340 | |||
4a501b2e07 |
@@ -34,7 +34,7 @@ Here's where we're at right now:
|
|||||||
- [x] Disconnect!
|
- [x] Disconnect!
|
||||||
- [ ] Set up an account manually
|
- [ ] Set up an account manually
|
||||||
- [ ] Contacts handling
|
- [ ] Contacts handling
|
||||||
- [ ] Text messages
|
- [~] Text messages
|
||||||
- [ ] Multimedia messages
|
- [ ] Multimedia messages
|
||||||
- [ ] Setup messages
|
- [ ] Setup messages
|
||||||
- [ ] Import/Export
|
- [ ] Import/Export
|
||||||
|
11
src/main.rs
11
src/main.rs
@@ -13,6 +13,7 @@ use padfoot::{
|
|||||||
};
|
};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
// TODO: move this to the ConnectionManager?
|
||||||
fn run() -> Result<()> {
|
fn run() -> Result<()> {
|
||||||
let (cm, msg_r) = ConnectionManager::new();
|
let (cm, msg_r) = ConnectionManager::new();
|
||||||
let cm_rc = std::rc::Rc::new(cm);
|
let cm_rc = std::rc::Rc::new(cm);
|
||||||
@@ -24,7 +25,12 @@ fn run() -> Result<()> {
|
|||||||
let mut tree = f.tree(());
|
let mut tree = f.tree(());
|
||||||
|
|
||||||
let cm_iface = telepathy::connection_manager_server(&f, (), move |_| cm_rc.clone());
|
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(
|
tree = tree.add(
|
||||||
f.object_path(CM_OBJECT_PATH, ())
|
f.object_path(CM_OBJECT_PATH, ())
|
||||||
@@ -34,7 +40,8 @@ fn run() -> Result<()> {
|
|||||||
tree = tree.add(
|
tree = tree.add(
|
||||||
f.object_path(PROTO_OBJECT_PATH, ())
|
f.object_path(PROTO_OBJECT_PATH, ())
|
||||||
.introspectable()
|
.introspectable()
|
||||||
.add(proto_iface),
|
.add(proto_iface)
|
||||||
|
.add(proto_presence_iface),
|
||||||
);
|
);
|
||||||
|
|
||||||
tree = tree.add(f.object_path("/", ()).introspectable());
|
tree = tree.add(f.object_path("/", ()).introspectable());
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::padfoot::{statuses, SimpleStatusSpec};
|
||||||
use crate::telepathy;
|
use crate::telepathy;
|
||||||
|
|
||||||
use dbus::tree::MethodErr;
|
use dbus::tree::MethodErr;
|
||||||
@@ -11,12 +12,6 @@ pub type SimplePresenceSpec = (
|
|||||||
String, // status message
|
String, // status message
|
||||||
);
|
);
|
||||||
|
|
||||||
pub type SimpleStatusSpec = (
|
|
||||||
u32, // connection presence type
|
|
||||||
bool, // may set on self?
|
|
||||||
bool, // can have message?
|
|
||||||
);
|
|
||||||
|
|
||||||
impl AsRef<dyn telepathy::ConnectionInterfaceSimplePresence + 'static> for std::rc::Rc<Connection> {
|
impl AsRef<dyn telepathy::ConnectionInterfaceSimplePresence + 'static> for std::rc::Rc<Connection> {
|
||||||
fn as_ref(&self) -> &(dyn telepathy::ConnectionInterfaceSimplePresence + 'static) {
|
fn as_ref(&self) -> &(dyn telepathy::ConnectionInterfaceSimplePresence + 'static) {
|
||||||
&**self
|
&**self
|
||||||
@@ -55,12 +50,7 @@ impl telepathy::ConnectionInterfaceSimplePresence for Connection {
|
|||||||
fn statuses(&self) -> Result<HashMap<String, SimpleStatusSpec>, MethodErr> {
|
fn statuses(&self) -> Result<HashMap<String, SimpleStatusSpec>, MethodErr> {
|
||||||
println!("Connection<{}>::statuses()", self.id());
|
println!("Connection<{}>::statuses()", self.id());
|
||||||
|
|
||||||
let mut out = HashMap::<String, SimpleStatusSpec>::new();
|
Ok(statuses())
|
||||||
|
|
||||||
out.insert("available".to_string(), (2, true, false));
|
|
||||||
out.insert("offline".to_string(), (1, true, false));
|
|
||||||
|
|
||||||
Ok(out)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn maximum_status_message_length(&self) -> Result<u32, MethodErr> {
|
fn maximum_status_message_length(&self) -> Result<u32, MethodErr> {
|
||||||
|
@@ -1,7 +1,12 @@
|
|||||||
use crate::telepathy;
|
use crate::telepathy;
|
||||||
use dbus::{arg, tree};
|
|
||||||
|
use dbus::arg;
|
||||||
|
use dbus::tree::MethodErr;
|
||||||
|
use deltachat as dc;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use super::ConnSettings;
|
||||||
|
|
||||||
pub const PROTO_OBJECT_PATH: &str = "/org/freedesktop/Telepathy/ConnectionManager/padfoot/delta";
|
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_BUS_NAME: &str = "org.freedesktop.Telepathy.ConnectionManager.padfoot.delta";
|
||||||
pub const PROTO_NAME: &str = "delta";
|
pub const PROTO_NAME: &str = "delta";
|
||||||
@@ -49,6 +54,13 @@ pub fn parameters() -> Vec<ParamSpec> {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn protocol_interfaces() -> Vec<String> {
|
||||||
|
vec![
|
||||||
|
"org.freedesktop.Telepathy.Protocol".to_string(),
|
||||||
|
"org.freedesktop.Telepathy.Protocol.Interface.Presence".to_string(),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
pub fn requestables() -> Vec<RequestableChannelSpec> {
|
pub fn requestables() -> Vec<RequestableChannelSpec> {
|
||||||
let mut rf = HashMap::<String, Variant>::new();
|
let mut rf = HashMap::<String, Variant>::new();
|
||||||
|
|
||||||
@@ -79,62 +91,63 @@ impl AsRef<dyn telepathy::Protocol + 'static> for std::rc::Rc<Protocol> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl telepathy::Protocol for Protocol {
|
impl telepathy::Protocol for Protocol {
|
||||||
fn identify_account(&self, params: HashMap<&str, Variant>) -> Result<String, tree::MethodErr> {
|
fn identify_account(&self, params: HashMap<&str, Variant>) -> Result<String, MethodErr> {
|
||||||
println!("Protocol::identify_account({:?})", params);
|
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<String, tree::MethodErr> {
|
fn normalize_contact(&self, contact_id: &str) -> Result<String, MethodErr> {
|
||||||
println!("Protocol::normalize_contact({})", contact_id);
|
println!("Protocol::normalize_contact({})", contact_id);
|
||||||
|
|
||||||
Err(tree::MethodErr::no_arg())
|
Ok(dc::contact::addr_normalize(contact_id).to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interfaces(&self) -> Result<Vec<String>, tree::MethodErr> {
|
fn interfaces(&self) -> Result<Vec<String>, MethodErr> {
|
||||||
println!("Protocol::interfaces()");
|
println!("Protocol::interfaces()");
|
||||||
|
|
||||||
Ok(vec![])
|
Ok(protocol_interfaces())
|
||||||
}
|
}
|
||||||
fn parameters(&self) -> Result<Vec<ParamSpec>, tree::MethodErr> {
|
|
||||||
|
fn parameters(&self) -> Result<Vec<ParamSpec>, MethodErr> {
|
||||||
println!("Protocol::parameters()");
|
println!("Protocol::parameters()");
|
||||||
|
|
||||||
Ok(parameters())
|
Ok(parameters())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn connection_interfaces(&self) -> Result<Vec<String>, tree::MethodErr> {
|
fn connection_interfaces(&self) -> Result<Vec<String>, MethodErr> {
|
||||||
println!("Protocol::connection_interfaces()");
|
println!("Protocol::connection_interfaces()");
|
||||||
|
|
||||||
Ok(vec![
|
Ok(super::connection_interfaces())
|
||||||
"org.freedesktop.Telepathy.Connection.Interface.Contacts".to_string(),
|
|
||||||
"org.freedesktop.Telepathy.Connection.Interface.Requests".to_string(),
|
|
||||||
])
|
|
||||||
}
|
}
|
||||||
fn requestable_channel_classes(&self) -> Result<Vec<RequestableChannelSpec>, tree::MethodErr> {
|
|
||||||
|
fn requestable_channel_classes(&self) -> Result<Vec<RequestableChannelSpec>, MethodErr> {
|
||||||
println!("Protocol::requestable_channel_classes()");
|
println!("Protocol::requestable_channel_classes()");
|
||||||
|
|
||||||
Ok(requestables())
|
Ok(requestables())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn vcard_field(&self) -> Result<String, tree::MethodErr> {
|
fn vcard_field(&self) -> Result<String, MethodErr> {
|
||||||
println!("Protocol::vcard_field()");
|
println!("Protocol::vcard_field()");
|
||||||
|
|
||||||
Ok("email".to_string())
|
Ok("email".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn english_name(&self) -> Result<String, tree::MethodErr> {
|
fn english_name(&self) -> Result<String, MethodErr> {
|
||||||
println!("Protocol::english_name()");
|
println!("Protocol::english_name()");
|
||||||
|
|
||||||
Ok("Delta Chat".to_string())
|
Ok("Delta Chat".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn icon(&self) -> Result<String, tree::MethodErr> {
|
fn icon(&self) -> Result<String, MethodErr> {
|
||||||
println!("Protocol::icon()");
|
println!("Protocol::icon()");
|
||||||
|
|
||||||
Ok("im-delta".to_string())
|
Ok("im-delta".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn authentication_types(&self) -> Result<Vec<String>, tree::MethodErr> {
|
fn authentication_types(&self) -> Result<Vec<String>, MethodErr> {
|
||||||
println!("Protocol::authentication_types()");
|
println!("Protocol::authentication_types()");
|
||||||
|
|
||||||
Ok(vec![
|
Ok(vec![
|
||||||
@@ -142,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<String, SimpleStatusSpec> {
|
||||||
|
let mut out = HashMap::<String, SimpleStatusSpec>::new();
|
||||||
|
|
||||||
|
out.insert("available".to_string(), (2, true, false));
|
||||||
|
out.insert("offline".to_string(), (1, true, false));
|
||||||
|
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsRef<dyn telepathy::ProtocolInterfacePresence + 'static> for std::rc::Rc<Protocol> {
|
||||||
|
fn as_ref(&self) -> &(dyn telepathy::ProtocolInterfacePresence + 'static) {
|
||||||
|
&**self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl telepathy::ProtocolInterfacePresence for Protocol {
|
||||||
|
fn statuses(&self) -> Result<HashMap<String, SimpleStatusSpec>, MethodErr> {
|
||||||
|
println!("Protocol::presences()");
|
||||||
|
|
||||||
|
Ok(statuses())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user