atspi_common/
cache.rs

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