void ActivityRunner::match(Plasma::RunnerContext &context) { if (!m_enabled) { return; } const QString term = context.query().trimmed(); bool list = false; QString name; if (term.startsWith(m_keywordi18n, Qt::CaseInsensitive)) { if (term.size() == m_keywordi18n.size()) { list = true; } else { name = term.right(term.size() - m_keywordi18n.size()).trimmed(); list = name.isEmpty(); } } else if (term.startsWith(m_keyword, Qt::CaseInsensitive)) { if (term.size() == m_keyword.size()) { list = true; } else { name = term.right(term.size() - m_keyword.size()).trimmed(); list = name.isEmpty(); } } else if (context.singleRunnerQueryMode()) { name = term; } else { return; } QList<Plasma::QueryMatch> matches; QStringList activities = m_activities->listActivities(); qSort(activities); const QString current = m_activities->currentActivity(); if (!context.isValid()) { return; } if (list) { foreach (const QString &activity, activities) { if (current == activity) { continue; } KActivities::Info info(activity); addMatch(info, matches); if (!context.isValid()) { return; } } } else {
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); } } }
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); } } }
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); }
void Translator::match(Plasma::RunnerContext &context) { const QString term = context.query(); QString text; QPair<QString, QString> language; if (!parseTerm(term, text, language)) return; if (!context.isValid()) return; if (text.contains(" ")) { if(m_yandexPhrase) { QEventLoop loop; Yandex yandex(this, context, text, language, m_yandexKey); connect(&yandex, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); } if(m_glosbePhrase) { if(m_glosbeExamples) { QEventLoop loop; Glosbe glosbe(this, context, text, language, m_glosbeExamples); connect(&glosbe, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); } QEventLoop loop; Glosbe glosbe(this, context, text, language); connect(&glosbe, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); } } else { if(m_yandexWord) { QEventLoop loop; Yandex yandex(this, context, text, language, m_yandexKey); connect(&yandex, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); } if(m_glosbeWord) { if(m_glosbeExamples) { QEventLoop loop; Glosbe glosbe(this, context, text, language, m_glosbeExamples); connect(&glosbe, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); } QEventLoop loop; Glosbe glosbe(this, context, text, language); connect(&glosbe, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); } } }
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)); } }
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); } } }
void Translator::match(Plasma::RunnerContext& context) { QString term = context.query(); QString text; QPair<QString, QString> language; if (!parseTerm(term, text, language)) { return; } if (!context.isValid()) { return; } QEventLoop loop; TranslatorJob job(text, language); connect(&job, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); parseResult(job.result(), context, text); }
void AudioPlayerControlRunner::match(Plasma::RunnerContext &context) { if (context.query().length() < 3) { return; } const QString term = context.query(); QList<Plasma::QueryMatch> matches; if (m_useCommands) { /* DBus paths that are used in the command executes */ /* The data variable looks like this: * "/PlayerQLatin1String( " " )org.freedesktop.MediaPlayerQLatin1String( " " )PlayQLatin1String( " " )actionsQLatin1String( " " )start" args... * <path> <interface> <method> <actions> <start player> * <actions> is NONE if no action is needed */ QVariantList playcontrol; playcontrol << QLatin1String( "/Player" ) << QLatin1String( "org.freedesktop.MediaPlayer" ); /* The commands */ //Play if (context.isValid() && m_comPlay.startsWith(term, Qt::CaseInsensitive) && (!m_running || m_songsInPlaylist)) { QVariantList data = playcontrol; data << ((currentSong() == -1) ? QLatin1String( "Next" ) : QLatin1String( "Play" )) << NONE << QLatin1String( "start" ); matches << createMatch(this, i18n("Start playing"), i18n("Audio player control"), QLatin1String( "play" ), KIcon( QLatin1String( "media-playback-start" )), data, 1.0); } if (!context.isValid() || !m_running) { //The interface of the player is not availalbe, so the rest of the commands //is not needed context.addMatches(matches); return; } if (context.isValid() && m_songsInPlaylist) { //The playlist isn't empty //Next song if (m_comNext.startsWith(term,Qt::CaseInsensitive) && m_nextSongAvailable) { QVariantList data = playcontrol; data << QLatin1String( "Next" ) << NONE << QLatin1String( "nostart" ); matches << createMatch(this, i18n("Play next song"), i18n("Audio player control"), QLatin1String( "next" ), KIcon( QLatin1String( "media-skip-forward" )), data, 1.0); } //Previous song if (context.isValid() && m_comPrev.startsWith(term,Qt::CaseInsensitive) && m_prevSongAvailable) { QVariantList data = playcontrol; data << QLatin1String( "Prev" ) << NONE << QLatin1String( "nostart" ); matches << createMatch(this, i18n("Play previous song"), i18n("Audio player control") , QLatin1String( "previous" ), KIcon( QLatin1String( "media-skip-backward" )), data, 1.0); } }//--- if (m_songsInPlaylist) //Pause if (context.isValid() && m_comPause.startsWith(term,Qt::CaseInsensitive)) { QVariantList data = playcontrol; data << QLatin1String( "Pause" ) << NONE << QLatin1String( "nostart" ); matches << createMatch(this, i18n("Pause playing"), i18n("Audio player control"), QLatin1String( "pause" ), KIcon( QLatin1String( "media-playback-pause" )), data, 1.0); } //Stop if (context.isValid() && m_comStop.startsWith(term,Qt::CaseInsensitive)) { QVariantList data = playcontrol; data << QLatin1String( "Stop" ) << NONE << QLatin1String( "nostart" ); matches << createMatch(this, i18n("Stop playing"), i18n("Audio player control"), QLatin1String( "stop" ), KIcon( QLatin1String( "media-playback-stop" )), data, 1.0); } //Increase if (context.isValid() && m_comIncrease.startsWith(term,Qt::CaseInsensitive)) { QVariantList data = playcontrol; data << QLatin1String( "VolumeUp" ) << NONE << QLatin1String( "nostart" ) << m_increaseBy; matches << createMatch(this, i18n("Increase volume by %1" , m_increaseBy), QLatin1String( "volumeup" ), i18n("Audio player control"), KIcon(QLatin1String( "audio-volume-high" )), data, 1.0); } else if (context.isValid() && equals(term, QRegExp( m_comIncrease + QLatin1String( " \\d{1,2}0{0,1}" ) ) ) ) { int volumeChange = getNumber(term, ' ' ); QVariantList data = playcontrol; data << QLatin1String( "VolumeUp" ) << NONE << QLatin1String( "nostart" ) << volumeChange; matches << createMatch(this, i18n("Increase volume by %1" , volumeChange), QLatin1String( "volumeup" ), i18n("Audio player control"), KIcon(QLatin1String( "audio-volume-high" )), data, 1.0); } //Decrease if (context.isValid() && m_comDecrease.startsWith(term,Qt::CaseInsensitive)) { QVariantList data = playcontrol; data << QLatin1String( "VolumeDown" ) << NONE << QLatin1String( "nostart" ) << m_decreaseBy; matches << createMatch(this, i18n("Reduce volume by %1", m_decreaseBy), QLatin1String( "volumedown" ), i18n("Audio player control"), KIcon(QLatin1String( "audio-volume-low" )), data, 1.0); } else if (context.isValid() && equals(term, QRegExp( m_comDecrease + QLatin1String( " \\d{1,2}0{0,1}" ) ) ) ) { int volumeChange = getNumber(term, ' '); QVariantList data = playcontrol; data << QLatin1String( "VolumeDown" ) << NONE << QLatin1String( "nostart" ) << volumeChange; matches << createMatch(this, i18n("Reduce volume by %1", volumeChange), QLatin1String( "volumedown" ), i18n("Audio player control"), KIcon(QLatin1String( "audio-volume-low" )), data, 1.0); } //Set volume to if (context.isValid() && equals(term, QRegExp( m_comVolume + QLatin1String( " \\d{1,2}0{0,1}" ) ) ) ) { QVariantList data = playcontrol; int newVolume = getNumber(term , ' '); data << QLatin1String( "VolumeSet" ) << NONE << QLatin1String( "nostart" ) << newVolume; matches << createMatch(this, i18n("Set volume to %1%" , newVolume), QLatin1String( "volume" ), i18n("Audio player control"), KIcon(QLatin1String( "audio-volume-medium" )), data, 1.0); } //Mute if (context.isValid() && m_comMute.startsWith(term,Qt::CaseInsensitive)) { QVariantList data = playcontrol; data << QLatin1String( "Mute" ) << NONE << QLatin1String( "nostart" ); matches << createMatch(this, i18n("Mute"), i18n("Audio player control"), QLatin1String( "mute" ), KIcon( QLatin1String( "audio-volume-muted" )), data, 1.0); } //Quit player if (context.isValid() && m_comQuit.startsWith(term,Qt::CaseInsensitive)) { QVariantList data; data << QLatin1String( "/" ) << QLatin1String( "org.freedesktop.MediaPlayer" ) << QLatin1String( "Quit" ) << NONE << QLatin1String( "nostart" ); matches << createMatch(this, i18n("Quit %1", m_player),QLatin1String( "" ), QLatin1String( "quit" ), KIcon( QLatin1String( "application-exit" )), data, 1.0); } }//--- if (m_useCommands) if (context.isValid() && m_searchCollection) { QString actionNames; QString searchTerm = term; QString command; if (term.startsWith(m_comPlay,Qt::CaseInsensitive) && term.length() > m_comPlay.length()) { command = m_comPlay; actionNames = PLAY; } else if (term.startsWith(m_comAppend, Qt::CaseInsensitive) && term.length() > m_comAppend.length()) { command = m_comAppend; actionNames = APPEND; } else if (term.startsWith(m_comQueue, Qt::CaseInsensitive) && term.length() > m_comQueue.length()) { command = m_comQueue; actionNames = QUEUE; } else { actionNames = QString::fromLatin1( "%1,%2,%3").arg(PLAY).arg(APPEND).arg(QUEUE); } if (!context.isValid()) { return; } searchTerm = searchTerm.right(searchTerm.length() - (command.length() + 1)); matches << searchCollectionFor(searchTerm, actionNames); //Adds matches for all song matches for term } context.addMatches(matches); }