class GrowleeConfiguration(Screen, ConfigListScreen): skin = """ <screen name="GrowleeConfiguration" position="center,center" size="560,400" title="Growlee Setup" > <ePixmap position="0,0" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" /> <ePixmap position="140,0" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" /> <ePixmap position="280,0" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" /> <ePixmap position="420,0" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" /> <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget name="config" position="5,45" size="550,350" scrollbarMode="showOnDemand" /> </screen>""" def __init__(self, session): Screen.__init__(self, session) # Buttons self["key_red"] = StaticText(_("Cancel")) self["key_green"] = StaticText(_("OK")) self["key_yellow"] = StaticText(_("New")) self["key_blue"] = StaticText(_("Delete")) # Summary self.setup_title = "Growlee Configuration" self.onChangedEntry = [] # Define Actions self["setupActions"] = ActionMap( ["SetupActions", "ColorActions"], {"blue": self.delete, "yellow": self.new, "cancel": self.keyCancel, "save": self.keySave}, ) self.hostElement = NoSave(ConfigSelection(choices=[(x, x.name.value) for x in config.plugins.growlee.hosts])) self.hostElement.addNotifier(self.setupList, initial_call=False) ConfigListScreen.__init__(self, [], session=session, on_change=self.changed) self.cur = self.hostElement.value # Trigger change self.setupList() self.changed() def delete(self): from Screens.MessageBox import MessageBox self.session.openWithCallback( self.deleteConfirm, MessageBox, _("Really delete this entry?\nIt cannot be recovered!") ) def deleteConfirm(self, result): if result and config.plugins.growlee.hostcount.value > 0: config.plugins.growlee.hostcount.value -= 1 config.plugins.growlee.hosts.remove(self.cur) self.hostElement.setChoices([(x, x.name.value) for x in config.plugins.growlee.hosts]) self.cur = self.hostElement.value def new(self): self.cur = addHost(_("New connection")) config.plugins.growlee.hostcount.value += 1 self.hostElement.setChoices([(x, x.name.value) for x in config.plugins.growlee.hosts]) self.hostElement.setValue(self.cur) def changed(self): for x in self.onChangedEntry: x() def setupList(self, *args): last = self.cur if self.setupList in last.protocol.notifiers: last.protocol.removeNotifier(self.setupList) cur = self.hostElement.value self.cur = cur cur.protocol.addNotifier(self.setupList, initial_call=False) l = [ getConfigListEntry(_("Host"), self.hostElement), getConfigListEntry(_("Name"), cur.name), getConfigListEntry(_("Type"), cur.protocol), getConfigListEntry(_("Minimum Priority"), cur.level), getConfigListEntry(_("Send Notifications?"), cur.enable_outgoing), ] proto = cur.protocol.value if proto == "prowl": l.append(getConfigListEntry(_("API Key"), cur.password)) else: if proto != "gntp": l.append(getConfigListEntry(_("Receive Notifications?"), cur.enable_incoming)) l.append(getConfigListEntry(_("Address"), cur.address)) if proto == "growl" or proto == "gntp": l.append(getConfigListEntry(_("Password"), cur.password)) self["config"].list = l def getCurrentEntry(self): cur = self["config"].getCurrent() return cur and cur[0] def getCurrentValue(self): cur = self["config"].getCurrent() return cur and str(cur[1].getText()) def createSummary(self): return SetupSummary def keySave(self): config.plugins.growlee.save() if self["config"].isChanged(): def doConnect(*args, **kwargs): growleeConnection.listen() d = growleeConnection.stop() if d is not None: d.addCallback(doConnect).addErrback(emergencyDisable) else: maybeConnect() self.saveAll() self.close() def close(self): if self.setupList in self.cur.protocol.notifiers: self.cur.protocol.removeNotifier(self.setupList) Screen.close(self)
class setupNfs(Screen, ConfigListScreen): skin = """ <screen name="setupNfs" position="center,center" size="560,350" title="setup NFS-Server"> <widget name="config" position="10,10" size="540,30" scrollbarMode="showOnDemand" /> <widget source="exportlist" render="Listbox" position="10,50" size="540,100" scrollbarMode="showOnDemand"> <convert type="TemplatedMultiContent"> {"template": [ MultiContentEntryText(pos = (0, 13), size = (200, 25), font=0, flags = RT_HALIGN_LEFT, text = 0), # index 0 is the exportdir MultiContentEntryText(pos = (210, 3), size = (330, 18), font=1, flags = RT_HALIGN_LEFT, text = 1), # index 1 is the client MultiContentEntryText(pos = (210, 28), size = (330, 18), font=1, flags = RT_HALIGN_LEFT, text = 2), # index 2 is the options ], "fonts": [gFont("Regular", 20),gFont("Regular", 14)], "itemHeight": 50 } </convert> </widget> <widget name="nfsdLabel" position="20,170" size="520,30" font="Regular;21"/> <widget name="portmapLabel" position="20,200" size="520,30" font="Regular;21"/> <widget name="ButtonGreentext" position="50,270" size="460,21" halign="left" zPosition="10" font="Regular;20" transparent="1" /> <widget name="ButtonGreen" pixmap="skin_default/buttons/button_green.png" position="30,273" zPosition="10" size="15,16" transparent="1" alphatest="on" /> <widget name="ButtonRedtext" position="50,300" size="145,21" halign="left" zPosition="10" font="Regular;20" transparent="1" /> <widget name="ButtonRed" pixmap="skin_default/buttons/button_red.png" position="30,303" zPosition="10" size="15,16" transparent="1" alphatest="on" /> <widget name="ButtonYellowtext" position="220,300" size="145,21" halign="left" zPosition="10" font="Regular;20" transparent="1" /> <widget name="ButtonYellow" pixmap="skin_default/buttons/button_yellow.png" position="200,303" zPosition="10" size="15,16" transparent="1" alphatest="on" /> <widget name="ButtonBluetext" position="390,300" size="145,21" halign="left" zPosition="10" font="Regular;20" transparent="1" /> <widget name="ButtonBlue" pixmap="skin_default/buttons/button_blue.png" position="370,303" zPosition="10" size="15,16" transparent="1" alphatest="on" /> <ePixmap pixmap="skin_default/bottombar.png" position="10,250" size="540,120" zPosition="1" transparent="1" alphatest="on" /> </screen>""" def __init__(self, session, iface, plugin_path): self.skin = setupNfs.skin self.session = session Screen.__init__(self, session) self.container = eConsoleAppContainer() self.container.appClosed.append(self.runFinished) self.container.dataAvail.append(self.dataAvail) if isRunning('portmap') and isRunning('nfsd'): isEnabled = True else: isEnabled = False self.activeConfigEntry = NoSave(ConfigEnableDisable(default=isEnabled)) self["nfsdLabel"] = Label() self["portmapLabel"] = Label() self["ButtonGreen"] = Pixmap() self["ButtonGreentext"] = Button( _("save and start/restart NFS-Server")) self["ButtonRed"] = Pixmap() self["ButtonRedtext"] = Label(_("Close")) self["ButtonYellow"] = Pixmap() self["ButtonYellowtext"] = Label(_("New Entry")) self["ButtonBlue"] = Pixmap() self["ButtonBluetext"] = Label(_("Remove Entry")) self.startingUp = False self.goingDown = False self.cmdlist = [] self.run = 0 self.exportlist = [] data = self.readExports() if data is not None: for line in data: exportDir = line[0] client = line[1] options = line[2] options = options.replace('(', '') options = options.replace(')', '') self.exportlist.append((exportDir, client, options)) else: self.exportlist.append( ('/media/hdd', '*', 'rw,no_root_squash,sync')) self["exportlist"] = List(self.exportlist) self.hideList = self["exportlist"].list self.createSetup() ConfigListScreen.__init__(self, self.list, session=session) self.activeConfigEntry.addNotifier(self.toggleServer) self["actions"] = ActionMap( ["OkCancelActions", "ColorActions"], { "cancel": self.cancel, "ok": self.editExportEntry, "green": self.green, "red": self.cancel, "yellow": self.newExportEntry, "blue": self.deleteExportEntry }, -2) def readExports(self): try: exportfile = open('/etc/exports', 'r') lines = [] for line in exportfile: if line[0] != '#' and line != '\n': tmp = [] line = line.replace('\t', ' ') val = line.strip().split(' ') exportdir = val[0].strip() tmp.append(exportdir) line = line[len(exportdir):].strip() val = line.strip().split('(') client = val[0].strip() tmp.append(client) options = line[len(client):].strip() tmp.append(options) lines.append(tmp) return lines except IOError: pass return None def writeExports(self, data): exportfile = open('/etc/exports', 'w') for line in data: exportfile.write(line[0] + ' ' + line[1] + '(' + line[2] + ')' + '\n') exportfile.close() def createSetup(self): self.list = [] self.list.append( getConfigListEntry(_("Enable/Disable NFS-Server"), self.activeConfigEntry)) if self.activeConfigEntry.value: self.exportlistShow() self["nfsdLabel"].show() self["portmapLabel"].show() self["ButtonGreentext"].show() self["ButtonGreen"].show() self["ButtonYellow"].show() self["ButtonYellowtext"].show() self["ButtonBlue"].show() self["ButtonBluetext"].show() if self.goingDown or self.startingUp: if self.goingDown: self["nfsdLabel"].setText(_("Status nfsd: going down...")) self["portmapLabel"].setText( _("Status portmap: going down...")) if self.startingUp: self["nfsdLabel"].setText(_("Status nfsd: starting up...")) self["portmapLabel"].setText( _("Status portmap: starting up...")) else: self.nfsdLabelSet() self.portmapLabelSet() else: self.exportlistHide() self["nfsdLabel"].hide() self["portmapLabel"].hide() self["ButtonGreentext"].hide() self["ButtonGreen"].hide() self["ButtonYellow"].hide() self["ButtonYellowtext"].hide() self["ButtonBlue"].hide() self["ButtonBluetext"].hide() def toggleServer(self, configElement): self.createSetup() self["config"].l.setList(self.list) if not configElement.value: if not self.goingDown or not self.startingUp: if isRunning('portmap') and isRunning('nfsd'): self.nfsServerDown() def exportlistShow(self): self.exportlist = [] for line in self.hideList: self.exportlist.append((line[0], line[1], line[2])) self["exportlist"].setList(self.exportlist) def exportlistHide(self): if len(self["exportlist"].list) == 0: return self.hideList = self["exportlist"].list self.exportlist = [] self["exportlist"].setList(self.exportlist) def cancel(self): if self.run == len(self.cmdlist): self.close() self.container.appClosed.remove(self.runFinished) def editExportEntry(self): if self.activeConfigEntry.value: sel = self["exportlist"].getCurrent() if sel: self.tmpList = self["exportlist"].list self.session.openWithCallback(self.editExportEntryClosed, editExportEntry, sel[0], sel[1], sel[2]) def editExportEntryClosed(self, data): if data: self.tmpList[self["exportlist"].getIndex()] = data self.exportlist = [] for line in self.tmpList: self.exportlist.append((line[0], line[1], line[2])) self["exportlist"].setList(self.exportlist) def newExportEntry(self): if self.activeConfigEntry.value: self.tmpList = self["exportlist"].list self.session.openWithCallback(self.newExportEntryClosed, editExportEntry, '/media/hdd', '*', 'rw,no_root_squash,sync') def newExportEntryClosed(self, data): if data: self.tmpList.append(data) self.exportlist = [] for line in self.tmpList: self.exportlist.append((line[0], line[1], line[2])) self["exportlist"].setList(self.exportlist) def deleteExportEntry(self): if self.activeConfigEntry.value: if len(self["exportlist"].list) < 2: return self.tmpList = self["exportlist"].list mbox = self.session.openWithCallback( self.deleteExportEntryClosed, MessageBox, _("Really delete this entry?"), MessageBox.TYPE_YESNO) mbox.setTitle(_("delete entry")) def deleteExportEntryClosed(self, answer): if answer is True: itemIndex = self["exportlist"].getIndex() self.exportlist = [] for cnt, line in enumerate(self.tmpList): if cnt != itemIndex: self.exportlist.append((line[0], line[1], line[2])) self["exportlist"].setList(self.exportlist) def green(self): if self.activeConfigEntry.value: self.nfsServerDown() self.writeExports(self["exportlist"].list) self.nfsServerUp() def nfsdLabelSet(self): if isRunning('nfsd'): self["nfsdLabel"].setText(_("Status nfsd: started")) else: self["nfsdLabel"].setText(_("Status nfsd: stopped")) def portmapLabelSet(self): if isRunning('portmap'): self["portmapLabel"].setText(_("Status portmap: started")) else: self["portmapLabel"].setText(_("Status portmap: stopped")) def dataAvail(self, str): print str, def runFinished(self, retval): self.run += 1 if self.run != len(self.cmdlist): self.container.execute(self.cmdlist[self.run]) else: self.run = 0 self.cmdlist = [] self.startingUp = False self.goingDown = False self.nfsdLabelSet() self.portmapLabelSet() def nfsServerUp(self): self["nfsdLabel"].setText(_("Status nfsd: starting up...")) self["portmapLabel"].setText(_("Status portmap: starting up...")) self.cmdlist.append( "update-rc.d -s portmap start 43 S . start 32 0 6 . stop 81 1 .") self.cmdlist.append("/etc/init.d/portmap start") self.cmdlist.append("update-rc.d -s nfsserver defaults") self.startingUp = True self.container.execute(self.cmdlist[self.run]) def nfsServerDown(self): self["nfsdLabel"].setText(_("Status nfsd: going down...")) self["portmapLabel"].setText(_("Status portmap: going down...")) self.cmdlist.append("/etc/init.d/portmap stop") self.cmdlist.append("/etc/init.d/nfsserver stop") self.cmdlist.append("update-rc.d -f portmap remove") self.cmdlist.append("update-rc.d -f nfsserver remove") self.cmdlist.append("killall portmap mountd") self.goingDown = True self.container.execute(self.cmdlist[self.run])
class editExportEntry(Screen, ConfigListScreen): skin = """ <screen name="editExportEntry" position="center,center" size="560,350" title="edit Export Entry"> <widget name="config" position="10,10" size="540,150" scrollbarMode="showOnDemand" /> <widget name="ButtonGreentext" position="50,270" size="460,21" halign="left" zPosition="10" font="Regular;21" transparent="1" /> <widget name="ButtonGreen" pixmap="skin_default/buttons/button_green.png" position="30,273" zPosition="10" size="15,16" transparent="1" alphatest="on" /> <widget name="ButtonRedtext" position="50,300" size="460,21" halign="left" zPosition="10" font="Regular;21" transparent="1" /> <widget name="ButtonRed" pixmap="skin_default/buttons/button_red.png" position="30,303" zPosition="10" size="15,16" transparent="1" alphatest="on" /> <ePixmap pixmap="skin_default/bottombar.png" position="10,250" size="540,120" zPosition="1" transparent="1" alphatest="on" /> </screen>""" def __init__(self, session, exportDir, client, options): self.skin = editExportEntry.skin self.session = session Screen.__init__(self, session) nfsoptions = [\ "ro,sync", "rw,sync", "ro,async", "rw,async", "ro,no_root_squash", "rw,no_root_squash", "ro,no_subtree_check", "rw,no_subtree_check", "ro,insecure", "rw,insecure", "ro,insecure,no_subtree_check", "rw,insecure,no_subtree_check", "ro,sync,no_subtree_check", "rw,sync,no_subtree_check", "ro,async,no_subtree_check", "rw,async,no_subtree_check", "ro,no_root_squash,no_subtree_check", "rw,no_root_squash,no_subtree_check", "ro,no_root_squash,sync", "rw,no_root_squash,sync", "ro,no_root_squash,sync,no_subtree_check", "rw,no_root_squash,sync,no_subtree_check", "ro,no_root_squash,async", "rw,no_root_squash,async", "ro,no_root_squash,async,no_subtree_check", "rw,no_root_squash,async,no_subtree_check"] optionsEntrys = {} for x in nfsoptions: optionsEntrys[x] = x clientIP = [192, 168, 0, 0] self.netmask = '' tmp = client.split('/') if len(tmp) > 1: client = tmp[0] self.netmask = tmp[1] if client == '*': everyIP = True else: everyIP = False theIP = client.split('.') clientIP = [] for x in theIP: clientIP.append(int(x)) self.exportDirConfigEntry = NoSave(ConfigDirectory(exportDir)) self.everyIPConfigEntry = NoSave(ConfigEnableDisable(default=everyIP)) self.clientConfigEntry = NoSave(ConfigIP(clientIP)) self.optionsConfigEntry = NoSave( ConfigSelection(optionsEntrys, options)) ConfigListScreen.__init__(self, []) self.createSetup() self.everyIPConfigEntry.addNotifier(self.toggleEveryIP) self["actions"] = ActionMap( ["OkCancelActions", "ColorActions"], { "cancel": self.cancel, "red": self.cancel, "green": self.green, "ok": self.ok }, -2) self["ButtonGreen"] = Pixmap() self["ButtonGreentext"] = Label(_("Save and Close")) self["ButtonRed"] = Pixmap() self["ButtonRedtext"] = Label(_("Close")) def createSetup(self): self.list = [] self.list.append( getConfigListEntry(_("export directory"), self.exportDirConfigEntry)) self.list.append( getConfigListEntry(_("every ip"), self.everyIPConfigEntry)) if not self.everyIPConfigEntry.value: self.list.append( getConfigListEntry(_("client ip"), self.clientConfigEntry)) self.list.append( getConfigListEntry(_("options"), self.optionsConfigEntry)) self["config"].setList(self.list) def toggleEveryIP(self, configElement): self.createSetup() def cancel(self): self.close(False) def ok(self): if self["config"].getCurrent()[1] == self.exportDirConfigEntry: self.session.openWithCallback( self.dirSelectDlgClosed, dirSelectDlg, self.exportDirConfigEntry.value + '/') def dirSelectDlgClosed(self, path): if path != False: if path.endswith('/'): path = path[:-1] self.exportDirConfigEntry.setValue(path) def green(self): data = [] data.append(self.exportDirConfigEntry.value) if self.everyIPConfigEntry.value: ipdata = '*' else: ipdata = "%d.%d.%d.%d" % tuple(self.clientConfigEntry.value) if len(self.netmask) > 0: ipdata = ipdata + "/" + self.netmask data.append(ipdata) data.append(self.optionsConfigEntry.value) self.close(data)
class AutoTimerFilterEditor(Screen, ConfigListScreen): """Edit AutoTimer Filter""" skin = """<screen name="AutoTimerFilterEditor" title="Edit AutoTimer Filters" position="center,center" size="565,280"> <ePixmap position="0,0" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" /> <ePixmap position="140,0" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" /> <ePixmap position="280,0" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" /> <ePixmap position="420,0" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" /> <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget name="config" position="5,45" size="555,225" scrollbarMode="showOnDemand" /> </screen>""" def __init__(self, session, filterset, excludes, includes): Screen.__init__(self, session) # Summary self.setup_title = _("AutoTimer Filters") self.onChangedEntry = [] self.typeSelection = NoSave(ConfigSelection(choices = [ ("title", _("in Title")), ("short", _("in Shortdescription")), ("desc", _("in Description")), ("day", _("on Weekday"))] )) self.typeSelection.addNotifier(self.refresh, initial_call = False) self.enabled = NoSave(ConfigYesNo(default = filterset)) self.enabled.addNotifier(self.refresh, initial_call = False) self.excludes = excludes self.includes = includes self.oldexcludes = excludes self.oldincludes = includes self.idx = 0 self.reloadList() ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed) # Initialize Buttons self["key_red"] = StaticText(_("Cancel")) self["key_green"] = StaticText(_("Save")) self["key_yellow"] = StaticText(_("Delete")) self["key_blue"] = StaticText(_("New")) # Define Actions self["actions"] = ActionMap(["SetupActions", "ColorActions"], { "cancel": self.cancel, "save": self.save, "yellow": self.remove, "blue": self.new } ) # Trigger change self.changed() self.onLayoutFinish.append(self.setCustomTitle) def setCustomTitle(self): self.setTitle(_("Edit AutoTimer filters")) def changed(self): for x in self.onChangedEntry: try: x() except Exception: pass def getCurrentEntry(self): return self["config"].getCurrent()[0] def getCurrentValue(self): return str(self["config"].getCurrent()[1].getText()) def createSummary(self): return SetupSummary def saveCurrent(self): del self.excludes[self.idx][:] del self.includes[self.idx][:] # Warning, accessing a ConfigListEntry directly might be considered evil! idx = -1 for item in self["config"].getList()[:]: idx += 1 # Skip empty entries (and those which are no filters) if item[1].value == "" or idx < 2: continue elif idx < self.lenExcludes: self.excludes[self.idx].append(item[1].value.encode("UTF-8")) else: self.includes[self.idx].append(item[1].value.encode("UTF-8")) def refresh(self, *args, **kwargs): self.saveCurrent() self.reloadList() self["config"].setList(self.list) def reloadList(self): self.list = [getConfigListEntry(_("Enable Filtering"), self.enabled)] if self.enabled.value: self.list.append(getConfigListEntry(_("Filter"), self.typeSelection)) self.excludes = self.oldexcludes self.includes = self.oldincludes else: self.excludes = ([], [], [], []) self.includes = ([], [], [], []) if self.typeSelection.value == "day": self.idx = 3 # Weekdays are presented as ConfigSelection self.list.extend([ getConfigListEntry(_("Exclude"), NoSave(ConfigSelection(choices = weekdays, default = x))) for x in self.excludes[3] ]) self.lenExcludes = len(self.list) self.list.extend([ getConfigListEntry(_("Include"), NoSave(ConfigSelection(choices = weekdays, default = x))) for x in self.includes[3] ]) return elif self.typeSelection.value == "title": self.idx = 0 elif self.typeSelection.value == "short": self.idx = 1 else: # self.typeSelection.value == "desc": self.idx = 2 self.list.extend([ getConfigListEntry(_("Exclude"), NoSave(ConfigText(default = x, fixed_size = False))) for x in self.excludes[self.idx] ]) self.lenExcludes = len(self.list) self.list.extend([ getConfigListEntry(_("Include"), NoSave(ConfigText(default = x, fixed_size = False))) for x in self.includes[self.idx] ]) def remove(self): idx = self["config"].getCurrentIndex() if idx and idx > 1: if idx < self.lenExcludes: self.lenExcludes -= 1 list = self["config"].getList() list.remove(self["config"].getCurrent()) self["config"].setList(list) def new(self): self.session.openWithCallback( self.typeSelected, ChoiceBox, _("Select type of Filter"), [ (_("Exclude"), 0), (_("Include"), 1), ] ) def typeSelected(self, ret): if ret is not None: list = self["config"].getList() if ret[1] == 0: pos = self.lenExcludes self.lenExcludes += 1 text = ret[0] else: pos = len(self.list) text = ret[0] if self.typeSelection.value == "day": entry = getConfigListEntry(text, NoSave(ConfigSelection(choices = weekdays))) else: entry = getConfigListEntry(text, NoSave(ConfigText(fixed_size = False))) list.insert(pos, entry) self["config"].setList(list) def cancel(self): if self["config"].isChanged(): self.session.openWithCallback( self.cancelConfirm, MessageBox, _("Really close without saving settings?") ) else: self.close(None) def cancelConfirm(self, ret): if ret: self.close(None) def save(self): self.refresh() self.close(( self.enabled.value, self.excludes, self.includes ))
class setupSamba(Screen, ConfigListScreen): skin = """ <screen name="setupSamba" position="center,center" size="560,350" title="setup Samba-Server"> <widget name="config" position="10,10" size="540,150" scrollbarMode="showOnDemand" /> <widget name="smbdLabel" position="20,160" size="520,30" font="Regular;21"/> <widget name="nmbdLabel" position="20,190" size="520,30" font="Regular;21"/> <widget name="ButtonGreentext" position="50,270" size="460,21" halign="left" zPosition="10" font="Regular;21" transparent="1" /> <widget name="ButtonGreen" pixmap="buttons/button_green.png" position="30,273" zPosition="10" size="15,16" transparent="1" alphatest="on" /> <widget name="ButtonRedtext" position="50,300" size="460,21" halign="left" zPosition="10" font="Regular;21" transparent="1" /> <widget name="ButtonRed" pixmap="buttons/button_red.png" position="30,303" zPosition="10" size="15,16" transparent="1" alphatest="on" /> <ePixmap pixmap="bottombar.png" position="10,250" size="540,120" zPosition="1" transparent="1" alphatest="on" /> </screen>""" def __init__(self, session, iface, plugin_path): self.skin = setupSamba.skin self.session = session Screen.__init__(self, session) self.container = eConsoleAppContainer() self.container.appClosed.append(self.runFinished) self.container.dataAvail.append(self.dataAvail) if isRunning('smbd') and isRunning('nmbd'): isEnabled = True else: isEnabled = False confError = False tmp = getAttribute('/etc/samba/smb.conf', 'global', 'server string') if tmp != None: serverString = tmp else: serverString = 'READERROR server string' confError = True tmp = getAttribute('/etc/samba/smb.conf', 'global', 'netbios name') if tmp != None: netbiosName = tmp else: netbiosName = 'READERROR netbios name' confError = True tmp = getAttribute('/etc/samba/smb.conf', 'global', 'workgroup') if tmp != None: workgroup = tmp else: workgroup = 'READERROR workgroup' confError = True self.activeConfigEntry = NoSave(ConfigEnableDisable(default=isEnabled)) self.serverStringConfigEntry = NoSave( ConfigText(default=serverString, visible_width=50, fixed_size=False)) self.netbiosNameConfigEntry = NoSave( ConfigText(default=netbiosName, visible_width=50, fixed_size=False)) self.workgroupConfigEntry = NoSave( ConfigText(default=workgroup, visible_width=50, fixed_size=False)) self["smbdLabel"] = Label() self["nmbdLabel"] = Label() self["ButtonGreen"] = Pixmap() self["ButtonGreentext"] = Button( _("save and start/restart Samba-Server")) self["ButtonRed"] = Pixmap() self["ButtonRedtext"] = Label(_("Close")) self.startingUp = False self.goingDown = False self.cmdlist = [] self.run = 0 self.createSetup() ConfigListScreen.__init__(self, self.list, session=session) self.activeConfigEntry.addNotifier(self.toggleServer) self["actions"] = ActionMap(["OkCancelActions", "ColorActions"], { "cancel": self.cancel, "red": self.cancel, "green": self.green }, -2) if confError: self.onExecBegin.append(self.errorMbox) def errorMbox(self): info = self.session.open(MessageBox, _("/etc/smb.conf not found or readerror!"), MessageBox.TYPE_ERROR) info.setTitle("setup Samba-Server") self.close() def createSetup(self): self.list = [] self.list.append( getConfigListEntry(_("Enable/Disable Samba-Server"), self.activeConfigEntry)) if self.activeConfigEntry.value: self.list.append( getConfigListEntry(_("server string"), self.serverStringConfigEntry)) self.list.append( getConfigListEntry(_("netbios name"), self.netbiosNameConfigEntry)) self.list.append( getConfigListEntry(_("workgroup"), self.workgroupConfigEntry)) self["smbdLabel"].show() self["nmbdLabel"].show() self["ButtonGreentext"].show() self["ButtonGreen"].show() if self.goingDown or self.startingUp: if self.goingDown: self["smbdLabel"].setText(_("Status smbd: going down...")) self["nmbdLabel"].setText(_("Status nmbd: going down...")) if self.startingUp: self["smbdLabel"].setText(_("Status smbd: starting up...")) self["nmbdLabel"].setText(_("Status nmbd: starting up...")) else: self.smbdLabelSet() self.nmbdLabelSet() else: self["smbdLabel"].hide() self["nmbdLabel"].hide() self["ButtonGreentext"].hide() self["ButtonGreen"].hide() def toggleServer(self, configElement): self.createSetup() self["config"].l.setList(self.list) if not configElement.value: if not self.goingDown or not self.startingUp: if isRunning('smbd') or isRunning('nmbd'): self.sambaDown() self.deleteScripts() def cancel(self): if self.run == len(self.cmdlist): self.close() self.container.appClosed.remove(self.runFinished) def green(self): if self.activeConfigEntry.value: self.sambaDown() confError = 0 confError += writeAttribute('/etc/samba/smb.conf', 'global', 'server string', self.serverStringConfigEntry.value) confError += writeAttribute('/etc/samba/smb.conf', 'global', 'netbios name', self.netbiosNameConfigEntry.value) confError += writeAttribute('/etc/samba/smb.conf', 'global', 'workgroup', self.workgroupConfigEntry.value) if confError < 3: info = self.session.open( MessageBox, _("/etc/smb.conf not found or writeerror!"), MessageBox.TYPE_ERROR) info.setTitle("setup Samba-Server") self.cancel() else: self.sambaUp() self.createUpScript() self.createDownScript() def smbdLabelSet(self): if isRunning('smbd'): self["smbdLabel"].setText(_("Status smbd: started")) else: self["smbdLabel"].setText(_("Status smbd: stopped")) def nmbdLabelSet(self): if isRunning('nmbd'): self["nmbdLabel"].setText(_("Status nmbd: started")) else: self["nmbdLabel"].setText(_("Status nmbd: stopped")) def dataAvail(self, str): print(str, ) def runFinished(self, retval): self.run += 1 if self.run != len(self.cmdlist): self.container.execute(self.cmdlist[self.run]) else: self.run = 0 self.cmdlist = [] self.startingUp = False self.goingDown = False self.smbdLabelSet() self.nmbdLabelSet() def sambaUp(self): self["smbdLabel"].setText(_("Status smbd: starting up...")) self["nmbdLabel"].setText(_("Status nmbd: starting up...")) self.cmdlist.append("nmbd -D") self.cmdlist.append("smbd -D") self.startingUp = True self.container.execute(self.cmdlist[self.run]) def sambaDown(self): self["smbdLabel"].setText(_("Status smbd: going down...")) self["nmbdLabel"].setText(_("Status nmbd: going down...")) self.cmdlist.append("killall -9 smbd") self.cmdlist.append("killall -9 nmbd") self.goingDown = True self.container.execute(self.cmdlist[self.run]) def createUpScript(self): scriptfile = open("/etc/network/if-up.d/01samba-start", "w") scriptfile.write("#!/bin/sh\n") scriptfile.write("nmbd -D\n") scriptfile.write("smbd -D\n") scriptfile.close() Console().ePopen("chmod 755 /etc/network/if-up.d/01samba-start") def createDownScript(self): scriptfile = open("/etc/network/if-down.d/01samba-kill", "w") scriptfile.write("#!/bin/sh\n") scriptfile.write("killall -9 smbd\n") scriptfile.write("rm -rf /var/log/log.smbd\n") scriptfile.write("killall -9 nmbd\n") scriptfile.write("rm -rf /var/log/log.nmbd\n") scriptfile.close() Console().ePopen("chmod 755 /etc/network/if-down.d/01samba-kill") def deleteScripts(self): Console().ePopen("rm -rf /etc/network/if-up.d/01samba-start") Console().ePopen("rm -rf /etc/network/if-down.d/01samba-kill")
class EPGRefreshServiceEditor(Screen, ConfigListScreen): """Edit Services to be refreshed by EPGRefresh""" skin = """<screen name="EPGRefreshServiceEditor" title="Edit Services to refresh" position="center,center" size="565,280"> <ePixmap position="0,0" size="140,40" pixmap="buttons/red.png" transparent="1" alphatest="on" /> <ePixmap position="140,0" size="140,40" pixmap="buttons/green.png" transparent="1" alphatest="on" /> <ePixmap position="280,0" size="140,40" pixmap="buttons/yellow.png" transparent="1" alphatest="on" /> <ePixmap position="420,0" size="140,40" pixmap="buttons/blue.png" transparent="1" alphatest="on" /> <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget name="config" position="5,45" size="555,225" scrollbarMode="showOnDemand" /> </screen>""" def __init__(self, session, services): Screen.__init__(self, session) # Summary self.setup_title = _("EPGRefresh Services") self.onChangedEntry = [] # We need to copy the list to be able to ignore changes self.services = (services[0][:], services[1][:]) self.typeSelection = NoSave( ConfigSelection( choices=[("channels", _("Channels")), ("bouquets", _("Bouquets"))])) self.typeSelection.addNotifier(self.refresh, initial_call=False) self.reloadList() ConfigListScreen.__init__(self, self.list, session=session, on_change=self.changed) # Initialize StaticTexts self["key_red"] = StaticText(_("Cancel")) self["key_green"] = StaticText(_("OK")) self["key_yellow"] = StaticText(_("Delete")) self["key_blue"] = StaticText(_("New")) # Define Actions self["actions"] = ActionMap( ["SetupActions", "ColorActions"], { "cancel": self.cancel, "save": self.save, "yellow": self.removeService, "blue": self.newService }, prio=-2) # Trigger change self.changed() self.onLayoutFinish.append(self.setCustomTitle) def setCustomTitle(self): self.setTitle(_("Edit Services to refresh")) def saveCurrent(self): del self.services[self.idx][:] # Warning, accessing a ConfigListEntry directly might be considered evil! myl = self["config"].getList() myl.pop(0) for item in myl: self.services[self.idx].append(item[1].value) def refresh(self, value): self.saveCurrent() self.reloadList() self["config"].setList(self.list) def reloadList(self): self.list = [getConfigListEntry(_("Editing"), self.typeSelection)] if self.typeSelection.value == "channels": self.idx = 0 else: # self.typeSelection.value == "bouquets": self.idx = 1 self.list.extend([ getConfigListEntry( _("Refreshing"), NoSave( ConfigSelection( choices=[(x, ServiceReference(x.sref).getServiceName( ).replace('\xc2\x86', '').replace('\xc2\x87', ''))]))) for x in self.services[self.idx] ]) def changed(self): for x in self.onChangedEntry: x() def getCurrentEntry(self): cur = self["config"].getCurrent() if cur: return cur[0] return "" def getCurrentValue(self): cur = self["config"].getCurrent() if cur: return str(cur[1].getText()) return "" def createSummary(self): return SetupSummary def removeService(self): cur = self["config"].getCurrent() if cur and cur[1] is not self.typeSelection: list = self["config"].getList() list.remove(cur) self["config"].setList(list) def newService(self): if self.typeSelection.value == "channels": self.session.openWithCallback(self.finishedServiceSelection, SimpleChannelSelection, _("Select channel to refresh")) else: # self.typeSelection.value == "bouquets": self.session.openWithCallback(self.finishedServiceSelection, SimpleBouquetSelection, _("Select bouquet to refresh")) def finishedServiceSelection(self, *args): if args: list = self["config"].getList() list.append( getConfigListEntry( _("Refreshing"), NoSave( ConfigSelection(choices=[( EPGRefreshService(str(args[0].toString()), None), ServiceReference(args[0]).getServiceName().replace( '\xc2\x86', '').replace('\xc2\x87', ''))])))) self["config"].setList(list) def cancel(self): self.close(None) def closeRecursive(self): self.cancel() def save(self): self.saveCurrent() self.close(self.services)
class AutoTimerServiceEditor(Screen, ConfigListScreen): """Edit allowed Services of a AutoTimer""" skin = """<screen name="AutoTimerServiceEditor" title="Edit AutoTimer Services" position="center,center" size="565,280"> <ePixmap position="0,0" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" /> <ePixmap position="140,0" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" /> <ePixmap position="280,0" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" /> <ePixmap position="420,0" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" /> <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget name="config" position="5,45" size="555,225" scrollbarMode="showOnDemand" /> </screen>""" def __init__(self, session, servicerestriction, servicelist, bouquetlist): Screen.__init__(self, session) # Summary self.setup_title = _("AutoTimer Services") self.onChangedEntry = [] self.services = ( servicelist[:], bouquetlist[:] ) self.enabled = NoSave(ConfigEnableDisable(default = servicerestriction)) self.typeSelection = NoSave(ConfigSelection(choices = [ ("channels", _("Channels")), ("bouquets", _("Bouquets"))] )) self.typeSelection.addNotifier(self.refresh, initial_call = False) self.reloadList() ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed) # Initialize Buttons self["key_red"] = StaticText(_("Cancel")) self["key_green"] = StaticText(_("OK")) self["key_yellow"] = StaticText(_("Delete")) self["key_blue"] = StaticText(_("New")) # Define Actions self["actions"] = ActionMap(["SetupActions", "ColorActions"], { "cancel": self.cancel, "save": self.save, "yellow": self.remove, "blue": self.new } ) # Trigger change self.changed() self.onLayoutFinish.append(self.setCustomTitle) def setCustomTitle(self): self.setTitle(_("Edit AutoTimer services")) def saveCurrent(self): del self.services[self.idx][:] # Warning, accessing a ConfigListEntry directly might be considered evil! myl = self["config"].getList()[:] myl.pop(0) # Enabled myl.pop(0) # Type for item in myl: self.services[self.idx].append(item[1].value) def refresh(self, *args, **kwargs): self.saveCurrent() self.reloadList() self["config"].setList(self.list) def reloadList(self): self.list = [ getConfigListEntry(_("Enable Service Restriction"), self.enabled), getConfigListEntry(_("Editing"), self.typeSelection) ] if self.typeSelection.value == "channels": self.idx = 0 else: # self.typeSelection.value == "bouquets": self.idx = 1 self.list.extend([ getConfigListEntry(_("Record on"), NoSave(ConfigSelection(choices = [(str(x), ServiceReference(str(x)).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', ''))]))) for x in self.services[self.idx] ]) def changed(self): for x in self.onChangedEntry: try: x() except Exception: pass def getCurrentEntry(self): return self["config"].getCurrent()[0] def getCurrentValue(self): return str(self["config"].getCurrent()[1].getText()) def createSummary(self): return SetupSummary def remove(self): idx = self["config"].getCurrentIndex() if idx and idx > 1: list = self["config"].getList() list.remove(self["config"].getCurrent()) self["config"].setList(list) def new(self): if self.typeSelection.value == "channels": self.session.openWithCallback( self.finishedServiceSelection, SimpleChannelSelection, _("Select channel to record on") ) else: # self.typeSelection.value == "bouquets": self.session.openWithCallback( self.finishedServiceSelection, SimpleBouquetSelection, _("Select bouquet to record on") ) def finishedServiceSelection(self, *args): if args: list = self["config"].getList() sname = args[0].toString() if self.typeSelection.value == "channels" and not (args[0].flags & eServiceReference.isGroup): # strip all after last : when adding a (non alternative) channel pos = sname.rfind(':') if pos != -1: if sname[pos-1] == ':': pos -= 1 sname = sname[:pos+1] list.append(getConfigListEntry(_("Record on"), NoSave(ConfigSelection(choices = [(sname, ServiceReference(args[0]).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', ''))])))) self["config"].setList(list) def cancel(self): if self["config"].isChanged(): self.session.openWithCallback( self.cancelConfirm, MessageBox, _("Really close without saving settings?") ) else: self.close(None) def cancelConfirm(self, ret): if ret: self.close(None) def save(self): self.refresh() self.close(( self.enabled.value, self.services ))
class GrowleeConfiguration(Screen, ConfigListScreen): skin = """ <screen name="GrowleeConfiguration" position="center,center" size="560,400" title="Growlee Setup" > <ePixmap position="0,0" size="140,40" pixmap="buttons/red.png" transparent="1" alphatest="on" /> <ePixmap position="140,0" size="140,40" pixmap="buttons/green.png" transparent="1" alphatest="on" /> <ePixmap position="280,0" size="140,40" pixmap="buttons/yellow.png" transparent="1" alphatest="on" /> <ePixmap position="420,0" size="140,40" pixmap="buttons/blue.png" transparent="1" alphatest="on" /> <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget name="config" position="5,45" size="550,350" scrollbarMode="showOnDemand" /> </screen>""" def __init__(self, session): Screen.__init__(self, session) # Buttons self["key_red"] = StaticText(_("Cancel")) self["key_green"] = StaticText(_("OK")) self["key_yellow"] = StaticText(_("New")) self["key_blue"] = StaticText(_("Delete")) # Summary self.setup_title = "Growlee Configuration" self.onChangedEntry = [] # Define Actions self["setupActions"] = ActionMap( ["SetupActions", "ColorActions"], { "blue": self.delete, "yellow": self.new, "cancel": self.keyCancel, "save": self.keySave, }) self.hostElement = NoSave( ConfigSelection(choices=[(x, x.name.value) for x in config.plugins.growlee.hosts])) self.hostElement.addNotifier(self.setupList, initial_call=False) ConfigListScreen.__init__(self, [], session=session, on_change=self.changed) self.cur = self.hostElement.value # Trigger change self.setupList() self.changed() def delete(self): from Screens.MessageBox import MessageBox self.session.openWithCallback( self.deleteConfirm, MessageBox, _("Really delete this entry?\nIt cannot be recovered!")) def deleteConfirm(self, result): if result and config.plugins.growlee.hostcount.value > 0: config.plugins.growlee.hostcount.value -= 1 config.plugins.growlee.hosts.remove(self.cur) self.hostElement.setChoices([ (x, x.name.value) for x in config.plugins.growlee.hosts ]) self.cur = self.hostElement.value def new(self): self.cur = addHost(_("New connection")) config.plugins.growlee.hostcount.value += 1 self.hostElement.setChoices([(x, x.name.value) for x in config.plugins.growlee.hosts]) self.hostElement.setValue(self.cur) def changed(self): for x in self.onChangedEntry: x() def setupList(self, *args): last = self.cur if self.setupList in last.protocol.notifiers: last.protocol.removeNotifier(self.setupList) cur = self.hostElement.value self.cur = cur cur.protocol.addNotifier(self.setupList, initial_call=False) l = [ getConfigListEntry(_("Host"), self.hostElement), getConfigListEntry(_("Name"), cur.name), getConfigListEntry(_("Type"), cur.protocol), getConfigListEntry(_("Minimum Priority"), cur.level), getConfigListEntry(_("Send Notifications?"), cur.enable_outgoing), ] proto = cur.protocol.value if proto == "prowl": l.append(getConfigListEntry(_("API Key"), cur.password)) else: if proto != "gntp": l.append( getConfigListEntry(_("Receive Notifications?"), cur.enable_incoming)) l.append(getConfigListEntry(_("Address"), cur.address)) if proto == "growl" or proto == "gntp": l.append(getConfigListEntry(_("Password"), cur.password)) self["config"].list = l def getCurrentEntry(self): cur = self["config"].getCurrent() return cur and cur[0] def getCurrentValue(self): cur = self["config"].getCurrent() return cur and str(cur[1].getText()) def createSummary(self): return SetupSummary def keySave(self): config.plugins.growlee.save() if self["config"].isChanged(): def doConnect(*args, **kwargs): growleeConnection.listen() d = growleeConnection.stop() if d is not None: d.addCallback(doConnect).addErrback(emergencyDisable) else: maybeConnect() self.saveAll() self.close() def close(self): if self.setupList in self.cur.protocol.notifiers: self.cur.protocol.removeNotifier(self.setupList) Screen.close(self)
class EPGRefreshServiceEditor(Screen, ConfigListScreen): """Edit Services to be refreshed by EPGRefresh""" skin = """<screen name="EPGRefreshServiceEditor" title="Edit Services to refresh" position="center,center" size="565,280"> <ePixmap position="0,0" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" /> <ePixmap position="140,0" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" /> <ePixmap position="280,0" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" /> <ePixmap position="420,0" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" /> <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" /> <widget name="config" position="5,45" size="555,225" scrollbarMode="showOnDemand" /> </screen>""" def __init__(self, session, services): Screen.__init__(self, session) # Summary self.setup_title = _("EPGRefresh Services") self.onChangedEntry = [] # We need to copy the list to be able to ignore changes self.services = ( services[0][:], services[1][:] ) self.typeSelection = NoSave(ConfigSelection(choices = [ ("channels", _("Channels")), ("bouquets", _("Bouquets"))] )) self.typeSelection.addNotifier(self.refresh, initial_call = False) self.reloadList() ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed) # Initialize StaticTexts self["key_red"] = StaticText(_("Cancel")) self["key_green"] = StaticText(_("OK")) self["key_yellow"] = StaticText(_("delete")) self["key_blue"] = StaticText(_("New")) # Define Actions self["actions"] = ActionMap(["SetupActions", "ColorActions"], { "cancel": self.cancel, "save": self.save, "yellow": self.removeService, "blue": self.newService } ) # Trigger change self.changed() self.onLayoutFinish.append(self.setCustomTitle) def setCustomTitle(self): self.setTitle(_("Edit Services to refresh")) def saveCurrent(self): del self.services[self.idx][:] # Warning, accessing a ConfigListEntry directly might be considered evil! myl = self["config"].getList() myl.pop(0) for item in myl: self.services[self.idx].append(item[1].value) def refresh(self, value): self.saveCurrent() self.reloadList() self["config"].setList(self.list) def reloadList(self): self.list = [ getConfigListEntry(_("Editing"), self.typeSelection) ] if self.typeSelection.value == "channels": self.idx = 0 else: # self.typeSelection.value == "bouquets": self.idx = 1 self.list.extend([ getConfigListEntry(_("Refreshing"), NoSave(ConfigSelection(choices = [(x, ServiceReference(x.sref).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', ''))]))) for x in self.services[self.idx] ]) def changed(self): for x in self.onChangedEntry: x() def getCurrentEntry(self): cur = self["config"].getCurrent() if cur: return cur[0] return "" def getCurrentValue(self): cur = self["config"].getCurrent() if cur: return str(cur[1].getText()) return "" def createSummary(self): return SetupSummary def removeService(self): cur = self["config"].getCurrent() if cur and cur[1] is not self.typeSelection: list = self["config"].getList() list.remove(cur) self["config"].setList(list) def newService(self): if self.typeSelection.value == "channels": self.session.openWithCallback( self.finishedServiceSelection, SimpleChannelSelection, _("Select channel to refresh") ) else: # self.typeSelection.value == "bouquets": self.session.openWithCallback( self.finishedServiceSelection, SimpleBouquetSelection, _("Select bouquet to refresh") ) def finishedServiceSelection(self, *args): if args: list = self["config"].getList() list.append(getConfigListEntry( _("Refreshing"), NoSave(ConfigSelection(choices = [( EPGRefreshService(str(args[0].toString()), None), ServiceReference(args[0]).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '') )])) )) self["config"].setList(list) def cancel(self): self.close(None) def save(self): self.saveCurrent() self.close(self.services)
class EmissionBandwidth(Screen, ConfigListScreen): def __init__(self, session, val, isTorrent, rpc_version): Screen.__init__(self, session) self.skinName = [ "EmissionBandwith", "Setup" ] # Summary self.setup_title = _("Bandwidth settings") self.onChangedEntry = [] ConfigListScreen.__init__(self, [], session = session, on_change = self.changed) self.isTorrent = isTorrent if isTorrent: if rpc_version < 5: downloadLimitMode = val.downloadLimitMode uploadLimitMode = val.uploadLimitMode modelist = [(0, _("Global Setting")), (2, _("Unlimited")), (1, _("Limit"))] else: downloadLimitMode = val.downloadLimited uploadLimitMode = val.uploadLimited modelist = [(0, _("Global Setting")), (1, _("Limit"))] # XXX: this is a pure guess... self.downloadLimitMode = NoSave(ConfigSelection(choices = modelist, default = downloadLimitMode)) self.downloadLimit = NoSave(ConfigNumber(default = val.downloadLimit)) self.uploadLimitMode = NoSave(ConfigSelection(choices = modelist, default = uploadLimitMode)) self.uploadLimit = NoSave(ConfigNumber(default = val.uploadLimit)) self.maxConnectedPeers = NoSave(ConfigNumber(default = val.maxConnectedPeers)) else: #if not isTorrent: if rpc_version < 5: peerLimit = val.peer_limit port = val.port pex_allowed = val.pex_allowed else: peerLimit = val.peer_limit_global port = val.peer_port pex_allowed = val.pex_enabled self.downloadLimitMode = NoSave(ConfigSelection(choices = [(0, _("Unlimited")), (1, _("Limit"))], default = val.speed_limit_down_enabled)) self.downloadLimit = NoSave(ConfigNumber(default = val.speed_limit_down)) self.uploadLimitMode = NoSave(ConfigSelection(choices = [(0, _("Unlimited")), (1, _("Limit"))], default = val.speed_limit_up_enabled)) self.uploadLimit = NoSave(ConfigNumber(default = val.speed_limit_up)) self.maxConnectedPeers = NoSave(ConfigNumber(default = peerLimit)) self.encryption = NoSave(ConfigSelection(choices = [('required', _("required")), ('preferred', _("preferred")), ('tolerated', _("tolerated"))], default = val.encryption)) self.download_dir = NoSave(ConfigText(default = val.download_dir, fixed_size = False)) self.pex_allowed = NoSave(ConfigYesNo(default = pex_allowed)) self.port = NoSave(ConfigNumber(default = port)) self.port_forwarding_enabled = NoSave(ConfigYesNo(default = val.port_forwarding_enabled)) self.downloadLimitMode.addNotifier(self.updateList, initial_call = False) self.uploadLimitMode.addNotifier(self.updateList, initial_call = False) self.updateList() # Initialize widgets self["key_green"] = StaticText(_("OK")) self["key_red"] = StaticText(_("Cancel")) self.full_title = _("%s bandwidth settings") % (isTorrent and str(val.name) or "eMission") # Define Actions self["actions"] = ActionMap(["SetupActions"], { "cancel": self.keyCancel, "save": self.keySave, } ) # Trigger change self.changed() self.onLayoutFinish.append(self.setCustomTitle) def updateList(self, *args): list = [ getConfigListEntry(_("Download rate"), self.downloadLimitMode) ] if self.downloadLimitMode.value == 1: list.append(getConfigListEntry(_("Limit"), self.downloadLimit)) list.append(getConfigListEntry(_("Upload rate"), self.uploadLimitMode)) if self.uploadLimitMode.value == 1: list.append(getConfigListEntry(_("Limit"), self.uploadLimit)) list.append(getConfigListEntry(_("Maximum Connections"), self.maxConnectedPeers)) if not self.isTorrent: list.extend(( getConfigListEntry(_("Encryption"), self.encryption), getConfigListEntry(_("Download directory"), self.download_dir), getConfigListEntry(_("Allow PEX"), self.pex_allowed), getConfigListEntry(_("Port"), self.port), getConfigListEntry(_("Enable Port-Forwarding"), self.port_forwarding_enabled), )) self["config"].setList(list) def setCustomTitle(self): self.setTitle(self.full_title) def changed(self): for x in self.onChangedEntry: x() def getCurrentEntry(self): return self["config"].getCurrent()[0] def getCurrentValue(self): return str(self["config"].getCurrent()[1].getText()) def createSummary(self): return SetupSummary def keySave(self): if self.downloadLimitMode.value == 2 or self.uploadLimitMode.value == 2: self.session.open( MessageBox, _("Setting \"Unlimited\" is not supported via RPC.\nEither abort or choose another limit to continue."), type = MessageBox.TYPE_ERROR ) else: # NOTE: transmissionrpc will take care of translating the arguments dict = { 'speed_limit_down_enabled': self.downloadLimitMode.value, 'speed_limit_down': self.downloadLimit.value, 'speed_limit_up_enabled': self.uploadLimitMode.value, 'speed_limit_up': self.uploadLimit.value, 'peer_limit': self.maxConnectedPeers.value, } if not self.isTorrent: dict.update({ 'encryption': self.encryption.value, 'download_dir': self.download_dir.value, 'pex_allowed': self.pex_allowed.value, 'port': self.port.value, 'port_forwarding_enabled': self.port_forwarding_enabled.value, }) self.close(dict)
class EmissionBandwidth(Screen, ConfigListScreen): def __init__(self, session, val, isTorrent, rpc_version): Screen.__init__(self, session) self.skinName = ["EmissionBandwith", "Setup"] # Summary self.setup_title = _("Bandwidth settings") self.onChangedEntry = [] ConfigListScreen.__init__(self, [], session=session, on_change=self.changed) self.isTorrent = isTorrent if isTorrent: if rpc_version < 5: downloadLimitMode = val.downloadLimitMode uploadLimitMode = val.uploadLimitMode modelist = [(0, _("Global Setting")), (2, _("Unlimited")), (1, _("Limit"))] else: downloadLimitMode = val.downloadLimited uploadLimitMode = val.uploadLimited modelist = [(0, _("Global Setting")), (1, _("Limit"))] # XXX: this is a pure guess... self.downloadLimitMode = NoSave( ConfigSelection(choices=modelist, default=downloadLimitMode)) self.downloadLimit = NoSave( ConfigNumber(default=val.downloadLimit)) self.uploadLimitMode = NoSave( ConfigSelection(choices=modelist, default=uploadLimitMode)) self.uploadLimit = NoSave(ConfigNumber(default=val.uploadLimit)) self.maxConnectedPeers = NoSave( ConfigNumber(default=val.maxConnectedPeers)) else: #if not isTorrent: if rpc_version < 5: peerLimit = val.peer_limit port = val.port pex_allowed = val.pex_allowed else: peerLimit = val.peer_limit_global port = val.peer_port pex_allowed = val.pex_enabled self.downloadLimitMode = NoSave( ConfigSelection(choices=[(0, _("Unlimited")), (1, _("Limit"))], default=val.speed_limit_down_enabled)) self.downloadLimit = NoSave( ConfigNumber(default=val.speed_limit_down)) self.uploadLimitMode = NoSave( ConfigSelection(choices=[(0, _("Unlimited")), (1, _("Limit"))], default=val.speed_limit_up_enabled)) self.uploadLimit = NoSave(ConfigNumber(default=val.speed_limit_up)) self.maxConnectedPeers = NoSave(ConfigNumber(default=peerLimit)) self.encryption = NoSave( ConfigSelection(choices=[('required', _("required")), ('preferred', _("preferred")), ('tolerated', _("tolerated"))], default=val.encryption)) self.download_dir = NoSave( ConfigText(default=val.download_dir, fixed_size=False)) self.pex_allowed = NoSave(ConfigYesNo(default=pex_allowed)) self.port = NoSave(ConfigNumber(default=port)) self.port_forwarding_enabled = NoSave( ConfigYesNo(default=val.port_forwarding_enabled)) self.downloadLimitMode.addNotifier(self.updateList, initial_call=False) self.uploadLimitMode.addNotifier(self.updateList, initial_call=False) self.updateList() # Initialize widgets self["key_green"] = StaticText(_("OK")) self["key_red"] = StaticText(_("Cancel")) self.full_title = _("%s bandwidth settings") % ( isTorrent and str(val.name) or "eMission") # Define Actions self["actions"] = ActionMap(["SetupActions"], { "cancel": self.keyCancel, "save": self.keySave, }) # Trigger change self.changed() self.onLayoutFinish.append(self.setCustomTitle) def updateList(self, *args): list = [getConfigListEntry(_("Download rate"), self.downloadLimitMode)] if self.downloadLimitMode.value == 1: list.append(getConfigListEntry(_("Limit"), self.downloadLimit)) list.append(getConfigListEntry(_("Upload rate"), self.uploadLimitMode)) if self.uploadLimitMode.value == 1: list.append(getConfigListEntry(_("Limit"), self.uploadLimit)) list.append( getConfigListEntry(_("Maximum Connections"), self.maxConnectedPeers)) if not self.isTorrent: list.extend(( getConfigListEntry(_("Encryption"), self.encryption), getConfigListEntry(_("Download directory"), self.download_dir), getConfigListEntry(_("Allow PEX"), self.pex_allowed), getConfigListEntry(_("Port"), self.port), getConfigListEntry(_("Enable Port-Forwarding"), self.port_forwarding_enabled), )) self["config"].setList(list) def setCustomTitle(self): self.setTitle(self.full_title) def changed(self): for x in self.onChangedEntry: x() def getCurrentEntry(self): return self["config"].getCurrent()[0] def getCurrentValue(self): return str(self["config"].getCurrent()[1].getText()) def createSummary(self): return SetupSummary def keySave(self): if self.downloadLimitMode.value == 2 or self.uploadLimitMode.value == 2: self.session.open( MessageBox, _("Setting \"Unlimited\" is not supported via RPC.\nEither abort or choose another limit to continue." ), type=MessageBox.TYPE_ERROR) else: # NOTE: transmissionrpc will take care of translating the arguments dict = { 'speed_limit_down_enabled': self.downloadLimitMode.value, 'speed_limit_down': self.downloadLimit.value, 'speed_limit_up_enabled': self.uploadLimitMode.value, 'speed_limit_up': self.uploadLimit.value, 'peer_limit': self.maxConnectedPeers.value, } if not self.isTorrent: dict.update({ 'encryption': self.encryption.value, 'download_dir': self.download_dir.value, 'pex_allowed': self.pex_allowed.value, 'port': self.port.value, 'port_forwarding_enabled': self.port_forwarding_enabled.value, }) self.close(dict)
class AutoMountEdit(Screen, ConfigListScreen): skin = """ <screen name="AutoMountEdit" position="center,center" size="560,450" title="MountEdit"> <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" /> <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" /> <widget name="config" position="5,50" size="550,250" zPosition="1" scrollbarMode="showOnDemand" /> <ePixmap pixmap="skin_default/div-h.png" position="0,420" zPosition="1" size="560,2" /> <widget source="introduction" render="Label" position="10,430" size="540,21" zPosition="10" font="Regular;21" halign="center" valign="center" backgroundColor="#25062748" transparent="1"/> <widget source="VKeyIcon" render="Pixmap" pixmap="skin_default/buttons/key_text.png" position="10,430" zPosition="10" size="35,25" transparent="1" alphatest="on"> <convert type="ConditionalShowHide" /> </widget> <widget name="HelpWindow" pixmap="skin_default/vkey_icon.png" position="160,350" zPosition="1" size="1,1" transparent="1" alphatest="on" /> </screen>""" def __init__(self, session, plugin_path, mountinfo=None, newmount=True): self.skin_path = plugin_path self.session = session Screen.__init__(self, self.session) self.onChangedEntry = [] self.mountinfo = mountinfo self.newmount = newmount if self.mountinfo is None: # Initialize blank mount entry self.mountinfo = { 'isMounted': False, 'mountusing': False, 'active': False, 'ip': False, 'sharename': False, 'sharedir': False, 'username': False, 'password': False, 'mounttype': False, 'options': False, 'hdd_replacement': False } self.editableMountType = not self.mountinfo['mounttype'] self.applyConfigRef = None self.updateConfigRef = None self.mounts = iAutoMount.getMountsList() self.createConfig() self["actions"] = NumberActionMap( ["SetupActions", "ColorActions"], { "ok": self.ok, "back": self.close, "cancel": self.close, "red": self.close, "green": self.ok, }, -2) self.list = [] ConfigListScreen.__init__(self, self.list, session=self.session) self.createSetup() self.onLayoutFinish.append(self.layoutFinished) # Initialize Buttons self["VKeyIcon"] = Boolean(False) self["HelpWindow"] = Pixmap() self["introduction"] = StaticText( _("Press OK to activate the settings.")) self["key_red"] = StaticText(_("Cancel")) self["key_green"] = StaticText(_("Save")) # for summary: def changedEntry(self): for x in self.onChangedEntry: x() def getCurrentEntry(self): return self["config"].getCurrent()[0] def getCurrentValue(self): return str(self["config"].getCurrent()[1].getText()) def createSummary(self): from Screens.Setup import SetupSummary return SetupSummary def layoutFinished(self): self.setup_title = _("Mounts editor") Screen.setTitle(self, _(self.setup_title)) self["VKeyIcon"].boolean = False self["VirtualKB"].setEnabled(False) self["HelpWindow"].hide() # helper function to convert ips from a sring to a list of ints def convertIP(self, ip): strIP = ip.split('.') ip = [] for x in strIP: ip.append(int(x)) return ip def cleanSharename(self, sharename): # "\W" matches everything that is "not numbers, letters, or underscores", where the alphabet defaults to ASCII. return re_sub("\W", "", sharename) def exit(self): self.close() def createConfig(self): self.mountusingEntry = None self.sharenameEntry = None self.mounttypeEntry = None self.activeEntry = None self.ipEntry = None self.sharedirEntry = None self.optionsEntry = None self.smbprotoEntry = None self.usernameEntry = None self.passwordEntry = None self.hdd_replacementEntry = None self.smb_proto_versions = [] self.smb_proto_versions.append(("", _("Default"))) if getMachineBuild != "inihdx": self.smb_proto_versions.append((",vers=1.0", _("1.0"))) self.smb_proto_versions.append((",vers=2.1", _("2.1"))) self.mountusing = [] self.mountusing.append(("autofs", _("AUTOFS (mount as needed)"))) self.mountusing.append(("fstab", _("FSTAB (mount at boot)"))) self.mountusing.append(("enigma2", _("Enigma2 (mount using enigma2)"))) self.sharetypelist = [] self.sharetypelist.append(("cifs", _("CIFS share"))) self.sharetypelist.append(("nfs", _("NFS share"))) mountusing_default = "fstab" if getImageDistro() in ("openvix", "easy-gui-aus", "beyonwiz", "openatv", "openhdf"): mountusing_default = "autofs" if 'mountusing' in self.mountinfo: mountusing = self.mountinfo['mountusing'] if mountusing is False: mountusing = mountusing_default else: mountusing = mountusing_default if 'mounttype' in self.mountinfo: mounttype = self.mountinfo['mounttype'] if mounttype is False: mounttype = "nfs" else: mounttype = "nfs" if 'active' in self.mountinfo: active = self.mountinfo['active'] if active == 'True': active = True if active == 'False': active = False else: active = True if 'ip' in self.mountinfo: if self.mountinfo['ip'] is False: ip = [192, 168, 0, 0] else: ip = self.convertIP(self.mountinfo['ip']) else: ip = [192, 168, 0, 0] defaultOptions = default_mount_options[mounttype] if self.mountinfo.get('sharename'): sharename = self.cleanSharename(self.mountinfo['sharename']) self.old_sharename = self.mountinfo['sharename'] else: sharename = "" self.old_sharename = None if 'sharedir' in self.mountinfo: sharedir = self.mountinfo['sharedir'] self.old_sharedir = sharedir else: sharedir = "" self.old_sharedir = None def parseOptions(options): s = str(options) if ",vers=1.0" in s: smb = ",vers=1.0" opt = s.replace(",vers=1.0", "") elif ",vers=2.1" in s: smb = ",vers=2.1" opt = s.replace(",vers=2.1", "") else: smb = "" opt = options return (smb, opt) if 'options' in self.mountinfo: smbdefault, options = parseOptions(self.mountinfo['options']) else: options = defaultOptions smbdefault = "" if 'username' in self.mountinfo: username = self.mountinfo['username'] else: username = "" if 'password' in self.mountinfo: password = self.mountinfo['password'] else: password = "" if 'hdd_replacement' in self.mountinfo: hdd_replacement = self.mountinfo['hdd_replacement'] if hdd_replacement == 'True': hdd_replacement = True if hdd_replacement == 'False': hdd_replacement = False else: hdd_replacement = False if sharename is False: sharename = "" if sharedir is False: sharedir = "" if username is False: username = "" if password is False: password = "" def removeSpaces(configEntry): t = configEntry.value.translate(None, " \t\r\n") if t != configEntry.value: configEntry.value = t self.mountusingConfigEntry = NoSave( ConfigSelection(self.mountusing, default=mountusing)) self.activeConfigEntry = NoSave(ConfigEnableDisable(default=active)) self.ipConfigEntry = NoSave(ConfigIP(default=ip)) self.sharenameConfigEntry = NoSave( ConfigText(default=sharename, visible_width=50, fixed_size=False)) self.sharenameConfigEntry.addNotifier(removeSpaces) self.sharedirConfigEntry = NoSave( ConfigText(default=sharedir, visible_width=50, fixed_size=False)) self.sharedirConfigEntry.addNotifier(removeSpaces) self.optionsConfigEntry = NoSave( ConfigText(default=defaultOptions, visible_width=50, fixed_size=False)) if options is not False: self.optionsConfigEntry.value = options self.optionsConfigEntry.addNotifier(removeSpaces) self.smbprotoConfigEntry = NoSave( ConfigSelection(self.smb_proto_versions, default=smbdefault)) self.usernameConfigEntry = NoSave( ConfigText(default=username, visible_width=50, fixed_size=False)) self.usernameConfigEntry.addNotifier(removeSpaces) self.passwordConfigEntry = NoSave( ConfigPassword(default=password, visible_width=50, fixed_size=False)) self.passwordConfigEntry.addNotifier(removeSpaces) self.mounttypeConfigEntry = NoSave( ConfigSelection(self.sharetypelist, default=mounttype)) self.hdd_replacementConfigEntry = NoSave( ConfigYesNo(default=hdd_replacement)) def createSetup(self): self.list = [] self.mountusingEntry = getConfigListEntry(_("Mount using"), self.mountusingConfigEntry) self.list.append(self.mountusingEntry) self.activeEntry = getConfigListEntry(_("Active"), self.activeConfigEntry) self.list.append(self.activeEntry) self.sharenameEntry = getConfigListEntry(_("Local share name"), self.sharenameConfigEntry) self.list.append(self.sharenameEntry) if self.editableMountType: self.mounttypeEntry = getConfigListEntry(_("Mount type"), self.mounttypeConfigEntry) self.list.append(self.mounttypeEntry) self.ipEntry = getConfigListEntry(_("Server IP"), self.ipConfigEntry) self.list.append(self.ipEntry) self.sharedirEntry = getConfigListEntry(_("Server share"), self.sharedirConfigEntry) self.list.append(self.sharedirEntry) self.hdd_replacementEntry = getConfigListEntry( _("Use as HDD replacement"), self.hdd_replacementConfigEntry) self.list.append(self.hdd_replacementEntry) self.optionsEntry = getConfigListEntry(_("Mount options"), self.optionsConfigEntry) self.list.append(self.optionsEntry) if self.mounttypeConfigEntry.value == "cifs": self.smbprotoEntry = getConfigListEntry(_("SMB protocol version"), self.smbprotoConfigEntry) self.list.append(self.smbprotoEntry) self.usernameEntry = getConfigListEntry(_("Username"), self.usernameConfigEntry) self.list.append(self.usernameEntry) self.passwordEntry = getConfigListEntry(_("Password"), self.passwordConfigEntry) self.list.append(self.passwordEntry) self["config"].list = self.list self["config"].l.setList(self.list) self.kbentries = { self.sharenameEntry: _("Enter share name:"), self.sharedirEntry: _("Enter share directory:"), self.optionsEntry: _("Enter options:"), self.usernameEntry: _("Enter username:"******"Enter password:"******"config"].getCurrent() == self.mounttypeEntry: defaultOptions = default_mount_options[ self.mounttypeConfigEntry.value] if 'options' in self.mountinfo: options = self.mountinfo['options'] else: options = defaultOptions self.optionsConfigEntry = NoSave( ConfigText(default=defaultOptions, visible_width=50, fixed_size=False)) if options is not False: self.optionsConfigEntry.value = options self.createSetup() def KeyText(self): current = self["config"].getCurrent() if current in self.kbentries: self.HideHelp() self.session.openWithCallback(self.VirtualKeyBoardCallback, VirtualKeyBoard, title=self.kbentries[current], text=current[1].value) def VirtualKeyBoardCallback(self, callback=None): if callback is not None and len(callback): current = self["config"].getCurrent()[1] current.value = callback self["config"].invalidate(current) self.ShowHelp() def keyLeft(self): ConfigListScreen.keyLeft(self) self.newConfig() def keyRight(self): ConfigListScreen.keyRight(self) self.newConfig() def ok(self): self.HideHelp() sharename = self.cleanSharename(self.sharenameConfigEntry.value) sharedir = self.sharedirConfigEntry.value.lstrip("/") # Require both a local share name and remote mount point if not (sharename and sharedir): self.session.openWithCallback( self.restoreHelp, MessageBox, "Neither Local share name nor Server share can be blank!", type=MessageBox.TYPE_ERROR) return sharexists = False for data in self.mounts: if self.mounts[data]['sharename'] == self.old_sharename: sharexists = True break if not self.newmount and self.old_sharename and self.old_sharename != sharename: self.session.openWithCallback( self.updateConfig, MessageBox, _("You have changed the share name!\nUpdate existing entry and continue?\n" ), default=False) elif not self.newmount and self.old_sharename and self.old_sharename == sharename and sharexists: self.session.openWithCallback( self.updateConfig, MessageBox, _("A mount entry with this name already exists!\nUpdate existing entry and continue?\n" ), default=False) else: self.session.openWithCallback( self.applyConfig, MessageBox, _("Are you sure you want to save this network mount?\n\n")) def restoreHelp(self, _): self.ShowHelp() def updateConfig(self, ret=False): if (ret): sharedir = None sharename = self.cleanSharename(self.sharenameConfigEntry.value) xml_sharename = self.old_sharename if self.sharedirConfigEntry.value.startswith("/"): sharedir = self.sharedirConfigEntry.value[1:] else: sharedir = self.sharedirConfigEntry.value iAutoMount.setMountsAttribute(xml_sharename, "mountusing", self.mountusingConfigEntry.value) iAutoMount.setMountsAttribute(xml_sharename, "sharename", sharename) iAutoMount.setMountsAttribute(xml_sharename, "active", self.activeConfigEntry.value) iAutoMount.setMountsAttribute(xml_sharename, "ip", self.ipConfigEntry.getText()) iAutoMount.setMountsAttribute(xml_sharename, "sharedir", sharedir) iAutoMount.setMountsAttribute(xml_sharename, "mounttype", self.mounttypeConfigEntry.value) iAutoMount.setMountsAttribute( xml_sharename, "options", self.optionsConfigEntry.value + self.smbprotoConfigEntry.value) iAutoMount.setMountsAttribute(xml_sharename, "username", self.usernameConfigEntry.value) iAutoMount.setMountsAttribute(xml_sharename, "password", self.passwordConfigEntry.value) iAutoMount.setMountsAttribute( xml_sharename, "hdd_replacement", self.hdd_replacementConfigEntry.value) self.updateConfigRef = None self.updateConfigRef = self.session.openWithCallback( self.updateConfigfinishedCB, MessageBox, _("Please wait while updating your network mount..."), type=MessageBox.TYPE_INFO, enable_input=False) iAutoMount.writeMountsConfig() iAutoMount.getAutoMountPoints(self.updateConfigDataAvail, True) else: self.close() def updateConfigDataAvail(self, data): if data is True: self.updateConfigRef.close(True) def updateConfigfinishedCB(self, data): if data is True: self.session.openWithCallback( self.Updatefinished, MessageBox, _("Your network mount has been updated."), type=MessageBox.TYPE_INFO, timeout=10) def Updatefinished(self, data): if data is not None: if data is True: self.close() def applyConfig(self, ret=False): if (ret): data = { 'isMounted': False, 'mountusing': False, 'active': False, 'ip': False, 'sharename': False, 'sharedir': False, 'username': False, 'password': False, 'mounttype': False, 'options': False, 'hdd_replacement': False } data['mountusing'] = self.mountusingConfigEntry.value data['active'] = self.activeConfigEntry.value data['ip'] = self.ipConfigEntry.getText() data['sharename'] = self.cleanSharename( self.sharenameConfigEntry.value) if self.sharedirConfigEntry.value.startswith("/"): data['sharedir'] = self.sharedirConfigEntry.value[1:] else: data['sharedir'] = self.sharedirConfigEntry.value data[ 'options'] = self.optionsConfigEntry.value + self.smbprotoConfigEntry.value data['mounttype'] = self.mounttypeConfigEntry.value data['username'] = self.usernameConfigEntry.value data['password'] = self.passwordConfigEntry.value data['hdd_replacement'] = self.hdd_replacementConfigEntry.value self.applyConfigRef = None self.applyConfigRef = self.session.openWithCallback( self.applyConfigfinishedCB, MessageBox, _("Please wait for activation of your network mount..."), type=MessageBox.TYPE_INFO, enable_input=False) iAutoMount.automounts[self.sharenameConfigEntry.value] = data iAutoMount.writeMountsConfig() iAutoMount.getAutoMountPoints(self.applyConfigDataAvail, True) else: self.close() def applyConfigDataAvail(self, data): if data is True: self.applyConfigRef.close(True) def applyConfigfinishedCB(self, data): if data is True: self.session.openWithCallback( self.applyfinished, MessageBox, _("Your network mount has been activated."), type=MessageBox.TYPE_INFO, timeout=10) def applyfinished(self, data): if data is not None: if data is True: self.close()