Пример #1
0
class BrowserMenu(Screen):
	ACTION_BOOKMARK = 0
	ACTION_COOKIES = 1
	ACTION_STORAGE_PATH = 2

	MENU_BOOKMARKS = 0
	MENU_SETTINGS = 1
	MENU_HISTORY = 2
	MENU_DOWNLOADS = 3
	MENU_CERTS = 4
	MENU_COOKIES = 5

	size = getDesktop(0).size()
	width = int(size.width() * 0.9)
	height = int(size.height() * 0.85)
	bof = height - 35 #Button-Offset

	skin = """
		<screen name="BrowserMenu" position="center,center" size="%(w)d,%(h)d" title="Web Browser - Menu" >
			<widget name="menu" position="0,0" zPosition="1" size="200,%(h)d" backgroundColor="#000000" transparent="1" />
			<widget source="line" render="Canvas" position="203,0" zPosition="2" size="4,%(h)d" backgroundColor="#000000" transparent="1" alphatest="on"/>
			<widget source="list" render="Listbox" position="210,0" zPosition="1" size="%(listW)d,%(listH)d" backgroundColor="#000000" transparent="1">
				<convert type="TemplatedMultiContent">
					{"templates":
						{"default": (55, [
							MultiContentEntryText(pos = (10, 1), size = (920, 25), font = 0, flags = RT_VALIGN_CENTER, text = 1),
							MultiContentEntryText(pos = (10, 30), size = (920, 25), font = 1, flags = RT_VALIGN_CENTER, text = 2),
						]),
						"history": (55, [
							MultiContentEntryText(pos = (10, 1), size = (150, 25), font = 1, flags = RT_VALIGN_CENTER, text = 1),
							MultiContentEntryText(pos = (10, 28), size = (150, 25), font = 1, flags = RT_VALIGN_CENTER, text = 2),
							MultiContentEntryText(pos = (190, 1), size = (690, 25), font = 0, flags = RT_VALIGN_CENTER, text = 3),
							MultiContentEntryText(pos = (190, 28), size = (690, 25), font = 1, flags = RT_VALIGN_CENTER, text = 4),
						]),
						"downloads": (25, [
							MultiContentEntryText(pos = (0, 1), size = (600, 24), font=1, flags = RT_HALIGN_LEFT, text = 1),
							MultiContentEntryText(pos = (610, 1), size = (150, 24), font=1, flags = RT_HALIGN_RIGHT, text = 2),
							MultiContentEntryProgress(pos = (760, 1), size = (100, 24), percent = 3),
							MultiContentEntryText(pos = (870, 1), size = (70, 24), font=1, flags = RT_HALIGN_RIGHT, text = 4),
						]),
						"certificates": (85, [
							MultiContentEntryText(pos = (10, 1), size = (150, 25), font = 1, flags = RT_VALIGN_CENTER, text = 1),
							MultiContentEntryText(pos = (10, 28), size = (150, 25), font = 1, flags = RT_VALIGN_CENTER, text = 2),
							MultiContentEntryText(pos = (190, 1), size = (690, 25), font = 0, flags = RT_VALIGN_CENTER, text = 3),
							MultiContentEntryText(pos = (190, 28), size = (690, 25), font = 1, flags = RT_VALIGN_CENTER, text = 4),
							MultiContentEntryText(pos = (10, 60), size = (900, 25), font = 0, flags = RT_VALIGN_CENTER, text = 5),
						]),
						"cookies": (75, [
							MultiContentEntryText(pos = (10, 1), size = (150, 25), font = 1, flags = RT_VALIGN_CENTER, text = 1),
							MultiContentEntryText(pos = (10, 28), size = (150, 25), font = 1, flags = RT_VALIGN_CENTER, text = 2),
							MultiContentEntryText(pos = (180, 1), size = (720, 25), font = 0, flags = RT_VALIGN_CENTER, text = 3),
							MultiContentEntryText(pos = (180, 28), size = (625, 25), font = 1, flags = RT_VALIGN_CENTER, text = 4),
							MultiContentEntryText(pos = (10, 60), size = (900, 15), font = 2, flags = RT_VALIGN_CENTER, text = 5),
						])
						},
					"fonts": [gFont("Regular", 22), gFont("Regular", 16), gFont("Regular", 13)]
					}
				</convert>
			</widget>
			<widget name="statuslabel" position="210,%(inputY)d" size="%(listW)d,25" font="Regular;20"  zPosition="2" halign="center" valign="center" backgroundColor="#000000" transparent="0" />
			<widget name="input" position="210,%(inputY)d" zPosition="1" size="%(listW)d,25" font="Regular;20" halign="left" valign="bottom" backgroundColor="#000000" transparent="1"/>
			<widget name="config" position="210,0" zPosition="2" size="%(listW)d,%(configH)d" backgroundColor="background" transparent="0" />

			<ePixmap pixmap="skin_default/buttons/button_red_off.png" position="210,%(btnY)d" size="15,16" alphatest="on" />
			<widget source="button_red" zPosition="2" render="Pixmap" pixmap="skin_default/buttons/button_red.png" position="210,%(btnY)d" size="15,16" alphatest="on">
				<convert type="ConditionalShowHide" />
			</widget>
			<widget name="red" position="230,%(btnTxtY)d" size="100,20" foregroundColor="white" backgroundColor="background" font="Regular;18" transparent="1" halign="left" valign="top"/>

			<ePixmap pixmap="skin_default/buttons/button_green_off.png" position="340,%(btnY)d" size="15,16" zPosition="1" alphatest="on" />
			<widget source="button_green" zPosition="2" render="Pixmap" pixmap="skin_default/buttons/button_green.png" position="340,%(btnY)d" size="15,16" alphatest="on">
				<convert type="ConditionalShowHide" />
			</widget>
			<widget name="green" position="360,%(btnTxtY)d" size="100,20" foregroundColor="white" backgroundColor="background" font="Regular;18" transparent="1" halign="left" valign="top"/>

			<ePixmap pixmap="skin_default/buttons/button_yellow_off.png" position="470,%(btnY)d" size="15,16" alphatest="on" />
			<widget source="button_yellow" zPosition="2" render="Pixmap" pixmap="skin_default/buttons/button_yellow.png" position="470,%(btnY)d" size="15,16" alphatest="on">
				<convert type="ConditionalShowHide" />
			</widget>
			<widget name="yellow" position="490,%(btnTxtY)d" size="100,20" foregroundColor="white" backgroundColor="background" font="Regular;18" transparent="1" halign="left" valign="top"/>

			<ePixmap pixmap="skin_default/buttons/button_blue_off.png" position="600,%(btnY)d" size="15,16" alphatest="on" />
			<widget source="button_blue" zPosition="2" render="Pixmap" pixmap="skin_default/buttons/button_blue.png" position="600,%(btnY)d" size="15,16" alphatest="on">
				<convert type="ConditionalShowHide" />
			</widget>
			<widget name="blue" position="620,%(btnTxtY)d" size="200,20" foregroundColor="white" backgroundColor="background" font="Regular;18" transparent="1" halign="left" valign="top"/>
		</screen>
		""" %{ 	"w" : width,
				"h" : height,
				"listW" : width - 210, "listH" : height - 90,
				"inputY" : height - 80,
				"configH" : height - 90,
				"btnY" : bof + 2,
				"btnTxtY" : bof
			}

	def __init__(self, session, currentTitle, currentUrl, menulist = None):
		Screen.__init__(self, session)

		self.currentUrl = currentUrl
		self.currentTitle = currentTitle

		#Menu
		if menulist is None:
			self.menu = MenuList([
						(_("Bookmarks"), self.MENU_BOOKMARKS),
						(_("History"), self.MENU_HISTORY),
						(_("Downloads"), self.MENU_DOWNLOADS),
						(_("Certificates"), self.MENU_CERTS),
						(_("Cookies"), self.MENU_COOKIES),
						(_("Settings"), self.MENU_SETTINGS),
				], enableWrapAround = True)
		else:
			self.menu = MenuList(menulist, enableWrapAround=True)
		self["menu"] = self.menu

		self["statuslabel"] = Label("")
		self["statuslabel"].hide()

		#Color Buttons
		self["button_red"] = Boolean(False)
		self["button_green"] = Boolean(False)
		self["button_yellow"] = Boolean(False)
		self["button_blue"] = Boolean(False)
		self.red = Label("")
		self.green = Label("")
		self.yellow = Label("")
		self.blue = Label("")
		self["red"] = self.red
		self["green"] = self.green
		self["yellow"] = self.yellow
		self["blue"] = self.blue

		#Lists
		self.detailList = List([], enableWrapAround = True)
		self.detailConfigList = ConfigList([])
		self.detailConfigList.l.setSeperation( (BrowserMenu.width - 210) / 2 )
		config.plugins.WebBrowser.storage.enabled.addNotifier(self.__cfgExpandableElementChanged, initial_call = False)
		config.plugins.WebBrowser.storage.enabled.addNotifier(self.__cfgStoragePathChanged, initial_call = False)
		config.plugins.WebBrowser.storage.path.addNotifier(self.__cfgStoragePathChanged, initial_call = False)

		self.detailInput = EnhancedInput()

		self["list"] = self.detailList
		self["config"] = self.detailConfigList
		self["input"] = self.detailInput
		self["line"] = CanvasSource()

		self.__cfgCreateSetup()

		self.__db = BrowserDB.getInstance()
		self.__curMenu = self.MENU_BOOKMARKS
		self.__bmList = None
		self.__hisList = None
		self.__crtList = None
		self.__ckList = None
		self.__bmNeedle = ""
		self.__bmFilterTimer = eTimer()
		self.__bmFilterTimer_conn = self.__bmFilterTimer.timeout.connect(self.__bmFilterCB)
		self.__hisNeedle = ""
		self.__hisFilterTimer = eTimer()
		self.__hisFilterTimer_conn = self.__hisFilterTimer.timeout.connect(self.__hisFilterCB)
		self.__dlRefreshTimer = eTimer()
		self.__dlRefreshTimer_conn = self.__dlRefreshTimer.timeout.connect(self.__dlBuildList)
		self.__statusTimer = eTimer()
		self.__statusTimer_conn = self.__statusTimer.timeout.connect(self.__hideStatus)
		self.__actions = []

		self.onFirstExecBegin.append(self.__drawSeparator)
		self.onFirstExecBegin.append(self.__onMenuChanged)
		self.onExecBegin.append(self.__reloadData)
		self.onShow.append(self.setKeyboardModeAscii)

		self["actions"] = ActionMap(["BrowserActions", "ColorActions"],
		{
			"ok" : self.__actionOk,
			"enter" : self.__actionOk,
			"exit" : self.__actionExit,
			"pageUp" : self.__actionMenuUp,
			"pageDown" : self.__actionMenuDown,
			"up" : boundFunction(self.__action, "up"),
			"down" : boundFunction(self.__action, "down"),
			"left" : boundFunction(self.__action, "left"),
			"right" : boundFunction(self.__action, "right"),
			"red" : boundFunction(self.__action, "red"),
			"green" : boundFunction(self.__action, "green"),
			"yellow" : boundFunction(self.__action, "yellow"),
			"blue" : boundFunction(self.__action, "blue"),
			"backspace" : boundFunction(self.__action, "backspace"),
			"delete" : boundFunction(self.__action, "delete"),
			"ascii": boundFunction(self.__action, "ascii"),
			# TODO "text" : self.__text
		}, -2)

		self["numberactions"] = NumberActionMap(["NumberActions"],
		{
			"1": self.__keyNumberGlobal,
			"2": self.__keyNumberGlobal,
			"3": self.__keyNumberGlobal,
			"4": self.__keyNumberGlobal,
			"5": self.__keyNumberGlobal,
			"6": self.__keyNumberGlobal,
			"7": self.__keyNumberGlobal,
			"8": self.__keyNumberGlobal,
			"9": self.__keyNumberGlobal,
			"0": self.__keyNumberGlobal
		}, -2)

		self.__actionFuncs = {
			self.MENU_BOOKMARKS : {
				"up" : self.detailList.selectPrevious,
				"down" : self.detailList.selectNext,
				"left" : self.detailList.selectPrevious,
				"right" : self.detailList.pageDown,
				"ok" : self.__bmOk,
				"enter" : self.__bmOk,
				"red" : self.__bmDelete,
				"green" : self.__bmAdd,
				"yellow" : self.__bmEdit,
				"blue" : self.__bmSetCurrentAsHome,
				"backspace" : self.__bmKeyBackspace,
				"delete" : self.__bmKeyDelete,
				"ascii": self.__bmKeyAscii,
				},
			self.MENU_HISTORY : {
				"up" : self.detailList.selectPrevious,
				"down" : self.detailList.selectNext,
				"left" : self.detailList.pageUp,
				"right" : self.detailList.pageDown,
				"ok" : self.__hisOk,
				"enter" : self.__hisOk,
				"red" : self.__hisClear,
				"blue" : self.__hisSetCurrentAsHome,
				"backspace" : self.__hisKeyBackspace,
				"delete" : self.__hisKeyDelete,
				"ascii": self.__hisKeyAscii,
				},
			self.MENU_SETTINGS : {
				"up" : self.__cfgKeyUp,
				"down" : self.__cfgKeyDown,
				"left" : self.__cfgKeyLeft,
				"right" : self.__cfgKeyRight,
				"ok" : self.__cfgKeyOK,
				"enter" : self.__cfgKeyOK,
				"red" : self.__cfgCancel,
				"green" : self.__cfgSave,
				"backspace" : self.__cfgKeyBackspace,
				"delete" : self.__cfgKeyDelete,
				"ascii": self.__cfgKeyAscii,
				},
			self.MENU_DOWNLOADS : {
				"up" : self.detailList.selectPrevious,
				"down" : self.detailList.selectNext,
				"left" : self.detailList.pageUp,
				"right" : self.detailList.pageDown,
				"red" : self.__dlAbort,
				},
			self.MENU_CERTS : {
				"up" : self.detailList.selectPrevious,
				"down" : self.detailList.selectNext,
				"left" : self.detailList.pageUp,
				"right" : self.detailList.pageDown,
				"red" : self.__crtDelete,
				"green" : self.__crtDetails,
				},
			self.MENU_COOKIES : {
				"up" : self.detailList.selectPrevious,
				"down" : self.detailList.selectNext,
				"left" : self.detailList.pageUp,
				"right" : self.detailList.pageDown,
				"red" : self.__ckDelete,
				"blue" : self.__ckDeleteAll,
				}
		}

	def _close(self):
		config.plugins.WebBrowser.storage.enabled.removeNotifier(self.__cfgExpandableElementChanged)
		config.plugins.WebBrowser.storage.enabled.removeNotifier(self.__cfgStoragePathChanged)
		config.plugins.WebBrowser.storage.path.removeNotifier(self.__cfgStoragePathChanged)
		self.close(self.__actions)

	def __actionOk(self):
		if self["statuslabel"].visible:
			self["statuslabel"].hide()
		else:
			self.__action("ok")

	def __actionExit(self):
		if self["statuslabel"].visible:
			self["statuslabel"].hide()
		else:
			if self.detailConfigList.isChanged():
				self.__cfgSave()
			self._close()

	def __actionMenuUp(self):
		self.menu.up()
		self.__onMenuChanged()

	def __actionMenuDown(self):
		self.menu.down()
		self.__onMenuChanged()

	def __reloadData(self):
		self.__bmList = self.__db.getBookmarks()
		self.__hisList = self.__db.getHistory()
		self.__crtList = self.__db.getCerts()
		self.__ckList = self.__db.getCookies()

	def __action(self, action):
		print "[BrowserMenu].__action :: action='%s'" %action
		fnc = self.__actionFuncs[self.__curMenu].get(action, None)
		if fnc != None:
			fnc()

	def __text(self):
		if self.__curMenu == self.MENU_SETTINGS:
			self.__cfgKeyText()
		elif self.__curMenu == self.MENU_BOOKMARKS:
			pass

	def __keyNumberGlobal(self, number):
		if self.__curMenu == self.MENU_SETTINGS:
			self.__cfgKeyNumberGlobal(number)
		elif self.__curMenu == self.MENU_BOOKMARKS:
			self.__bmKeyNumberGlobal(number)
		elif self.__curMenu == self.MENU_HISTORY:
			self.__hisKeyNumberGlobal(number)

	def __onMenuChanged(self):
		self.__bmFilterTimer.stop()
		self.__hisFilterTimer.stop()
		self.__dlRefreshTimer.stop()

		self.__curMenu = self.menu.getCurrent()[1]
		if self.__curMenu == self.MENU_BOOKMARKS:
			self.__showMenuList(True)
			self.__setButtons(_("Delete"), _("Add"), _("Edit"), _("Set as Startpage"))
			self.detailList.style = "default"
			self.__bmBuildList()
			self.detailInput.setText(self.__bmNeedle)
		elif self.__curMenu == self.MENU_HISTORY:
			self.__showMenuList(True)
			self.__setButtons(_("Clear"), "", "", _("Set as Startpage"))
			self.detailList.style = "history"
			self.__hisBuildList()
			self.detailInput.setText(self.__hisNeedle)
		elif self.__curMenu == self.MENU_SETTINGS:
			self.__showConfigList()
			self.__setButtons(_("Cancel"), _("Save"), "", "")
		elif self.__curMenu == self.MENU_DOWNLOADS:
			self.__showMenuList()
			self.__setButtons(_("Abort"), "", "", "")
			self.detailList.style = "downloads"
			self.__dlBuildList()
		elif self.__curMenu == self.MENU_CERTS:
			self.__showMenuList()
			self.__setButtons(_("Delete"), _("Details"), "", "")
			self.detailList.style = "certificates"
			self.__crtBuildList()
		elif self.__curMenu == self.MENU_COOKIES:
			self.__showMenuList()
			self.__setButtons(_("Delete"), "", "", _("Delete All"))
			self.detailList.style = "cookies"
			self.__ckBuildList()

	def __setButtons(self, red, green, yellow, blue):
		self.red.setText(red)
		self.__setButtonPixmapVisible(self["button_red"], red)
		self.green.setText(green)
		self.__setButtonPixmapVisible(self["button_green"], green)
		self.yellow.setText(yellow)
		self.__setButtonPixmapVisible(self["button_yellow"], yellow)
		self.blue.setText(blue)
		self.__setButtonPixmapVisible(self["button_blue"], blue)

	def __setButtonPixmapVisible(self, B, label):
		show = True
		if label == "":
			show = False
		B.setBoolean(show)

	def __showMenuList(self, hasFilter = False):
		if self.detailConfigList.visible:
			self.detailConfigList.hide()

