summaryrefslogtreecommitdiffstats
path: root/iw/timezone_gui.py
blob: fb946773017ce6e03185bdd7a23df34dea82fdf3 (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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#
# timezone_gui.py: gui timezone selection.
#
# Copyright 2001 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 iutil
import gtk
from timezone_map_gui import TimezoneMap, ZoneTab
from iw_gui import *
from translate import _

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

        ics.setTitle (_("Time Zone Selection"))
        ics.setNextEnabled (1)
        ics.readHTML ("timezone")
        self.old_page = 0
        self.old_ulist_row = 9 # default to UTC row
        self.old_use_dst = 0

	self.timeZones = ((("-14", ""), ("Etc/GMT-14", "Etc/GMT-14")),
                          (("-13", ""), ("Etc/GMT-13", "Etc/GMT-13")),
                          (("-12", ""), ("Etc/GMT-12", "Etc/GMT-12")),
                          (("-11", ""), ("Etc/GMT-11", "Etc/GMT-11")),
                          (("-10", ""), ("Etc/GMT-10", "Etc/GMT-10")),
                          (("-09", ""), ("Etc/GMT-9", "Etc/GMT-9")),
                          (("-08", "US Pacific"),  ("Etc/GMT-8", "America/Los_Angeles")),
                          (("-07", "US Mountain"), ("Etc/GMT-7", "America/Denver")),
                          (("-06", "US Central"),  ("Etc/GMT-6", "America/Chicago")),
                          (("-05", "US Eastern"),  ("Etc/GMT-5", "America/New_York")),
                          (("-04", ""), ("Etc/GMT-4", "Etc/GMT-4")),
                          (("-03", ""), ("Etc/GMT-3", "Etc/GMT-3")),
                          (("-02", ""), ("Etc/GMT-2", "Etc/GMT-2")),
                          (("-01", ""), ("Etc/GMT-1", "Etc/GMT-1")),
                          (("",       ""), ("Etc/GMT", "Etc/GMT")),
                          (("+01", ""), ("Etc/GMT+1", "Etc/GMT+1")),
                          (("+02", ""), ("Etc/GMT+2", "Etc/GMT+2")),
                          (("+03", ""), ("Etc/GMT+3", "Etc/GMT+3")),
                          (("+04", ""), ("Etc/GMT+4", "Etc/GMT+4")),
                          (("+05", ""), ("Etc/GMT+5", "Etc/GMT+5")),
                          (("+06", ""), ("Etc/GMT+6", "Etc/GMT+6")),
                          (("+07", ""), ("Etc/GMT+7", "Etc/GMT+7")),
                          (("+08", ""), ("Etc/GMT+8", "Etc/GMT+8")),
                          (("+09", ""), ("Etc/GMT+9", "Etc/GMT+9")),
                          (("+10", ""), ("Etc/GMT+10", "Etc/GMT+10")),
                          (("+11", ""), ("Etc/GMT+11", "Etc/GMT+11")),
                          (("+12", ""), ("Etc/GMT+12", "Etc/GMT+12")))                    

    def getNext (self):
        self.old_page = self.nb.get_current_page ()
        self.timezone.utcOffset = self.nb.get_current_page ()
        self.timezone.dst = self.daylightCB.get_active ()
        
        if self.old_page == 0:
            newzone = self.tz.getCurrent().tz
            self.timezone.setTimezoneInfo (newzone, self.systemUTC.get_active ())
        else:
            timezone = self.timeZones[self.ulist.selection[0]][1]
            if self.daylightCB.get_active ():
                timezone = timezone[1]
            else:
                timezone = timezone[0]
            self.timezone.setTimezoneInfo (timezone, self.systemUTC.get_active ())

        return None

    def copy_toggled (self, cb1, cb2):
        if cb1.get_data ("toggling"): return
        
        cb2.set_data ("toggling", 1)
        cb2.set_active (cb1.get_active ())
        cb2.set_data ("toggling", 0)

    def view_change (self, widget, *args):
        if not self.tz.getCurrent():
            self.ics.setNextEnabled (gtk.FALSE)
        else:
            self.ics.setNextEnabled (gtk.TRUE)

    def setcurrent (self, widget, area):
        try:
            self.tz.setcurrent (self.default)
        except SystemError:
            self.default = _(self.langDefault)
            try:
                self.tz.setcurrent (self.default)
            except:
                pass
        widget.disconnect (self.id)

    # TimezoneWindow tag="timezone"
    def getScreen (self, instLang, timezone):
	self.timezone = timezone

        try:
            f = open ("/usr/share/anaconda/pixmaps/map480.png")
            f.close ()
        except:
            path = "pixmaps/map480.png"
        else:
            path = "/usr/share/anaconda/pixmaps/map480.png"
        
	nb = gtk.Notebook ()
        self.nb = nb

        mainBox = gtk.VBox (gtk.FALSE, 5)

        zonetab = ZoneTab()
        self.tz = TimezoneMap(zonetab=zonetab, map=path)

	(self.default, asUTC, asArc) = self.timezone.getTimezoneInfo()
        entry = zonetab.findEntryByTZ(self.default)
        if entry:
            self.tz.setCurrent(entry)

        self.old_page = timezone.utcOffset
        self.old_use_dst = timezone.dst
        self.langDefault = instLang.getDefaultTimeZone()
        if self.old_page:
            i = 0
            for ((offset, descr), (file, daylight)) in self.timeZones:
                if self.default == daylight or self.default == file:
                    break
                i = i + 1
            self.old_ulist_row = i
	if self.default:
            self.default = _(self.default)
	else:
            self.default = _(self.langDefault)
	    asUTC = 0

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

        self.nb.connect ("realize", lambda widget, self=self:
                         self.nb.set_current_page (self.old_page))

        systemUTCCopy = gtk.CheckButton (_("System clock uses UTC"))
        self.systemUTC = gtk.CheckButton (_("System clock uses UTC"))

        systemUTCCopy.connect ("toggled", self.copy_toggled, self.systemUTC)
        self.systemUTC.connect ("toggled", self.copy_toggled, systemUTCCopy)

        self.systemUTC.set_active (asUTC)

        hbox = gtk.HBox(gtk.FALSE, 5)
        align = gtk.Alignment (0.5, 0.5)
        align.add (self.systemUTC)
        hbox.pack_start (align, gtk.FALSE)

        pix = self.ics.readPixmap ("timezone.png")
        if pix:
            a = gtk.Alignment ()
            a.add (pix)
            a.set (1.0, 0.0, 0.0, 0.0)
            hbox.pack_start (a, gtk.TRUE)
        
        mainBox.pack_start(hbox, gtk.FALSE)
        mainBox.pack_start(self.tz, gtk.TRUE, gtk.TRUE)
        mainBox.set_border_width (5)
       	nb.append_page (mainBox, gtk.Label (_("Location")))
        
        # set up page 2
	tzBox = gtk.VBox (gtk.FALSE)
        sw = gtk.ScrolledWindow ()
        sw.set_policy (gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	self.ulist = gtk.CList (2)
        self.ulist.connect ("expose-event", lambda widget, area, self=self:
                            self.ulist.moveto (self.old_ulist_row))
        self.ulist.set_selection_mode (gtk.SELECTION_BROWSE)
        self.ulist.freeze ()
        for zone in self.timeZones:
            self.ulist.append (("UTC%s" % (zone[0][0],), zone[0][1]))
        self.ulist.columns_autosize ()
        self.ulist.thaw ()
        self.ulist.select_row (self.old_ulist_row, 0)
        sw.add (self.ulist)
        tzBox.pack_start (sw)
        box = gtk.HBox (gtk.FALSE)
        align = gtk.Alignment (0.5, 0.5)
        self.daylightCB = gtk.CheckButton (_("Use Daylight Saving Time (US only)"))
        self.daylightCB.set_active (self.old_use_dst)
        align.add (self.daylightCB)
        box.pack_start (align, gtk.FALSE)

        align = gtk.Alignment (1.0, 0.5)
        align.add (systemUTCCopy)

        box.pack_start (align, gtk.TRUE)
        tzBox.pack_start (box, gtk.FALSE)
        tzBox.set_border_width (5)
        self.tzBox = tzBox

        nb.append_page (tzBox, gtk.Label (_("UTC Offset")))

        def switch_page (widget, page, page_num, self=self):
            if page_num == 1:
                self.ics.setNextEnabled (gtk.TRUE)
            else:
                self.view_change (None)
                
        nb.connect ("switch_page", switch_page)
        
        box = gtk.VBox (gtk.FALSE, 5)
        box.pack_start (nb)
#        self.systemUTC = gtk.CheckButton (_("System clock uses UTC"))
#        self.systemUTC.set_active (asUTC)
#        align = gtk.Alignment (0, 0)
#        align.add (self.systemUTC)
#        box.pack_start (align, gtk.FALSE)
        box.set_border_width (5)

        return box