Exemplo n.º 1
0
 def _set(self, value, settings=None):
     utils.unused(settings)
     setter = getattr(QWebEngineProfile.defaultProfile(), self._setter)
     setter(
         QWebEngineProfile.AllowPersistentCookies if value else
         QWebEngineProfile.NoPersistentCookies
     )
Exemplo n.º 2
0
    def set_perc(self, x, y):
        """Setter to be used as a Qt slot.

        Args:
            x: The x percentage (int), currently ignored.
            y: The y percentage (int)
        """
        utils.unused(x)
        self._set_text(self._strings.get(y, '[???]'))
Exemplo n.º 3
0
    def to_doc(self, value, indent=0):
        """Get a string with the given value for the documentation.

        This currently uses asciidoc syntax.
        """
        utils.unused(indent)  # only needed for Dict/List
        if not value:
            return 'empty'
        return '+pass:[{}]+'.format(html.escape(self.to_str(value)))
Exemplo n.º 4
0
    def to_doc(self, value, indent=0):
        """Get a string with the given value for the documentation.

        This currently uses asciidoc syntax.
        """
        utils.unused(indent)  # only needed for Dict/List
        str_value = self.to_str(value)
        if not str_value:
            return 'empty'
        return '+pass:[{}]+'.format(html.escape(str_value))
Exemplo n.º 5
0
def session(*, info=None):
    """A CompletionModel filled with session names."""
    from qutebrowser.misc import sessions
    utils.unused(info)
    model = completionmodel.CompletionModel()
    try:
        sess = ((name, ) for name in sessions.session_manager.list_sessions()
                if not name.startswith('_'))
        model.add_category(listcategory.ListCategory("Sessions", sess))
    except OSError:
        log.completion.exception("Failed to list sessions!")
    return model
Exemplo n.º 6
0
def quickmark(*, info=None):
    """A CompletionModel filled with all quickmarks."""
    def delete(data: Sequence[str]) -> None:
        """Delete a quickmark from the completion menu."""
        name = data[0]
        quickmark_manager = objreg.get('quickmark-manager')
        log.completion.debug('Deleting quickmark {}'.format(name))
        quickmark_manager.delete(name)

    utils.unused(info)
    model = completionmodel.CompletionModel(column_widths=(30, 70, 0))
    marks = objreg.get('quickmark-manager').marks.items()
    model.add_category(listcategory.ListCategory('Quickmarks', marks,
                                                 delete_func=delete,
                                                 sort=False))
    return model
Exemplo n.º 7
0
    def present(
        self,
        qt_notification: "QWebEngineNotification",
        *,
        replaces_id: Optional[int],
    ) -> int:
        utils.unused(replaces_id)  # QSystemTray can only show one message
        self.close_id.emit(self.NOTIFICATION_ID)
        self._systray.show()

        icon = self._convert_icon(qt_notification.icon())
        msg = self._format_message(qt_notification.message(), qt_notification.origin())

        self._systray.showMessage(qt_notification.title(), msg, icon)

        return self.NOTIFICATION_ID
Exemplo n.º 8
0
def bookmark(*, info=None):
    """A CompletionModel filled with all bookmarks."""
    def delete(data: typing.Sequence[str]) -> None:
        """Delete a bookmark from the completion menu."""
        urlstr = data[0]
        log.completion.debug('Deleting bookmark {}'.format(urlstr))
        bookmark_manager = objreg.get('bookmark-manager')
        bookmark_manager.delete(urlstr)

    utils.unused(info)
    model = completionmodel.CompletionModel(column_widths=(30, 70, 0))
    marks = objreg.get('bookmark-manager').marks.items()
    model.add_category(listcategory.ListCategory('Bookmarks', marks,
                                                 delete_func=delete,
                                                 sort=False))
    return model
Exemplo n.º 9
0
    def rect_on_view(self,
                     *,
                     elem_geometry: QRect = None,
                     no_js: bool = False) -> QRect:
        """Get the geometry of the element relative to the webview.

        Skipping of small rectangles is due to <a> elements containing other
        elements with "display:block" style, see
        https://github.com/qutebrowser/qutebrowser/issues/1298

        Args:
            elem_geometry: The geometry of the element, or None.
                           Ignored with QtWebEngine.
            no_js: Fall back to the Python implementation.
                   Ignored with QtWebEngine.
        """
        utils.unused(elem_geometry)
        utils.unused(no_js)
        rects = self._js_dict['rects']
        for rect in rects:
            # FIXME:qtwebengine
            # width = rect.get("width", 0)
            # height = rect.get("height", 0)
            width = rect['width']
            height = rect['height']
            left = rect['left']
            top = rect['top']
            if width > 1 and height > 1:
                # Fix coordinates according to zoom level
                # We're not checking for zoom.text_only here as that doesn't
                # exist for QtWebEngine.
                zoom = self._tab.zoom.factor()
                rect = QRect(int(left * zoom), int(top * zoom),
                             int(width * zoom), int(height * zoom))
                # FIXME:qtwebengine
                # frame = self._elem.webFrame()
                # while frame is not None:
                #     # Translate to parent frames' position (scroll position
                #     # is taken care of inside getClientRects)
                #     rect.translate(frame.geometry().topLeft())
                #     frame = frame.parentFrame()
                return rect
        log.webelem.debug("Couldn't find rectangle for {!r} ({})".format(
            self, rects))
        return QRect()
Exemplo n.º 10
0
def init(args: argparse.Namespace) -> None:
    """Initialize all QWeb(Engine)Settings."""
    utils.unused(args)
    if objects.backend == usertypes.Backend.QtWebEngine:
        from qutebrowser.browser.webengine import webenginesettings
        webenginesettings.init()
    elif objects.backend == usertypes.Backend.QtWebKit:
        from qutebrowser.browser.webkit import webkitsettings
        webkitsettings.init()
    else:
        raise utils.Unreachable(objects.backend)

    # Make sure special URLs always get JS support
    for pattern in ['chrome://*/*', 'qute://*/*']:
        config.instance.set_obj('content.javascript.enabled',
                                True,
                                pattern=urlmatch.UrlPattern(pattern),
                                hide_userconfig=True)
Exemplo n.º 11
0
    def find_css(self, selector, callback, error_cb, *, only_visible=False):
        utils.unused(error_cb)
        mainframe = self._widget.page().mainFrame()
        if mainframe is None:
            raise browsertab.WebTabError("No frame focused!")

        elems = []
        frames = webkitelem.get_child_frames(mainframe)
        for f in frames:
            for elem in f.findAllElements(selector):
                elems.append(webkitelem.WebKitElement(elem, tab=self._tab))

        if only_visible:
            # pylint: disable=protected-access
            elems = [e for e in elems if e._is_visible(mainframe)]
            # pylint: enable=protected-access

        callback(elems)
Exemplo n.º 12
0
    def find_css(self, selector, callback, error_cb, *, only_visible=False):
        utils.unused(error_cb)
        mainframe = self._widget.page().mainFrame()
        if mainframe is None:
            raise browsertab.WebTabError("No frame focused!")

        elems = []
        frames = webkitelem.get_child_frames(mainframe)
        for f in frames:
            for elem in f.findAllElements(selector):
                elems.append(webkitelem.WebKitElement(elem, tab=self._tab))

        if only_visible:
            # pylint: disable=protected-access
            elems = [e for e in elems if e._is_visible(mainframe)]
            # pylint: enable=protected-access

        callback(elems)
Exemplo n.º 13
0
def process(*, info):
    """A CompletionModel filled with processes."""
    utils.unused(info)
    from qutebrowser.misc import guiprocess
    model = completionmodel.CompletionModel(column_widths=(10, 10, 80))
    for what, processes in itertools.groupby(
        (p for p in guiprocess.all_processes.values() if p is not None),
            lambda proc: proc.what):

        # put successful processes last
        sorted_processes = sorted(
            processes,
            key=lambda proc: proc.outcome.state_str() == 'successful',
        )

        entries = [(str(proc.pid), proc.outcome.state_str(), str(proc))
                   for proc in sorted_processes]
        cat = listcategory.ListCategory(what.capitalize(), entries, sort=False)
        model.add_category(cat)
    return model
