295 """ |
295 """ |
296 Private slot to open a new browser tab. |
296 Private slot to open a new browser tab. |
297 """ |
297 """ |
298 self.newBrowser() |
298 self.newBrowser() |
299 |
299 |
300 # TODO: remove requestData from signature |
|
301 def newBrowser(self, link=None, requestData=None, position=-1): |
300 def newBrowser(self, link=None, requestData=None, position=-1): |
302 """ |
301 """ |
303 Public method to create a new web browser tab. |
302 Public method to create a new web browser tab. |
304 |
303 |
305 @param link link to be shown (string or QUrl) |
304 @param link link to be shown (string or QUrl) |
306 @param requestData tuple containing the request data (QNetworkRequest, |
305 @param requestData page load request data (LoadRequest) |
307 QNetworkAccessManager.Operation, QByteArray) |
|
308 @keyparam position position to create the new tab at or -1 to add it |
306 @keyparam position position to create the new tab at or -1 to add it |
309 to the end (integer) |
307 to the end (integer) |
310 """ |
308 """ |
311 if link is None: |
309 if link is None: |
312 linkName = "" |
310 linkName = "" |
315 else: |
313 else: |
316 linkName = link |
314 linkName = link |
317 |
315 |
318 from .UrlBar.UrlBar import UrlBar |
316 from .UrlBar.UrlBar import UrlBar |
319 urlbar = UrlBar(self.__mainWindow, self) |
317 urlbar = UrlBar(self.__mainWindow, self) |
320 ## if self.__historyCompleter is None: |
318 if self.__historyCompleter is None: |
321 ## import Helpviewer.HelpWindow |
319 import Helpviewer.HelpWindow |
322 ## from .History.HistoryCompleter import HistoryCompletionModel, \ |
320 from .History.HistoryCompleter import HistoryCompletionModel, \ |
323 ## HistoryCompleter |
321 HistoryCompleter |
324 ## self.__historyCompletionModel = HistoryCompletionModel(self) |
322 self.__historyCompletionModel = HistoryCompletionModel(self) |
325 ## self.__historyCompletionModel.setSourceModel( |
323 self.__historyCompletionModel.setSourceModel( |
326 ## Helpviewer.HelpWindow.HelpWindow.historyManager() |
324 Helpviewer.HelpWindow.HelpWindow.historyManager() |
327 ## .historyFilterModel()) |
325 .historyFilterModel()) |
328 ## self.__historyCompleter = HistoryCompleter( |
326 self.__historyCompleter = HistoryCompleter( |
329 ## self.__historyCompletionModel, self) |
327 self.__historyCompletionModel, self) |
330 ## self.__historyCompleter.activated[str].connect(self.__pathSelected) |
328 self.__historyCompleter.activated[str].connect(self.__pathSelected) |
331 ## urlbar.setCompleter(self.__historyCompleter) |
329 urlbar.setCompleter(self.__historyCompleter) |
332 urlbar.returnPressed.connect(self.__lineEditReturnPressed) |
330 urlbar.returnPressed.connect(self.__lineEditReturnPressed) |
333 if position == -1: |
331 if position == -1: |
334 self.__stackedUrlBar.addWidget(urlbar) |
332 self.__stackedUrlBar.addWidget(urlbar) |
335 else: |
333 else: |
336 self.__stackedUrlBar.insertWidget(position, urlbar) |
334 self.__stackedUrlBar.insertWidget(position, urlbar) |
362 self.__mainWindow.closeAct.setEnabled(True) |
360 self.__mainWindow.closeAct.setEnabled(True) |
363 self.__mainWindow.closeAllAct.setEnabled(True) |
361 self.__mainWindow.closeAllAct.setEnabled(True) |
364 self.__closeButton.setEnabled(True) |
362 self.__closeButton.setEnabled(True) |
365 self.__navigationButton.setEnabled(True) |
363 self.__navigationButton.setEnabled(True) |
366 |
364 |
367 ## if not linkName and not requestData: |
365 if not linkName and not requestData: |
368 if not linkName: |
|
369 if Preferences.getWebBrowser("StartupBehavior") == 0: |
366 if Preferences.getWebBrowser("StartupBehavior") == 0: |
370 linkName = Preferences.getWebBrowser("HomePage") |
367 linkName = Preferences.getWebBrowser("HomePage") |
371 elif Preferences.getWebBrowser("StartupBehavior") == 1: |
368 elif Preferences.getWebBrowser("StartupBehavior") == 1: |
372 linkName = "eric:speeddial" |
369 linkName = "eric:speeddial" |
373 |
370 |
379 else: |
376 else: |
380 self.setTabText( |
377 self.setTabText( |
381 index, |
378 index, |
382 self.__elide(browser.documentTitle().replace("&", "&&"))) |
379 self.__elide(browser.documentTitle().replace("&", "&&"))) |
383 self.setTabToolTip(index, browser.documentTitle()) |
380 self.setTabToolTip(index, browser.documentTitle()) |
384 ## elif requestData: |
381 elif requestData: |
385 ## browser.load(*requestData) |
382 browser.load(requestData) |
386 |
383 |
387 # TODO: remove requestData from signature |
|
388 def newBrowserAfter(self, browser, link=None, requestData=None): |
384 def newBrowserAfter(self, browser, link=None, requestData=None): |
389 """ |
385 """ |
390 Public method to create a new web browser tab after a given one. |
386 Public method to create a new web browser tab after a given one. |
391 |
387 |
392 @param browser reference to the browser to add after (WebBrowserView) |
388 @param browser reference to the browser to add after (WebBrowserView) |
393 @param link link to be shown (string or QUrl) |
389 @param link link to be shown (string or QUrl) |
394 @param requestData tuple containing the request data (QNetworkRequest, |
390 @param requestData page load request data (LoadRequest) |
395 QNetworkAccessManager.Operation, QByteArray) |
|
396 """ |
391 """ |
397 if browser: |
392 if browser: |
398 position = self.indexOf(browser) + 1 |
393 position = self.indexOf(browser) + 1 |
399 else: |
394 else: |
400 position = -1 |
395 position = -1 |
891 self.currentBrowser().setSource(url) |
886 self.currentBrowser().setSource(url) |
892 ## self.currentBrowser().setSource( |
887 ## self.currentBrowser().setSource( |
893 ## None, (request, QNetworkAccessManager.GetOperation, b"")) |
888 ## None, (request, QNetworkAccessManager.GetOperation, b"")) |
894 self.currentBrowser().setFocus() |
889 self.currentBrowser().setFocus() |
895 |
890 |
896 ## def __pathSelected(self, path): |
891 def __pathSelected(self, path): |
897 ## """ |
892 """ |
898 ## Private slot called when a URL is selected from the completer. |
893 Private slot called when a URL is selected from the completer. |
899 ## |
894 |
900 ## @param path path to be shown (string) |
895 @param path path to be shown (string) |
901 ## """ |
896 """ |
902 ## url = self.__guessUrlFromPath(path) |
897 url = self.__guessUrlFromPath(path) |
903 ## self.currentBrowser().setSource(url) |
898 self.currentBrowser().setSource(url) |
904 |
899 |
905 def __guessUrlFromPath(self, path): |
900 def __guessUrlFromPath(self, path): |
906 """ |
901 """ |
907 Private method to guess an URL given a path string. |
902 Private method to guess an URL given a path string. |
908 |
903 |
909 @param path path string to guess an URL for (string) |
904 @param path path string to guess an URL for (string) |
910 @return guessed URL (QUrl) |
905 @return guessed URL (QUrl) |
911 """ |
906 """ |
912 # TODO: Open Search |
907 manager = self.__mainWindow.openSearchManager() |
913 ## manager = self.__mainWindow.openSearchManager() |
908 path = Utilities.fromNativeSeparators(path) |
914 ## path = Utilities.fromNativeSeparators(path) |
909 url = manager.convertKeywordSearchToUrl(path) |
915 ## url = manager.convertKeywordSearchToUrl(path) |
910 if url.isValid(): |
916 ## if url.isValid(): |
911 return url |
917 ## return url |
|
918 |
912 |
919 try: |
913 try: |
920 url = QUrl.fromUserInput(path) |
914 url = QUrl.fromUserInput(path) |
921 except AttributeError: |
915 except AttributeError: |
922 url = QUrl(path) |
916 url = QUrl(path) |
925 url.path() == "home": |
919 url.path() == "home": |
926 url = QUrl("eric:home") |
920 url = QUrl("eric:home") |
927 |
921 |
928 # TODO: extend this logic to about:config (open config dialog) |
922 # TODO: extend this logic to about:config (open config dialog) |
929 |
923 |
930 ## if url.scheme() in ["s", "search"]: |
924 if url.scheme() in ["s", "search"]: |
931 ## url = manager.currentEngine().searchUrl(url.path().strip()) |
925 url = manager.currentEngine().searchUrl(url.path().strip()) |
932 |
926 |
933 if url.scheme() != "" and \ |
927 if url.scheme() != "" and \ |
934 (url.host() != "" or url.path() != ""): |
928 (url.host() != "" or url.path() != ""): |
935 return url |
929 return url |
936 |
930 |