1use crate::{object_ref::ObjectRefOwned, InterfaceSet, ObjectRef, Role, StateSet};
5use serde::{Deserialize, Serialize};
6use zbus_lockstep_macros::validate;
7use zvariant::Type;
8
9#[allow(clippy::module_name_repetitions)]
11#[derive(Clone, Debug, Serialize, Deserialize, Type, PartialEq, Eq, Hash)]
12#[validate(signal: "AddAccessible")]
13pub struct CacheItem {
14 pub object: ObjectRefOwned,
16 pub app: ObjectRefOwned,
18 pub parent: ObjectRefOwned,
20 pub index: i32,
22 pub children: i32,
24 pub ifaces: InterfaceSet,
26 pub short_name: String,
28 pub role: Role,
30 pub name: String,
32 pub states: StateSet,
34}
35
36impl Default for CacheItem {
37 fn default() -> Self {
38 Self {
39 object: ObjectRefOwned::from_static_str_unchecked(
40 ":0.0",
41 "/org/a11y/atspi/accessible/object",
42 ),
43 app: ObjectRefOwned::from_static_str_unchecked(
44 ":0.0",
45 "/org/a11y/atspi/accessible/application",
46 ),
47 parent: ObjectRefOwned::from_static_str_unchecked(
48 ":0.0",
49 "/org/a11y/atspi/accessible/parent",
50 ),
51 index: 0,
52 children: 0,
53 ifaces: InterfaceSet::empty(),
54 short_name: String::default(),
55 role: Role::Invalid,
56 name: String::default(),
57 states: StateSet::empty(),
58 }
59 }
60}
61
62#[allow(clippy::module_name_repetitions)]
64#[derive(Clone, Debug, Serialize, Deserialize, Type, PartialEq, Eq, Hash)]
65pub struct LegacyCacheItem {
66 pub object: ObjectRefOwned,
68 pub app: ObjectRefOwned,
70 pub parent: ObjectRefOwned,
72 pub children: Vec<ObjectRefOwned>,
74 pub ifaces: InterfaceSet,
76 pub short_name: String,
78 pub role: Role,
80 pub name: String,
82 pub states: StateSet,
84}
85
86impl Default for LegacyCacheItem {
87 fn default() -> Self {
88 Self {
89 object: ObjectRef::from_static_str_unchecked(
90 ":0.0",
91 "/org/a11y/atspi/accessible/object",
92 )
93 .into(),
94 app: ObjectRef::from_static_str_unchecked(
95 ":0.0",
96 "/org/a11y/atspi/accessible/application",
97 )
98 .into(),
99 parent: ObjectRef::from_static_str_unchecked(
100 ":0.0",
101 "/org/a11y/atspi/accessible/parent",
102 )
103 .into(),
104 children: Vec::new(),
105 ifaces: InterfaceSet::empty(),
106 short_name: String::default(),
107 role: Role::Invalid,
108 name: String::default(),
109 states: StateSet::empty(),
110 }
111 }
112}
113
114#[cfg(test)]
115#[test]
116fn zvariant_type_signature_of_legacy_cache_item() {
117 use std::str::FromStr;
118 assert_eq!(
119 *<LegacyCacheItem as Type>::SIGNATURE,
120 zbus::zvariant::Signature::from_str("((so)(so)(so)a(so)assusau)").unwrap()
121 );
122}