use crate::{
accessible::AccessibleProxy, action::ActionProxy, application::ApplicationProxy,
cache::CacheProxy, collection::CollectionProxy, component::ComponentProxy,
document::DocumentProxy, editable_text::EditableTextProxy, hyperlink::HyperlinkProxy,
hypertext::HypertextProxy, image::ImageProxy, selection::SelectionProxy, table::TableProxy,
table_cell::TableCellProxy, text::TextProxy, value::ValueProxy, AtspiError,
};
use atspi_common::{Interface, InterfaceSet, Result};
pub trait ProxyExt<'a> {
fn proxies(&self) -> impl std::future::Future<Output = Result<Proxies<'a>>>;
}
#[derive(Clone, Debug)]
pub struct Proxies<'a> {
interfaces: InterfaceSet,
proxy: zbus::Proxy<'a>,
}
impl<'a> ProxyExt<'a> for AccessibleProxy<'a> {
async fn proxies(&self) -> Result<Proxies<'a>> {
let iface_set: InterfaceSet = self.get_interfaces().await?;
let proxy = self.inner().clone();
Ok(Proxies { interfaces: iface_set, proxy })
}
}
impl<'a> Proxies<'a> {
pub async fn action(&self) -> Result<ActionProxy<'a>> {
if self.interfaces.contains(Interface::Action) {
Ok(ActionProxy::builder(self.proxy.connection())
.cache_properties(zbus::proxy::CacheProperties::No)
.destination(self.proxy.destination())?
.path(self.proxy.path())?
.build()
.await?)
} else {
Err(AtspiError::InterfaceNotAvailable("Action"))
}
}
pub async fn application(&self) -> Result<ApplicationProxy<'a>> {
if self.interfaces.contains(Interface::Application) {
Ok(ApplicationProxy::builder(self.proxy.connection())
.cache_properties(zbus::proxy::CacheProperties::No)
.destination(self.proxy.destination())?
.path(self.proxy.path())?
.build()
.await?)
} else {
Err(AtspiError::InterfaceNotAvailable("Application"))
}
}
pub async fn cache(&self) -> Result<CacheProxy<'a>> {
if self.interfaces.contains(Interface::Cache) {
Ok(CacheProxy::builder(self.proxy.connection())
.cache_properties(zbus::proxy::CacheProperties::No)
.destination(self.proxy.destination())?
.path(self.proxy.path())?
.build()
.await?)
} else {
Err(AtspiError::InterfaceNotAvailable("Cache"))
}
}
pub async fn collection(&self) -> Result<CollectionProxy<'a>> {
if self.interfaces.contains(Interface::Collection) {
Ok(CollectionProxy::builder(self.proxy.connection())
.cache_properties(zbus::proxy::CacheProperties::No)
.destination(self.proxy.destination())?
.path(self.proxy.path())?
.build()
.await?)
} else {
Err(AtspiError::InterfaceNotAvailable("Collection"))
}
}
pub async fn component(&self) -> Result<ComponentProxy<'a>> {
if self.interfaces.contains(Interface::Component) {
Ok(ComponentProxy::builder(self.proxy.connection())
.cache_properties(zbus::proxy::CacheProperties::No)
.destination(self.proxy.destination())?
.path(self.proxy.path())?
.build()
.await?)
} else {
Err(AtspiError::InterfaceNotAvailable("Component"))
}
}
pub async fn document(&self) -> Result<DocumentProxy<'a>> {
if self.interfaces.contains(Interface::Document) {
Ok(DocumentProxy::builder(self.proxy.connection())
.cache_properties(zbus::proxy::CacheProperties::No)
.destination(self.proxy.destination())?
.path(self.proxy.path())?
.build()
.await?)
} else {
Err(AtspiError::InterfaceNotAvailable("Document"))
}
}
pub async fn editable_text(&self) -> Result<EditableTextProxy<'a>> {
if self.interfaces.contains(Interface::EditableText) {
Ok(EditableTextProxy::builder(self.proxy.connection())
.cache_properties(zbus::proxy::CacheProperties::No)
.destination(self.proxy.destination())?
.path(self.proxy.path())?
.build()
.await?)
} else {
Err(AtspiError::InterfaceNotAvailable("EditableText"))
}
}
pub async fn hyperlink(&self) -> Result<HyperlinkProxy<'a>> {
if self.interfaces.contains(Interface::Hyperlink) {
Ok(HyperlinkProxy::builder(self.proxy.connection())
.cache_properties(zbus::proxy::CacheProperties::No)
.destination(self.proxy.destination())?
.path(self.proxy.path())?
.build()
.await?)
} else {
Err(AtspiError::InterfaceNotAvailable("Hyperlink"))
}
}
pub async fn hypertext(&self) -> Result<HypertextProxy<'a>> {
if self.interfaces.contains(Interface::Hypertext) {
Ok(HypertextProxy::builder(self.proxy.connection())
.cache_properties(zbus::proxy::CacheProperties::No)
.destination(self.proxy.destination())?
.path(self.proxy.path())?
.build()
.await?)
} else {
Err(AtspiError::InterfaceNotAvailable("Hypertext"))
}
}
pub async fn image(&self) -> Result<ImageProxy<'a>> {
if self.interfaces.contains(Interface::Image) {
Ok(ImageProxy::builder(self.proxy.connection())
.cache_properties(zbus::proxy::CacheProperties::No)
.destination(self.proxy.destination())?
.path(self.proxy.path())?
.build()
.await?)
} else {
Err(AtspiError::InterfaceNotAvailable("Image"))
}
}
pub async fn selection(&self) -> Result<SelectionProxy<'a>> {
if self.interfaces.contains(Interface::Selection) {
Ok(SelectionProxy::builder(self.proxy.connection())
.cache_properties(zbus::proxy::CacheProperties::No)
.destination(self.proxy.destination())?
.path(self.proxy.path())?
.build()
.await?)
} else {
Err(AtspiError::InterfaceNotAvailable("Selection"))
}
}
pub async fn table(&self) -> Result<TableProxy<'a>> {
if self.interfaces.contains(Interface::Table) {
Ok(TableProxy::builder(self.proxy.connection())
.cache_properties(zbus::proxy::CacheProperties::No)
.destination(self.proxy.destination())?
.path(self.proxy.path())?
.build()
.await?)
} else {
Err(AtspiError::InterfaceNotAvailable("Table"))
}
}
pub async fn table_cell(&self) -> Result<TableCellProxy<'a>> {
if self.interfaces.contains(Interface::TableCell) {
Ok(TableCellProxy::builder(self.proxy.connection())
.cache_properties(zbus::proxy::CacheProperties::No)
.destination(self.proxy.destination())?
.path(self.proxy.path())?
.build()
.await?)
} else {
Err(AtspiError::InterfaceNotAvailable("TableCell"))
}
}
pub async fn text(&self) -> Result<TextProxy<'a>> {
if self.interfaces.contains(Interface::Text) {
Ok(TextProxy::builder(self.proxy.connection())
.cache_properties(zbus::proxy::CacheProperties::No)
.destination(self.proxy.destination())?
.path(self.proxy.path())?
.build()
.await?)
} else {
Err(AtspiError::InterfaceNotAvailable("Text"))
}
}
pub async fn value(&self) -> Result<ValueProxy<'a>> {
if self.interfaces.contains(Interface::Value) {
Ok(ValueProxy::builder(self.proxy.connection())
.cache_properties(zbus::proxy::CacheProperties::No)
.destination(self.proxy.destination())?
.path(self.proxy.path())?
.build()
.await?)
} else {
Err(AtspiError::InterfaceNotAvailable("Value"))
}
}
}