Exemplo n.º 14
0
    def __init__(self,
                 *,
                 win_id: int,
                 mode_manager: modeman.ModeManager,
                 private: bool,
                 parent: QWidget = None) -> None:
        utils.unused(mode_manager)  # needed for mypy
        self.is_private = private
        self.win_id = win_id
        self.tab_id = next(tab_id_gen)
        super().__init__(parent)

        self.registry = objreg.ObjectRegistry()
        tab_registry = objreg.get('tab-registry',
                                  scope='window',
                                  window=win_id)
        tab_registry[self.tab_id] = self
        objreg.register('tab', self, registry=self.registry)

        self.data = TabData()
        self._layout = miscwidgets.WrapperLayout(self)
        self._widget = cast(QWidget, None)
        self._progress = 0
        self._load_status = usertypes.LoadStatus.none
        self._tab_event_filter = eventfilter.TabEventFilter(self, parent=self)
        self.backend: Optional[usertypes.Backend] = None

        self._last_history_url: Optional[QUrl] = None
        self._last_history_atime: Optional[int] = None
        self._last_history_title: Optional[str] = None
        self._last_history_requested_url: Optional[QUrl] = None

        # If true, this tab has been requested to be removed (or is removed).
        self.pending_removal = False
        self.shutting_down.connect(
            functools.partial(setattr, self, 'pending_removal', True))

        self.before_load_started.connect(self._on_before_load_started)
Exemplo n.º 15
0
 def download_open(self, cmdline, pdfjs):
     """Open the download directly if this is a download prompt."""
     utils.unused(cmdline)
     utils.unused(pdfjs)
     raise UnsupportedOperationError
Exemplo n.º 16
0
 def get(self, settings=None):
     utils.unused(settings)
     return config.get('content', 'cookies-store')
Exemplo n.º 17
0
 def get(self, settings=None):
     utils.unused(settings)
     return config.get('content', 'cookies-store')
Exemplo n.º 18
0
 def _set(self, value, settings=None):
     utils.unused(settings)
     setter = getattr(default_profile, self._setter)
     setter(value)
Exemplo n.º 19
0
 def get(self, settings=None):
     utils.unused(settings)
     getter = getattr(default_profile, self._getter)
     return getter()
Exemplo n.º 20
0
 def _set(self, value, settings=None):
     utils.unused(settings)
     setter = getattr(QWebEngineProfile.defaultProfile(), self._setter)
     setter(value)
Exemplo n.º 21
0
 def get(self, settings=None):
     utils.unused(settings)
     return self._getter()
Exemplo n.º 22
0
 def _set(self, value, settings=None):
     utils.unused(settings)
     self._setter(value)
Exemplo n.º 23
0
 def get(self, settings=None):
     utils.unused(settings)
     getter = getattr(QWebEngineProfile.defaultProfile(), self._getter)
     return getter()
Exemplo n.º 24
0
 def _set(self, value, settings=None):
     utils.unused(settings)
     self._setter(QWebEngineProfile.AllowPersistentCookies
                  if value else QWebEngineProfile.NoPersistentCookies)
Exemplo n.º 25
0
 def __delitem__(self, key: str) -> None:
     utils.unused(key)
     log.stub()
Exemplo n.º 26
0
 def get(self, settings=None):
     utils.unused(settings)
     getter = getattr(default_profile, self._getter)
     return getter()
Exemplo n.º 27
0
 def _set(self, value, settings=None):
     utils.unused(settings)
     setter = getattr(default_profile, self._setter)
     setter(value)
Exemplo n.º 28
0
 def columnCount(self, parent=QModelIndex()):
     """Override QAbstractItemModel::columnCount."""
     utils.unused(parent)
     return len(self.column_widths)
Exemplo n.º 29
0
 def download_open(self, cmdline, pdfjs):
     """Open the download directly if this is a download prompt."""
     utils.unused(cmdline)
     utils.unused(pdfjs)
     raise UnsupportedOperationError