Webinterface: check fullpath in getMovieSubdirs
[enigma2-plugins.git] / emailclient / src / EmailConfig.py
1 '''
2 Configuration screens for EmailClient
3 '''
4 from Screens.Screen import Screen
5 from Screens.MessageBox import MessageBox
6 from Components.config import config, getConfigListEntry, ConfigText, ConfigPassword, ConfigSelection, ConfigOnOff
7 from Components.ConfigList import ConfigListScreen
8 from Components.Label import Label
9 from Components.ActionMap import ActionMap
10
11 from . import initLog, debug, scaleV, DESKTOP_WIDTH, DESKTOP_HEIGHT #@UnresolvedImport# pylint: disable-msg=C0103,F0401
12
13 class EmailConfigOptions(ConfigListScreen, Screen):
14         noButtons = 2
15         width = max(noButtons*140+100, 550)
16         height = 5*30+50
17         buttonsGap = (width-noButtons*140)/(noButtons+1)
18         skin = """
19                 <screen position="%d,%d" size="%d,%d" title="Email Setup" >
20                 <widget name="config" position="0,0" size="%d,%d" scrollbarMode="showOnDemand" />
21                 <ePixmap position="%d,%d" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
22                 <ePixmap position="%d,%d" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
23                 <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" />
24                 <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" />
25                 </screen>""" % (
26                                         (DESKTOP_WIDTH-width)/2, (DESKTOP_HEIGHT-height)/2, width, height,
27                                         width, height-50,  # config
28                                         buttonsGap, height-45,
29                                         2*buttonsGap+140, height-45,
30                                         buttonsGap, height-45, scaleV(22,18),
31                                         2*buttonsGap+140, height-45, scaleV(22,18),
32                                         )
33
34         def __init__(self, session, versionString):
35                 self.versionString = versionString
36                 Screen.__init__(self, session)
37                 self.list = []
38                 ConfigListScreen.__init__(self, self.list, session=session)
39                 self["buttonred"] = Label(_("cancel"))
40                 self["buttongreen"] = Label(_("ok"))
41                 self["setupActions"] = ActionMap(["SetupActions"],
42                 {
43                         "green": self.save,
44                         "red": self.cancel,
45                         "save": self.save,
46                         "cancel": self.cancel,
47                         "ok": self.save,
48                 }, -2)
49                 self.list = [
50                         getConfigListEntry(_("show deleted entries"), config.plugins.emailimap.showDeleted),
51                         getConfigListEntry(_("display timeout (seconds)"), config.plugins.emailimap.timeout),
52                         getConfigListEntry(_("display connection errors"), config.plugins.emailimap.verbose),
53                         getConfigListEntry(_("debug"), config.plugins.emailimap.debug),
54                         ]       
55                 self["config"].list = self.list
56                 self["config"].l.setList(self.list)
57                 self.onLayoutFinish.append(self._layoutFinish)
58
59         def _layoutFinish(self):
60                 self.setTitle(_("Email setup") + " (" + self.versionString + ")")
61
62         def save(self):
63                 debug("[EmailConfigOptions] saving")
64                 for x in self["config"].list:
65                         x[1].save()
66                 if config.plugins.emailimap.debug.isChanged():
67                         initLog()
68                 self.close(True)
69
70         def cancel(self):
71                 debug("[EmailConfigOptions] cancel")
72                 for x in self["config"].list:
73                         x[1].cancel()
74                 self.close(False)
75
76 class EmailConfigAccount(ConfigListScreen, Screen):
77         width = max(2*140+100, 550)
78         height = 5*30+50
79         buttonsGap = (width-2*140)/3
80         skin = """
81                 <screen position="%d,%d" size="%d,%d" title="Account Setup" >
82                 <widget name="config" position="0,0" size="%d,%d" scrollbarMode="showOnDemand" />
83                 <ePixmap position="%d,%d" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
84                 <ePixmap position="%d,%d" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
85                 <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" />
86                 <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" />
87                 </screen>""" % (
88                                         (DESKTOP_WIDTH-width)/2, (DESKTOP_HEIGHT-height)/2, width, height,
89                                         width, height-50,  # config
90                                         buttonsGap, height-45,
91                                         2*buttonsGap+140, height-45,
92                                         buttonsGap, height-45, scaleV(22,18),
93                                         2*buttonsGap+140, height-45, scaleV(22,18)
94                                         )
95
96         def __init__(self, session, params=None):
97                 debug("[EmailConfigAccount] __init__")
98                 self._session = session
99                 Screen.__init__(self, session)
100                 self.list = []
101                 ConfigListScreen.__init__(self, self.list, session=session)
102                 self["buttonred"] = Label(_("cancel"))
103                 self["buttongreen"] = Label(_("ok"))
104                 self["setupActions"] = ActionMap(["SetupActions"],
105                 {
106                         "green": self.save,
107                         "red": self.cancel,
108                         "save": self.save,
109                         "cancel": self.cancel,
110                         "ok": self.save,
111                 }, -2)
112                 
113                 if params:
114                         (self._name, self._server, self._port, self._user, self._password, self._interval, self._maxmail, self._listall) = params
115                 else:
116                         (self._name, self._server, self._port, self._user, self._password, self._interval, self._maxmail, self._listall) = ("", "", "993", "", "", "60", "50", False)
117                 self._cName = ConfigText(self._name, fixed_size=False)
118                 self._cServer = ConfigText(self._server, fixed_size=False)
119                 self._cPort = ConfigSelection(choices=[("143", "143"), ("993", "993 (SSL)")], default=self._port)
120                 self._cUser = ConfigText(self._user, fixed_size=False)
121                 self._cPassword = ConfigPassword(self._password, fixed_size=False)
122                 self._cInterval = ConfigText(self._interval, fixed_size=False)
123                 self._cInterval.setUseableChars('0123456789,')
124                 self._cMaxmail = ConfigText(self._maxmail, fixed_size=False)
125                 self._cMaxmail.setUseableChars('0123456789,')
126                 self._cListall = ConfigOnOff(self._listall)
127                 
128                 self.list = [
129                                         getConfigListEntry(_("account name"), self._cName),
130                                         getConfigListEntry(_("IMAP Server"), self._cServer),
131                                         getConfigListEntry(_("IMAP Port"), self._cPort),
132                                         getConfigListEntry(_("user name"), self._cUser),
133                                         getConfigListEntry(_("password"), self._cPassword),
134                                         getConfigListEntry(_("mail check interval (minutes)"), self._cInterval),
135                                         getConfigListEntry(_("maximum mail size to fetch"), self._cMaxmail),
136                                         getConfigListEntry(_("list all mailboxes"), self._cListall)
137                                         ]
138                 self["config"].list = self.list
139                 self["config"].l.setList(self.list)
140
141         def save(self):
142                 debug("[EmailConfigAccount] saving")
143                 # do some sanity checks
144                 if not self._cName.value or not self._cServer.value or not self._cUser.value or not self._cPassword.value or not self._cInterval.value or not self._cMaxmail.value:
145                         self._session.open(MessageBox, _("empty values - retry"), type=MessageBox.TYPE_ERROR, timeout=config.plugins.emailimap.timeout.value)
146                 else:
147                         if self._cListall.value:
148                                 self.close((self._cName.value, self._cServer.value, self._cPort.value, self._cUser.value, self._cPassword.value, self._cInterval.value, self._cMaxmail.value, 1))
149                         else:
150                                 self.close((self._cName.value, self._cServer.value, self._cPort.value, self._cUser.value, self._cPassword.value, self._cInterval.value, self._cMaxmail.value, 0))
151
152         def cancel(self):
153                 debug("[EmailConfigAccount] cancel")
154                 self.close(None)