summaryrefslogtreecommitdiffstats
path: root/textw/timezone_text.py
blob: 431836fb7077dc0509a62c91d1d580468c2d464d (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
#
# timezone_text.py: text mode timezone selection dialog
#
# 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 sys
import string
import iutil
import os
from time import *
from snack import *
from constants_text import *
from rhpl.translate import _, textdomain
from bootloader import hasWindows

textdomain("system-config-date")

sys.path.append("/usr/share/system-config-date")

class TimezoneWindow:

    def getTimezoneList(self):
        import zonetab

        zt = zonetab.ZoneTab()
        zoneList = [ x.tz for x in zt.getEntries() ]
        zoneList.sort()
        return zoneList

    def updateSysClock(self):
	args = ["--hctosys"]
	if self.c.selected():
	    args.append("--utc")

	iutil.execWithRedirect("hwclock", args, searchPath=1)
	self.g.setTimer(500)
	self.updateClock()

    def updateClock(self):
        # disable for now
        return
        
#	if os.access("/usr/share/zoneinfo/" + self.l.current(), os.R_OK):
#	    os.environ['TZ'] = self.l.current()
#	    self.label.setText(self.currentTime())
#	else:
#	    self.label.setText("")

    def currentTime(self):
	return "Current time: " + strftime("%X %Z", localtime(time()))

    def __call__(self, screen, anaconda):
	timezones = self.getTimezoneList()
	(default, asUtc, asArc) = anaconda.id.timezone.getTimezoneInfo()
        if not default:
	    default = anaconda.id.instLanguage.getDefaultTimeZone()

	bb = ButtonBar(screen, [TEXT_OK_BUTTON, TEXT_BACK_BUTTON])
	t = TextboxReflowed(30, 
			_("What time zone are you located in?"))

        if not anaconda.isKickstart and not hasWindows(anaconda.id.bootloader):
            asUtc = True

#
# disabling this for now
# 
#	self.label = Label(self.currentTime())
		
	self.l = Listbox(5, scroll = 1, returnExit = 0)

        for tz in timezones:
	    self.l.append(_(tz), tz)

	self.l.setCurrent(default)
#	self.l.setCallback(self.updateClock)
        
	self.c = Checkbox(_("System clock uses UTC"), isOn = asUtc)
#	self.c.setCallback(self.updateSysClock)

	self.g = GridFormHelp(screen, _("Time Zone Selection"), "timezone",
			      1, 5)
	self.g.add(t, 0, 0)
#	self.g.add(self.label, 0, 1, padding = (0, 1, 0, 0), anchorLeft = 1)
	self.g.add(self.c, 0, 2, padding = (0, 1, 0, 1), anchorLeft = 1)
	self.g.add(self.l, 0, 3, padding = (0, 0, 0, 1))
	self.g.add(bb, 0, 4, growx = 1)

# disabling for now
#	self.updateClock()
#	self.updateSysClock()
#
#	self.g.setTimer(500)
#
#	result = "TIMER"
#	while result == "TIMER":
#	    result = self.g.run()
#	    if result == "TIMER":
#		self.updateClock()

        result = ""
        while 1:
            result = self.g.run()
            rc = bb.buttonPressed (result)
            
            if rc == TEXT_BACK_CHECK:
                screen.popWindow()
                return INSTALL_BACK
            else:
                break

        screen.popWindow()
	anaconda.id.timezone.setTimezoneInfo(self.l.current(), asUtc = self.c.selected())

	return INSTALL_OK