def keySave(self):
		# Check field configuration
		fieldname = []
		fieldicon = []
		fieldprogress = []
		text = ""
		for i, c in enumerate( config.infobartunerstate.fields.dict().itervalues() ):
			if c.value == "Name":
				fieldname.append( i )
			if c.value == "TypeIcon":
				fieldicon.append( i )
			if c.value == "TimerProgressGraphical":
				fieldprogress.append( i )
		
		if len(fieldname) > 1:
			text += _("Only one Name field allowed:") + "\n" \
							+ "\n".join(["Field " + (str(f)) for f in fieldname])
		
		if len(fieldicon) > 1:
			text += _("Only one Icon field allowed:") + "\n" \
							+ "\n".join(["Field " + (str(f)) for f in fieldicon])
		
		if len(fieldprogress) > 1:
			if text: text += "\n\n"
			text += _("Only one Graphical Progress field allowed:") + "\n" \
							+ "\n".join(["Field " + (str(f)) for f in fieldprogress])
		
		if text:
			self.session.open(MessageBox, text, MessageBox.TYPE_ERROR, 3)
			return
		
		# Now save all
		self.saveAll()
		
		# Overwrite Screen close function to handle new config
		
		# We need assign / "write" access import the plugin module
		# global won't work across module scope
		import plugin
		if config.infobartunerstate.enabled.value:
			# Plugin should be enabled
			#TODO use a separate init function similar to the close
			if plugin.gInfoBarTunerState:
				# Plugin is active - close it
				plugin.gInfoBarTunerState.close()
			
			# Force new instance
			plugin.gInfoBarTunerState = InfoBarTunerState(self.session)
			
			if plugin.gInfoBarTunerState:
				
				# Handle InfoBar overwrite
				if config.infobartunerstate.show_overwrite.value:
					overwriteInfoBar()
				else:
					recoverInfoBar()
				
				# Handle extension menu integration
				if config.infobartunerstate.extensions_menu_show.value or config.infobartunerstate.extensions_menu_setup.value:
					# Add to extension menu
					addExtension()
				else:
					# Remove from extension menu
					removeExtension()
				
				# Handle show with InfoBar
				if config.infobartunerstate.show_infobar.value:
					plugin.gInfoBarTunerState.bindInfoBar()
				else:
					plugin.gInfoBarTunerState.unbindInfoBar()
				
				#TODO actually not possible to do this, because these events provides the relevant information
				#if config.infobartunerstate.show_events.value:
				#	plugin.gInfoBarTunerState.appendEvents()
				#else:
				#	plugin.gInfoBarTunerState.removeEvents()
				
				# Remove and append because of show streams handling
				plugin.gInfoBarTunerState.removeEvents()
				plugin.gInfoBarTunerState.appendEvents()
				
				# Check for actual events
				plugin.gInfoBarTunerState.updateRecordTimer()
				if config.infobartunerstate.show_streams.value:
					plugin.gInfoBarTunerState.updateStreams()
		else:
			# Plugin should be disabled
			if plugin.gInfoBarTunerState:
				# Plugin is active, disable it
				plugin.gInfoBarTunerState.close()

		self.close()
    def keySave(self):
        # Check field configuration
        fieldname = []
        fieldicon = []
        fieldprogress = []
        text = ""
        for i, c in enumerate(
                config.infobartunerstate.fields.dict().itervalues()):
            if c.value == "Name":
                fieldname.append(i)
            if c.value == "TypeIcon":
                fieldicon.append(i)
            if c.value == "TimerProgressGraphical":
                fieldprogress.append(i)

        if len(fieldname) > 1:
            text += _("Only one Name field allowed:") + "\n" \
                + "\n".join(["Field " + (str(f)) for f in fieldname])

        if len(fieldicon) > 1:
            text += _("Only one Icon field allowed:") + "\n" \
                + "\n".join(["Field " + (str(f)) for f in fieldicon])

        if len(fieldprogress) > 1:
            if text: text += "\n\n"
            text += _("Only one Graphical Progress field allowed:") + "\n" \
                + "\n".join(["Field " + (str(f)) for f in fieldprogress])

        if text:
            self.session.open(MessageBox, text, MessageBox.TYPE_ERROR, 3)
            return

        # Now save all
        self.saveAll()

        # Overwrite Screen close function to handle new config

        # We need assign / "write" access import the plugin module
        # global won't work across module scope
        import plugin
        if config.infobartunerstate.enabled.value:
            # Plugin should be enabled
            #TODO use a separate init function similar to the close
            if plugin.gInfoBarTunerState:
                # Plugin is active - close it
                plugin.gInfoBarTunerState.close()

            # Force new instance
            plugin.gInfoBarTunerState = InfoBarTunerState(self.session)

            if plugin.gInfoBarTunerState:

                # Handle InfoBar overwrite
                if config.infobartunerstate.show_overwrite.value:
                    overwriteInfoBar()
                else:
                    recoverInfoBar()

                # Handle extension menu integration
                if config.infobartunerstate.extensions_menu_show.value or config.infobartunerstate.extensions_menu_setup.value:
                    # Add to extension menu
                    addExtension()
                else:
                    # Remove from extension menu
                    removeExtension()

                # Handle show with InfoBar
                if config.infobartunerstate.show_infobar.value:
                    plugin.gInfoBarTunerState.bindInfoBar()
                else:
                    plugin.gInfoBarTunerState.unbindInfoBar()

                #TODO actually not possible to do this, because these events provides the relevant information
                #if config.infobartunerstate.show_events.value:
                #	plugin.gInfoBarTunerState.appendEvents()
                #else:
                #	plugin.gInfoBarTunerState.removeEvents()

                # Remove and append because of show streams handling
                plugin.gInfoBarTunerState.removeEvents()
                plugin.gInfoBarTunerState.appendEvents()

                # Check for actual events
                plugin.gInfoBarTunerState.updateRecordTimer()
                if config.infobartunerstate.show_streams.value:
                    plugin.gInfoBarTunerState.updateStreams()
        else:
            # Plugin should be disabled
            if plugin.gInfoBarTunerState:
                # Plugin is active, disable it
                plugin.gInfoBarTunerState.close()

        self.close()
	def close(self):
		# Check field configuration
		fieldicon = []
		fieldprogress = []
		text = ""
		for i, c in enumerate( config.infobartunerstate.fields.dict().itervalues() ):
			if c.value == "TypeIcon":
				fieldicon.append( i )
			if c.value == "TimerProgressGraphical":
				fieldprogress.append( i )
		
		if len(fieldicon) > 1:
			text += _("Only one Icon field allowed:") + "\n" \
							+ "\n".join(["Field " + (str(f)) for f in fieldicon])
		
		if len(fieldprogress) > 1:
			if text: text += "\n\n"
			text += _("Only one Graphical Progress field allowed:") + "\n" \
							+ "\n".join(["Field " + (str(f)) for f in fieldprogress])
		
		if text:
			self.session.open(MessageBox, text, MessageBox.TYPE_ERROR, 3)
			return
		
		# Overwrite Screen close function to handle new config
		from Plugins.Extensions.InfoBarTunerState.plugin import gInfoBarTunerState
		global gInfoBarTunerState
		if config.infobartunerstate.enabled.value:
			# Plugin should be enabled
			#TODO use a separate init function similar to the close
			if not gInfoBarTunerState:
				# Plugin is not active - enable it
				gInfoBarTunerState = InfoBarTunerState(self.session)
			
			if gInfoBarTunerState:
				
				# Handle InfoBar overwrite
				if config.infobartunerstate.show_overwrite.value:
					overwriteInfoBar()
				else:
					recoverInfoBar()
				
				# Handle extension menu integration
				if config.infobartunerstate.extensions_menu.value:
					# Add to extension menu
					addExtension()
				else:
					# Remove from extension menu
					removeExtension()
				
				# Handle show with InfoBar
				if config.infobartunerstate.show_infobar.value:
					gInfoBarTunerState.bindInfoBar()
				else:
					gInfoBarTunerState.unbindInfoBar()
				
				#TODO actually not possible to do this, because these events provides the relevant information
				#if config.infobartunerstate.show_events.value:
				#	gInfoBarTunerState.appendEvents()
				#else:
				#	gInfoBarTunerState.removeEvents()
				
				# Remove and append because of show streams handling
				gInfoBarTunerState.removeEvents()
				gInfoBarTunerState.appendEvents()
				
				# Check for actual events
				gInfoBarTunerState.updateRecordTimer()
				if config.infobartunerstate.show_streams.value:
					gInfoBarTunerState.updateStreams()
		else:
			# Plugin should be disabled
			if gInfoBarTunerState:
				# Plugin is active, disable it
				gInfoBarTunerState.close()
		
		# Call baseclass function
		Screen.close(self)