コード例 #1
0
    def _matchKeyword(self, context, query, searchTerms, matchedKeyword):
        """
        Add a keyword match for the given `query` to `context`.
        """
        shortName, url = self._keywords[matchedKeyword]

        # This explicit "cast" to QString is necessary in order to prevent
        # python from interpreting `url` as a regular string. This way,
        # unicode handling is a lot easier.
        url = QString(url).replace("{searchTerms}", searchTerms)

        # Default google search URL is some freaky contruction like:
        # {google:baseURL}search?{google:RLZ}{google:acceptedSuggestion}{google:originalQueryForSuggestion}{google:searchFieldtrialParameter}{google:instantFieldTrialGroupParameter}sourceid=chrome&client=ubuntu&channel=cs&ie={inputEncoding}&q=%s
        # google:baseURL is in attr "last_known_google_url" in ~./config/chromium/Local State
        # Quick workaround...
        if url.startsWith("{google:baseURL}"):
            url = QUrl("%s/search" % self._googleBaseURL)
            url.addQueryItem("q", searchTerms)
            url.addQueryItem("qf", "f")
            url = url.toString()

        m = Plasma.QueryMatch(self.runner)
        m.setText("Query \"%s\" for '%s'\n%s" % (shortName, searchTerms, url))
        m.setType(Plasma.QueryMatch.ExactMatch)
        m.setIcon(KIcon("chromium-browser"))
        m.setData(url)
        context.addMatch(query, m)