@@ -45,6 +45,7 @@ pub struct Page {
4545 show_seconds : bool ,
4646 ntp_enabled : bool ,
4747 show_date_in_top_panel : bool ,
48+ format_strftime : String ,
4849 timezone_context : bool ,
4950 local_time : Option < DateTime < Gregorian > > ,
5051 timezone : Option < usize > ,
@@ -102,6 +103,15 @@ impl Default for Page {
102103 true
103104 } ) ;
104105
106+ let format_strftime = cosmic_applet_config
107+ . get ( "format_strftime" )
108+ . inspect_err ( |err| {
109+ if err. is_err ( ) {
110+ error ! ( ?err, "Failed to read config 'format_strftime'" ) ;
111+ }
112+ } )
113+ . unwrap_or_default ( ) ;
114+
105115 Self {
106116 entity : page:: Entity :: null ( ) ,
107117 cosmic_applet_config,
@@ -112,6 +122,7 @@ impl Default for Page {
112122 show_seconds,
113123 ntp_enabled : false ,
114124 show_date_in_top_panel,
125+ format_strftime,
115126 timezone : None ,
116127 timezone_context : false ,
117128 timezone_list : Vec :: new ( ) ,
@@ -242,6 +253,17 @@ impl Page {
242253 }
243254 }
244255
256+ Message :: Strftime ( format) => {
257+ self . format_strftime = format;
258+
259+ if let Err ( err) = self
260+ . cosmic_applet_config
261+ . set ( "format_strftime" , & self . format_strftime )
262+ {
263+ error ! ( ?err, "Failed to set config 'format_strftime'" ) ;
264+ }
265+ }
266+
245267 Message :: TimezoneSearch ( text) => {
246268 self . timezone_search = text;
247269 }
@@ -398,6 +420,7 @@ pub enum Message {
398420 FirstDayOfWeek ( usize ) ,
399421 Refresh ( Info ) ,
400422 ShowDate ( bool ) ,
423+ Strftime ( String ) ,
401424 Timezone ( usize ) ,
402425 TimezoneContext ,
403426 TimezoneSearch ( String ) ,
@@ -435,6 +458,7 @@ fn format() -> Section<crate::pages::Message> {
435458 let show_seconds = descriptions. insert ( fl ! ( "time-format" , "show-seconds" ) ) ;
436459 let first = descriptions. insert ( fl ! ( "time-format" , "first" ) ) ;
437460 let show_date = descriptions. insert ( fl ! ( "time-format" , "show-date" ) ) ;
461+ let format_strftime = descriptions. insert ( fl ! ( "time-format" , "format-strftime" ) ) ;
438462
439463 Section :: default ( )
440464 . title ( fl ! ( "time-format" ) )
@@ -486,6 +510,12 @@ fn format() -> Section<crate::pages::Message> {
486510 settings:: item:: builder ( & section. descriptions [ show_date] )
487511 . toggler ( page. show_date_in_top_panel , Message :: ShowDate ) ,
488512 )
513+ // Format with strftime
514+ . add (
515+ settings:: item:: builder ( & section. descriptions [ format_strftime] ) . control (
516+ widget:: text_input ( "" , & page. format_strftime ) . on_submit ( Message :: Strftime ) ,
517+ ) ,
518+ )
489519 . apply ( cosmic:: Element :: from)
490520 . map ( crate :: pages:: Message :: DateAndTime )
491521 } )
0 commit comments