enigma2 20130114 (master) -> 20130216 (master)
[enigma2.git] / usr / lib / enigma2 / python / Plugins / Extensions / Browser / BrowserMenu.py
1 from enigma import getDesktop, eListboxPythonMultiContent, eListbox, RT_VALIGN_CENTER, RT_HALIGN_LEFT, RT_HALIGN_RIGHT, gFont, eTimer, getPrevAsciiCode
2
3 from Components.ActionMap import ActionMap, NumberActionMap
4 from Components.config import config, getConfigListEntry, KEY_LEFT, KEY_RIGHT, KEY_HOME, KEY_END, KEY_0, KEY_DELETE, KEY_BACKSPACE, KEY_OK, KEY_TOGGLEOW, KEY_ASCII
5 from Components.ConfigList import ConfigList
6 from Components.Label import Label
7 from Components.MenuList import MenuList
8 from Components.Sources.List import List
9 from Components.MultiContent import MultiContentEntryText, MultiContentEntryProgress
10 from Components.Sources.Boolean import Boolean
11 from Components.Sources.CanvasSource import CanvasSource
12
13 from Screens.MessageBox import MessageBox
14 from Screens.Screen import Screen
15
16 from Tools.BoundFunction import boundFunction
17
18 from Bookmarks import BookmarkEditor
19 from BrowserDB import Bookmark, BrowserDB
20 from Downloads import downloadManager
21 from EnhancedInput import EnhancedInput
22
23 from time import localtime, strftime
24
25 class BrowserMenu(Screen):
26         ACTION_BOOKMARK = 0
27         ACTION_COOKIES = 1
28         ACTION_STORAGE_PATH = 2
29
30         MENU_BOOKMARKS = 0
31         MENU_SETTINGS = 1
32         MENU_HISTORY = 2
33         MENU_DOWNLOADS = 3
34         MENU_CERTS = 4
35         MENU_COOKIES = 5
36
37         size = getDesktop(0).size()
38         width = int(size.width() * 0.9)
39         height = int(size.height() * 0.85)
40         bof = height - 35 #Button-Offset
41
42         skin = """
43                 <screen name="BrowserMenu" position="center,center" size="%(w)d,%(h)d" title="Web Browser - Menu" >
44                         <widget name="menu" position="0,0" zPosition="1" size="200,%(h)d" backgroundColor="#000000" transparent="1" />
45                         <widget source="line" render="Canvas" position="203,0" zPosition="2" size="4,%(h)d" backgroundColor="#000000" transparent="1" alphatest="on"/>
46                         <widget source="list" render="Listbox" position="210,0" zPosition="1" size="%(listW)d,%(listH)d" backgroundColor="#000000" transparent="1">
47                                 <convert type="TemplatedMultiContent">
48                                         {"templates":
49                                                 {"default": (55, [
50                                                         MultiContentEntryText(pos = (10, 1), size = (920, 25), font = 0, flags = RT_VALIGN_CENTER, text = 1),
51                                                         MultiContentEntryText(pos = (10, 30), size = (920, 25), font = 1, flags = RT_VALIGN_CENTER, text = 2),
52                                                 ]),
53                                                 "history": (55, [
54                                                         MultiContentEntryText(pos = (10, 1), size = (150, 25), font = 1, flags = RT_VALIGN_CENTER, text = 1),
55                                                         MultiContentEntryText(pos = (10, 28), size = (150, 25), font = 1, flags = RT_VALIGN_CENTER, text = 2),
56                                                         MultiContentEntryText(pos = (190, 1), size = (690, 25), font = 0, flags = RT_VALIGN_CENTER, text = 3),
57                                                         MultiContentEntryText(pos = (190, 28), size = (690, 25), font = 1, flags = RT_VALIGN_CENTER, text = 4),
58                                                 ]),
59                                                 "downloads": (25, [
60                                                         MultiContentEntryText(pos = (0, 1), size = (600, 24), font=1, flags = RT_HALIGN_LEFT, text = 1),
61                                                         MultiContentEntryText(pos = (610, 1), size = (150, 24), font=1, flags = RT_HALIGN_RIGHT, text = 2),
62                                                         MultiContentEntryProgress(pos = (760, 1), size = (100, 24), percent = 3),
63                                                         MultiContentEntryText(pos = (870, 1), size = (70, 24), font=1, flags = RT_HALIGN_RIGHT, text = 4),
64                                                 ]),
65                                                 "certificates": (85, [
66                                                         MultiContentEntryText(pos = (10, 1), size = (150, 25), font = 1, flags = RT_VALIGN_CENTER, text = 1),
67                                                         MultiContentEntryText(pos = (10, 28), size = (150, 25), font = 1, flags = RT_VALIGN_CENTER, text = 2),
68                                                         MultiContentEntryText(pos = (190, 1), size = (690, 25), font = 0, flags = RT_VALIGN_CENTER, text = 3),
69                                                         MultiContentEntryText(pos = (190, 28), size = (690, 25), font = 1, flags = RT_VALIGN_CENTER, text = 4),
70                                                         MultiContentEntryText(pos = (10, 60), size = (900, 25), font = 0, flags = RT_VALIGN_CENTER, text = 5),
71                                                 ]),
72                                                 "cookies": (75, [
73                                                         MultiContentEntryText(pos = (10, 1), size = (150, 25), font = 1, flags = RT_VALIGN_CENTER, text = 1),
74                                                         MultiContentEntryText(pos = (10, 28), size = (150, 25), font = 1, flags = RT_VALIGN_CENTER, text = 2),
75                                                         MultiContentEntryText(pos = (180, 1), size = (720, 25), font = 0, flags = RT_VALIGN_CENTER, text = 3),
76                                                         MultiContentEntryText(pos = (180, 28), size = (625, 25), font = 1, flags = RT_VALIGN_CENTER, text = 4),
77                                                         MultiContentEntryText(pos = (10, 60), size = (900, 15), font = 2, flags = RT_VALIGN_CENTER, text = 5),
78                                                 ])
79                                                 },
80                                         "fonts": [gFont("Regular", 22), gFont("Regular", 16), gFont("Regular", 13)]
81                                         }
82                                 </convert>
83                         </widget>
84                         <widget name="statuslabel" position="210,%(inputY)d" size="%(listW)d,25" font="Regular;20"  zPosition="2" halign="center" valign="center" backgroundColor="#000000" transparent="0" />
85                         <widget name="input" position="210,%(inputY)d" zPosition="1" size="%(listW)d,25" font="Regular;20" halign="left" valign="bottom" backgroundColor="#000000" transparent="1"/>
86                         <widget name="config" position="210,0" zPosition="2" size="%(listW)d,%(configH)d" backgroundColor="background" transparent="0" />
87
88                         <ePixmap pixmap="skin_default/buttons/button_red_off.png" position="210,%(btnY)d" size="15,16" alphatest="on" />
89                         <widget source="button_red" zPosition="2" render="Pixmap" pixmap="skin_default/buttons/button_red.png" position="210,%(btnY)d" size="15,16" alphatest="on">
90                                 <convert type="ConditionalShowHide" />
91                         </widget>
92                         <widget name="red" position="230,%(btnTxtY)d" size="100,20" foregroundColor="white" backgroundColor="background" font="Regular;18" transparent="1" halign="left" valign="top"/>
93
94                         <ePixmap pixmap="skin_default/buttons/button_green_off.png" position="340,%(btnY)d" size="15,16" zPosition="1" alphatest="on" />
95                         <widget source="button_green" zPosition="2" render="Pixmap" pixmap="skin_default/buttons/button_green.png" position="340,%(btnY)d" size="15,16" alphatest="on">
96                                 <convert type="ConditionalShowHide" />
97                         </widget>
98                         <widget name="green" position="360,%(btnTxtY)d" size="100,20" foregroundColor="white" backgroundColor="background" font="Regular;18" transparent="1" halign="left" valign="top"/>
99
100                         <ePixmap pixmap="skin_default/buttons/button_yellow_off.png" position="470,%(btnY)d" size="15,16" alphatest="on" />
101                         <widget source="button_yellow" zPosition="2" render="Pixmap" pixmap="skin_default/buttons/button_yellow.png" position="470,%(btnY)d" size="15,16" alphatest="on">
102                                 <convert type="ConditionalShowHide" />
103                         </widget>
104                         <widget name="yellow" position="490,%(btnTxtY)d" size="100,20" foregroundColor="white" backgroundColor="background" font="Regular;18" transparent="1" halign="left" valign="top"/>
105
106                         <ePixmap pixmap="skin_default/buttons/button_blue_off.png" position="600,%(btnY)d" size="15,16" alphatest="on" />
107                         <widget source="button_blue" zPosition="2" render="Pixmap" pixmap="skin_default/buttons/button_blue.png" position="600,%(btnY)d" size="15,16" alphatest="on">
108                                 <convert type="ConditionalShowHide" />
109                         </widget>
110                         <widget name="blue" position="620,%(btnTxtY)d" size="200,20" foregroundColor="white" backgroundColor="background" font="Regular;18" transparent="1" halign="left" valign="top"/>
111                 </screen>
112                 """ %{  "w" : width,
113                                 "h" : height,
114                                 "listW" : width - 210, "listH" : height - 90,
115                                 "inputY" : height - 80,
116                                 "configH" : height - 90,
117                                 "btnY" : bof + 2,
118                                 "btnTxtY" : bof
119                         }
120
121         def __init__(self, session, currentTitle, currentUrl, menulist = None):
122                 Screen.__init__(self, session)
123
124                 self.currentUrl = currentUrl
125                 self.currentTitle = currentTitle
126
127                 #Menu
128                 if menulist is None:
129                         self.menu = MenuList([
130                                                 (_("Bookmarks"), self.MENU_BOOKMARKS),
131                                                 (_("History"), self.MENU_HISTORY),
132                                                 (_("Downloads"), self.MENU_DOWNLOADS),
133                                                 (_("Certificates"), self.MENU_CERTS),
134                                                 (_("Cookies"), self.MENU_COOKIES),
135                                                 (_("Settings"), self.MENU_SETTINGS),
136                                 ], enableWrapAround = True)
137                 else:
138                         self.menu = MenuList(menulist, enableWrapAround=True)
139                 self["menu"] = self.menu
140
141                 self["statuslabel"] = Label("")
142                 self["statuslabel"].hide()
143
144                 #Color Buttons
145                 self["button_red"] = Boolean(False)
146                 self["button_green"] = Boolean(False)
147                 self["button_yellow"] = Boolean(False)
148                 self["button_blue"] = Boolean(False)
149                 self.red = Label("")
150                 self.green = Label("")
151                 self.yellow = Label("")
152                 self.blue = Label("")
153                 self["red"] = self.red
154                 self["green"] = self.green
155                 self["yellow"] = self.yellow
156                 self["blue"] = self.blue
157
158                 #Lists
159                 self.detailList = List([], enableWrapAround = True, item_height = 55)
160                 self.detailConfigList = ConfigList([])
161                 self.detailConfigList.l.setSeperation( (BrowserMenu.width - 210) / 2 )
162                 config.plugins.WebBrowser.storage.enabled.addNotifier(self.__cfgExpandableElementChanged, initial_call = False)
163                 config.plugins.WebBrowser.storage.enabled.addNotifier(self.__cfgStoragePathChanged, initial_call = False)
164                 config.plugins.WebBrowser.storage.path.addNotifier(self.__cfgStoragePathChanged, initial_call = False)
165
166                 self.detailInput = EnhancedInput()
167
168                 self["list"] = self.detailList
169                 self["config"] = self.detailConfigList
170                 self["input"] = self.detailInput
171                 self["line"] = CanvasSource()
172
173                 self.__cfgCreateSetup()
174
175                 self.__db = BrowserDB.getInstance()
176                 self.__curMenu = self.MENU_BOOKMARKS
177                 self.__bmList = None
178                 self.__hisList = None
179                 self.__crtList = None
180                 self.__ckList = None
181                 self.__bmNeedle = ""
182                 self.__bmFilterTimer = eTimer()
183                 self.__bmFilterTimer.callback.append(self.__bmFilterCB)
184                 self.__hisNeedle = ""
185                 self.__hisFilterTimer = eTimer()
186                 self.__hisFilterTimer.callback.append(self.__hisFilterCB)
187                 self.__dlRefreshTimer = eTimer()
188                 self.__dlRefreshTimer.callback.append(self.__dlBuildList)
189                 self.__statusTimer = eTimer()
190                 self.__statusTimer.callback.append(self.__hideStatus)
191                 self.__actions = []
192
193                 self.onFirstExecBegin.append(self.__drawSeparator)
194                 self.onFirstExecBegin.append(self.__onMenuChanged)
195                 self.onExecBegin.append(self.__reloadData)
196                 self.onShow.append(self.setKeyboardModeAscii)
197
198                 self["actions"] = ActionMap(["BrowserActions", "ColorActions"],
199                 {
200                         "ok" : self.__actionOk,
201                         "enter" : self.__actionOk,
202                         "exit" : self.__actionExit,
203                         "pageUp" : self.__actionMenuUp,
204                         "pageDown" : self.__actionMenuDown,
205                         "up" : boundFunction(self.__action, "up"),
206                         "down" : boundFunction(self.__action, "down"),
207                         "left" : boundFunction(self.__action, "left"),
208                         "right" : boundFunction(self.__action, "right"),
209                         "red" : boundFunction(self.__action, "red"),
210                         "green" : boundFunction(self.__action, "green"),
211                         "yellow" : boundFunction(self.__action, "yellow"),
212                         "blue" : boundFunction(self.__action, "blue"),
213                         "backspace" : boundFunction(self.__action, "backspace"),
214                         "delete" : boundFunction(self.__action, "delete"),
215                         "ascii": boundFunction(self.__action, "ascii"),
216                         # TODO "text" : self.__text
217                 }, -2)
218
219                 self["numberactions"] = NumberActionMap(["NumberActions"],
220                 {
221                         "1": self.__keyNumberGlobal,
222                         "2": self.__keyNumberGlobal,
223                         "3": self.__keyNumberGlobal,
224                         "4": self.__keyNumberGlobal,
225                         "5": self.__keyNumberGlobal,
226                         "6": self.__keyNumberGlobal,
227                         "7": self.__keyNumberGlobal,
228                         "8": self.__keyNumberGlobal,
229                         "9": self.__keyNumberGlobal,
230                         "0": self.__keyNumberGlobal
231                 }, -2)
232
233                 self.__actionFuncs = {
234                         self.MENU_BOOKMARKS : {
235                                 "up" : self.detailList.selectPrevious,
236                                 "down" : self.detailList.selectNext,
237                                 "left" : self.detailList.selectPrevious,
238                                 "right" : self.detailList.pageDown,
239                                 "ok" : self.__bmOk,
240                                 "enter" : self.__bmOk,
241                                 "red" : self.__bmDelete,
242                                 "green" : self.__bmAdd,
243                                 "yellow" : self.__bmEdit,
244                                 "blue" : self.__bmSetCurrentAsHome,
245                                 "backspace" : self.__bmKeyBackspace,
246                                 "delete" : self.__bmKeyDelete,
247                                 "ascii": self.__bmKeyAscii,
248                                 },
249                         self.MENU_HISTORY : {
250                                 "up" : self.detailList.selectPrevious,
251                                 "down" : self.detailList.selectNext,
252                                 "left" : self.detailList.pageUp,
253                                 "right" : self.detailList.pageDown,
254                                 "ok" : self.__hisOk,
255                                 "enter" : self.__hisOk,
256                                 "red" : self.__hisClear,
257                                 "blue" : self.__hisSetCurrentAsHome,
258                                 "backspace" : self.__hisKeyBackspace,
259                                 "delete" : self.__hisKeyDelete,
260                                 "ascii": self.__hisKeyAscii,
261                                 },
262                         self.MENU_SETTINGS : {
263                                 "up" : self.__cfgKeyUp,
264                                 "down" : self.__cfgKeyDown,
265                                 "left" : self.__cfgKeyLeft,
266                                 "right" : self.__cfgKeyRight,
267                                 "ok" : self.__cfgKeyOK,
268                                 "enter" : self.__cfgKeyOK,
269                                 "red" : self.__cfgCancel,
270                                 "green" : self.__cfgSave,
271                                 "backspace" : self.__cfgKeyBackspace,
272                                 "delete" : self.__cfgKeyDelete,
273                                 "ascii": self.__cfgKeyAscii,
274                                 },
275                         self.MENU_DOWNLOADS : {
276                                 "up" : self.detailList.selectPrevious,
277                                 "down" : self.detailList.selectNext,
278                                 "left" : self.detailList.pageUp,
279                                 "right" : self.detailList.pageDown,
280                                 "red" : self.__dlAbort,
281                                 },
282                         self.MENU_CERTS : {
283                                 "up" : self.detailList.selectPrevious,
284                                 "down" : self.detailList.selectNext,
285                                 "left" : self.detailList.pageUp,
286                                 "right" : self.detailList.pageDown,
287                                 "red" : self.__crtDelete,
288                                 "green" : self.__crtDetails,
289                                 },
290                         self.MENU_COOKIES : {
291                                 "up" : self.detailList.selectPrevious,
292                                 "down" : self.detailList.selectNext,
293                                 "left" : self.detailList.pageUp,
294                                 "right" : self.detailList.pageDown,
295                                 "red" : self.__ckDelete,
296                                 "blue" : self.__ckDeleteAll,
297                                 }
298                 }
299
300         def __close(self):
301                 config.plugins.WebBrowser.storage.enabled.removeNotifier(self.__cfgExpandableElementChanged)
302                 config.plugins.WebBrowser.storage.enabled.removeNotifier(self.__cfgStoragePathChanged)
303                 config.plugins.WebBrowser.storage.path.removeNotifier(self.__cfgStoragePathChanged)
304                 self.close(self.__actions)
305
306         def __actionOk(self):
307                 if self["statuslabel"].visible:
308                         self["statuslabel"].hide()
309                 else:
310                         self.__action("ok")
311
312         def __actionExit(self):
313                 if self["statuslabel"].visible:
314                         self["statuslabel"].hide()
315                 else:
316                         if self.detailConfigList.isChanged():
317                                 self.__cfgSave()
318                         self.__close()
319
320         def __actionMenuUp(self):
321                 self.menu.up()
322                 self.__onMenuChanged()
323
324         def __actionMenuDown(self):
325                 self.menu.down()
326                 self.__onMenuChanged()
327
328         def __reloadData(self):
329                 self.__bmList = self.__db.getBookmarks()
330                 self.__hisList = self.__db.getHistory()
331                 self.__crtList = self.__db.getCerts()
332                 self.__ckList = self.__db.getCookies()
333
334         def __action(self, action):
335                 print "[BrowserMenu].__action :: action='%s'" %action
336                 fnc = self.__actionFuncs[self.__curMenu].get(action, None)
337                 if fnc != None:
338                         fnc()
339
340         def __text(self):
341                 if self.__curMenu == self.MENU_SETTINGS:
342                         self.__cfgKeyText()
343                 elif self.__curMenu == self.MENU_BOOKMARKS:
344                         pass
345
346         def __keyNumberGlobal(self, number):
347                 if self.__curMenu == self.MENU_SETTINGS:
348                         self.__cfgKeyNumberGlobal(number)
349                 elif self.__curMenu == self.MENU_BOOKMARKS:
350                         self.__bmKeyNumberGlobal(number)
351                 elif self.__curMenu == self.MENU_HISTORY:
352                         self.__hisKeyNumberGlobal(number)
353
354         def __onMenuChanged(self):
355                 self.__bmFilterTimer.stop()
356                 self.__hisFilterTimer.stop()
357                 self.__dlRefreshTimer.stop()
358
359                 self.__curMenu = self.menu.getCurrent()[1]
360                 if self.__curMenu == self.MENU_BOOKMARKS:
361                         self.__showMenuList(True)
362                         self.__setButtons(_("Delete"), _("Add"), _("Edit"), _("Set as Startpage"))
363                         self.detailList.style = "default"
364                         self.__bmBuildList()
365                         self.detailInput.setText(self.__bmNeedle)
366                 elif self.__curMenu == self.MENU_HISTORY:
367                         self.__showMenuList(True)
368                         self.__setButtons(_("Clear"), "", "", _("Set as Startpage"))
369                         self.detailList.style = "history"
370                         self.__hisBuildList()
371                         self.detailInput.setText(self.__hisNeedle)
372                 elif self.__curMenu == self.MENU_SETTINGS:
373                         self.__showConfigList()
374                         self.__setButtons(_("Cancel"), _("Save"), "", "")
375                 elif self.__curMenu == self.MENU_DOWNLOADS:
376                         self.__showMenuList()
377                         self.__setButtons(_("Abort"), "", "", "")
378                         self.detailList.style = "downloads"
379                         self.__dlBuildList()
380                 elif self.__curMenu == self.MENU_CERTS:
381                         self.__showMenuList()
382                         self.__setButtons(_("Delete"), _("Details"), "", "")
383                         self.detailList.style = "certificates"
384                         self.__crtBuildList()
385                 elif self.__curMenu == self.MENU_COOKIES:
386                         self.__showMenuList()
387                         self.__setButtons(_("Delete"), "", "", _("Delete All"))
388                         self.detailList.style = "cookies"
389                         self.__ckBuildList()
390
391         def __setButtons(self, red, green, yellow, blue):
392                 self.red.setText(red)
393                 self.__setButtonPixmapVisible(self["button_red"], red)
394                 self.green.setText(green)
395                 self.__setButtonPixmapVisible(self["button_green"], green)
396                 self.yellow.setText(yellow)
397                 self.__setButtonPixmapVisible(self["button_yellow"], yellow)
398                 self.blue.setText(blue)
399                 self.__setButtonPixmapVisible(self["button_blue"], blue)
400
401         def __setButtonPixmapVisible(self, B, label):
402                 show = True
403                 if label == "":
404                         show = False
405                 B.setBoolean(show)
406
407         def __showMenuList(self, hasFilter = False):
408                 if self.detailConfigList.visible:
409                         self.detailConfigList.hide()
410
411 #               if not self.detailList.instance.visible:
412 #                       self.detailList.instance.show()
413                 if hasFilter:
414                         self.detailInput.show()
415                 else:
416                         self.detailInput.hide()
417
418         def __showConfigList(self):
419 #               if self.detailList.instance.visible == 1:
420 #                       self.detailList.instance.hide()
421                 self.detailInput.hide()
422                 if self.detailConfigList.visible == 0:
423                         self.detailConfigList.show()
424
425         def __drawSeparator(self):
426                 self["line"].fill(0, 0, 4, BrowserMenu.height, 0xFF9900)
427                 self["line"].flush()
428
429         def __setStatus(self, text):
430                 print "[BrowserMenu].__setStatus"
431                 self["statuslabel"].setText(text)
432                 self["statuslabel"].show()
433                 self.__statusTimer.startLongTimer(3)
434
435         def __hideStatus(self):
436                 self["statuslabel"].hide()
437                 self.__statusTimer.stop()
438
439         # Config List Methods
440         def __cfgCreateSetup(self):
441                 list = [
442                         getConfigListEntry(_("Home Page"), config.plugins.WebBrowser.home),
443                         getConfigListEntry(_("Page to load on startup"), config.plugins.WebBrowser.startPage),
444                         getConfigListEntry(_("Search Provider"), config.plugins.WebBrowser.searchProvider),
445                         getConfigListEntry(_("Run fullscreen"), config.plugins.WebBrowser.fullscreen),
446                         getConfigListEntry(_("Offset in scroll mode (px)"), config.plugins.WebBrowser.scrollOffset),
447                         getConfigListEntry(_("Target directory for downloads"), config.plugins.WebBrowser.downloadpath),
448                         getConfigListEntry(_("Enable persistent storage"), config.plugins.WebBrowser.storage.enabled),
449                 ]
450                 if config.plugins.WebBrowser.storage.enabled.value:
451                         list.append(getConfigListEntry(_("Path for persistent storage"), config.plugins.WebBrowser.storage.path))
452
453                 self.detailConfigList.setList(list)
454
455         def __cfgExpandableElementChanged(self, element):
456                 self.__cfgCreateSetup()
457
458         def __cfgSave(self):
459                 for x in self.detailConfigList.list:
460                         x[1].save()
461                 self.__setStatus(_("Settings have been saved successfully!"))
462
463         def __cfgStoragePathChanged(self, element):
464                 action = [self.ACTION_STORAGE_PATH,True]
465                 if not action in self.__actions:
466                         self.__actions.append(action)
467
468         def __cfgCancel(self):
469                 dlg = self.session.openWithCallback(self.__cfgCancelCB, MessageBox, _("Do you really want to discard all changes?"), type = MessageBox.TYPE_YESNO)
470                 dlg.setTitle(_("Discard changed settings?"))
471
472         def __cfgCancelCB(self, confirmed):
473                 for x in self.detailConfigList.list:
474                         x[1].cancel()
475                 self.__setStatus(_("All changes to the settings have been discarded!"))
476
477         def __cfgKeyText(self):
478                 from Screens.VirtualKeyBoard import VirtualKeyBoard
479                 self.session.openWithCallback(self.__cfgVirtualKeyBoardCallback, VirtualKeyBoard, title = self.detailConfigList.getCurrent()[0], text = self.detailConfigList.getCurrent()[1].getValue())
480
481         def __cfgVirtualKeyBoardCallback(self, callback = None):
482                 if callback is not None and len(callback):
483                         self.detailConfigList.getCurrent()[1].setValue(callback)
484                         self.detailConfigList.invalidate(self.detailConfigList.getCurrent())
485
486         def  __cfgKeyOK(self):
487                 self.detailConfigList.handleKey(KEY_OK)
488
489         def  __cfgKeyUp(self):
490                 self.detailConfigList.instance.moveSelection(eListbox.moveUp)
491
492         def  __cfgKeyDown(self):
493                 self.detailConfigList.instance.moveSelection(eListbox.moveDown)
494
495         def  __cfgKeyLeft(self):
496                 self.detailConfigList.handleKey(KEY_LEFT)
497
498         def __cfgKeyRight(self):
499                 self.detailConfigList.handleKey(KEY_RIGHT)
500
501         def __cfgKeyHome(self):
502                 self.detailConfigList.handleKey(KEY_HOME)
503
504         def __cfgKeyEnd(self):
505                 self.detailConfigList.handleKey(KEY_END)
506
507         def __cfgKeyDelete(self):
508                 self.detailConfigList.handleKey(KEY_DELETE)
509
510         def __cfgKeyBackspace(self):
511                 self.detailConfigList.handleKey(KEY_BACKSPACE)
512
513         def __cfgKeyToggleOW(self):
514                 self.detailConfigList.handleKey(KEY_TOGGLEOW)
515
516         def __cfgKeyAscii(self):
517                 self.detailConfigList.handleKey(KEY_ASCII)
518
519         def __cfgKeyNumberGlobal(self, number):
520                 self.detailConfigList.handleKey(KEY_0 + number)
521
522         #Bookmark List Methods
523         def __bmOk(self):
524                 print "[BrowserMenu].__bmOk"
525                 if self.detailList.index > 0 and  self.detailList.getCurrent() != None:
526                         current = self.detailList.getCurrent()[0]
527                         print "[BrowserMenu].__bmOk, current = '%s'" %current
528                         self.__actions.append( (self.ACTION_BOOKMARK, current.url) )
529                         self.close( self.__actions )
530                 else:
531                         self.__bmAdd(Bookmark(-1, self.currentTitle, self.currentUrl))
532
533         def __bmAdd(self, bookmark = None):
534                 self.session.openWithCallback(self.__bmEditCB, BookmarkEditor, bookmark)
535
536         def __bmEdit(self):
537                 if self.detailList.index > 0 and  self.detailList.getCurrent() != None:
538                         cur = self.detailList.getCurrent()[0]
539                         self.session.openWithCallback(self.__bmEditCB, BookmarkEditor, cur)
540
541         def __bmEditCB(self, bookmark):
542                 if bookmark != None:
543                         self.__db.setBookmark(bookmark)
544                         self.__bmReload()
545                         self.__setStatus(_("Bookmark '%s' saved succesfully!" %bookmark.name))
546
547         def __bmDelete(self):
548                 if self.detailList.getCurrent() != None:
549                         name = self.detailList.getCurrent()[0].name
550                         print "[BrowserMenu].__bmDelete, name='%s'" %name
551                         dlg = self.session.openWithCallback( self.__bmDeleteCB, MessageBox, _("Do you really want to delete the bookmark '%s'?") %name, type = MessageBox.TYPE_YESNO )
552                         dlg.setTitle(_("Delete Bookmark?"))
553
554         def __bmDeleteCB(self, confirmed):
555                 if confirmed:
556                         self.__db.deleteBookmark( self.detailList.getCurrent()[0] )
557                         name = self.detailList.getCurrent()[0]
558                         self.__setStatus(_("Bookmark '%s' deleted!" %name))
559                         self.__bmReload()
560
561         def __bmSetCurrentAsHome(self):
562                 cur = self.detailList.getCurrent()[0]
563                 self.__setUrlAsHome(cur.url)
564
565         def __bmGetEntryComponent(self, bookmark):
566                 return ( bookmark, bookmark.name, bookmark.url )
567
568         def __bmBuildList(self):
569                 print "[BrowserMenu].__bmBuildList"
570                 list = []
571                 #Suggest current page for adding
572
573                 default = Bookmark(-2, _("Add '%s' to Bookmarks" %self.currentTitle), self.currentUrl)
574                 list.append(self.__bmGetEntryComponent(default))
575                 for b in self.__bmList:
576                         list.append(self.__bmGetEntryComponent(b))
577                 self.detailList.setList(list)
578
579         def __bmReload(self, needle = ""):
580                 print "[BrowserMenu].__bmReload"
581                 self.__bmNeedle = needle
582                 self.__bmList = self.__db.getBookmarks(needle)
583                 self.__bmBuildList()
584
585         def __bmFilterCB(self):
586                 print "[BrowserMenu].__bmFilterCB"
587                 needle = self.detailInput.getText()
588                 if needle != self.__bmNeedle:
589                         self.__bmReload(needle)
590                 else:
591                         self.__bmFilterTimer.stop()
592
593         def __bmKeyNumberGlobal(self, number):
594                 self.detailInput.number(number)
595                 self.__bmFilterTimer.startLongTimer(1)
596
597         def __bmKeyAscii(self):
598                 self.detailInput.handleAscii(getPrevAsciiCode())
599                 self.__bmFilterTimer.startLongTimer(1)
600
601         def __bmKeyDelete(self):
602                 self.detailInput.delete()
603                 self.__bmFilterTimer.startLongTimer(1)
604
605         def __bmKeyBackspace(self):
606                 self.detailInput.deleteBackward()
607                 self.__bmFilterTimer.startLongTimer(1)
608
609         #History list methods
610         def __hisSetCurrentAsHome(self):
611                 if self.detailList.getCurrent() != None:
612                         cur = self.detailList.getCurrent()[0]
613                         self.__setUrlAsHome(cur.url)
614
615         def __setUrlAsHome(self, url):
616                 config.plugins.WebBrowser.home.value = url
617                 config.plugins.WebBrowser.home.save()
618                 self.__setStatus(_("Home page has been set to '%s'" %url))
619
620         def __hisClear(self):
621                 dlg = self.session.openWithCallback(self.__hisClearCB, MessageBox, _("Do you really want to clear the History?"), type = MessageBox.TYPE_YESNO)
622                 dlg.setTitle(_("Clear History?"))
623
624         def __hisClearCB(self, confirmed):
625                 if confirmed:
626                         self.__db.clearHistory()
627                         self.__hisReload()
628                         self.__setStatus(_("History cleared!"))
629
630         def __hisGetEntryComponent(self, historyItem):
631                 date = strftime("%Y-%m-%d", localtime(historyItem.timestamp))
632                 time = strftime("%H:%M:%S", localtime(historyItem.timestamp))
633                 return ( historyItem, date, time, historyItem.title, historyItem.url )
634
635         def __hisReload(self, needle = ""):
636                 print "[BrowserMenu].__hisReload"
637                 self.__hisNeedle = needle
638                 self.__hisList = self.__db.getHistory(needle)
639                 self.__hisBuildList()
640
641         def __hisBuildList(self):
642                 print "[BrowserMenu].__hisBuildList"
643                 history = []
644                 for h in self.__hisList:
645                         history.append(self.__hisGetEntryComponent(h))
646                 self.detailList.setList(history)
647
648         def __hisOk(self):
649                 if self.detailList.getCurrent() != None:
650                         current = self.detailList.getCurrent()[0]
651                         self.__actions.append( (self.ACTION_BOOKMARK, current.url) )
652                         self.close( self.__actions )
653
654         def __hisFilterCB(self):
655                 needle = self.detailInput.getText()
656                 if needle != self.__hisNeedle:
657                         self.__hisReload(needle)
658                 else:
659                         self.__hisFilterTimer.stop()
660
661         def __hisKeyNumberGlobal(self, number):
662                 self.detailInput.number(number)
663                 self.__hisFilterTimer.startLongTimer(1)
664
665         def __hisKeyAscii(self):
666                 self.detailInput.handleAscii(getPrevAsciiCode())
667                 self.__hisFilterTimer.startLongTimer(1)
668
669         def __hisKeyDelete(self):
670                 self.detailInput.delete()
671                 self.__hisFilterTimer.startLongTimer(1)
672
673         def __hisKeyBackspace(self):
674                 self.detailInput.deleteBackward()
675                 self.__hisFilterTimer.startLongTimer(1)
676
677         #Download list methods
678         def __dlGetEntryComponent(self, job):
679                 return ( job, job.name, job.getStatustext(), int(100*job.progress/float(job.end)), str(100*job.progress/float(job.end)) + "%")
680
681         def __dlBuildList(self):
682                 print "[BrowserMenu].__dlBuildList"
683                 downloads = []
684                 for job in downloadManager.getPendingJobs():
685                         downloads.append(self.__dlGetEntryComponent(job))
686                 self.detailList.setList(downloads)
687                 if not self.__dlRefreshTimer.isActive():
688                         self.__dlRefreshTimer.startLongTimer(3)
689
690         def __dlAbort(self):
691                 print "[BrowserMenu].__dlAbort"
692                 cur = self.detailList.getCurrent()
693                 if cur != None:
694                         job = cur[0]
695                         dlg = self.session.openWithCallback( self.__dlAbortCB, MessageBox, _("Do you really want to abort downloading '%s'?") %job.name, type = MessageBox.TYPE_YESNO)
696                         dlg.setTitle(_("Abort Download?"))
697
698         #Certificate list methods
699         def __dlAbortCB(self, confirmed):
700                 if confirmed:
701                         self.detailList.getCurrent()[0].remove(downloadManager.jobDone)
702                         self.__dlBuildList()
703
704         def __crtGetEntryComponent(self, cert):
705                 cn = "CN: %s" %(str(cert.cert.get_subject().commonName))
706                 return ( cert, str(cert.notBefore()), str(cert.notAfter()), str(cert.host), cn, str(cert.cert.digest("sha1")) )
707
708         def __crtReload(self):
709                 print "[BrowserMenu].__crtReload"
710                 self.__crtList = self.__db.getCerts()
711                 self.__crtBuildList()
712
713
714         def __crtBuildList(self):
715                 print "[BrowserMenu].__crtBuildList"
716                 certs = []
717                 for c in self.__crtList:
718                         certs.append(self.__crtGetEntryComponent(c))
719                 self.detailList.setList(certs)
720
721         def __crtDelete(self):
722                 if self.detailList.index >= 0 and self.detailList.getCurrent() != None:
723                         cert = self.detailList.getCurrent()[0]
724                         print "[BrowserMenu].__crtDelete, host=%s,SHA1 fingerprint=%s" %(cert.host,cert.cert.digest("sha1"))
725                         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"))
726                         dlg = self.session.openWithCallback( self.__crtDeleteCB, MessageBox, text, type = MessageBox.TYPE_YESNO )
727                         dlg.setTitle(_("Remove trusted certificate?"))
728
729         def __crtDeleteCB(self, confirmed):
730                 print "[BrowserMenu].__crtDeleteCB"
731                 if confirmed:
732                         cert = self.detailList.getCurrent()[0]
733                         self.__db.deleteCert(cert)
734                         self.__crtReload()
735
736         def __crtDetails(self):
737                 print "[BrowserMenu].__crtDetails"
738                 if self.detailList.index >= 0 and self.detailList.getCurrent() != None:
739                         cert = self.detailList.getCurrent()[0]
740
741                         text = _("Issued for:")
742                         for item in cert.cert.get_subject().get_components():
743                                 text += "\n%s : %s" %(item[0], item[1])
744                         text += _("\n\nIssued from:")
745                         for item in cert.cert.get_issuer().get_components():
746                                 text += "\n%s : %s" %(item[0], item[1])
747
748                         text += _("\n\nValidity:\n")
749                         text += _("From: %s\n") %cert.notBefore()
750                         text += _("Until: %s\n") %cert.notAfter()
751                         text += _("Expired: %s\n") %(_("Yes") if cert.cert.has_expired() else _("No"))
752
753                         dlg = self.session.open(MessageBox, text, type = MessageBox.TYPE_INFO)
754                         dlg.setTitle(_("Certificate Details (%s)") %cert.host)
755
756         def __ckReload(self):
757                 print "[BrowserMenu].__ckReload"
758                 self.__ckList = self.__db.getCookies()
759                 self.__ckBuildList()
760
761         def __ckBuildList(self):
762                 print "[BrowserMenu].__ckBuildList"
763                 cookies = []
764                 for c in self.__ckList:
765                         cookies.append(self.__ckGetEntryComponent(c))
766                 self.detailList.setList(cookies)
767
768         def __ckGetEntryComponent(self, cookie):
769                 date = strftime("%Y-%m-%d", localtime(cookie.expires))
770                 time = strftime("%H:%M:%S", localtime(cookie.expires))
771                 return ( cookie, date, time, cookie.domain, cookie.path, cookie.raw )
772
773         def __ckDelete(self):
774                 if self.detailList.index >= 0 and self.detailList.getCurrent() != None:
775                         cookie = self.detailList.getCurrent()[0]
776                         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)
777                         dlg = self.session.openWithCallback( self.__ckDeleteCB, MessageBox, text, type = MessageBox.TYPE_YESNO )
778                         dlg.setTitle(_("Delete Cookie?"))
779
780         def __ckDeleteCB(self, confirmed):
781                 print "[BrowserMenu].__ckDeleteCB"
782                 if confirmed:
783                         self.__db.deleteCookie(self.detailList.getCurrent()[0])
784                         self.__ckReload()
785                         action = [self.ACTION_COOKIES,True]
786                         if not action in self.__actions:
787                                 self.__actions.append(action)
788
789         def __ckDeleteAll(self):
790                 if self.detailList.index >= 0 and self.detailList.getCurrent() != None:
791                         cookie = self.detailList.getCurrent()[0]
792                         text = _("Do you really want to delete ALL cookies?")
793                         dlg = self.session.openWithCallback( self.__ckDeleteAllCB, MessageBox, text, type = MessageBox.TYPE_YESNO )
794                         dlg.setTitle(_("Delete Cookie?"))
795
796         def __ckDeleteAllCB(self, confirmed):
797                 print "[BrowserMenu].__ckDeleteCB"
798                 if confirmed:
799                         self.__db.deleteAllCookies()
800                         self.__ckReload()
801                         action = [self.ACTION_COOKIES,True]
802                         if not action in self.__actions:
803                                 self.__actions.append(action)