1 # -*- coding: utf-8 -*-
2 # for localized messages
3 #from __init__ import _
4 from Screens.Screen import Screen
5 from Screens.MessageBox import MessageBox
6 from Screens.VirtualKeyBoard import VirtualKeyBoard
7 from Components.ActionMap import ActionMap
8 from Components.Sources.StaticText import StaticText
9 from Components.config import config, ConfigIP, NoSave, ConfigText, ConfigEnableDisable, ConfigPassword, ConfigSelection, getConfigListEntry, ConfigYesNo
10 from Components.ConfigList import ConfigListScreen
11 from Components.Pixmap import Pixmap
12 from Components.ActionMap import ActionMap, NumberActionMap
13 from enigma import ePoint
14 from AutoMount import iAutoMount, AutoMount
15 from re import sub as re_sub
17 class AutoMountEdit(Screen, ConfigListScreen):
19 <screen name="AutoMountEdit" position="center,center" size="560,450" title="MountEdit">
20 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
21 <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
22 <widget name="config" position="5,50" size="550,250" zPosition="1" scrollbarMode="showOnDemand" />
23 <ePixmap pixmap="skin_default/div-h.png" position="0,420" zPosition="1" size="560,2" />
24 <widget source="introduction" render="Label" position="10,430" size="540,21" zPosition="10" font="Regular;21" halign="center" valign="center" backgroundColor="#25062748" transparent="1"/>
25 <widget name="VKeyIcon" pixmap="skin_default/buttons/key_text.png" position="10,430" zPosition="10" size="35,25" transparent="1" alphatest="on" />
26 <widget name="HelpWindow" pixmap="skin_default/vkey_icon.png" position="160,350" zPosition="1" size="1,1" transparent="1" alphatest="on" />
29 def __init__(self, session, plugin_path, mountinfo = None ):
30 self.skin_path = plugin_path
31 self.session = session
32 Screen.__init__(self, self.session)
34 self.mountinfo = mountinfo
35 if self.mountinfo is None:
36 #Initialize blank mount enty
37 self.mountinfo = { 'isMounted': False, 'active': False, 'ip': False, 'sharename': False, 'sharedir': False, 'username': False, 'password': False, 'mounttype' : False, 'options' : False, 'hdd_replacement' : False }
39 self.applyConfigRef = None
40 self.updateConfigRef = None
41 self.mounts = iAutoMount.getMountsList()
44 self["actions"] = NumberActionMap(["SetupActions"],
52 self["VirtualKB"] = ActionMap(["VirtualKeyboardActions"],
54 "showVirtualKeyboard": self.KeyText,
58 ConfigListScreen.__init__(self, self.list,session = self.session)
60 self.onLayoutFinish.append(self.layoutFinished)
62 self["VKeyIcon"] = Pixmap()
63 self["HelpWindow"] = Pixmap()
64 self["introduction"] = StaticText(_("Press OK to activate the settings."))
65 self["key_red"] = StaticText(_("Cancel"))
68 def layoutFinished(self):
69 self.setTitle(_("Mounts editor"))
70 self["VKeyIcon"].hide()
71 self["VirtualKB"].setEnabled(False)
72 self["HelpWindow"].hide()
74 # helper function to convert ips from a sring to a list of ints
75 def convertIP(self, ip):
85 def createConfig(self):
86 self.sharenameEntry = None
87 self.mounttypeEntry = None
88 self.activeEntry = None
90 self.sharedirEntry = None
91 self.optionsEntry = None
92 self.usernameEntry = None
93 self.passwordEntry = None
94 self.hdd_replacementEntry = None
96 self.sharetypelist = []
97 self.sharetypelist.append(("nfs", _("NFS share")))
98 self.sharetypelist.append(("cifs", _("CIFS share")))
100 if self.mountinfo.has_key('mounttype'):
101 mounttype = self.mountinfo['mounttype']
105 if self.mountinfo.has_key('active'):
106 active = self.mountinfo['active']
109 if active == 'False':
113 if self.mountinfo.has_key('ip'):
114 if self.mountinfo['ip'] is False:
115 ip = [192, 168, 0, 0]
117 ip = self.convertIP(self.mountinfo['ip'])
119 ip = [192, 168, 0, 0]
120 if self.mountinfo.has_key('sharename'):
121 sharename = self.mountinfo['sharename']
123 sharename = "Sharename"
124 if self.mountinfo.has_key('sharedir'):
125 sharedir = self.mountinfo['sharedir']
127 sharedir = "/export/hdd"
128 if self.mountinfo.has_key('options'):
129 options = self.mountinfo['options']
131 options = "rw,nolock,tcp"
132 if self.mountinfo.has_key('username'):
133 username = self.mountinfo['username']
136 if self.mountinfo.has_key('password'):
137 password = self.mountinfo['password']
140 if self.mountinfo.has_key('hdd_replacement'):
141 hdd_replacement = self.mountinfo['hdd_replacement']
142 if hdd_replacement == 'True':
143 hdd_replacement = True
144 if hdd_replacement == 'False':
145 hdd_replacement = False
147 hdd_replacement = False
148 if sharename is False:
149 sharename = "Sharename"
150 if sharedir is False:
151 sharedir = "/export/hdd"
153 if mounttype == "nfs":
154 options = "rw,nolock,tcp"
157 if username is False:
159 if password is False:
161 if mounttype is False:
164 self.activeConfigEntry = NoSave(ConfigEnableDisable(default = active))
165 self.ipConfigEntry = NoSave(ConfigIP(default = ip))
166 self.sharenameConfigEntry = NoSave(ConfigText(default = sharename, visible_width = 50, fixed_size = False))
167 self.sharedirConfigEntry = NoSave(ConfigText(default = sharedir, visible_width = 50, fixed_size = False))
168 self.optionsConfigEntry = NoSave(ConfigText(default = options, visible_width = 50, fixed_size = False))
169 self.usernameConfigEntry = NoSave(ConfigText(default = username, visible_width = 50, fixed_size = False))
170 self.passwordConfigEntry = NoSave(ConfigPassword(default = password, visible_width = 50, fixed_size = False))
171 self.mounttypeConfigEntry = NoSave(ConfigSelection(self.sharetypelist, default = mounttype ))
172 self.hdd_replacementConfigEntry = NoSave(ConfigYesNo(default = hdd_replacement))
174 def createSetup(self):
176 self.activeEntry = getConfigListEntry(_("Active"), self.activeConfigEntry)
177 self.list.append(self.activeEntry)
178 self.sharenameEntry = getConfigListEntry(_("Local share name"), self.sharenameConfigEntry)
179 self.list.append(self.sharenameEntry)
180 self.mounttypeEntry = getConfigListEntry(_("Mount type"), self.mounttypeConfigEntry)
181 self.list.append(self.mounttypeEntry)
182 self.ipEntry = getConfigListEntry(_("Server IP"), self.ipConfigEntry)
183 self.list.append(self.ipEntry)
184 self.sharedirEntry = getConfigListEntry(_("Server share"), self.sharedirConfigEntry)
185 self.list.append(self.sharedirEntry)
186 self.hdd_replacementEntry = getConfigListEntry(_("use as HDD replacement"), self.hdd_replacementConfigEntry)
187 self.list.append(self.hdd_replacementEntry)
188 if self.mounttypeConfigEntry.value == "cifs":
189 self.optionsConfigEntry = NoSave(ConfigText(default = "rw", visible_width = 50, fixed_size = False))
191 self.optionsConfigEntry = NoSave(ConfigText(default = "rw,nolock,tcp", visible_width = 50, fixed_size = False))
192 self.optionsEntry = getConfigListEntry(_("Mount options"), self.optionsConfigEntry)
193 self.list.append(self.optionsEntry)
194 if self.mounttypeConfigEntry.value == "cifs":
195 self.usernameEntry = getConfigListEntry(_("Username"), self.usernameConfigEntry)
196 self.list.append(self.usernameEntry)
197 self.passwordEntry = getConfigListEntry(_("Password"), self.passwordConfigEntry)
198 self.list.append(self.passwordEntry)
200 self["config"].list = self.list
201 self["config"].l.setList(self.list)
202 self["config"].onSelectionChanged.append(self.selectionChanged)
205 if self["config"].getCurrent() == self.mounttypeEntry:
209 print "Green Pressed"
210 if self["config"].getCurrent() == self.sharenameEntry:
211 self.session.openWithCallback(lambda x : self.VirtualKeyBoardCallback(x, 'sharename'), VirtualKeyBoard, title = (_("Enter share name:")), text = self.sharenameConfigEntry.value)
212 if self["config"].getCurrent() == self.sharedirEntry:
213 self.session.openWithCallback(lambda x : self.VirtualKeyBoardCallback(x, 'sharedir'), VirtualKeyBoard, title = (_("Enter share directory:")), text = self.sharedirConfigEntry.value)
214 if self["config"].getCurrent() == self.optionsEntry:
215 self.session.openWithCallback(lambda x : self.VirtualKeyBoardCallback(x, 'options'), VirtualKeyBoard, title = (_("Enter options:")), text = self.optionsConfigEntry.value)
216 if self["config"].getCurrent() == self.usernameEntry:
217 self.session.openWithCallback(lambda x : self.VirtualKeyBoardCallback(x, 'username'), VirtualKeyBoard, title = (_("Enter username:")), text = self.usernameConfigEntry.value)
218 if self["config"].getCurrent() == self.passwordEntry:
219 self.session.openWithCallback(lambda x : self.VirtualKeyBoardCallback(x, 'password'), VirtualKeyBoard, title = (_("Enter password:")), text = self.passwordConfigEntry.value)
221 def VirtualKeyBoardCallback(self, callback = None, entry = None):
222 if callback is not None and len(callback) and entry is not None and len(entry):
223 if entry == 'sharename':
224 self.sharenameConfigEntry.setValue(callback)
225 self["config"].invalidate(self.sharenameConfigEntry)
226 if entry == 'sharedir':
227 self.sharedirConfigEntry.setValue(callback)
228 self["config"].invalidate(self.sharedirConfigEntry)
229 if entry == 'options':
230 self.optionsConfigEntry.setValue(callback)
231 self["config"].invalidate(self.optionsConfigEntry)
232 if entry == 'username':
233 self.usernameConfigEntry.setValue(callback)
234 self["config"].invalidate(self.usernameConfigEntry)
235 if entry == 'password':
236 self.passwordConfigEntry.setValue(callback)
237 self["config"].invalidate(self.passwordConfigEntry)
240 ConfigListScreen.keyLeft(self)
244 ConfigListScreen.keyRight(self)
247 def selectionChanged(self):
248 current = self["config"].getCurrent()
249 if current == self.activeEntry or current == self.ipEntry or current == self.mounttypeEntry or current == self.hdd_replacementEntry:
250 self["VKeyIcon"].hide()
251 self["VirtualKB"].setEnabled(False)
253 helpwindowpos = self["HelpWindow"].getPosition()
254 if current[1].help_window.instance is not None:
255 current[1].help_window.instance.move(ePoint(helpwindowpos[0],helpwindowpos[1]))
256 self["VKeyIcon"].show()
257 self["VirtualKB"].setEnabled(True)
260 current = self["config"].getCurrent()
261 if current == self.sharenameEntry or current == self.sharedirEntry or current == self.sharedirEntry or current == self.optionsEntry or current == self.usernameEntry or current == self.passwordEntry:
262 if current[1].help_window.instance is not None:
263 current[1].help_window.instance.hide()
264 sharename = self.sharenameConfigEntry.value
266 if self.mounts.has_key(sharename) is True:
267 self.session.openWithCallback(self.updateConfig, MessageBox, (_("A mount entry with this name already exists!\nUpdate existing entry and continue?\n") ) )
269 self.session.openWithCallback(self.applyConfig, MessageBox, (_("Are you sure you want to save this network mount?\n\n") ) )
271 def updateConfig(self, ret = False):
274 if self.sharedirConfigEntry.value.startswith("/"):
275 sharedir = self.sharedirConfigEntry.value[1:]
277 sharedir = self.sharedirConfigEntry.value
278 iAutoMount.setMountsAttribute(self.sharenameConfigEntry.value, "sharename", self.sharenameConfigEntry.value)
279 iAutoMount.setMountsAttribute(self.sharenameConfigEntry.value, "active", self.activeConfigEntry.value)
280 iAutoMount.setMountsAttribute(self.sharenameConfigEntry.value, "ip", self.ipConfigEntry.getText())
281 iAutoMount.setMountsAttribute(self.sharenameConfigEntry.value, "sharedir", sharedir)
282 iAutoMount.setMountsAttribute(self.sharenameConfigEntry.value, "mounttype", self.mounttypeConfigEntry.value)
283 iAutoMount.setMountsAttribute(self.sharenameConfigEntry.value, "options", self.optionsConfigEntry.value)
284 iAutoMount.setMountsAttribute(self.sharenameConfigEntry.value, "username", self.usernameConfigEntry.value)
285 iAutoMount.setMountsAttribute(self.sharenameConfigEntry.value, "password", self.passwordConfigEntry.value)
286 iAutoMount.setMountsAttribute(self.sharenameConfigEntry.value, "hdd_replacement", self.hdd_replacementConfigEntry.value)
288 self.updateConfigRef = None
289 self.updateConfigRef = self.session.openWithCallback(self.updateConfigfinishedCB, MessageBox, _("Please wait while updating your network mount..."), type = MessageBox.TYPE_INFO, enable_input = False)
290 iAutoMount.writeMountsConfig()
291 iAutoMount.getAutoMountPoints(self.updateConfigDataAvail)
295 def updateConfigDataAvail(self, data):
297 self.updateConfigRef.close(True)
299 def updateConfigfinishedCB(self,data):
301 self.session.openWithCallback(self.Updatefinished, MessageBox, _("Your network mount has been updated."), type = MessageBox.TYPE_INFO, timeout = 10)
303 def Updatefinished(self,data):
308 def applyConfig(self, ret = False):
310 data = { 'isMounted': False, 'active': False, 'ip': False, 'sharename': False, 'sharedir': False, \
311 'username': False, 'password': False, 'mounttype' : False, 'options' : False, 'hdd_replacement' : False }
312 data['active'] = self.activeConfigEntry.value
313 data['ip'] = self.ipConfigEntry.getText()
314 data['sharename'] = re_sub("\W", "", self.sharenameConfigEntry.value)
315 # "\W" matches everything that is "not numbers, letters, or underscores",where the alphabet defaults to ASCII.
316 if self.sharedirConfigEntry.value.startswith("/"):
317 data['sharedir'] = self.sharedirConfigEntry.value[1:]
319 data['sharedir'] = self.sharedirConfigEntry.value
320 data['options'] = self.optionsConfigEntry.value
321 data['mounttype'] = self.mounttypeConfigEntry.value
322 data['username'] = self.usernameConfigEntry.value
323 data['password'] = self.passwordConfigEntry.value
324 data['hdd_replacement'] = self.hdd_replacementConfigEntry.value
325 self.applyConfigRef = None
326 self.applyConfigRef = self.session.openWithCallback(self.applyConfigfinishedCB, MessageBox, _("Please wait for activation of your network mount..."), type = MessageBox.TYPE_INFO, enable_input = False)
327 iAutoMount.automounts[self.sharenameConfigEntry.value] = data
328 iAutoMount.writeMountsConfig()
329 iAutoMount.getAutoMountPoints(self.applyConfigDataAvail)
333 def applyConfigDataAvail(self, data):
335 self.applyConfigRef.close(True)
337 def applyConfigfinishedCB(self,data):
339 self.session.openWithCallback(self.applyfinished, MessageBox, _("Your network mount has been activated."), type = MessageBox.TYPE_INFO, timeout = 10)
341 def applyfinished(self,data):