# 		if not self.detailList.instance.visible:
# 			self.detailList.instance.show()
		if hasFilter:
			self.detailInput.show()
		else:
			self.detailInput.hide()

	def __showConfigList(self):
# 		if self.detailList.instance.visible == 1:
# 			self.detailList.instance.hide()
		self.detailInput.hide()
		if self.detailConfigList.visible == 0:
			self.detailConfigList.show()

	def __drawSeparator(self):
		self["line"].fill(0, 0, 4, BrowserMenu.height, 0xFF9900)
		self["line"].flush()

	def __setStatus(self, text):
		print "[BrowserMenu].__setStatus"
		self["statuslabel"].setText(text)
		self["statuslabel"].show()
		self.__statusTimer.startLongTimer(3)

	def __hideStatus(self):
		self["statuslabel"].hide()
		self.__statusTimer.stop()

	# Config List Methods
	def __cfgCreateSetup(self):
		list = [
			getConfigListEntry(_("Home Page"), config.plugins.WebBrowser.home),
			getConfigListEntry(_("Page to load on startup"), config.plugins.WebBrowser.startPage),
			getConfigListEntry(_("Search Provider"), config.plugins.WebBrowser.searchProvider),
			getConfigListEntry(_("Run fullscreen"), config.plugins.WebBrowser.fullscreen),
			getConfigListEntry(_("Offset in scroll mode (px)"), config.plugins.WebBrowser.scrollOffset),
			getConfigListEntry(_("Target directory for downloads"), config.plugins.WebBrowser.downloadpath),
			getConfigListEntry(_("Enable persistent storage"), config.plugins.WebBrowser.storage.enabled),
		]
		if config.plugins.WebBrowser.storage.enabled.value:
			list.append(getConfigListEntry(_("Path for persistent storage"), config.plugins.WebBrowser.storage.path))

		self.detailConfigList.setList(list)

	def __cfgExpandableElementChanged(self, element):
		self.__cfgCreateSetup()

	def __cfgSave(self):
		for x in self.detailConfigList.list:
			x[1].save()
		self.__setStatus(_("Settings have been saved successfully!"))

	def __cfgStoragePathChanged(self, element):
		action = [self.ACTION_STORAGE_PATH,True]
		if not action in self.__actions:
			self.__actions.append(action)

	def __cfgCancel(self):
		dlg = self.session.openWithCallback(self.__cfgCancelCB, MessageBox, _("Do you really want to discard all changes?"), type = MessageBox.TYPE_YESNO)
		dlg.setTitle(_("Discard changed settings?"))

	def __cfgCancelCB(self, confirmed):
		for x in self.detailConfigList.list:
			x[1].cancel()
		self.__setStatus(_("All changes to the settings have been discarded!"))

	def __cfgKeyText(self):
		from Screens.VirtualKeyBoard import VirtualKeyBoard
		self.session.openWithCallback(self.__cfgVirtualKeyBoardCallback, VirtualKeyBoard, title = self.detailConfigList.getCurrent()[0], text = self.detailConfigList.getCurrent()[1].getValue())

	def __cfgVirtualKeyBoardCallback(self, callback = None):
		if callback is not None and len(callback):
			self.detailConfigList.getCurrent()[1].setValue(callback)
			self.detailConfigList.invalidate(self.detailConfigList.getCurrent())

	def  __cfgKeyOK(self):
		self.detailConfigList.handleKey(KEY_OK)

	def  __cfgKeyUp(self):
		self.detailConfigList.instance.moveSelection(eListbox.moveUp)

	def  __cfgKeyDown(self):
		self.detailConfigList.instance.moveSelection(eListbox.moveDown)

	def  __cfgKeyLeft(self):
		self.detailConfigList.handleKey(KEY_LEFT)

	def __cfgKeyRight(self):
		self.detailConfigList.handleKey(KEY_RIGHT)

	def __cfgKeyHome(self):
		self.detailConfigList.handleKey(KEY_HOME)

	def __cfgKeyEnd(self):
		self.detailConfigList.handleKey(KEY_END)

	def __cfgKeyDelete(self):
		self.detailConfigList.handleKey(KEY_DELETE)

	def __cfgKeyBackspace(self):
		self.detailConfigList.handleKey(KEY_BACKSPACE)

	def __cfgKeyToggleOW(self):
		self.detailConfigList.handleKey(KEY_TOGGLEOW)

	def __cfgKeyAscii(self):
		self.detailConfigList.handleKey(KEY_ASCII)

	def __cfgKeyNumberGlobal(self, number):
		self.detailConfigList.handleKey(KEY_0 + number)

	#Bookmark List Methods
	def __bmOk(self):
		print "[BrowserMenu].__bmOk"
		if self.detailList.index > 0 and  self.detailList.getCurrent() != None:
			current = self.detailList.getCurrent()[0]
			print "[BrowserMenu].__bmOk, current = '%s'" %current
			self.__actions.append( (self.ACTION_BOOKMARK, current.url) )
			self.close( self.__actions )
		else:
			self.__bmAdd(Bookmark(-1, self.currentTitle, self.currentUrl))

	def __bmAdd(self, bookmark = None):
		self.session.openWithCallback(self.__bmEditCB, BookmarkEditor, bookmark)

	def __bmEdit(self):
		if self.detailList.index > 0 and  self.detailList.getCurrent() != None:
			cur = self.detailList.getCurrent()[0]
			self.session.openWithCallback(self.__bmEditCB, BookmarkEditor, cur)

	def __bmEditCB(self, bookmark):
		if bookmark != None:
			self.__db.setBookmark(bookmark)
			self.__bmReload()
			self.__setStatus(_("Bookmark '%s' saved succesfully!" %bookmark.name))

	def __bmDelete(self):
		if self.detailList.getCurrent() != None:
			name = self.detailList.getCurrent()[0].name
			print "[BrowserMenu].__bmDelete, name='%s'" %name
			dlg = self.session.openWithCallback( self.__bmDeleteCB, MessageBox, _("Do you really want to delete the bookmark '%s'?") %name, type = MessageBox.TYPE_YESNO )
			dlg.setTitle(_("Delete Bookmark?"))

	def __bmDeleteCB(self, confirmed):
		if confirmed:
			self.__db.deleteBookmark( self.detailList.getCurrent()[0] )
			name = self.detailList.getCurrent()[0]
			self.__setStatus(_("Bookmark '%s' deleted!" %name))
			self.__bmReload()

	def __bmSetCurrentAsHome(self):
		cur = self.detailList.getCurrent()[0]
		self.__setUrlAsHome(cur.url)

	def __bmGetEntryComponent(self, bookmark):
		return ( bookmark, bookmark.name, bookmark.url )

	def __bmBuildList(self):
		print "[BrowserMenu].__bmBuildList"
		list = []
		#Suggest current page for adding

		default = Bookmark(-2, _("Add '%s' to Bookmarks" %self.currentTitle), self.currentUrl)
		list.append(self.__bmGetEntryComponent(default))
		for b in self.__bmList:
			list.append(self.__bmGetEntryComponent(b))
		self.detailList.setList(list)

	def __bmReload(self, needle = ""):
		print "[BrowserMenu].__bmReload"
		self.__bmNeedle = needle
		self.__bmList = self.__db.getBookmarks(needle)
		self.__bmBuildList()

	def __bmFilterCB(self):
		print "[BrowserMenu].__bmFilterCB"
		needle = self.detailInput.getText()
		if needle != self.__bmNeedle:
			self.__bmReload(needle)
		else:
			self.__bmFilterTimer.stop()

	def __bmKeyNumberGlobal(self, number):
		self.detailInput.number(number)
		self.__bmFilterTimer.startLongTimer(1)

	def __bmKeyAscii(self):
		self.detailInput.handleAscii(getPrevAsciiCode())
		self.__bmFilterTimer.startLongTimer(1)

	def __bmKeyDelete(self):
		self.detailInput.delete()
		self.__bmFilterTimer.startLongTimer(1)

	def __bmKeyBackspace(self):
		self.detailInput.deleteBackward()
		self.__bmFilterTimer.startLongTimer(1)

	#History list methods
	def __hisSetCurrentAsHome(self):
		if self.detailList.getCurrent() != None:
			cur = self.detailList.getCurrent()[0]
			self.__setUrlAsHome(cur.url)

	def __setUrlAsHome(self, url):
		config.plugins.WebBrowser.home.value = url
		config.plugins.WebBrowser.home.save()
		self.__setStatus(_("Home page has been set to '%s'" %url))

	def __hisClear(self):
		dlg = self.session.openWithCallback(self.__hisClearCB, MessageBox, _("Do you really want to clear the History?"), type = MessageBox.TYPE_YESNO)
		dlg.setTitle(_("Clear History?"))

	def __hisClearCB(self, confirmed):
		if confirmed:
			self.__db.clearHistory()
			self.__hisReload()
			self.__setStatus(_("History cleared!"))

	def __hisGetEntryComponent(self, historyItem):
		date = strftime("%Y-%m-%d", localtime(historyItem.timestamp))
		time = strftime("%H:%M:%S", localtime(historyItem.timestamp))
		return ( historyItem, date, time, historyItem.title, historyItem.url )

	def __hisReload(self, needle = ""):
		print "[BrowserMenu].__hisReload"
		self.__hisNeedle = needle
		self.__hisList = self.__db.getHistory(needle)
		self.__hisBuildList()

	def __hisBuildList(self):
		print "[BrowserMenu].__hisBuildList"
		history = []
		for h in self.__hisList:
			history.append(self.__hisGetEntryComponent(h))
		self.detailList.setList(history)

	def __hisOk(self):
		if self.detailList.getCurrent() != None:
			current = self.detailList.getCurrent()[0]
			self.__actions.append( (self.ACTION_BOOKMARK, current.url) )
			self.close( self.__actions )

	def __hisFilterCB(self):
		needle = self.detailInput.getText()
		if needle != self.__hisNeedle:
			self.__hisReload(needle)
		else:
			self.__hisFilterTimer.stop()

	def __hisKeyNumberGlobal(self, number):
		self.detailInput.number(number)
		self.__hisFilterTimer.startLongTimer(1)

	def __hisKeyAscii(self):
		self.detailInput.handleAscii(getPrevAsciiCode())
		self.__hisFilterTimer.startLongTimer(1)

	def __hisKeyDelete(self):
		self.detailInput.delete()
		self.__hisFilterTimer.startLongTimer(1)

	def __hisKeyBackspace(self):
		self.detailInput.deleteBackward()
		self.__hisFilterTimer.startLongTimer(1)

	#Download list methods
	def __dlGetEntryComponent(self, job):
		return ( job, job.name, job.getStatustext(), int(100*job.progress/float(job.end)), str(100*job.progress/float(job.end)) + "%")

	def __dlBuildList(self):
		print "[BrowserMenu].__dlBuildList"
		downloads = []
		for job in downloadManager.getPendingJobs():
			downloads.append(self.__dlGetEntryComponent(job))
		self.detailList.setList(downloads)
		if not self.__dlRefreshTimer.isActive():
			self.__dlRefreshTimer.startLongTimer(3)

	def __dlAbort(self):
		print "[BrowserMenu].__dlAbort"
		cur = self.detailList.getCurrent()
		if cur != None:
			job = cur[0]
			dlg = self.session.openWithCallback( self.__dlAbortCB, MessageBox, _("Do you really want to abort downloading '%s'?") %job.name, type = MessageBox.TYPE_YESNO)
			dlg.setTitle(_("Abort Download?"))

	#Certificate list methods
	def __dlAbortCB(self, confirmed):
		if confirmed:
			self.detailList.getCurrent()[0].remove(downloadManager.jobDone)
			self.__dlBuildList()

	def __crtGetEntryComponent(self, cert):
		cn = "CN: %s" %(str(cert.cert.get_subject().commonName))
		return ( cert, str(cert.notBefore()), str(cert.notAfter()), str(cert.host), cn, str(cert.cert.digest("sha1")) )

	def __crtReload(self):
		print "[BrowserMenu].__crtReload"
		self.__crtList = self.__db.getCerts()
		self.__crtBuildList()


	def __crtBuildList(self):
		print "[BrowserMenu].__crtBuildList"
		certs = []
		for c in self.__crtList:
			certs.append(self.__crtGetEntryComponent(c))
		self.detailList.setList(certs)

	def __crtDelete(self):
		if self.detailList.index >= 0 and self.detailList.getCurrent() != None:
			cert = self.detailList.getCurrent()[0]
			print "[BrowserMenu].__crtDelete, host=%s,SHA1 fingerprint=%s" %(cert.host,cert.cert.digest("sha1"))
			text = _("Do you really want to remove the following certificate from the list of trusted certificates?\n\nHostname: %s\nSHA1-Fingerprint: %s") %(cert.host, cert.cert.digest("sha1"))
			dlg = self.session.openWithCallback( self.__crtDeleteCB, MessageBox, text, type = MessageBox.TYPE_YESNO )
			dlg.setTitle(_("Remove trusted certificate?"))

	def __crtDeleteCB(self, confirmed):
		print "[BrowserMenu].__crtDeleteCB"
		if confirmed:
			cert = self.detailList.getCurrent()[0]
			self.__db.deleteCert(cert)
			self.__crtReload()

	def __crtDetails(self):
		print "[BrowserMenu].__crtDetails"
		if self.detailList.index >= 0 and self.detailList.getCurrent() != None:
			cert = self.detailList.getCurrent()[0]

			text = _("Issued for:")
			for item in cert.cert.get_subject().get_components():
				text += "\n%s : %s" %(item[0], item[1])
			text += _("\n\nIssued from:")
			for item in cert.cert.get_issuer().get_components():
				text += "\n%s : %s" %(item[0], item[1])

			text += _("\n\nValidity:\n")
			text += _("From: %s\n") %cert.notBefore()
			text += _("Until: %s\n") %cert.notAfter()
			text += _("Expired: %s\n") %(_("Yes") if cert.cert.has_expired() else _("No"))

			dlg = self.session.open(MessageBox, text, type = MessageBox.TYPE_INFO)
			dlg.setTitle(_("Certificate Details (%s)") %cert.host)

	def __ckReload(self):
		print "[BrowserMenu].__ckReload"
		self.__ckList = self.__db.getCookies()
		self.__ckBuildList()

	def __ckBuildList(self):
		print "[BrowserMenu].__ckBuildList"
		cookies = []
		for c in self.__ckList:
			cookies.append(self.__ckGetEntryComponent(c))
		self.detailList.setList(cookies)

	def __ckGetEntryComponent(self, cookie):
		try:
			date = strftime("%Y-%m-%d", localtime(cookie.expires))
			time = strftime("%H:%M:%S", localtime(cookie.expires))
		except:
			date = _("never")
			time = _("never")
		return ( cookie, date, time, cookie.domain, cookie.path, cookie.raw )

	def __ckDelete(self):
		if self.detailList.index >= 0 and self.detailList.getCurrent() != None:
			cookie = self.detailList.getCurrent()[0]
			text = _("Do you really want to delete the following cookie?\nDomain: %s\nPath: %s\nKey: %s\nRaw-Content:\n%s") %(cookie.domain, cookie.path, cookie.key, cookie.raw)
			dlg = self.session.openWithCallback( self.__ckDeleteCB, MessageBox, text, type = MessageBox.TYPE_YESNO )
			dlg.setTitle(_("Delete Cookie?"))

	def __ckDeleteCB(self, confirmed):
		print "[BrowserMenu].__ckDeleteCB"
		if confirmed:
			self.__db.deleteCookie(self.detailList.getCurrent()[0])
			self.__ckReload()
			action = [self.ACTION_COOKIES,True]
			if not action in self.__actions:
				self.__actions.append(action)

	def __ckDeleteAll(self):
		if self.detailList.index >= 0 and self.detailList.getCurrent() != None:
			text = _("Do you really want to delete ALL cookies?")
			dlg = self.session.openWithCallback( self.__ckDeleteAllCB, MessageBox, text, type = MessageBox.TYPE_YESNO )
			dlg.setTitle(_("Delete Cookie?"))

	def __ckDeleteAllCB(self, confirmed):
		print "[BrowserMenu].__ckDeleteCB"
		if confirmed:
			self.__db.deleteAllCookies()
			self.__ckReload()
			action = [self.ACTION_COOKIES,True]
			if not action in self.__actions:
				self.__actions.append(action)
