Beispiel #1
0
        def emit_message_info(title=False):
            """
            If requesting for the document's title, emit it. Otherwise,
            if a link is focused, emit its target to the message label

            """

            if title:
                self.show_message.emit(self.title())
            elif self.__in_focus is not None:
                qurl = QUrl(self.__in_focus.attribute('href'))
                qurl = do_redirect(qurl)
                self.show_message.emit(qurl.toString())
Beispiel #2
0
        def on_link_click(qurl):
            """ Callback for connection. Reads the 'paste' attribute
            to know if a middle click requested to open on a new tab.

            BRW01 BRW12 VID01 CB03

            """

            # required for 'open in new tab if not in this instance'
            qurl = do_redirect(qurl)  # BRW12

            # 'play' and 'save' should only happen from inside the webkit and
            # if the user started the action; handle here, not in 'navigate'

            if 'play' in self.attr:
                print("PLAYING")

                GLOBAL_VID_PLAY.play(qurl)  # VID01

                self.attr.clear('play')

                return

            if 'save' in self.attr:
                clipboard(qurl)  # CB02
                self.attr.clear('save')
                return

            instance = extract_instance(qurl.toString())

            target_prefix = get_options()['sites'][instance]['prefix']

            # if the prefixes don't match, we're requesting a new instance
            # TAB04 TAB05
            if 'paste' in self.attr or self.attr.prefix != target_prefix:
                mainwin().add_tab(qurl,
                                  scripting=('open_scripted' in self.attr))
                self.attr.clear('paste')
            else:
                self.navigate(qurl)  # BRW01

            if 'open_scripted' in self.attr:
                self.attr.clear('open_scripted')
Beispiel #3
0
    def navigate(self, request=None):
        """ Open the url on this tab. If 'url' is already a QUrl
        (if it comes from a href click), just send it. Otherwise,
        it comes either from the address bar or the PRIMARY
        clipboard through a keyboard shortcut.
        Check if the "url" is actually one, partial or otherwise;
        if it's not, construct a web search.

        BRW01

        """

        if isinstance(request, QUrl):
            qurl = request

        # 'navigate' was connected to a QLineEdit to extract its text
        elif isinstance(request, QLineEdit):
            url = request.text()
            qurl = fix_url(url)  # BRW11
        else:
            raise RuntimeError("Navigating to non-navigable")

        # if the qurl does not trigger an URL in SHORTENERS or REDIRECTORS,
        # this will be a no-op
        qurl = do_redirect(qurl)  # BRW12

        if self.attr.prefix is None:
            # this is the first navigation on this tab/webkit; replace
            # the Network Access Manager CFG02

            instance = extract_instance(qurl.toString())
            self.attr.set_prefix(get_options()['sites'][instance]['prefix'])

            if self.attr.prefix is None:
                raise RuntimeError(
                    "prefix failed to be set... 'options' is broken")

            # strictly speaking, this should emit from Attributes.set_prefix
            self.set_prefix.emit(self.attr.prefix)
            if self.attr.prefix == "":
                print("GENERAL")
            else:
                print("INSTANCE: {}".format(self.attr.prefix))

            if not has_manager(self.attr.prefix):
                register_manager(self.attr.prefix,
                                 InterceptNAM(instance,
                                              parent=None))

            if not has_manager(self.attr.prefix):
                raise RuntimeError("prefix manager not registered...")

            self.page().setNetworkAccessManager(get_manager(self.attr.prefix))

        print("{}>>>\t\t{}\n>>> NAVIGATE {}{}".format(
            Fore.CYAN,
            datetime.datetime.now().isoformat(),
            qurl.toString(),
            Fore.RESET))

        self.setFocus()
        self.load_requested.emit(qurl.toString())
        self.load(qurl)