accesskit_unix/atspi/interfaces/
action.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2022 The AccessKit Authors. All rights reserved.
// Licensed under the Apache License, Version 2.0 (found in
// the LICENSE-APACHE file) or the MIT license (found in
// the LICENSE-MIT file), at your option.

use accesskit_atspi_common::{Action, PlatformNode};
use zbus::{dbus_interface, fdo};

pub(crate) struct ActionInterface(PlatformNode);

impl ActionInterface {
    pub fn new(node: PlatformNode) -> Self {
        Self(node)
    }

    fn map_error(&self) -> impl '_ + FnOnce(accesskit_atspi_common::Error) -> fdo::Error {
        |error| crate::util::map_error_from_node(&self.0, error)
    }
}

#[dbus_interface(name = "org.a11y.atspi.Action")]
impl ActionInterface {
    #[dbus_interface(property)]
    fn n_actions(&self) -> fdo::Result<i32> {
        self.0.n_actions().map_err(self.map_error())
    }

    fn get_description(&self, _index: i32) -> &str {
        ""
    }

    fn get_name(&self, index: i32) -> fdo::Result<String> {
        self.0.action_name(index).map_err(self.map_error())
    }

    fn get_localized_name(&self, index: i32) -> fdo::Result<String> {
        self.0.action_name(index).map_err(self.map_error())
    }

    fn get_key_binding(&self, _index: i32) -> &str {
        ""
    }

    fn get_actions(&self) -> fdo::Result<Vec<Action>> {
        self.0.actions().map_err(self.map_error())
    }

    fn do_action(&self, index: i32) -> fdo::Result<bool> {
        self.0.do_action(index).map_err(self.map_error())
    }
}