summaryrefslogtreecommitdiffstats
path: root/iw/timezone_gui.py
blob: 77814349cbe982fed762db207218aa611f009f3f (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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#
# timezone_gui.py: gui timezone selection.
#
# Copyright 2000-2002 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
import gobject
from timezone_map_gui import TimezoneMap, ZoneTab
from iw_gui import *
from rhpl.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_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:
	    selection = self.uview.get_selection()
	    (model, iter) = selection.get_selected()
	    if iter:
		val = model.get_value(iter, 0)
		timezone = None
		for zone in self.timeZones:
		    if val[3:] == zone[0][0]:
			timezone=zone[1]
			break

		if not timezone:
		    print "unknown utc selected!!"
		    timezone = self.timeZones[12][1]
		    
	    else:
		print "unknown utc selected!!"
		timezone = self.timeZones[12][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)

    # 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()

        self.old_page = timezone.utcOffset
        self.old_use_dst = timezone.dst
        self.langDefault = instLang.getDefaultTimeZone()

	if not self.default:
            self.default = self.langDefault
	    asUTC = 0

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

        self.tz.setCurrent(zonetab.findEntryByTZ(self.default))

        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)
#        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(self.tz, gtk.TRUE, gtk.TRUE)
        mainBox.set_border_width(5)

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

       	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.ustore = gtk.ListStore(gobject.TYPE_STRING,
				    gobject.TYPE_STRING)

	# default to US/Eastern
	utc_match = "Etc/GMT-5"
        if self.old_page:
            i = 0
            for ((offset, descr), (file, daylight)) in self.timeZones:
                if self.default == daylight or self.default == file:
		    utc_match = file
                    break
                i = i + 1

	self.utc_default_iter = None
        for zone in self.timeZones:
	    iter=self.ustore.append()
	    if not self.utc_default_iter:
		self.utc_default_iter = iter
		
	    self.ustore.set_value(iter, 0, "UTC%s" % (zone[0][0],))
	    self.ustore.set_value(iter, 1, zone[0][1])
	    if utc_match and utc_match == zone[1][0]:
		self.utc_default_iter = iter

#        self.ulist.select_row (self.old_ulist_row, 0)

        self.uview = gtk.TreeView(self.ustore)

	self.uview.get_selection().select_iter(self.utc_default_iter)

	renderer = gtk.CellRendererText()
	col = gtk.TreeViewColumn("", renderer, text=0)
	self.uview.append_column(col)
	renderer = gtk.CellRendererText()
	col = gtk.TreeViewColumn("", renderer, text=1)
	self.uview.append_column(col)
	self.uview.set_headers_visible(gtk.FALSE)

        sw.add(self.uview)
        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