From b3a34d487c8c3724752b522fd352c96ba0bcf1a4 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 23 Feb 2011 14:07:19 -0500 Subject: add week-start controls and settings --- data/com.canonical.indicator.datetime.gschema.xml | 12 +++++ data/datetime-dialog.ui | 5 ++- src/datetime-prefs.c | 53 +++++++++++++++++++++-- src/settings-shared.h | 2 +- src/utils.c | 11 +++++ src/utils.h | 1 + 6 files changed, 78 insertions(+), 6 deletions(-) diff --git a/data/com.canonical.indicator.datetime.gschema.xml b/data/com.canonical.indicator.datetime.gschema.xml index b33f34e..5361896 100644 --- a/data/com.canonical.indicator.datetime.gschema.xml +++ b/data/com.canonical.indicator.datetime.gschema.xml @@ -5,6 +5,11 @@ + + + + + true @@ -78,6 +83,13 @@ Shows the week numbers in the monthly calendar in indicator-datetime's menu. + + 'locale-default' + When the week starts + + Controls whether weeks in the calendar are shown to start on Sunday or Monday. + + true Show events in the indicator diff --git a/data/datetime-dialog.ui b/data/datetime-dialog.ui index 8b48702..c2a39b9 100644 --- a/data/datetime-dialog.ui +++ b/data/datetime-dialog.ui @@ -578,6 +578,7 @@ True False + 6 Include week num_bers @@ -597,8 +598,8 @@ + True False - True 0 Week begins on: @@ -610,8 +611,8 @@ + True False - True True diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c index 622a999..44b9b24 100644 --- a/src/datetime-prefs.c +++ b/src/datetime-prefs.c @@ -29,7 +29,7 @@ with this program. If not, see . #include #include #include -#include +#include #include #include #include @@ -85,6 +85,45 @@ bind_hours_get (GValue * value, GVariant * variant, gpointer user_data) return TRUE; } +/* Turns the boolean property into a string gsettings */ +static GVariant * +bind_week_start_set (const GValue * value, const GVariantType * type, gpointer user_data) +{ + const gchar * output = NULL; + gboolean is_sunday_button = (gboolean)GPOINTER_TO_INT(user_data); + + if (g_value_get_boolean(value)) { + /* Only do anything if we're setting active = true */ + output = is_sunday_button ? "sunday" : "monday"; + } else { + return NULL; + } + + return g_variant_new_string (output); +} + +/* Turns a string gsettings into a boolean property */ +static gboolean +bind_week_start_get (GValue * value, GVariant * variant, gpointer user_data) +{ + const gchar * str = g_variant_get_string(variant, NULL); + gboolean output = FALSE; + gboolean is_sunday_button = (gboolean)GPOINTER_TO_INT(user_data); + + if (g_strcmp0(str, "locale-default") == 0) { + output = (is_sunday_button == is_locale_week_start_sunday ()); + } else if (g_strcmp0(str, "sunday") == 0) { + output = is_sunday_button; + } else if (g_strcmp0(str, "monday") == 0) { + output = !is_sunday_button; + } else { + return FALSE; + } + + g_value_set_boolean (value, output); + return TRUE; +} + static void widget_dependency_cb (GtkWidget * parent, GParamSpec *pspec, GtkWidget * dependent) { @@ -473,8 +512,16 @@ create_dialog (void) "active", G_SETTINGS_BIND_DEFAULT); g_settings_bind (conf, SETTINGS_SHOW_WEEK_NUMBERS_S, WIG ("includeWeekNumbersCheck"), "active", G_SETTINGS_BIND_DEFAULT); - /*g_settings_bind_(conf, SETTINGS_WEEK_BEGINS_SUNDAY_S, WIG ("startOnSundayRadio"), - "active", G_SETTINGS_BIND_DEFAULT);*/ + g_settings_bind_with_mapping (conf, SETTINGS_WEEK_START_S, + WIG ("startOnSundayRadio"), "active", + G_SETTINGS_BIND_DEFAULT, + bind_week_start_get, bind_week_start_set, + GINT_TO_POINTER(TRUE), NULL); + g_settings_bind_with_mapping (conf, SETTINGS_WEEK_START_S, + WIG ("startOnMondayRadio"), "active", + G_SETTINGS_BIND_DEFAULT, + bind_week_start_get, bind_week_start_set, + GINT_TO_POINTER(FALSE), NULL); g_settings_bind (conf, SETTINGS_SHOW_EVENTS_S, WIG ("showEventsCheck"), "active", G_SETTINGS_BIND_DEFAULT); g_settings_bind (conf, SETTINGS_SHOW_LOCATIONS_S, WIG ("showLocationsCheck"), diff --git a/src/settings-shared.h b/src/settings-shared.h index d866b81..b8e1789 100644 --- a/src/settings-shared.h +++ b/src/settings-shared.h @@ -33,7 +33,7 @@ with this program. If not, see . #define SETTINGS_CUSTOM_TIME_FORMAT_S "custom-time-format" #define SETTINGS_SHOW_CALENDAR_S "show-calendar" #define SETTINGS_SHOW_WEEK_NUMBERS_S "show-week-numbers" -#define SETTINGS_WEEK_BEGINS_SUNDAY_S "week-begins-sunday" +#define SETTINGS_WEEK_START_S "week-start" #define SETTINGS_SHOW_EVENTS_S "show-events" #define SETTINGS_SHOW_LOCATIONS_S "show-locations" #define SETTINGS_LOCATIONS_S "locations" diff --git a/src/utils.c b/src/utils.c index f73ed14..89c499b 100644 --- a/src/utils.c +++ b/src/utils.c @@ -50,6 +50,17 @@ is_locale_12h (void) return TRUE; } +/* Check the system locale setting to see if the week starts on Sunday or Monday */ +gboolean +is_locale_week_start_sunday (void) +{ + const char * week_1stday = nl_langinfo (_NL_TIME_WEEK_1STDAY); + + /* This appears to be a special value that libc uses for Sunday, it's not + really a string */ + return (GPOINTER_TO_INT (week_1stday) == 19971130); +} + void split_settings_location (const gchar * location, gchar ** zone, gchar ** name) { diff --git a/src/utils.h b/src/utils.h index 5f7842c..3dc8df1 100644 --- a/src/utils.h +++ b/src/utils.h @@ -28,6 +28,7 @@ with this program. If not, see . G_BEGIN_DECLS gboolean is_locale_12h (void); +gboolean is_locale_week_start_sunday (void); void split_settings_location (const gchar * location, gchar ** zone, gchar ** name); gchar * generate_format_string_full (gboolean show_day, gboolean show_date); gchar * generate_format_string_at_time (GDateTime * time); -- cgit v1.2.3