1use anyhow::format_err;
6use fidl_fuchsia_settings::IntlSettings;
7use serde::{Deserialize, Serialize};
8
9pub enum SetUiMethod {
11 IsMicMuted,
12 SetNetwork,
13 GetNetwork,
14 SetIntl,
15 GetIntl,
16 SetBrightness,
17 SetMediaVolume,
18 SetMicMute,
19}
20
21impl std::str::FromStr for SetUiMethod {
22 type Err = anyhow::Error;
23
24 fn from_str(method: &str) -> Result<Self, Self::Err> {
25 match method {
26 "SetNetwork" => Ok(SetUiMethod::SetNetwork),
27 "GetNetwork" => Ok(SetUiMethod::GetNetwork),
28 "SetIntl" => Ok(SetUiMethod::SetIntl),
29 "GetIntl" => Ok(SetUiMethod::GetIntl),
30 "IsMicMuted" => Ok(SetUiMethod::IsMicMuted),
31 "SetBrightness" => Ok(SetUiMethod::SetBrightness),
32 "SetMediaVolume" => Ok(SetUiMethod::SetMediaVolume),
33 "SetMicMute" => Ok(SetUiMethod::SetMicMute),
34 _ => return Err(format_err!("invalid SetUi SL4F method: {}", method)),
35 }
36 }
37}
38
39#[derive(Serialize, Deserialize, Debug)]
40pub enum SetUiResult {
41 Success,
42}
43
44#[derive(Serialize, Deserialize, Debug)]
45#[serde(rename_all = "snake_case")]
46pub enum NetworkType {
47 Ethernet,
48 Wifi,
49 Unknown,
50}
51
52#[derive(Serialize, Deserialize, Debug)]
53#[serde(rename_all = "snake_case")]
54pub enum MicStates {
55 Muted,
56 Available,
57 Unknown,
58}
59
60#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)]
66pub struct IntlInfo {
67 pub locales: Option<Vec<LocaleId>>,
68 pub temperature_unit: Option<TemperatureUnit>,
69 pub time_zone_id: Option<String>,
70 pub hour_cycle: Option<HourCycle>,
71}
72
73impl From<fidl_fuchsia_settings::IntlSettings> for IntlInfo {
75 fn from(src: IntlSettings) -> Self {
76 IntlInfo {
77 locales: src.locales.map_or(None, |locales| {
78 Some(locales.into_iter().map(fidl_fuchsia_intl::LocaleId::into).collect())
79 }),
80 temperature_unit: src.temperature_unit.map(fidl_fuchsia_intl::TemperatureUnit::into),
81 time_zone_id: src.time_zone_id.map_or(None, |tz| Some(tz.id)),
82 hour_cycle: src.hour_cycle.map(fidl_fuchsia_settings::HourCycle::into),
83 }
84 }
85}
86
87impl Into<fidl_fuchsia_settings::IntlSettings> for IntlInfo {
89 fn into(self) -> IntlSettings {
90 let mut intl_settings = IntlSettings::default();
91
92 intl_settings.locales = self
93 .locales
94 .map_or(None, |locales| Some(locales.into_iter().map(LocaleId::into).collect()));
95 intl_settings.temperature_unit = self.temperature_unit.map(TemperatureUnit::into);
96 intl_settings.time_zone_id =
97 self.time_zone_id.map_or(None, |tz| Some(fidl_fuchsia_intl::TimeZoneId { id: tz }));
98 intl_settings.hour_cycle = self.hour_cycle.map(HourCycle::into);
99
100 intl_settings
101 }
102}
103
104#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)]
108pub struct LocaleId {
109 pub id: String,
110}
111
112impl From<fidl_fuchsia_intl::LocaleId> for LocaleId {
113 fn from(src: fidl_fuchsia_intl::LocaleId) -> Self {
114 LocaleId { id: src.id }
115 }
116}
117
118impl From<LocaleId> for fidl_fuchsia_intl::LocaleId {
119 fn from(src: LocaleId) -> Self {
120 fidl_fuchsia_intl::LocaleId { id: src.id }
121 }
122}
123
124#[derive(PartialEq, Eq, Debug, Clone, Copy, Serialize, Deserialize)]
128pub enum TemperatureUnit {
129 Celsius,
130 Fahrenheit,
131}
132
133impl From<fidl_fuchsia_intl::TemperatureUnit> for TemperatureUnit {
134 fn from(src: fidl_fuchsia_intl::TemperatureUnit) -> Self {
135 match src {
136 fidl_fuchsia_intl::TemperatureUnit::Celsius => TemperatureUnit::Celsius,
137 fidl_fuchsia_intl::TemperatureUnit::Fahrenheit => TemperatureUnit::Fahrenheit,
138 }
139 }
140}
141
142impl From<TemperatureUnit> for fidl_fuchsia_intl::TemperatureUnit {
143 fn from(src: TemperatureUnit) -> Self {
144 match src {
145 TemperatureUnit::Celsius => fidl_fuchsia_intl::TemperatureUnit::Celsius,
146 TemperatureUnit::Fahrenheit => fidl_fuchsia_intl::TemperatureUnit::Fahrenheit,
147 }
148 }
149}
150
151#[derive(PartialEq, Eq, Debug, Clone, Copy, Serialize, Deserialize)]
157pub enum HourCycle {
158 Unknown,
159 H11,
160 H12,
161 H23,
162 H24,
163}
164
165impl From<fidl_fuchsia_settings::HourCycle> for HourCycle {
166 fn from(src: fidl_fuchsia_settings::HourCycle) -> Self {
167 match src {
168 fidl_fuchsia_settings::HourCycle::Unknown => HourCycle::Unknown,
169 fidl_fuchsia_settings::HourCycle::H11 => HourCycle::H11,
170 fidl_fuchsia_settings::HourCycle::H12 => HourCycle::H12,
171 fidl_fuchsia_settings::HourCycle::H23 => HourCycle::H23,
172 fidl_fuchsia_settings::HourCycle::H24 => HourCycle::H24,
173 }
174 }
175}
176
177impl From<HourCycle> for fidl_fuchsia_settings::HourCycle {
178 fn from(src: HourCycle) -> Self {
179 match src {
180 HourCycle::Unknown => fidl_fuchsia_settings::HourCycle::Unknown,
181 HourCycle::H11 => fidl_fuchsia_settings::HourCycle::H11,
182 HourCycle::H12 => fidl_fuchsia_settings::HourCycle::H12,
183 HourCycle::H23 => fidl_fuchsia_settings::HourCycle::H23,
184 HourCycle::H24 => fidl_fuchsia_settings::HourCycle::H24,
185 }
186 }
187}