diff options
author | alex1701c <alex1701c.dev@gmx.net> | 2020-08-18 15:34:46 +0200 |
---|---|---|
committer | alex1701c <alex1701c.dev@gmx.net> | 2020-08-18 15:34:46 +0200 |
commit | 5325780f768c9bb75924c08b4663b84b86e12bd9 (patch) | |
tree | 235980b86631747ff6d1466d13192e317fc1e5a3 | |
parent | 89490957bb4e37a631a75cb05b298bfd3d752d1b (diff) |
Cleanup, set better default behavior
The prefix is by default enabled, but cant be foreced.
Also the plugin requires at least three characters typed, unless
the single runner mode is used.
-rw-r--r-- | config.cpp | 8 | ||||
-rw-r--r-- | config.h | 1 | ||||
-rw-r--r-- | config.ui | 7 | ||||
-rwxr-xr-x | install.sh | 4 | ||||
-rw-r--r-- | pass.cpp | 39 | ||||
-rw-r--r-- | pass.h | 5 | ||||
-rwxr-xr-x | uninstall.sh | 1 |
7 files changed, 23 insertions, 42 deletions
@@ -141,7 +141,6 @@ PassConfig::PassConfig(QWidget *parent, const QVariantList &args) #endif connect(this->ui, &PassConfigForm::passActionAdded, this, changedSlotPointer); connect(this->ui, &PassConfigForm::passActionRemoved, this, changedSlotPointer); - connect(this->ui->checkShowOnlyPrefixed, &QCheckBox::stateChanged, this, changedSlotPointer); connect(this->ui->checkAdditionalActions, &QCheckBox::stateChanged, this, changedSlotPointer); connect(this->ui->checkShowFileContentAction, &QCheckBox::stateChanged, this, changedSlotPointer); connect(this->ui->listSavedActions, &QListWidget::itemSelectionChanged, this, changedSlotPointer); @@ -154,11 +153,9 @@ void PassConfig::load() KSharedConfig::Ptr cfg = KSharedConfig::openConfig(QStringLiteral("krunnerrc")); KConfigGroup passCfg = cfg->group("Runners").group("Pass"); - bool showOnlyPrefixed = passCfg.readEntry(Config::showOnlyPrefixed, false); bool showActions = passCfg.readEntry(Config::showActions, false); bool showFileContentAction = passCfg.readEntry(Config::showFileContentAction, false); - this->ui->checkShowOnlyPrefixed->setChecked(showOnlyPrefixed); this->ui->checkAdditionalActions->setChecked(showActions); this->ui->checkShowFileContentAction->setChecked(showFileContentAction); @@ -180,11 +177,9 @@ void PassConfig::save() KSharedConfig::Ptr cfg = KSharedConfig::openConfig(QStringLiteral("krunnerrc")); KConfigGroup passCfg = cfg->group("Runners").group("Pass"); - auto showOnlyPrefixed = this->ui->checkShowOnlyPrefixed->isChecked(); auto showActions = this->ui->checkAdditionalActions->isChecked(); auto showFileContentAction = this->ui->checkShowFileContentAction->isChecked(); - passCfg.writeEntry(Config::showOnlyPrefixed, showOnlyPrefixed); passCfg.writeEntry(Config::showActions, showActions); passCfg.writeEntry(Config::showFileContentAction, showFileContentAction); @@ -203,14 +198,13 @@ void PassConfig::defaults() { KCModule::defaults(); - ui->checkShowOnlyPrefixed->setChecked(false); ui->checkAdditionalActions->setChecked(false); ui->checkShowFileContentAction->setChecked(false); ui->clearPassActions(); ui->clearInputs(); #if KCMUTILS_VERSION >= QT_VERSION_CHECK(5, 64, 0) - emit markAsChanged(); + markAsChanged(); #else emit changed(true); #endif @@ -25,7 +25,6 @@ struct Config { - constexpr static const char *showOnlyPrefixed = "showOnlyPrefixed"; constexpr static const char *showActions = "showAdditionalActions"; constexpr static const char *showFileContentAction = "showFullFileContentAction"; struct Group { @@ -108,13 +108,6 @@ </property> </widget> </item> - <item row="0" column="0"> - <widget class="QCheckBox" name="checkShowOnlyPrefixed"> - <property name="text"> - <string>Show only options when query starts with "pass"</string> - </property> - </widget> - </item> </layout> </widget> <resources/> @@ -11,5 +11,5 @@ sudo make install set +e -kquitapp5 krunner 2> /dev/null -kstart5 --windowclass krunner krunner > /dev/null 2>&1 & +kquitapp5 krunner +kstart5 --windowclass krunner krunner @@ -40,33 +40,29 @@ using namespace std; Pass::Pass(QObject *parent, const QVariantList &args) : Plasma::AbstractRunner(parent, args) { - Q_UNUSED(args); - // General runner configuration - setObjectName(QString("Pass")); + setObjectName(QStringLiteral("Pass")); setSpeed(AbstractRunner::NormalSpeed); setPriority(HighestPriority); - auto comment = i18n("Looks for a password matching :q:. Pressing ENTER copies the password to the clipboard."); - setDefaultSyntax(Plasma::RunnerSyntax(QString(":q:"), comment)); } Pass::~Pass() = default; void Pass::reloadConfiguration() { - actions().clear(); + clearActions(); orderedActions.clear(); KConfigGroup cfg = config(); + cfg.config()->reparseConfiguration(); // Just to be sure this->showActions = cfg.readEntry(Config::showActions, false); - this->showOnlyPrefixed = cfg.readEntry(Config::showOnlyPrefixed, false); - if (showActions) { const auto configActions = cfg.group(Config::Group::Actions); // Create actions for every additional field - for (const auto &name: configActions.groupList()) { + const auto configActionsList = configActions.groupList(); + for (const auto &name: configActionsList) { auto group = configActions.group(name); auto passAction = PassAction::fromConfig(group); @@ -86,6 +82,12 @@ void Pass::reloadConfiguration() act->setData(Config::showFileContentAction); this->orderedActions << act; } + + setDefaultSyntax(Plasma::RunnerSyntax(QString(":q:"), + i18n("Looks for a password matching :q:. Pressing ENTER copies the password to the clipboard."))); + + addSyntax(Plasma::RunnerSyntax(QString("pass :q:"), + i18n("Looks for a password matching :q:. This way you avoid results from other runners"))); } void Pass::init() @@ -142,7 +144,7 @@ void Pass::initPasswords() void Pass::reinitPasswords(const QString &path) { - Q_UNUSED(path); + Q_UNUSED(path) lock.lockForWrite(); initPasswords(); @@ -156,12 +158,11 @@ void Pass::match(Plasma::RunnerContext &context) } auto input = context.query(); - if (showOnlyPrefixed) { - if (input.startsWith(queryPrefix)) { - input = input.remove(queryPrefix).simplified(); - } else { - return; - } + // If we use the prefix we want to remove it + if (input.startsWith(queryPrefix)) { + input = input.remove(queryPrefix).simplified(); + } else if (input.count() < 3 && !context.singleRunnerQueryMode()) { + return; } QList<Plasma::QueryMatch> matches; @@ -207,16 +208,12 @@ void Pass::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &m connect(pass, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), [=](int exitCode, QProcess::ExitStatus exitStatus) { - Q_UNUSED(exitCode); - Q_UNUSED(exitStatus); + Q_UNUSED(exitStatus) if (exitCode == 0) { - const auto output = pass->readAllStandardOutput(); - if (match.selectedAction() != nullptr) { const auto data = match.selectedAction()->data().toString(); - if (data == Config::showFileContentAction) { QMessageBox::information(nullptr, match.text(), output); } else { @@ -39,7 +39,7 @@ public: void reloadConfiguration() override; -public slots: +public Q_SLOTS: void reinitPasswords(const QString &path); protected: @@ -58,8 +58,7 @@ private: bool showActions; QList<QAction *> orderedActions; - bool showOnlyPrefixed; - QLatin1String queryPrefix = QLatin1String("pass"); + const QLatin1String queryPrefix = QLatin1String("pass"); }; #endif diff --git a/uninstall.sh b/uninstall.sh index 7e9fbfc..e3efe5b 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -7,4 +7,3 @@ cd build sudo make uninstall kquitapp5 krunner kstart5 --windowclass krunner krunner - |