8#ifndef SRC_NATIVEGREP_H_
9#define SRC_NATIVEGREP_H_
14#include <QProcessEnvironment>
20class QRegularExpression;
39 explicit NativeGrep(QObject *parent =
nullptr);
80 [[nodiscard]]
static auto isMoreMarker(
const QString &line) ->
bool {
81 return line.isEmpty();
95 [[nodiscard]]
static auto isOtpMarker(
const QString &line) ->
bool {
96 return line == QLatin1String(
"\n");
109 return line.size() > 1 && line.front() == QLatin1Char(
'\n');
130 [[nodiscard]]
static auto
132 return result.first.isEmpty();
149 void search(
const QString &pattern,
bool caseInsensitive,
150 const QString &gpgExe,
const QString &storeDir,
151 const QProcessEnvironment &env);
180 static auto matchFile(
const QProcessEnvironment &env,
const QString &gpgExe,
181 const QString &filePath,
const QRegularExpression &rx,
182 const std::atomic_bool *
cancel =
nullptr,
183 const QString &storeDir = QString()) -> QStringList;
198 static auto scanStore(
const QProcessEnvironment &env,
const QString &gpgExe,
199 const QString &storeDir,
const QRegularExpression &rx,
200 const std::atomic_bool *
cancel =
nullptr)
201 -> QList<QPair<QString, QStringList>>;
208 void finished(
const QList<QPair<QString, QStringList>> &results);
218 std::shared_ptr<std::atomic_bool>
cancel;
Full-text search over a password store without pass grep: every .gpg file is decrypted with gpg on a ...
void finished(const QList< QPair< QString, QStringList > > &results)
The newest search is over.
void search(const QString &pattern, bool caseInsensitive, const QString &gpgExe, const QString &storeDir, const QProcessEnvironment &env)
Start a search; finished() follows asynchronously, also for an empty or invalid pattern (with no resu...
static auto isPasswordMatch(const QString &line) -> bool
Whether a line in a result is a match in the entry's first line, the password: passwordMatchText() is...
static constexpr int kMaxMatches
Most matching lines a search collects over the whole store.
static auto isMoreMarker(const QString &line) -> bool
Whether a line in a result is the marker for "more matches inthis entry" rather than a match.
static constexpr qsizetype kMaxPreviewLength
Longest preview of a matching line, in UTF-16 code units.
static constexpr int kMaxMatchesPerEntry
Most matching lines taken from one entry.
static auto passwordMatchText(const QString &line) -> QString
The text of a match isPasswordMatch() accepts.
static auto scanStore(const QProcessEnvironment &env, const QString &gpgExe, const QString &storeDir, const QRegularExpression &rx, const std::atomic_bool *cancel=nullptr) -> QList< QPair< QString, QStringList > >
Walk storeDir, decrypt every .gpg file and collect the matches.
static auto isStoppedMarker(const QPair< QString, QStringList > &result) -> bool
Whether a result is the marker for "the search stopped atkMaxMatches, more entries were not searched"...
int m_seq
Number of the newest search. A worker reports through finished() only when its own number still equal...
QList< Worker > m_workers
Searches still running, superseded ones included.
static auto matchFile(const QProcessEnvironment &env, const QString &gpgExe, const QString &filePath, const QRegularExpression &rx, const std::atomic_bool *cancel=nullptr, const QString &storeDir=QString()) -> QStringList
Decrypt one .gpg file and return its trimmed lines matching rx.
static auto isOtpMarker(const QString &line) -> bool
Whether a line in a result stands for a match in a line holding a one-time password secret (FileConte...
void cancel()
Ask running searches to stop without waiting for them: the walk ends at the next file and a gpg that ...
NativeGrep(QObject *parent=nullptr)
Create a searcher.
QThread * thread
The thread the search runs on.
std::shared_ptr< std::atomic_bool > cancel
Set to ask the search to stop; polled by its gpg runs.