Without this patch the final word about the selected timezone was on the TimezoneMap which brought bugs and complicated things because the map doesn't store the timezone it was asked to select and when queried, it returns the value it calculates from the currently selected timezone. Thus when selecting e.g. US/Central, the map selected it correctly (visually), but when queried with get_timezone afterwards it returned America/Chicago.
All in all we shouldn't rely on the map having the best data when it does some transformations on its own and does not necessary support all timezones we want to set (now or in the future).
Signed-off-by: Vratislav Podzimek vpodzime@redhat.com --- pyanaconda/ui/gui/spokes/datetime_spoke.py | 69 +++++++++++++++++------------- 1 file changed, 40 insertions(+), 29 deletions(-)
diff --git a/pyanaconda/ui/gui/spokes/datetime_spoke.py b/pyanaconda/ui/gui/spokes/datetime_spoke.py index 33dc4f4..ad1ae64 100644 --- a/pyanaconda/ui/gui/spokes/datetime_spoke.py +++ b/pyanaconda/ui/gui/spokes/datetime_spoke.py @@ -1,6 +1,6 @@ # Datetime configuration spoke class # -# Copyright (C) 2012 Red Hat, Inc. +# Copyright (C) 2012-2013 Red Hat, Inc. # # This copyrighted material is made available to anyone wishing to use, # modify, copy, or redistribute it subject to the terms and conditions of @@ -369,11 +369,11 @@ class DatetimeSpoke(FirstbootSpokeMixIn, NormalSpoke):
self._update_datetime_timer_id = None if timezone.is_valid_timezone(self.data.timezone.timezone): - self._tzmap.set_timezone(self.data.timezone.timezone) + self._set_timezone(self.data.timezone.timezone) elif not flags.flags.automatedInstall: log.warning("%s is not a valid timezone, falling back to default "\ "(%s)" % (self.data.timezone.timezone, DEFAULT_TZ)) - self._tzmap.set_timezone(DEFAULT_TZ) + self._set_timezone(DEFAULT_TZ) self.data.timezone.timezone = DEFAULT_TZ
if not flags.can_touch_runtime_system("modify system time and date"): @@ -436,7 +436,7 @@ class DatetimeSpoke(FirstbootSpokeMixIn, NormalSpoke): self._start_updating_timer_id = None
if timezone.is_valid_timezone(self.data.timezone.timezone): - self._tzmap.set_timezone(self.data.timezone.timezone) + self._set_timezone(self.data.timezone.timezone)
self._update_datetime()
@@ -454,6 +454,28 @@ class DatetimeSpoke(FirstbootSpokeMixIn, NormalSpoke):
self._ntpSwitch.set_active(ntp_working)
+ def _set_timezone(self, timezone): + """ + Sets timezone to the city/region comboboxes and the timezone map. + + :param timezone: timezone to set + :type timezone: str + :return: if successfully set or not + :rtype: bool + + """ + + parts = timezone.split("/", 1) + if len(parts) != 2: + # invalid timezone cannot be set + return False + + region, city = parts + self._set_combo_selection(self._regionCombo, region) + self._set_combo_selection(self._cityCombo, city) + + return True + @gtk_action_nowait def add_to_store(self, store, item): store.append([item]) @@ -666,8 +688,7 @@ class DatetimeSpoke(FirstbootSpokeMixIn, NormalSpoke): def _restore_old_city_region(self): """Restore stored "old" (or last valid) values."""
- self._set_combo_selection(self._regionCombo, self._old_region) - self._set_combo_selection(self._cityCombo, self._old_city) + self._set_timezone(self._old_region + "/" + self._old_city)
def on_up_hours_clicked(self, *args): self._stop_and_maybe_start_time_updating() @@ -741,6 +762,7 @@ class DatetimeSpoke(FirstbootSpokeMixIn, NormalSpoke): """
region = self._get_active_region() + if not region or region == self._old_region: # region entry being edited or old_value chosen, no action needed # @see: on_city_changed @@ -779,18 +801,17 @@ class DatetimeSpoke(FirstbootSpokeMixIn, NormalSpoke):
if city and region: timezone = region + "/" + city + else: + # both city and region are needed to form a valid timezone + return
- if timezone is not None and region == "Etc": + if region == "Etc": # Etc timezones cannot be displayed on the map, so let's set the map # to "" which sets it to "Europe/London" (UTC) without a city pin - self._tzmap.set_timezone("") - - # Change to Etc/XXXXX emits timezone-changed with "" as timezone, - # so let's help it a bit. - self._tzmap.emit("timezone-changed", timezone) - - elif timezone and (self._tzmap.get_timezone() != timezone): - self._tzmap.set_timezone(timezone) + self._tzmap.set_timezone("", no_signal=True) + else: + # we don't want the timezone-changed signal to be emitted + self._tzmap.set_timezone(timezone, no_signal=True)
# update "old" values self._old_city = city @@ -838,20 +859,10 @@ class DatetimeSpoke(FirstbootSpokeMixIn, NormalSpoke): self._daysFilter.refilter()
def on_timezone_changed(self, tz_map, timezone): - fields = timezone.split("/", 1) - if len(fields) == 1: - # timezone may be "" - return - - region, city = fields - if region != "Etc": - # If region is "Etc", TimezoneMap returns "" from get_timezone - # and changing comboboxes here would create an endless loop. - self._set_combo_selection(self._regionCombo, region) - self._set_combo_selection(self._cityCombo, city) - - os.environ["TZ"] = timezone - self._update_datetime() + if self._set_timezone(timezone): + # timezone successfully set + os.environ["TZ"] = timezone + self._update_datetime()
def on_timeformat_changed(self, button24h, *args): hours = int(self._hoursLabel.get_text())