Enable Translations
[vuplus_dvbapp-plugin] / webinterface / src / __init__.py
1 import Plugins.Plugin
2 from Components.config import config
3 from Components.config import ConfigSubsection
4 from Components.config import ConfigSelection
5 from Components.config import ConfigInteger
6 from Components.config import ConfigSubList
7 from Components.config import ConfigSubDict
8 from Components.config import ConfigText
9 from Components.config import configfile
10 from Components.config import ConfigYesNo
11 from Components.Network import iNetwork
12 from Components.Language import language
13 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_LANGUAGE
14 import os,gettext
15
16 __version__ = "1.5beta2"
17
18 PluginLanguageDomain = "WebInterface"
19 PluginLanguagePath = "Extensions/WebInterface/locale"
20
21 def localeInit():
22     lang = language.getLanguage()[:2] # getLanguage returns e.g. "fi_FI" for "language_country"
23     os.environ["LANGUAGE"] = lang # Enigma doesn't set this (or LC_ALL, LC_MESSAGES, LANG). gettext needs it!
24     print "[WebInterface] set language to ", lang
25     gettext.bindtextdomain(PluginLanguageDomain, resolveFilename(SCOPE_PLUGINS, PluginLanguagePath))
26
27 def _(txt):
28     t = gettext.dgettext(PluginLanguageDomain, txt)
29     if t == txt:
30         print "[WebInterface] fallback to default translation for", txt
31         t = gettext.gettext(txt)
32     return t
33     
34 localeInit()
35 language.addCallback(localeInit)
36
37
38 config.plugins.Webinterface = ConfigSubsection()
39 config.plugins.Webinterface.enable = ConfigYesNo(default = True)
40 config.plugins.Webinterface.allowzapping = ConfigYesNo(default = True)
41 config.plugins.Webinterface.includehdd = ConfigYesNo(default = False)
42 config.plugins.Webinterface.autowritetimer = ConfigYesNo(default = False)
43 config.plugins.Webinterface.loadmovielength = ConfigYesNo(default = False)
44 config.plugins.Webinterface.version = ConfigText(__version__) # used to make the versioninfo accessible enigma2-wide, not confgurable in GUI. 
45 config.plugins.Webinterface.interfacecount = ConfigInteger(0)
46 config.plugins.Webinterface.interfaces = ConfigSubList()
47 config.plugins.Webinterface.warningsslsend = ConfigYesNo(default = False)
48
49
50 def addInterfaceConfig():
51     choices = getCofiguredAndSpecialNetworkinterfaces()
52     i = len(config.plugins.Webinterface.interfaces)
53     config.plugins.Webinterface.interfaces.append(ConfigSubsection())
54     config.plugins.Webinterface.interfaces[i].disabled = ConfigYesNo(default = False)
55     config.plugins.Webinterface.interfaces[i].address = ConfigSelection(choices,default=choices[0])
56     config.plugins.Webinterface.interfaces[i].port = ConfigInteger(80, (0,65535))
57     config.plugins.Webinterface.interfaces[i].useauth = ConfigYesNo(default = False)
58     config.plugins.Webinterface.interfaces[i].usessl = ConfigYesNo(default = False)
59     config.plugins.Webinterface.interfacecount.value = i+1
60     return i
61
62 def getCofiguredAndSpecialNetworkinterfaces():
63     nw = iNetwork
64     choices = []
65     choices.append('0.0.0.0')
66     choices.append('127.0.0.1')
67     for adaptername in nw.ifaces:
68         extip = nw.ifaces[adaptername]['ip']
69         if nw.ifaces[adaptername]['up'] is True:
70             extip = "%i.%i.%i.%i"%(extip[0],extip[1],extip[2],extip[3])
71             choices.append(extip)
72     return choices
73
74 if config.plugins.Webinterface.interfacecount.value == 0:
75     # setting default interface
76     # 0.0.0.0:80 auth=False
77     config.plugins.Webinterface.interfaces.append(ConfigSubsection())
78     config.plugins.Webinterface.interfaces[0].disabled = ConfigYesNo(default = False)
79     
80     #needs to be refreshed before each call, because ifaces can be changed since e2 boot 
81     config.plugins.Webinterface.interfaces[0].address = ConfigSelection(getCofiguredAndSpecialNetworkinterfaces(),default='0.0.0.0')
82     
83     config.plugins.Webinterface.interfaces[0].port = ConfigInteger(80, (0,65535))
84     config.plugins.Webinterface.interfaces[0].useauth = ConfigYesNo(default = False)
85     config.plugins.Webinterface.interfaces[0].usessl = ConfigYesNo(default = False)
86     config.plugins.Webinterface.interfacecount.value = 1
87     config.plugins.Webinterface.interfacecount.save()
88     config.plugins.Webinterface.interfaces[0].save()
89 else:    
90     for i in range(0, config.plugins.Webinterface.interfacecount.value):
91         addInterfaceConfig()
92