16 |
16 |
17 from eric7 import Preferences, Utilities |
17 from eric7 import Preferences, Utilities |
18 from eric7.EricWidgets import EricMessageBox |
18 from eric7.EricWidgets import EricMessageBox |
19 from eric7.EricWidgets.EricApplication import ericApp |
19 from eric7.EricWidgets.EricApplication import ericApp |
20 from eric7.Utilities.AutoSaver import AutoSaver |
20 from eric7.Utilities.AutoSaver import AutoSaver |
|
21 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow |
21 |
22 |
22 |
23 |
23 class OpenSearchManager(QObject): |
24 class OpenSearchManager(QObject): |
24 """ |
25 """ |
25 Class implementing a manager for open search engines. |
26 Class implementing a manager for open search engines. |
168 @return flag indicating success (boolean) |
169 @return flag indicating success (boolean) |
169 """ |
170 """ |
170 if not url.isValid(): |
171 if not url.isValid(): |
171 return False |
172 return False |
172 |
173 |
173 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow |
|
174 |
|
175 reply = WebBrowserWindow.networkManager().get(QNetworkRequest(url)) |
174 reply = WebBrowserWindow.networkManager().get(QNetworkRequest(url)) |
176 reply.finished.connect(lambda: self.__engineFromUrlAvailable(reply)) |
175 reply.finished.connect(lambda: self.__engineFromUrlAvailable(reply)) |
177 reply.setParent(self) |
176 reply.setParent(self) |
178 self.__replies.append(reply) |
177 self.__replies.append(reply) |
179 |
178 |
185 |
184 |
186 @param filename name of a file containing the engine definition |
185 @param filename name of a file containing the engine definition |
187 (string) |
186 (string) |
188 @return flag indicating success (boolean) |
187 @return flag indicating success (boolean) |
189 """ |
188 """ |
|
189 from .OpenSearchReader import OpenSearchReader |
|
190 |
190 file_ = QFile(filename) |
191 file_ = QFile(filename) |
191 if not file_.open(QIODevice.OpenModeFlag.ReadOnly): |
192 if not file_.open(QIODevice.OpenModeFlag.ReadOnly): |
192 return False |
193 return False |
193 |
|
194 from .OpenSearchReader import OpenSearchReader |
|
195 |
194 |
196 reader = OpenSearchReader() |
195 reader = OpenSearchReader() |
197 engine = reader.read(file_) |
196 engine = reader.read(file_) |
198 |
197 |
199 if not self.__addEngineByEngine(engine): |
198 if not self.__addEngineByEngine(engine): |
275 if not ok: |
276 if not ok: |
276 return |
277 return |
277 |
278 |
278 actionUrl.setQuery(searchUrlQuery) |
279 actionUrl.setQuery(searchUrlQuery) |
279 |
280 |
280 from .OpenSearchEngine import OpenSearchEngine |
|
281 |
|
282 engine = OpenSearchEngine() |
281 engine = OpenSearchEngine() |
283 engine.setName(engineName) |
282 engine.setName(engineName) |
284 engine.setDescription(engineName) |
283 engine.setDescription(engineName) |
285 engine.setSearchUrlTemplate( |
284 engine.setSearchUrlTemplate( |
286 actionUrl.toDisplayString(QUrl.ComponentFormattingOption.FullyDecoded) |
285 actionUrl.toDisplayString(QUrl.ComponentFormattingOption.FullyDecoded) |
342 """ |
341 """ |
343 Public method to save the search engine definitions to files. |
342 Public method to save the search engine definitions to files. |
344 |
343 |
345 @param dirName name of the directory to write the files to (string) |
344 @param dirName name of the directory to write the files to (string) |
346 """ |
345 """ |
|
346 from .OpenSearchWriter import OpenSearchWriter |
|
347 |
347 qdir = QDir() |
348 qdir = QDir() |
348 if not qdir.mkpath(dirName): |
349 if not qdir.mkpath(dirName): |
349 return |
350 return |
350 qdir.setPath(dirName) |
351 qdir.setPath(dirName) |
351 |
|
352 from .OpenSearchWriter import OpenSearchWriter |
|
353 |
352 |
354 writer = OpenSearchWriter() |
353 writer = OpenSearchWriter() |
355 |
354 |
356 for engine in list(self.__engines.values()): |
355 for engine in list(self.__engines.values()): |
357 name = self.generateEngineFileName(engine.name()) |
356 name = self.generateEngineFileName(engine.name()) |
473 Private slot to add a search engine from the net. |
472 Private slot to add a search engine from the net. |
474 |
473 |
475 @param reply reference to the network reply |
474 @param reply reference to the network reply |
476 @type QNetworkReply |
475 @type QNetworkReply |
477 """ |
476 """ |
|
477 from .OpenSearchReader import OpenSearchReader |
|
478 |
478 reply.close() |
479 reply.close() |
479 if reply in self.__replies: |
480 if reply in self.__replies: |
480 self.__replies.remove(reply) |
481 self.__replies.remove(reply) |
481 |
482 |
482 if reply.error() == QNetworkReply.NetworkError.NoError: |
483 if reply.error() == QNetworkReply.NetworkError.NoError: |
483 from .OpenSearchReader import OpenSearchReader |
|
484 |
|
485 reader = OpenSearchReader() |
484 reader = OpenSearchReader() |
486 engine = reader.read(reply) |
485 engine = reader.read(reply) |
487 |
486 |
488 if not engine.isValid(): |
487 if not engine.isValid(): |
489 return |
488 return |
496 |
495 |
497 if not self.__addEngineByEngine(engine): |
496 if not self.__addEngineByEngine(engine): |
498 return |
497 return |
499 else: |
498 else: |
500 # some error happened |
499 # some error happened |
501 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow |
|
502 |
|
503 WebBrowserWindow.getWindow().statusBar().showMessage( |
500 WebBrowserWindow.getWindow().statusBar().showMessage( |
504 reply.errorString(), 10000 |
501 reply.errorString(), 10000 |
505 ) |
502 ) |
506 |
503 |
507 def convertKeywordSearchToUrl(self, keywordSearch): |
504 def convertKeywordSearchToUrl(self, keywordSearch): |