Exemplo n.º 1
0
class DPS_ServerConfig(ConfigListScreen, Screen, DPH_PlexScreen):

    useMappings = False
    useHomeUsers = False
    authenticated = False

    def __init__(self, session, entry, data=None):
        printl("", self, "S")

        Screen.__init__(self, session)

        self.guiElements = getGuiElements()

        self["actions"] = ActionMap(
            ["DPS_ServerConfig", "ColorActions"], {
                "green": self.keySave,
                "cancel": self.keyCancel,
                "exit": self.keyCancel,
                "yellow": self.keyYellow,
                "blue": self.keyBlue,
                "red": self.keyRed,
                "left": self.keyLeft,
                "right": self.keyRight,
            }, -2)

        self["help"] = StaticText()

        self["btn_redText"] = Label()
        self["btn_red"] = Pixmap()

        self["btn_greenText"] = Label()
        self["btn_green"] = Pixmap()

        self["btn_yellowText"] = Label()
        self["btn_yellow"] = Pixmap()

        self["btn_blueText"] = Label()
        self["btn_blue"] = Pixmap()

        if entry is None:
            self.newmode = 1
            self.current = initServerEntryConfig()
            if data is not None:
                ipBlocks = data.get("server").split(".")
                self.current.name.value = data.get("serverName")
                self.current.ip.value = [
                    int(ipBlocks[0]),
                    int(ipBlocks[1]),
                    int(ipBlocks[2]),
                    int(ipBlocks[3])
                ]
                self.current.port.value = int(data.get("port"))

        else:
            self.newmode = 0
            self.current = entry
            self.currentId = self.current.id.value
            printl("currentId: " + str(self.currentId), self, "D")

        self.cfglist = []
        ConfigListScreen.__init__(self, self.cfglist, session)

        self["config"].onSelectionChanged.append(self.updateHelp)

        self.onLayoutFinish.append(self.finishLayout)

        self.onShown.append(self.checkForPinUsage)

        printl("", self, "C")

    #===========================================================================
    #
    #===========================================================================
    def finishLayout(self):
        printl("", self, "S")
        print "here"

        # first we set the pics for buttons
        self.setColorFunctionIcons()

        self.setKeyNames()

        printl("", self, "C")

    #===========================================================================
    #
    #===========================================================================
    def checkForPinUsage(self):
        printl("", self, "S")

        self.onShown = []

        if not self.authenticated:
            if self.current.protectSettings.value:
                self.session.openWithCallback(
                    self.askForPin,
                    InputBox,
                    title=_("Please enter the pincode!"),
                    type=Input.PIN)
            else:
                self.authenticated = True
                self.createSetup()
        else:
            self.createSetup()

        printl("", self, "C")

    #===============================================================
    #
    #===============================================================
    def askForPin(self, enteredPin):
        printl("", self, "S")

        if enteredPin is None:
            pass
        else:
            if int(enteredPin) == int(self.current.settingsPin.value):
                #self.session.open(MessageBox,"The pin was correct!", MessageBox.TYPE_INFO)
                self.authenticated = True
                self.createSetup()
            else:
                self.session.open(MessageBox,
                                  "The pin was wrong! Returning ...",
                                  MessageBox.TYPE_INFO)
                self.close()

        printl("", self, "C")

    #===========================================================================
    #
    #===========================================================================
    def createSetup(self):
        printl("", self, "S")

        separator = "".ljust(250, "_")

        self.cfglist = []
        ##
        self.cfglist.append(
            getConfigListEntry(
                _("General Settings ") + separator,
                config.plugins.dreamplex.about, _("-")))
        ##
        self.cfglist.append(
            getConfigListEntry(
                _(" > State"), self.current.state,
                _("Toggle state to on/off to show this server in lost or not.")
            ))
        self.cfglist.append(
            getConfigListEntry(
                _(" > Autostart"), self.current.autostart,
                _("Enter this server automatically on startup.")))
        self.cfglist.append(
            getConfigListEntry(_(" > Name"), self.current.name,
                               _("Simply a name for better overview")))
        self.cfglist.append(
            getConfigListEntry(
                _(" > Trailer"), self.current.loadExtraData,
                _("Enable trailer function. Only works with PlexPass or YYTrailer plugin."
                  )))

        ##
        self.cfglist.append(
            getConfigListEntry(
                _("Connection Settings ") + separator,
                config.plugins.dreamplex.about, _(" ")))
        ##
        self.cfglist.append(
            getConfigListEntry(
                _(" > Connection Type"), self.current.connectionType,
                _("Select your type how the box is reachable.")))

        if self.current.connectionType.value == "0" or self.current.connectionType.value == "1":  # IP or DNS
            self.cfglist.append(
                getConfigListEntry(
                    _(" > Local Authentication"), self.current.localAuth,
                    _("Use this if you secured your plex server in the settings."
                      )))
            if self.current.connectionType.value == "0":
                self.addIpSettings()
            else:
                self.cfglist.append(
                    getConfigListEntry(_(" >> DNS"), self.current.dns, _(" ")))
                self.cfglist.append(
                    getConfigListEntry(_(" >> Port"), self.current.port,
                                       _(" ")))
            if self.current.localAuth.value:
                self.addMyPlexSettings()

        elif self.current.connectionType.value == "2":  # MYPLEX
            self.addMyPlexSettings()

        ##
        self.cfglist.append(
            getConfigListEntry(
                _("Playback Settings ") + separator,
                config.plugins.dreamplex.about, _(" ")))
        ##

        self.cfglist.append(
            getConfigListEntry(_(" > Playback Type"),
                               self.current.playbackType, _(" ")))
        if self.current.playbackType.value == "0":
            self.useMappings = False

        elif self.current.playbackType.value == "1":
            self.useMappings = False
            self.cfglist.append(
                getConfigListEntry(
                    _(" >> Use universal Transcoder"),
                    self.current.universalTranscoder,
                    _("You need gstreamer_fragmented installed for this feature! Please check in System ... "
                      )))
            if not self.current.universalTranscoder.value:
                self.cfglist.append(
                    getConfigListEntry(
                        _(" >> Transcoding quality"), self.current.quality,
                        _("You need gstreamer_fragmented installed for this feature! Please check in System ... "
                          )))
                self.cfglist.append(
                    getConfigListEntry(
                        _(" >> Segmentsize in seconds"), self.current.segments,
                        _("You need gstreamer_fragmented installed for this feature! Please check in System ... "
                          )))
            else:
                self.cfglist.append(
                    getConfigListEntry(
                        _(" >> Transcoding quality"), self.current.uniQuality,
                        _("You need gstreamer_fragmented installed for this feature! Please check in System ... "
                          )))

        elif self.current.playbackType.value == "2":
            self.useMappings = True
            self.cfglist.append(
                getConfigListEntry(
                    _("> Search and use forced subtitles"),
                    self.current.useForcedSubtitles,
                    _("Monitor playback to activate subtitles automatically if needed. You have to enable subtitles with 'Text'-Buttion first."
                      )))

        elif self.current.playbackType.value == "3":
            self.useMappings = False
            #self.cfglist.append(getConfigListEntry(_(">> Username"), self.current.smbUser))
            #self.cfglist.append(getConfigListEntry(_(">> Password"), self.current.smbPassword))
            #self.cfglist.append(getConfigListEntry(_(">> Server override IP"), self.current.nasOverrideIp))
            #self.cfglist.append(getConfigListEntry(_(">> Servers root"), self.current.nasRoot))

        if self.current.playbackType.value == "2":
            ##
            self.cfglist.append(
                getConfigListEntry(
                    _("Subtitle Settings ") + separator,
                    config.plugins.dreamplex.about, _(" ")))
            ##
            self.cfglist.append(
                getConfigListEntry(
                    _(" >> Enable Subtitle renaming in direct local mode"),
                    self.current.srtRenamingForDirectLocal,
                    _("Renames filename.eng.srt automatically to filename.srt so e2 is able to read them."
                      )))
            if self.current.srtRenamingForDirectLocal.value:
                self.cfglist.append(
                    getConfigListEntry(
                        _(" >> Target subtitle language"),
                        self.current.subtitlesLanguage,
                        _("Search string that should be removed from srt file."
                          )))

        ##
        self.cfglist.append(
            getConfigListEntry(
                _("Wake On Lan Settings ") + separator,
                config.plugins.dreamplex.about, _(" ")))
        ##
        self.cfglist.append(
            getConfigListEntry(_(" > Use Wake on Lan (WoL)"), self.current.wol,
                               _(" ")))

        if self.current.wol.value:
            self.cfglist.append(
                getConfigListEntry(
                    _(" >> Mac address (Size: 12 alphanumeric no seperator) only for WoL"
                      ), self.current.wol_mac, _(" ")))
            self.cfglist.append(
                getConfigListEntry(
                    _(" >> Wait for server delay (max 180 seconds) only for WoL"
                      ), self.current.wol_delay, _(" ")))

        ##
        self.cfglist.append(
            getConfigListEntry(
                _("Sync Settings ") + separator,
                config.plugins.dreamplex.about, _(" ")))
        ##
        self.cfglist.append(
            getConfigListEntry(_(" > Sync Movies Medias"),
                               self.current.syncMovies,
                               _("Sync this content.")))
        self.cfglist.append(
            getConfigListEntry(_(" > Sync Shows Medias"),
                               self.current.syncShows,
                               _("Sync this content.")))
        self.cfglist.append(
            getConfigListEntry(_(" > Sync Music Medias"),
                               self.current.syncMusic,
                               _("Sync this content.")))

        self["config"].list = self.cfglist
        self["config"].l.setList(self.cfglist)

        if self.current.myplexHomeUsers.value:
            self.useHomeUsers = True
        else:
            self.useHomeUsers = False

        self.setKeyNames()

        printl("", self, "C")

    #===========================================================================
    #
    #===========================================================================
    def addIpSettings(self):
        printl("", self, "S")

        self.cfglist.append(
            getConfigListEntry(_(" >> IP"), self.current.ip, _(" ")))
        self.cfglist.append(
            getConfigListEntry(_(" >> Port"), self.current.port, _(" ")))

        printl("", self, "C")

    #===========================================================================
    #
    #===========================================================================
    def addMyPlexSettings(self):
        printl("", self, "S")

        self.cfglist.append(
            getConfigListEntry(
                _(" >> myPLEX URL"), self.current.myplexUrl,
                _("You need openSSL installed for this feature! Please check in System ..."
                  )))
        self.cfglist.append(
            getConfigListEntry(
                _(" >> myPLEX Username"), self.current.myplexUsername,
                _("You need openSSL installed for this feature! Please check in System ..."
                  )))
        self.cfglist.append(
            getConfigListEntry(
                _(" >> myPLEX Password"), self.current.myplexPassword,
                _("You need openSSL installed for this feature! Please check in System ..."
                  )))

        self.cfglist.append(
            getConfigListEntry(_(" >> myPLEX Home Users"),
                               self.current.myplexHomeUsers,
                               _("Use Home Users?")))
        if self.current.myplexHomeUsers.value:
            self.cfglist.append(
                getConfigListEntry(_(" >> Use Settings Protection"),
                                   self.current.protectSettings,
                                   _("Ask for pin?")))
            if self.current.protectSettings.value:
                self.cfglist.append(
                    getConfigListEntry(_(" >> Settings Pincode"),
                                       self.current.settingsPin,
                                       _("Pincode for changing settings")))

            self.cfglist.append(
                getConfigListEntry(
                    _(" >> myPLEX Pin Protection"),
                    self.current.myplexPinProtect,
                    _("Use Pinprotection for switch back to myPlex user?")))
            if self.current.myplexPinProtect.value:
                self.cfglist.append(
                    getConfigListEntry(
                        _(" >> myPLEX Pincode"), self.current.myplexPin,
                        _("Pincode for switching back from any home user.")))

        printl("", self, "C")

    #===========================================================================
    #
    #===========================================================================
    def updateHelp(self):
        printl("", self, "S")

        cur = self["config"].getCurrent()
        printl("cur: " + str(cur), self, "D")
        self["help"].setText(cur[2])  # = cur and cur[2] or ""

        printl("", self, "C")

    #===========================================================================
    #
    #===========================================================================
    def setKeyNames(self):
        printl("", self, "S")

        self["btn_greenText"].setText(_("Save"))

        if self.useMappings and self.newmode == 0:
            self["btn_yellowText"].setText(_("Mappings"))
            self["btn_yellowText"].show()
            self["btn_yellow"].show()
        elif self.current.localAuth.value:
            self["btn_yellowText"].setText(_("get local auth Token"))
            self["btn_yellowText"].show()
            self["btn_yellow"].show()
        else:
            self["btn_yellowText"].hide()
            self["btn_yellow"].hide()

        if (self.current.localAuth.value or self.current.connectionType.value
                == "2") and self.newmode == 0:
            if self.useHomeUsers:
                self["btn_redText"].setText(_("Home Users"))
                self["btn_redText"].show()
                self["btn_red"].show()
            else:
                self["btn_redText"].hide()
                self["btn_red"].hide()

            self["btn_blueText"].setText(_("(re)create myPlex Token"))

            self["btn_blueText"].show()
            self["btn_blue"].show()
        else:
            self["btn_redText"].hide()
            self["btn_red"].hide()
            self["btn_blueText"].hide()
            self["btn_blue"].hide()

        printl("", self, "C")

    #===========================================================================
    #
    #===========================================================================
    def keyLeft(self):
        printl("", self, "S")

        ConfigListScreen.keyLeft(self)
        self.createSetup()

        printl("", self, "C")

    #===========================================================================
    #
    #===========================================================================
    def keyRight(self):
        printl("", self, "S")

        ConfigListScreen.keyRight(self)
        self.createSetup()

        printl("", self, "C")

    #===========================================================================
    #
    #===========================================================================
    def keySave(self):
        printl("", self, "S")

        if self.newmode == 1:
            config.plugins.dreamplex.entriescount.value += 1
            config.plugins.dreamplex.entriescount.save()

        #if self.current.machineIdentifier.value == "":
        from DP_PlexLibrary import PlexLibrary
        self.plexInstance = Singleton().getPlexInstance(
            PlexLibrary(self.session, self.current))

        machineIdentifiers = ""

        if self.current.connectionType.value == "2":
            xmlResponse = self.plexInstance.getSharedServerForPlexUser()
            machineIdentifier = xmlResponse.get("machineIdentifier")
            if machineIdentifier is not None:
                machineIdentifiers += machineIdentifier

            servers = xmlResponse.findall("Server")
            for server in servers:
                machineIdentifier = server.get("machineIdentifier")
                if machineIdentifier is not None:
                    machineIdentifiers += ", " + machineIdentifier

        else:
            xmlResponse = self.plexInstance.getXmlTreeFromUrl(
                "http://" + str(self.plexInstance.g_host) + ":" +
                str(self.plexInstance.serverConfig_port))
            machineIdentifier = xmlResponse.get("machineIdentifier")

            if machineIdentifier is not None:
                machineIdentifiers += xmlResponse.get("machineIdentifier")

        self.current.machineIdentifier.value = machineIdentifiers
        printl(
            "machineIdentifier: " + str(self.current.machineIdentifier.value),
            self, "D")

        if self.current.connectionType.value == "2" or self.current.localAuth.value:
            self.keyBlue()
        else:
            self.saveNow()

        printl("", self, "C")

    #===========================================================================
    #
    #===========================================================================
    def saveNow(self, retval=None):
        printl("", self, "S")

        config.plugins.dreamplex.entriescount.save()
        config.plugins.dreamplex.Entries.save()
        config.plugins.dreamplex.save()
        configfile.save()

        self.close()

        printl("", self, "C")

    #===========================================================================
    #
    #===========================================================================
    def keyCancel(self):
        printl("", self, "S")

        if self.newmode == 1:
            config.plugins.dreamplex.Entries.remove(self.current)
        ConfigListScreen.cancelConfirm(self, True)

        printl("", self, "C")

    #===========================================================================
    #
    #===========================================================================
    def keyYellow(self):
        printl("", self, "S")

        if self.useMappings:
            serverID = self.currentId
            self.session.open(DPS_Mappings, serverID)

        elif self.current.localAuth.value:
            # now that we know the server we establish global plexInstance
            self.plexInstance = Singleton().getPlexInstance(
                PlexLibrary(self.session, self.current))

            ipInConfig = "%d.%d.%d.%d" % tuple(self.current.ip.value)
            token = self.plexInstance.getPlexUserTokenForLocalServerAuthentication(
                ipInConfig)

            if token:
                self.current.myplexLocalToken.value = token
                self.current.myplexLocalToken.save()
                self.session.open(
                    MessageBox,
                    (_("Local Token:") + "\n%s \n" + _("for the user:"******"\n%s") % (token, self.current.myplexTokenUsername.value),
                    MessageBox.TYPE_INFO)
            else:
                response = self.plexInstance.getLastResponse()
                self.session.open(
                    MessageBox,
                    (_("Error:") + "\n%s \n" + _("for the user:"******"\n%s") %
                    (response, self.current.myplexTokenUsername.value),
                    MessageBox.TYPE_INFO)

        printl("", self, "C")

    #===========================================================================
    #
    #===========================================================================
    def keyBlue(self):
        printl("", self, "S")

        # now that we know the server we establish global plexInstance
        self.plexInstance = Singleton().getPlexInstance(
            PlexLibrary(self.session, self.current))

        token = self.plexInstance.getNewMyPlexToken()

        if token:
            self.session.openWithCallback(
                self.saveNow, MessageBox,
                (_("myPlex Token:") + "\n%s \n" + _("for the user:"******"\n%s \n" + _("with the id:") + "\n%s") %
                (token, self.current.myplexTokenUsername.value,
                 self.current.myplexId.value), MessageBox.TYPE_INFO)
        else:
            response = self.plexInstance.getLastResponse()
            self.session.openWithCallback(
                self.saveNow, MessageBox,
                (_("Error:") + "\n%s \n" + _("for the user:"******"\n%s") %
                (response, self.current.myplexTokenUsername.value),
                MessageBox.TYPE_INFO)

        printl("", self, "C")

    #===========================================================================
    #
    #===========================================================================
    def keyRed(self):
        printl("", self, "S")

        if self.useHomeUsers:
            serverID = self.currentId
            plexInstance = Singleton().getPlexInstance(
                PlexLibrary(self.session, self.current))
            self.session.open(DPS_Users, serverID, plexInstance)

        #self.session.open(MessageBox,(_("myPlex Token:") + "\n%s \n" + _("myPlex Localtoken:") + "\n%s \n"+ _("for the user:"******"\n%s") % (self.current.myplexToken.value, self.current.myplexLocalToken.value, self.current.myplexTokenUsername.value), MessageBox.TYPE_INFO)

        printl("", self, "C")
Exemplo n.º 2
0
class DPS_ServerConfig(ConfigListScreen, Screen, DPH_PlexScreen):

	useMappings = False

	def __init__(self, session, entry, data = None):
		printl("", self, "S")

		Screen.__init__(self, session)

		self.guiElements = getGuiElements()

		self["actions"] = ActionMap(["DPS_ServerConfig", "ColorActions"],
		{
			"green": self.keySave,
			"cancel": self.keyCancel,
		    "exit": self.keyCancel,
			"yellow": self.keyYellow,
			"blue": self.keyBlue,
			"red": self.keyRed,
			"left": self.keyLeft,
			"right": self.keyRight,
		}, -2)

		self["help"] = StaticText()

		self["btn_redText"] = Label()
		self["btn_red"] = Pixmap()

		self["btn_greenText"] = Label()
		self["btn_green"] = Pixmap()

		self["btn_yellowText"] = Label()
		self["btn_yellow"] = Pixmap()

		self["btn_blueText"] = Label()
		self["btn_blue"] = Pixmap()

		if entry is None:
			self.newmode = 1
			self.current = initServerEntryConfig()
			if data is not None:
				ipBlocks = data.get("server").split(".")
				self.current.name.value = data.get("serverName")
				self.current.ip.value = [int(ipBlocks[0]),int(ipBlocks[1]),int(ipBlocks[2]),int(ipBlocks[3])]
				self.current.port.value = int(data.get("port"))
				self.keySave(True)

		else:
			self.newmode = 0
			self.current = entry
			self.currentId = self.current.id.value
			printl("currentId: " + str(self.currentId), self, "D")

		self.cfglist = []
		ConfigListScreen.__init__(self, self.cfglist, session)

		self.createSetup()

		self["config"].onSelectionChanged.append(self.updateHelp)

		self.onLayoutFinish.append(self.finishLayout)

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def finishLayout(self):
		printl("", self, "S")

		# first we set the pics for buttons
		self.setColorFunctionIcons()

		self.setKeyNames()

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def createSetup(self):
		printl("", self, "S")

		separator = "".ljust(90,"_")

		self.cfglist = []
		##
		self.cfglist.append(getConfigListEntry(_("General Settings") + separator, config.plugins.dreamplex.about, _("-")))
		##
		self.cfglist.append(getConfigListEntry(_(" > State"), self.current.state, _("Toggle state to on/off to show this server in lost or not.")))
		self.cfglist.append(getConfigListEntry(_(" > Autostart"), self.current.autostart, _("Enter this server automatically on startup.")))
		self.cfglist.append(getConfigListEntry(_(" > Name"), self.current.name, _(" ")))
		self.cfglist.append(getConfigListEntry(_(" > Trailer"), self.current.loadExtraData, _(" ")))

		##
		self.cfglist.append(getConfigListEntry(_("Connection Settings") + separator, config.plugins.dreamplex.about, _(" ")))
		##
		self.cfglist.append(getConfigListEntry(_(" > Connection Type"), self.current.connectionType, _(" ")))

		if self.current.connectionType.value == "0" or self.current.connectionType.value == "1": # IP or DNS
			self.cfglist.append(getConfigListEntry(_(" > Local Authentication"), self.current.localAuth, _(" ")))
			if self.current.connectionType.value == "0":
				self.addIpSettings()
			else:
				self.cfglist.append(getConfigListEntry(_(" >> DNS"), self.current.dns, _(" ")))
				self.cfglist.append(getConfigListEntry(_(" >> Port"), self.current.port, _(" ")))
			if self.current.localAuth.value:
				self.addMyPlexSettings()

		elif self.current.connectionType.value == "2": # MYPLEX
			self.addMyPlexSettings()

		##
		self.cfglist.append(getConfigListEntry(_("Playback Settings") + separator, config.plugins.dreamplex.about, _(" ")))
		##

		self.cfglist.append(getConfigListEntry(_(" > Playback Type"), self.current.playbackType, _(" ")))
		if self.current.playbackType.value == "0":
			self.useMappings = False

		elif self.current.playbackType.value == "1":
			self.useMappings = False
			self.cfglist.append(getConfigListEntry(_(" >> Use universal Transcoder"), self.current.universalTranscoder, _("You need gstreamer_fragmented installed for this feature! Please check in System ... ")))
			if not self.current.universalTranscoder.value:
				self.cfglist.append(getConfigListEntry(_(" >> Transcoding quality"), self.current.quality, _("You need gstreamer_fragmented installed for this feature! Please check in System ... ")))
				self.cfglist.append(getConfigListEntry(_(" >> Segmentsize in seconds"), self.current.segments, _("You need gstreamer_fragmented installed for this feature! Please check in System ... ")))
			else:
				self.cfglist.append(getConfigListEntry(_(" >> Transcoding quality"), self.current.uniQuality, _("You need gstreamer_fragmented installed for this feature! Please check in System ... ")))

		elif self.current.playbackType.value == "2":
			self.useMappings = True
			self.cfglist.append(getConfigListEntry(_("> Search and use forced subtitles"), self.current.useForcedSubtitles, _(" ")))

		elif self.current.playbackType.value == "3":
			self.useMappings = False
			#self.cfglist.append(getConfigListEntry(_(">> Username"), self.current.smbUser))
			#self.cfglist.append(getConfigListEntry(_(">> Password"), self.current.smbPassword))
			#self.cfglist.append(getConfigListEntry(_(">> Server override IP"), self.current.nasOverrideIp))
			#self.cfglist.append(getConfigListEntry(_(">> Servers root"), self.current.nasRoot))

		if self.current.playbackType.value == "2":
			##
			self.cfglist.append(getConfigListEntry(_("Subtitle Settings") + separator, config.plugins.dreamplex.about, _(" ")))
			##
			self.cfglist.append(getConfigListEntry(_(" >> Enable Subtitle renaming in direct local mode"), self.current.subtitlesForDirectLocal, _(" ")))
			if self.current.subtitlesForDirectLocal.value:
				self.cfglist.append(getConfigListEntry(_(" >> Target subtitle language"), self.current.subtitlesLanguage, _(" ")))

		##
		self.cfglist.append(getConfigListEntry(_("Wake On Lan Settings") + separator, config.plugins.dreamplex.about, _(" ")))
		##
		self.cfglist.append(getConfigListEntry(_(" > Use Wake on Lan (WoL)"), self.current.wol, _(" ")))

		if self.current.wol.value:
			self.cfglist.append(getConfigListEntry(_(" >> Mac address (Size: 12 alphanumeric no seperator) only for WoL"), self.current.wol_mac, _(" ")))
			self.cfglist.append(getConfigListEntry(_(" >> Wait for server delay (max 180 seconds) only for WoL"), self.current.wol_delay, _(" ")))

		##
		self.cfglist.append(getConfigListEntry(_("Sync Settings") + separator, config.plugins.dreamplex.about, _(" ")))
		##
		self.cfglist.append(getConfigListEntry(_(" > Sync Movies Medias"), self.current.syncMovies, _(" ")))
		self.cfglist.append(getConfigListEntry(_(" > Sync Shows Medias"), self.current.syncShows, _(" ")))
		self.cfglist.append(getConfigListEntry(_(" > Sync Music Medias"), self.current.syncMusic, _(" ")))

		#===================================================================
		#
		# getConfigListEntry(_("Transcode Type (no function yet but soon ;-)"), self.current.transcodeType),
		# getConfigListEntry(_("Quality (no function yet but soon ;-)"), self.current.quality),
		# getConfigListEntry(_("Audio Output (no function yet but soon ;-)"), self.current.audioOutput),
		# getConfigListEntry(_("Stream Mode (no function yet but soon ;-)"), self.current.streamMode),
		#===================================================================

		self["config"].list = self.cfglist
		self["config"].l.setList(self.cfglist)

		self.setKeyNames()

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def addIpSettings(self):
		printl("", self, "S")

		self.cfglist.append(getConfigListEntry(_(" >> IP"), self.current.ip, _(" ")))
		self.cfglist.append(getConfigListEntry(_(" >> Port"), self.current.port, _(" ")))

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def addMyPlexSettings(self):
		printl("", self, "S")

		self.cfglist.append(getConfigListEntry(_(" >> myPLEX URL"), self.current.myplexUrl, _("You need openSSL installed for this feature! Please check in System ...")))
		self.cfglist.append(getConfigListEntry(_(" >> myPLEX Username"), self.current.myplexUsername, _("You need openSSL installed for this feature! Please check in System ...")))
		self.cfglist.append(getConfigListEntry(_(" >> myPLEX Password"), self.current.myplexPassword, _("You need openSSL installed for this feature! Please check in System ...")))

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def updateHelp(self):
		printl("", self, "S")

		cur = self["config"].getCurrent()
		printl("cur: " + str(cur), self, "D")
		self["help"].setText(cur[2])# = cur and cur[2] or ""

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def setKeyNames(self):
		printl("", self, "S")

		self["btn_greenText"].setText(_("Save"))

		if self.useMappings and self.newmode == 0:
			self["btn_yellowText"].setText(_("Mappings"))
			self["btn_yellowText"].show()
			self["btn_yellow"].show()
		elif self.current.localAuth.value:
			self["btn_yellowText"].setText(_("get local auth Token"))
			self["btn_yellowText"].show()
			self["btn_yellow"].show()
		else:
			self["btn_yellowText"].hide()
			self["btn_yellow"].hide()

		if (self.current.localAuth.value or self.current.connectionType.value == "2") and self.newmode == 0:
			self["btn_redText"].setText(_("check myPlex Token"))
			self["btn_blueText"].setText(_("(re)create myPlex Token"))
			self["btn_redText"].show()
			self["btn_red"].show()
			self["btn_blueText"].show()
			self["btn_blue"].show()
		else:
			self["btn_redText"].hide()
			self["btn_red"].hide()
			self["btn_blueText"].hide()
			self["btn_blue"].hide()

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def keyLeft(self):
		printl("", self, "S")

		ConfigListScreen.keyLeft(self)
		self.createSetup()

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def keyRight(self):
		printl("", self, "S")

		ConfigListScreen.keyRight(self)
		self.createSetup()

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def keySave(self, stayOpen = False):
		printl("", self, "S")

		if self.newmode == 1:
			config.plugins.dreamplex.entriescount.value += 1
			config.plugins.dreamplex.entriescount.save()

		#if self.current.machineIdentifier.value == "":
		from DP_PlexLibrary import PlexLibrary
		self.plexInstance = Singleton().getPlexInstance(PlexLibrary(self.session, self.current))

		machineIdentifiers = ""

		if self.current.connectionType.value == "2":
			xmlResponse = self.plexInstance.getSharedServerForPlexUser()
			machineIdentifier = xmlResponse.get("machineIdentifier")
			if machineIdentifier is not None:
				machineIdentifiers += machineIdentifier

			servers = xmlResponse.findall("Server")
			for server in servers:
				machineIdentifier = server.get("machineIdentifier")
				if machineIdentifier is not None:
					machineIdentifiers += ", " + machineIdentifier

		else:
			xmlResponse = self.plexInstance.getXmlTreeFromUrl("http://" + self.plexInstance.g_currentServer)
			machineIdentifier = xmlResponse.get("machineIdentifier")
			if machineIdentifier is not None:
				machineIdentifiers += xmlResponse.get("machineIdentifier")

		self.current.machineIdentifier.value = machineIdentifiers
		printl("machineIdentifier: " + str(self.current.machineIdentifier.value), self, "D")

		config.plugins.dreamplex.entriescount.save()
		config.plugins.dreamplex.Entries.save()
		config.plugins.dreamplex.save()
		configfile.save()

		if not stayOpen:
			self.close()

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def keyCancel(self):
		printl("", self, "S")

		if self.newmode == 1:
			config.plugins.dreamplex.Entries.remove(self.current)
		ConfigListScreen.cancelConfirm(self, True)

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def keyYellow(self):
		printl("", self, "S")

		if self.useMappings:
			serverID = self.currentId
			self.session.open(DPS_Mappings, serverID)

		elif self.current.localAuth.value:
			# now that we know the server we establish global plexInstance
			self.plexInstance = Singleton().getPlexInstance(PlexLibrary(self.session, self.current))

			ipInConfig = "%d.%d.%d.%d" % tuple(self.current.ip.value)
			token = self.plexInstance.getPlexUserTokenForLocalServerAuthentication(ipInConfig)

			if token:
				self.current.myplexLocalToken.value = token
				self.current.myplexLocalToken.save()
				self.session.open(MessageBox,(_("Local Token:") + "\n%s \n" + _("for the user:"******"\n%s") % (token, self.current.myplexTokenUsername.value), MessageBox.TYPE_INFO)
			else:
				response = self.plexInstance.getLastResponse()
				self.session.open(MessageBox,(_("Error:") + "\n%s \n" + _("for the user:"******"\n%s") % (response, self.current.myplexTokenUsername.value), MessageBox.TYPE_INFO)

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def keyBlue(self):
		printl("", self, "S")

		# now that we know the server we establish global plexInstance
		self.plexInstance = Singleton().getPlexInstance(PlexLibrary(self.session, self.current))

		token = self.plexInstance.getNewMyPlexToken()

		if token:
			self.session.open(MessageBox,(_("myPlex Token:") + "\n%s \n" + _("for the user:"******"\n%s") % (token, self.current.myplexTokenUsername.value), MessageBox.TYPE_INFO)
		else:
			response = self.plexInstance.getLastResponse()
			self.session.open(MessageBox,(_("Error:") + "\n%s \n" + _("for the user:"******"\n%s") % (response, self.current.myplexTokenUsername.value), MessageBox.TYPE_INFO)

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def keyRed(self):
		printl("", self, "S")

		self.session.open(MessageBox,(_("myPlex Token:") + "\n%s \n" + _("myPlex Localtoken:") + "\n%s \n"+ _("for the user:"******"\n%s") % (self.current.myplexToken.value, self.current.myplexLocalToken.value, self.current.myplexTokenUsername.value), MessageBox.TYPE_INFO)

		printl("", self, "C")
Exemplo n.º 3
0
class DPS_ServerConfig(ConfigListScreen, Screen, DPH_PlexScreen):

    useMappings = False

    def __init__(self, session, entry, data=None):
        printl("", self, "S")

        self.session = session
        Screen.__init__(self, session)

        self.guiElements = getGuiElements()

        self["actions"] = ActionMap(
            ["DPS_ServerConfig", "ColorActions"],
            {
                "green": self.keySave,
                "cancel": self.keyCancel,
                "exit": self.keyCancel,
                "yellow": self.keyYellow,
                "blue": self.keyBlue,
                "red": self.keyRed,
                "left": self.keyLeft,
                "right": self.keyRight,
            },
            -2,
        )

        self["help"] = StaticText()

        self["btn_redText"] = Label()
        self["btn_red"] = Pixmap()

        self["btn_greenText"] = Label()
        self["btn_green"] = Pixmap()

        self["btn_yellowText"] = Label()
        self["btn_yellow"] = Pixmap()

        self["btn_blueText"] = Label()
        self["btn_blue"] = Pixmap()

        if entry is None:
            self.newmode = 1
            self.current = initServerEntryConfig()
            if data is not None:
                ipBlocks = data.get("server").split(".")
                self.current.name.value = data.get("serverName")
                self.current.ip.value = [int(ipBlocks[0]), int(ipBlocks[1]), int(ipBlocks[2]), int(ipBlocks[3])]
                self.current.port.value = int(data.get("port"))
                self.keySave(True)

        else:
            self.newmode = 0
            self.current = entry
            self.currentId = self.current.id.value
            printl("currentId: " + str(self.currentId), self, "D")

        self.cfglist = []
        ConfigListScreen.__init__(self, self.cfglist, session)

        self.createSetup()

        self["config"].onSelectionChanged.append(self.updateHelp)

        self.onLayoutFinish.append(self.finishLayout)

        printl("", self, "C")

        # ===========================================================================
        #
        # ===========================================================================

    def finishLayout(self):
        printl("", self, "S")

        # first we set the pics for buttons
        self.setColorFunctionIcons()

        self.setKeyNames()

        printl("", self, "C")

        # ===========================================================================
        #
        # ===========================================================================

    def createSetup(self):
        printl("", self, "S")

        separator = "".ljust(90, "_")

        self.cfglist = []
        ##
        self.cfglist.append(
            getConfigListEntry(_("General Settings") + separator, config.plugins.dreamplex.about, _("-"))
        )
        ##
        self.cfglist.append(
            getConfigListEntry(
                _(" > State"), self.current.state, _("Toggle state to on/off to show this server in lost or not.")
            )
        )
        self.cfglist.append(
            getConfigListEntry(
                _(" > Autostart"), self.current.autostart, _("Enter this server automatically on startup.")
            )
        )
        self.cfglist.append(getConfigListEntry(_(" > Name"), self.current.name, _(" ")))

        ##
        self.cfglist.append(
            getConfigListEntry(_("Connection Settings") + separator, config.plugins.dreamplex.about, _(" "))
        )
        ##
        self.cfglist.append(getConfigListEntry(_(" > Connection Type"), self.current.connectionType, _(" ")))

        if self.current.connectionType.value == "0" or self.current.connectionType.value == "1":  # IP or DNS
            self.cfglist.append(
                getConfigListEntry(
                    _(" > Local Authentication"),
                    self.current.localAuth,
                    _(
                        "For currentlyRunning feature just activate.\nFor section management you have to connect your server successfully to myPlex once.\nAfter that just disable your Portforwarding policy."
                    ),
                )
            )
            self.addIpSettings()
            if self.current.localAuth.value:
                self.addMyPlexSettings()

        elif self.current.connectionType.value == "1":  # DNS
            self.cfglist.append(getConfigListEntry(_(" >> DNS"), self.current.dns, _(" ")))
            self.cfglist.append(getConfigListEntry(_(" >> Port"), self.current.port, _(" ")))

        elif self.current.connectionType.value == "2":  # MYPLEX
            self.addMyPlexSettings()

            ##
        self.cfglist.append(
            getConfigListEntry(_("Playback Settings") + separator, config.plugins.dreamplex.about, _(" "))
        )
        ##

        self.cfglist.append(getConfigListEntry(_(" > Playback Type"), self.current.playbackType, _(" ")))
        if self.current.playbackType.value == "0":
            self.useMappings = False

        elif self.current.playbackType.value == "1":
            self.useMappings = False
            self.cfglist.append(
                getConfigListEntry(
                    _(" >> Use universal Transcoder"),
                    self.current.universalTranscoder,
                    _("You need gstreamer_fragmented installed for this feature! Please check in System ... "),
                )
            )
            if not self.current.universalTranscoder.value:
                self.cfglist.append(
                    getConfigListEntry(
                        _(" >> Transcoding quality"),
                        self.current.quality,
                        _("You need gstreamer_fragmented installed for this feature! Please check in System ... "),
                    )
                )
                self.cfglist.append(
                    getConfigListEntry(
                        _(" >> Segmentsize in seconds"),
                        self.current.segments,
                        _("You need gstreamer_fragmented installed for this feature! Please check in System ... "),
                    )
                )
            else:
                self.cfglist.append(
                    getConfigListEntry(
                        _(" >> Transcoding quality"),
                        self.current.uniQuality,
                        _("You need gstreamer_fragmented installed for this feature! Please check in System ... "),
                    )
                )

        elif self.current.playbackType.value == "2":
            printl("i am here", self, "D")
            self.useMappings = True

        elif self.current.playbackType.value == "3":
            self.useMappings = False
            # self.cfglist.append(getConfigListEntry(_(">> Username"), self.current.smbUser))
            # self.cfglist.append(getConfigListEntry(_(">> Password"), self.current.smbPassword))
            # self.cfglist.append(getConfigListEntry(_(">> Server override IP"), self.current.nasOverrideIp))
            # self.cfglist.append(getConfigListEntry(_(">> Servers root"), self.current.nasRoot))

            ##
        self.cfglist.append(
            getConfigListEntry(_("Wake On Lan Settings") + separator, config.plugins.dreamplex.about, _(" "))
        )
        ##
        self.cfglist.append(getConfigListEntry(_(" > Use Wake on Lan (WoL)"), self.current.wol, _(" ")))

        if self.current.wol.value:
            self.cfglist.append(
                getConfigListEntry(
                    _(" >> Mac address (Size: 12 alphanumeric no seperator) only for WoL"), self.current.wol_mac, _(" ")
                )
            )
            self.cfglist.append(
                getConfigListEntry(
                    _(" >> Wait for server delay (max 180 seconds) only for WoL"), self.current.wol_delay, _(" ")
                )
            )

            ##
        self.cfglist.append(getConfigListEntry(_("Sync Settings") + separator, config.plugins.dreamplex.about, _(" ")))
        ##
        self.cfglist.append(getConfigListEntry(_(" > Sync Movies Medias"), self.current.syncMovies, _(" ")))
        self.cfglist.append(getConfigListEntry(_(" > Sync Shows Medias"), self.current.syncShows, _(" ")))
        self.cfglist.append(getConfigListEntry(_(" > Sync Music Medias"), self.current.syncMusic, _(" ")))

        # ===================================================================
        #
        # getConfigListEntry(_("Transcode Type (no function yet but soon ;-)"), self.current.transcodeType),
        # getConfigListEntry(_("Quality (no function yet but soon ;-)"), self.current.quality),
        # getConfigListEntry(_("Audio Output (no function yet but soon ;-)"), self.current.audioOutput),
        # getConfigListEntry(_("Stream Mode (no function yet but soon ;-)"), self.current.streamMode),
        # ===================================================================

        self["config"].list = self.cfglist
        self["config"].l.setList(self.cfglist)

        self.setKeyNames()

        printl("", self, "C")

        # ===========================================================================
        #
        # ===========================================================================

    def addIpSettings(self):
        printl("", self, "S")

        self.cfglist.append(getConfigListEntry(_(" >> IP"), self.current.ip, _(" ")))
        self.cfglist.append(getConfigListEntry(_(" >> Port"), self.current.port, _(" ")))

        printl("", self, "C")

        # ===========================================================================
        #
        # ===========================================================================

    def addMyPlexSettings(self):
        printl("", self, "S")

        self.cfglist.append(
            getConfigListEntry(
                _(" >> myPLEX URL"),
                self.current.myplexUrl,
                _("You need openSSL installed for this feature! Please check in System ..."),
            )
        )
        self.cfglist.append(
            getConfigListEntry(
                _(" >> myPLEX Username"),
                self.current.myplexUsername,
                _("You need openSSL installed for this feature! Please check in System ..."),
            )
        )
        self.cfglist.append(
            getConfigListEntry(
                _(" >> myPLEX Password"),
                self.current.myplexPassword,
                _("You need openSSL installed for this feature! Please check in System ..."),
            )
        )

        printl("", self, "C")

        # ===========================================================================
        #
        # ===========================================================================

    def updateHelp(self):
        printl("", self, "S")

        cur = self["config"].getCurrent()
        printl("cur: " + str(cur), self, "D")
        self["help"].setText(cur[2])  # = cur and cur[2] or ""

        printl("", self, "C")

        # ===========================================================================
        #
        # ===========================================================================

    def setKeyNames(self):
        printl("", self, "S")

        self["btn_greenText"].setText(_("Save"))

        if self.useMappings and self.newmode == 0:
            self["btn_yellowText"].setText(_("Mappings"))
            self["btn_yellowText"].show()
            self["btn_yellow"].show()
        elif self.current.localAuth.value:
            self["btn_yellowText"].setText(_("get local auth Token"))
            self["btn_yellowText"].show()
            self["btn_yellow"].show()
        else:
            self["btn_yellowText"].hide()
            self["btn_yellow"].hide()

        if (self.current.localAuth.value or self.current.connectionType.value == "2") and self.newmode == 0:
            self["btn_redText"].setText(_("check myPlex Token"))
            self["btn_blueText"].setText(_("(re)create myPlex Token"))
            self["btn_redText"].show()
            self["btn_red"].show()
            self["btn_blueText"].show()
            self["btn_blue"].show()
        else:
            self["btn_redText"].hide()
            self["btn_red"].hide()
            self["btn_blueText"].hide()
            self["btn_blue"].hide()

        printl("", self, "C")

        # ===========================================================================
        #
        # ===========================================================================

    def keyLeft(self):
        printl("", self, "S")

        ConfigListScreen.keyLeft(self)
        self.createSetup()

        printl("", self, "C")

        # ===========================================================================
        #
        # ===========================================================================

    def keyRight(self):
        printl("", self, "S")

        ConfigListScreen.keyRight(self)
        self.createSetup()

        printl("", self, "C")

        # ===========================================================================
        #
        # ===========================================================================

    def keySave(self, stayOpen=False):
        printl("", self, "S")

        if self.newmode == 1:
            config.plugins.dreamplex.entriescount.value += 1
            config.plugins.dreamplex.entriescount.save()

        config.plugins.dreamplex.entriescount.save()
        config.plugins.dreamplex.Entries.save()
        config.plugins.dreamplex.save()
        configfile.save()

        if not stayOpen:
            self.close()

        printl("", self, "C")

        # ===========================================================================
        #
        # ===========================================================================

    def keyCancel(self):
        printl("", self, "S")

        if self.newmode == 1:
            config.plugins.dreamplex.Entries.remove(self.current)
        ConfigListScreen.cancelConfirm(self, True)

        printl("", self, "C")

        # ===========================================================================
        #
        # ===========================================================================

    def keyYellow(self):
        printl("", self, "S")

        if self.useMappings:
            serverID = self.currentId
            self.session.open(DPS_Mappings, serverID)

        elif self.current.localAuth.value:
            # now that we know the server we establish global plexInstance
            self.plexInstance = Singleton().getPlexInstance(PlexLibrary(self.session, self.current))

            ipInConfig = "%d.%d.%d.%d" % tuple(self.current.ip.value)
            token = self.plexInstance.getPlexUserTokenForLocalServerAuthentication(ipInConfig)

            if token:
                self.current.myplexLocalToken.value = token
                self.current.myplexLocalToken.save()
                self.session.open(
                    MessageBox,
                    (_("Local Token:") + "\n%s \n" + _("for the user:"******"\n%s")
                    % (token, self.current.myplexTokenUsername.value),
                    MessageBox.TYPE_INFO,
                )
            else:
                response = self.plexInstance.getLastResponse()
                self.session.open(
                    MessageBox,
                    (_("Error:") + "\n%s \n" + _("for the user:"******"\n%s")
                    % (response, self.current.myplexTokenUsername.value),
                    MessageBox.TYPE_INFO,
                )

        printl("", self, "C")

        # ===========================================================================
        #
        # ===========================================================================

    def keyBlue(self):
        printl("", self, "S")

        # now that we know the server we establish global plexInstance
        self.plexInstance = Singleton().getPlexInstance(PlexLibrary(self.session, self.current))

        token = self.plexInstance.getNewMyPlexToken()

        if token:
            self.session.open(
                MessageBox,
                (_("myPlex Token:") + "\n%s \n" + _("for the user:"******"\n%s")
                % (token, self.current.myplexTokenUsername.value),
                MessageBox.TYPE_INFO,
            )
        else:
            response = self.plexInstance.getLastResponse()
            self.session.open(
                MessageBox,
                (_("Error:") + "\n%s \n" + _("for the user:"******"\n%s")
                % (response, self.current.myplexTokenUsername.value),
                MessageBox.TYPE_INFO,
            )

        printl("", self, "C")

        # ===========================================================================
        #
        # ===========================================================================

    def keyRed(self):
        printl("", self, "S")

        self.session.open(
            MessageBox,
            (_("myPlex Token:") + "\n%s \n" + _("myPlex Localtoken:") + "\n%s \n" + _("for the user:"******"\n%s")
            % (
                self.current.myplexToken.value,
                self.current.myplexLocalToken.value,
                self.current.myplexTokenUsername.value,
            ),
            MessageBox.TYPE_INFO,
        )

        printl("", self, "C")
Exemplo n.º 4
0
class DPS_ServerConfig(ConfigListScreen, Screen, DPH_PlexScreen):

	useMappings = False
	useHomeUsers = False
	authenticated = False

	def __init__(self, session, entry, data = None):
		printl("", self, "S")

		Screen.__init__(self, session)

		self.guiElements = getGuiElements()

		self["actions"] = ActionMap(["DPS_ServerConfig", "ColorActions"],
		{
			"green": self.keySave,
			"cancel": self.keyCancel,
		    "exit": self.keyCancel,
			"yellow": self.keyYellow,
			"blue": self.keyBlue,
			"red": self.keyRed,
			"left": self.keyLeft,
			"right": self.keyRight,
		}, -2)

		self["help"] = StaticText()

		self["btn_redText"] = Label()
		self["btn_red"] = Pixmap()

		self["btn_greenText"] = Label()
		self["btn_green"] = Pixmap()

		self["btn_yellowText"] = Label()
		self["btn_yellow"] = Pixmap()

		self["btn_blueText"] = Label()
		self["btn_blue"] = Pixmap()

		if entry is None:
			self.newmode = 1
			self.current = initServerEntryConfig()
			if data is not None:
				ipBlocks = data.get("server").split(".")
				self.current.name.value = data.get("serverName")
				self.current.ip.value = [int(ipBlocks[0]),int(ipBlocks[1]),int(ipBlocks[2]),int(ipBlocks[3])]
				self.current.port.value = int(data.get("port"))

		else:
			self.newmode = 0
			self.current = entry
			self.currentId = self.current.id.value
			printl("currentId: " + str(self.currentId), self, "D")

		self.cfglist = []
		ConfigListScreen.__init__(self, self.cfglist, session)

		self["config"].onSelectionChanged.append(self.updateHelp)

		self.onLayoutFinish.append(self.finishLayout)

		self.onShown.append(self.checkForPinUsage)

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def finishLayout(self):
		printl("", self, "S")
		print "here"

		# first we set the pics for buttons
		self.setColorFunctionIcons()

		self.setKeyNames()

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def checkForPinUsage(self):
		printl("", self, "S")

		self.onShown = []

		if not self.authenticated:
			if self.current.protectSettings.value:
				self.session.openWithCallback(self.askForPin, InputBox, title=_("Please enter the pincode!") , type=Input.PIN)
			else:
				self.authenticated = True
				self.createSetup()
		else:
			self.createSetup()

		printl("", self, "C")

	#===============================================================
	#
	#===============================================================
	def askForPin(self, enteredPin):
		printl("", self, "S")

		if enteredPin is None:
			pass
		else:
			if int(enteredPin) == int(self.current.settingsPin.value):
				#self.session.open(MessageBox,"The pin was correct!", MessageBox.TYPE_INFO)
				self.authenticated = True
				self.createSetup()
			else:
				self.session.open(MessageBox,"The pin was wrong! Returning ...", MessageBox.TYPE_INFO)
				self.close()

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def createSetup(self):
		printl("", self, "S")

		separator = "".ljust(250,"_")

		self.cfglist = []
		##
		self.cfglist.append(getConfigListEntry(_("General Settings ") + separator, config.plugins.dreamplex.about, _("-")))
		##
		self.cfglist.append(getConfigListEntry(_(" > State"), self.current.state, _("Toggle state to on/off to show this server in lost or not.")))
		self.cfglist.append(getConfigListEntry(_(" > Autostart"), self.current.autostart, _("Enter this server automatically on startup.")))
		self.cfglist.append(getConfigListEntry(_(" > Name"), self.current.name, _("Simply a name for better overview")))
		self.cfglist.append(getConfigListEntry(_(" > Trailer"), self.current.loadExtraData, _("Enable trailer function. Only works with PlexPass or YYTrailer plugin.")))

		##
		self.cfglist.append(getConfigListEntry(_("Connection Settings ") + separator, config.plugins.dreamplex.about, _(" ")))
		##
		self.cfglist.append(getConfigListEntry(_(" > Connection Type"), self.current.connectionType, _("Select your type how the box is reachable.")))

		if self.current.connectionType.value == "0" or self.current.connectionType.value == "1": # IP or DNS
			self.cfglist.append(getConfigListEntry(_(" > Local Authentication"), self.current.localAuth, _("Use this if you secured your plex server in the settings.")))
			if self.current.connectionType.value == "0":
				self.addIpSettings()
			else:
				self.cfglist.append(getConfigListEntry(_(" >> DNS"), self.current.dns, _(" ")))
				self.cfglist.append(getConfigListEntry(_(" >> Port"), self.current.port, _(" ")))
			if self.current.localAuth.value:
				self.addMyPlexSettings()

		elif self.current.connectionType.value == "2": # MYPLEX
			self.addMyPlexSettings()

		##
		self.cfglist.append(getConfigListEntry(_("Playback Settings ") + separator, config.plugins.dreamplex.about, _(" ")))
		##

		self.cfglist.append(getConfigListEntry(_(" > Playback Type"), self.current.playbackType, _(" ")))
		if self.current.playbackType.value == "0":
			self.useMappings = False

		elif self.current.playbackType.value == "1":
			self.useMappings = False
			self.cfglist.append(getConfigListEntry(_(" >> Use universal Transcoder"), self.current.universalTranscoder, _("You need gstreamer_fragmented installed for this feature! Please check in System ... ")))
			if not self.current.universalTranscoder.value:
				self.cfglist.append(getConfigListEntry(_(" >> Transcoding quality"), self.current.quality, _("You need gstreamer_fragmented installed for this feature! Please check in System ... ")))
				self.cfglist.append(getConfigListEntry(_(" >> Segmentsize in seconds"), self.current.segments, _("You need gstreamer_fragmented installed for this feature! Please check in System ... ")))
			else:
				self.cfglist.append(getConfigListEntry(_(" >> Transcoding quality"), self.current.uniQuality, _("You need gstreamer_fragmented installed for this feature! Please check in System ... ")))

		elif self.current.playbackType.value == "2":
			self.useMappings = True
			self.cfglist.append(getConfigListEntry(_("> Search and use forced subtitles"), self.current.useForcedSubtitles, _("Monitor playback to activate subtitles automatically if needed. You have to enable subtitles with 'Text'-Buttion first.")))

		elif self.current.playbackType.value == "3":
			self.useMappings = False
			#self.cfglist.append(getConfigListEntry(_(">> Username"), self.current.smbUser))
			#self.cfglist.append(getConfigListEntry(_(">> Password"), self.current.smbPassword))
			#self.cfglist.append(getConfigListEntry(_(">> Server override IP"), self.current.nasOverrideIp))
			#self.cfglist.append(getConfigListEntry(_(">> Servers root"), self.current.nasRoot))

		if self.current.playbackType.value == "2":
			##
			self.cfglist.append(getConfigListEntry(_("Subtitle Settings ") + separator, config.plugins.dreamplex.about, _(" ")))
			##
			self.cfglist.append(getConfigListEntry(_(" >> Enable Subtitle renaming in direct local mode"), self.current.srtRenamingForDirectLocal, _("Renames filename.eng.srt automatically to filename.srt so e2 is able to read them.")))
			if self.current.srtRenamingForDirectLocal.value:
				self.cfglist.append(getConfigListEntry(_(" >> Target subtitle language"), self.current.subtitlesLanguage, _("Search string that should be removed from srt file.")))

		##
		self.cfglist.append(getConfigListEntry(_("Wake On Lan Settings ") + separator, config.plugins.dreamplex.about, _(" ")))
		##
		self.cfglist.append(getConfigListEntry(_(" > Use Wake on Lan (WoL)"), self.current.wol, _(" ")))

		if self.current.wol.value:
			self.cfglist.append(getConfigListEntry(_(" >> Mac address (Size: 12 alphanumeric no seperator) only for WoL"), self.current.wol_mac, _(" ")))
			self.cfglist.append(getConfigListEntry(_(" >> Wait for server delay (max 180 seconds) only for WoL"), self.current.wol_delay, _(" ")))

		##
		self.cfglist.append(getConfigListEntry(_("Sync Settings ") + separator, config.plugins.dreamplex.about, _(" ")))
		##
		self.cfglist.append(getConfigListEntry(_(" > Sync Movies Medias"), self.current.syncMovies, _("Sync this content.")))
		self.cfglist.append(getConfigListEntry(_(" > Sync Shows Medias"), self.current.syncShows, _("Sync this content.")))
		self.cfglist.append(getConfigListEntry(_(" > Sync Music Medias"), self.current.syncMusic, _("Sync this content.")))

		self["config"].list = self.cfglist
		self["config"].l.setList(self.cfglist)

		if self.current.myplexHomeUsers.value:
			self.useHomeUsers = True
		else:
			self.useHomeUsers = False

		self.setKeyNames()

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def addIpSettings(self):
		printl("", self, "S")

		self.cfglist.append(getConfigListEntry(_(" >> IP"), self.current.ip, _(" ")))
		self.cfglist.append(getConfigListEntry(_(" >> Port"), self.current.port, _(" ")))

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def addMyPlexSettings(self):
		printl("", self, "S")

		self.cfglist.append(getConfigListEntry(_(" >> myPLEX URL"), self.current.myplexUrl, _("You need openSSL installed for this feature! Please check in System ...")))
		self.cfglist.append(getConfigListEntry(_(" >> myPLEX Username"), self.current.myplexUsername, _("You need openSSL installed for this feature! Please check in System ...")))
		self.cfglist.append(getConfigListEntry(_(" >> myPLEX Password"), self.current.myplexPassword, _("You need openSSL installed for this feature! Please check in System ...")))

		self.cfglist.append(getConfigListEntry(_(" >> myPLEX Home Users"), self.current.myplexHomeUsers, _("Use Home Users?")))
		if self.current.myplexHomeUsers.value:
			self.cfglist.append(getConfigListEntry(_(" >> Use Settings Protection"), self.current.protectSettings, _("Ask for pin?")))
			if self.current.protectSettings.value:
				self.cfglist.append(getConfigListEntry(_(" >> Settings Pincode"), self.current.settingsPin, _("Pincode for changing settings")))

			self.cfglist.append(getConfigListEntry(_(" >> myPLEX Pin Protection"), self.current.myplexPinProtect, _("Use Pinprotection for switch back to myPlex user?")))
			if self.current.myplexPinProtect.value:
				self.cfglist.append(getConfigListEntry(_(" >> myPLEX Pincode"), self.current.myplexPin, _("Pincode for switching back from any home user.")))

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def updateHelp(self):
		printl("", self, "S")

		cur = self["config"].getCurrent()
		printl("cur: " + str(cur), self, "D")
		self["help"].setText(cur[2])# = cur and cur[2] or ""

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def setKeyNames(self):
		printl("", self, "S")

		self["btn_greenText"].setText(_("Save"))

		if self.useMappings and self.newmode == 0:
			self["btn_yellowText"].setText(_("Mappings"))
			self["btn_yellowText"].show()
			self["btn_yellow"].show()
		elif self.current.localAuth.value:
			self["btn_yellowText"].setText(_("get local auth Token"))
			self["btn_yellowText"].show()
			self["btn_yellow"].show()
		else:
			self["btn_yellowText"].hide()
			self["btn_yellow"].hide()

		if (self.current.localAuth.value or self.current.connectionType.value == "2") and self.newmode == 0:
			if self.useHomeUsers:
				self["btn_redText"].setText(_("Home Users"))
				self["btn_redText"].show()
				self["btn_red"].show()
			else:
				self["btn_redText"].hide()
				self["btn_red"].hide()

			self["btn_blueText"].setText(_("(re)create myPlex Token"))

			self["btn_blueText"].show()
			self["btn_blue"].show()
		else:
			self["btn_redText"].hide()
			self["btn_red"].hide()
			self["btn_blueText"].hide()
			self["btn_blue"].hide()

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def keyLeft(self):
		printl("", self, "S")

		ConfigListScreen.keyLeft(self)
		self.createSetup()

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def keyRight(self):
		printl("", self, "S")

		ConfigListScreen.keyRight(self)
		self.createSetup()

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def keySave(self):
		printl("", self, "S")

		if self.newmode == 1:
			config.plugins.dreamplex.entriescount.value += 1
			config.plugins.dreamplex.entriescount.save()

		#if self.current.machineIdentifier.value == "":
		from DP_PlexLibrary import PlexLibrary
		self.plexInstance = Singleton().getPlexInstance(PlexLibrary(self.session, self.current))

		machineIdentifiers = ""

		if self.current.connectionType.value == "2":
			xmlResponse = self.plexInstance.getSharedServerForPlexUser()
			machineIdentifier = xmlResponse.get("machineIdentifier")
			if machineIdentifier is not None:
				machineIdentifiers += machineIdentifier

			servers = xmlResponse.findall("Server")
			for server in servers:
				machineIdentifier = server.get("machineIdentifier")
				if machineIdentifier is not None:
					machineIdentifiers += ", " + machineIdentifier

		else:
			xmlResponse = self.plexInstance.getXmlTreeFromUrl("http://" + str(self.plexInstance.g_host) + ":" + str(self.plexInstance.serverConfig_port))
			machineIdentifier = xmlResponse.get("machineIdentifier")

			if machineIdentifier is not None:
				machineIdentifiers += xmlResponse.get("machineIdentifier")

		self.current.machineIdentifier.value = machineIdentifiers
		printl("machineIdentifier: " + str(self.current.machineIdentifier.value), self, "D")

		if self.current.connectionType.value == "2" or self.current.localAuth.value:
			self.keyBlue()
		else:
			self.saveNow()

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def saveNow(self, retval=None):
		printl("", self, "S")

		config.plugins.dreamplex.entriescount.save()
		config.plugins.dreamplex.Entries.save()
		config.plugins.dreamplex.save()
		configfile.save()

		self.close()

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def keyCancel(self):
		printl("", self, "S")

		if self.newmode == 1:
			config.plugins.dreamplex.Entries.remove(self.current)
		ConfigListScreen.cancelConfirm(self, True)

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def keyYellow(self):
		printl("", self, "S")

		if self.useMappings:
			serverID = self.currentId
			self.session.open(DPS_Mappings, serverID)

		elif self.current.localAuth.value:
			# now that we know the server we establish global plexInstance
			self.plexInstance = Singleton().getPlexInstance(PlexLibrary(self.session, self.current))

			ipInConfig = "%d.%d.%d.%d" % tuple(self.current.ip.value)
			token = self.plexInstance.getPlexUserTokenForLocalServerAuthentication(ipInConfig)

			if token:
				self.current.myplexLocalToken.value = token
				self.current.myplexLocalToken.save()
				self.session.open(MessageBox,(_("Local Token:") + "\n%s \n" + _("for the user:"******"\n%s") % (token, self.current.myplexTokenUsername.value), MessageBox.TYPE_INFO)
			else:
				response = self.plexInstance.getLastResponse()
				self.session.open(MessageBox,(_("Error:") + "\n%s \n" + _("for the user:"******"\n%s") % (response, self.current.myplexTokenUsername.value), MessageBox.TYPE_INFO)

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def keyBlue(self):
		printl("", self, "S")

		# now that we know the server we establish global plexInstance
		self.plexInstance = Singleton().getPlexInstance(PlexLibrary(self.session, self.current))

		token = self.plexInstance.getNewMyPlexToken()

		if token:
			self.session.openWithCallback(self.saveNow, MessageBox,(_("myPlex Token:") + "\n%s \n" + _("for the user:"******"\n%s \n" + _("with the id:") + "\n%s") % (token, self.current.myplexTokenUsername.value, self.current.myplexId.value), MessageBox.TYPE_INFO)
		else:
			response = self.plexInstance.getLastResponse()
			self.session.openWithCallback(self.saveNow, MessageBox,(_("Error:") + "\n%s \n" + _("for the user:"******"\n%s") % (response, self.current.myplexTokenUsername.value), MessageBox.TYPE_INFO)

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def keyRed(self):
		printl("", self, "S")

		if self.useHomeUsers:
			serverID = self.currentId
			plexInstance = Singleton().getPlexInstance(PlexLibrary(self.session, self.current))
			self.session.open(DPS_Users, serverID, plexInstance)

		#self.session.open(MessageBox,(_("myPlex Token:") + "\n%s \n" + _("myPlex Localtoken:") + "\n%s \n"+ _("for the user:"******"\n%s") % (self.current.myplexToken.value, self.current.myplexLocalToken.value, self.current.myplexTokenUsername.value), MessageBox.TYPE_INFO)

		printl("", self, "C")