Clean up dbus::arg::Variant type alias
This commit is contained in:
@@ -6,3 +6,6 @@ pub use self::connection_manager::*;
|
||||
|
||||
mod protocol;
|
||||
pub use self::protocol::*;
|
||||
|
||||
mod var_arg;
|
||||
pub use self::var_arg::*;
|
||||
|
@@ -20,6 +20,7 @@ pub use self::requests::*;
|
||||
mod simple_presence;
|
||||
pub use self::simple_presence::*;
|
||||
|
||||
use crate::padfoot::VarArg;
|
||||
use crate::telepathy;
|
||||
|
||||
use dbus::blocking::{stdintf::org_freedesktop_dbus::RequestNameReply, LocalConnection};
|
||||
@@ -60,7 +61,7 @@ pub struct ConnSettings {
|
||||
}
|
||||
|
||||
impl ConnSettings {
|
||||
pub fn from_params(params: HashMap<&str, super::Variant>) -> Result<Self, MethodErr> {
|
||||
pub fn from_params(params: HashMap<&str, VarArg>) -> Result<Self, MethodErr> {
|
||||
let err = Err(MethodErr::no_arg());
|
||||
|
||||
let account = match params.get("account") {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
use crate::padfoot::VarArg;
|
||||
use crate::telepathy;
|
||||
|
||||
use dbus::arg::{RefArg, Variant};
|
||||
use dbus::tree::MethodErr;
|
||||
use deltachat::constants::DC_GCL_ADD_SELF;
|
||||
use deltachat::contact::Contact;
|
||||
@@ -16,9 +16,6 @@ impl AsRef<dyn telepathy::ConnectionInterfaceContactList + 'static> for std::rc:
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: extract a utility module for this?
|
||||
type VarArg = Variant<Box<dyn RefArg + 'static>>;
|
||||
|
||||
// FIXME: come back and do this properly later
|
||||
impl telepathy::ConnectionInterfaceContactList for Connection {
|
||||
fn get_contact_list_attributes(
|
||||
|
@@ -1,6 +1,6 @@
|
||||
use crate::padfoot::{var_str, VarArg};
|
||||
use crate::telepathy;
|
||||
|
||||
use dbus::arg::{RefArg, Variant};
|
||||
use dbus::tree::MethodErr;
|
||||
use deltachat::contact::{Contact, Origin};
|
||||
use std::collections::HashMap;
|
||||
@@ -13,16 +13,13 @@ impl AsRef<dyn telepathy::ConnectionInterfaceContacts + 'static> for std::rc::Rc
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: extract a utility module for this?
|
||||
type VarArgs = Variant<Box<dyn RefArg + 'static>>;
|
||||
|
||||
impl telepathy::ConnectionInterfaceContacts for Connection {
|
||||
fn get_contact_attributes(
|
||||
&self,
|
||||
handles: Vec<u32>,
|
||||
interfaces: Vec<&str>,
|
||||
hold: bool,
|
||||
) -> Result<HashMap<u32, HashMap<String, VarArgs>>, MethodErr> {
|
||||
) -> Result<HashMap<u32, HashMap<String, VarArg>>, MethodErr> {
|
||||
println!(
|
||||
"Connection<{}>::get_contact_attributes({:?}, {:?}, {})",
|
||||
self.id(),
|
||||
@@ -31,7 +28,7 @@ impl telepathy::ConnectionInterfaceContacts for Connection {
|
||||
hold
|
||||
);
|
||||
|
||||
let mut out = HashMap::<u32, HashMap<String, VarArgs>>::new();
|
||||
let mut out = HashMap::<u32, HashMap<String, VarArg>>::new();
|
||||
for id in handles.iter() {
|
||||
// FIXME: work out how to use get_all
|
||||
let contact = match Contact::get_by_id(&self.ctx.read().unwrap(), *id) {
|
||||
@@ -39,28 +36,28 @@ impl telepathy::ConnectionInterfaceContacts for Connection {
|
||||
Err(_e) => continue, // Invalid IDs are silently ignored
|
||||
};
|
||||
|
||||
let mut props = HashMap::<String, VarArgs>::new();
|
||||
let mut props = HashMap::<String, VarArg>::new();
|
||||
// This is mandatory
|
||||
props.insert(
|
||||
"org.freedesktop.Telepathy.Connection/contact-id".to_string(),
|
||||
Variant(Box::new(contact.get_addr().to_string())),
|
||||
var_str(contact.get_addr().to_string()),
|
||||
);
|
||||
|
||||
// The empty string means "no avatar"
|
||||
props.insert(
|
||||
"org.freedesktop.Telepathy.Connection.Interface.Avatars/token".to_string(),
|
||||
Variant(Box::new("".to_string())),
|
||||
var_str("".to_string()),
|
||||
);
|
||||
/*
|
||||
// TODO: we need to publish DBUS services on these endpoints
|
||||
props.insert(
|
||||
"org.freedesktop.Telepathy.Connection.Interface.ContactList/publish".to_string(),
|
||||
Variant(Box::new(4)),
|
||||
var_arg(Box::new(4)),
|
||||
);
|
||||
|
||||
props.insert(
|
||||
"org.freedesktop.Telepathy.Connection.Interface.ContactList/subscribe".to_string(),
|
||||
Variant(Box::new(4)),
|
||||
var_arg(Box::new(4)),
|
||||
);
|
||||
*/
|
||||
out.insert(*id, props);
|
||||
@@ -73,7 +70,7 @@ impl telepathy::ConnectionInterfaceContacts for Connection {
|
||||
&self,
|
||||
identifier: &str,
|
||||
interfaces: Vec<&str>,
|
||||
) -> Result<(u32, HashMap<String, VarArgs>), MethodErr> {
|
||||
) -> Result<(u32, HashMap<String, VarArg>), MethodErr> {
|
||||
println!(
|
||||
"Connection<{}>::get_contact_by_id({}, {:?})",
|
||||
self.id(),
|
||||
|
@@ -1,14 +1,11 @@
|
||||
use crate::padfoot::{requestables, VarArg};
|
||||
use crate::telepathy;
|
||||
|
||||
use dbus::arg::{RefArg, Variant};
|
||||
use dbus::tree::MethodErr;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use super::Connection;
|
||||
|
||||
// TODO: extract a utility module for this?
|
||||
type VarArg = Variant<Box<dyn RefArg + 'static>>;
|
||||
|
||||
impl AsRef<dyn telepathy::ConnectionInterfaceRequests + 'static> for std::rc::Rc<Connection> {
|
||||
fn as_ref(&self) -> &(dyn telepathy::ConnectionInterfaceRequests + 'static) {
|
||||
&**self
|
||||
@@ -44,6 +41,6 @@ impl telepathy::ConnectionInterfaceRequests for Connection {
|
||||
|
||||
fn requestable_channel_classes(&self) -> Result<Vec<RequestableChannelSpec>, MethodErr> {
|
||||
println!("Connection<{}>::requestable_channel_classes()", self.id());
|
||||
Ok(crate::padfoot::requestables())
|
||||
Ok(requestables())
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
use crate::padfoot::{var_arg, var_str, var_str_vec, VarArg};
|
||||
use crate::telepathy;
|
||||
|
||||
use dbus::arg;
|
||||
use dbus::message::SignalArgs;
|
||||
use dbus::tree::MethodErr;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
@@ -114,7 +114,7 @@ impl telepathy::ConnectionManager for ConnectionManager {
|
||||
fn request_connection(
|
||||
&self,
|
||||
protocol: &str,
|
||||
params: HashMap<&str, super::Variant>,
|
||||
params: HashMap<&str, VarArg>,
|
||||
) -> Result<(String, dbus::Path<'static>), MethodErr> {
|
||||
println!("CM::request_connection({}, ...)", protocol);
|
||||
|
||||
@@ -124,48 +124,48 @@ impl telepathy::ConnectionManager for ConnectionManager {
|
||||
}
|
||||
}
|
||||
|
||||
fn protocols(&self) -> Result<HashMap<String, HashMap<String, super::Variant>>, MethodErr> {
|
||||
fn protocols(&self) -> Result<HashMap<String, HashMap<String, VarArg>>, MethodErr> {
|
||||
println!("CM::protocols()");
|
||||
|
||||
// FIXME: so much duplication. It would be good if we could get the
|
||||
// properties from the Protocol instead
|
||||
let mut out = HashMap::<String, HashMap<String, super::Variant>>::new();
|
||||
let mut props = HashMap::<String, super::Variant>::new();
|
||||
let mut out = HashMap::<String, HashMap<String, VarArg>>::new();
|
||||
let mut props = HashMap::<String, VarArg>::new();
|
||||
|
||||
props.insert(
|
||||
"org.freedesktop.Telepathy.Protocol.AuthenticationTypes".to_string(),
|
||||
arg::Variant(Box::new(vec![
|
||||
var_str_vec(vec![
|
||||
"org.freedesktop.Telepathy.Channel.Type.ServerTLSConnection".to_string(),
|
||||
])),
|
||||
]),
|
||||
);
|
||||
|
||||
props.insert(
|
||||
"org.freedesktop.Telepathy.Protocol.ConnectionInterfaces".to_string(),
|
||||
arg::Variant(Box::new(super::connection_interfaces())),
|
||||
var_str_vec(super::connection_interfaces()),
|
||||
);
|
||||
props.insert(
|
||||
"org.freedesktop.Telepathy.Protocol.EnglishName".to_string(),
|
||||
arg::Variant(Box::new("Delta Chat".to_string())),
|
||||
var_str("Delta Chat".to_string()),
|
||||
);
|
||||
props.insert(
|
||||
"org.freedesktop.Telepathy.Protocol.Icon".to_string(),
|
||||
arg::Variant(Box::new("im-delta".to_string())),
|
||||
var_str("im-delta".to_string()),
|
||||
);
|
||||
props.insert(
|
||||
"org.freedesktop.Telepathy.Protocol.Interfaces".to_string(),
|
||||
arg::Variant(Box::new(super::protocol_interfaces())),
|
||||
var_str_vec(super::protocol_interfaces()),
|
||||
);
|
||||
props.insert(
|
||||
"org.freedesktop.Telepathy.Protocol.Parameters".to_string(),
|
||||
arg::Variant(Box::new(super::parameters())),
|
||||
var_arg(Box::new(super::parameters())),
|
||||
);
|
||||
props.insert(
|
||||
"org.freedesktop.Telepathy.Protocol.RequestableChannelClasses".to_string(),
|
||||
arg::Variant(Box::new(super::requestables())),
|
||||
var_arg(Box::new(super::requestables())),
|
||||
);
|
||||
props.insert(
|
||||
"org.freedesktop.Telepathy.Protocol.VCardField".to_string(),
|
||||
arg::Variant(Box::new("email".to_string())),
|
||||
var_str("email".to_string()),
|
||||
);
|
||||
|
||||
out.insert(super::PROTO_NAME.to_string(), props);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
use crate::padfoot::{var_str, var_u32, VarArg};
|
||||
use crate::telepathy;
|
||||
|
||||
use dbus::arg;
|
||||
use dbus::tree::MethodErr;
|
||||
use deltachat as dc;
|
||||
use std::collections::HashMap;
|
||||
@@ -14,19 +14,17 @@ pub const PROTO_NAME: &str = "delta";
|
||||
#[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
|
||||
VarArg, // Default value
|
||||
);
|
||||
|
||||
// Requestable_Channel_Class
|
||||
pub type RequestableChannelSpec = (
|
||||
HashMap<String, Variant>, // Fixed properties
|
||||
Vec<String>, // Allowed properties
|
||||
HashMap<String, VarArg>, // Fixed properties
|
||||
Vec<String>, // Allowed properties
|
||||
);
|
||||
|
||||
// FIXME: these should come from codegen
|
||||
@@ -43,13 +41,13 @@ pub fn parameters() -> Vec<ParamSpec> {
|
||||
"account".to_string(),
|
||||
FLAG_REQUIRED,
|
||||
"s".to_string(),
|
||||
arg::Variant(Box::new("".to_string())),
|
||||
var_str("".to_string()),
|
||||
),
|
||||
(
|
||||
"password".to_string(),
|
||||
FLAG_REQUIRED | FLAG_SECRET,
|
||||
"s".to_string(),
|
||||
arg::Variant(Box::new("".to_string())),
|
||||
var_str("".to_string()),
|
||||
),
|
||||
]
|
||||
}
|
||||
@@ -62,19 +60,14 @@ pub fn protocol_interfaces() -> Vec<String> {
|
||||
}
|
||||
|
||||
pub fn requestables() -> Vec<RequestableChannelSpec> {
|
||||
let mut rf = HashMap::<String, Variant>::new();
|
||||
let mut rf = HashMap::<String, VarArg>::new();
|
||||
|
||||
rf.insert(
|
||||
"org.freedesktop.Telepathy.Channel.ChannelType".to_string(),
|
||||
arg::Variant(Box::new(
|
||||
"org.freedesktop.Telepathy.Channel.Type.Text".to_string(),
|
||||
)),
|
||||
var_str("org.freedesktop.Telepathy.Channel.Type.Text".to_string()),
|
||||
);
|
||||
|
||||
rf.insert(
|
||||
"org.freedesktop.Telepathy.Channel.TargetHandleType".to_string(),
|
||||
arg::Variant(Box::new(1)),
|
||||
);
|
||||
rf.insert("org.freedesktop.Telepathy.Channel.TargetHandleType".to_string(), var_u32(1));
|
||||
|
||||
let ra = vec![
|
||||
"org.freedesktop.Telepathy.Channel.TargetHandle".to_string(),
|
||||
@@ -91,7 +84,7 @@ impl AsRef<dyn telepathy::Protocol + 'static> for std::rc::Rc<Protocol> {
|
||||
}
|
||||
|
||||
impl telepathy::Protocol for Protocol {
|
||||
fn identify_account(&self, params: HashMap<&str, Variant>) -> Result<String, MethodErr> {
|
||||
fn identify_account(&self, params: HashMap<&str, VarArg>) -> Result<String, MethodErr> {
|
||||
println!("Protocol::identify_account(...)");
|
||||
|
||||
let settings = ConnSettings::from_params(params)?;
|
||||
|
19
src/padfoot/var_arg.rs
Normal file
19
src/padfoot/var_arg.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use dbus::arg::{RefArg, Variant};
|
||||
|
||||
pub type VarArg = Variant<Box<dyn RefArg + 'static>>;
|
||||
|
||||
pub fn var_arg(item: Box<dyn RefArg + 'static>) -> VarArg {
|
||||
Variant(item)
|
||||
}
|
||||
|
||||
pub fn var_str(item: String) -> VarArg {
|
||||
var_arg(Box::new(item))
|
||||
}
|
||||
|
||||
pub fn var_str_vec(item: Vec<String>) -> VarArg {
|
||||
var_arg(Box::new(item))
|
||||
}
|
||||
|
||||
pub fn var_u32(item: u32) -> VarArg {
|
||||
var_arg(Box::new(item))
|
||||
}
|
Reference in New Issue
Block a user