void PowerDevilRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match) { Q_UNUSED(context) QDBusInterface iface("org.kde.Solid.PowerManagement", "/org/kde/Solid/PowerManagement", "org.kde.Solid.PowerManagement"); if (match.id().startsWith("PowerDevil_ProfileChange")) { iface.asyncCall("loadProfile", match.data().toString()); } else if (match.id() == "PowerDevil_BrightnessChange") { iface.asyncCall("setBrightness", match.data().toInt()); } else if (match.id() == "PowerDevil_DimTotal") { iface.asyncCall("setBrightness", 0); } else if (match.id() == "PowerDevil_DimHalf") { iface.asyncCall("setBrightness", -2); } else if (match.id() == "PowerDevil_TurnOffScreen") { // FIXME: Maybe this should be even removed // iface.asyncCall("turnOffScreen"); } else if (match.id().startsWith("PowerDevil_Suspend")) { switch ((Solid::PowerManagement::SleepState)match.data().toInt()) { case Solid::PowerManagement::SuspendState: case Solid::PowerManagement::StandbyState: iface.asyncCall("suspendToRam"); break; case Solid::PowerManagement::HibernateState: iface.asyncCall("suspendToDisk"); break; } } }
QVariant SourcesModel::data(const QModelIndex& index, int role) const { if (!index.isValid()) return QVariant(); if (index.row() >= m_size) return QVariant(); Plasma::QueryMatch m = fetchMatch(index.row()); Q_ASSERT(m.runner()); switch(role) { case Qt::DisplayRole: return m.text(); case Qt::DecorationRole: if (!m.iconName().isEmpty()) { return m.iconName(); } return m.icon(); case TypeRole: return m.matchCategory(); case SubtextRole: return m.subtext(); case ActionsRole: { const auto &actions = m_manager->actionsForMatch(m); if (actions.isEmpty()) { return QVariantList(); } QVariantList actionsList; actionsList.reserve(actions.size()); for (QAction *action : actions) { actionsList.append(QVariant::fromValue(action)); } return actionsList; } case DuplicateRole: return m_duplicates.value(m.text()); /* case PreviewTypeRole: return m.previewType(); case PreviewUrlRole: return m.previewUrl(); case PreviewLabelRole: return m.previewLabel(); */ } return QVariant(); }
void AudioPlayerControlRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match) { Q_UNUSED(context) QDBusInterface tracklist(QString::fromLatin1( "org.mpris.%1").arg(m_player), QLatin1String( "/TrackList" ), QLatin1String( "org.freedesktop.MediaPlayer" )); QVariantList data = match.data().value<QVariantList>(); /* Only Amarok part*/ QString url = data[2].toString(); int pos = posInPlaylist(url); kDebug() << "pos" << pos; QAction *a = match.selectedAction(); if (data[3].toString().compare(NONE)) { if (!a) { a = action(data[3].toString()); } if (a == action(QUEUE)) { KUrl::List list; list << KUrl(url); KRun::run(QLatin1String( "amarok --queue %u" ), list, 0); } else if (a == action(APPEND)) { if (!(pos > -1)) { tracklist.call(QDBus::NoBlock, QLatin1String( "AddTrack" ), url , false); } } else { //Action play was selected if (pos > -1) { tracklist.call(QDBus::NoBlock, QLatin1String( "PlayTrack" ), pos); } else { tracklist.call(QDBus::NoBlock, QLatin1String( "AddTrack" ), url, true); } } }/* Only Amarok part over */ else { if ((data[4].toString().compare(QLatin1String( "start" )) == 0)) { //The players's interface isn't available but it should be started if (!startPlayer()) { return; } } QDBusMessage msg = QDBusMessage::createMethodCall(QString::fromLatin1( "org.mpris.%1").arg(m_player),data[0].toString(), data[1].toString(), data[2].toString()); kDebug() << msg; QVariantList args; for (int i = 5;data.length() > i;++i) { args << data[i]; } msg.setArguments(args); QDBusConnection::sessionBus().call(msg, QDBus::NoBlock); } }
void RecentDocuments::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match) { Q_UNUSED(context) const QString url = match.data().toString(); if (match.selectedAction() && match.selectedAction()->data().toString() == QLatin1String("openParentDir")) { KIO::highlightInFileManager({QUrl(url)}); return; } new KRun(QUrl(url), 0); }
void RecentDocuments::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match) { Q_UNUSED(context) QString url = match.data().toString(); qDebug() << "Opening Recent Document" << url; new KRun(url, 0); }
void BookmarksRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &action) { Q_UNUSED(context); const QString term = action.data().toString(); QUrl url = QUrl(term); //support urls like "kde.org" by transforming them to http://kde.org if (url.scheme().isEmpty()) { const int idx = term.indexOf('/'); url.clear(); url.setHost(term.left(idx)); if (idx != -1) { //allow queries const int queryStart = term.indexOf('?', idx); int pathLength = -1; if ((queryStart > -1) && (idx < queryStart)) { pathLength = queryStart - idx; url.setQuery(term.mid(queryStart)); } url.setPath(term.mid(idx, pathLength)); } url.setScheme(QStringLiteral("http")); } KToolInvocation::invokeBrowser(url.url()); }
void KopeteRunner::run(const Plasma::RunnerContext& context, const Plasma::QueryMatch& match) { Q_UNUSED(context) // HACK: Strip off the "kopete_" prefix const QString id = match.data().toString(); QString method; QVariantList args; if (id == "connect") method = "connectAll"; else if (id == "disconnect") method = "disconnectAll"; else if (id == "status") { method = "setOnlineStatus"; QStringList status = match.text().split(": "); status.takeFirst(); QStringList message = match.subtext().split(": "); message.takeFirst(); args << status.join(": ") << message.join(": "); } else if (id == "message") { method = "setStatusMessage"; QStringList message = match.text().split(": "); message.takeFirst(); args << message.join(": "); } else if (!QUuid(id).isNull()) { method = "openChat"; args << id; } else qDebug("Unknown ID: %s", id.toUtf8().constData()); if (!method.isNull()) { QDBusMessage message = generateMethodCall(method); message.setArguments(args); QDBusConnection::sessionBus().send(message); } }
void KRunnerModel::matchesChanged(const QList< Plasma::QueryMatch > & m) { QList< Plasma::QueryMatch > matches = m; qSort(matches.begin(), matches.end()); clear(); while (matches.size()) { Plasma::QueryMatch match = matches.takeLast(); appendRow( StandardItemFactory::createItem( match.icon(), match.text(), match.subtext(), QString("krunner://") + match.runner()->id() + "/" + ::runnerManager()->query() + "#" + match.id(), match.relevance(), CommonModel::AddAction ) ); } sort(0, Qt::DescendingOrder); }
QList<QAction *> RecentDocuments::actionsForMatch(const Plasma::QueryMatch &match) { Q_UNUSED(match) const QString openParentDirId = QStringLiteral("openParentDir"); if (!action(openParentDirId)) { (addAction(openParentDirId, QIcon::fromTheme(QStringLiteral("document-open-folder")), i18n("Open Containing Folder")))->setData(openParentDirId); } QList<QAction *> actions; if (QUrl(match.data().toString()).isLocalFile()) { actions << action(openParentDirId); } return actions; }
void WebshortcutRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match) { QUrl location; //qDebug() << "filter before run?" << m_filterBeforeRun; if (m_filterBeforeRun) { m_filterBeforeRun = false; //qDebug() << "look up webshortcut:" << context.query(); KUriFilterData filterData (context.query()); if (KUriFilter::self()->filterSearchUri(filterData, KUriFilter::WebShortcutFilter)) location = filterData.uri(); } else { location = match.data().toUrl(); } //qDebug() << location; if (!location.isEmpty()) { QDesktopServices::openUrl(location); } }
void WebshortcutRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match) { QString location; //qDebug() << "filter before run?" << m_filterBeforeRun; if (m_filterBeforeRun) { m_filterBeforeRun = false; //qDebug() << "look up webshortcut:" << context.query(); KUriFilterData filterData (context.query()); if (KUriFilter::self()->filterSearchUri(filterData, KUriFilter::WebShortcutFilter)) location = filterData.uri().url(); } else { location = match.data().toString(); } //qDebug() << location; if (!location.isEmpty()) { KToolInvocation::invokeBrowser(location); } }
// // Tries to make sure that all the types have the same number // of visible items // void SourcesModel::slotMatchAdded(const Plasma::QueryMatch& m) { if (m_queryString.isEmpty()) return; QString matchType = m.matchCategory(); if (!m_types.contains(matchType)) { m_types << matchType; } if (m_size == m_queryLimit) { int maxShownItems = 0; QString maxShownType; foreach (const QString& type, m_types) { TypeData data = m_matches.value(type); if (data.shown.size() >= maxShownItems) { maxShownItems = data.shown.size(); maxShownType = type; } }
void PlasmaRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match) { Q_UNUSED(context) const QVariantList data = match.data().toList(); // pass in C locale, should be always understood const QString latLon = QString::number(data.at(1).toReal()) + QLatin1Char(' ') + QString::number(data.at(0).toReal()); const QString distance = data.at(2).toString(); const QStringList parameters = QStringList() << QStringLiteral( "--latlon" ) << latLon << QStringLiteral( "--distance" ) << distance << QStringLiteral( "--map" ) << QStringLiteral( "earth/openstreetmap/openstreetmap.dgml" ); QProcess::startDetached( QStringLiteral("marble"), parameters ); }
QList<QAction*> AudioPlayerControlRunner::actionsForMatch(const Plasma::QueryMatch &match) { QList<QAction*> ret; QVariantList data = match.data().value<QVariantList>(); if (data.length() > 3 && data[3].toString().compare(NONE)) { if (!action(PLAY)) { addAction(PLAY, KIcon(QLatin1String( "media-playback-start" )), i18n("Play")); addAction(QUEUE, KIcon(QLatin1String( "media-track-queue-amarok" )), i18n("Queue")); addAction(APPEND, KIcon(QLatin1String( "media-track-add-amarok" )), i18n("Append to playlist")); } const QStringList actions = data[3].toString().split(QLatin1Char( ',' )); for (int i = 0; i < actions.length(); ++i) { ret << action(actions[i]); } } return ret; }
void PidginRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match){ Q_UNUSED(context); qDebug() << match.text() << match.data().toString(); pidgin_d.startChat(match.data().toString()); }
QueryMatchItem::QueryMatchItem(const Plasma::QueryMatch &match, QGraphicsWidget *parent) : MatchItem(match.icon(), match.text(), match.subtext(), parent), m_match(match) {}
void Translator::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match) { Q_UNUSED(context); QApplication::clipboard()->setText(match.text()); }