1//! Common types for `org.a11y.atspi.Cache` events.
2//!
3
4use crate::{InterfaceSet, ObjectRef, Role, StateSet};
5use serde::{Deserialize, Serialize};
6use zbus_lockstep_macros::validate;
7use zbus_names::UniqueName;
8use zvariant::{ObjectPath, Type};
9
10/// The item type provided by `Cache:Add` signals
11#[allow(clippy::module_name_repetitions)]
12#[derive(Clone, Debug, Serialize, Deserialize, Type, PartialEq, Eq, Hash)]
13#[validate(signal: "AddAccessible")]
14pub struct CacheItem {
15 /// The accessible object (within the application) (so)
16 pub object: ObjectRef,
17 /// The application (root object(?) (so)
18 pub app: ObjectRef,
19 /// The parent object. (so)
20 pub parent: ObjectRef,
21 /// The accessbile index in parent. i
22 pub index: i32,
23 /// Child count of the accessible i
24 pub children: i32,
25 /// The exposed interface(s) set. as
26 pub ifaces: InterfaceSet,
27 /// The short localized name. s
28 pub short_name: String,
29 /// `ObjectRef` role. u
30 pub role: Role,
31 /// More detailed localized name.
32 pub name: String,
33 /// The states applicable to the accessible. au
34 pub states: StateSet,
35}
36
37impl Default for CacheItem {
38 fn default() -> Self {
39 Self {
40 object: ObjectRef {
41 name: UniqueName::from_static_str(":0.0").unwrap().into(),
42 path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/object")
43 .unwrap()
44 .into(),
45 },
46 app: ObjectRef {
47 name: UniqueName::from_static_str(":0.0").unwrap().into(),
48 path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/application")
49 .unwrap()
50 .into(),
51 },
52 parent: ObjectRef {
53 name: UniqueName::from_static_str(":0.0").unwrap().into(),
54 path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/parent")
55 .unwrap()
56 .into(),
57 },
58 index: 0,
59 children: 0,
60 ifaces: InterfaceSet::empty(),
61 short_name: String::default(),
62 role: Role::Invalid,
63 name: String::default(),
64 states: StateSet::empty(),
65 }
66 }
67}
68
69/// The item type provided by `Cache:Add` signals
70#[allow(clippy::module_name_repetitions)]
71#[derive(Clone, Debug, Serialize, Deserialize, Type, PartialEq, Eq, Hash)]
72pub struct LegacyCacheItem {
73 /// The accessible object (within the application) (so)
74 pub object: ObjectRef,
75 /// The application (root object(?) (so)
76 pub app: ObjectRef,
77 /// The parent object. (so)
78 pub parent: ObjectRef,
79 /// List of references to the accessible's children. a(so)
80 pub children: Vec<ObjectRef>,
81 /// The exposed interface(s) set. as
82 pub ifaces: InterfaceSet,
83 /// The short localized name. s
84 pub short_name: String,
85 /// `ObjectRef` role. u
86 pub role: Role,
87 /// More detailed localized name.
88 pub name: String,
89 /// The states applicable to the accessible. au
90 pub states: StateSet,
91}
92impl Default for LegacyCacheItem {
93 fn default() -> Self {
94 Self {
95 object: ObjectRef {
96 name: UniqueName::from_static_str(":0.0").unwrap().into(),
97 path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/object")
98 .unwrap()
99 .into(),
100 },
101 app: ObjectRef {
102 name: UniqueName::from_static_str(":0.0").unwrap().into(),
103 path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/application")
104 .unwrap()
105 .into(),
106 },
107 parent: ObjectRef {
108 name: UniqueName::from_static_str(":0.0").unwrap().into(),
109 path: ObjectPath::from_static_str("/org/a11y/atspi/accessible/parent")
110 .unwrap()
111 .into(),
112 },
113 children: Vec::new(),
114 ifaces: InterfaceSet::empty(),
115 short_name: String::default(),
116 role: Role::Invalid,
117 name: String::default(),
118 states: StateSet::empty(),
119 }
120 }
121}
122
123#[cfg(test)]
124#[test]
125fn zvariant_type_signature_of_legacy_cache_item() {
126 assert_eq!(
127 LegacyCacheItem::signature(),
128 zbus::zvariant::Signature::from_static_str("((so)(so)(so)a(so)assusau)").unwrap()
129 );
130}
131