summaryrefslogtreecommitdiffstats
path: root/iw/timezone_gui.py
blob: c6969c1132af9995c822e0804823302111227780 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#
# timezone_gui.py: gui timezone selection.
#
# Copyright 2000-2006 Red Hat, Inc.
#
# This software may be freely redistributed under the terms of the GNU
# library public license.
#
# You should have received a copy of the GNU Library Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

import string
import gtk
import gtk.glade
import gtk.gdk
import gobject
import zonetab
import pango
import sys

from timezone_map_gui import TimezoneMap
from rhpl.translate import _, textdomain
from iw_gui import *
from bootloaderInfo import dosFilesystems
from bootloader import hasWindows

try:
    import gnomecanvas
except ImportError:
    import gnome.canvas as gnomecanvas

textdomain("system-config-date")

class TimezoneWindow(InstallWindow):
    def __init__(self, ics):
        InstallWindow.__init__(self, ics)

        # Need to set the custom handler before loading the glade file or
        # this won't work.
        gtk.glade.set_custom_handler(self.custom_widget_handler)

        # Set the default now.  We'll fix it for real in getScreen.
        self.default = "America/New York"

        self.zonetab = zonetab.ZoneTab()

        # Pull in a bunch of widgets.
        self.xml = gtk.glade.XML("/usr/share/system-config-date/system-config-date.glade", domain="system-config-date")
        self.vbox = self.xml.get_widget("tz_vbox")
        self.utcCheckbox = self.xml.get_widget("utc_check")
        self.notebook = self.xml.get_widget("notebook")

        ics.setTitle(_("Time Zone Selection"))
        ics.setNextEnabled(1)

    def custom_widget_handler(self, xml, function_name, widget_name, str1, str2,
                              int1, int2):
        if hasattr(self, function_name):
            handler = getattr(self, function_name)
            return handler(str1, str2, int1, int2)
        else:
            # Lame.
            return gtk.Label()

    def timezone_widget_create (self, str1, str2, int1, int2):
        mappath = "/usr/share/system-config-date/pixmaps/map1440.png"

        self.tz = AnacondaTZMap(self.zonetab, self.default, map=mappath,
                                viewportWidth=480)
        self.tz.show_all()
        return self.tz

    def getNext(self):
        newzone = self.tz.getCurrent().tz
        self.timezone.setTimezoneInfo(newzone.replace(" ", "_"), self.utcCheckbox.get_active())
        return None

    # TimezoneWindow tag="timezone"
    def getScreen(self, anaconda):
	self.intf = anaconda.intf        
        self.timezone = anaconda.id.timezone
        (self.default, asUTC, asArc) = self.timezone.getTimezoneInfo()

        if not self.default:
            self.default = anaconda.id.instLanguage.getDefaultTimeZone()
            asUTC = 0

        if (string.find(self.default, "UTC") != -1):
            self.default = "America/New_York"

        self.default = self.default.replace("_", " ")

        # Now fix the default we set when we made the timezone map widget.
        self.tz.setCurrent(self.zonetab.findEntryByTZ(self.default))
        self.utcCheckbox.set_active(asUTC)

        if not anaconda.isKickstart:
            self.utcCheckbox.set_active(not hasWindows(anaconda.id.bootloader))

        self.notebook.remove(self.vbox)
        return self.vbox

class AnacondaTZMap(TimezoneMap):
    def status_bar_init(self):
        self.status = None

    def load_entries (self, root):
        iter = self.tzStore.get_iter_first()

        for entry in self.zonetab.getEntries():
            if entry.lat is not None and entry.long is not None:
                x, y = self.map2canvas(entry.lat, entry.long)
                marker = root.add(gnomecanvas.CanvasText, x=x, y=y,
                                  text=u'\u00B7', fill_color='yellow',
                                  anchor=gtk.ANCHOR_CENTER,
                                  weight=pango.WEIGHT_BOLD)
                self.markers[entry.tz] = marker

                if entry.tz == "America/New York":
                    # In case the /etc/sysconfig/clock is messed up, use New
                    # York as the default.
                    self.fallbackEntry = entry

            iter = self.tzStore.insert_after(iter, [_(entry.tz), entry.tz])

    def timezone_list_init (self, default):
        self.hbox = gtk.HBox()
        self.tzStore = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)

        root = self.canvas.root()

        self.load_entries(root)

        # Add the ListStore to the sorted model after the list has been
        # populated, since otherwise we end up resorting on every addition.
        self.tzSorted = gtk.TreeModelSort(self.tzStore)
        self.tzSorted.set_sort_column_id(0, gtk.SORT_ASCENDING)
        self.tzCombo = gtk.ComboBox(model=self.tzSorted)
        cell = gtk.CellRendererText()
        self.tzCombo.pack_start(cell, True)
        self.tzCombo.add_attribute(cell, 'text', 0)
        self.tzCombo.connect("changed", self.selectionChanged)
        self.hbox.pack_start(self.tzCombo, False, False)

        self.pack_start(self.hbox, False, False)

    def selectionChanged(self, widget, *args):
        iter = widget.get_active_iter()
        entry = self.zonetab.findEntryByTZ(widget.get_model().get_value(iter, 1))
        self.setCurrent(entry)

    def updateTimezoneList(self):
        # Find the currently selected item in the combo box and update both
        # the combo and the comment label.
        iter = self.tzCombo.get_model().get_iter_first()
        while iter:
            if self.tzCombo.get_model().get_value(iter, 1) == self.currentEntry.tz:
                self.tzCombo.set_active_iter(iter)
                break

            iter = self.tzCombo.get_model().iter_next(iter)