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