add stv0299 snr to dB Calculation (thx to adenin for this)
[enigma2.git] / lib / python / Components / Timezones.py
index 90b227f770e07d5abd38c40acd619d66ca3ecdf9..6e43aa21120c9e6d3d3367d6ffbf148a050e8999 100644 (file)
@@ -1,6 +1,9 @@
 from xml.sax import make_parser
 from xml.sax.handler import ContentHandler
 
+import os
+import time
+
 class Timezones:
        class parseTimezones(ContentHandler):
                def __init__(self, timezones):
@@ -8,26 +11,50 @@ 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:
+                       from enigma import e_tzset
+                       e_tzset()
+               
+       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?
+               t = "(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Vienna"
+               for (a,b) in self.timezones:
+                       if a == t:
+                               return a
+               return self.timezones[0][0]
 
 timezones = Timezones()