1 # -*- coding: utf-8 -*-
2 # for localized messages
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.Button import Button
9 from Components.config import config, ConfigIP, NoSave, ConfigText, ConfigEnableDisable, ConfigPassword, ConfigSelection, getConfigListEntry, ConfigYesNo
10 from Components.ConfigList import ConfigListScreen
11 from Components.Label import Label
12 from Components.Pixmap import Pixmap
13 from Components.ActionMap import ActionMap, NumberActionMap
14 from enigma import ePoint
15 from AutoMount import iAutoMount, AutoMount
16 from re import sub as re_sub
18 class AutoMountEdit(Screen, ConfigListScreen):
20 <screen name="AutoMountEdit" position="90,110" size="560,400" title="MountEdit">
21 <widget name="config" position="10,10" size="540,200" zPosition="1" scrollbarMode="showOnDemand" />
22 <widget name="ButtonGreen" pixmap="skin_default/buttons/button_green.png" position="30,365" zPosition="10" size="15,16" transparent="1" alphatest="on" />
23 <widget name="introduction2" position="110,330" size="300,20" zPosition="10" font="Regular;21" halign="center" transparent="1" />
24 <widget name="ButtonRedtext" position="410,365" size="140,21" zPosition="10" font="Regular;21" transparent="1" />
25 <widget name="ButtonRed" pixmap="skin_default/buttons/button_red.png" position="390,365" zPosition="10" size="15,16" transparent="1" alphatest="on" />
26 <widget name="VKeyIcon" pixmap="skin_default/vkey_icon.png" position="40,345" zPosition="10" size="60,48" transparent="1" alphatest="on" />
27 <widget name="HelpWindow" pixmap="skin_default/vkey_icon.png" position="175,325" zPosition="1" size="1,1" transparent="1" alphatest="on" />
28 <ePixmap pixmap="skin_default/bottombar.png" position="10,310" size="540,120" zPosition="1" transparent="1" alphatest="on" />
31 def __init__(self, session, plugin_path, mountinfo = None ):
32 self.skin_path = plugin_path
33 self.session = session
34 Screen.__init__(self, self.session)
36 self.mountinfo = mountinfo
37 if self.mountinfo is None:
38 #Initialize blank mount enty
39 self.mountinfo = { 'isMounted': False, 'active': False, 'ip': False, 'sharename': False, 'sharedir': False, 'username': False, 'password': False, 'mounttype' : False, 'options' : False, 'hdd_replacement' : False }
41 self.applyConfigRef = None
42 self.updateConfigRef = None
43 self.mounts = iAutoMount.getMountsList()
46 self["actions"] = NumberActionMap(["SetupActions"],
54 self["VirtualKB"] = ActionMap(["ShortcutActions"],
56 "green": self.KeyGreen,
60 ConfigListScreen.__init__(self, self.list,session = self.session)
62 self.onLayoutFinish.append(self.layoutFinished)
64 self["ButtonGreen"] = Pixmap()
65 self["VKeyIcon"] = Pixmap()
66 self["HelpWindow"] = Pixmap()
67 self["introduction2"] = Label(_("Press OK to activate the settings."))
68 self["ButtonRed"] = Pixmap()
69 self["ButtonRedtext"] = Label(_("Close"))
72 def layoutFinished(self):
73 self.setTitle(_("Mounts editor"))
74 self["ButtonGreen"].hide()
75 self["VKeyIcon"].hide()
76 self["VirtualKB"].setEnabled(False)
77 self["HelpWindow"].hide()
79 # helper function to convert ips from a sring to a list of ints
80 def convertIP(self, ip):
90 def createConfig(self):
91 self.sharenameEntry = None
92 self.mounttypeEntry = None
93 self.activeEntry = None
95 self.sharedirEntry = None
96 self.optionsEntry = None
97 self.usernameEntry = None
98 self.passwordEntry = None
99 self.hdd_replacementEntry = None
101 self.sharetypelist = []
102 self.sharetypelist.append(("nfs", _("NFS share")))
103 self.sharetypelist.append(("cifs", _("CIFS share")))
105 if self.mountinfo.has_key('mounttype'):
106 mounttype = self.mountinfo['mounttype']
110 if self.mountinfo.has_key('active'):
111 active = self.mountinfo['active']
114 if active == 'False':
118 if self.mountinfo.has_key('ip'):
119 if self.mountinfo['ip'] is False:
120 ip = [192, 168, 0, 0]
122 ip = self.convertIP(self.mountinfo['ip'])
124 ip = [192, 168, 0, 0]
125 if self.mountinfo.has_key('sharename'):
126 sharename = self.mountinfo['sharename']
128 sharename = "Sharename"
129 if self.mountinfo.has_key('sharedir'):
130 sharedir = self.mountinfo['sharedir']
132 sharedir = "/export/hdd"
133 if self.mountinfo.has_key('options'):
134 options = self.mountinfo['options']
136 options = "rw,nolock"
137 if self.mountinfo.has_key('username'):
138 username = self.mountinfo['username']
141 if self.mountinfo.has_key('password'):
142 password = self.mountinfo['password']
145 if self.mountinfo.has_key('hdd_replacement'):
146 hdd_replacement = self.mountinfo['hdd_replacement']
147 if hdd_replacement == 'True':
148 hdd_replacement = True
149 if hdd_replacement == 'False':
150 hdd_replacement = False
152 hdd_replacement = False
153 if sharename is False:
154 sharename = "Sharename"
155 if sharedir is False:
156 sharedir = "/export/hdd"
158 if mounttype == "nfs":
159 options = "rw,nolock"
162 if username is False:
164 if password is False:
166 if mounttype is False:
169 self.activeConfigEntry = NoSave(ConfigEnableDisable(default = active))
170 self.ipConfigEntry = NoSave(ConfigIP(default = ip))
171 self.sharenameConfigEntry = NoSave(ConfigText(default = sharename, visible_width = 50, fixed_size = False))
172 self.sharedirConfigEntry = NoSave(ConfigText(default = sharedir, visible_width = 50, fixed_size = False))
173 self.optionsConfigEntry = NoSave(ConfigText(default = options, visible_width = 50, fixed_size = False))
174 self.usernameConfigEntry = NoSave(ConfigText(default = username, visible_width = 50, fixed_size = False))
175 self.passwordConfigEntry = NoSave(ConfigPassword(default = password, visible_width = 50, fixed_size = False))
176 self.mounttypeConfigEntry = NoSave(ConfigSelection(self.sharetypelist, default = mounttype ))
177 self.hdd_replacementConfigEntry = NoSave(ConfigYesNo(default = hdd_replacement))
179 def createSetup(self):
181 self.activeEntry = getConfigListEntry(_("Active"), self.activeConfigEntry)
182 self.list.append(self.activeEntry)
183 self.sharenameEntry = getConfigListEntry(_("Local share name"), self.sharenameConfigEntry)
184 self.list.append(self.sharenameEntry)
185 self.mounttypeEntry = getConfigListEntry(_("Mount type"), self.mounttypeConfigEntry)
186 self.list.append(self.mounttypeEntry)
187 self.ipEntry = getConfigListEntry(_("Server IP"), self.ipConfigEntry)
188 self.list.append(self.ipEntry)
189 self.sharedirEntry = getConfigListEntry(_("Server share"), self.sharedirConfigEntry)
190 self.list.append(self.sharedirEntry)
191 self.hdd_replacementEntry = getConfigListEntry(_("use as HDD replacement"), self.hdd_replacementConfigEntry)
192 self.list.append(self.hdd_replacementEntry)
193 if self.mounttypeConfigEntry.value == "cifs":
194 self.optionsConfigEntry = NoSave(ConfigText(default = "rw", visible_width = 50, fixed_size = False))
196 self.optionsConfigEntry = NoSave(ConfigText(default = "rw,nolock", visible_width = 50, fixed_size = False))
197 self.optionsEntry = getConfigListEntry(_("Mount options"), self.optionsConfigEntry)
198 self.list.append(self.optionsEntry)
199 if self.mounttypeConfigEntry.value == "cifs":
200 self.usernameEntry = getConfigListEntry(_("Username"), self.usernameConfigEntry)
201 self.list.append(self.usernameEntry)
202 self.passwordEntry = getConfigListEntry(_("Password"), self.passwordConfigEntry)
203 self.list.append(self.passwordEntry)
205 self["config"].list = self.list
206 self["config"].l.setList(self.list)
207 self["config"].onSelectionChanged.append(self.selectionChanged)
210 if self["config"].getCurrent() == self.mounttypeEntry:
214 print "Green Pressed"
215 if self["config"].getCurrent() == self.sharenameEntry:
216 self.session.openWithCallback(lambda x : self.VirtualKeyBoardCallback(x, 'sharename'), VirtualKeyBoard, title = (_("Enter share name:")), text = self.sharenameConfigEntry.value)
217 if self["config"].getCurrent() == self.sharedirEntry:
218 self.session.openWithCallback(lambda x : self.VirtualKeyBoardCallback(x, 'sharedir'), VirtualKeyBoard, title = (_("Enter share directory:")), text = self.sharedirConfigEntry.value)
219 if self["config"].getCurrent() == self.optionsEntry:
220 self.session.openWithCallback(lambda x : self.VirtualKeyBoardCallback(x, 'options'), VirtualKeyBoard, title = (_("Enter options:")), text = self.optionsConfigEntry.value)
221 if self["config"].getCurrent() == self.usernameEntry:
222 self.session.openWithCallback(lambda x : self.VirtualKeyBoardCallback(x, 'username'), VirtualKeyBoard, title = (_("Enter username:")), text = self.usernameConfigEntry.value)
223 if self["config"].getCurrent() == self.passwordEntry:
224 self.session.openWithCallback(lambda x : self.VirtualKeyBoardCallback(x, 'password'), VirtualKeyBoard, title = (_("Enter password:")), text = self.passwordConfigEntry.value)
226 def VirtualKeyBoardCallback(self, callback = None, entry = None):
227 if callback is not None and len(callback) and entry is not None and len(entry):
228 if entry == 'sharename':
229 self.sharenameConfigEntry = NoSave(ConfigText(default = callback, visible_width = 50, fixed_size = False))
231 if entry == 'sharedir':
232 self.sharedirConfigEntry = NoSave(ConfigText(default = callback, visible_width = 50, fixed_size = False))
234 if entry == 'options':
235 self.optionsConfigEntry = NoSave(ConfigText(default = callback, visible_width = 50, fixed_size = False))
237 if entry == 'username':
238 self.usernameConfigEntry = NoSave(ConfigText(default = callback, visible_width = 50, fixed_size = False))
240 if entry == 'password':
241 self.passwordConfigEntry = NoSave(ConfigPassword(default = callback, visible_width = 50, fixed_size = False))
245 ConfigListScreen.keyLeft(self)
249 ConfigListScreen.keyRight(self)
252 def selectionChanged(self):
253 current = self["config"].getCurrent()
254 if current == self.activeEntry or current == self.ipEntry or current == self.mounttypeEntry or current == self.hdd_replacementEntry:
255 self["ButtonGreen"].hide()
256 self["VKeyIcon"].hide()
257 self["VirtualKB"].setEnabled(False)
259 helpwindowpos = self["HelpWindow"].getPosition()
260 if current[1].help_window.instance is not None:
261 current[1].help_window.instance.move(ePoint(helpwindowpos[0],helpwindowpos[1]))
262 self["ButtonGreen"].show()
263 self["VKeyIcon"].show()
264 self["VirtualKB"].setEnabled(True)
267 current = self["config"].getCurrent()
268 if current == self.sharenameEntry or current == self.sharedirEntry or current == self.sharedirEntry or current == self.optionsEntry or current == self.usernameEntry or current == self.passwordEntry:
269 if current[1].help_window.instance is not None:
270 current[1].help_window.instance.hide()
271 sharename = self.sharenameConfigEntry.value
273 if self.mounts.has_key(sharename) is True:
274 self.session.openWithCallback(self.updateConfig, MessageBox, (_("A mount entry with this name already exists!\nUpdate existing entry and continue?\n") ) )
276 self.session.openWithCallback(self.applyConfig, MessageBox, (_("Are you sure you want to save this network mount?\n\n") ) )
278 def updateConfig(self, ret = False):
280 iAutoMount.setMountsAttribute(self.sharenameConfigEntry.value, "sharename", self.sharenameConfigEntry.value)
281 iAutoMount.setMountsAttribute(self.sharenameConfigEntry.value, "active", self.activeConfigEntry.value)
282 iAutoMount.setMountsAttribute(self.sharenameConfigEntry.value, "ip", self.ipConfigEntry.getText())
283 iAutoMount.setMountsAttribute(self.sharenameConfigEntry.value, "sharedir", self.sharedirConfigEntry.value)
284 iAutoMount.setMountsAttribute(self.sharenameConfigEntry.value, "mounttype", self.mounttypeConfigEntry.value)
285 iAutoMount.setMountsAttribute(self.sharenameConfigEntry.value, "options", self.optionsConfigEntry.value)
286 iAutoMount.setMountsAttribute(self.sharenameConfigEntry.value, "username", self.usernameConfigEntry.value)
287 iAutoMount.setMountsAttribute(self.sharenameConfigEntry.value, "password", self.passwordConfigEntry.value)
288 iAutoMount.setMountsAttribute(self.sharenameConfigEntry.value, "hdd_replacement", self.hdd_replacementConfigEntry.value)
290 self.updateConfigRef = None
291 self.updateConfigRef = self.session.openWithCallback(self.updateConfigfinishedCB, MessageBox, _("Please wait while updating your network mount..."), type = MessageBox.TYPE_INFO, enable_input = False)
292 iAutoMount.writeMountsConfig()
293 iAutoMount.getAutoMountPoints(self.updateConfigDataAvail)
297 def updateConfigDataAvail(self, data):
299 self.updateConfigRef.close(True)
301 def updateConfigfinishedCB(self,data):
303 self.session.openWithCallback(self.Updatefinished, MessageBox, _("Your network mount has been updated."), type = MessageBox.TYPE_INFO, timeout = 10)
305 def Updatefinished(self,data):
310 def applyConfig(self, ret = False):
312 data = { 'isMounted': False, 'active': False, 'ip': False, 'sharename': False, 'sharedir': False, \
313 'username': False, 'password': False, 'mounttype' : False, 'options' : False, 'hdd_replacement' : False }
314 data['active'] = self.activeConfigEntry.value
315 data['ip'] = self.ipConfigEntry.getText()
316 data['sharename'] = re_sub("\W", "", self.sharenameConfigEntry.value)
317 # "\W" matches everything that is "not numbers, letters, or underscores",where the alphabet defaults to ASCII.
318 data['sharedir'] = self.sharedirConfigEntry.value
319 data['options'] = self.optionsConfigEntry.value
320 data['mounttype'] = self.mounttypeConfigEntry.value
321 data['username'] = self.usernameConfigEntry.value
322 data['password'] = self.passwordConfigEntry.value
323 data['hdd_replacement'] = self.hdd_replacementConfigEntry.value
324 self.applyConfigRef = None
325 self.applyConfigRef = self.session.openWithCallback(self.applyConfigfinishedCB, MessageBox, _("Please wait for activation of your network mount..."), type = MessageBox.TYPE_INFO, enable_input = False)
326 iAutoMount.automounts[self.sharenameConfigEntry.value] = data
327 iAutoMount.writeMountsConfig()
328 iAutoMount.getAutoMountPoints(self.applyConfigDataAvail)
332 def applyConfigDataAvail(self, data):
334 self.applyConfigRef.close(True)
336 def applyConfigfinishedCB(self,data):
338 self.session.openWithCallback(self.applyfinished, MessageBox, _("Your network mount has been activated."), type = MessageBox.TYPE_INFO, timeout = 10)
340 def applyfinished(self,data):