Пример #2
0
class SetupGuide(Screen):
    MENU_CHOICE_LEAVE = "leave"

    skin = """<screen name="SetupGuide" position="0,0" size="1280,720" title="Welcome" flags="wfNoBorder">
		<widget name="banner" position="0,0" size="240,720" pixmap="skin_default/wizard.png" scale="fill" />
		<widget source="green" render="Pixmap" pixmap="skin_default/buttons/green.png" position="475,15" size="200,40" >
			<convert type="ConditionalShowHide"/>
		</widget>
		<widget name="green_text" position="475,15" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2"/>
		<widget source="yellow" render="Pixmap" pixmap="skin_default/buttons/yellow.png" position="685,15" size="200,40" >
			<convert type="ConditionalShowHide"/>
		</widget>
		<widget name="yellow_text" position="685,15" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2"/>
		<widget source="blue" render="Pixmap" pixmap="skin_default/buttons/blue.png" position="895,15" size="200,40" >
			<convert type="ConditionalShowHide"/>
		</widget>
		<widget name="blue_text" position="895,15" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2"/>
		<widget source="Title" render="Label" position="250,70" size="950,40" font="Regular;36" halign="center" valign="center" />
		<widget name="text" position="250,120" size="950,240" font="Regular;24" halign="center" valign="center" />
		<widget source="list" render="Listbox" position="250,370" size="950,300" zPosition="1" enableWrapAround="1" scrollbarMode="showOnDemand" transparent="1">
			<convert type="TemplatedMultiContent">
				{"templates":
					{	"default" :  (28,[ MultiContentEntryText(pos=(10,4),size=(580,22),flags=RT_HALIGN_LEFT,text=0) ]),
						"iconized" :  (50,[
							MultiContentEntryText(pos=(75,0),size=(310,50),flags=RT_HALIGN_LEFT|RT_VALIGN_CENTER,text=0),# index 0 is the text,
							MultiContentEntryPixmap(pos=(5,5),size=(60,40),png=1),# index 1 is the pixmap
						]),
						"networkservice" : (50,[
							MultiContentEntryPixmapAlphaTest(pos=(0,0),size=(50,50),png=1),#type icon
							MultiContentEntryText(pos=(55,0),size=(400,24),font=0,flags=RT_HALIGN_LEFT,text=3),#service name
							MultiContentEntryText(pos=(780,0),size=(100,24),font=1,flags=RT_HALIGN_RIGHT|RT_VALIGN_BOTTOM,text=7),#security
							MultiContentEntryText(pos=(780,30),size=(100,18),font=1,flags=RT_HALIGN_RIGHT|RT_VALIGN_TOP,text=2),#signal strength
							MultiContentEntryText(pos=(55,30),size=(220,18),font=1,flags=RT_HALIGN_LEFT|RT_VALIGN_CENTER,text=4),#ip
							MultiContentEntryText(pos=(605,30),size=(150,18),font=1,flags=RT_HALIGN_RIGHT|RT_VALIGN_CENTER,text=5),#state
							MultiContentEntryText(pos=(5,0),size=(490,50),font=0,flags=RT_HALIGN_LEFT|RT_VALIGN_CENTER,text=6),#technology name
						]),
						"inputdevice":(50, [
							MultiContentEntryText(pos = (5, 0), size = (200, 24), font=0, flags = RT_HALIGN_LEFT, text = 0), #device name
							MultiContentEntryText(pos = (210, 0), size = (310, 50), font=0, flags = RT_HALIGN_CENTER|RT_VALIGN_CENTER, text = 3), #pairing state
							MultiContentEntryText(pos = (670, 0), size = (200, 18), font=1, flags = RT_HALIGN_RIGHT|RT_VALIGN_CENTER, text = 4), #connection state
							MultiContentEntryText(pos = (5, 30), size = (200, 18), font=1, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER, text = 2), #device address
							MultiContentEntryText(pos = (670, 30), size = (200, 18), font=1, flags = RT_HALIGN_RIGHT|RT_VALIGN_TOP, text = 1), #rssi
						]),
					},
					"fonts": [gFont("Regular",20),gFont("Regular",18)],
					"itemHeight": 30
				}
			</convert>
		</widget>
		<widget name="config" position="250,370" size="950,300" zPosition="1" enableWrapAround="1" scrollbarMode="showOnDemand" transparent="1" />
	</screen>
	"""

    def __init__(self, session, steps={}):
        Screen.__init__(self, session, windowTitle=_("Welcome"))
        self["Title"] = StaticText()
        self["banner"] = Pixmap()

        self._text = Label()
        self["text"] = self._text
        #buttons
        self["green"] = Boolean(False)
        self["green_text"] = Label()
        self["green_text"].hide()
        self["yellow"] = Boolean(False)
        self["yellow_text"] = Label()
        self["yellow_text"].hide()
        self["blue"] = Boolean(False)
        self["blue_text"] = Label()
        self["blue_text"].hide()
        #list
        self.listContent = []
        self.list = List(self.listContent)
        self.list.hide()
        self["list"] = self.list
        #config
        self.configContent = []
        self.configList = ConfigList(self.configContent, session=session)
        self.configList.hide()
        self["config"] = self.configList

        self._movingBack = False
        self._currentStep = None

        self._stepper = PrioritizedStepper()
        if not steps:
            initialSetupSteps.prepare()
            for s in initialSetupSteps.steps:
                self.addSteps(s)

        self["actions"] = NumberActionMap(
            ["MenuActions", "SetupActions", "ColorActions"], {
                "ok": self._ok,
                "cancel": self._cancelAndBack,
                "menu": self._menu,
                "left": self.left,
                "right": self.right,
                "up": self.up,
                "down": self.down,
                "red": self.red,
                "green": self.green,
                "yellow": self.yellow,
                "blue": self.blue,
                "1": self.keyNumberGlobal,
                "2": self.keyNumberGlobal,
                "3": self.keyNumberGlobal,
                "4": self.keyNumberGlobal,
                "5": self.keyNumberGlobal,
                "6": self.keyNumberGlobal,
                "7": self.keyNumberGlobal,
                "8": self.keyNumberGlobal,
                "9": self.keyNumberGlobal,
                "0": self.keyNumberGlobal
            }, -1)
        self.onFirstExecBegin.append(self._nextStep)
        self.onClose.append(self.__onClose)

    def __onClose(self):
        self._stepper.cleanup()
        self._currentStep = None

    def _menu(self):
        choices = [
            (_("Cancel guided setup"), self.MENU_CHOICE_LEAVE),
        ]
        self.session.openWithCallback(self._onMenuChoice,
                                      ChoiceBox,
                                      title=_("Menu"),
                                      list=choices)

    def _onMenuChoice(self, choice):
        choice = choice and choice[1]
        if not choice:
            return
        if choice == self.MENU_CHOICE_LEAVE:
            self._cancel()

    def createSummary(self):
        return SetupGuideSummary

    def updateSummary(self):
        if not self._currentStep:
            return
        self.summaries.setTitle(self._currentStep.title)
        summaryText = self._currentStep.text
        if isinstance(self._currentStep, SetupListStep):
            current = self.list.current
            if current:
                style = self.list.style
                Log.d("%s - %s" % (current, style))
                if style in ("default", "iconized"):
                    summaryText = current[1]
                elif style == "networkservice":
                    summaryText = current[1].name()
                elif style == "inputdevice":
                    deviceName = current[1].name() or current[1].shortName(
                    ) or _("DM Remote")
                    summaryText = "%s (%s)" % (deviceName,
                                               current[1].address())
            else:
                summaryText = _("n/A")
        elif isinstance(self._currentStep, SetupConfigStep):
            current = self.configList.current
            summaryText = (current and "%s\n%s" %
                           (current[0], _(current[1].getText()))) or _("n/A")
        Log.d("%s" % (summaryText, ))
        self.summaries.setText(summaryText)

    def getText(self):
        return self._text.getText()

    def setText(self, text):
        self._text.setText(text)

    text = property(getText, setText)

    def getTitle(self):
        return Screen.getTitle(self)

    def setTitle(self, title):
        Screen.setTitle(self, title)

    title = property(getTitle, setTitle)

    def checkButtons(self):
        keys = ["red", "green", "yellow", "blue"]
        texts = self._currentStep.buttons()
        for i in range(1, 4):
            buttonText = texts[i]
            key = keys[i]
            key_text = "%s_text" % (key, )
            if buttonText:
                self[key].boolean = True
                self[key_text].text = buttonText
                self[key_text].show()
            else:
                self[key].boolean = False
                self[key_text].text = ""
                self[key_text].show()

    def addSteps(self, steps):
        for prio, step in six.iteritems(steps):
            self._stepper.add(self, prio, step)

    def left(self):
        if isinstance(self._currentStep, SetupConfigStep):
            self.configList.handleKey(KEY_LEFT)
            self._currentStep.left()

    def right(self):
        if isinstance(self._currentStep, SetupConfigStep):
            self.configList.handleKey(KEY_RIGHT)
            self._currentStep.right()

    def keyNumberGlobal(self, number):
        if isinstance(self._currentStep, SetupConfigStep):
            self.configList.handleKey(KEY_0 + number)

    def up(self):
        pass

    def down(self):
        pass

    def red(self):
        pass

    def green(self):
        if self._currentStep:
            self._currentStep.green()

    def yellow(self):
        if self._currentStep:
            self._currentStep.yellow()

    def blue(self):
        if self._currentStep:
            self._currentStep.blue()

    def nextStep(self):
        self._nextStep()

    def _nextStep(self):
        self._movingBack = False
        step = self._stepper.next()
        if step:
            self._runStep(step)
            return
        Log.w("No next step available!")
        self.close()

    def _cancelAndBack(self):
        if self._currentStep:
            self._currentStep.cancel()
        self._previousStep()

    def _previousStep(self):
        self._movingBack = True
        step = self._stepper.previous()
        if step:
            self._runStep(step)
        else:
            Log.w("No previous step available!")
            self._cancel()

    def _cancel(self):
        self.session.openWithCallback(
            self._onCancelAnswered,
            MessageBox,
            _("Do you want to cancel the guided setup?"),
            type=MessageBox.TYPE_YESNO,
            windowTitle=_("Cancel guided setup?"),
        )

    def _onCancelAnswered(self, answer):
        if answer:
            if self._currentStep:
                self._currentStep.cancel()
            self.close()

    def _ok(self):
        if self._currentStep.onOk():
            self._nextStep()

    def onSelectionChanged(self):
        self.updateSummary()

    def _runStep(self, step):
        self._currentStep = step
        self.listContent = []
        self.configList.onSelectionChanged = []
        self.list.onSelectionChanged = []
        if not step.prepare():
            if self._movingBack:
                self._previousStep()
            else:
                self.nextStep()
            return
        if isinstance(step, SetupListStep):
            self.configList.hide()
            self.listContent = step.listContent
            self.list.list = self.listContent
            self.list.style = step.listStyle
            self.list.buildfunc = step.buildfunc
            self.list.onSelectionChanged = [
                step.onSelectionChanged, self.onSelectionChanged
            ]
            self.list.index = step.selectedIndex
            self.list.show()
        elif isinstance(step, SetupConfigStep):
            self.list.hide()
            self.configContent = step.configContent
            self.configList.list = self.configContent
            self.configList.onSelectionChanged = [
                step.onSelectionChanged, self.onSelectionChanged
            ]
            self.configList.show()
        else:
            self.configList.hide()
            self.list.hide()
        self.setTitle(step.title)
        self._text.text = step.text
        self.checkButtons()
        self.updateSummary()
