From da61c2a69e259b029c39a6deb0f65217d90e73e4 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 17 May 2012 15:46:42 -0500 Subject: Add the "Time in auto-detected location" setting described in https://wiki.ubuntu.com/TimeAndDate --- data/com.canonical.indicator.datetime.gschema.xml | 7 +++++ data/datetime-dialog.ui | 19 ++++++++++++- src/datetime-prefs.c | 2 ++ src/datetime-service.c | 34 ++++++++++++++--------- src/settings-shared.h | 1 + 5 files changed, 49 insertions(+), 14 deletions(-) diff --git a/data/com.canonical.indicator.datetime.gschema.xml b/data/com.canonical.indicator.datetime.gschema.xml index 8ce75e6..4f831d5 100644 --- a/data/com.canonical.indicator.datetime.gschema.xml +++ b/data/com.canonical.indicator.datetime.gschema.xml @@ -85,6 +85,13 @@ Shows events from Evolution in indicator-datetime's menu. + + false + Show the auto-detected location in the indicator + + Shows your current location (determined from geoclue and /etc/timezone) in indicator-datetime's menu. + + false Show locations in the indicator diff --git a/data/datetime-dialog.ui b/data/datetime-dialog.ui index f3110ec..3b777fc 100644 --- a/data/datetime-dialog.ui +++ b/data/datetime-dialog.ui @@ -678,6 +678,23 @@ 3 + + + Time in _auto-detected location + True + True + False + False + True + 0 + True + + + False + True + 4 + + Time in _other locations @@ -719,7 +736,7 @@ True True - 5 + 6 diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c index 611d9ef..d80a59f 100644 --- a/src/datetime-prefs.c +++ b/src/datetime-prefs.c @@ -733,6 +733,8 @@ indicator_datetime_panel_init (IndicatorDatetimePanel * self) "active", G_SETTINGS_BIND_DEFAULT); g_settings_bind (conf, SETTINGS_SHOW_EVENTS_S, WIG ("showEventsCheck"), "active", G_SETTINGS_BIND_DEFAULT); + g_settings_bind (conf, SETTINGS_SHOW_DETECTED_S, WIG ("showDetectedCheck"), + "active", G_SETTINGS_BIND_DEFAULT); g_settings_bind (conf, SETTINGS_SHOW_LOCATIONS_S, WIG ("showLocationsCheck"), "active", G_SETTINGS_BIND_DEFAULT); diff --git a/src/datetime-service.c b/src/datetime-service.c index d264900..5b3bf81 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -115,6 +115,7 @@ struct TimeLocation gint32 offset; gchar * zone; gchar * name; + gboolean visible; }; static void time_location_free (struct TimeLocation * loc) @@ -124,7 +125,7 @@ time_location_free (struct TimeLocation * loc) g_free (loc); } static struct TimeLocation* -time_location_new (const char * zone, const char * name, time_t now) +time_location_new (const char * zone, const char * name, gboolean visible, time_t now) { struct TimeLocation * loc = g_new (struct TimeLocation, 1); GTimeZone * tz = g_time_zone_new (zone); @@ -132,6 +133,7 @@ time_location_new (const char * zone, const char * name, time_t now) loc->offset = g_time_zone_get_offset (tz, interval); loc->zone = g_strdup (zone); loc->name = g_strdup (name); + loc->visible = visible; g_time_zone_unref (tz); g_debug ("%s zone '%s' name '%s' offset is %d", G_STRLOC, zone, name, (int)loc->offset); return loc; @@ -139,18 +141,18 @@ time_location_new (const char * zone, const char * name, time_t now) static int time_location_compare (const struct TimeLocation * a, const struct TimeLocation * b) { - int ret; - if (a->offset != b->offset) /* primary key s.t. we can sort by timezone order */ - ret = a->offset - b->offset; - else + int ret = a->offset - b->offset; /* primary key */ + if (!ret) ret = g_strcmp0 (a->name, b->name); /* secondary key */ + if (!ret) + ret = a->visible - b->visible; /* tertiary key */ g_debug ("%s comparing '%s' (%d) to '%s' (%d), returning %d", G_STRLOC, a->name, (int)a->offset, b->name, (int)b->offset, ret); return ret; } static GSList* -locations_add (GSList * locations, const char * zone, const char * name, time_t now) +locations_add (GSList * locations, const char * zone, const char * name, gboolean visible, time_t now) { - struct TimeLocation * loc = time_location_new (zone, name, now); + struct TimeLocation * loc = time_location_new (zone, name, visible, now); if (g_slist_find_custom (locations, loc, (GCompareFunc)time_location_compare) == NULL) { g_debug ("%s Adding zone '%s', name '%s'", G_STRLOC, zone, name); @@ -188,15 +190,17 @@ update_location_menu_items (void) /* maybe add geo_timezone */ if (geo_timezone != NULL) { + const gboolean visible = g_settings_get_boolean (conf, SETTINGS_SHOW_DETECTED_S); gchar * name = get_current_zone_name (geo_timezone); - locations = locations_add (locations, geo_timezone, name, now); + locations = locations_add (locations, geo_timezone, name, visible, now); g_free (name); } /* maybe add current_timezone */ if (current_timezone != NULL) { + const gboolean visible = g_settings_get_boolean (conf, SETTINGS_SHOW_DETECTED_S); gchar * name = get_current_zone_name (current_timezone); - locations = locations_add (locations, current_timezone, name, now); + locations = locations_add (locations, current_timezone, name, visible, now); g_free (name); } @@ -205,12 +209,13 @@ update_location_menu_items (void) if (user_locations != NULL) { gint i; const guint location_count = g_strv_length (user_locations); + const gboolean visible = g_settings_get_boolean (conf, SETTINGS_SHOW_LOCATIONS_S); g_debug ("%s Found %u user-specified locations", G_STRLOC, location_count); for (i=0; inext) { struct TimeLocation * loc = l->data; g_debug("%s Adding location: zone '%s', name '%s'", G_STRLOC, loc->zone, loc->name); @@ -234,17 +239,19 @@ update_location_menu_items (void) dbusmenu_menuitem_property_set (item, TIMEZONE_MENUITEM_PROP_ZONE, loc->zone); dbusmenu_menuitem_property_set_bool (item, TIMEZONE_MENUITEM_PROP_RADIO, FALSE); dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); - dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_VISIBLE, show_locations); + dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_VISIBLE, loc->visible); dbusmenu_menuitem_child_add_position (root, item, offset++); g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL); location_menu_items = g_slist_append (location_menu_items, item); + if (loc->visible) + have_visible_location = TRUE; time_location_free (loc); } g_slist_free (locations); locations = NULL; /* if there's at least one item being shown, show the separator too */ - dbusmenu_menuitem_property_set_bool (locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, show_locations && (location_menu_items!=NULL)); + dbusmenu_menuitem_property_set_bool (locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, have_visible_location); } /* Update the current timezone */ @@ -1090,6 +1097,7 @@ build_menus (DbusmenuMenuitem * root) update_location_menu_items(); g_signal_connect (conf, "changed::" SETTINGS_SHOW_LOCATIONS_S, G_CALLBACK (show_locations_changed), NULL); + g_signal_connect (conf, "changed::" SETTINGS_SHOW_DETECTED_S, G_CALLBACK (show_locations_changed), NULL); g_signal_connect (conf, "changed::" SETTINGS_LOCATIONS_S, G_CALLBACK (show_locations_changed), NULL); g_signal_connect (conf, "changed::" SETTINGS_SHOW_EVENTS_S, G_CALLBACK (show_events_changed), NULL); g_signal_connect (conf, "changed::" SETTINGS_TIME_FORMAT_S, G_CALLBACK (time_format_changed), NULL); diff --git a/src/settings-shared.h b/src/settings-shared.h index da66205..8c14f1e 100644 --- a/src/settings-shared.h +++ b/src/settings-shared.h @@ -33,6 +33,7 @@ with this program. If not, see . #define SETTINGS_SHOW_WEEK_NUMBERS_S "show-week-numbers" #define SETTINGS_SHOW_EVENTS_S "show-events" #define SETTINGS_SHOW_LOCATIONS_S "show-locations" +#define SETTINGS_SHOW_DETECTED_S "show-auto-detected-location" #define SETTINGS_LOCATIONS_S "locations" #define SETTINGS_TIMEZONE_NAME_S "timezone-name" -- cgit v1.2.3