feat(date): add context drawer for date & time applet settings (#2190)
This commit is contained in:
parent
7aa7807c35
commit
9a6aff11d1
2 changed files with 74 additions and 14 deletions
|
|
@ -21,7 +21,9 @@ use tracing::error;
|
||||||
|
|
||||||
crate::cache_dynamic_lazy! {
|
crate::cache_dynamic_lazy! {
|
||||||
static WEEKDAYS: [String; 4] = [fl!("time-format", "friday"), fl!("time-format", "saturday"), fl!("time-format", "sunday"), fl!("time-format", "monday")];
|
static WEEKDAYS: [String; 4] = [fl!("time-format", "friday"), fl!("time-format", "saturday"), fl!("time-format", "sunday"), fl!("time-format", "monday")];
|
||||||
}
|
static SHOW_WEEKDAY: String = fl!("time-format", "show-weekday");
|
||||||
|
static SHOW_SECONDS: String = fl!("time-format", "show-seconds");
|
||||||
|
static SHOW_DATE: String = fl!("time-format", "date");}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Info {
|
pub struct Info {
|
||||||
|
|
@ -36,9 +38,11 @@ pub struct Page {
|
||||||
first_day_of_week: usize,
|
first_day_of_week: usize,
|
||||||
military_time: bool,
|
military_time: bool,
|
||||||
show_seconds: bool,
|
show_seconds: bool,
|
||||||
|
show_weekday: bool,
|
||||||
ntp_enabled: bool,
|
ntp_enabled: bool,
|
||||||
show_date_in_top_panel: bool,
|
show_date_in_top_panel: bool,
|
||||||
timezone_context: bool,
|
timezone_context: bool,
|
||||||
|
date_time_applet_context: bool,
|
||||||
local_time: Option<DateTime<Gregorian>>,
|
local_time: Option<DateTime<Gregorian>>,
|
||||||
timezone: Option<usize>,
|
timezone: Option<usize>,
|
||||||
timezone_list: Vec<String>,
|
timezone_list: Vec<String>,
|
||||||
|
|
@ -73,6 +77,16 @@ impl Default for Page {
|
||||||
false
|
false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let show_weekday = cosmic_applet_config
|
||||||
|
.get("show_weekday")
|
||||||
|
.unwrap_or_else(|err| {
|
||||||
|
if err.is_err() {
|
||||||
|
error!(?err, "Failed to read config 'show_weekday'");
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
});
|
||||||
|
|
||||||
let first_day_of_week = cosmic_applet_config
|
let first_day_of_week = cosmic_applet_config
|
||||||
.get("first_day_of_week")
|
.get("first_day_of_week")
|
||||||
.unwrap_or_else(|err| {
|
.unwrap_or_else(|err| {
|
||||||
|
|
@ -103,10 +117,12 @@ impl Default for Page {
|
||||||
local_time: None,
|
local_time: None,
|
||||||
military_time,
|
military_time,
|
||||||
show_seconds,
|
show_seconds,
|
||||||
|
show_weekday,
|
||||||
ntp_enabled: false,
|
ntp_enabled: false,
|
||||||
show_date_in_top_panel,
|
show_date_in_top_panel,
|
||||||
timezone: None,
|
timezone: None,
|
||||||
timezone_context: false,
|
timezone_context: false,
|
||||||
|
date_time_applet_context: false,
|
||||||
timezone_list: Vec::new(),
|
timezone_list: Vec::new(),
|
||||||
timezone_search: String::new(),
|
timezone_search: String::new(),
|
||||||
}
|
}
|
||||||
|
|
@ -183,6 +199,15 @@ impl page::Page<crate::pages::Message> for Page {
|
||||||
.title(fl!("time-zone"))
|
.title(fl!("time-zone"))
|
||||||
.header(search),
|
.header(search),
|
||||||
);
|
);
|
||||||
|
} else if self.date_time_applet_context {
|
||||||
|
return Some(
|
||||||
|
cosmic::app::context_drawer(
|
||||||
|
self.date_time_applet_view()
|
||||||
|
.map(crate::pages::Message::from),
|
||||||
|
crate::pages::Message::CloseContextDrawer,
|
||||||
|
)
|
||||||
|
.title(fl!("date-time-applet-settings-title")),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
|
|
@ -216,6 +241,15 @@ impl Page {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Message::ShowWeekday(enable) => {
|
||||||
|
self.show_weekday = enable;
|
||||||
|
self.update_local_time();
|
||||||
|
|
||||||
|
if let Err(err) = self.cosmic_applet_config.set("show_weekday", enable) {
|
||||||
|
error!(?err, "Failed to set config 'show_weekday'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Message::FirstDayOfWeek(weekday) => {
|
Message::FirstDayOfWeek(weekday) => {
|
||||||
self.first_day_of_week = weekday;
|
self.first_day_of_week = weekday;
|
||||||
|
|
||||||
|
|
@ -224,6 +258,11 @@ impl Page {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Message::DateAndTimeContext => {
|
||||||
|
self.date_time_applet_context = true;
|
||||||
|
return cosmic::task::message(crate::app::Message::OpenContextDrawer(self.entity));
|
||||||
|
}
|
||||||
|
|
||||||
Message::ShowDate(enable) => {
|
Message::ShowDate(enable) => {
|
||||||
self.show_date_in_top_panel = enable;
|
self.show_date_in_top_panel = enable;
|
||||||
|
|
||||||
|
|
@ -342,6 +381,25 @@ impl Page {
|
||||||
.map(crate::pages::Message::DateAndTime)
|
.map(crate::pages::Message::DateAndTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn date_time_applet_view(&self) -> Element<'_, crate::pages::Message> {
|
||||||
|
let mut list = widget::list_column();
|
||||||
|
|
||||||
|
list = list.add(
|
||||||
|
settings::item::builder(&*SHOW_DATE)
|
||||||
|
.toggler(self.show_date_in_top_panel, Message::ShowDate)
|
||||||
|
)
|
||||||
|
.add(
|
||||||
|
settings::item::builder(&*SHOW_WEEKDAY)
|
||||||
|
.toggler(self.show_weekday, Message::ShowWeekday),
|
||||||
|
)
|
||||||
|
.add(
|
||||||
|
settings::item::builder(&*SHOW_SECONDS)
|
||||||
|
.toggler(self.show_seconds, Message::ShowSeconds));
|
||||||
|
|
||||||
|
list.apply(Element::from)
|
||||||
|
.map(crate::pages::Message::DateAndTime)
|
||||||
|
}
|
||||||
|
|
||||||
fn update_local_time(&mut self) {
|
fn update_local_time(&mut self) {
|
||||||
self.local_time = Some(update_local_time());
|
self.local_time = Some(update_local_time());
|
||||||
|
|
||||||
|
|
@ -357,12 +415,14 @@ pub enum Message {
|
||||||
Error(String),
|
Error(String),
|
||||||
MilitaryTime(bool),
|
MilitaryTime(bool),
|
||||||
ShowSeconds(bool),
|
ShowSeconds(bool),
|
||||||
|
ShowWeekday(bool),
|
||||||
None,
|
None,
|
||||||
FirstDayOfWeek(usize),
|
FirstDayOfWeek(usize),
|
||||||
Refresh(Info),
|
Refresh(Info),
|
||||||
ShowDate(bool),
|
ShowDate(bool),
|
||||||
Timezone(usize),
|
Timezone(usize),
|
||||||
TimezoneContext,
|
TimezoneContext,
|
||||||
|
DateAndTimeContext,
|
||||||
TimezoneSearch(String),
|
TimezoneSearch(String),
|
||||||
UpdateTime,
|
UpdateTime,
|
||||||
Surface(surface::Action<crate::app::Message>),
|
Surface(surface::Action<crate::app::Message>),
|
||||||
|
|
@ -394,9 +454,8 @@ fn date() -> Section<crate::pages::Message> {
|
||||||
fn format() -> Section<crate::pages::Message> {
|
fn format() -> Section<crate::pages::Message> {
|
||||||
crate::slab!(descriptions {
|
crate::slab!(descriptions {
|
||||||
military = fl!("time-format", "twenty-four");
|
military = fl!("time-format", "twenty-four");
|
||||||
show_seconds = fl!("time-format", "show-seconds");
|
|
||||||
first = fl!("time-format", "first");
|
first = fl!("time-format", "first");
|
||||||
show_date = fl!("time-format", "show-date");
|
date_time_applet_settings_label = fl!("date-time-applet-settings-label");
|
||||||
});
|
});
|
||||||
|
|
||||||
Section::default()
|
Section::default()
|
||||||
|
|
@ -410,11 +469,6 @@ fn format() -> Section<crate::pages::Message> {
|
||||||
settings::item::builder(§ion.descriptions[military])
|
settings::item::builder(§ion.descriptions[military])
|
||||||
.toggler(page.military_time, Message::MilitaryTime),
|
.toggler(page.military_time, Message::MilitaryTime),
|
||||||
)
|
)
|
||||||
// Show seconds in time format
|
|
||||||
.add(
|
|
||||||
settings::item::builder(§ion.descriptions[show_seconds])
|
|
||||||
.toggler(page.show_seconds, Message::ShowSeconds),
|
|
||||||
)
|
|
||||||
// First day of week
|
// First day of week
|
||||||
.add(
|
.add(
|
||||||
settings::item::builder(§ion.descriptions[first]).control(
|
settings::item::builder(§ion.descriptions[first]).control(
|
||||||
|
|
@ -444,11 +498,13 @@ fn format() -> Section<crate::pages::Message> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
// Date on top panel toggle
|
// Show a Context Drawer which contains settings for how the Date and Time applet displays the date.
|
||||||
.add(
|
.add(
|
||||||
settings::item::builder(§ion.descriptions[show_date])
|
crate::widget::go_next_with_item(
|
||||||
.toggler(page.show_date_in_top_panel, Message::ShowDate),
|
§ion.descriptions[date_time_applet_settings_label],
|
||||||
)
|
"",
|
||||||
|
Message::DateAndTimeContext,
|
||||||
|
))
|
||||||
.apply(cosmic::Element::from)
|
.apply(cosmic::Element::from)
|
||||||
.map(crate::pages::Message::DateAndTime)
|
.map(crate::pages::Message::DateAndTime)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
8
i18n/en/cosmic_settings.ftl
vendored
8
i18n/en/cosmic_settings.ftl
vendored
|
|
@ -962,14 +962,18 @@ time-zone = Time zone
|
||||||
|
|
||||||
time-format = Date & time format
|
time-format = Date & time format
|
||||||
.twenty-four = 24-hour time
|
.twenty-four = 24-hour time
|
||||||
.show-seconds = Show seconds
|
.show-seconds = Seconds
|
||||||
|
.show-weekday = Day of week
|
||||||
.first = First day of week
|
.first = First day of week
|
||||||
.show-date = Show date in the time applet
|
.date = Date
|
||||||
.friday = Friday
|
.friday = Friday
|
||||||
.saturday = Saturday
|
.saturday = Saturday
|
||||||
.sunday = Sunday
|
.sunday = Sunday
|
||||||
.monday = Monday
|
.monday = Monday
|
||||||
|
|
||||||
|
date-time-applet-settings-title = Date & time applet
|
||||||
|
date-time-applet-settings-label = Date & time applet settings
|
||||||
|
|
||||||
time-region = Region & language
|
time-region = Region & language
|
||||||
|
|
||||||
formatting = Formatting
|
formatting = Formatting
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue