Esempio n. 1
0
 def serialize(self):
     # WORKAROUND for https://github.com/qutebrowser/qutebrowser/issues/2289
     # FIXME:qtwebengine can we get rid of this with Qt 5.8.1?
     scheme = self._history.currentItem().url().scheme()
     if scheme in ['view-source', 'chrome']:
         raise browsertab.WebTabError("Can't serialize special URL!")
     return qtutils.serialize(self._history)
Esempio n. 2
0
    def _remove_tab(self, tab):
        """Remove a tab from the tab list and delete it properly.

        Args:
            tab: The QWebView to be closed.
        """
        idx = self.indexOf(tab)
        if idx == -1:
            raise ValueError(
                "tab {} is not contained in TabbedWidget!".format(tab))
        if tab is self._now_focused:
            self._now_focused = None
        if tab is objreg.get(
                'last-focused-tab', None, scope='window', window=self._win_id):
            objreg.delete('last-focused-tab',
                          scope='window',
                          window=self._win_id)
        if tab.cur_url.isValid():
            history_data = qtutils.serialize(tab.history())
            entry = UndoEntry(tab.cur_url, history_data)
            self._undo_stack.append(entry)
        elif tab.cur_url.isEmpty():
            # There are some good reasons why an URL could be empty
            # (target="_blank" with a download, see [1]), so we silently ignore
            # this.
            # [1] https://github.com/The-Compiler/qutebrowser/issues/163
            pass
        else:
            # We display a warnings for URLs which are not empty but invalid -
            # but we don't return here because we want the tab to close either
            # way.
            urlutils.invalid_url_error(self._win_id, tab.cur_url, "saving tab")
        tab.shutdown()
        self.removeTab(idx)
        tab.deleteLater()
Esempio n. 3
0
    def _remove_tab(self, tab):
        """Remove a tab from the tab list and delete it properly.

        Args:
            tab: The QWebView to be closed.
        """
        idx = self.indexOf(tab)
        if idx == -1:
            raise ValueError("tab {} is not contained in TabbedWidget!".format(
                tab))
        if tab is self._now_focused:
            self._now_focused = None
        if tab is objreg.get('last-focused-tab', None, scope='window',
                             window=self._win_id):
            objreg.delete('last-focused-tab', scope='window',
                          window=self._win_id)
        if tab.cur_url.isValid():
            history_data = qtutils.serialize(tab.history())
            entry = UndoEntry(tab.cur_url, history_data)
            self._undo_stack.append(entry)
        elif tab.cur_url.isEmpty():
            # There are some good reasons why an URL could be empty
            # (target="_blank" with a download, see [1]), so we silently ignore
            # this.
            # [1] https://github.com/The-Compiler/qutebrowser/issues/163
            pass
        else:
            # We display a warnings for URLs which are not empty but invalid -
            # but we don't return here because we want the tab to close either
            # way.
            urlutils.invalid_url_error(self._win_id, tab.cur_url, "saving tab")
        tab.shutdown()
        self.removeTab(idx)
        tab.deleteLater()
Esempio n. 4
0
    def _remove_tab(self, tab):
        """Remove a tab from the tab list and delete it properly.

        Args:
            tab: The QWebView to be closed.

        Raise:
            ValueError if the tab is not in the QTabWidget.
        """
        idx = self.indexOf(tab)
        if idx == -1:
            raise ValueError("tab {} is not contained in TabbedWidget!".format(
                tab))
        if tab is self._now_focused:
            self._now_focused = None
        if tab is objreg.get('last-focused-tab', None):
            objreg.delete('last-focused-tab')
        if not tab.cur_url.isEmpty():
            qtutils.ensure_valid(tab.cur_url)
            history_data = qtutils.serialize(tab.history())
            entry = UndoEntry(tab.cur_url, history_data)
            self._undo_stack.append(entry)
        tab.shutdown()
        self._tabs.remove(tab)
        self.removeTab(idx)
        tab.deleteLater()
Esempio n. 5
0
    def tab_clone(self, bg=False, window=False):
        """Duplicate the current tab.

        Args:
            bg: Open in a background tab.
            window: Open in a new window.

        Return:
            The new QWebView.
        """
        if bg and window:
            raise cmdexc.CommandError("Only one of -b/-w can be given!")
        cur_tabbed_browser = self._tabbed_browser()
        curtab = self._current_widget()
        cur_title = cur_tabbed_browser.page_title(self._current_index())
        # The new tab could be in a new tabbed_browser (e.g. because of
        # tabs-are-windows being set)
        new_tabbed_browser = self._tabbed_browser(window)
        newtab = new_tabbed_browser.tabopen(background=bg, explicit=True)
        new_tabbed_browser = objreg.get('tabbed-browser', scope='window',
                                        window=newtab.win_id)
        idx = new_tabbed_browser.indexOf(newtab)
        new_tabbed_browser.set_page_title(idx, cur_title)
        new_tabbed_browser.setTabIcon(idx, curtab.icon())
        newtab.keep_icon = True
        newtab.setZoomFactor(curtab.zoomFactor())
        history = qtutils.serialize(curtab.history())
        qtutils.deserialize(history, newtab.history())
        return newtab
Esempio n. 6
0
    def tab_clone(self, bg=False, window=False):
        """Duplicate the current tab.

        Args:
            bg: Open in a background tab.
            window: Open in a new window.

        Return:
            The new QWebView.
        """
        if bg and window:
            raise cmdexc.CommandError("Only one of -b/-w can be given!")
        cur_tabbed_browser = self._tabbed_browser()
        curtab = self._current_widget()
        cur_title = cur_tabbed_browser.page_title(self._current_index())
        # The new tab could be in a new tabbed_browser (e.g. because of
        # tabs-are-windows being set)
        new_tabbed_browser = self._tabbed_browser(window)
        newtab = new_tabbed_browser.tabopen(background=bg, explicit=True)
        new_tabbed_browser = objreg.get('tabbed-browser',
                                        scope='window',
                                        window=newtab.win_id)
        idx = new_tabbed_browser.indexOf(newtab)
        new_tabbed_browser.set_page_title(idx, cur_title)
        new_tabbed_browser.setTabIcon(idx, curtab.icon())
        newtab.keep_icon = True
        newtab.setZoomFactor(curtab.zoomFactor())
        history = qtutils.serialize(curtab.history())
        qtutils.deserialize(history, newtab.history())
        return newtab
Esempio n. 7
0
def test_serialize(obj):
    """Test a serialize/deserialize round trip.

    Args:
        obj: The object to test with.
    """
    new_obj = type(obj)()
    qtutils.deserialize(qtutils.serialize(obj), new_obj)
    assert new_obj == obj
Esempio n. 8
0
def test_serialize(obj):
    """Test a serialize/deserialize round trip.

    Args:
        obj: The object to test with.
    """
    new_obj = type(obj)()
    qtutils.deserialize(qtutils.serialize(obj), new_obj)
    assert new_obj == obj
Esempio n. 9
0
 def serialize(self):
     if not qtutils.version_check('5.9'):
         # WORKAROUND for
         # https://github.com/qutebrowser/qutebrowser/issues/2289
         # Don't use the history's currentItem here, because of
         # https://bugreports.qt.io/browse/QTBUG-59599 and because it doesn't
         # contain view-source.
         scheme = self._tab.url().scheme()
         if scheme in ['view-source', 'chrome']:
             raise browsertab.WebTabError("Can't serialize special URL!")
     return qtutils.serialize(self._history)
Esempio n. 10
0
 def serialize(self):
     if not qtutils.version_check('5.9', compiled=False):
         # WORKAROUND for
         # https://github.com/qutebrowser/qutebrowser/issues/2289
         # Don't use the history's currentItem here, because of
         # https://bugreports.qt.io/browse/QTBUG-59599 and because it doesn't
         # contain view-source.
         scheme = self._tab.url().scheme()
         if scheme in ['view-source', 'chrome']:
             raise browsertab.WebTabError("Can't serialize special URL!")
     return qtutils.serialize(self._history)
Esempio n. 11
0
 def serialize(self):
     # WORKAROUND (remove this when we bump the requirements to 5.9)
     # https://bugreports.qt.io/browse/QTBUG-59599
     if self._history.count() == 0:
         raise browsertab.WebTabError("Can't serialize page without "
                                      "history!")
     # WORKAROUND (FIXME: remove this when we bump the requirements to 5.9?)
     # https://github.com/qutebrowser/qutebrowser/issues/2289
     scheme = self._history.currentItem().url().scheme()
     if scheme in ['view-source', 'chrome']:
         raise browsertab.WebTabError("Can't serialize special URL!")
     return qtutils.serialize(self._history)
Esempio n. 12
0
    def tab_clone(self, bg=False):
        """Duplicate the current tab.

        Args:
            bg: Open in a background tab.

        Return:
            The new QWebView.
        """
        curtab = self._current_widget()
        tabbed_browser = objreg.get('tabbed-browser')
        newtab = tabbed_browser.tabopen(background=bg, explicit=True)
        history = qtutils.serialize(curtab.history())
        qtutils.deserialize(history, newtab.history())
        return newtab
Esempio n. 13
0
    def tab_clone(self, bg=False, window=False):
        """Duplicate the current tab.

        Args:
            bg: Open in a background tab.
            window: Open in a new window.

        Return:
            The new QWebView.
        """
        if bg and window:
            raise cmdexc.CommandError("Only one of -b/-w can be given!")
        curtab = self._current_widget()
        tabbed_browser = self._tabbed_browser(window)
        newtab = tabbed_browser.tabopen(background=bg, explicit=True)
        history = qtutils.serialize(curtab.history())
        qtutils.deserialize(history, newtab.history())
        return newtab
Esempio n. 14
0
    def tab_clone(self, bg=False, window=False):
        """Duplicate the current tab.

        Args:
            bg: Open in a background tab.
            window: Open in a new window.

        Return:
            The new QWebView.
        """
        if bg and window:
            raise cmdexc.CommandError("Only one of -b/-w can be given!")
        curtab = self._current_widget()
        tabbed_browser = self._tabbed_browser(window)
        newtab = tabbed_browser.tabopen(background=bg, explicit=True)
        history = qtutils.serialize(curtab.history())
        qtutils.deserialize(history, newtab.history())
        return newtab
Esempio n. 15
0
    def tab_clone(self, bg=False, window=False):
        """Duplicate the current tab.

        Args:
            bg: Open in a background tab.
            window: Open in a new window.

        Return:
            The new QWebView.
        """
        if bg and window:
            raise cmdexc.CommandError("Only one of -b/-w can be given!")
        curtab = self._current_widget()
        tabbed_browser = self._tabbed_browser(window)
        newtab = tabbed_browser.tabopen(background=bg, explicit=True)
        idx = tabbed_browser.indexOf(newtab)
        tabbed_browser.setTabText(idx, curtab.title().replace('&', '&&'))
        tabbed_browser.setTabIcon(idx, curtab.icon())
        newtab.keep_icon = True
        newtab.setZoomFactor(curtab.zoomFactor())
        history = qtutils.serialize(curtab.history())
        qtutils.deserialize(history, newtab.history())
        return newtab
Esempio n. 16
0
 def serialize(self):
     return qtutils.serialize(self._history)