Compare commits
2 Commits
| Author | SHA256 | Date | |
|---|---|---|---|
| bc46f042dc | |||
| dae1586636 |
@@ -26,7 +26,7 @@ use iced::{Alignment, widget};
|
||||
use rust_i18n::t;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{stage, theme};
|
||||
use crate::stage;
|
||||
use crate::stage::StageResult;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -83,8 +83,8 @@ impl LicenseStage {
|
||||
widget::text(t!("license.accept_text")),
|
||||
widget::container(widget::text(t!("license.license")))
|
||||
.padding(10)
|
||||
.style(theme::text_with_border)
|
||||
].align_x(Alignment::Center).padding(20).spacing(5))
|
||||
.style(widget::container::bordered_box)
|
||||
].align_x(Alignment::Center).padding(20).spacing(10))
|
||||
.height(iced::Length::Fill)
|
||||
.width(iced::Length::Fill)
|
||||
.align_x(Alignment::Center)
|
||||
|
||||
@@ -71,7 +71,7 @@ pub enum UpdateResult {
|
||||
fn check_connection_blocking() -> CheckResult {
|
||||
use std::process::Command;
|
||||
|
||||
std::thread::sleep(std::time::Duration::from_secs(1));
|
||||
std::thread::sleep(std::time::Duration::from_millis(500));
|
||||
|
||||
match Command::new("nm-online").arg("-q").status() {
|
||||
Ok(status) => {
|
||||
|
||||
+36
-34
@@ -15,7 +15,7 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/*
|
||||
This is Welcome stage, used to greet used and allow user to choose program language
|
||||
This is TimeZone stage, used to select timezone
|
||||
*/
|
||||
|
||||
use crate::stage::{ConfigValue, StageAction, StageResult};
|
||||
@@ -32,10 +32,6 @@ pub struct TimeZoneData {
|
||||
}
|
||||
|
||||
impl TimeZoneData {
|
||||
|
||||
fn to_full_code(&self) -> String {
|
||||
format!("{}/{}", self.region, self.zone)
|
||||
}
|
||||
fn from_str(s: &str) -> Option<Self> {
|
||||
let idx = s.find('/')?;
|
||||
let (region, zone) = s.split_at(idx);
|
||||
@@ -48,17 +44,19 @@ impl TimeZoneData {
|
||||
|
||||
impl std::fmt::Display for TimeZoneData {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.zone)
|
||||
write!(f, "{}/{}", self.region, self.zone)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TimeZoneStage {
|
||||
time_zones: Result<HashMap<String, Vec<TimeZoneData>>, String>,
|
||||
time_zones: Result<HashMap<String, Vec<String>>, String>,
|
||||
regions: Vec<String>,
|
||||
region_id: Option<usize>,
|
||||
zones: Vec<TimeZoneData>,
|
||||
zones: Vec<String>,
|
||||
zone_id: Option<usize>,
|
||||
selected_zone: Option<TimeZoneData>,
|
||||
selected_zone_text: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -103,22 +101,24 @@ fn get_timezones_blocking() -> Result<Vec<TimeZoneData>, String> {
|
||||
impl TimeZoneStage {
|
||||
pub fn new() -> Self {
|
||||
match get_timezones_blocking() {
|
||||
Ok(tzs) => {
|
||||
let mut time_zones: HashMap<String, Vec<TimeZoneData>> = HashMap::new();
|
||||
for tz in &tzs {
|
||||
if let Some(z) = time_zones.get_mut(tz.region.as_str()) {
|
||||
z.push(tz.clone());
|
||||
Ok(time_zones_data_list) => {
|
||||
let mut time_zones_map: HashMap<String, Vec<String>> = HashMap::new();
|
||||
for tz_data in &time_zones_data_list {
|
||||
if let Some(zones) = time_zones_map.get_mut(&tz_data.region) {
|
||||
zones.push(tz_data.zone.clone());
|
||||
} else {
|
||||
time_zones.insert(tz.region.clone(), vec![tz.clone()]);
|
||||
time_zones_map.insert(tz_data.region.clone(), vec![tz_data.zone.clone()]);
|
||||
}
|
||||
}
|
||||
//let time_zones: HashMap<String, TimeZoneData> = HashMap::from_iter(tzs.iter().map(|tz| (tz.region.clone(), tz.clone())));
|
||||
Self {
|
||||
regions: time_zones.keys().cloned().collect(),
|
||||
zones: tzs.clone(),
|
||||
time_zones: Ok(time_zones),
|
||||
regions: time_zones_map.keys().cloned().collect(),
|
||||
zones: Vec::new(),
|
||||
time_zones: Ok(time_zones_map),
|
||||
region_id: None,
|
||||
zone_id: None,
|
||||
selected_zone: None,
|
||||
selected_zone_text: String::new(),
|
||||
}
|
||||
}
|
||||
Err(ex) => {
|
||||
@@ -132,20 +132,21 @@ impl TimeZoneStage {
|
||||
zones: Vec::new(),
|
||||
region_id: None,
|
||||
zone_id: None,
|
||||
selected_zone: None,
|
||||
selected_zone_text: String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn gen_result(&self) -> StageResult {
|
||||
if let Some(tz_id) = self.zone_id {
|
||||
let time_zone = &self.zones[tz_id];
|
||||
if let Some(time_zone) = &self.selected_zone {
|
||||
StageResult {
|
||||
name: "time_zone".to_string(),
|
||||
config: Some(HashMap::from([
|
||||
(
|
||||
"name".to_string(),
|
||||
ConfigValue::String(time_zone.to_full_code()),
|
||||
ConfigValue::String(time_zone.to_string()),
|
||||
),
|
||||
(
|
||||
"region".to_string(),
|
||||
@@ -181,10 +182,19 @@ impl TimeZoneStage {
|
||||
.unwrap()
|
||||
.clone();
|
||||
self.region_id = Some(region_id);
|
||||
self.zone_id = None;
|
||||
//self.selected_zone_text.clear();
|
||||
StageAction::None
|
||||
}
|
||||
Message::SelectZone(scroll_list::ListViewMessage::Select(zone_id)) => {
|
||||
let zone = TimeZoneData { region: self.regions[self.region_id.unwrap()].clone(), zone: self.zones[zone_id].clone() };
|
||||
self.selected_zone_text = format!(
|
||||
"{} {}",
|
||||
t!("timezone.selected_timezone"),
|
||||
zone.to_string()
|
||||
);
|
||||
self.zone_id = Some(zone_id);
|
||||
self.selected_zone = Some(zone);
|
||||
StageAction::None
|
||||
}
|
||||
Message::Next => StageAction::Next(self.gen_result()),
|
||||
@@ -199,8 +209,8 @@ impl TimeZoneStage {
|
||||
widget::button(widget::text(t!("button.next")))
|
||||
};
|
||||
let main_content = match &self.time_zones {
|
||||
Ok(_) => {
|
||||
let mut col = widget::column![
|
||||
Ok(_) => widget::container(
|
||||
widget::column![
|
||||
widget::text(t!("timezone.select_timezone")),
|
||||
widget::row![
|
||||
scroll_list::list_view(&self.regions, self.region_id, Length::Shrink)
|
||||
@@ -210,21 +220,13 @@ impl TimeZoneStage {
|
||||
]
|
||||
.padding(20)
|
||||
.spacing(10)
|
||||
.height(Length::Shrink)
|
||||
.height(Length::Shrink),
|
||||
widget::text(self.selected_zone_text.clone())
|
||||
]
|
||||
.spacing(10)
|
||||
.align_x(Alignment::Center);
|
||||
.align_x(Alignment::Center),
|
||||
),
|
||||
|
||||
if let Some(tz_id) = self.zone_id {
|
||||
col = col.push(widget::text(format!(
|
||||
"{} {}",
|
||||
t!("timezone.selected_timezone"),
|
||||
self.zones[tz_id].to_full_code()
|
||||
)))
|
||||
};
|
||||
|
||||
widget::container(col)
|
||||
}
|
||||
Err(_) => widget::container(widget::text(t!("timezone.init_error"))),
|
||||
};
|
||||
let back_button = widget::button(widget::text(t!("button.back"))).on_press(Message::Back);
|
||||
|
||||
Reference in New Issue
Block a user