use crate::{InterfaceSet, ObjectRef, Role, StateSet};
use serde::{Deserialize, Serialize};
use zbus_lockstep_macros::validate;
use zbus_names::UniqueName;
use zvariant::{ObjectPath, Type};
#[allow(clippy::module_name_repetitions)]
#[derive(Clone, Debug, Serialize, Deserialize, Type, PartialEq, Eq, Hash)]
#[validate(signal: "AddAccessible")]
pub struct CacheItem {
pub object: ObjectRef,
pub app: ObjectRef,
pub parent: ObjectRef,
pub index: i32,
pub children: i32,
pub ifaces: InterfaceSet,
pub short_name: String,
pub role: Role,
pub name: String,
pub states: StateSet,
}
impl Default for CacheItem {
fn default() -> Self {
Self {
object: ObjectRef {
name: UniqueName::from_static_str(":0.0").unwrap().into(),
path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/object")
.unwrap()
.into(),
},
app: ObjectRef {
name: UniqueName::from_static_str(":0.0").unwrap().into(),
path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/application")
.unwrap()
.into(),
},
parent: ObjectRef {
name: UniqueName::from_static_str(":0.0").unwrap().into(),
path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/parent")
.unwrap()
.into(),
},
index: 0,
children: 0,
ifaces: InterfaceSet::empty(),
short_name: String::default(),
role: Role::Invalid,
name: String::default(),
states: StateSet::empty(),
}
}
}
#[allow(clippy::module_name_repetitions)]
#[derive(Clone, Debug, Serialize, Deserialize, Type, PartialEq, Eq, Hash)]
pub struct LegacyCacheItem {
pub object: ObjectRef,
pub app: ObjectRef,
pub parent: ObjectRef,
pub children: Vec<ObjectRef>,
pub ifaces: InterfaceSet,
pub short_name: String,
pub role: Role,
pub name: String,
pub states: StateSet,
}
impl Default for LegacyCacheItem {
fn default() -> Self {
Self {
object: ObjectRef {
name: UniqueName::from_static_str(":0.0").unwrap().into(),
path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/object")
.unwrap()
.into(),
},
app: ObjectRef {
name: UniqueName::from_static_str(":0.0").unwrap().into(),
path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/application")
.unwrap()
.into(),
},
parent: ObjectRef {
name: UniqueName::from_static_str(":0.0").unwrap().into(),
path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/parent")
.unwrap()
.into(),
},
children: Vec::new(),
ifaces: InterfaceSet::empty(),
short_name: String::default(),
role: Role::Invalid,
name: String::default(),
states: StateSet::empty(),
}
}
}
#[cfg(test)]
#[test]
fn zvariant_type_signature_of_legacy_cache_item() {
assert_eq!(
LegacyCacheItem::signature(),
zbus::zvariant::Signature::from_static_str("((so)(so)(so)a(so)assusau)").unwrap()
);
}