13 # Copyright (C) David Rosca <nowrep@gmail.com> |
13 # Copyright (C) David Rosca <nowrep@gmail.com> |
14 # |
14 # |
15 |
15 |
16 from __future__ import unicode_literals |
16 from __future__ import unicode_literals |
17 |
17 |
18 from PyQt5.QtCore import pyqtSlot, QObject, QUrl, QByteArray |
18 from PyQt5.QtCore import pyqtSlot, pyqtProperty, QObject, QUrl |
19 |
19 |
20 import WebBrowser.WebBrowserWindow |
20 import WebBrowser.WebBrowserWindow |
|
21 |
|
22 from .StartPageJsObject import StartPageJsObject |
|
23 from .PasswordManagerJsObject import PasswordManagerJsObject |
21 |
24 |
22 |
25 |
23 class ExternalJsObject(QObject): |
26 class ExternalJsObject(QObject): |
24 """ |
27 """ |
25 Class implementing the endpoint of our web channel. |
28 Class implementing the endpoint of our web channel. |
32 @type WebBrowserPage |
35 @type WebBrowserPage |
33 """ |
36 """ |
34 super(ExternalJsObject, self).__init__(page) |
37 super(ExternalJsObject, self).__init__(page) |
35 |
38 |
36 self.__page = page |
39 self.__page = page |
|
40 |
|
41 self.__startPage = None |
|
42 self.__passwordManager = None |
37 |
43 |
38 def page(self): |
44 def page(self): |
39 """ |
45 """ |
40 Public method returning a reference to the web page object. |
46 Public method returning a reference to the web page object. |
41 |
47 |
42 @return reference to the web page object |
48 @return reference to the web page object |
43 @rtype WebBrowserPage |
49 @rtype WebBrowserPage |
44 """ |
50 """ |
45 return self.__page |
51 return self.__page |
46 |
52 |
47 @pyqtSlot(result=QObject) |
53 @pyqtProperty(QObject, constant=True) |
|
54 def passwordManager(self): |
|
55 """ |
|
56 Public method to get a reference to the password manager JavaScript |
|
57 object. |
|
58 |
|
59 @return reference to the password manager JavaScript object |
|
60 @rtype StartPageJsObject |
|
61 """ |
|
62 if self.__passwordManager is None: |
|
63 self.__passwordManager = PasswordManagerJsObject(self) |
|
64 |
|
65 return self.__passwordManager |
|
66 |
|
67 @pyqtProperty(QObject, constant=True) |
48 def speedDial(self): |
68 def speedDial(self): |
49 """ |
69 """ |
50 Public method returning a reference to a speed dial object. |
70 Public method returning a reference to a speed dial object. |
51 |
71 |
52 @return reference to a speed dial object |
72 @return reference to a speed dial object |
57 |
77 |
58 # TODO: SpeedDial |
78 # TODO: SpeedDial |
59 ## return WebBrowser.WebBrowserWindow.WebBrowserWindow.speedDial() |
79 ## return WebBrowser.WebBrowserWindow.WebBrowserWindow.speedDial() |
60 return None |
80 return None |
61 |
81 |
62 @pyqtSlot(str) |
82 @pyqtProperty(QObject, constant=True) |
63 def AddSearchProvider(self, engineUrl): |
83 def startPage(self): |
64 """ |
84 """ |
65 Public slot to add a search provider. |
85 Public method to get a reference to the start page JavaScript object. |
66 |
86 |
67 @param engineUrl engineUrl of the XML file defining the search provider |
87 @return reference to the start page JavaScript object |
68 @type str |
88 @rtype StartPageJsObject |
69 """ |
89 """ |
70 WebBrowser.WebBrowserWindow.WebBrowserWindow.openSearchManager()\ |
90 if self.__startPage is None: |
71 .addEngine(QUrl(engineUrl)) |
91 self.__startPage = StartPageJsObject(self) |
72 |
|
73 @pyqtSlot(str, str, str, QByteArray) |
|
74 def formSubmitted(self, urlStr, userName, password, data): |
|
75 """ |
|
76 Public slot passing form data to the password manager. |
|
77 |
92 |
78 @param urlStr form submission URL |
93 return self.__startPage |
79 @type str |
|
80 @param userName name of the user |
|
81 @type str |
|
82 @param password user password |
|
83 @type str |
|
84 @param data data to be submitted |
|
85 @type QByteArray |
|
86 """ |
|
87 import WebBrowser.WebBrowserWindow |
|
88 WebBrowser.WebBrowserWindow.WebBrowserWindow.passwordManager()\ |
|
89 .formSubmitted(urlStr, userName, password, data, |
|
90 self.page()) |
|
91 |
|
92 @pyqtSlot(result=str) |
|
93 def providerString(self): |
|
94 """ |
|
95 Public method to get a string for the search provider. |
|
96 |
|
97 @return string for the search provider (string) |
|
98 """ |
|
99 return (self.tr("Search results provided by {0}") |
|
100 .format(self.__page.view().mainWindow().openSearchManager() |
|
101 .currentEngineName())) |
|
102 |
|
103 @pyqtSlot(str, result=str) |
|
104 def searchUrl(self, searchStr): |
|
105 """ |
|
106 Public method to get the search URL for the given search term. |
|
107 |
|
108 @param searchStr search term (string) |
|
109 @return search URL (string) |
|
110 """ |
|
111 return bytes( |
|
112 self.__page.view().mainWindow().openSearchManager().currentEngine() |
|
113 .searchUrl(searchStr).toEncoded()).decode() |
|