Пример #3
0
class BrowserMenu(Screen):
    ACTION_BOOKMARK = 0
    ACTION_COOKIES = 1
    ACTION_STORAGE_PATH = 2

    MENU_BOOKMARKS = 0
    MENU_SETTINGS = 1
    MENU_HISTORY = 2
    MENU_DOWNLOADS = 3
    MENU_CERTS = 4
    MENU_COOKIES = 5

    size = getDesktop(0).size()
    width = int(size.width() * 0.9)
    height = int(size.height() * 0.85)
    bof = height - 35  #Button-Offset

    skin = """
		<screen name="BrowserMenu" position="center,center" size="%(w)d,%(h)d" title="Web Browser - Menu" >
			<widget name="menu" position="0,0" zPosition="1" size="200,%(h)d" backgroundColor="#000000" transparent="1" />
			<widget source="line" render="Canvas" position="203,0" zPosition="2" size="4,%(h)d" backgroundColor="#000000" transparent="1" alphatest="on"/>
			<widget source="list" render="Listbox" position="210,0" zPosition="1" size="%(listW)d,%(listH)d" backgroundColor="#000000" transparent="1">
				<convert type="TemplatedMultiContent">
					{"templates":
						{"default": (55, [
							MultiContentEntryText(pos = (10, 1), size = (920, 25), font = 0, flags = RT_VALIGN_CENTER, text = 1),
							MultiContentEntryText(pos = (10, 30), size = (920, 25), font = 1, flags = RT_VALIGN_CENTER, text = 2),
						]),
						"history": (55, [
							MultiContentEntryText(pos = (10, 1), size = (150, 25), font = 1, flags = RT_VALIGN_CENTER, text = 1),
							MultiContentEntryText(pos = (10, 28), size = (150, 25), font = 1, flags = RT_VALIGN_CENTER, text = 2),
							MultiContentEntryText(pos = (190, 1), size = (690, 25), font = 0, flags = RT_VALIGN_CENTER, text = 3),
							MultiContentEntryText(pos = (190, 28), size = (690, 25), font = 1, flags = RT_VALIGN_CENTER, text = 4),
						]),
						"downloads": (25, [
							MultiContentEntryText(pos = (0, 1), size = (600, 24), font=1, flags = RT_HALIGN_LEFT, text = 1),
							MultiContentEntryText(pos = (610, 1), size = (150, 24), font=1, flags = RT_HALIGN_RIGHT, text = 2),
							MultiContentEntryProgress(pos = (760, 1), size = (100, 24), percent = 3),
							MultiContentEntryText(pos = (870, 1), size = (70, 24), font=1, flags = RT_HALIGN_RIGHT, text = 4),
						]),
						"certificates": (85, [
							MultiContentEntryText(pos = (10, 1), size = (150, 25), font = 1, flags = RT_VALIGN_CENTER, text = 1),
							MultiContentEntryText(pos = (10, 28), size = (150, 25), font = 1, flags = RT_VALIGN_CENTER, text = 2),
							MultiContentEntryText(pos = (190, 1), size = (690, 25), font = 0, flags = RT_VALIGN_CENTER, text = 3),
							MultiContentEntryText(pos = (190, 28), size = (690, 25), font = 1, flags = RT_VALIGN_CENTER, text = 4),
							MultiContentEntryText(pos = (10, 60), size = (900, 25), font = 0, flags = RT_VALIGN_CENTER, text = 5),
						]),
						"cookies": (75, [
							MultiContentEntryText(pos = (10, 1), size = (150, 25), font = 1, flags = RT_VALIGN_CENTER, text = 1),
							MultiContentEntryText(pos = (10, 28), size = (150, 25), font = 1, flags = RT_VALIGN_CENTER, text = 2),
							MultiContentEntryText(pos = (180, 1), size = (720, 25), font = 0, flags = RT_VALIGN_CENTER, text = 3),
							MultiContentEntryText(pos = (180, 28), size = (625, 25), font = 1, flags = RT_VALIGN_CENTER, text = 4),
							MultiContentEntryText(pos = (10, 60), size = (900, 15), font = 2, flags = RT_VALIGN_CENTER, text = 5),
						])
						},
					"fonts": [gFont("Regular", 22), gFont("Regular", 16), gFont("Regular", 13)]
					}
				</convert>
			</widget>
			<widget name="statuslabel" position="210,%(inputY)d" size="%(listW)d,25" font="Regular;20"  zPosition="2" halign="center" valign="center" backgroundColor="#000000" transparent="0" />
			<widget name="input" position="210,%(inputY)d" zPosition="1" size="%(listW)d,25" font="Regular;20" halign="left" valign="bottom" backgroundColor="#000000" transparent="1"/>
			<widget name="config" position="210,0" zPosition="2" size="%(listW)d,%(configH)d" backgroundColor="background" transparent="0" />

			<ePixmap pixmap="skin_default/buttons/button_red_off.png" position="210,%(btnY)d" size="15,16" alphatest="on" />
			<widget source="button_red" zPosition="2" render="Pixmap" pixmap="skin_default/buttons/button_red.png" position="210,%(btnY)d" size="15,16" alphatest="on">
				<convert type="ConditionalShowHide" />
			</widget>
			<widget name="red" position="230,%(btnTxtY)d" size="100,20" foregroundColor="white" backgroundColor="background" font="Regular;18" transparent="1" halign="left" valign="top"/>

			<ePixmap pixmap="skin_default/buttons/button_green_off.png" position="340,%(btnY)d" size="15,16" zPosition="1" alphatest="on" />
			<widget source="button_green" zPosition="2" render="Pixmap" pixmap="skin_default/buttons/button_green.png" position="340,%(btnY)d" size="15,16" alphatest="on">
				<convert type="ConditionalShowHide" />
			</widget>
			<widget name="green" position="360,%(btnTxtY)d" size="100,20" foregroundColor="white" backgroundColor="background" font="Regular;18" transparent="1" halign="left" valign="top"/>

			<ePixmap pixmap="skin_default/buttons/button_yellow_off.png" position="470,%(btnY)d" size="15,16" alphatest="on" />
			<widget source="button_yellow" zPosition="2" render="Pixmap" pixmap="skin_default/buttons/button_yellow.png" position="470,%(btnY)d" size="15,16" alphatest="on">
				<convert type="ConditionalShowHide" />
			</widget>
			<widget name="yellow" position="490,%(btnTxtY)d" size="100,20" foregroundColor="white" backgroundColor="background" font="Regular;18" transparent="1" halign="left" valign="top"/>

			<ePixmap pixmap="skin_default/buttons/button_blue_off.png" position="600,%(btnY)d" size="15,16" alphatest="on" />
			<widget source="button_blue" zPosition="2" render="Pixmap" pixmap="skin_default/buttons/button_blue.png" position="600,%(btnY)d" size="15,16" alphatest="on">
				<convert type="ConditionalShowHide" />
			</widget>
			<widget name="blue" position="620,%(btnTxtY)d" size="200,20" foregroundColor="white" backgroundColor="background" font="Regular;18" transparent="1" halign="left" valign="top"/>
		</screen>
		""" % {
        "w": width,
        "h": height,
        "listW": width - 210,
        "listH": height - 90,
        "inputY": height - 80,
        "configH": height - 90,
        "btnY": bof + 2,
        "btnTxtY": bof
    }

    def __init__(self, session, currentTitle, currentUrl, menulist=None):
        Screen.__init__(self, session)

        self.currentUrl = currentUrl
        self.currentTitle = currentTitle

        #Menu
        if menulist is None:
            self.menu = MenuList([
                (_("Bookmarks"), self.MENU_BOOKMARKS),
                (_("History"), self.MENU_HISTORY),
                (_("Downloads"), self.MENU_DOWNLOADS),
                (_("Certificates"), self.MENU_CERTS),
                (_("Cookies"), self.MENU_COOKIES),
                (_("Settings"), self.MENU_SETTINGS),
            ],
                                 enableWrapAround=True)
        else:
            self.menu = MenuList(menulist, enableWrapAround=True)
        self["menu"] = self.menu

        self["statuslabel"] = Label("")
        self["statuslabel"].hide()

        #Color Buttons
        self["button_red"] = Boolean(False)
        self["button_green"] = Boolean(False)
        self["button_yellow"] = Boolean(False)
        self["button_blue"] = Boolean(False)
        self.red = Label("")
        self.green = Label("")
        self.yellow = Label("")
        self.blue = Label("")
        self["red"] = self.red
        self["green"] = self.green
        self["yellow"] = self.yellow
        self["blue"] = self.blue

        #Lists
        self.detailList = List([], enableWrapAround=True)
        self.detailConfigList = ConfigList([])
        self.detailConfigList.l.setSeperation((BrowserMenu.width - 210) / 2)
        config.plugins.WebBrowser.storage.enabled.addNotifier(
            self.__cfgExpandableElementChanged, initial_call=False)
        config.plugins.WebBrowser.storage.enabled.addNotifier(
            self.__cfgStoragePathChanged, initial_call=False)
        config.plugins.WebBrowser.storage.path.addNotifier(
            self.__cfgStoragePathChanged, initial_call=False)

        self.detailInput = EnhancedInput()

        self["list"] = self.detailList
        self["config"] = self.detailConfigList
        self["input"] = self.detailInput
        self["line"] = CanvasSource()

        self.__cfgCreateSetup()

        self.__db = BrowserDB.getInstance()
        self.__curMenu = self.MENU_BOOKMARKS
        self.__bmList = None
        self.__hisList = None
        self.__crtList = None
        self.__ckList = None
        self.__bmNeedle = ""
        self.__bmFilterTimer = eTimer()
        self.__bmFilterTimer_conn = self.__bmFilterTimer.timeout.connect(
            self.__bmFilterCB)
        self.__hisNeedle = ""
        self.__hisFilterTimer = eTimer()
        self.__hisFilterTimer_conn = self.__hisFilterTimer.timeout.connect(
            self.__hisFilterCB)
        self.__dlRefreshTimer = eTimer()
        self.__dlRefreshTimer_conn = self.__dlRefreshTimer.timeout.connect(
            self.__dlBuildList)
        self.__statusTimer = eTimer()
        self.__statusTimer_conn = self.__statusTimer.timeout.connect(
            self.__hideStatus)
        self.__actions = []

        self.onFirstExecBegin.append(self.__drawSeparator)
        self.onFirstExecBegin.append(self.__onMenuChanged)
        self.onExecBegin.append(self.__reloadData)
        self.onShow.append(self.setKeyboardModeAscii)

        self["actions"] = ActionMap(
            ["BrowserActions", "ColorActions"],
            {
                "ok": self.__actionOk,
                "enter": self.__actionOk,
                "exit": self.__actionExit,
                "pageUp": self.__actionMenuUp,
                "pageDown": self.__actionMenuDown,
                "up": boundFunction(self.__action, "up"),
                "down": boundFunction(self.__action, "down"),
                "left": boundFunction(self.__action, "left"),
                "right": boundFunction(self.__action, "right"),
                "red": boundFunction(self.__action, "red"),
                "green": boundFunction(self.__action, "green"),
                "yellow": boundFunction(self.__action, "yellow"),
                "blue": boundFunction(self.__action, "blue"),
                "backspace": boundFunction(self.__action, "backspace"),
                "delete": boundFunction(self.__action, "delete"),
                "ascii": boundFunction(self.__action, "ascii"),
                # TODO "text" : self.__text
            },
            -2)

        self["numberactions"] = NumberActionMap(
            ["NumberActions"], {
                "1": self.__keyNumberGlobal,
                "2": self.__keyNumberGlobal,
                "3": self.__keyNumberGlobal,
                "4": self.__keyNumberGlobal,
                "5": self.__keyNumberGlobal,
                "6": self.__keyNumberGlobal,
                "7": self.__keyNumberGlobal,
                "8": self.__keyNumberGlobal,
                "9": self.__keyNumberGlobal,
                "0": self.__keyNumberGlobal
            }, -2)

        self.__actionFuncs = {
            self.MENU_BOOKMARKS: {
                "up": self.detailList.selectPrevious,
                "down": self.detailList.selectNext,
                "left": self.detailList.selectPrevious,
                "right": self.detailList.pageDown,
                "ok": self.__bmOk,
                "enter": self.__bmOk,
                "red": self.__bmDelete,
                "green": self.__bmAdd,
                "yellow": self.__bmEdit,
                "blue": self.__bmSetCurrentAsHome,
                "backspace": self.__bmKeyBackspace,
                "delete": self.__bmKeyDelete,
                "ascii": self.__bmKeyAscii,
            },
            self.MENU_HISTORY: {
                "up": self.detailList.selectPrevious,
                "down": self.detailList.selectNext,
                "left": self.detailList.pageUp,
                "right": self.detailList.pageDown,
                "ok": self.__hisOk,
                "enter": self.__hisOk,
                "red": self.__hisClear,
                "blue": self.__hisSetCurrentAsHome,
                "backspace": self.__hisKeyBackspace,
                "delete": self.__hisKeyDelete,
                "ascii": self.__hisKeyAscii,
            },
            self.MENU_SETTINGS: {
                "up": self.__cfgKeyUp,
                "down": self.__cfgKeyDown,
                "left": self.__cfgKeyLeft,
                "right": self.__cfgKeyRight,
                "ok": self.__cfgKeyOK,
                "enter": self.__cfgKeyOK,
                "red": self.__cfgCancel,
                "green": self.__cfgSave,
                "backspace": self.__cfgKeyBackspace,
                "delete": self.__cfgKeyDelete,
                "ascii": self.__cfgKeyAscii,
            },
            self.MENU_DOWNLOADS: {
                "up": self.detailList.selectPrevious,
                "down": self.detailList.selectNext,
                "left": self.detailList.pageUp,
                "right": self.detailList.pageDown,
                "red": self.__dlAbort,
            },
            self.MENU_CERTS: {
                "up": self.detailList.selectPrevious,
                "down": self.detailList.selectNext,
                "left": self.detailList.pageUp,
                "right": self.detailList.pageDown,
                "red": self.__crtDelete,
                "green": self.__crtDetails,
            },
            self.MENU_COOKIES: {
                "up": self.detailList.selectPrevious,
                "down": self.detailList.selectNext,
                "left": self.detailList.pageUp,
                "right": self.detailList.pageDown,
                "red": self.__ckDelete,
                "blue": self.__ckDeleteAll,
            }
        }

    def _close(self):
        config.plugins.WebBrowser.storage.enabled.removeNotifier(
            self.__cfgExpandableElementChanged)
        config.plugins.WebBrowser.storage.enabled.removeNotifier(
            self.__cfgStoragePathChanged)
        config.plugins.WebBrowser.storage.path.removeNotifier(
            self.__cfgStoragePathChanged)
        self.close(self.__actions)

    def __actionOk(self):
        if self["statuslabel"].visible:
            self["statuslabel"].hide()
        else:
            self.__action("ok")

    def __actionExit(self):
        if self["statuslabel"].visible:
            self["statuslabel"].hide()
        else:
            if self.detailConfigList.isChanged():
                self.__cfgSave()
            self._close()

    def __actionMenuUp(self):
        self.menu.up()
        self.__onMenuChanged()

    def __actionMenuDown(self):
        self.menu.down()
        self.__onMenuChanged()

    def __reloadData(self):
        self.__bmList = self.__db.getBookmarks()
        self.__hisList = self.__db.getHistory()
        self.__crtList = self.__db.getCerts()
        self.__ckList = self.__db.getCookies()

    def __action(self, action):
        print "[BrowserMenu].__action :: action='%s'" % action
        fnc = self.__actionFuncs[self.__curMenu].get(action, None)
        if fnc != None:
            fnc()

    def __text(self):
        if self.__curMenu == self.MENU_SETTINGS:
            self.__cfgKeyText()
        elif self.__curMenu == self.MENU_BOOKMARKS:
            pass

    def __keyNumberGlobal(self, number):
        if self.__curMenu == self.MENU_SETTINGS:
            self.__cfgKeyNumberGlobal(number)
        elif self.__curMenu == self.MENU_BOOKMARKS:
            self.__bmKeyNumberGlobal(number)
        elif self.__curMenu == self.MENU_HISTORY:
            self.__hisKeyNumberGlobal(number)

    def __onMenuChanged(self):
        self.__bmFilterTimer.stop()
        self.__hisFilterTimer.stop()
        self.__dlRefreshTimer.stop()

        self.__curMenu = self.menu.getCurrent()[1]
        if self.__curMenu == self.MENU_BOOKMARKS:
            self.__showMenuList(True)
            self.__setButtons(_("Delete"), _("Add"), _("Edit"),
                              _("Set as Startpage"))
            self.detailList.style = "default"
            self.__bmBuildList()
            self.detailInput.setText(self.__bmNeedle)
        elif self.__curMenu == self.MENU_HISTORY:
            self.__showMenuList(True)
            self.__setButtons(_("Clear"), "", "", _("Set as Startpage"))
            self.detailList.style = "history"
            self.__hisBuildList()
            self.detailInput.setText(self.__hisNeedle)
        elif self.__curMenu == self.MENU_SETTINGS:
            self.__showConfigList()
            self.__setButtons(_("Cancel"), _("Save"), "", "")
        elif self.__curMenu == self.MENU_DOWNLOADS:
            self.__showMenuList()
            self.__setButtons(_("Abort"), "", "", "")
            self.detailList.style = "downloads"
            self.__dlBuildList()
        elif self.__curMenu == self.MENU_CERTS:
            self.__showMenuList()
            self.__setButtons(_("Delete"), _("Details"), "", "")
            self.detailList.style = "certificates"
            self.__crtBuildList()
        elif self.__curMenu == self.MENU_COOKIES:
            self.__showMenuList()
            self.__setButtons(_("Delete"), "", "", _("Delete All"))
            self.detailList.style = "cookies"
            self.__ckBuildList()

    def __setButtons(self, red, green, yellow, blue):
        self.red.setText(red)
        self.__setButtonPixmapVisible(self["button_red"], red)
        self.green.setText(green)
        self.__setButtonPixmapVisible(self["button_green"], green)
        self.yellow.setText(yellow)
        self.__setButtonPixmapVisible(self["button_yellow"], yellow)
        self.blue.setText(blue)
        self.__setButtonPixmapVisible(self["button_blue"], blue)

    def __setButtonPixmapVisible(self, B, label):
        show = True
        if label == "":
            show = False
        B.setBoolean(show)

    def __showMenuList(self, hasFilter=False):
        if self.detailConfigList.visible:
            self.detailConfigList.hide()

