File indexing completed on 2024-05-12 05:29:44
0001 /* 0002 * SPDX-FileCopyrightText: 2008 Montel Laurent <montel@kde.org> 0003 * based on kate session from sebas 0004 * SPDX-FileCopyrightText: 2020 Alexander Lohnau <alexander.lohnau@gmx.de> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #include "konsoleprofiles.h" 0010 0011 // KF 0012 #include <KConfig> 0013 #include <KConfigGroup> 0014 #include <KDirWatch> 0015 #include <KLocalizedString> 0016 #include <QDir> 0017 #include <QFileInfo> 0018 #include <QStandardPaths> 0019 0020 KonsoleProfiles::KonsoleProfiles(QObject *parent, const KPluginMetaData &metaData) 0021 : AbstractRunner(parent, metaData) 0022 { 0023 addSyntax({QStringLiteral(":q:"), QStringLiteral("konsole :q:")}, i18n("Finds Konsole profiles matching :q:.")); 0024 addSyntax(QStringLiteral("konsole"), i18n("Lists all the Konsole profiles in your account.")); 0025 setTriggerWords({m_triggerWord}); 0026 } 0027 0028 void KonsoleProfiles::match(RunnerContext &context) 0029 { 0030 QString term = context.query(); 0031 term = term.remove(m_triggerWord).simplified(); 0032 for (int i = 0, count = m_model->rowCount(); i < count; ++i) { 0033 QModelIndex idx = m_model->index(i); 0034 const QString name = idx.data(ProfilesModel::NameRole).toString(); 0035 if (name.contains(term, Qt::CaseInsensitive)) { 0036 const QString profileIdentifier = idx.data(ProfilesModel::ProfileIdentifierRole).toString(); 0037 QueryMatch match(this); 0038 match.setCategoryRelevance(QueryMatch::CategoryRelevance::Low); 0039 match.setIconName(idx.data(ProfilesModel::IconNameRole).toString()); 0040 match.setData(profileIdentifier); 0041 match.setText(QStringLiteral("Konsole: ") + name); 0042 match.setRelevance((float)term.length() / (float)name.length()); 0043 context.addMatch(match); 0044 } 0045 } 0046 } 0047 0048 void KonsoleProfiles::run(const RunnerContext & /*context*/, const QueryMatch &match) 0049 { 0050 const QString profile = match.data().toString(); 0051 m_model->openProfile(profile); 0052 } 0053 0054 void KonsoleProfiles::init() 0055 { 0056 // Only create this in the correct thread. Inside we use KDirWatch which is thread sensitive. 0057 m_model = new ProfilesModel(this); 0058 m_model->setAppName(m_triggerWord); 0059 } 0060 0061 K_PLUGIN_CLASS_WITH_JSON(KonsoleProfiles, "plasma-runner-konsoleprofiles.json") 0062 0063 #include "konsoleprofiles.moc"