From a7a0c1cc6f76b2c5d844bbbd32dad70d4f7473e8 Mon Sep 17 00:00:00 2001 From: "Eugene San (eugenesan)" Date: Sun, 6 Jun 2021 07:50:26 -0700 Subject: Allow change of time and date formats on lock screen v4 --- data/org.mate.screensaver.gschema.xml.in | 10 ++++++++ src/gs-lock-plug.c | 42 +++++++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/data/org.mate.screensaver.gschema.xml.in b/data/org.mate.screensaver.gschema.xml.in index 5e2cf06..1d88ef9 100644 --- a/data/org.mate.screensaver.gschema.xml.in +++ b/data/org.mate.screensaver.gschema.xml.in @@ -75,6 +75,16 @@ Theme for lock dialog Theme to use for the lock dialog + + 'locale' + Format for time on lock dialog + Format do display the time on lock dialog. Default is 'locale' which uses default format for current locale. Custom values should be set according to g-date-time-format. Try %R for 24H format. + + + 'locale' + Format for date on lock dialog + Format do display the date on lock dialog. Default is 'locale' which uses default format for current locale. Custom values should be set according to g-date-time-format. Try %F for ISO 8601 date format. + true Allow the session status message to be displayed diff --git a/src/gs-lock-plug.c b/src/gs-lock-plug.c index 7d223c8..5e09f9c 100644 --- a/src/gs-lock-plug.c +++ b/src/gs-lock-plug.c @@ -59,6 +59,10 @@ #define KEY_LOCK_DIALOG_THEME "lock-dialog-theme" +#define KEY_LOCK_DIALOG_T_FMT "lock-dialog-time-format" +#define KEY_LOCK_DIALOG_D_FMT "lock-dialog-date-format" + + #define MDM_FLEXISERVER_COMMAND "mdmflexiserver" #define MDM_FLEXISERVER_ARGS "--startnew Standard" @@ -294,12 +298,42 @@ date_time_update (GSLockPlug *plug) GDateTime *datetime; gchar *time; gchar *date; + gchar *tfmt; + gchar *dfmt; + gchar *str; + GSettings *settings; + + settings = g_settings_new (GSETTINGS_SCHEMA); + tfmt = g_settings_get_string (settings, KEY_LOCK_DIALOG_T_FMT); + dfmt = g_settings_get_string (settings, KEY_LOCK_DIALOG_D_FMT); + g_object_unref (settings); + + /* Time/Date formating https://developer.gnome.org/glib/stable/glib-GDateTime.html#g-date-time-format */ + datetime = g_date_time_new_now_local (); - time = g_date_time_format (datetime, "%X"); - /* Translators: Date format, see https://developer.gnome.org/glib/stable/glib-GDateTime.html#g-date-time-format */ - date = g_date_time_format (datetime, _("%A, %B %e")); + if (g_strcmp0(tfmt, "locale") == 0) + { + // Use locale default format + time = g_date_time_format (datetime, "%X"); + } + else + { + // Apply user defined format + time = g_date_time_format (datetime, tfmt); + } + + if (g_strcmp0(dfmt, "locale") == 0) + { + // Use locale default format + date = g_date_time_format (datetime, _("%A, %B %e")); + } + else + { + // Apply user defined format + date = g_date_time_format (datetime, dfmt); + } str = g_strdup_printf ("%s", time); gtk_label_set_text (GTK_LABEL (plug->priv->auth_time_label), str); @@ -313,6 +347,8 @@ date_time_update (GSLockPlug *plug) g_free (time); g_free (date); + g_free (tfmt); + g_free (dfmt); g_date_time_unref (datetime); } -- cgit v1.2.1