Beispiel #1
0
class DPS_ServerMenu(DPH_Screen, DPH_HorizontalMenu, DPH_ScreenHelper, DPH_Filter, DPH_PlexScreen):

	g_horizontal_menu = False

	selectedEntry = None
	g_serverConfig = None

	g_serverDataMenu = None
	currentService = None
	plexInstance = None
	selectionOverride = None
	secondRun = False
	menuStep = 0 # vaule how many steps we made to restore navigation data
	currentMenuDataDict = {}
	currentIndexDict = {}
	isHomeUser = False

	#===========================================================================
	#
	#===========================================================================
	def __init__(self, session, g_serverConfig ):
		printl("", self, "S")
		DPH_Screen.__init__(self, session)
		DPH_ScreenHelper.__init__(self)
		DPH_Filter.__init__(self)
		DPH_PlexScreen.__init__(self)

		self.selectionOverride = None
		printl("selectionOverride:" +str(self.selectionOverride), self, "D")
		self.session = session

		self.g_serverConfig = g_serverConfig
		self.plexInstance = Singleton().getPlexInstance()
		self.guiElements = getGuiElements()

		self.initScreen("server_menu")
		self.initMenu()

		if self.g_horizontal_menu:
			self.setHorMenuElements(depth=2)
			self.translateNames()

		self["title"] = StaticText()

		self["menu"]= List(enableWrapAround=True)

		self["actions"] = HelpableActionMap(self, "DP_MainMenuActions",
			{
				"ok":		(self.okbuttonClick, ""),
				"left":		(self.left, ""),
				"right":	(self.right, ""),
				"up":		(self.up, ""),
				"down":		(self.down, ""),
				"cancel":	(self.cancel, ""),
			    "red":		(self.onKeyRed, ""),
			    "green":    (self.onKeyGreen, ""),
			}, -2)

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

		self["text_HomeUserLabel"]   = Label()
		self["text_HomeUser"]   = Label()

		self.onLayoutFinish.append(self.finishLayout)
		self.onLayoutFinish.append(self.getInitialData)
		self.onLayoutFinish.append(self.checkSelectionOverride)

		printl("", self, "C")

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

		self.setTitle(_("Server Menu"))

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

		if self.miniTv:
			self.initMiniTv()

		if self.g_serverConfig.myplexHomeUsers.value:
			self["btn_green"].show()
			self["btn_greenText"].setText(_("Switch User"))
			self["text_HomeUserLabel"].setText(_("Current User:"******"":
				self["text_HomeUser"].setText(self.g_serverConfig.myplexCurrentHomeUser.value)
				self.plexInstance.setAccessTokenHeader(self.plexInstance.g_currentServer, self.g_serverConfig.myplexCurrentHomeUserAccessToken.value)
			else:
				self["text_HomeUser"].setText(self.g_serverConfig.myplexTokenUsername.value)

		printl("", self, "C")

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

		self.getServerData()

		# save the mainMenuList for later usage
		self.menu_main_list = self["menu"].list

		if self.g_horizontal_menu:
			# init horizontal menu
			self.refreshOrientationHorMenu(0)

		printl("", self, "C")

	#===============================================================================
	#
	#===============================================================================
	def checkSelectionOverride(self):
		printl("", self, "S")
		printl("self.selectionOverride: " + str(self.selectionOverride), self, "D")

		if self.selectionOverride is not None:
			self.okbuttonClick()

		printl("", self, "C")

#===============================================================================
# KEYSTROKES
#===============================================================================

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

		self.session.open(DPS_Syncer, "sync", self.g_serverConfig,)

		printl("", self, "C")

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

		self.displayOptionsMenu()

		printl("", self, "C")

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

		functionList = []

		# add myPlex User as first one
		functionList.append((self.g_serverConfig.myplexTokenUsername.value, self.g_serverConfig.myplexPin.value, self.g_serverConfig.myplexToken.value, False, self.g_serverConfig.myplexId.value))

		# now add all home users
		self.homeUsersObject = DPS_Users(self.session, self.g_serverConfig.id.value, self.plexInstance)
		homeUsersFromServer = self.homeUsersObject["content"].getHomeUsersFromServer()

		if homeUsersFromServer is not None:
			for user in homeUsersFromServer.findall('user'):
				self.lastUserId = user.attrib.get("id")
				self.currentHomeUsername = user.attrib.get("username")
				self.currentPin = user.attrib.get("pin")
				self.currentHomeUserToken = user.attrib.get("token")

				functionList.append((self.currentHomeUsername, self.currentPin, self.currentHomeUserToken, True, self.lastUserId))

		self.session.openWithCallback(self.displayOptionsMenuCallback, ChoiceBox, title=_("Home Users"), list=functionList)

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def displayOptionsMenuCallback(self, choice):
		printl("", self, "S")

		if choice is None or choice[1] is None:
			printl("choice: None - we pressed exit", self, "D")
			return

		printl("choice: " + str(choice), self, "D")
		self.isHomeUser = choice[3]
		self.currentHomeUserId = choice[4]
		self.currentHomeUserPin = choice[1]

		if self.isHomeUser:
			if choice[1] != "":
				printl(choice[1], self, "D")
				self.session.openWithCallback(self.askForPin, InputBox, title=_("Please enter the pincode!") ,type=Input.PIN)
			else:
				self.switchUser()
		else:
			if self.g_serverConfig.myplexPinProtect.value:
				self.session.openWithCallback(self.askForPin, InputBox, title=_("Please enter the pincode!") , type=Input.PIN)
				self.currentPin = self.g_serverConfig.myplexPin.value
			else:
				self.switchUser()

		printl("", self, "C")

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

		# TODO add use saved values if we have no internet connection

		xmlResponse = self.plexInstance.switchHomeUser(self.currentHomeUserId, self.currentHomeUserPin)

		entryData = (dict(xmlResponse.items()))
		myId = entryData['id']
		token = entryData['authenticationToken']
		title = entryData['title']

		self.plexInstance.serverConfig_myplexToken = token
		accessToken = self.plexInstance.getPlexUserTokenForLocalServerAuthentication(self.plexInstance.g_host)

		if not accessToken:
			# we get all the restriction data from plex and not from the local server this means that if we ar not connected no data is coming to check, means no restction
			self.session.open(MessageBox,"No accessToken! Check plex.tv connection and plexPass status.", MessageBox.TYPE_INFO)
		else:
			self.g_serverConfig.myplexCurrentHomeUser.value = title
			self.g_serverConfig.myplexCurrentHomeUserAccessToken.value = accessToken
			self.g_serverConfig.myplexCurrentHomeUserId.value = myId
			self.g_serverConfig.save()

			self.plexInstance.setAccessTokenHeader(self.plexInstance.g_currentServer, accessToken)

			self["text_HomeUser"].setText(title)

		printl("", self, "C")

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

		if enteredPin is None:
			pass
		else:
			if int(enteredPin) == int(self.currentPin):
				self.session.open(MessageBox,"The pin was correct! Switching user.", MessageBox.TYPE_INFO)
				if self.isHomeUser:
					self.switchUser()
				else:
					self.switchUser()
			else:
				self.session.open(MessageBox,"The pin was wrong! Abort user switiching.", MessageBox.TYPE_INFO)

		printl("", self, "C")

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

		self.currentMenuDataDict[self.menuStep] = self.g_serverDataMenu
		printl("currentMenuDataDict: " + str(self.currentMenuDataDict), self, "D")

		# first of all we save the data from the current step
		self.currentIndexDict[self.menuStep] = self["menu"].getIndex()

		# now we increase the step value because we go to the next step
		self.menuStep += 1
		printl("menuStep: " + str(self.menuStep), self, "D")

		# this is used to step in directly into a server when there is only one entry in the serverlist
		if self.selectionOverride is not None:
			selection = self.selectionOverride

			# because we change the screen we have to unset the information to be able to return to main menu
			self.selectionOverride = None
		else:
			selection = self["menu"].getCurrent()

		printl("selection = " + str(selection), self, "D")

		if selection is not None and selection:

			self.selectedEntry = selection[1]
			printl("selected entry " + str(self.selectedEntry), self, "D")

			if type(self.selectedEntry) is int:
				printl("selected entry is int", self, "D")

				if self.selectedEntry == Plugin.MENU_MOVIES:
					printl("found Plugin.MENU_MOVIES", self, "D")
					self.getServerData("movies")

				elif self.selectedEntry == Plugin.MENU_TVSHOWS:
					printl("found Plugin.MENU_TVSHOWS", self, "D")
					self.getServerData("tvshow")

				elif self.selectedEntry == Plugin.MENU_MUSIC:
					printl("found Plugin.MENU_MUSIC", self, "D")
					self.getServerData("music")

				elif self.selectedEntry == Plugin.MENU_FILTER:
					printl("found Plugin.MENU_FILTER", self, "D")
					self.getFilterData(selection[3])

				elif self.selectedEntry == Plugin.MENU_SERVERFILTER:
					self.getServerData(filterBy=selection[3]['myCurrentFilterData'], serverFilterActive=selection[3]['serverName'])

			else:
				printl("selected entry is executable", self, "D")
				self.mediaType = selection[2]
				printl("mediaType: " + str(self.mediaType), self, "D")

				entryData = selection[3]
				printl("entryData: " + str(entryData), self, "D")

				hasPromptTag = entryData.get('hasPromptTag', False)
				printl("hasPromptTag: " + str(hasPromptTag), self, "D")
				if hasPromptTag:
					self.session.openWithCallback(self.addSearchString, DPS_InputBox, entryData, title=_("Please enter your search string: "), text=" " * 55, maxSize=55, type=Input.TEXT )
				else:
					self.menuStep -= 1
					self.executeSelectedEntry(entryData)

			self.refreshMenu()
		else:
			printl("no data, leaving ...", self, "D")
			self.cancel()

		printl("", self, "C")

	#===========================================================================
	#
	#===========================================================================
	def addSearchString(self, entryData, searchString = None):
		printl("", self, "S")
		printl("entryData: " + str(entryData), self, "D")

		if searchString is not None:
			if "origContentUrl" in entryData[0]:
				searchUrl = entryData[0]["origContentUrl"] + "&query=" + searchString
			else:
				searchUrl = entryData[0]["contentUrl"] + "&query=" + searchString
				entryData[0]["origContentUrl"] = entryData[0]["contentUrl"]

			printl("searchUrl: " + str(searchUrl), self, "D")

			entryData[0]["contentUrl"] = searchUrl

		self.executeSelectedEntry(entryData[0])

		printl("", self, "C")

	#===========================================================================
	# this function starts DP_Lib...
	#===========================================================================
	def executeSelectedEntry(self, entryData):
		printl("", self, "S")

		if self.selectedEntry.start is not None:
			printl("we are startable ...", self, "D")
			self.session.openWithCallback(self.myCallback, self.selectedEntry.start, entryData)

		elif self.selectedEntry.fnc is not None:
			printl("we are a function ...", self, "D")
			self.selectedEntry.fnc(self.session)

		if config.plugins.dreamplex.showFilter.value:
			self.selectedEntry = Plugin.MENU_FILTER # we overwrite this now to handle correct menu jumps with exit/cancel button

		printl("", self, "C")

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

		if not config.plugins.dreamplex.stopLiveTvOnStartup.value:
			self.session.nav.playService(getLiveTv(), forceRestart=True)

		printl("", self, "C")

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

		if self.g_horizontal_menu:
			self.left()
		else:
			self["menu"].selectPrevious()

		printl("", self, "C")

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

		if self.g_horizontal_menu:
			self.right()
		else:
			self["menu"].selectNext()

		printl("", self, "C")

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

		try:
			if self.g_horizontal_menu:
				self.refreshOrientationHorMenu(+1)
			else:
				self["menu"].pageDown()
		except Exception, ex:
			printl("Exception(" + str(type(ex)) + "): " + str(ex), self, "W")
			self["menu"].selectNext()

		printl("", self, "C")
Beispiel #2
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")
Beispiel #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")
Beispiel #4
0
class DPS_ServerMenu(DPH_Screen, DPH_HorizontalMenu, DPH_ScreenHelper, DPH_Filter, DPH_PlexScreen):

    g_horizontal_menu = False

    selectedEntry = None
    g_serverConfig = None

    g_serverDataMenu = None
    currentService = None
    plexInstance = None
    selectionOverride = None
    secondRun = False
    menuStep = 0  # vaule how many steps we made to restore navigation data
    currentMenuDataDict = {}
    currentIndexDict = {}
    isHomeUser = False

    # ===========================================================================
    #
    # ===========================================================================
    def __init__(self, session, g_serverConfig):
        printl("", self, "S")
        DPH_Screen.__init__(self, session)
        DPH_ScreenHelper.__init__(self)
        DPH_Filter.__init__(self)
        DPH_PlexScreen.__init__(self)

        self.selectionOverride = None
        printl("selectionOverride:" + str(self.selectionOverride), self, "D")
        self.session = session

        self.g_serverConfig = g_serverConfig
        self.plexInstance = Singleton().getPlexInstance()
        self.guiElements = getGuiElements()

        self.initScreen("server_menu")
        self.initMenu()

        if self.g_horizontal_menu:
            self.setHorMenuElements(depth=2)
            self.translateNames()

        self["title"] = StaticText()

        self["menu"] = List(enableWrapAround=True)

        self["actions"] = HelpableActionMap(
            self,
            "DP_MainMenuActions",
            {
                "ok": (self.okbuttonClick, ""),
                "left": (self.left, ""),
                "right": (self.right, ""),
                "up": (self.up, ""),
                "down": (self.down, ""),
                "cancel": (self.cancel, ""),
                "red": (self.onKeyRed, ""),
                "green": (self.onKeyGreen, ""),
            },
            -2,
        )

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

        self["text_HomeUserLabel"] = Label()
        self["text_HomeUser"] = Label()

        self.onLayoutFinish.append(self.finishLayout)
        self.onLayoutFinish.append(self.getInitialData)
        self.onLayoutFinish.append(self.checkSelectionOverride)

        printl("", self, "C")

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

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

        self.setTitle(_("Server Menu"))

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

        if self.miniTv:
            self.initMiniTv()

        if self.g_serverConfig.myplexHomeUsers.value:
            self["btn_green"].show()
            self["btn_greenText"].setText(_("Switch User"))
            self["text_HomeUserLabel"].setText(_("Current User:"******"":
                self["text_HomeUser"].setText(self.g_serverConfig.myplexCurrentHomeUser.value)
                self.plexInstance.setAccessTokenHeader(
                    self.plexInstance.g_currentServer, self.g_serverConfig.myplexCurrentHomeUserAccessToken.value
                )
            else:
                self["text_HomeUser"].setText(self.g_serverConfig.myplexTokenUsername.value)

        printl("", self, "C")

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

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

        self.getServerData()

        # save the mainMenuList for later usage
        self.menu_main_list = self["menu"].list

        if self.g_horizontal_menu:
            # init horizontal menu
            self.refreshOrientationHorMenu(0)

        printl("", self, "C")

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

    def checkSelectionOverride(self):
        printl("", self, "S")
        printl("self.selectionOverride: " + str(self.selectionOverride), self, "D")

        if self.selectionOverride is not None:
            self.okbuttonClick()

        printl("", self, "C")

    # ===============================================================================
    # KEYSTROKES
    # ===============================================================================

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

        self.session.open(DPS_Syncer, "sync", self.g_serverConfig)

        printl("", self, "C")

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

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

        self.displayOptionsMenu()

        printl("", self, "C")

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

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

        functionList = []

        # add myPlex User as first one
        functionList.append(
            (
                self.g_serverConfig.myplexTokenUsername.value,
                self.g_serverConfig.myplexPin.value,
                self.g_serverConfig.myplexToken.value,
                False,
                self.g_serverConfig.myplexId.value,
            )
        )

        # now add all home users
        self.homeUsersObject = DPS_Users(self.session, self.g_serverConfig.id.value, self.plexInstance)
        homeUsersFromServer = self.homeUsersObject["content"].getHomeUsersFromServer()

        if homeUsersFromServer is not None:
            for user in homeUsersFromServer.findall("user"):
                self.lastUserId = user.attrib.get("id")
                self.currentHomeUsername = user.attrib.get("username")
                self.currentPin = user.attrib.get("pin")
                self.currentHomeUserToken = user.attrib.get("token")

                functionList.append(
                    (self.currentHomeUsername, self.currentPin, self.currentHomeUserToken, True, self.lastUserId)
                )

        self.session.openWithCallback(
            self.displayOptionsMenuCallback, ChoiceBox, title=_("Home Users"), list=functionList
        )

        printl("", self, "C")

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

    def displayOptionsMenuCallback(self, choice):
        printl("", self, "S")

        if choice is None or choice[1] is None:
            printl("choice: None - we pressed exit", self, "D")
            return

        printl("choice: " + str(choice), self, "D")
        self.isHomeUser = choice[3]
        self.currentHomeUserId = choice[4]
        self.currentHomeUserPin = choice[1]

        if self.isHomeUser:
            if choice[1] != "":
                printl(choice[1], self, "D")
                self.session.openWithCallback(
                    self.askForPin, InputBox, title=_("Please enter the pincode!"), type=Input.PIN
                )
            else:
                self.switchUser()
        else:
            if self.g_serverConfig.myplexPinProtect.value:
                self.session.openWithCallback(
                    self.askForPin, InputBox, title=_("Please enter the pincode!"), type=Input.PIN
                )
                self.currentPin = self.g_serverConfig.myplexPin.value
            else:
                self.switchUser()

        printl("", self, "C")

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

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

        # TODO add use saved values if we have no internet connection

        xmlResponse = self.plexInstance.switchHomeUser(self.currentHomeUserId, self.currentHomeUserPin)

        entryData = dict(xmlResponse.items())
        myId = entryData["id"]
        token = entryData["authenticationToken"]
        title = entryData["title"]

        self.plexInstance.serverConfig_myplexToken = token
        accessToken = self.plexInstance.getPlexUserTokenForLocalServerAuthentication(self.plexInstance.g_host)

        if not accessToken:
            # we get all the restriction data from plex and not from the local server this means that if we ar not connected no data is coming to check, means no restction
            self.session.open(
                MessageBox, "No accessToken! Check plex.tv connection and plexPass status.", MessageBox.TYPE_INFO
            )
        else:
            self.g_serverConfig.myplexCurrentHomeUser.value = title
            self.g_serverConfig.myplexCurrentHomeUserAccessToken.value = accessToken
            self.g_serverConfig.myplexCurrentHomeUserId.value = myId
            self.g_serverConfig.save()

            self.plexInstance.setAccessTokenHeader(self.plexInstance.g_currentServer, accessToken)

            self["text_HomeUser"].setText(title)

        printl("", self, "C")

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

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

        if enteredPin is None:
            pass
        else:
            if int(enteredPin) == int(self.currentPin):
                self.session.open(MessageBox, "The pin was correct! Switching user.", MessageBox.TYPE_INFO)
                if self.isHomeUser:
                    self.switchUser()
                else:
                    self.switchUser()
            else:
                self.session.open(MessageBox, "The pin was wrong! Abort user switiching.", MessageBox.TYPE_INFO)

        printl("", self, "C")

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

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

        self.currentMenuDataDict[self.menuStep] = self.g_serverDataMenu
        printl("currentMenuDataDict: " + str(self.currentMenuDataDict), self, "D")

        # first of all we save the data from the current step
        self.currentIndexDict[self.menuStep] = self["menu"].getIndex()

        # now we increase the step value because we go to the next step
        self.menuStep += 1
        printl("menuStep: " + str(self.menuStep), self, "D")

        # this is used to step in directly into a server when there is only one entry in the serverlist
        if self.selectionOverride is not None:
            selection = self.selectionOverride

            # because we change the screen we have to unset the information to be able to return to main menu
            self.selectionOverride = None
        else:
            selection = self["menu"].getCurrent()

        printl("selection = " + str(selection), self, "D")

        if selection is not None and selection:

            self.selectedEntry = selection[1]
            printl("selected entry " + str(self.selectedEntry), self, "D")

            if type(self.selectedEntry) is int:
                printl("selected entry is int", self, "D")

                if self.selectedEntry == Plugin.MENU_MOVIES:
                    printl("found Plugin.MENU_MOVIES", self, "D")
                    self.getServerData("movies")

                elif self.selectedEntry == Plugin.MENU_TVSHOWS:
                    printl("found Plugin.MENU_TVSHOWS", self, "D")
                    self.getServerData("tvshow")

                elif self.selectedEntry == Plugin.MENU_MUSIC:
                    printl("found Plugin.MENU_MUSIC", self, "D")
                    self.getServerData("music")

                elif self.selectedEntry == Plugin.MENU_FILTER:
                    printl("found Plugin.MENU_FILTER", self, "D")
                    self.getFilterData(selection[3])

                elif self.selectedEntry == Plugin.MENU_SERVERFILTER:
                    self.getServerData(
                        filterBy=selection[3]["myCurrentFilterData"], serverFilterActive=selection[3]["serverName"]
                    )

            else:
                printl("selected entry is executable", self, "D")
                self.mediaType = selection[2]
                printl("mediaType: " + str(self.mediaType), self, "D")

                entryData = selection[3]
                printl("entryData: " + str(entryData), self, "D")

                hasPromptTag = entryData.get("hasPromptTag", False)
                printl("hasPromptTag: " + str(hasPromptTag), self, "D")
                if hasPromptTag:
                    self.session.openWithCallback(
                        self.addSearchString,
                        DPS_InputBox,
                        entryData,
                        title=_("Please enter your search string: "),
                        text=" " * 55,
                        maxSize=55,
                        type=Input.TEXT,
                    )
                else:
                    self.menuStep -= 1
                    self.executeSelectedEntry(entryData)

            self.refreshMenu()
        else:
            printl("no data, leaving ...", self, "D")
            self.cancel()

        printl("", self, "C")

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

    def addSearchString(self, entryData, searchString=None):
        printl("", self, "S")
        printl("entryData: " + str(entryData), self, "D")

        if searchString is not None:
            if "origContentUrl" in entryData[0]:
                searchUrl = entryData[0]["origContentUrl"] + "&query=" + searchString
            else:
                searchUrl = entryData[0]["contentUrl"] + "&query=" + searchString
                entryData[0]["origContentUrl"] = entryData[0]["contentUrl"]

            printl("searchUrl: " + str(searchUrl), self, "D")

            entryData[0]["contentUrl"] = searchUrl

        self.executeSelectedEntry(entryData[0])

        printl("", self, "C")

        # ===========================================================================
        # this function starts DP_Lib...
        # ===========================================================================

    def executeSelectedEntry(self, entryData):
        printl("", self, "S")

        if self.selectedEntry.start is not None:
            printl("we are startable ...", self, "D")
            self.session.openWithCallback(self.myCallback, self.selectedEntry.start, entryData)

        elif self.selectedEntry.fnc is not None:
            printl("we are a function ...", self, "D")
            self.selectedEntry.fnc(self.session)

        if config.plugins.dreamplex.showFilter.value:
            self.selectedEntry = (
                Plugin.MENU_FILTER
            )  # we overwrite this now to handle correct menu jumps with exit/cancel button

        printl("", self, "C")

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

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

        if not config.plugins.dreamplex.stopLiveTvOnStartup.value:
            self.session.nav.playService(getLiveTv(), forceRestart=True)

        printl("", self, "C")

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

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

        if self.g_horizontal_menu:
            self.left()
        else:
            self["menu"].selectPrevious()

        printl("", self, "C")

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

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

        if self.g_horizontal_menu:
            self.right()
        else:
            self["menu"].selectNext()

        printl("", self, "C")

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

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

        try:
            if self.g_horizontal_menu:
                self.refreshOrientationHorMenu(+1)
            else:
                self["menu"].pageDown()
        except Exception, ex:
            printl("Exception(" + str(type(ex)) + "): " + str(ex), self, "W")
            self["menu"].selectNext()

        printl("", self, "C")
Beispiel #5
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")
Beispiel #6
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")