katesessions.cpp   katesessions.cpp 
skipping to change at line 35 skipping to change at line 35
KateSessions::KateSessions(QObject *parent, const KPluginMetaData &metaData , const QVariantList &args) KateSessions::KateSessions(QObject *parent, const KPluginMetaData &metaData , const QVariantList &args)
: AbstractRunner(parent, metaData, args) : AbstractRunner(parent, metaData, args)
{ {
setObjectName(QStringLiteral("Kate Sessions")); setObjectName(QStringLiteral("Kate Sessions"));
addSyntax(RunnerSyntax(QStringLiteral("kate :q:"), i18n("Finds Kate ses sions matching :q:."))); addSyntax(RunnerSyntax(QStringLiteral("kate :q:"), i18n("Finds Kate ses sions matching :q:.")));
addSyntax(RunnerSyntax(QStringLiteral("kate"), i18n("Lists all the Kate editor sessions in your account."))); addSyntax(RunnerSyntax(QStringLiteral("kate"), i18n("Lists all the Kate editor sessions in your account.")));
// Initialize watchers and sessions // Initialize watchers and sessions
setTriggerWords({m_triggerWord}); setTriggerWords({m_triggerWord});
m_model.setAppName(m_triggerWord);
} }
void KateSessions::match(RunnerContext &context) void KateSessions::match(RunnerContext &context)
{ {
QString term = context.query(); QString term = context.query();
bool listAll = false; bool listAll = false;
if (term.trimmed().compare(m_triggerWord, Qt::CaseInsensitive) == 0) { if (term.trimmed().compare(m_triggerWord, Qt::CaseInsensitive) == 0) {
listAll = true; listAll = true;
term.clear(); term.clear();
} else if (term.at(4) == QLatin1Char(' ')) { } else if (term.at(4) == QLatin1Char(' ')) {
term = term.remove(m_triggerWord, Qt::CaseInsensitive).trimmed(); term = term.remove(m_triggerWord, Qt::CaseInsensitive).trimmed();
} else { } else {
// Prevent results for queries like "katee" // Prevent results for queries like "katee"
return; return;
} }
QList<QueryMatch> matches; QList<QueryMatch> matches;
int maxScore = 0; int maxScore = 0;
for (int i = 0, count = m_model.rowCount(); i < count; ++i) { for (int i = 0, count = m_model->rowCount(); i < count; ++i) {
// Does the query match exactly? // Does the query match exactly?
// no query = perfect match => list everything // no query = perfect match => list everything
QString session = m_model.index(i).data(ProfilesModel::NameRole).to String(); QString session = m_model->index(i).data(ProfilesModel::NameRole).t oString();
if (listAll || session.compare(term, Qt::CaseInsensitive) == 0) { if (listAll || session.compare(term, Qt::CaseInsensitive) == 0) {
QueryMatch match(this); QueryMatch match(this);
match.setType(QueryMatch::ExactMatch); match.setType(QueryMatch::ExactMatch);
match.setRelevance(session.compare(term, Qt::CaseInsensitive) = = 0 ? 1 : 0.8); match.setRelevance(session.compare(term, Qt::CaseInsensitive) = = 0 ? 1 : 0.8);
match.setIconName(m_triggerWord); match.setIconName(m_triggerWord);
match.setData(session); match.setData(session);
match.setText(session); match.setText(session);
match.setSubtext(i18n("Open Kate Session")); match.setSubtext(i18n("Open Kate Session"));
context.addMatch(match); context.addMatch(match);
} else { } else {
skipping to change at line 98 skipping to change at line 96
for (auto &match : matches) { for (auto &match : matches) {
match.setRelevance(calculate_relevance(match.relevance())); match.setRelevance(calculate_relevance(match.relevance()));
} }
context.addMatches(matches); context.addMatches(matches);
} }
void KateSessions::run(const RunnerContext &context, const QueryMatch &matc h) void KateSessions::run(const RunnerContext &context, const QueryMatch &matc h)
{ {
Q_UNUSED(context) Q_UNUSED(context)
m_model.openProfile(match.data().toString()); m_model->openProfile(match.data().toString());
}
void KateSessions::init()
{
// Only create this in the correct thread. Inside we use KDirWatch whic
h is thread sensitive.
m_model = new ProfilesModel(this);
m_model->setAppName(m_triggerWord);
} }
#include "katesessions.moc" #include "katesessions.moc"
 End of changes. 4 change blocks. 
5 lines changed or deleted 11 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/