Ejemplo n.º 1
0
void WebshortcutRunner::match(Plasma::RunnerContext &context)
{
    const QString term = context.query();

    if (term.length() < 3 || !term.contains(m_delimiter))
        return;

    // qDebug() << "checking term" << term;

    const int delimIndex = term.indexOf(m_delimiter);
    if (delimIndex == term.length() - 1)
        return;

    const QString key = term.left(delimIndex);

    if (key == m_lastFailedKey) {
        return;    // we already know it's going to suck ;)
    }

    if (!context.isValid()) {
        qDebug() << "invalid context";
        return;
    }

    // Do a fake user feedback text update if the keyword has not changed.
    // There is no point filtering the request on every key stroke.
    // filtering
    if (m_lastKey == key) {
        m_filterBeforeRun = true;
        m_match.setText(i18n("Search %1 for %2", m_lastProvider, term.mid(delimIndex + 1)));
        context.addMatch(m_match);
        return;
    }

    KUriFilterData filterData(term);
    if (!KUriFilter::self()->filterSearchUri(filterData, KUriFilter::WebShortcutFilter)) {
        m_lastFailedKey = key;
        return;
    }

    m_lastFailedKey.clear();
    m_lastKey = key;
    m_lastProvider = filterData.searchProvider();

    m_match.setData(filterData.uri().url());
    m_match.setId("WebShortcut:" + key);

    m_match.setIcon(QIcon::fromTheme(filterData.iconName()));
    m_match.setText(i18n("Search %1 for %2", m_lastProvider, filterData.searchTerm()));
    context.addMatch(m_match);
}
Ejemplo n.º 2
0
void RecentDocuments::match(Plasma::RunnerContext &context)
{
    if (m_recentdocuments.isEmpty()) {
        return;
    }

    const QString term = context.query();
    if (term.length() < 3) {
        return;
    }

    foreach (const QString &document, m_recentdocuments) {
        if (!context.isValid()) {
            return;
        }

        if (document.contains(term, Qt::CaseInsensitive)) {
            KConfig _config( document, KConfig::SimpleConfig );
            KConfigGroup config(&_config, "Desktop Entry" );
            QString niceName =  config.readEntry( "Name" );
            Plasma::QueryMatch match(this);
            match.setType(Plasma::QueryMatch::PossibleMatch);
            match.setRelevance(1.0);
            match.setIcon(QIcon::fromTheme(config.readEntry("Icon")));
            match.setData(document); // TODO: Read URL[$e], or can we just pass the path to the .desktop file?
            match.setText(niceName);
            match.setSubtext(i18n("Recent Document"));
            context.addMatch(match);
        }
    }
}
Ejemplo n.º 3
0
void RecentDocuments::match(Plasma::RunnerContext &context)
{
    if (m_recentdocuments.isEmpty()) {
        return;
    }

    const QString term = context.query();
    if (term.length() < 3) {
        return;
    }

    foreach (const QString &document, m_recentdocuments) {
        if (!context.isValid()) {
            return;
        }

        if (document.contains(term, Qt::CaseInsensitive)) {
            KDesktopFile config(document);
            Plasma::QueryMatch match(this);
            match.setType(Plasma::QueryMatch::PossibleMatch);
            match.setRelevance(1.0);
            match.setIcon(QIcon::fromTheme(config.readIcon()));
            match.setData(config.readUrl());
            match.setText(config.readName());
            match.setSubtext(i18n("Recent Document"));
            context.addMatch(match);
        }
    }
}
Ejemplo n.º 4
0
void ShellRunner::match(Plasma::RunnerContext &context)
{
    if (!m_enabled) {
        return;
    }

    if (context.type() == Plasma::RunnerContext::Executable ||
        context.type() == Plasma::RunnerContext::ShellCommand)  {
        const QString term = context.query();
        Plasma::QueryMatch match(this);
        match.setId(term);
        match.setType(Plasma::QueryMatch::ExactMatch);
        match.setIcon(QIcon::fromTheme("system-run"));
        match.setText(i18n("Run %1", term));
        match.setRelevance(0.7);
        context.addMatch(match);
    }
}
Ejemplo n.º 5
0
void KGetRunner::match(Plasma::RunnerContext& context)
{
    QString query = context.query();
    m_urls = parseUrls(context.query());
    if (!m_urls.isEmpty()) {
        Plasma::QueryMatch match(this);
        match.setType(Plasma::QueryMatch::PossibleMatch);
        match.setRelevance(0.9);
        match.setIcon(m_icon);
        if(m_urls.size() == 1) {
            match.setText(i18n("Download %1 with KGet.", KUrl(m_urls.first()).prettyUrl()));
        }
        else {
            match.setText(i18np("Download %1 link with KGet.", "Download %1 links with KGet.", m_urls.size()));
        }
        context.addMatch(query, match);
    }
}
Ejemplo n.º 6
0
void BookmarksRunner::match(Plasma::RunnerContext &context)
{
    if(! m_browser) return;
    const QString term = context.query();
    if ((term.length() < 3) && (!context.singleRunnerQueryMode())) {
        return;
    }

    bool allBookmarks = term.compare(i18nc("list of all konqueror bookmarks", "bookmarks"),
                                     Qt::CaseInsensitive) == 0;
                                     
    QList<BookmarkMatch> matches = m_browser->match(term, allBookmarks);
    foreach(BookmarkMatch match, matches) {
        if(!context.isValid())
            return;
        context.addMatch(match.asQueryMatch(this));
    }
}
Ejemplo n.º 7
0
void CharacterRunner::match(Plasma::RunnerContext &context)
{
    QString term = context.query();
    QString specChar;

    term = term.replace(QLatin1Char( ' ' ), QLatin1String( "" )); //remove blanks
    if (term.length() < 2) //ignore too short queries
    {
        return;
    }
    if (!term.startsWith(m_triggerWord)) //ignore queries without the triggerword
    {
      return;
    }
    term = term.remove(0, m_triggerWord.length()); //remove the triggerword

    if (m_aliases.contains(term)) //replace aliases by their hex.-code
    {
      term = m_codes[m_aliases.indexOf(term)];
    }

    bool ok; //checkvariable
    int hex = term.toInt(&ok, 16); //convert query into int
    if (!ok) //check if conversion was successful
    {
      return;
    }

    //make special caracter out of the hex.-code
    specChar=QString();
    specChar.toUtf8();
    specChar[0]=hex;

    //create match
    Plasma::QueryMatch match(this);
    match.setType(Plasma::QueryMatch::InformationalMatch);
    match.setIcon(KIcon(QLatin1String( "accessories-character-map" )));
    match.setText(specChar);
    match.setData(specChar);
    match.setId(QString());
    context.addMatch(term, match);
}
void RecentDocuments::match(Plasma::RunnerContext &context)
{
    if (m_recentdocuments.isEmpty()) {
        return;
    }

    const QString term = context.query();
    if (term.length() < 3) {
        return;
    }

    const QString homePath = QDir::homePath();

    foreach (const QString &document, m_recentdocuments) {
        if (!context.isValid()) {
            return;
        }

        if (document.contains(term, Qt::CaseInsensitive)) {
            KDesktopFile config(document);
            Plasma::QueryMatch match(this);
            match.setType(Plasma::QueryMatch::PossibleMatch);
            match.setRelevance(1.0);
            match.setIconName(config.readIcon());
            match.setData(config.readUrl());
            match.setText(config.readName());

            QUrl folderUrl = QUrl(config.readUrl()).adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash);
            if (folderUrl.isLocalFile()) {
                QString folderPath = folderUrl.toLocalFile();
                if (folderPath.startsWith(homePath)) {
                    folderPath.replace(0, homePath.length(), QStringLiteral("~"));
                }
                match.setSubtext(folderPath);
            } else {
                match.setSubtext(folderUrl.toDisplayString());
            }

            context.addMatch(match);
        }
    }
}
Ejemplo n.º 9
0
void LocationsRunner::match(Plasma::RunnerContext &context)
{
    QString term = context.query();
    Plasma::RunnerContext::Type type = context.type();

    if (type == Plasma::RunnerContext::Directory || type == Plasma::RunnerContext::File) {
        Plasma::QueryMatch match(this);
        match.setType(Plasma::QueryMatch::ExactMatch);
        match.setText(i18n("Open %1", term));

        if (type == Plasma::RunnerContext::File) {
            match.setIcon(QIcon::fromTheme(KIO::iconNameForUrl(QUrl(term))));
        } else {
            match.setIcon(QIcon::fromTheme(QStringLiteral("system-file-manager")));
        }

        match.setRelevance(1);
        match.setData(term);
        match.setType(Plasma::QueryMatch::ExactMatch);

        if (type == Plasma::RunnerContext::Directory) {
            match.setId(QStringLiteral("opendir"));
        } else {
            match.setId(QStringLiteral("openfile"));
        }
        context.addMatch(match);
    } else if (type == Plasma::RunnerContext::Help) {
        //qDebug() << "Locations matching because of" << type;
        Plasma::QueryMatch match(this);
        match.setType(Plasma::QueryMatch::ExactMatch);
        match.setText(i18n("Open %1", term));
        match.setIcon(QIcon::fromTheme(QStringLiteral("system-help")));
        match.setRelevance(1);
        match.setType(Plasma::QueryMatch::ExactMatch);
        match.setId(QStringLiteral("help"));
        context.addMatch(match);
    } else if (type == Plasma::RunnerContext::NetworkLocation || type == Plasma::RunnerContext::UnknownType) {
        const bool filtered = KUriFilter::self()->filterUri(term, QStringList() << QStringLiteral("kshorturifilter"));

        if (!filtered) {
            return;
        }

        QUrl url(term);

        if (!KProtocolInfo::isKnownProtocol(url.scheme())) {
            return;
        }

        Plasma::QueryMatch match(this);
        match.setText(i18n("Go to %1", url.toDisplayString()));
        match.setIcon(QIcon::fromTheme(KProtocolInfo::icon(url.scheme())));
        match.setData(url.url());

        if (KProtocolInfo::isHelperProtocol(url.scheme())) {
            //qDebug() << "helper protocol" << url.protocol() <<"call external application" ;
            if (url.scheme() == QLatin1String("mailto")) {
                match.setText(i18n("Send email to %1",url.path()));
            } else {
                match.setText(i18n("Launch with %1", KProtocolInfo::exec(url.scheme())));
            }
        } else {
            //qDebug() << "protocol managed by browser" << url.protocol();
            match.setText(i18n("Go to %1", url.toDisplayString()));
        }

        if (type == Plasma::RunnerContext::UnknownType) {
            match.setId(QStringLiteral("openunknown"));
            match.setRelevance(0.5);
            match.setType(Plasma::QueryMatch::PossibleMatch);
        } else {
            match.setId(QStringLiteral("opennetwork"));
            match.setRelevance(0.7);
            match.setType(Plasma::QueryMatch::ExactMatch);
        }

        context.addMatch(match);
    }
}