示例#1
0
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);
}
示例#2
0
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();
}
示例#3
0
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);
    }
}
QueryMatchItem::QueryMatchItem(const Plasma::QueryMatch &match, QGraphicsWidget *parent)
    : MatchItem(match.icon(), match.text(), match.subtext(), parent),
      m_match(match)
{}