| 1 | // Copyright 2022 The AccessKit Authors. All rights reserved. |
| 2 | // Licensed under the Apache License, Version 2.0 (found in |
| 3 | // the LICENSE-APACHE file) or the MIT license (found in |
| 4 | // the LICENSE-MIT file), at your option. |
| 5 | |
| 6 | use atspi::ObjectRef; |
| 7 | use serde::{Deserialize, Serialize}; |
| 8 | use zbus::{ |
| 9 | names::UniqueName, |
| 10 | zvariant::{ObjectPath, OwnedObjectPath, OwnedValue, Str, Type, Value}, |
| 11 | }; |
| 12 | |
| 13 | // https://gnome.pages.gitlab.gnome.org/at-spi2-core/libatspi/const.DBUS_PATH_NULL.html |
| 14 | const NULL_PATH: &str = "/org/a11y/atspi/null" ; |
| 15 | |
| 16 | #[derive (Clone, Debug, Serialize, Deserialize, PartialEq, Eq, OwnedValue, Type, Value)] |
| 17 | pub(crate) struct OwnedObjectAddress { |
| 18 | bus_name: String, |
| 19 | path: OwnedObjectPath, |
| 20 | } |
| 21 | |
| 22 | impl OwnedObjectAddress { |
| 23 | pub(crate) fn new(bus_name: &UniqueName, path: OwnedObjectPath) -> Self { |
| 24 | Self { |
| 25 | bus_name: bus_name.to_string(), |
| 26 | path, |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | pub(crate) fn null() -> Self { |
| 31 | Self { |
| 32 | bus_name: String::new(), |
| 33 | path: ObjectPath::from_str_unchecked(NULL_PATH).into(), |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | impl From<ObjectRef> for OwnedObjectAddress { |
| 39 | fn from(object: ObjectRef) -> Self { |
| 40 | Self { |
| 41 | bus_name: Str::from(object.name).into(), |
| 42 | path: object.path, |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |