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