ADD: (un)delete message, option to show deleted messages
[vuplus_dvbapp-plugin] / 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                         getConfigListEntry(_("show deleted entries"), config.plugins.emailimap.showDeleted)                     
56                 ]
57                 
58                 ConfigListScreen.__init__(self, l)
59                 self["buttonred"] = Label(_("cancel"))
60                 self["buttongreen"] = Label(_("ok"))
61                 self["info"] = Label('by 3c5x9')
62                 self["setupActions"] = ActionMap(["SetupActions"],
63                 {
64                         "green": self.save,
65                         "red": self.cancel,
66                         "save": self.save,
67                         "cancel": self.cancel,
68                         "ok": self.save,
69                 }, -2)
70
71         def save(self):
72                 print "saving"
73                 for x in self["config"].list:
74                         x[1].save()
75                 self.close(True)
76
77         def cancel(self):
78                 print "cancel"
79                 for x in self["config"].list:
80                         x[1].cancel()
81                 self.close(False)