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.
master
alex1701c 6 years ago
parent 89490957bb
commit 5325780f76
  1. 8
      config.cpp
  2. 1
      config.h
  3. 7
      config.ui
  4. 4
      install.sh
  5. 39
      pass.cpp
  6. 5
      pass.h
  7. 1
      uninstall.sh

@ -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 &quot;pass&quot;</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

@ -7,4 +7,3 @@ cd build
sudo make uninstall
kquitapp5 krunner
kstart5 --windowclass krunner krunner

Loading…
Cancel
Save