follow core event changes
[enigma2.git] / lib / python / Components / Timezones.py
index 90b227f770e07d5abd38c40acd619d66ca3ecdf9..15837450e1074a70966a57a627740c74b0ed807e 100644 (file)
@@ -1,6 +1,11 @@
 from xml.sax import make_parser
 from xml.sax.handler import ContentHandler
 
+import os
+import time
+
+from enigma import *
+
 class Timezones:
        class parseTimezones(ContentHandler):
                def __init__(self, timezones):
@@ -8,26 +13,45 @@ class Timezones:
                        self.timezones = timezones
        
                def startElement(self, name, attrs):
-                       print "Name: " + str(name)
                        if (name == "zone"):
-                               self.timezones[attrs.get('name',"")] = attrs.get('zone',"")
-                               #print "found sat " + attrs.get('name',"") + " " + str(attrs.get('position',""))
-                               #tpos = attrs.get('position',"")
-                               #tname = attrs.get('name',"")
-                               #self.satellites[tpos] = tname
-                               #self.satList.append( (tname, tpos) )
-                               #self.parsedSat = int(tpos)
+                               self.timezones.append((attrs.get('name',""), attrs.get('zone',"")))
        
        def __init__(self):
-               self.timezones = {}
+               self.timezones = []
                
                self.readTimezonesFromFile()
 
        def readTimezonesFromFile(self):
                parser = make_parser()
-               timezonesHandler = self.parseTimezones(self.timezones)
-               parser.setContentHandler(timezonesHandler)
-               parser.parse('/etc/timezone.xml')
                
+               try:
+                       timezonesHandler = self.parseTimezones(self.timezones)
+                       parser.setContentHandler(timezonesHandler)
+                       parser.parse('/etc/timezone.xml')
+               except:
+                       pass
+               
+               if len(self.timezones) == 0:
+                       self.timezones = [("UTC", "UTC")]
+               
+       def activateTimezone(self, index):
+               if len(self.timezones) <= index:
+                       return
+               
+               os.environ['TZ'] = self.timezones[index][1]
+               try:
+                       time.tzset()
+               except:
+                       etimezone()
+               
+       def getTimezoneList(self):
+               list = []
+               for x in self.timezones:
+                       list.append(str(x[0]))
+               return list
+       
+       def getDefaultTimezone(self):
+               # TODO return something more useful - depending on country-settings?
+               return 27
 
 timezones = Timezones()