TimeZone stage allmost done.
This commit is contained in:
+2
-2
@@ -11,7 +11,7 @@ rust-i18n = "3"
|
|||||||
toml = "1"
|
toml = "1"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
#lto = true
|
||||||
codegen-units = 1
|
codegen-units = 16
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
strip = true
|
strip = true
|
||||||
|
|||||||
+2
-2
@@ -18,8 +18,8 @@
|
|||||||
"network.no_connection": "Network inactive.",
|
"network.no_connection": "Network inactive.",
|
||||||
"network.check_error": "Error while cheking network connection.",
|
"network.check_error": "Error while cheking network connection.",
|
||||||
"network.button.check": "Check Network",
|
"network.button.check": "Check Network",
|
||||||
"timezone.select_region": "Select region:",
|
"timezone.selected_timezone": "Selected timezone:",
|
||||||
"timezone.select_timezone": "Select time zone:",
|
"timezone.select_timezone": "Please select preffered time zone",
|
||||||
"timezone.init_error": "Erro getting time zones data from system."
|
"timezone.init_error": "Erro getting time zones data from system."
|
||||||
|
|
||||||
}
|
}
|
||||||
+6
-1
@@ -184,7 +184,12 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
|
|||||||
iced::exit()
|
iced::exit()
|
||||||
}
|
}
|
||||||
StageAction::Abort(_) => iced::exit(),
|
StageAction::Abort(_) => iced::exit(),
|
||||||
StageAction::Back => iced::exit(),
|
StageAction::Back => {
|
||||||
|
k_state.config.config_trail.pop();
|
||||||
|
k_state.current_view =
|
||||||
|
Views::Network(network::NetworkStage::new(&k_state.toml_config));
|
||||||
|
Task::done(Message::Network(network::Message::CheckNetwork))
|
||||||
|
}
|
||||||
StageAction::None => Task::none(),
|
StageAction::None => Task::none(),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ pub enum Message {
|
|||||||
//['ace', 'af', 'sq', 'ar', 'an', 'hy', 'as', 'ay', 'az', 'ba', 'eu', 'be', 'bn', 'bho', 'bs', 'br', 'bg', 'my', 'yue', 'ca', 'ceb', 'zh-Hans', 'zh-Hant', 'hr', 'cs', 'da', 'prs', 'nl', 'en-US', 'en-GB', 'eo', 'et', 'fi', 'fr', 'gl', 'ka', 'de', 'el', 'gn', 'gu', 'ht', 'ha', 'he', 'hi', 'hu', 'is', 'ig', 'id', 'ga', 'it', 'ja', 'jv', 'pam', 'kk', 'gom', 'ko', 'kmr', 'ckb', 'ky', 'la', 'lv', 'ln', 'lt', 'lmo', 'lb', 'mk', 'mai', 'mg', 'ms', 'ml', 'mt', 'mi', 'mr', 'mn', 'ne', 'nb', 'oc', 'om', 'pag', 'ps', 'fa', 'pl', 'pt-PT', 'pt-BR', 'pa', 'qu', 'ro', 'ru', 'sa', 'sr', 'st', 'scn', 'sk', 'sl', 'es', 'es-419', 'su', 'sw', 'sv', 'tl', 'tg', 'ta', 'tt', 'te', 'ts', 'tn', 'tr', 'tk', 'uk', 'ur', 'uz', 'vi', 'cy', 'wo', 'xh', 'yi', 'zu']
|
//['ace', 'af', 'sq', 'ar', 'an', 'hy', 'as', 'ay', 'az', 'ba', 'eu', 'be', 'bn', 'bho', 'bs', 'br', 'bg', 'my', 'yue', 'ca', 'ceb', 'zh-Hans', 'zh-Hant', 'hr', 'cs', 'da', 'prs', 'nl', 'en-US', 'en-GB', 'eo', 'et', 'fi', 'fr', 'gl', 'ka', 'de', 'el', 'gn', 'gu', 'ht', 'ha', 'he', 'hi', 'hu', 'is', 'ig', 'id', 'ga', 'it', 'ja', 'jv', 'pam', 'kk', 'gom', 'ko', 'kmr', 'ckb', 'ky', 'la', 'lv', 'ln', 'lt', 'lmo', 'lb', 'mk', 'mai', 'mg', 'ms', 'ml', 'mt', 'mi', 'mr', 'mn', 'ne', 'nb', 'oc', 'om', 'pag', 'ps', 'fa', 'pl', 'pt-PT', 'pt-BR', 'pa', 'qu', 'ro', 'ru', 'sa', 'sr', 'st', 'scn', 'sk', 'sl', 'es', 'es-419', 'su', 'sw', 'sv', 'tl', 'tg', 'ta', 'tt', 'te', 'ts', 'tn', 'tr', 'tk', 'uk', 'ur', 'uz', 'vi', 'cy', 'wo', 'xh', 'yi', 'zu']
|
||||||
//
|
//
|
||||||
|
|
||||||
const license_text: &str = include_str!("gpl-3.0.txt");
|
//const LICENSE_TEXT: &str = include_str!("gpl-3.0.txt");
|
||||||
|
|
||||||
impl LicenseStage {
|
impl LicenseStage {
|
||||||
fn accepted() -> StageResult {
|
fn accepted() -> StageResult {
|
||||||
|
|||||||
@@ -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(5));
|
std::thread::sleep(std::time::Duration::from_secs(1));
|
||||||
|
|
||||||
match Command::new("nm-online").arg("-q").status() {
|
match Command::new("nm-online").arg("-q").status() {
|
||||||
Ok(status) => {
|
Ok(status) => {
|
||||||
|
|||||||
+72
-61
@@ -19,10 +19,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use crate::stage::{ConfigValue, StageAction, StageResult};
|
use crate::stage::{ConfigValue, StageAction, StageResult};
|
||||||
use iced::{Alignment, widget};
|
use iced::{Alignment, Length, widget};
|
||||||
use rust_i18n::t;
|
use rust_i18n::t;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
mod scroll_list;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct TimeZoneData {
|
pub struct TimeZoneData {
|
||||||
region: String,
|
region: String,
|
||||||
@@ -30,7 +32,8 @@ pub struct TimeZoneData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TimeZoneData {
|
impl TimeZoneData {
|
||||||
fn to_string(&self) -> String {
|
|
||||||
|
fn to_full_code(&self) -> String {
|
||||||
format!("{}/{}", self.region, self.zone)
|
format!("{}/{}", self.region, self.zone)
|
||||||
}
|
}
|
||||||
fn from_str(s: &str) -> Option<Self> {
|
fn from_str(s: &str) -> Option<Self> {
|
||||||
@@ -38,30 +41,30 @@ impl TimeZoneData {
|
|||||||
let (region, zone) = s.split_at(idx);
|
let (region, zone) = s.split_at(idx);
|
||||||
Some(Self {
|
Some(Self {
|
||||||
region: region.into(),
|
region: region.into(),
|
||||||
zone: zone.into(),
|
zone: zone.trim_start_matches('/').into(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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.region, self.zone)
|
write!(f, "{}", self.zone)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct TimeZoneStage {
|
pub struct TimeZoneStage {
|
||||||
time_zone: Option<TimeZoneData>,
|
|
||||||
time_zone_region: Option<String>,
|
|
||||||
time_zones: Result<HashMap<String, Vec<TimeZoneData>>, String>,
|
time_zones: Result<HashMap<String, Vec<TimeZoneData>>, String>,
|
||||||
regions: Vec<String>,
|
regions: Vec<String>,
|
||||||
|
region_id: Option<usize>,
|
||||||
zones: Vec<TimeZoneData>,
|
zones: Vec<TimeZoneData>,
|
||||||
|
zone_id: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Message {
|
pub enum Message {
|
||||||
SelectRegion(String),
|
SelectRegion(scroll_list::ListViewMessage),
|
||||||
SelectZone(TimeZoneData),
|
SelectZone(scroll_list::ListViewMessage),
|
||||||
Next,
|
Next,
|
||||||
Back,
|
Back,
|
||||||
}
|
}
|
||||||
@@ -113,36 +116,45 @@ impl TimeZoneStage {
|
|||||||
Self {
|
Self {
|
||||||
regions: time_zones.keys().cloned().collect(),
|
regions: time_zones.keys().cloned().collect(),
|
||||||
zones: tzs.clone(),
|
zones: tzs.clone(),
|
||||||
time_zone: None,
|
|
||||||
time_zone_region: None,
|
|
||||||
time_zones: Ok(time_zones),
|
time_zones: Ok(time_zones),
|
||||||
|
region_id: None,
|
||||||
|
zone_id: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(ex) => {
|
Err(ex) => {
|
||||||
println!(
|
println!(
|
||||||
"Exception while trying to get time zones list from system {}",
|
"Exception while trying to get time zones list from system {}",
|
||||||
ex
|
ex
|
||||||
);
|
);
|
||||||
Self {
|
Self {
|
||||||
time_zone: None,
|
|
||||||
time_zone_region: None,
|
|
||||||
time_zones: Err(ex),
|
time_zones: Err(ex),
|
||||||
regions: Vec::new(),
|
regions: Vec::new(),
|
||||||
zones: Vec::new(),
|
zones: Vec::new(),
|
||||||
|
region_id: None,
|
||||||
|
zone_id: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gen_result(&self) -> StageResult {
|
fn gen_result(&self) -> StageResult {
|
||||||
if let Some(tz) = &self.time_zone {
|
if let Some(tz_id) = self.zone_id {
|
||||||
|
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(), ConfigValue::String(tz.to_string())),
|
(
|
||||||
("region".to_string(), ConfigValue::String(tz.region.clone())),
|
"name".to_string(),
|
||||||
("zone".to_string(), ConfigValue::String(tz.zone.clone())),
|
ConfigValue::String(time_zone.to_full_code()),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"region".to_string(),
|
||||||
|
ConfigValue::String(time_zone.region.clone()),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"zone".to_string(),
|
||||||
|
ConfigValue::String(time_zone.zone.clone()),
|
||||||
|
),
|
||||||
])),
|
])),
|
||||||
resuts: None,
|
resuts: None,
|
||||||
error: None,
|
error: None,
|
||||||
@@ -159,12 +171,20 @@ impl TimeZoneStage {
|
|||||||
|
|
||||||
pub fn update(&mut self, message: Message) -> StageAction {
|
pub fn update(&mut self, message: Message) -> StageAction {
|
||||||
match message {
|
match message {
|
||||||
Message::SelectRegion(region) => {
|
Message::SelectRegion(scroll_list::ListViewMessage::Select(region_id)) => {
|
||||||
self.time_zone_region = Some(region);
|
let region = self.regions.get(region_id).unwrap();
|
||||||
|
self.zones = self
|
||||||
|
.time_zones
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.get(region)
|
||||||
|
.unwrap()
|
||||||
|
.clone();
|
||||||
|
self.region_id = Some(region_id);
|
||||||
StageAction::None
|
StageAction::None
|
||||||
}
|
}
|
||||||
Message::SelectZone(zone) => {
|
Message::SelectZone(scroll_list::ListViewMessage::Select(zone_id)) => {
|
||||||
self.time_zone = Some(zone);
|
self.zone_id = Some(zone_id);
|
||||||
StageAction::None
|
StageAction::None
|
||||||
}
|
}
|
||||||
Message::Next => StageAction::Next(self.gen_result()),
|
Message::Next => StageAction::Next(self.gen_result()),
|
||||||
@@ -173,48 +193,39 @@ impl TimeZoneStage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> iced::Element<'_, Message> {
|
pub fn view(&self) -> iced::Element<'_, Message> {
|
||||||
let (next_button, main_content) = match &self.time_zones {
|
let next_button = if self.zone_id.is_some() {
|
||||||
Ok(time_zones) => (
|
widget::button(widget::text(t!("button.next"))).on_press(Message::Next)
|
||||||
widget::button(widget::text(t!("button.next"))).on_press(Message::Next),
|
} else {
|
||||||
widget::container(
|
widget::button(widget::text(t!("button.next")))
|
||||||
widget::column![
|
};
|
||||||
widget::text(t!("timezone.select_timezone")),
|
let main_content = match &self.time_zones {
|
||||||
widget::row![
|
Ok(_) => {
|
||||||
widget::text(t!("timezone.select_region")),
|
let mut col = widget::column![
|
||||||
widget::pick_list(
|
widget::text(t!("timezone.select_timezone")),
|
||||||
self.regions.clone(),
|
widget::row![
|
||||||
self.time_zone_region.clone(),
|
scroll_list::list_view(&self.regions, self.region_id, Length::Shrink)
|
||||||
Message::SelectRegion,
|
.map(Message::SelectRegion),
|
||||||
)
|
scroll_list::list_view(&self.zones, self.zone_id, Length::FillPortion(1))
|
||||||
.placeholder("Select Region")
|
.map(Message::SelectZone),
|
||||||
],
|
|
||||||
widget::row![
|
|
||||||
widget::text(t!("timezone.select_timezone")),
|
|
||||||
widget::pick_list(
|
|
||||||
time_zones
|
|
||||||
.get(
|
|
||||||
self.time_zone_region
|
|
||||||
.clone()
|
|
||||||
.unwrap_or("Etc".into())
|
|
||||||
.as_str()
|
|
||||||
)
|
|
||||||
.unwrap()
|
|
||||||
.clone(),
|
|
||||||
self.time_zone.clone(),
|
|
||||||
Message::SelectZone,
|
|
||||||
)
|
|
||||||
.placeholder("Select Timezone")
|
|
||||||
]
|
|
||||||
]
|
]
|
||||||
.padding(10)
|
.padding(20)
|
||||||
.spacing(10)
|
.spacing(10)
|
||||||
.align_x(Alignment::Center),
|
.height(Length::Shrink)
|
||||||
),
|
]
|
||||||
),
|
.spacing(10)
|
||||||
Err(_) => (
|
.align_x(Alignment::Center);
|
||||||
widget::button(widget::text(t!("button.next"))),
|
|
||||||
widget::container(widget::text(t!("timezone.init_error"))),
|
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);
|
let back_button = widget::button(widget::text(t!("button.back"))).on_press(Message::Back);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
use iced::widget::{Column, button, container, scrollable, text};
|
||||||
|
use iced::{Alignment, Color, Element, Length, Theme};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum ListViewMessage {
|
||||||
|
Select(usize),
|
||||||
|
}
|
||||||
|
|
||||||
|
fn unselected_button_style(theme: &Theme, status: button::Status) -> button::Style {
|
||||||
|
//let palette = theme.extended_palette();
|
||||||
|
use iced::{Border, border::Radius};
|
||||||
|
|
||||||
|
match status {
|
||||||
|
button::Status::Hovered => button::Style {
|
||||||
|
border: Border {
|
||||||
|
color: Color::from_rgb(0.8, 0.3, 0.3),
|
||||||
|
width: 2.0,
|
||||||
|
radius: Radius::new(5.0),
|
||||||
|
},
|
||||||
|
..button::primary(theme, status)
|
||||||
|
},
|
||||||
|
button::Status::Active => button::Style {
|
||||||
|
background: Some(iced::Background::Color(crate::theme::change_lightnes(
|
||||||
|
&theme.palette().primary,
|
||||||
|
-0.1,
|
||||||
|
))),
|
||||||
|
..button::primary(theme, status)
|
||||||
|
},
|
||||||
|
_ => button::primary(theme, status),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn selected_button_style(theme: &Theme, status: button::Status) -> button::Style {
|
||||||
|
//let palette = theme.extended_palette();
|
||||||
|
|
||||||
|
match status {
|
||||||
|
button::Status::Active => button::Style {
|
||||||
|
background: Some(iced::Background::Color(Color::from_rgb(0.8, 0.3, 0.3))),
|
||||||
|
..button::primary(theme, status)
|
||||||
|
},
|
||||||
|
_ => button::Style {
|
||||||
|
background: Some(iced::Background::Color(Color::from_rgb(0.8, 0.3, 0.3))),
|
||||||
|
..button::primary(theme, status)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fn view() -> container::Style {
|
||||||
|
// container::Style {
|
||||||
|
// text_color: None,
|
||||||
|
// background: None,
|
||||||
|
// border: Border {
|
||||||
|
// color: Color::BLACK,
|
||||||
|
// width: 2.0,
|
||||||
|
// radius: Radius::new(5.0),
|
||||||
|
// },
|
||||||
|
// shadow: None,
|
||||||
|
// snap: false,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// fn border_style(theme: &Theme) -> container::Style {
|
||||||
|
// use iced::{Border, border::Radius};
|
||||||
|
|
||||||
|
// container::Style {
|
||||||
|
// border: Border {
|
||||||
|
// color: Color::from_rgb(0.8, 0.3, 0.3),
|
||||||
|
// width: 2.0,
|
||||||
|
// radius: Radius::new(5.0),
|
||||||
|
// },
|
||||||
|
// ..container::bordered_box(theme)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Assuming your Item struct or type implements Display or has a text representation
|
||||||
|
pub fn list_view<T: Display>(
|
||||||
|
items: &Vec<T>,
|
||||||
|
selected_id: Option<usize>,
|
||||||
|
container_height: Length,
|
||||||
|
) -> Element<'_, ListViewMessage> {
|
||||||
|
let mut column = Column::new()
|
||||||
|
.spacing(2)
|
||||||
|
.align_x(Alignment::Center)
|
||||||
|
.width(Length::Fill);
|
||||||
|
|
||||||
|
for (index, value) in items.iter().enumerate() {
|
||||||
|
// Create a row for each item, possibly with buttons or other controls
|
||||||
|
let list_item = if let Some(id) = selected_id
|
||||||
|
&& id == index
|
||||||
|
{
|
||||||
|
button(text(value.to_string())).style(selected_button_style)
|
||||||
|
} else {
|
||||||
|
button(text(value.to_string())).style(unselected_button_style)
|
||||||
|
};
|
||||||
|
let list_item = list_item
|
||||||
|
.width(Length::Fill)
|
||||||
|
.on_press(ListViewMessage::Select(index));
|
||||||
|
|
||||||
|
column = column.push(list_item);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wrap the column in a scrollable widget
|
||||||
|
container(scrollable(column).width(Length::Fill))
|
||||||
|
.style(container::bordered_box)
|
||||||
|
.height(container_height)
|
||||||
|
.padding(8)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user