本文整理汇总了C++中plasma::RunnerContext类的典型用法代码示例。如果您正苦于以下问题:C++ RunnerContext类的具体用法?C++ RunnerContext怎么用?C++ RunnerContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RunnerContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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)) {
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);
}
}
}
示例2: match
void PidginRunner::match(Plasma::RunnerContext &context)
{
qDebug() << Q_FUNC_INFO ;
QString query = context.query();
if ( !query.isEmpty() )
{
qDebug() << " Pidgin runner trigger word";
QString contactName = query ;
// so now let's filter all contacts from
// pidgin
QStringList contacts = pidgin_d.search(query);
QList<Plasma::QueryMatch> matches;
std::for_each(contacts.begin(), contacts.end(), [&contacts, &matches, this](const QString& c )
{
Plasma::QueryMatch match(this);
QVariantMap map = pidgin_d.buddyId(c);
match.setText(c);
match.setSubtext(map["buddyStatus"].toString());
match.setData(c);
match.setId(c);
match.setType(Plasma::QueryMatch::ExactMatch);
QIcon icon(map["buddyIconPath"].toString());
match.setIcon(icon);
matches.append(match);
});
context.addMatches(matches);
}
}
示例3: 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);
}
}
}
示例4: match
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 {
示例5: 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);
}
示例6: 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();
}
}
}
示例7: match
void ServiceRunner::match(Plasma::RunnerContext &context)
{
const QString term = context.query();
if (term.length() < 3) {
return;
}
// Search for applications which are executable and case-insensitively match the search term
// See http://techbase.kde.org/Development/Tutorials/Services/Traders#The_KTrader_Query_Language
// if the following is unclear to you.
QString query = QString("exist Exec and ('%1' =~ Name)").arg(term);
KService::List services = KServiceTypeTrader::self()->query("Application", query);
QList<Plasma::QueryMatch> matches;
QSet<QString> seen;
if (!services.isEmpty()) {
//kDebug() << service->name() << "is an exact match!" << service->storageId() << service->exec();
foreach (const KService::Ptr &service, services) {
if (!service->noDisplay() && service->property("NotShowIn", QVariant::String) != "KDE") {
Plasma::QueryMatch match(this);
match.setType(Plasma::QueryMatch::ExactMatch);
setupMatch(service, match);
match.setRelevance(1);
matches << match;
seen.insert(service->storageId());
seen.insert(service->exec());
}
}
}
示例8: match
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);
}
}
示例9: match
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);
}
}
示例10: match
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));
}
}
示例11: 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);
}
}
}
示例12: match
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);
}
示例13: 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);
}
示例14: match
void KJiebaRunner::match(Plasma::RunnerContext &context)
{
const QString term = context.query();
QList<Plasma::QueryMatch> matches;
QSet<QString> seen;
if (term.length() > 1) {
#if DEBUG
qDebug() << "DEBUG:" << __PRETTY_FUNCTION__ << term;
#endif
KService::List services = KServiceTypeTrader::self()->query("Application");
services.erase(std::remove_if(services.begin(),
services.end(),
[=](QExplicitlySharedDataPointer<KService> it) {
return it->exec().isEmpty() ||
(!kjiebaPtr->query(it->genericName()).contains(term) &&
!kjiebaPtr->topinyin(it->genericName()).contains(term) &&
!kjiebaPtr->topinyin(it->genericName(), false).contains(term) &&
!kjiebaPtr->query(it->name()).contains(term) &&
!kjiebaPtr->topinyin(it->name()).contains(term) &&
!kjiebaPtr->topinyin(it->name(), false).contains(term));
}), services.end());
if (!services.isEmpty()) {
Q_FOREACH (const KService::Ptr &service, services) {
if (!service->noDisplay() &&
service->property(QStringLiteral("NotShowIn"), QVariant::String) != "KDE") {
Plasma::QueryMatch match(this);
match.setType(Plasma::QueryMatch::ExactMatch);
const QString name = service->name();
#if DEBUG
qDebug() << "DEBUG:" << name;
#endif
match.setText(name);
match.setData(service->storageId());
if (!service->genericName().isEmpty() && service->genericName() != name)
match.setSubtext(service->genericName());
else if (!service->comment().isEmpty())
match.setSubtext(service->comment());
if (!service->icon().isEmpty())
match.setIcon(QIcon::fromTheme(service->icon()));
match.setRelevance(1);
matches << match;
seen.insert(service->storageId());
seen.insert(service->exec());
}
}
}
示例15: run
void LocationsRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match)
{
Q_UNUSED(match)
QString location = context.query();
if (location.isEmpty()) {
return;
}
location = convertCaseInsensitivePath(location);
//qDebug() << "command: " << context.query();
//qDebug() << "url: " << location << data;
QUrl urlToRun(KUriFilter::self()->filteredUri(location, QStringList() << QStringLiteral("kshorturifilter")));
new KRun(urlToRun, 0);
}