use space better under HD skins, decode quoted printables, cosmetic changes
[enigma2-plugins.git] / emailclient / src / EmailConfig.py
1 from Screens.Screen import Screen
2 from Components.config import config, getConfigListEntry
3 from Components.ConfigList import ConfigListScreen
4 from Components.Label import Label
5 from Components.ActionMap import ActionMap
6
7 from enigma import getDesktop
8 DESKTOP_WIDTH = getDesktop(0).size().width()
9 DESKTOP_HEIGHT = getDesktop(0).size().height()
10 def scaleH(y2, y1):
11         if y2 == -1:
12                 y2 = y1*1280/720
13         elif y1 == -1:
14                 y1 = y2*720/1280
15         return scale(y2, y1, 1280, 720, DESKTOP_WIDTH)
16 def scaleV(y2, y1):
17         if y2 == -1:
18                 y2 = y1*720/576
19         elif y1 == -1:
20                 y1 = y2*576/720
21         return scale(y2, y1, 720, 576, DESKTOP_HEIGHT)
22 def scale(y2, y1, x2, x1, x):
23         return (y2 - y1) * (x - x1) / (x2 - x1) + y1
24
25 class EmailConfigScreen(ConfigListScreen,Screen):
26         width = max(2*140+100, 550)
27         height = 5*30+50
28         buttonsGap = (width-2*140)/3
29         skin = """
30                 <screen position="%d,%d" size="%d,%d" title="Email Setup" >
31                 <widget name="config" position="0,0" size="%d,%d" scrollbarMode="showOnDemand" />
32                 <ePixmap position="%d,%d" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
33                 <ePixmap position="%d,%d" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
34                 <widget name="buttonred" position="%d,%d" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;%d" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
35                 <widget name="buttongreen" position="%d,%d" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;%d" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
36                 <widget name="info" position="%d,%d" size="100,40" halign="right" zPosition="2"  foregroundColor="white" font="Regular;%d"/> 
37                 </screen>""" %(
38                                         (DESKTOP_WIDTH-width)/2, (DESKTOP_HEIGHT-height)/2, width, height,
39                                         width, height-50,  # config
40                                         buttonsGap, height-45,
41                                         2*buttonsGap+140, height-45,
42                                         buttonsGap, height-45, scaleV(22,18),
43                                         2*buttonsGap+140, height-45, scaleV(22,18),
44                                         3*buttonsGap+2*140, height-45, scaleV(22,18)
45                                         )
46
47         def __init__(self, session, args = 0):
48                 Screen.__init__(self, session)
49                 l = [
50                         getConfigListEntry(_("Username"), config.plugins.emailimap.username),
51                         getConfigListEntry(_("Password"), config.plugins.emailimap.password),
52                         getConfigListEntry(_("IMAP Server"), config.plugins.emailimap.server),
53                         getConfigListEntry(_("IMAP Port"), config.plugins.emailimap.port),
54                         getConfigListEntry(_("max of Headers to load"), config.plugins.emailimap.maxheadertoload)
55                 ]
56                 
57                 ConfigListScreen.__init__(self, l)
58                 self["buttonred"] = Label(_("cancel"))
59                 self["buttongreen"] = Label(_("ok"))
60                 self["info"] = Label('by 3c5x9')
61                 self["setupActions"] = ActionMap(["SetupActions"],
62                 {
63                         "green": self.save,
64                         "red": self.cancel,
65                         "save": self.save,
66                         "cancel": self.cancel,
67                         "ok": self.save,
68                 }, -2)
69
70         def save(self):
71                 print "saving"
72                 for x in self["config"].list:
73                         x[1].save()
74                 self.close(True)
75
76         def cancel(self):
77                 print "cancel"
78                 for x in self["config"].list:
79                         x[1].cancel()
80                 self.close(False)