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();
93 [[nodiscard]]
static auto
95 return result.first.isEmpty();
112 void search(
const QString &pattern,
bool caseInsensitive,
113 const QString &gpgExe,
const QString &storeDir,
114 const QProcessEnvironment &env);
135 static auto matchFile(
const QProcessEnvironment &env,
const QString &gpgExe,
136 const QString &filePath,
const QRegularExpression &rx,
137 const std::atomic_bool *
cancel =
nullptr)
153 static auto scanStore(
const QProcessEnvironment &env,
const QString &gpgExe,
154 const QString &storeDir,
const QRegularExpression &rx,
155 const std::atomic_bool *
cancel =
nullptr)
156 -> QList<QPair<QString, QStringList>>;
163 void finished(
const QList<QPair<QString, QStringList>> &results);
173 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 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 matchFile(const QProcessEnvironment &env, const QString &gpgExe, const QString &filePath, const QRegularExpression &rx, const std::atomic_bool *cancel=nullptr) -> QStringList
Decrypt one .gpg file and return its trimmed lines matching rx.
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.
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.