from Components.SetupGuide.BaseStep import SetupListStep
from Plugins.SystemPlugins.SetPasswd.plugin import ChangePasswordScreen

class PasswordStep(SetupListStep):
	def __init__(self, parent):
		SetupListStep.__init__(self, parent)
		self._options = []

	def prepare(self):
		self.title = _("Password Setup")
		self.text = _("Activating password protection is very important for security if you enabled telnet sessions.\nDo you want to do this?")
		self._options = [
			(True, _("Yes")),
			(False, _("No"))
		]
		return True

	@property
	def listContent(self):
		return self._options

	def buildfunc(self, enabled, entry):
		return [entry,enabled]

	def onOk(self):
		lst = self.parent.list
		if not lst.current or not lst.current[0]:
			return True
		self.parent.session.openWithCallback(self._onPWSet, ChangePasswordScreen)
		return False

	def _onPWSet(self, result=False):
		self.parent.nextStep()
