Without this, telepathy-glib/empathy doesn't believe the protocol is bonafide (i.e., implementing TP_PROTOCOL_FEATURE_CORE). Adding a dummy gets empathy to display the protocol without needing to be patched \o/.
137 lines
3.7 KiB
Rust
137 lines
3.7 KiB
Rust
use crate::telepathy;
|
|
use dbus::{arg, tree};
|
|
use std::collections::HashMap;
|
|
|
|
#[derive(Debug)]
|
|
pub struct Protocol {}
|
|
|
|
pub type Variant = arg::Variant<Box<dyn arg::RefArg + 'static>>;
|
|
|
|
pub type ParamSpec = (
|
|
String, // Name
|
|
u32, // Flags (Conn_Mgr_Param_Flags)
|
|
String, // Signature
|
|
Variant, // Default
|
|
);
|
|
|
|
pub type RequestableChannelSpec = (
|
|
// Requestable_Channel_Class
|
|
HashMap<String, Variant>, // Fixed properties
|
|
Vec<String>, // Allowed properties
|
|
);
|
|
|
|
pub const NAME: &'static str = "delta";
|
|
|
|
// 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<ParamSpec> {
|
|
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())),
|
|
),
|
|
]
|
|
}
|
|
|
|
pub fn requestables() -> Vec<RequestableChannelSpec> {
|
|
let mut rf = HashMap::<String, Variant>::new();
|
|
|
|
rf.insert(
|
|
"org.freedesktop.Telepathy.Channel.ChannelType".to_string(),
|
|
arg::Variant(Box::new(
|
|
"org.freedesktop.Telepathy.Channel.Type.Text".to_string(),
|
|
)),
|
|
);
|
|
|
|
rf.insert(
|
|
"org.freedesktop.Telepathy.Channel.TargetHandleType".to_string(),
|
|
arg::Variant(Box::new(1)),
|
|
);
|
|
|
|
let ra = vec![
|
|
"org.freedesktop.Telepathy.Channel.TargetHandle".to_string(),
|
|
"org.freedesktop.Telepathy.Channel.TargetID".to_string(),
|
|
];
|
|
|
|
vec![(rf, ra)]
|
|
}
|
|
|
|
impl telepathy::Protocol for Protocol {
|
|
fn identify_account(&self, params: HashMap<&str, Variant>) -> Result<String, tree::MethodErr> {
|
|
println!("Protocol::identify_account({:?})", params);
|
|
|
|
Err(tree::MethodErr::no_arg())
|
|
}
|
|
|
|
fn normalize_contact(&self, contact_id: &str) -> Result<String, tree::MethodErr> {
|
|
println!("Protocol::normalize_contact({})", contact_id);
|
|
|
|
Err(tree::MethodErr::no_arg())
|
|
}
|
|
|
|
fn interfaces(&self) -> Result<Vec<String>, tree::MethodErr> {
|
|
println!("Protocol::interfaces()");
|
|
|
|
Ok(vec![])
|
|
}
|
|
fn parameters(&self) -> Result<Vec<ParamSpec>, tree::MethodErr> {
|
|
println!("Protocol::parameters()");
|
|
|
|
Ok(parameters())
|
|
}
|
|
|
|
fn connection_interfaces(&self) -> Result<Vec<String>, tree::MethodErr> {
|
|
println!("Protocol::connection_interfaces()");
|
|
|
|
Ok(vec![
|
|
"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> {
|
|
println!("Protocol::requestable_channel_classes()");
|
|
|
|
Ok(requestables())
|
|
}
|
|
|
|
fn vcard_field(&self) -> Result<String, tree::MethodErr> {
|
|
println!("Protocol::vcard_field()");
|
|
|
|
Ok("email".to_string())
|
|
}
|
|
|
|
fn english_name(&self) -> Result<String, tree::MethodErr> {
|
|
println!("Protocol::english_name()");
|
|
|
|
Ok("Delta Chat".to_string())
|
|
}
|
|
|
|
fn icon(&self) -> Result<String, tree::MethodErr> {
|
|
println!("Protocol::icon()");
|
|
|
|
Ok("im-delta".to_string())
|
|
}
|
|
|
|
fn authentication_types(&self) -> Result<Vec<String>, tree::MethodErr> {
|
|
println!("Protocol::authentication_types()");
|
|
|
|
Ok(vec![
|
|
"org.freedesktop.Telepathy.Channel.Type.ServerTLSConnection".to_string(),
|
|
])
|
|
}
|
|
}
|