# 		if not self.detailList.instance.visible:
# 			self.detailList.instance.show()
        if hasFilter:
            self.detailInput.show()
        else:
            self.detailInput.hide()

    def __showConfigList(self):
        # 		if self.detailList.instance.visible == 1:
        # 			self.detailList.instance.hide()
        self.detailInput.hide()
        if self.detailConfigList.visible == 0:
            self.detailConfigList.show()

    def __drawSeparator(self):
        self["line"].fill(0, 0, 4, BrowserMenu.height, 0xFF9900)
        self["line"].flush()

    def __setStatus(self, text):
        print "[BrowserMenu].__setStatus"
        self["statuslabel"].setText(text)
        self["statuslabel"].show()
        self.__statusTimer.startLongTimer(3)

    def __hideStatus(self):
        self["statuslabel"].hide()
        self.__statusTimer.stop()

    # Config List Methods
    def __cfgCreateSetup(self):
        list = [
            getConfigListEntry(_("Home Page"), config.plugins.WebBrowser.home),
            getConfigListEntry(_("Page to load on startup"),
                               config.plugins.WebBrowser.startPage),
            getConfigListEntry(_("Search Provider"),
                               config.plugins.WebBrowser.searchProvider),
            getConfigListEntry(_("Run fullscreen"),
                               config.plugins.WebBrowser.fullscreen),
            getConfigListEntry(_("Offset in scroll mode (px)"),
                               config.plugins.WebBrowser.scrollOffset),
            getConfigListEntry(_("Target directory for downloads"),
                               config.plugins.WebBrowser.downloadpath),
            getConfigListEntry(_("Enable persistent storage"),
                               config.plugins.WebBrowser.storage.enabled),
        ]
        if config.plugins.WebBrowser.storage.enabled.value:
            list.append(
                getConfigListEntry(_("Path for persistent storage"),
                                   config.plugins.WebBrowser.storage.path))

        self.detailConfigList.setList(list)

    def __cfgExpandableElementChanged(self, element):
        self.__cfgCreateSetup()

    def __cfgSave(self):
        for x in self.detailConfigList.list:
            x[1].save()
        self.__setStatus(_("Settings have been saved successfully!"))

    def __cfgStoragePathChanged(self, element):
        action = [self.ACTION_STORAGE_PATH, True]
        if not action in self.__actions:
            self.__actions.append(action)

    def __cfgCancel(self):
        dlg = self.session.openWithCallback(
            self.__cfgCancelCB,
            MessageBox,
            _("Do you really want to discard all changes?"),
            type=MessageBox.TYPE_YESNO)
        dlg.setTitle(_("Discard changed settings?"))

    def __cfgCancelCB(self, confirmed):
        for x in self.detailConfigList.list:
            x[1].cancel()
        self.__setStatus(_("All changes to the settings have been discarded!"))

    def __cfgKeyText(self):
        from Screens.VirtualKeyBoard import VirtualKeyBoard
        self.session.openWithCallback(
            self.__cfgVirtualKeyBoardCallback,
            VirtualKeyBoard,
            title=self.detailConfigList.getCurrent()[0],
            text=self.detailConfigList.getCurrent()[1].getValue())

    def __cfgVirtualKeyBoardCallback(self, callback=None):
        if callback is not None and len(callback):
            self.detailConfigList.getCurrent()[1].setValue(callback)
            self.detailConfigList.invalidate(
                self.detailConfigList.getCurrent())

    def __cfgKeyOK(self):
        self.detailConfigList.handleKey(KEY_OK)

    def __cfgKeyUp(self):
        self.detailConfigList.instance.moveSelection(eListbox.moveUp)

    def __cfgKeyDown(self):
        self.detailConfigList.instance.moveSelection(eListbox.moveDown)

    def __cfgKeyLeft(self):
        self.detailConfigList.handleKey(KEY_LEFT)

    def __cfgKeyRight(self):
        self.detailConfigList.handleKey(KEY_RIGHT)

    def __cfgKeyHome(self):
        self.detailConfigList.handleKey(KEY_HOME)

    def __cfgKeyEnd(self):
        self.detailConfigList.handleKey(KEY_END)

    def __cfgKeyDelete(self):
        self.detailConfigList.handleKey(KEY_DELETE)

    def __cfgKeyBackspace(self):
        self.detailConfigList.handleKey(KEY_BACKSPACE)

    def __cfgKeyToggleOW(self):
        self.detailConfigList.handleKey(KEY_TOGGLEOW)

    def __cfgKeyAscii(self):
        self.detailConfigList.handleKey(KEY_ASCII)

    def __cfgKeyNumberGlobal(self, number):
        self.detailConfigList.handleKey(KEY_0 + number)

    #Bookmark List Methods
    def __bmOk(self):
        print "[BrowserMenu].__bmOk"
        if self.detailList.index > 0 and self.detailList.getCurrent() != None:
            current = self.detailList.getCurrent()[0]
            print "[BrowserMenu].__bmOk, current = '%s'" % current
            self.__actions.append((self.ACTION_BOOKMARK, current.url))
            self.close(self.__actions)
        else:
            self.__bmAdd(Bookmark(-1, self.currentTitle, self.currentUrl))

    def __bmAdd(self, bookmark=None):
        self.session.openWithCallback(self.__bmEditCB, BookmarkEditor,
                                      bookmark)

    def __bmEdit(self):
        if self.detailList.index > 0 and self.detailList.getCurrent() != None:
            cur = self.detailList.getCurrent()[0]
            self.session.openWithCallback(self.__bmEditCB, BookmarkEditor, cur)

    def __bmEditCB(self, bookmark):
        if bookmark != None:
            self.__db.setBookmark(bookmark)
            self.__bmReload()
            self.__setStatus(
                _("Bookmark '%s' saved succesfully!" % bookmark.name))

    def __bmDelete(self):
        if self.detailList.getCurrent() != None:
            name = self.detailList.getCurrent()[0].name
            print "[BrowserMenu].__bmDelete, name='%s'" % name
            dlg = self.session.openWithCallback(
                self.__bmDeleteCB,
                MessageBox,
                _("Do you really want to delete the bookmark '%s'?") % name,
                type=MessageBox.TYPE_YESNO)
            dlg.setTitle(_("Delete Bookmark?"))

    def __bmDeleteCB(self, confirmed):
        if confirmed:
            self.__db.deleteBookmark(self.detailList.getCurrent()[0])
            name = self.detailList.getCurrent()[0]
            self.__setStatus(_("Bookmark '%s' deleted!" % name))
            self.__bmReload()

    def __bmSetCurrentAsHome(self):
        cur = self.detailList.getCurrent()[0]
        self.__setUrlAsHome(cur.url)

    def __bmGetEntryComponent(self, bookmark):
        return (bookmark, bookmark.name, bookmark.url)

    def __bmBuildList(self):
        print "[BrowserMenu].__bmBuildList"
        list = []
        #Suggest current page for adding

        default = Bookmark(-2, _("Add '%s' to Bookmarks" % self.currentTitle),
                           self.currentUrl)
        list.append(self.__bmGetEntryComponent(default))
        for b in self.__bmList:
            list.append(self.__bmGetEntryComponent(b))
        self.detailList.setList(list)

    def __bmReload(self, needle=""):
        print "[BrowserMenu].__bmReload"
        self.__bmNeedle = needle
        self.__bmList = self.__db.getBookmarks(needle)
        self.__bmBuildList()

    def __bmFilterCB(self):
        print "[BrowserMenu].__bmFilterCB"
        needle = self.detailInput.getText()
        if needle != self.__bmNeedle:
            self.__bmReload(needle)
        else:
            self.__bmFilterTimer.stop()

    def __bmKeyNumberGlobal(self, number):
        self.detailInput.number(number)
        self.__bmFilterTimer.startLongTimer(1)

    def __bmKeyAscii(self):
        self.detailInput.handleAscii(getPrevAsciiCode())
        self.__bmFilterTimer.startLongTimer(1)

    def __bmKeyDelete(self):
        self.detailInput.delete()
        self.__bmFilterTimer.startLongTimer(1)

    def __bmKeyBackspace(self):
        self.detailInput.deleteBackward()
        self.__bmFilterTimer.startLongTimer(1)

    #History list methods
    def __hisSetCurrentAsHome(self):
        if self.detailList.getCurrent() != None:
            cur = self.detailList.getCurrent()[0]
            self.__setUrlAsHome(cur.url)

    def __setUrlAsHome(self, url):
        config.plugins.WebBrowser.home.value = url
        config.plugins.WebBrowser.home.save()
        self.__setStatus(_("Home page has been set to '%s'" % url))

    def __hisClear(self):
        dlg = self.session.openWithCallback(
            self.__hisClearCB,
            MessageBox,
            _("Do you really want to clear the History?"),
            type=MessageBox.TYPE_YESNO)
        dlg.setTitle(_("Clear History?"))

    def __hisClearCB(self, confirmed):
        if confirmed:
            self.__db.clearHistory()
            self.__hisReload()
            self.__setStatus(_("History cleared!"))

    def __hisGetEntryComponent(self, historyItem):
        date = strftime("%Y-%m-%d", localtime(historyItem.timestamp))
        time = strftime("%H:%M:%S", localtime(historyItem.timestamp))
        return (historyItem, date, time, historyItem.title, historyItem.url)

    def __hisReload(self, needle=""):
        print "[BrowserMenu].__hisReload"
        self.__hisNeedle = needle
        self.__hisList = self.__db.getHistory(needle)
        self.__hisBuildList()

    def __hisBuildList(self):
        print "[BrowserMenu].__hisBuildList"
        history = []
        for h in self.__hisList:
            history.append(self.__hisGetEntryComponent(h))
        self.detailList.setList(history)

    def __hisOk(self):
        if self.detailList.getCurrent() != None:
            current = self.detailList.getCurrent()[0]
            self.__actions.append((self.ACTION_BOOKMARK, current.url))
            self.close(self.__actions)

    def __hisFilterCB(self):
        needle = self.detailInput.getText()
        if needle != self.__hisNeedle:
            self.__hisReload(needle)
        else:
            self.__hisFilterTimer.stop()

    def __hisKeyNumberGlobal(self, number):
        self.detailInput.number(number)
        self.__hisFilterTimer.startLongTimer(1)

    def __hisKeyAscii(self):
        self.detailInput.handleAscii(getPrevAsciiCode())
        self.__hisFilterTimer.startLongTimer(1)

    def __hisKeyDelete(self):
        self.detailInput.delete()
        self.__hisFilterTimer.startLongTimer(1)

    def __hisKeyBackspace(self):
        self.detailInput.deleteBackward()
        self.__hisFilterTimer.startLongTimer(1)

    #Download list methods
    def __dlGetEntryComponent(self, job):
        return (job, job.name, job.getStatustext(),
                int(100 * job.progress / float(job.end)),
                str(100 * job.progress / float(job.end)) + "%")

    def __dlBuildList(self):
        print "[BrowserMenu].__dlBuildList"
        downloads = []
        for job in downloadManager.getPendingJobs():
            downloads.append(self.__dlGetEntryComponent(job))
        self.detailList.setList(downloads)
        if not self.__dlRefreshTimer.isActive():
            self.__dlRefreshTimer.startLongTimer(3)

    def __dlAbort(self):
        print "[BrowserMenu].__dlAbort"
        cur = self.detailList.getCurrent()
        if cur != None:
            job = cur[0]
            dlg = self.session.openWithCallback(
                self.__dlAbortCB,
                MessageBox,
                _("Do you really want to abort downloading '%s'?") % job.name,
                type=MessageBox.TYPE_YESNO)
            dlg.setTitle(_("Abort Download?"))

    #Certificate list methods
    def __dlAbortCB(self, confirmed):
        if confirmed:
            self.detailList.getCurrent()[0].remove(downloadManager.jobDone)
            self.__dlBuildList()

    def __crtGetEntryComponent(self, cert):
        cn = "CN: %s" % (str(cert.cert.get_subject().commonName))
        return (cert, str(cert.notBefore()), str(cert.notAfter()),
                str(cert.host), cn, str(cert.cert.digest("sha1")))

    def __crtReload(self):
        print "[BrowserMenu].__crtReload"
        self.__crtList = self.__db.getCerts()
        self.__crtBuildList()

    def __crtBuildList(self):
        print "[BrowserMenu].__crtBuildList"
        certs = []
        for c in self.__crtList:
            certs.append(self.__crtGetEntryComponent(c))
        self.detailList.setList(certs)

    def __crtDelete(self):
        if self.detailList.index >= 0 and self.detailList.getCurrent() != None:
            cert = self.detailList.getCurrent()[0]
            print "[BrowserMenu].__crtDelete, host=%s,SHA1 fingerprint=%s" % (
                cert.host, cert.cert.digest("sha1"))
            text = _(
                "Do you really want to remove the following certificate from the list of trusted certificates?\n\nHostname: %s\nSHA1-Fingerprint: %s"
            ) % (cert.host, cert.cert.digest("sha1"))
            dlg = self.session.openWithCallback(self.__crtDeleteCB,
                                                MessageBox,
                                                text,
                                                type=MessageBox.TYPE_YESNO)
            dlg.setTitle(_("Remove trusted certificate?"))

    def __crtDeleteCB(self, confirmed):
        print "[BrowserMenu].__crtDeleteCB"
        if confirmed:
            cert = self.detailList.getCurrent()[0]
            self.__db.deleteCert(cert)
            self.__crtReload()

    def __crtDetails(self):
        print "[BrowserMenu].__crtDetails"
        if self.detailList.index >= 0 and self.detailList.getCurrent() != None:
            cert = self.detailList.getCurrent()[0]

            text = _("Issued for:")
            for item in cert.cert.get_subject().get_components():
                text += "\n%s : %s" % (item[0], item[1])
            text += _("\n\nIssued from:")
            for item in cert.cert.get_issuer().get_components():
                text += "\n%s : %s" % (item[0], item[1])

            text += _("\n\nValidity:\n")
            text += _("From: %s\n") % cert.notBefore()
            text += _("Until: %s\n") % cert.notAfter()
            text += _("Expired: %s\n") % (_("Yes") if cert.cert.has_expired()
                                          else _("No"))

            dlg = self.session.open(MessageBox,
                                    text,
                                    type=MessageBox.TYPE_INFO)
            dlg.setTitle(_("Certificate Details (%s)") % cert.host)

    def __ckReload(self):
        print "[BrowserMenu].__ckReload"
        self.__ckList = self.__db.getCookies()
        self.__ckBuildList()

    def __ckBuildList(self):
        print "[BrowserMenu].__ckBuildList"
        cookies = []
        for c in self.__ckList:
            cookies.append(self.__ckGetEntryComponent(c))
        self.detailList.setList(cookies)

    def __ckGetEntryComponent(self, cookie):
        try:
            date = strftime("%Y-%m-%d", localtime(cookie.expires))
            time = strftime("%H:%M:%S", localtime(cookie.expires))
        except:
            date = _("never")
            time = _("never")
        return (cookie, date, time, cookie.domain, cookie.path, cookie.raw)

    def __ckDelete(self):
        if self.detailList.index >= 0 and self.detailList.getCurrent() != None:
            cookie = self.detailList.getCurrent()[0]
            text = _(
                "Do you really want to delete the following cookie?\nDomain: %s\nPath: %s\nKey: %s\nRaw-Content:\n%s"
            ) % (cookie.domain, cookie.path, cookie.key, cookie.raw)
            dlg = self.session.openWithCallback(self.__ckDeleteCB,
                                                MessageBox,
                                                text,
                                                type=MessageBox.TYPE_YESNO)
            dlg.setTitle(_("Delete Cookie?"))

    def __ckDeleteCB(self, confirmed):
        print "[BrowserMenu].__ckDeleteCB"
        if confirmed:
            self.__db.deleteCookie(self.detailList.getCurrent()[0])
            self.__ckReload()
            action = [self.ACTION_COOKIES, True]
            if not action in self.__actions:
                self.__actions.append(action)

    def __ckDeleteAll(self):
        if self.detailList.index >= 0 and self.detailList.getCurrent() != None:
            text = _("Do you really want to delete ALL cookies?")
            dlg = self.session.openWithCallback(self.__ckDeleteAllCB,
                                                MessageBox,
                                                text,
                                                type=MessageBox.TYPE_YESNO)
            dlg.setTitle(_("Delete Cookie?"))

    def __ckDeleteAllCB(self, confirmed):
        print "[BrowserMenu].__ckDeleteCB"
        if confirmed:
            self.__db.deleteAllCookies()
            self.__ckReload()
            action = [self.ACTION_COOKIES, True]
            if not action in self.__actions:
                self.__actions.append(action)